OpenDrift / opendrift

Open source framework for ocean trajectory modelling
https://opendrift.github.io
GNU General Public License v2.0
247 stars 120 forks source link

Reader's data does not match provided data #1137

Closed chironbang closed 1 year ago

chironbang commented 1 year ago

Hello,

I am trying to generate virtual drifters by providing a velocity field (I used MITgcm from UC San Diego ). I exported the data, and when plotting the velocity vectors along a drifter's trajectory, they seem to make sense (the velocity vector is tangent to the trajectory). Nevertheless, I noticed that the data from the reader extracted using the method get_timeseries_at_position do not match the actual velocity field. I queried the eastward velocity at an existing location (so I guess interpolation is not the issue here).

The reader class I used is reader_netCDF_CF_generic.Reader. I used netCDF4 and Pandas to load, create then extract the time series at that location to compare with what get_timeseries_at_position gave me.

My code is adapted from the Drifter tutorial available on the OpenDrift website.

The only velocity I loaded are eastward and northward (no wind data provided). And the reader printout is:

Reader: ../data/num_models_data/MIT_data.nc
Projection: 
  +proj=latlong
Coverage: [degrees]
  xmin: -98.000000   xmax: -72.400000   step: 0.04   numx: 640
  ymin: 8.500000   ymax: 30.900000   step: 0.04   numy: 561
  Corners (lon, lat):
    (-98.00,  30.90)  (-72.40,  30.90)
    (-98.00,   8.50)  (-72.40,   8.50)
Vertical levels [m]: 
  Not specified
Available time range:
  start: 2015-01-01 00:00:00   end: 2015-12-31 00:00:00   step: 1 day, 0:00:00
    365 times (0 missing)
Variables:
  eastward_sea_water_velocity
  northward_sea_water_velocity
  x_sea_water_velocity
  y_sea_water_velocity
===========================

Any insight would be appreciated.

By the way, thank you for the library, it is really helpful.

Chiron

knutfrode commented 1 year ago

Hi, It is not clear to me why you get a difference. Can you post your code for this comparison, so that I can try to reproduce? Though I would probably need to use another dataset unless you can also share a minimalistic file from MITgcm.

chironbang commented 1 year ago

Hi @knutfrode,

There it is (code and minimalistic data): code_and_data.zip

Thanks for your time.

knutfrode commented 1 year ago

Hi,

It turns out that the netCDF CF generic reader reads these data wrongly, as the order of dimension is lat, lon, and not lon, lat. This is not the most common, and I believe it violates the COARDS convention, but not the CF convention.

Is this raw output from the MIT model, or something that you post processed? In the latter case, a workaround could be to switch dimension, e.g. with Nco: ncpdq -a lat,lon MITgcm.nc MIT_swapped.nc

Anyway, we should try to make the netCDF_CF_generic reader more robust by handling any ordering of dimensions.

chironbang commented 1 year ago

It is not the raw output but something I post-processed. I swapped it as you suggested and it works. Thank you!