Skip to content

Commit

Permalink
Add type alias for projection options
Browse files Browse the repository at this point in the history
Co-authored-by: Raphael Hagen <[email protected]>
  • Loading branch information
maxrjones and norlandrhagen committed Mar 18, 2024
1 parent bd63dd7 commit db69f1a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
5 changes: 4 additions & 1 deletion ndpyramid/common.py
Original file line number Diff line number Diff line change
@@ -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()

Expand Down
7 changes: 3 additions & 4 deletions ndpyramid/reproject.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
from __future__ import annotations # noqa: F401

import typing
from collections import defaultdict

import datatree as dt
import numpy as np
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,
Expand All @@ -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',
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit db69f1a

Please sign in to comment.