Skip to content
New issue

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

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

Already on GitHub? # to your account

Remove data_full_zdim from fieldfilebuffer #1936

Merged
merged 4 commits into from
Mar 13, 2025
Merged

Conversation

VeckoTheGecko
Copy link
Contributor

Removed data_full_zdim from fieldfilebuffer and the calling code.

@VeckoTheGecko
Copy link
Contributor Author

@erikvansebille I had a questions about a failing test that I am encountering tests/test_grids.py::test_bgrid_interpolation[*-mom5], namely that it's not finding the sw_ocean variable in the datasets as requested by the dimension dict.

dimensions = {
    "U": {"lon": "xu_ocean", "lat": "yu_ocean", "depth": "sw_ocean", "time": "time"},
    "V": {"lon": "xu_ocean", "lat": "yu_ocean", "depth": "sw_ocean", "time": "time"},
    "W": {"lon": "xu_ocean", "lat": "yu_ocean", "depth": "sw_ocean", "time": "time"},
}

Looking at each of the datasets, it is true that there isn't a sw_ocean for the U and V files (but is an st_ocean variable).

(Pdb) xr.open_mfdataset(ufile)
<xarray.Dataset> Size: 4kB
Dimensions:      (st_ocean: 4, time: 3, nv: 2, yu_ocean: 8, xu_ocean: 11)
Coordinates:
  * st_ocean     (st_ocean) float64 32B 0.5413 1.681 2.94 4.332
  * time         (time) object 24B 1950-01-01 12:00:00 ... 1950-01-03 12:00:00
  * xu_ocean     (xu_ocean) float64 88B -247.4 -247.3 -247.2 ... -246.5 -246.4
  * yu_ocean     (yu_ocean) float64 64B -64.27 -64.22 -64.18 ... -64.0 -63.96
Dimensions without coordinates: nv
Data variables:
    time_bounds  (time, nv) timedelta64[ns] 48B dask.array<chunksize=(3, 2), meta=np.ndarray>
    u            (time, st_ocean, yu_ocean, xu_ocean) float32 4kB dask.array<chunksize=(1, 4, 8, 11), meta=np.ndarray>
Attributes:
    filename:   ocean_daily_3d_u.nc
    title:      ACCESS-OM2-01
    grid_type:  mosaic
    grid_tile:  1
    history:    Thu Oct  8 09:46:23 2020: ncks -d st_ocean,0,3 -d yu_ocean,39...
    NCO:        netCDF Operators version 4.8.1 (Homepage = http://nco.sf.net,...


(Pdb) xr.open_mfdataset(vfile)
<xarray.Dataset> Size: 4kB
Dimensions:      (st_ocean: 4, time: 3, nv: 2, yu_ocean: 8, xu_ocean: 11)
Coordinates:
  * st_ocean     (st_ocean) float64 32B 0.5413 1.681 2.94 4.332
  * time         (time) object 24B 1950-01-01 12:00:00 ... 1950-01-03 12:00:00
  * xu_ocean     (xu_ocean) float64 88B -247.4 -247.3 -247.2 ... -246.5 -246.4
  * yu_ocean     (yu_ocean) float64 64B -64.27 -64.22 -64.18 ... -64.0 -63.96
Dimensions without coordinates: nv
Data variables:
    time_bounds  (time, nv) timedelta64[ns] 48B dask.array<chunksize=(3, 2), meta=np.ndarray>
    v            (time, st_ocean, yu_ocean, xu_ocean) float32 4kB dask.array<chunksize=(1, 4, 8, 11), meta=np.ndarray>
Attributes:
    filename:   ocean_daily_3d_v.nc
    title:      ACCESS-OM2-01
    grid_type:  mosaic
    grid_tile:  1
    history:    Thu Oct  8 09:47:11 2020: ncks -d st_ocean,0,3 -d yu_ocean,39...
    NCO:        netCDF Operators version 4.8.1 (Homepage = http://nco.sf.net,...


(Pdb) xr.open_mfdataset(wfile)
<xarray.Dataset> Size: 4kB
Dimensions:      (sw_ocean: 4, time: 3, nv: 2, yt_ocean: 8, xt_ocean: 11)
Coordinates:
  * sw_ocean     (sw_ocean) float64 32B 1.083 2.279 3.601 5.062
  * time         (time) object 24B 1950-01-01 12:00:00 ... 1950-01-03 12:00:00
  * xt_ocean     (xt_ocean) float64 88B -247.4 -247.3 -247.2 ... -246.5 -246.4
  * yt_ocean     (yt_ocean) float64 64B -64.29 -64.24 -64.2 ... -64.03 -63.98
Dimensions without coordinates: nv
Data variables:
    time_bounds  (time, nv) timedelta64[ns] 48B dask.array<chunksize=(3, 2), meta=np.ndarray>
    wt           (time, sw_ocean, yt_ocean, xt_ocean) float32 4kB dask.array<chunksize=(1, 4, 8, 11), meta=np.ndarray>
Attributes:
    filename:   ocean_daily_3d_wt.nc
    title:      ACCESS-OM2-01
    grid_type:  mosaic
    grid_tile:  1
    history:    Thu Oct  8 09:47:47 2020: ncks -d sw_ocean,0,3 -d yt_ocean,39...
    NCO:        netCDF Operators version 4.8.1 (Homepage = http://nco.sf.net,...
(Pdb) 

Updating the dim dict to use st_ocean instead of sw_ocean for U and V gives:

        if "U" in dimensions and "W" in dimensions and dimensions["U"] != dimensions["W"]:
>           raise ValueError(
                "On a B-grid, the dimensions of velocities should be the (top) corners of the grid cells, so the same for U, V and W. "
                "See also https://docs.oceanparcels.org/en/latest/examples/documentation_indexing.html"
            )
E           ValueError: On a B-grid, the dimensions of velocities should be the (top) corners of the grid cells, so the same for U, V and W. See also https://docs.oceanparcels.org/en/latest/examples/documentation_indexing.html

parcels/fieldset.py:873: ValueError

Disabling for now, but just wondering if you can provide additional insight here?

@erikvansebille
Copy link
Member

Yes, exactly! This is essentially the same argument that we use in the C-grid interpolation: the Parcels B-grid interpolation scheme expects the grid point on the w-level. And that is only available in the W field. This is exactly why we need to be very careful on how we construct the new grid in v4

@VeckoTheGecko
Copy link
Contributor Author

I see. There is also a breakage in tutorial_nemo_3D.ipynb related to how the depth dimension is handled. Should we disable the notebook for now until we clarify and implement how we're going to ingest grids in v4 then we can re-enable?

@VeckoTheGecko VeckoTheGecko force-pushed the 1844-data-full-zdim branch 2 times, most recently from 9b997d6 to d10d25a Compare March 13, 2025 13:17
@VeckoTheGecko VeckoTheGecko enabled auto-merge March 13, 2025 13:56
@VeckoTheGecko VeckoTheGecko merged commit 6c5f89e into v4-dev Mar 13, 2025
16 checks passed
@VeckoTheGecko VeckoTheGecko deleted the 1844-data-full-zdim branch March 13, 2025 14:22
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants