Skip to content
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
4 changes: 2 additions & 2 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, Set
from typing import Any

import xarray as xr

Expand Down Expand Up @@ -148,7 +148,7 @@ def remove_preserve_method(cls, method_name: str):
cls._preserve_methods.discard(method_name)

@classmethod
def set_preserve_methods(cls, methods: Set[str]):
def set_preserve_methods(cls, methods: set[str]):
"""Set the complete list of methods that preserve uxgrid."""
cls._preserve_methods = set(methods)

Expand Down
23 changes: 7 additions & 16 deletions uxarray/core/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,7 @@

import os
from pathlib import Path
from typing import (
TYPE_CHECKING,
Any,
Dict,
Mapping,
Optional,
Sequence,
TypeAlias,
Union,
)
from typing import TYPE_CHECKING, Any, Mapping, Sequence, TypeAlias
from warnings import warn

import numpy as np
Expand Down Expand Up @@ -46,8 +37,8 @@
def open_grid(
grid_filename_or_obj: str | os.PathLike[Any] | dict | Dataset,
chunks=None,
use_dual: Optional[bool] = False,
**kwargs: Dict[str, Any],
use_dual: bool | None = False,
**kwargs: dict[str, Any],
):
"""Constructs and returns a ``Grid`` from a grid file.

Expand Down Expand Up @@ -436,12 +427,12 @@ def open_dataset(

def open_mfdataset(
grid_filename_or_obj: str | os.PathLike[Any] | dict | Dataset,
paths: Union[str, os.PathLike],
paths: str | os.PathLike,
chunks=None,
chunk_grid: bool = True,
use_dual: Optional[bool] = False,
grid_kwargs: Optional[Dict[str, Any]] = None,
**kwargs: Dict[str, Any],
use_dual: bool | None = False,
grid_kwargs: dict[str, Any] | None = None,
**kwargs: dict[str, Any],
) -> UxDataset:
"""Wraps ``xarray.open_dataset()`` to support reading in a grid and
multiple data files together.
Expand Down
16 changes: 8 additions & 8 deletions uxarray/core/dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import warnings
from html import escape
from typing import TYPE_CHECKING, Any, Hashable, Literal, Mapping, Optional
from typing import TYPE_CHECKING, Any, Hashable, Literal, Mapping
from warnings import warn

import numpy as np
Expand Down Expand Up @@ -164,12 +164,12 @@ def data_mapping(self):

def to_geodataframe(
self,
periodic_elements: Optional[str] = "exclude",
periodic_elements: str | None = "exclude",
projection=None,
cache: Optional[bool] = True,
override: Optional[bool] = False,
engine: Optional[str] = "spatialpandas",
exclude_antimeridian: Optional[bool] = None,
cache: bool | None = True,
override: bool | None = False,
engine: str | None = "spatialpandas",
exclude_antimeridian: bool | None = None,
**kwargs,
):
"""Constructs a ``GeoDataFrame`` consisting of polygons representing
Expand Down Expand Up @@ -462,7 +462,7 @@ def to_xarray(self):
return xr.DataArray(self)

def integrate(
self, quadrature_rule: Optional[str] = "triangular", order: Optional[int] = 4
self, quadrature_rule: str | None = "triangular", order: int | None = 4
) -> UxDataArray:
"""Computes the integral of a data variable.

Expand Down Expand Up @@ -1501,7 +1501,7 @@ def divergence(self, other: "UxDataArray", **kwargs) -> "UxDataArray":

return divergence_da

