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
32 changes: 9 additions & 23 deletions uxarray/core/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

import os
from pathlib import Path
from typing import TYPE_CHECKING, Any, Mapping, Sequence, TypeAlias
from typing import Any, Mapping, Sequence, TypeAlias
from warnings import warn

import numpy as np
import xarray as xr

from uxarray.core.dataset import UxDataset
from uxarray.core.utils import (
Expand All @@ -22,9 +23,6 @@
_stack_cell_dims,
)

if TYPE_CHECKING:
from xarray import Dataset

__all__ = [
"open_grid",
"open_multigrid",
Expand All @@ -35,7 +33,7 @@


def open_grid(
grid_filename_or_obj: str | os.PathLike[Any] | dict | Dataset,
grid_filename_or_obj: str | os.PathLike[Any] | dict | xr.Dataset,
chunks=None,
use_dual: bool | None = False,
**kwargs: dict[str, Any],
Expand Down Expand Up @@ -85,8 +83,6 @@ def open_grid(

>>> uxgrid = ux.open_grid("grid_filename.nc", chunks=-1)
"""
import xarray as xr

# Handle chunk-related kwargs first.
data_chunks = kwargs.pop("data_chunks", None)
if data_chunks is not None:
Expand Down Expand Up @@ -144,9 +140,9 @@ def open_grid(


def open_multigrid(
grid_filename_or_obj: str | Path | "Dataset",
grid_filename_or_obj: str | Path | xr.Dataset,
gridnames: list[str] | None = None,
mask_filename: str | Path | "Dataset" | None = None,
mask_filename: str | Path | xr.Dataset | None = None,
mask_active_value: MaskActiveValue = 1,
**kwargs: dict[str, Any],
) -> dict[str, Grid]:
Expand Down Expand Up @@ -175,8 +171,6 @@ def open_multigrid(
dict[str, Grid]
Dictionary mapping grid names to ``Grid`` objects.
"""
import xarray as xr

grid_ds_opened = False
if isinstance(grid_filename_or_obj, xr.Dataset):
grid_ds = grid_filename_or_obj
Expand Down Expand Up @@ -314,7 +308,7 @@ def _active_mask_values_for_grid(grid_name: str) -> np.ndarray:


def list_grid_names(
grid_filename_or_obj: str | Path | "Dataset", **kwargs: dict[str, Any]
grid_filename_or_obj: str | Path | xr.Dataset, **kwargs: dict[str, Any]
) -> list[str]:
"""List all grid names available within a grid file.

Expand All @@ -331,8 +325,6 @@ def list_grid_names(
``['grid']`` for single-grid files or the detected grid names for
multi-grid files.
"""
import xarray as xr

grid_ds_opened = False
if isinstance(grid_filename_or_obj, xr.Dataset):
grid_ds = grid_filename_or_obj
Expand All @@ -352,8 +344,8 @@ def list_grid_names(


def open_dataset(
grid_filename_or_obj: str | os.PathLike[Any] | dict | Dataset,
filename_or_obj: str | os.PathLike[Any] | Dataset | None = None,
grid_filename_or_obj: str | os.PathLike[Any] | dict | xr.Dataset,
filename_or_obj: str | os.PathLike[Any] | xr.Dataset | None = None,
chunks=None,
chunk_grid: bool = True,
use_dual: bool | None = False,
Expand Down Expand Up @@ -426,8 +418,6 @@ def open_dataset(

>>> ux_ds = ux.open_dataset("combined_file.nc")
"""
import xarray as xr

if grid_kwargs is None:
grid_kwargs = {}

Expand Down Expand Up @@ -481,7 +471,7 @@ def open_dataset(


def open_mfdataset(
grid_filename_or_obj: str | os.PathLike[Any] | dict | Dataset,
grid_filename_or_obj: str | os.PathLike[Any] | dict | xr.Dataset,
paths: str | os.PathLike,
chunks=None,
chunk_grid: bool = True,
Expand Down Expand Up @@ -546,8 +536,6 @@ def open_mfdataset(

>>> ux_ds = ux.open_mfdataset("grid_filename.g", "grid_filename_vortex_*.nc")
"""
import xarray as xr

if grid_kwargs is None:
grid_kwargs = {}

Expand Down Expand Up @@ -588,8 +576,6 @@ def _get_grid(

def concat(objs, *args, **kwargs):
# Ensure there is at least one object to concat.
import xarray as xr

if not objs:
raise ValueError("No objects provided for concatenation.")

Expand Down
3 changes: 1 addition & 2 deletions uxarray/grid/coordinates.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import math
import warnings

import numpy as np
import xarray as xr
Expand Down Expand Up @@ -750,8 +751,6 @@ def _set_desired_longitude_range(uxgrid):
"""
if _is_projected_grid(uxgrid):
if not getattr(uxgrid, "_projected_warning_issued", False):
import warnings

warnings.warn(
"Projected (non-spherical) coordinates detected on this grid "
"(standard_name='projection_x_coordinate' or length units). "
Expand Down
10 changes: 4 additions & 6 deletions uxarray/grid/grid.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import copy
import os
import warnings
from html import escape
from typing import Optional, Sequence
from warnings import warn

import cartopy.crs as ccrs
import numpy as np
Expand Down Expand Up @@ -169,7 +169,7 @@ def __init__(

# grid spec not provided, check if grid_ds is a minimum representable UGRID dataset
if source_grid_spec is None:
warn(
warnings.warn(
"Attempting to construct a Grid without passing in source_grid_spec. Direct use of Grid constructor"
"is only advised if grid_ds is following the internal unstructured grid definition, including"
"variable and dimension names. Using ux.open_grid() or ux.from_dataset() is suggested.",
Expand Down Expand Up @@ -817,7 +817,7 @@ def descriptors(self) -> set:
@property
def parsed_attrs(self) -> dict:
"""Dictionary of parsed attributes from the source grid."""
warn(
warnings.warn(
"Grid.parsed_attrs will be deprecated in a future release. Please use Grid.attrs instead.",
DeprecationWarning,
)
Expand Down Expand Up @@ -2011,8 +2011,6 @@ def compute_face_areas(
``face_areas`` property instead, which ensures mathematical correctness by using
theoretical equal areas.
"""
import warnings

warnings.warn(
"compute_face_areas() is deprecated. Use the face_areas property instead for better performance and caching.",
DeprecationWarning,
Expand Down Expand Up @@ -2264,7 +2262,7 @@ def to_geodataframe(
)

if exclude_antimeridian is not None:
warn(
warnings.warn(
DeprecationWarning(
"The parameter ``exclude_antimeridian`` will be deprecated in a future release. Please "
"use ``periodic_elements='exclude'`` or ``periodic_elements='split'`` instead."
Expand Down
7 changes: 3 additions & 4 deletions uxarray/io/_esmf.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from datetime import datetime

import numpy as np
import xarray as xr

from uxarray.constants import INT_DTYPE, INT_FILL_VALUE
Expand Down Expand Up @@ -119,10 +122,6 @@ def _encode_esmf(ds: xr.Dataset) -> xr.Dataset:
xr.Dataset
An xarray.Dataset formatted according to ESMF Unstructured Grid conventions.
"""
from datetime import datetime

import numpy as np

out_ds = xr.Dataset()

# Node Coordinates (nodeCoords)
Expand Down