Skip to content
Draft
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
9 changes: 2 additions & 7 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,11 @@

import uxarray

__all__ = (uxarray, matplotlib.pyplot)

sys.path.insert(0, os.path.abspath("../")) # Source code dir relative to this file

LOGGER = logging.getLogger("conf")

try:
from unittest.mock import MagicMock
except ImportError:
from mock import Mock as MagicMock
from unittest.mock import MagicMock


class Mock(MagicMock):
Expand Down Expand Up @@ -137,7 +132,7 @@ def __getattr__(cls, name):
project = "uxarray"

current_year = datetime.datetime.now().year
copyright = "{}, UXarray".format(current_year)
copyright = f"{current_year}, UXarray"
author = "UXARRAY"

# The language for content autogenerated by Sphinx. Refer to documentation
Expand Down
Empty file modified docs/examples/e3sm-calc-workflow.ipynb
100755 → 100644
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
}
],
"source": [
"storm_box = dict(lon_bounds=(-71, -59), lat_bounds=(13, 22))\n",
"storm_box = {\"lon_bounds\": (-71, -59), \"lat_bounds\": (13, 22)}\n",
"\n",
"mslp_storm = mslp.subset.bounding_box(**storm_box)\n",
"wind_storm = wind.subset.bounding_box(**storm_box)\n",
Expand Down Expand Up @@ -993,7 +993,7 @@
"metadata": {},
"outputs": [],
"source": [
"region_box = dict(lon_bounds=(-105, -35), lat_bounds=(0, 48))\n",
"region_box = {\"lon_bounds\": (-105, -35), \"lat_bounds\": (0, 48)}\n",
"\n",
"z500_region = z500.subset.bounding_box(**region_box)\n",
"pw_region = pw.subset.bounding_box(**region_box)"
Expand Down
5 changes: 1 addition & 4 deletions docs/user-guide/area_calc.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2337,9 +2337,7 @@
"print(\"Area calculated using Gaussian Quadrature Order 2: \", area_gaussian)\n",
"\n",
"print(\n",
" \"Percentage difference between gaussian area above and corrected area: {:.4f}%\".format(\n",
" (corrected_area - area_gaussian) / corrected_area * 100\n",
" )\n",
" f\"Percentage difference between gaussian area above and corrected area: {(corrected_area - area_gaussian) / corrected_area * 100:.4f}%\"\n",
")"
]
},
Expand Down Expand Up @@ -2524,7 +2522,6 @@
"source": [
"verts_grid = ux.open_grid(faces_verts_ndarray, latlon=True)\n",
"\n",
"verts_grid\n",
"verts_grid.plot()"
]
},
Expand Down
6 changes: 3 additions & 3 deletions docs/user-guide/mpl.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@
" 1,\n",
" facecolor=\"w\",\n",
" constrained_layout=True,\n",
" subplot_kw=dict(projection=projection),\n",
" subplot_kw={\"projection\": projection},\n",
")\n",
"\n",
"ax.add_feature(cfeature.COASTLINE)\n",
Expand Down Expand Up @@ -418,7 +418,7 @@
" figsize=(7, 3.5),\n",
" facecolor=\"w\",\n",
" constrained_layout=True,\n",
" subplot_kw=dict(projection=projection),\n",
" subplot_kw={\"projection\": projection},\n",
")\n",
"\n",
"ax.set_extent(lon_bounds + lat_bounds)\n",
Expand Down Expand Up @@ -475,7 +475,7 @@
" 1,\n",
" facecolor=\"w\",\n",
" constrained_layout=True,\n",
" subplot_kw=dict(projection=projection),\n",
" subplot_kw={\"projection\": projection},\n",
")\n",
"\n",
"ax.add_feature(cfeature.COASTLINE)\n",
Expand Down
6 changes: 3 additions & 3 deletions docs/user-guide/parallel-load-ux-with-dask.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6806,9 +6806,9 @@
"metadata": {},
"outputs": [],
"source": [
"face_chunk = round(41_943_042 // 256)\n",
"node_chunk = round(83_886_080 // 256)\n",
"edge_chunk = round(125_829_120 // 256)"
"face_chunk = 41_943_042 // 256\n",
"node_chunk = 83_886_080 // 256\n",
"edge_chunk = 125_829_120 // 256"
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions docs/user-guide/zonal-average.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
"source": [
"from pathlib import Path\n",
"\n",
"import hvplot.pandas # noqa: F401 - activate pandas hvplot accessor\n",
"import hvplot.xarray # noqa: F401 - activate xarray hvplot accessor\n",
"import hvplot.pandas # activate pandas hvplot accessor\n",
"import hvplot.xarray # activate xarray hvplot accessor\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import xarray as xr\n",
Expand Down
28 changes: 13 additions & 15 deletions uxarray/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from importlib.metadata import PackageNotFoundError
from importlib.metadata import version as _version

from . import errors, tutorial
from .constants import INT_DTYPE, INT_FILL_VALUE
from .core.api import (
Expand All @@ -12,30 +15,25 @@
from .core.dataset import UxDataset
from .grid import Grid

try:
from importlib.metadata import version as _version
except Exception:
from importlib_metadata import version as _version

try:
__version__ = _version("uxarray")
except Exception:
except PackageNotFoundError:
# Placeholder version incase an error occurs, such as the library isn't installed
__version__ = "999"


__all__ = (
"open_grid",
"open_dataset",
"open_mfdataset",
"open_multigrid",
"list_grid_names",
"concat",
"tutorial",
"UxDataset",
"UxDataArray",
"INT_DTYPE",
"INT_FILL_VALUE",
"Grid",
"UxDataArray",
"UxDataset",
"concat",
"errors",
"list_grid_names",
"open_dataset",
"open_grid",
"open_mfdataset",
"open_multigrid",
"tutorial",
)
6 changes: 3 additions & 3 deletions uxarray/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from .dataset import UxDataset

__all__ = (
"open_grid",
"UxDataArray",
"UxDataset",
"open_dataset",
"open_grid",
"open_mfdataset",
"UxDataset",
"UxDataArray",
)
32 changes: 16 additions & 16 deletions uxarray/core/accessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
operations return UxDataArray/UxDataset objects with preserved uxgrid.
"""

from typing import Any
from typing import Any, ClassVar

import xarray as xr

Expand Down Expand Up @@ -37,7 +37,7 @@ class BaseAccessor:
"""Base class for all UXarray accessor classes."""

# Default methods known to return DataArrays/Datasets - optimized for performance
_DEFAULT_PRESERVE_METHODS = {
_DEFAULT_PRESERVE_METHODS: ClassVar[set[str]] = {
"mean",
"sum",
"std",
Expand Down Expand Up @@ -102,7 +102,7 @@ def _should_wrap_method(self, name: str) -> bool:
"""Determine if a method should be wrapped."""
if self._auto_wrap:
# In auto-wrap mode, check if it's callable
return hasattr(getattr(self._xr_obj, name, None), "__call__")
return callable(getattr(self._xr_obj, name, None))
return name in self._preserve_methods

def _wrap_method(self, method):
Expand Down Expand Up @@ -132,7 +132,7 @@ def __len__(self):

def __repr__(self):
# Subclasses should override this for specific names
return f"{self.__class__.__name__}({repr(self._xr_obj)})"
return f"{self.__class__.__name__}({self._xr_obj!r})"

def __dir__(self):
# Combine our methods with xarray's for better IDE support
Expand Down Expand Up @@ -192,7 +192,7 @@ def _process_result(self, result):
return result

def __repr__(self):
return f"UxDataArrayGroupBy({repr(self._xr_obj)})"
return f"UxDataArrayGroupBy({self._xr_obj!r})"


class UxDatasetGroupByAccessor(BaseAccessor):
Expand All @@ -213,75 +213,75 @@ def _process_result(self, result):
return result

def __repr__(self):
return f"UxDatasetGroupBy({repr(self._xr_obj)})"
return f"UxDatasetGroupBy({self._xr_obj!r})"


# Similar accessors for other operations
class UxDataArrayResampleAccessor(UxDataArrayGroupByAccessor):
"""Wraps xarray DataArrayResample to preserve uxgrid in results."""

def __repr__(self):
return f"UxDataArrayResample({repr(self._xr_obj)})"
return f"UxDataArrayResample({self._xr_obj!r})"


class UxDatasetResampleAccessor(UxDatasetGroupByAccessor):
"""Wraps xarray DatasetResample to preserve uxgrid in results."""

def __repr__(self):
return f"UxDatasetResample({repr(self._xr_obj)})"
return f"UxDatasetResample({self._xr_obj!r})"


class UxDataArrayRollingAccessor(UxDataArrayGroupByAccessor):
"""Wraps xarray DataArrayRolling to preserve uxgrid in results."""

def __repr__(self):
return f"UxDataArrayRolling({repr(self._xr_obj)})"
return f"UxDataArrayRolling({self._xr_obj!r})"


class UxDatasetRollingAccessor(UxDatasetGroupByAccessor):
"""Wraps xarray DatasetRolling to preserve uxgrid in results."""

def __repr__(self):
return f"UxDatasetRolling({repr(self._xr_obj)})"
return f"UxDatasetRolling({self._xr_obj!r})"


class UxDataArrayCoarsenAccessor(UxDataArrayGroupByAccessor):
"""Wraps xarray DataArrayCoarsen to preserve uxgrid in results."""

def __repr__(self):
return f"UxDataArrayCoarsen({repr(self._xr_obj)})"
return f"UxDataArrayCoarsen({self._xr_obj!r})"


class UxDatasetCoarsenAccessor(UxDatasetGroupByAccessor):
"""Wraps xarray DatasetCoarsen to preserve uxgrid in results."""

def __repr__(self):
return f"UxDatasetCoarsen({repr(self._xr_obj)})"
return f"UxDatasetCoarsen({self._xr_obj!r})"


class UxDataArrayWeightedAccessor(UxDataArrayGroupByAccessor):
"""Wraps xarray DataArrayWeighted to preserve uxgrid in results."""

def __repr__(self):
return f"UxDataArrayWeighted({repr(self._xr_obj)})"
return f"UxDataArrayWeighted({self._xr_obj!r})"


class UxDatasetWeightedAccessor(UxDatasetGroupByAccessor):
"""Wraps xarray DatasetWeighted to preserve uxgrid in results."""

def __repr__(self):
return f"UxDatasetWeighted({repr(self._xr_obj)})"
return f"UxDatasetWeighted({self._xr_obj!r})"


class UxDataArrayRollingExpAccessor(UxDataArrayGroupByAccessor):
"""Wraps xarray DataArrayRollingExp to preserve uxgrid in results."""

def __repr__(self):
return f"UxDataArrayRollingExp({repr(self._xr_obj)})"
return f"UxDataArrayRollingExp({self._xr_obj!r})"


class UxDatasetRollingExpAccessor(UxDatasetGroupByAccessor):
"""Wraps xarray DatasetRollingExp to preserve uxgrid in results."""

def __repr__(self):
return f"UxDatasetRollingExp({repr(self._xr_obj)})"
return f"UxDatasetRollingExp({self._xr_obj!r})"
2 changes: 1 addition & 1 deletion uxarray/core/aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def _node_to_face_kernel(
change_ind,
n_nodes_per_face_sorted_ind,
element_sizes,
size_counts,
_size_counts,
) = get_face_node_partitions(n_nodes_per_face)

result = np.empty(shape=(data.shape[:-1]) + (n_face,))
Expand Down
11 changes: 6 additions & 5 deletions uxarray/core/api.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from __future__ import annotations

import os
from collections.abc import Hashable, Iterable, Mapping, Sequence
from pathlib import Path
from typing import Any, Hashable, Iterable, Mapping, Sequence, TypeAlias
from typing import Any
from warnings import warn

import numpy as np
Expand All @@ -27,11 +28,11 @@
)

__all__ = [
"open_grid",
"open_multigrid",
"list_grid_names",
"open_dataset",
"open_grid",
"open_mfdataset",
"open_multigrid",
]


Expand Down Expand Up @@ -158,8 +159,8 @@ def open_grid(
return grid


MaskValue: TypeAlias = Any | Sequence[Any]
MaskActiveValue: TypeAlias = MaskValue | Mapping[str, MaskValue] | None
type MaskValue = Any | Sequence[Any]
type MaskActiveValue = MaskValue | Mapping[str, MaskValue] | None


def open_multigrid(
Expand Down
21 changes: 10 additions & 11 deletions uxarray/core/arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,16 @@ def _raise_if_grids_incompatible_during(self, other, f):
OR if either grid has n_face==1 (to avoid breaking "scalar-like" workflows,
because isel(n_face=int) maybe should provide scalar, but currently doesn't).
"""
if isinstance(other, UxSupportsArithmetic):
if (
(self.uxgrid.n_face > 1)
and (other.uxgrid.n_face > 1)
and (self.uxgrid != other.uxgrid)
):
raise GridsMismatchError(
f"A.uxgrid != B.uxgrid during binary operation {f.__name__!r}, "
f"with type(A)={type(self).__name__}, type(B)={type(other).__name__}. "
f"(Got A.uxgrid.sizes={self.uxgrid.sizes}; B.uxgrid.sizes={other.uxgrid.sizes}.)"
)
if isinstance(other, UxSupportsArithmetic) and (
(self.uxgrid.n_face > 1)
and (other.uxgrid.n_face > 1)
and (self.uxgrid != other.uxgrid)
):
raise GridsMismatchError(
f"A.uxgrid != B.uxgrid during binary operation {f.__name__!r}, "
f"with type(A)={type(self).__name__}, type(B)={type(other).__name__}. "
f"(Got A.uxgrid.sizes={self.uxgrid.sizes}; B.uxgrid.sizes={other.uxgrid.sizes}.)"
)

def __array_ufunc__(self, ufunc, method, *inputs, **kwargs):
"""Like super().__array_ufunc__, except that if multiple inputs have a uxgrid,
Expand Down
Loading
Loading