Skip to content

Commit c3acdad

Browse files
authored
Merge pull request #70 from kthyng/fix_boundaries
Fix boundaries
2 parents 2a2c61b + 3f04e8b commit c3acdad

File tree

5 files changed

+41
-5
lines changed

5 files changed

+41
-5
lines changed

docs/environment.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ dependencies:
99
- cf_xarray
1010
- cmocean
1111
- dask
12-
- esmf==8.4.1 # https://github.com/pangeo-data/xESMF/issues/246
12+
- esmf #==8.4.1 # https://github.com/pangeo-data/xESMF/issues/246
13+
- esmpy=>8.5.0 # https://github.com/esmf-org/esmf/issues/140
1314
- matplotlib-base
1415
- netcdf4
1516
- numpy <1.24 # https://github.com/numba/numba/issues/8615#issuecomment-1360792615

docs/whats_new.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# What's New
22

3+
## v0.6.1 (October 28, 2024)
4+
* Correction in a few built-in calculations of u/v grid to rho-grid interpolations of u and v velocities (currently `speed` and `_uv2eastnorth`). In these cases, we need to fill nans with zeros so that the masked locations in the velocity fields are not fully brought forward into the rho mask but are instead interpolated over. By making them 0, they are calculated into the mask\_rho positions by combining them with neighboring cells. If this wasn't done, the fact that they are masked would supersede the neighboring cells and they would be masked in mask\_rho. This needs to be done anytime the velocities are moved from their native grids to the rho or other grids to preserve their locations around masked cells.
5+
36
## v0.6.0 (February 9, 2024)
47
* fixed error in `derived.py`'s `uv_geostrophic` function after being pointed out by @ak11283
58
* updated docs so mostly well-formatted and working

environment.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ dependencies:
1212
# # https://github.com/h5py/h5py/issues/1880
1313
# # https://github.com/conda-forge/h5py-feedstock/issues/92
1414
# - h5py < 3.2
15+
- esmpy>=8.5.0 # https://github.com/esmf-org/esmf/issues/140
1516
- matplotlib-base
1617
- netcdf4
1718
- numpy <1.24 # https://github.com/numba/numba/issues/8615#issuecomment-1360792615

xroms/accessor.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,17 @@ def _uv2eastnorth(self):
202202
"units": "m/s",
203203
}
204204

205+
# need to fill nans with zeros so that the masked locations in
206+
# velocity fields are not fully brought forward into the rho mask
207+
# but are instead interpolated over. By making them 0, they are
208+
# calculated into the mask_rho positions by combining them with
209+
# neighboring cells. If this wasn't done, the fact that they are masked
210+
# would supersede the neighboring cells and they would be masked in mask_rho.
211+
# this needs to be done anytime the velocities are moved from their native
212+
# grids to the rho or other grids to preserve their locations around masked cells.
205213
east, north = rotate_vectors(
206-
self.ds.u,
207-
self.ds.v,
214+
self.ds.u.fillna(0),
215+
self.ds.v.fillna(0),
208216
self.ds.angle,
209217
isradians=True,
210218
reference="xaxis",
@@ -253,6 +261,21 @@ def north(self):
253261
self._uv2eastnorth()
254262
return self.ds["north"]
255263

264+
@property
265+
def eastnorth(self):
266+
"""East/north combined and returned as a tuple.
267+
268+
Notes
269+
-----
270+
This is a convenience function to return the east and north velocities as a tuple.
271+
272+
Examples
273+
--------
274+
>>> ds.xroms.eastnorth
275+
"""
276+
277+
return self.east, self.north
278+
256279
def _eastnorth2uv(self):
257280
"""Call the velocity rotation for accessor."""
258281

xroms/derived.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,16 @@ def speed(u, v, xgrid, hboundary="extend", hfill_value=None):
5959
assert isinstance(u, xr.DataArray), "var must be DataArray"
6060
assert isinstance(v, xr.DataArray), "var must be DataArray"
6161

62-
u = to_rho(u, xgrid, hboundary=hboundary, hfill_value=hfill_value)
63-
v = to_rho(v, xgrid, hboundary=hboundary, hfill_value=hfill_value)
62+
# need to fill nans with zeros so that the masked locations in
63+
# velocity fields are not fully brought forward into the rho mask
64+
# but are instead interpolated over. By making them 0, they are
65+
# calculated into the mask_rho positions by combining them with
66+
# neighboring cells. If this wasn't done, the fact that they are masked
67+
# would supersede the neighboring cells and they would be masked in mask_rho.
68+
# this needs to be done anytime the velocities are moved from their native
69+
# grids to the rho or other grids to preserve their locations around masked cells.
70+
u = to_rho(u.fillna(0), xgrid, hboundary=hboundary, hfill_value=hfill_value)
71+
v = to_rho(v.fillna(0), xgrid, hboundary=hboundary, hfill_value=hfill_value)
6472
var = np.sqrt(u**2 + v**2)
6573

6674
var.attrs["name"] = "speed"

0 commit comments

Comments
 (0)