OpenDrift / opendrift

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

Transitioning from one monthly ROMS input file to the next #999

Closed GilesFearon closed 1 year ago

GilesFearon commented 1 year ago

Hi All

I am playing around with using ROMS input files which are stored monthly. As my OpenDrift simulations can span multiple months, I am adding the required ROMS input files as separate readers i.e. one reader per calendar month. I encounter a problem when transitioning from one month to the next, when the time in the OpenDrift simulation is not actually covered by either file i.e. the last date of one file might be 2005-01-31 00:00:00 and the first time-step of the next file would be 2005-02-01 00:00:00, so neither reader covers the time between these two files, and so OpenDrift terminates at 2005-01-31 00:00:00.

I am presently getting around this by using netcdf operators to add the first time-step of the each file to the end of the file for the previous month. This solves my problem, but I was wondering if there is another way around the problem without having to edit the input files? There are probably others out there who have tried to run simulations using multiple monthly ROMS input files?

Thanks in advance! Giles

knutfrode commented 1 year ago

Hi,

You should here rather make a single reader with wildcards in the filename, e.g.:

r = reader_ROMS_native.Reader('/somepath*/filename*.nc')

The reader will the user MFDataset, with no holes between the individual files. The generic reader also supports MFDataset when wildcards are used.

GilesFearon commented 1 year ago

That simplifies things, thanks!

It unfortunately didn't work for me 'out the box' as my time variable is called 'time' (the files are generated using CROCO, built on ROMS_AGRIF) while the part of the code where the files are opened with MFDataset assumes the time dimension is called 'ocean_time'. Changing this in the code makes it work perfectly for me, and even seems to run faster than when I was using separate readers :)

I see later in the code when the time data is read there is a try/except in case the time variable is called 'time' instead of 'ocean_time'. Could be an idea to also do the same some sort of check when opening with MFDataset?

Thanks again, this really helped me out