diff --git a/docs/environment.yml b/docs/environment.yml index c08116f..93191b4 100644 --- a/docs/environment.yml +++ b/docs/environment.yml @@ -9,7 +9,8 @@ dependencies: - cf_xarray - cmocean - dask - - esmf==8.4.1 # https://github.com/pangeo-data/xESMF/issues/246 + - esmf #==8.4.1 # https://github.com/pangeo-data/xESMF/issues/246 + - esmpy=>8.5.0 # https://github.com/esmf-org/esmf/issues/140 - matplotlib-base - netcdf4 - numpy <1.24 # https://github.com/numba/numba/issues/8615#issuecomment-1360792615 diff --git a/docs/whats_new.md b/docs/whats_new.md index cd8bb0c..a73617d 100644 --- a/docs/whats_new.md +++ b/docs/whats_new.md @@ -1,5 +1,8 @@ # What's New +## v0.6.1 (October 28, 2024) +* 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. + ## v0.6.0 (February 9, 2024) * fixed error in `derived.py`'s `uv_geostrophic` function after being pointed out by @ak11283 * updated docs so mostly well-formatted and working diff --git a/environment.yml b/environment.yml index 02afee9..d9c2dcf 100644 --- a/environment.yml +++ b/environment.yml @@ -12,6 +12,7 @@ dependencies: # # https://github.com/h5py/h5py/issues/1880 # # https://github.com/conda-forge/h5py-feedstock/issues/92 # - h5py < 3.2 + - esmpy>=8.5.0 # https://github.com/esmf-org/esmf/issues/140 - matplotlib-base - netcdf4 - numpy <1.24 # https://github.com/numba/numba/issues/8615#issuecomment-1360792615 diff --git a/xroms/accessor.py b/xroms/accessor.py index f634019..56cf6d2 100644 --- a/xroms/accessor.py +++ b/xroms/accessor.py @@ -202,9 +202,17 @@ def _uv2eastnorth(self): "units": "m/s", } + # need to fill nans with zeros so that the masked locations in + # 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. east, north = rotate_vectors( - self.ds.u, - self.ds.v, + self.ds.u.fillna(0), + self.ds.v.fillna(0), self.ds.angle, isradians=True, reference="xaxis", @@ -253,6 +261,21 @@ def north(self): self._uv2eastnorth() return self.ds["north"] + @property + def eastnorth(self): + """East/north combined and returned as a tuple. + + Notes + ----- + This is a convenience function to return the east and north velocities as a tuple. + + Examples + -------- + >>> ds.xroms.eastnorth + """ + + return self.east, self.north + def _eastnorth2uv(self): """Call the velocity rotation for accessor.""" diff --git a/xroms/derived.py b/xroms/derived.py index a37e9cc..a11dfe4 100644 --- a/xroms/derived.py +++ b/xroms/derived.py @@ -59,8 +59,16 @@ def speed(u, v, xgrid, hboundary="extend", hfill_value=None): assert isinstance(u, xr.DataArray), "var must be DataArray" assert isinstance(v, xr.DataArray), "var must be DataArray" - u = to_rho(u, xgrid, hboundary=hboundary, hfill_value=hfill_value) - v = to_rho(v, xgrid, hboundary=hboundary, hfill_value=hfill_value) + # need to fill nans with zeros so that the masked locations in + # 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. + u = to_rho(u.fillna(0), xgrid, hboundary=hboundary, hfill_value=hfill_value) + v = to_rho(v.fillna(0), xgrid, hboundary=hboundary, hfill_value=hfill_value) var = np.sqrt(u**2 + v**2) var.attrs["name"] = "speed"