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

Using Barents 2.5 EPS with OpenDrift #1129

Closed nordam closed 6 months ago

nordam commented 1 year ago

I'm trying to run a small test with OpenDrift and the Barents EPS with files from thredds, but I run into some problems.

The files are downloaded from here: https://thredds.met.no/thredds/catalog/fou-hi/barents_eps_eps/catalog.html

My example is:

filenames = [
    '../data/barents_eps_20230604T18Z.nc',
    '../data/barents_eps_20230605T18Z.nc',
    '../data/barents_eps_20230606T18Z.nc',
]

o = PlastDrift(loglevel=0)

reader_barents = reader_netCDF_CF_generic.Reader(filenames)
o.add_reader([reader_barents])

start_time = reader_barents.start_time
end_time = reader_barents.end_time
time = [start_time, end_time]

lon = 10.0; lat = 70.0
o.seed_elements(lon, lat, radius=50, number=3000, time=time)
o.run(end_time=end_time, time_step=1800, time_step_output=3600)

The first issue is with creating the reader. I get the error message

ValueError: conflicting values for variable 'forecast_reference_time' on objects to be combined. You can skip this check by specifying compat='override'.

I assume this is because these files contain partially overlapping times? I tried passing the suggested keyword argument to Reader(filenames, compat='override'), but that gives another error, so I assume the compat argument isn't passed on to the correct location in the code. I could perhaps try to submit a pull request for that.

The second issue is that when I try again with only a single file, the simulation runs with no errors, but the particles don't move, they just remain in the same location. Could it be that OpenDrift isn't correctly identifying the u and v variables, since they are called u_eastward and v_northward in this dataset?

gauteh commented 1 year ago

For the first error: You could open the list of files using xarray manually and pass the ready Dataset to the Reader (https://github.com/OpenDrift/opendrift/blob/master/opendrift/readers/reader_netCDF_CF_generic.py#L70), but there could also be a good reason for the conflict (e.g. overlapping time coordinates).

knutfrode commented 1 year ago

Hi, Can you try to remove the overlapping part of the files, i.e. keep only first 23 hours from each daily file?

I am not sure whether the compat argument could make it work even with overlapping files? But as Gaute mentioned, it might be better in this case to open and provide an Xarray dataset directly to the Reader constructor.

gauteh commented 1 year ago

@knutfrode has a good example of how to do that here: https://github.com/knutfrode/concepts/blob/main/Open_MFDataset_overlap.ipynb

nordam commented 1 year ago

Many thanks, very helpful example, this solved the first problem perfectly. But the second issue is still there: The particles do not move.

knutfrode commented 1 year ago

If you use loglevel=0 the log should tell why they are not moving. Perhaps out of coverage? Variables names do not matter, OpenDrift scans only for attribute standard_name, so current should be identified here.

vic1309 commented 1 year ago

Hei all,

I am having a similar issue that @nordam was (is?) facing. I used the example that @gauteh provided, and I am trying to open the concatenated dataset with reader_netCDF_CF_generic.Reader. I get the following error:

ValueError: did not find a match in any of xarray's currently installed IO backends ['netcdf4', 'scipy', 'cfgrib']. Consider explicitly selecting one of the installed engines via the ``engine`` parameter, or installing additional IO dependencies, see:

https://docs.xarray.dev/en/stable/getting-started-guide/installing.html https://docs.xarray.dev/en/stable/user-guide/io.html

Though I do have the IO backends installed. Did you figure out the problem?

knutfrode commented 1 year ago

Hi Senhor vic1309!

I have seen your error message before, and I believe it is related to some problem/shortcoming with the installation, and (probably) not related the issue above. The example script above (Open_MFDataset_overlap.ipynb) works fine for me, does it work for you as is?

Did you install OpenDrift the "standard" way? https://opendrift.github.io/install.html

vic1309 commented 1 year ago

Hei herr knutfrode!

Yes, the script above worked like a charm! I noticed my OpenDrift version was out-of-date, it is working now.

Many thanks!