From db69f1aa18a519b3f8a00adf1472677c31172d3e Mon Sep 17 00:00:00 2001 From: Max Jones <14077947+maxrjones@users.noreply.github.com> Date: Mon, 18 Mar 2024 19:52:33 -0400 Subject: [PATCH] Add type alias for projection options Co-authored-by: Raphael Hagen --- ndpyramid/common.py | 5 ++++- ndpyramid/reproject.py | 7 +++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/ndpyramid/common.py b/ndpyramid/common.py index 1fdbf3f..b4c42c4 100644 --- a/ndpyramid/common.py +++ b/ndpyramid/common.py @@ -1,12 +1,15 @@ import typing +from typing import TypeAlias import pydantic import pyproj import rasterio.transform +ProjectionOptions: TypeAlias = typing.Literal['web-mercator', 'equidistant-cylindrical'] + class Projection(pydantic.BaseModel): - name: typing.Literal['web-mercator', 'equidistant-cylindrical'] = 'web-mercator' + name: ProjectionOptions = 'web-mercator' _crs: str = pydantic.PrivateAttr() _proj = pydantic.PrivateAttr() diff --git a/ndpyramid/reproject.py b/ndpyramid/reproject.py index 635ba7b..c7a95ce 100644 --- a/ndpyramid/reproject.py +++ b/ndpyramid/reproject.py @@ -1,6 +1,5 @@ from __future__ import annotations # noqa: F401 -import typing from collections import defaultdict import datatree as dt @@ -8,7 +7,7 @@ import xarray as xr from rasterio.warp import Resampling -from .common import Projection +from .common import Projection, ProjectionOptions from .utils import ( add_metadata_and_zarr_encoding, get_levels, @@ -31,7 +30,7 @@ def _da_reproject(da, *, dim, crs, resampling, transform): def level_reproject( ds: xr.Dataset, *, - projection: typing.Literal['web-mercator', 'equidistant-cylindrical'] = 'web-mercator', + projection: ProjectionOptions = 'web-mercator', level: int, pixels_per_tile: int = 128, resampling: str | dict = 'average', @@ -121,7 +120,7 @@ def level_reproject( def pyramid_reproject( ds: xr.Dataset, *, - projection: typing.Literal['web-mercator', 'equidistant-cylindrical'] = 'web-mercator', + projection: ProjectionOptions = 'web-mercator', levels: int = None, pixels_per_tile: int = 128, other_chunks: dict = None,