OpenDrift / opendrift

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

Question: Can PelagicEgg Drift use nc file as input data? #1240

Closed helena2281 closed 2 months ago

helena2281 commented 4 months ago

There was a problem with using the Pelagicegg drift. I want to use the nc file as a result of fvcom, but the results of the pelagic egg drift model found that none of the variables inside the nc file were read. When the same file was used in PlastDrift, it was simulated without any problems. Can't Pelagicegg drift use nc files? It can use only ncml file?

My Current code is as follows:

from opendrift.readers import reader_netCDF_CF_unstructured from opendrift.readers import reader_netCDF_CF_generic from opendrift.models.pelagicegg import PelagicEggDrift from datetime import datetime, timedelta

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

reader1=reader_netCDF_CF_unstructured.Reader(filename='/home/hwdo/models/03__OpenDrift/opendrift/examples/Base_04_0002_copy.nc') o.add_reader(reader1)

o.set_config('drift:vertical_mixing', True) o.set_config('vertical_mixing:diffusivitymodel', 'windspeed_Sundby1983') # windspeed parameterization for eddy diffusivity

o.set_config('vertical_mixing:timestep', 60.) # seconds

time=reader1.start_time o.seed_elements(126.51027, 37.7983,radius=1,number=10,time=time,diameter=0.0014,neutral_buoyancy_salinity=31.25)

Running model

ncfile='example_codegg_fvcom.nc' o.run(duration=timedelta(hours=48), time_step=3600,outfile=ncfile)

Print and plot results.

At the end the wind vanishes, and eggs come to surface

print(o)


and PelagicEgg result (entire result is in the attached file) :

Model: PelagicEggDrift (OpenDrift version 1.11.0) 10 active PelagicEgg particles (0 deactivated, 0 scheduled)

Environment variables:

land_binary_mask 1) global_landmask

Readers not added for the following variables: ocean_mixed_layer_thickness ocean_vertical_diffusivity sea_floor_depth_below_sea_level sea_ice_area_fraction sea_surface_wave_significant_height sea_water_salinity sea_water_temperature surface_downward_x_stress surface_downward_y_stress turbulent_generic_length_scale turbulent_kinetic_energy upward_sea_water_velocity x_sea_water_velocity x_wind y_sea_water_velocity y_wind

Discarded readers: /home/hwdo/models/03__OpenDrift/opendrift/examples/Base_04_0002_copy.nc (failed more than 1 times)

Time: Start: 2020-01-21 00:00:00 UTC Present: 2020-01-23 00:00:00 UTC Calculation steps: 48 1:00:00 - total time: 2 days, 0:00:00 Output steps: 49 1:00:00

pelagicegg drift log.txt

knutfrode commented 4 months ago

Hi, there is an error message in the log

  File "/home/hwdo/opendrift/opendrift/readers/reader_netCDF_CF_unstructured.py", line 273, in get_variables
    assert (len(node_variables) + len(face_variables)

Thus might be a problem with some or one of the variables? Is it possible to make available a small version of such an FVCOM-file, or the output from ncdump ?

I generally recommend using loglevel=0, then you will get a more detailed log, that could indicate why it does not work.

helena2281 commented 3 months ago

First of all, I solved the 'missing variables requested' error by removing some of the variables in my nc file. But now I have a problem that the flow rate is read, but the water temperature and salt in the file are not read. The nc file I have is the result file of fvcom, and the standard name is saved as sea_water_salinity, sea_water_temperature. When I opened the PelagicEgg code, I checked that the water temperature and salt part of the variable names required are sea_water_salinity and sea_water_temperature. Isn't the reader_netCDF_CF_unstructured code reading the file based on the standard name of the nc file? I thought it matched the request, but I'm not sure where the problem occurred.

fvcom salinity std name

The picture above shows the attributes for the salinity variable in the fvcom nc file I used. Salinity and temperature are not 0. I want to use salinity even if I can’t use temperature value.

knutfrode commented 3 months ago

Yes, the unstructured reader (first developed for FVCOM files) is supposed to detect variables having a standard_name attribute: https://github.com/OpenDrift/opendrift/blob/master/opendrift/readers/reader_netCDF_CF_unstructured.py#L159

However, there might still be issues related to whether this should be a node- or face variables. I am normally not using FVCOM myself, so have little experience with it. If you look carefully at the log (or insert debug printouts in the reader), you might see at which line in the reader an error might occur. But I believe there are more sophisticated versions of this reader around, perhaps e.g. @poplarShift has made some improvements of general interest?

(Also, there are unstructured readers for SCHISM, TELEMAC and SHYFEM. One long-term goal might be that the generic unstructured reader can read all these models.)