Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Sep 14, 2022
1 parent eb1748d commit 35f6fa6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 20 deletions.
25 changes: 7 additions & 18 deletions xwrf/accessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ class WRFDataArrayAccessor(WRFAccessor):
"""Adds a number of WRF specific methods to xarray.DataArray objects."""

def destagger(
self,
stagger_dim: Optional[str] = None,
unstaggered_dim_name: Optional[str] = None
self, stagger_dim: str | None = None, unstaggered_dim_name: str | None = None
) -> xr.DataArray:
"""
Destagger a single WRF xarray.DataArray
Expand All @@ -53,9 +51,7 @@ def destagger(
The destaggered DataArray with renamed dimension and adjusted coordinates.
"""
new_variable = _destag_variable(
self.xarray_obj.variable,
stagger_dim=stagger_dim,
unstag_dim_name=unstaggered_dim_name
self.xarray_obj.variable, stagger_dim=stagger_dim, unstag_dim_name=unstaggered_dim_name
)

# Need to recalculate staggered coordinates, as they don't already exist independently
Expand All @@ -65,14 +61,10 @@ def destagger(
if set(coord_data.dims).difference(set(new_variable.dims)):
# Has a dimension not in the destaggered output (and so still staggered)
new_name = _rename_staggered_coordinate(
coord_name,
stagger_dim=stagger_dim,
unstag_dim_name=unstaggered_dim_name
coord_name, stagger_dim=stagger_dim, unstag_dim_name=unstaggered_dim_name
)
new_coords[new_name] = _destag_variable(
coord_data,
stagger_dim=stagger_dim,
unstag_dim_name=unstaggered_dim_name
coord_data, stagger_dim=stagger_dim, unstag_dim_name=unstaggered_dim_name
)
else:
new_coords[coord_name] = coord_data.variable
Expand Down Expand Up @@ -136,10 +128,7 @@ def postprocess(

return ds.pipe(_rename_dims)

def destagger(
self,
staggered_to_unstaggered_dims: Optional[Dict[str, str]] = None
) -> xr.Dataset:
def destagger(self, staggered_to_unstaggered_dims: dict[str, str] | None = None) -> xr.Dataset:
"""
Destagger all data variables in a WRF xarray.Dataset
Expand All @@ -159,7 +148,7 @@ def destagger(
already being present in the dataset.
"""
staggered_dims = (
set(dim for dim in self.xarray_obj.dims if dim.endswith('_stag'))
{dim for dim in self.xarray_obj.dims if dim.endswith('_stag')}
if staggered_to_unstaggered_dims is None
else set(staggered_to_unstaggered_dims)
)
Expand All @@ -177,7 +166,7 @@ def destagger(
None
if staggered_to_unstaggered_dims is None
else staggered_to_unstaggered_dims[this_staggered_dim]
)
),
)
else:
# No staggered dims
Expand Down
4 changes: 2 additions & 2 deletions xwrf/destagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def _drop_attrs(attrs_dict, attrs_to_drop):
def _destag_variable(datavar, stagger_dim=None, unstag_dim_name=None):
"""
Destaggering function for a single wrf xarray.Variable
Based off of the wrf-python destagger function
https://github.com/NCAR/wrf-python/blob/22fb45c54f5193b849fdff0279445532c1a6c89f/src/wrf/destag.py
Copyright 2016 University Corporation for Atmospheric Research, reused with modification
Expand Down Expand Up @@ -75,7 +75,7 @@ def _destag_variable(datavar, stagger_dim=None, unstag_dim_name=None):
data=center_mean.data,
attrs=_drop_attrs(center_mean.attrs, ('stagger',)),
encoding=center_mean.encoding,
fastpath=True
fastpath=True,
)


Expand Down

0 comments on commit 35f6fa6

Please sign in to comment.