Skip to content

Commit

Permalink
Minor changes (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
andersy005 authored Apr 4, 2022
1 parent fb6e960 commit d10a18e
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['3.9', '3.10']
python-version: ['3.8', '3.9', '3.10']
timeout-minutes: 20
defaults:
run:
Expand Down
9 changes: 4 additions & 5 deletions ci/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ channels:
- conda-forge
- nodefaults
dependencies:
- esmpy>=8.2.0
- dask
- esmpy>=8.2.0
- mpich
- netcdf4
- numpy
- pip
- pooch
- pytest
- pytest-cov
Expand All @@ -15,9 +17,6 @@ dependencies:
- rioxarray
- scipy
- xarray
- xarray-datatree>=0.0.4
- xesmf
- zarr
- pip
- mpich
- pip:
- xarray-datatree==0.0.3
26 changes: 11 additions & 15 deletions ndpyramid/regrid.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations # noqa: F401

import itertools
import pathlib

import datatree as dt
Expand Down Expand Up @@ -52,22 +53,19 @@ def make_grid_ds(level: int, pixels_per_tile: int = 128) -> xr.Dataset:

# calc grid cell center coordinates
ii, jj = np.meshgrid(np.arange(dim) + 0.5, np.arange(dim) + 0.5)
for i in range(grid_shape[0]):
for j in range(grid_shape[1]):
locs = [ii[i, j], jj[i, j]]
xs[i, j], ys[i, j] = transform * locs
lon[i, j], lat[i, j] = p(xs[i, j], ys[i, j], inverse=True)
for i, j in itertools.product(range(grid_shape[0]), range(grid_shape[1])):
locs = [ii[i, j], jj[i, j]]
xs[i, j], ys[i, j] = transform * locs
lon[i, j], lat[i, j] = p(xs[i, j], ys[i, j], inverse=True)

# calc grid cell bounds
iib, jjb = np.meshgrid(np.arange(dim + 1), np.arange(dim + 1))
for i in range(bounds_shape[0]):
for j in range(bounds_shape[1]):
locs = [iib[i, j], jjb[i, j]]
x, y = transform * locs
lon_b[i, j], lat_b[i, j] = p(x, y, inverse=True)

# pack data into xarray.Dataset
ds = xr.Dataset(
for i, j in itertools.product(range(bounds_shape[0]), range(bounds_shape[1])):
locs = [iib[i, j], jjb[i, j]]
x, y = transform * locs
lon_b[i, j], lat_b[i, j] = p(x, y, inverse=True)

return xr.Dataset(
{
'x': xr.DataArray(xs[0, :], dims=['x']),
'y': xr.DataArray(ys[:, 0], dims=['y']),
Expand All @@ -79,8 +77,6 @@ def make_grid_ds(level: int, pixels_per_tile: int = 128) -> xr.Dataset:
attrs=dict(title='Web Mercator Grid', Convensions='CF-1.8'),
)

return ds


def make_grid_pyramid(levels: int = 6) -> dt.DataTree:
"""helper function to create a grid pyramid for use with xesmf
Expand Down
27 changes: 18 additions & 9 deletions ndpyramid/utils.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
from __future__ import annotations # noqa: F401

import importlib
from ._version import __version__


def get_version():
try:
return importlib.import_module('ndpyramid').__version__
except ModuleNotFoundError:
return '-9999'
def get_version() -> str:
return __version__


def multiscales_template(datasets=[], type='', method='', version='', args=[], kwargs={}):
def multiscales_template(
datasets: list = None,
type: str = '',
method: str = '',
version: str = '',
args: list = None,
kwargs: dict = None,
):
if datasets is None:
datasets = []
if args is None:
args = []
if kwargs is None:
kwargs = {}
# https://forum.image.sc/t/multiscale-arrays-v0-1/37930
d = [
return [
{
'datasets': datasets,
'type': type,
'metadata': {'method': method, 'version': version, 'args': args, 'kwargs': kwargs},
}
]
return d
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
numpy
xarray
xarray-datatree >= 0.0.3
xarray-datatree >= 0.0.4
zarr
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
INSTALL_REQUIRES = f.read().strip().split('\n')

LONG_DESCRIPTION = pathlib.Path('README.md').read_text()
PYTHON_REQUIRES = '>=3.9'
PYTHON_REQUIRES = '>=3.8'

description = 'A small utility for generating ND array pyramids using Xarray and Zarr.'

Expand Down

0 comments on commit d10a18e

Please sign in to comment.