Skip to content

Commit

Permalink
use pipe union syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
carderne committed Feb 19, 2024
1 parent da76e1c commit 239a85a
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 32 deletions.
44 changes: 31 additions & 13 deletions gridfinder/__init__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,35 @@
"""
gridfinder package contains the following modules:
- _util.py : helper functions used internally
- gridfinder.py : main implementation of Dijkstra's algorithm
- post.py : postprocess the algorithm output and check accuracy
- prepare.py : transforming input data into the cost and targets arrays
"""

from importlib.metadata import version

from .gridfinder import * # NoQA
from .post import * # NoQA
from .prepare import * # NoQA
from .util import * # NoQA
from gridfinder.gridfinder import get_targets_costs, optimise
from gridfinder.post import accuracy, raster_to_lines, thin, threshold, threshold_arr
from gridfinder.prepare import (
clip_rasters,
create_filter,
drop_zero_pop,
filter_func,
merge_rasters,
prepare_ntl,
prepare_roads,
)
from gridfinder.util import clip_raster, save_raster

__version__ = version("gridfinder")

__all__ = [
"get_targets_costs",
"optimise",
"threshold",
"threshold_arr",
"thin",
"raster_to_lines",
"accuracy",
"clip_rasters",
"merge_rasters",
"filter_func",
"create_filter",
"prepare_ntl",
"drop_zero_pop",
"prepare_roads",
"save_raster",
"clip_raster",
]
4 changes: 1 addition & 3 deletions gridfinder/gridfinder.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
Implements Dijkstra's algorithm on a cost-array to create an MST.
"""
from __future__ import annotations

from heapq import heapify, heappop, heappush
from math import sqrt
Expand Down
5 changes: 1 addition & 4 deletions gridfinder/post.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
"""
Post-processing for gridfinder package.
"""

from __future__ import annotations

import geopandas as gpd
import numpy as np
Expand Down
7 changes: 2 additions & 5 deletions gridfinder/prepare.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
"""
Prepare input layers for gridfinder.
"""
from __future__ import annotations

import json
import os
from math import sqrt
from pathlib import Path
from typing import Optional

import fiona
import geopandas as gpd
Expand Down Expand Up @@ -122,7 +119,7 @@ def create_filter() -> np.ndarray:
def prepare_ntl(
ntl_in: Pathy,
aoi_in: Pathy,
ntl_filter: Optional[np.ndarray] = None,
ntl_filter: np.ndarray | None = None,
threshold: float = 0.1,
upsample_by: int = 2,
) -> tuple[np.ndarray, Affine]:
Expand Down
9 changes: 3 additions & 6 deletions gridfinder/util.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
"""
Utility module used internally.
"""
from __future__ import annotations

import json
from pathlib import Path
from typing import Optional, Union

import numpy as np
import rasterio as rs
Expand All @@ -13,7 +10,7 @@
from pyproj import Proj
from rasterio.mask import mask

Pathy = Union[str, Path]
Pathy = str | Path

Loc = tuple[int, int]

Expand All @@ -22,7 +19,7 @@ def save_raster(
path: Pathy,
raster: np.ndarray,
affine: Affine,
crs: Optional[Union[str, Proj]] = None,
crs: str | Proj | None = None,
nodata: int = 0,
) -> None:
"""Save a raster to the specified file.
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ line-length = 88
exclude = []

[tool.ruff.lint]
ignore-init-module-imports = true
select = [
"F",
"E",
Expand All @@ -100,4 +101,4 @@ reportMissingImports = true
reportMissingParameterType = true
reportUnnecessaryTypeIgnoreComment = true
reportDeprecated = true
pythonVersion = "3.9"
pythonVersion = "3.10"

0 comments on commit 239a85a

Please sign in to comment.