def difference(self, destination: Optional[str] = "edge"):
def difference(self, destination: str | None = "edge"):
"""Computes the absolute difference of a data variable.

The difference for a face-centered data variable can be computed on each edge using the ``edge_face_connectivity``,
Expand Down
6 changes: 3 additions & 3 deletions uxarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os
import sys
from html import escape
from typing import IO, Any, Mapping, Optional, Union
from typing import IO, Any, Mapping
from warnings import warn

import numpy as np
Expand Down Expand Up @@ -75,7 +75,7 @@ def __init__(
self,
*args,
uxgrid: Grid = None,
source_datasets: Optional[str] = None,
source_datasets: str | None = None,
**kwargs,
):
self._uxgrid = None
Expand Down Expand Up @@ -301,7 +301,7 @@ def from_xarray(cls, ds: xr.Dataset, uxgrid: Grid = None, ugrid_dims: dict = Non
@classmethod
def from_healpix(
cls,
ds: Union[str, os.PathLike, xr.Dataset],
ds: str | os.PathLike | xr.Dataset,
pixels_only: bool = True,
face_dim: str = "cell",
**kwargs,
Expand Down
49 changes: 24 additions & 25 deletions uxarray/grid/coordinates.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import math
from typing import Union

import numpy as np
import xarray as xr
Expand All @@ -12,8 +11,8 @@

@njit(cache=True)
def _lonlat_rad_to_xyz(
lon: Union[np.ndarray, float],
lat: Union[np.ndarray, float],
lon: np.ndarray | float,
lat: np.ndarray | float,
) -> tuple[np.ndarray, np.ndarray, np.ndarray]:
"""Converts Spherical latitude and longitude coordinates into Cartesian x,
y, z coordinates."""
Expand All @@ -26,9 +25,9 @@ def _lonlat_rad_to_xyz(

@njit(cache=True)
def _xyz_to_lonlat_rad_no_norm(
x: Union[np.ndarray, float],
y: Union[np.ndarray, float],
z: Union[np.ndarray, float],
x: np.ndarray | float,
y: np.ndarray | float,
z: np.ndarray | float,
):
"""Converts a Cartesian x,y,z coordinates into Spherical latitude and
longitude without normalization, decorated with Numba.
Expand Down Expand Up @@ -93,30 +92,30 @@ def _xyz_to_lonlat_rad_scalar(x, y, z, normalize=True):


def _xyz_to_lonlat_rad(
x: Union[np.ndarray, float],
y: Union[np.ndarray, float],
z: Union[np.ndarray, float],
x: np.ndarray | float,
y: np.ndarray | float,
z: np.ndarray | float,
normalize: bool = True,
) -> tuple[np.ndarray, np.ndarray, np.ndarray]:
"""Converts Cartesian x, y, z coordinates in Spherical longitude and
latitude coordinates in radians.

Parameters
----------
x : Union[np.ndarray, float]
x : np.ndarray | float
Cartesian x coordinates
y: Union[np.ndarray, float]
y: np.ndarray | float
Cartesiain y coordinates
z: Union[np.ndarray, float]
z: np.ndarray | float
Cartesian z coordinates
normalize: bool
Flag to select whether to normalize the coordinates

Returns
-------
lon : Union[np.ndarray, float]
lon : np.ndarray | float
Longitude in radians
lat: Union[np.ndarray, float]
lat: np.ndarray | float
Latitude in radians
"""

Expand All @@ -142,30 +141,30 @@ def _xyz_to_lonlat_rad(


def _xyz_to_lonlat_deg(
x: Union[np.ndarray, float],
y: Union[np.ndarray, float],
z: Union[np.ndarray, float],
x: np.ndarray | float,
y: np.ndarray | float,
z: np.ndarray | float,
normalize: bool = True,
) -> tuple[np.ndarray, np.ndarray, np.ndarray]:
"""Converts Cartesian x, y, z coordinates in Spherical latitude and
longitude coordinates in degrees.

Parameters
----------
x : Union[np.ndarray, float]
x : np.ndarray | float
Cartesian x coordinates
y: Union[np.ndarray, float]
y: np.ndarray | float
Cartesiain y coordinates
z: Union[np.ndarray, float]
z: np.ndarray | float
Cartesian z coordinates
normalize: bool
Flag to select whether to normalize the coordinates

Returns
-------
lon : Union[np.ndarray, float]
lon : np.ndarray | float
Longitude in degrees
lat: Union[np.ndarray, float]
lat: np.ndarray | float
Latitude in degrees
"""
lon_rad, lat_rad = _xyz_to_lonlat_rad(x, y, z, normalize=normalize)
Expand All @@ -178,9 +177,9 @@ def _xyz_to_lonlat_deg(


def _normalize_xyz(
x: Union[np.ndarray, float],
y: Union[np.ndarray, float],
z: Union[np.ndarray, float],
x: np.ndarray | float,
y: np.ndarray | float,
z: np.ndarray | float,
) -> tuple[np.ndarray, np.ndarray, np.ndarray]:
"""Normalizes a set of Cartesian coordinates."""
denom = np.linalg.norm(
Expand Down
Loading
Loading