Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exchange xr.Dataset.dims by xr.Dataset.sizes #159

Merged
merged 4 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion xwrf/accessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def destagger(self, staggered_to_unstaggered_dims: dict[str, str] | None = None)
dataset, but will not be associated with any data variables.
"""
staggered_dims = (
{dim for dim in self.xarray_obj.dims if dim.endswith('_stag')}
lpilz marked this conversation as resolved.
Show resolved Hide resolved
{dim for dim in self.xarray_obj.sizes if dim.endswith('_stag')}
if staggered_to_unstaggered_dims is None
else set(staggered_to_unstaggered_dims)
)
Expand Down
4 changes: 2 additions & 2 deletions xwrf/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ def _wrf_grid_from_dataset(ds: xr.Dataset) -> Mapping[Hashable, pyproj.CRS | np.

# Get grid specifications
trf = pyproj.Transformer.from_crs(wgs84, crs, always_xy=True)
nx = ds.dims['west_east']
ny = ds.dims['south_north']
nx = ds.sizes['west_east']
ny = ds.sizes['south_north']
e, n = trf.transform(cen_lon, cen_lat)
x0 = -(nx - 1) / 2.0 * dx + e # DL corner
y0 = -(ny - 1) / 2.0 * dy + n # DL corner
Expand Down
4 changes: 2 additions & 2 deletions xwrf/postprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def _include_projection_coordinates(ds: xr.Dataset) -> xr.Dataset:
'projection metadata.'
)
return ds
horizontal_dims = set(config.get('horizontal_dims')).intersection(set(ds.dims))
lpilz marked this conversation as resolved.
Show resolved Hide resolved
horizontal_dims = set(config.get('horizontal_dims')).intersection(set(ds.sizes))

# Include dimension coordinates
for dim in horizontal_dims:
Expand All @@ -126,7 +126,7 @@ def _assign_coord_to_dim_of_different_name(ds: xr.Dataset) -> xr.Dataset:

def _rename_dims(ds: xr.Dataset) -> xr.Dataset:
"""Rename dims for more consistent semantics."""
rename_dim_map = {k: v for k, v in config.get('rename_dim_map').items() if k in ds.dims}
lpilz marked this conversation as resolved.
Show resolved Hide resolved
rename_dim_map = {k: v for k, v in config.get('rename_dim_map').items() if k in ds.sizes}
return ds.rename(rename_dim_map)


Expand Down