OpenDrift / opendrift

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

netCDF generic reader #745

Open daniel-i-lee opened 2 years ago

daniel-i-lee commented 2 years ago

Hello,

I am having difficulty loading a wind dataset using reader_netCDF_CF_generic. OpenDrift will add the reader but will not add the x_wind and y_wind variables. I see the issue could be due to missing projection information.

However, the file I am using is also a bit strange. I had to do some renaming of variables for it to even open with xarray or OpenDrift. This was because there were variables and coordinates sharing the same name (lat, lon).

Just wanted to confirm what the true issue is and if there is a way to fix it. Outputs are below and a sample file (after renaming) is attached.

Thank you!

13:07:02 INFO opendrift.readers.reader_netCDF_CF_generic: Opening dataset: Modified Data/Uwind_2019.nc 13:07:02 INFO opendrift.readers.reader_netCDF_CF_generic: Opening file with Dataset 13:07:02 WARNING opendrift.readers.basereader.structured: No proj string or projection could be derived, using 'fakeproj'. This assumes that the variables are structured and gridded approximately equidistantly on the surface (i.e. in meters). This must be guaranteed by the user. You can get rid of this warning by suppling a valid projection to the reader. 13:07:02 INFO opendrift.readers.basereader.structured: Making interpolator for lon,lat to x,y conversion...

Reader: Modified Data/Uwind_2019.nc Projection: None Coverage: [pixels] xmin: 0.000000 xmax: 155.000000 step: 1 numx: 156 ymin: 0.000000 ymax: 168.000000 step: 1 numy: 169 Corners (lon, lat): (146.90, -24.95) (162.40, -24.95) (146.90, -41.75) (162.40, -41.75) Vertical levels [m]: Not specified Available time range: start: None end: None step: None Variables:

Uwind_sample.zip

knutfrode commented 2 years ago

Hi,

The variables here are missing the standard_name attribute, which is key in the CF-convention. You can add this with: ncatted -a standard_name,Uwind,o,c,"x_wind" -a standard_name,longitude,o,c,"longitude" -a standard_name,latitude,o,c,"latitude" -a standard_name,wind_time,o,c,"time" Uwind_sample.nc

daniel-i-lee commented 2 years ago

Thank you, the reader is now adding the variables.

However, using o.run gives an error. Is this due to missing projection?

Reader: Modified Data/Uwind_2019_3.nc Projection: None Coverage: [pixels] xmin: 0.000000 xmax: 155.000000 step: 1 numx: 156 ymin: 0.000000 ymax: 168.000000 step: 1 numy: 169 Corners (lon, lat): (146.90, -24.95) (162.40, -24.95) (146.90, -41.75) (162.40, -41.75) Vertical levels [m]: Not specified Available time range: start: 2019-01-01 00:00:00 end: 2019-03-01 00:00:00 step: 0:59:45.937500 1422 times (5 missing) Variables: x_wind latitude longitude

16:52:45 INFO opendrift.models.basemodel: Fallback values will be used for the following variables which have no readers: 16:52:45 INFO opendrift.models.basemodel: x_sea_water_velocity: 0.000000 16:52:45 INFO opendrift.models.basemodel: y_sea_water_velocity: 0.000000 16:52:45 INFO opendrift.models.basemodel: y_wind: 0.000000 16:52:45 INFO opendrift.models.basemodel: Using existing reader for land_binary_mask 16:52:45 INFO opendrift.models.basemodel: All points are in ocean 16:52:45 INFO opendrift.models.basemodel: 2019-01-01 00:00:00 - step 1 of 52 - 10 active elements (0 deactivated) 16:52:45 INFO opendrift.models.basemodel: ======================== 16:52:45 INFO opendrift.models.basemodel: Exception: 16:52:45 INFO opendrift.models.basemodel: 'NoneType' object is not subscriptable 16:52:45 INFO opendrift.models.basemodel: ======================== 16:52:45 INFO opendrift.models.basemodel: 2019-01-01 00:30:00 - step 2 of 52 - 20 active elements (0 deactivated) 16:52:45 INFO opendrift.models.basemodel: ======================== 16:52:45 INFO opendrift.models.basemodel: Exception: 16:52:45 INFO opendrift.models.basemodel: 'NoneType' object is not subscriptable 16:52:45 INFO opendrift.models.basemodel: ========================

knutfrode commented 2 years ago

If you set loglevel to 0 (debug) the reason should become clear.