OpenDrift / opendrift

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

Error reading FVCOM file #126

Closed AndresSepulveda closed 3 years ago

AndresSepulveda commented 5 years ago

Hi,

I want to use an FVCOM file do lagrangian analysis. My .py reads it with the following commands:

from opendrift .readers import reader_basemap_landmask from opendrift .readers import reader_netCDF_CF_generic from opendrift .models .oceandrift import OceanDrift

o =OceanDrift (loglevel =0 )# Set loglevel to 0 for debug information

filename_nc ='../.././FVCOM/seleccion_fecha_de_datos/MESO0001/Mesoescala_0001.nc'

loco_native =reader_netCDF_CF_generic .Reader (filename_nc )

but it crashes with the following errors. Any clue on what is missing? Attached is the full log and the ncdump from the file being used.

Thanks...

16:33:23 DEBUG: Parsing variable: wet_cells_prev_ext /home/mosa/new_opendrift/opendrift/opendrift/readers/reader_netCDF_CF_generic.py:199: RuntimeWarning: invalid value encountered i n float_scalars rel_delta_x.min())/self.delta_x) /home/mosa/new_opendrift/opendrift/opendrift/readers/reader_netCDF_CF_generic.py:202: RuntimeWarning: invalid value encountered in float_scalars rel_delta_y.min())/self.delta_y) 16:33:23 DEBUG: Lon and lat are 1D arrays, assuming latong projection /home/mosa/new_opendrift/opendrift/opendrift/readers/basereader.py:194: RuntimeWarning: invalid value encountered in float_scalars numx = (self.xmax - self.xmin)/self.delta_x + 1 /home/mosa/new_opendrift/opendrift/opendrift/readers/basereader.py:195: RuntimeWarning: invalid value encountered in float_scalars numy = (self.ymax - self.ymin)/self.delta_y + 1 /home/mosa/new_opendrift/opendrift/opendrift/readers/basereader.py:231: RuntimeWarning: divide by zero encountered in double_scalars pixelsize)) + 2 Traceback (most recent call last): File "/var/www/html/FVCOM/www_data/simulations/2019-08-08_16-33-11_964118/2019-08-08_16-33-11_964118.py", line 26, in loco_native =reader_netCDF_CF_generic .Reader (filename_nc )#,gridfile='/var/www/html/Loco/3SE/croco_grd.nc') File "/home/mosa/new_opendrift/opendrift/opendrift/readers/reader_netCDF_CF_generic.py", line 254, in init super(Reader, self).init() File "/home/mosa/new_opendrift/opendrift/opendrift/readers/basereader.py", line 200, in init self.set_buffer_size(max_speed=5) # To be overriden by user/model File "/home/mosa/new_opendrift/opendrift/opendrift/readers/basereader.py", line 231, in set_buffer_size pixelsize)) + 2 OverflowError: cannot convert float infinity to integer

fvcom.ncdump.txt 2019-08-08_16-33-11_964118.txt

knutfrode commented 5 years ago

This file is not on a regular grid (with fixed deltax and deltay), but rather on a triangular, unstructured grid. You have to use another reader for this kind of files, try with either: https://github.com/OpenDrift/opendrift/blob/master/opendrift/readers/reader_FVCOM.py or https://github.com/OpenDrift/opendrift/blob/master/opendrift/readers/reader_netCDF_CF_unstructured.py

These readers (two slightly different variants of the same) are less developed and robst than the regular netCDF-reader, so you might need to do some minor edits to get it working.

AndresSepulveda commented 5 years ago

Sorry, my bad. I didn't saved the .py file and it used the reader for ROMS.

Now, the reader_netCDF_CF_unstructured.py works fine, but the FVCOM results are in UTM coordinates (easting, norting) and as such, OpenDrift finds that all particles are outside the domain.

How can I configure it so it can convert (using proj?) between lat/lon and proj?

knutfrode commented 5 years ago

But according to your ncdump above, the file contains arrays of lon ant lat, and then these should used as coordinates? I don't find anything about UTM in the ncdump output? Can you post the output of >>> print <reader>

AndresSepulveda commented 5 years ago

Indeed, there are lan and lon variables in the file but they are empty (all values equal 0)! Seems the file description is inconsistent, as in the global attributes it says

           :CoordinateSystem = "Cartesian" ;
            :CoordinateProjection = "none" ;

Could it be possible to tell the reader to read x and y, and convert with pyproj to lat and lon?

Here is the output from print

Reader: /var/www/html/FVCOM/FVCOM/seleccion_fecha_de_datos/MESO0001/Mesoescala_0001.nc Projection: +proj=latlong Coverage: [degrees] xmin: 0.000000 xmax: 0.000000 ymin: 0.000000 ymax: 0.000000 Corners (lon, lat): ( 0.00, 0.00) ( 0.00, 0.00) ( 0.00, 0.00) ( 0.00, 0.00) Vertical levels [m]: Not specified Available time range: start: 2009-12-01 00:00:00 end: 2009-12-30 23:00:00.054932 step: 1:00:00.000107 719 times (0 missing) Variables: ocean_sigma/general_coordinate y_sea_water_velocity longitude sea_floor_depth_below_geoid sea_surface_height_above_geoid sea_water_salinity x_sea_water_velocity latitude sea_water_temperature

AndresSepulveda commented 5 years ago

Well, we have a patch for the problem. Thanks to the work of @DanielBrieva who created this script to fill the lat/lon, latc/lonc arrays in the file

FVCOM_LOCO

AndresSepulveda commented 5 years ago

Sorry, I forgot to attach the file

fill_latlon_FVCOM.py.txt

gauteh commented 3 years ago

Think this will be handled in #243