OpenDrift / opendrift

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

reader_netCDF_CF_unstructured.Reader AssertionError: Only cartesian coordinate systems supported #547

Closed Boorhin closed 3 years ago

Boorhin commented 3 years ago

I am trying to read some FVCOM files from the Scottish Shelf Water netcdf files. I edit the x and y to UTM30 in the file as I am not sure what parameters the proj4 can take (could be good to indicate in the doc or to use crs codes and pyproj under the hood) but I get the error that only cartesian coordinates are supported although x and y are UTM30

proj = "+proj=utm +zone=30W, +north +ellps=WGS84 +datum=WGS84 +units=m +no_defs"
fvcom = reader_netCDF_CF_unstructured.Reader(filename = '/home/julien/DATA/Marine plastics/PlasticsATBay/Simulations/oceano/NW_Scot/SSWRS_V1_NOC_FVCOM_NWEuropeanShelf_01dy_19930101-1200_RE.nc', proj4 = proj)
16:32:11 INFO    opendrift.readers.reader_netCDF_CF_unstructured: Opening dataset: /home/julien/DATA/Marine plastics/PlasticsATBay/Simulations/oceano/NW_Scot/SSWRS_V1_NOC_FVCOM_NWEuropeanShelf_01dy_19930101-1200_RE.nc
16:32:11 INFO    opendrift.readers.reader_netCDF_CF_unstructured: Opening file with Dataset
16:32:11 INFO    opendrift.readers.reader_netCDF_CF_unstructured: Using custom projection: +proj=utm +zone=30W, +north +ellps=WGS84 +datum=WGS84 +units=m +no_defs..
16:32:11 INFO    opendrift.readers.reader_netCDF_CF_unstructured: Reading grid and coordinate variables..
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-18-7d6524d294d7> in <module>
----> 1 fvcom = reader_netCDF_CF_unstructured.Reader(filename = '/home/julien/DATA/Marine plastics/PlasticsATBay/Simulations/oceano/NW_Scot/SSWRS_V1_NOC_FVCOM_NWEuropeanShelf_01dy_19930101-1200_RE.nc', proj4 = proj)

~/Software/source/opendrift/opendrift/readers/reader_netCDF_CF_unstructured.py in __init__(self, filename, name, proj4)
    115 
    116         logger.info('Reading grid and coordinate variables..')
--> 117         assert self.dataset.CoordinateSystem == "Cartesian", "Only cartesian coordinate systems supported"
    118 
    119         self.x = self.dataset['x'][:]

AssertionError: Only cartesian coordinate systems supported
gauteh commented 3 years ago

It seems that it is quite different what type of attributes are set by different runs of FVCOM. As long as the grid is projected, and you know which projection it is (i.e. x and y are 1d-variables and proj is correct) this check/assertion should be safe to remove.

Boorhin commented 3 years ago

Is that information I should have added into the nc file? Could you tell me what is expected? I would not be surprised there are errors in it

gauteh commented 3 years ago

Upon checking http://fvcom.smast.umassd.edu/fvcom/:

The present version of FVCOM includes a number of options and components as shown in Figure above. These include (1) choice of Cartesian or spherical coordinate system

I think that my first comment was incorrect. The FVCOM reader has only been developed for cartesian coordinates.. But if this only refers to the simulation system, and not the coordinates of the FVCOM-output files this might be irrelevant. Perhaps the attribute is missing for FVCOM versions prior to the spherical coordinate system support. In short, as long as the output points are in a regular coordinate system on the projected grid - and those variables are given in meters (most likely) you should be fine without this check. Do you have the chance to try? Please let me know how it works out.

Boorhin commented 3 years ago

I have had some success by removing the cartesian coordinate test Still running into small errors, I am building a nc file from scratch to see what works and what doesn't

Boorhin commented 3 years ago

Is there someone I could directly communicate with that can inform me on how the netcdf4/FVCOM filter is made and what is expected? I have made a python tool to write such files but since there has been quite a lot of evolution in the standards, I am not too sure I am doing the right thing.

gauteh commented 3 years ago

I thought FVCOM wrote nc files? Do you construct them from another model?

Boorhin commented 3 years ago

I am using Telemac to make the models and I am converting the files into a "FVCOM" format. Most of their website is not working or inactive. Telemac is pretty popular in hydrodynamic and has particle tracking. However the tracking is not as good as in Opendrift so it seems. I mean if I get instructions on what is needed in Opendrift for unstructured grids, I can also make the filter straight from Telemac to Opendrift