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

Fix boundaries #70

Merged
merged 5 commits into from
Oct 28, 2024
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
3 changes: 2 additions & 1 deletion docs/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions docs/whats_new.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 25 additions & 2 deletions xroms/accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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."""

Expand Down
12 changes: 10 additions & 2 deletions xroms/derived.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading