Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix typing and ignore missing imports #100

Merged
merged 5 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,8 @@ repos:
rev: v4.0.0-alpha.8
hooks:
- id: prettier

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.8.0
hooks:
- id: mypy
10 changes: 7 additions & 3 deletions ndpyramid/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import xarray as xr

from .common import Projection
from .utils import add_metadata_and_zarr_encoding, get_version, multiscales_template
from .utils import add_metadata_and_zarr_encoding, get_levels, get_version, multiscales_template


def pyramid_coarsen(
Expand Down Expand Up @@ -48,7 +48,7 @@ def pyramid_coarsen(
for key, factor in enumerate(factors):
# merge dictionary via union operator
kwargs |= {d: factor for d in dims}
plevels[str(key)] = ds.coarsen(**kwargs).mean()
plevels[str(key)] = ds.coarsen(**kwargs).mean() # type: ignore

plevels['/'] = xr.Dataset(attrs=attrs)
return dt.DataTree.from_dict(plevels)
Expand Down Expand Up @@ -96,6 +96,9 @@ def pyramid_reproject(
import rioxarray # noqa: F401
from rasterio.warp import Resampling

if not levels:
levels = get_levels(ds)

# multiscales spec
save_kwargs = {'levels': levels, 'pixels_per_tile': pixels_per_tile}
attrs = {
Expand All @@ -108,9 +111,10 @@ def pyramid_reproject(
)
}


# Convert resampling from string to dictionary if necessary
if isinstance(resampling, str):
resampling_dict = defaultdict(lambda: resampling)
resampling_dict:dict = defaultdict(lambda: resampling)
else:
resampling_dict = resampling

Expand Down
2 changes: 2 additions & 0 deletions ndpyramid/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
def get_version() -> str:
return __version__

def get_levels(ds: xr.Dataset) -> int:
raise NotImplementedError('Automatic determination of number of levels is not yet implemented')

def multiscales_template(
*,
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,7 @@ known-first-party = ["ndpyramid"]
[tool.pytest.ini_options]
console_output_style = "count"
addopts = "--cov=./ --cov-report=xml --verbose"

[tool.mypy]
ignore_missing_imports = true
no_implicit_optional = false
Loading