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
38 changes: 23 additions & 15 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,43 @@ requires-python = ">=3.10"
# minimal dependencies start
dependencies = [
"antimeridian",
"cartopy",
"dask[dataframe]",
"datashader",
"geoviews",
"holoviews",
"matplotlib",
"matplotlib-inline",
"netcdf4",
"numba",
"numpy",
"pandas",
"pyarrow",
"requests",
"scikit-learn",
"scipy",
"shapely",
"spatialpandas",
"geopandas",
"xarray",
"hvplot",
"healpix",
"hvplot", # TODO: move to viz after PR #1541 gets merged.
"polars",
"pyproj"
]
# minimal dependencies end

[project.optional-dependencies]
complete = ["uxarray[dev]"]
dev = ['pathlib', 'pre_commit', 'pytest', 'pytest-cov', 'ruff', 'asv']
all = ["uxarray[dev,geo,viz]"]
complete = ["uxarray[dev,geo,viz]"] # alias to "all"
dev = [
'asv',
'pooch',
'pre_commit',
'pytest',
'pytest-cov',
'ruff',
]
geo = [
"geopandas",
"healpix",
"pyproj",
"spatialpandas",
]
viz = [
"cartopy",
"geoviews",
"holoviews",
"matplotlib",
]

[project.urls]
Documentation = "https://uxarray.readthedocs.io/"
Expand Down
3 changes: 3 additions & 0 deletions test/io/test_structured.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
import xarray as xr
import pytest

# import pooch # not necessary to actually import, but tests would likely fail if this fails.
# (commented here for future reference, since pooch is included in uxarray[dev]
# dependencies, but not imported explicitly anywhere in uxarray.)

@pytest.mark.parametrize("ds_name", ["air_temperature", "ersstv5"])
def test_read_structured_grid_from_ds(ds_name):
Expand Down
7 changes: 5 additions & 2 deletions uxarray/core/dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
from typing import TYPE_CHECKING, Any, Hashable, Literal, Mapping, Optional
from warnings import warn

import cartopy.crs as ccrs
import numpy as np
import xarray as xr
from cartopy.mpl.geoaxes import GeoAxes
from xarray.core import dtypes
from xarray.core.options import OPTIONS
from xarray.core.utils import UncachedAccessor
Expand Down Expand Up @@ -37,6 +35,9 @@
from uxarray.subset import DataArraySubsetAccessor

if TYPE_CHECKING:
import cartopy.crs as ccrs
from cartopy.mpl.geoaxes import GeoAxes

from uxarray.core.dataset import UxDataset


Expand Down Expand Up @@ -462,6 +463,8 @@ def to_raster(
>>> ax.imshow(raster, origin="lower", extent=ax.get_xlim() + ax.get_ylim())

"""
from cartopy.mpl.geoaxes import GeoAxes

from uxarray.constants import INT_DTYPE
from uxarray.plot.matplotlib import (
_ensure_dimensions,
Expand Down
3 changes: 2 additions & 1 deletion uxarray/cross_sections/sample.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import numpy as np
from numba import njit, prange
from pyproj import Geod


@njit(parallel=True)
Expand All @@ -17,6 +16,8 @@ def _fill_numba(flat_orig, face_idx, n_face, n_steps):
def sample_geodesic(
start: tuple[float, float], end: tuple[float, float], steps: int
) -> tuple[np.ndarray, np.ndarray]:
from pyproj import Geod

lon0, lat0 = start
lon1, lat1 = end

Expand Down
2 changes: 0 additions & 2 deletions uxarray/grid/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,6 @@ def _build_corrected_polygon_shells(polygon_shells):
_corrected_shells_to_original_faces : np.ndarray
Original indices used to map the corrected polygon shells to their entries in face nodes
"""

# import optional dependencies
import antimeridian
from shapely import Polygon

Expand Down
8 changes: 6 additions & 2 deletions uxarray/grid/grid.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from __future__ import annotations

import copy
import os
from html import escape
from typing import Optional, Sequence
from typing import TYPE_CHECKING, Optional, Sequence
from warnings import warn

import cartopy.crs as ccrs
import numpy as np
import xarray as xr
from xarray.core.options import OPTIONS
Expand Down Expand Up @@ -99,6 +100,9 @@
from uxarray.plot.accessor import GridPlotAccessor
from uxarray.subset import GridSubsetAccessor

if TYPE_CHECKING:
import cartopy.crs as ccrs


class Grid:
"""Represents a two-dimensional unstructured grid encoded following the
Expand Down
5 changes: 4 additions & 1 deletion uxarray/io/_healpix.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from typing import Any

import healpix as hp
import numpy as np
import polars as pl
import xarray as xr
Expand Down Expand Up @@ -68,6 +67,8 @@ def pix2corner_ang(
----
This will be updated when https://github.com/ntessore/healpix/issues/66 is implemented.
"""
import healpix as hp

if nest:
fu = hp._chp.nest2ang_uv
else:
Expand Down Expand Up @@ -102,6 +103,8 @@ def _pixels_to_ugrid(zoom, nest):
A dataset containing pixel longitude and latitude coordinates along with related attributes.

"""
import healpix as hp

ds = xr.Dataset()

nside = hp.order2nside(zoom)
Expand Down
4 changes: 1 addition & 3 deletions uxarray/plot/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import holoviews as hv


class HoloviewsBackend:
"""Utility class to compare and set a HoloViews plotting backend for
visualization."""
Expand All @@ -16,6 +13,7 @@ def assign(self, backend: str):
backend : str
Plotting backend to use, one of 'matplotlib', 'bokeh'
"""
import holoviews as hv

if self.matplotlib_backend is None:
import matplotlib as mpl
Expand Down
7 changes: 6 additions & 1 deletion uxarray/remap/weights.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
from dataclasses import dataclass
from os import PathLike
from pathlib import Path
from typing import TYPE_CHECKING

import numpy as np
import xarray as xr
from scipy import sparse

from uxarray.core.utils import _open_dataset_with_fallback

if TYPE_CHECKING:
from scipy import sparse

# LRU-bounded cache for loaded remap operators.
_WEIGHTS_CACHE_MAXSIZE = 32
_WEIGHTS_CACHE: "OrderedDict[tuple[str, int, int], RemapWeights]" = OrderedDict()
Expand Down Expand Up @@ -83,6 +86,8 @@ class RemapWeights:
@classmethod
def from_file(cls, filename_or_obj: str | PathLike[str] | xr.Dataset):
"""Load a standard sparse remap-weight file into memory once."""
from scipy import sparse

if isinstance(filename_or_obj, xr.Dataset):
ds = filename_or_obj
close_ds = False
Expand Down
Loading