NOAA-ORR-ERD / gridded

A single API for accessing / working with gridded model results on multiple grid types
https://noaa-orr-erd.github.io/gridded/index.html
The Unlicense
64 stars 14 forks source link

Hard crash on ROMS raw output file #79

Open knutfrode opened 11 months ago

knutfrode commented 11 months ago

When trying to use the at-method with the script/dataset bwlow, it crashes with the following error message:

/home/knutfd/miniconda3/envs/opendrift/lib/python3.11/site-packages/gridded/pysgrid/sgrid.py:272: UserWarning: Assuming low padding for faces
  warnings.warn('Assuming low padding for faces')
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 4) >= this->size() (which is 4)
Aborted (core dumped)
import gridded

# https://github.com/OpenDrift/opendrift/blob/master/tests/test_data/2Feb2016_Nordic_sigma_3d/Nordic-4km_SLEVELS_avg_00_subset2Feb2016.nc
f = '/home/knutfd/software/opendrift/tests/test_data/2Feb2016_Nordic_sigma_3d/Nordic-4km_SLEVELS_avg_00_subset2Feb2016.nc'
ds = gridded.Dataset(f)

temp = ds['temp']
p = [[14.2, 68, 0]]
t = temp.time.data[0]
print(t)
temp.at(points=p, time=t)
ChrisBarker-NOAA commented 11 months ago

@jay-hennen: I looked quickly at this, but haven't figure it out.

I suspect the hard crash is from CellTree2d -- where else would it be? So there is something wrong with this grid that celltree doesn't like.

IIUC, this file was processed from ROMS -- and I think the rho grid and psi grid may have gotten a bit changed -- e.g. they are the same size, which I don't think is usually the case. That may be the source of the warning: 'Assuming low padding for faces'

But it should never hard crash, and I think this should probably work, if being odd at thr boundaries.

jay-hennen commented 11 months ago

Yes, it's from CellTree2D

After peeking in, the problem is that lon_psi and lat_psi are both full of zeros. lon_rho and lat_rho seem to have valid data, but the CellTree is built across the psi grid.

(Pdb) self.data._grp['lon_psi'][:]
masked_array(
  data=[[0, 0, 0, ..., 0, 0, 0],
        [0, 0, 0, ..., 0, 0, 0],
        [0, 0, 0, ..., 0, 0, 0],
        ...,
        [0, 0, 0, ..., 0, 0, 0],
        [0, 0, 0, ..., 0, 0, 0],
        [0, 0, 0, ..., 0, 0, 0]],
  mask=False,
  fill_value=999999,
  dtype=int16)
ChrisBarker-NOAA commented 6 months ago

Hmm -- is it worth a sanity check on grid definitions before calling cell_tree?

Not sure how expensive that would be -- but at least a couple things would be good.