OpenDrift / opendrift

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

'fcntl' error using opendrift on windows #303

Closed HugoDENISFR closed 4 years ago

HugoDENISFR commented 4 years ago

Hello,

Thanks a lot for your tremendous work and available documentation ! I am trying to use opendrift for the first time with a ROMS test file. I think I managed to get the first steps okay following the exemple shown in the gallery but when I run the reader using :

o.run(time_step=7200,duration=delta(days=15),outfile='traj_test_opendrift.nc',time_step_output=21600)

I get the following error

`17:06:46 DEBUG: Adding new variable mappings ERROR:root:fcntl not available on this platform, concurrent generations of landmask (different threads or processes) might cause failing landmask generation. Make sure only one instance of landmask is running on the system the first time. ERROR:root:failed to generate landmask Traceback (most recent call last): File "C:\Users\Hugo\Anaconda3\envs\opendrift\lib\site-packages\opendrift_landmask_data-0.3-py3.8.egg\opendrift_landmask_data\mask.py", line 102, in generate import fcntl ModuleNotFoundError: No module named 'fcntl'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Users\Hugo\Anaconda3\envs\opendrift\lib\site-packages\opendrift_landmask_data-0.3-py3.8.egg\opendrift_landmask_data\mask.py", line 88, in __generate_impl__ os.rename(fd.name, self.mmapf) PermissionError: [WinError 32] Le processus ne peut pas accéder au fichier car ce fichier est utilisé par un autre processus: 'C:\Users\Hugo\AppData\Local\Temp\landmask\tmpq0q9y4jj' -> 'C:\Users\Hugo\AppData\Local\Temp\landmask\mask.dat' Traceback (most recent call last):`

I am a bit confused given that 'fcntl' doesn't exist in Windows, but I suppose the real error is the second one. I tried to close my IDE and everything that could use the file and try to reboot but without success..

Help would be highly appreciated !

Thanks in advance,

Hugo

gauteh commented 4 years ago

Hi, you are right. The first is a warning that we do not check if you have started several opendrift instances at the same time - the first time you start opendrift. This message will disappear. I have just uploaded some new packages with what I hope is a fix, could you please try to update opendrift and opendrift-landmask-data and see if the error persists?

HugoDENISFR commented 4 years ago

I don't obtain the error anymore so it looks like the issue was resolved. Thanks a lot !

Now I just have another issue that is probably unrelated : My particles aren't advected on the velocity field and stay at the same coordinates during the whole simulation.

I assume it has something to do with the way time is managed in opendrift. In fact the time of my ROMS dataset have (2000,1,1,0,0,0) as reference. I tried to use the argument .start_time when seeding elements but I end up with time values in the output file of the simulation totally different from those of the ROMS file.

So what is the reference date used in OpenDrift ?

Thanks in advance,

Hugo

knutfrode commented 4 years ago

Can you please report the output from:

>>> from opendrift.readers.reader_ROMS_native import Reader
>>> r = Reader(<your ROMS file>)
>>> print(r)
HugoDENISFR commented 4 years ago

Sure : print(roms_file)

Reader: roms native Projection: None Coverage: [pixels] xmin: 0.000000 xmax: 24.000000 step: 1 numx: 25 ymin: 0.000000 ymax: 36.000000 step: 1 numy: 37 Corners (lon, lat): ( 15.00, -29.95) ( 19.00, -29.95) ( 15.00, -35.00) ( 19.00, -35.00) Vertical levels [m]: Not specified Available time range: start: 2000-05-01 12:00:00 end: 2000-05-28 12:00:00 step: 3 days, 0:00:00 10 times (0 missing) Variables: sea_floor_depth_below_sea_level land_binary_mask sea_water_salinity sea_water_temperature x_sea_water_velocity y_sea_water_velocity sea_surface_height

    ` 0  total

0:00:00.7 preparing 0 reading`

knutfrode commented 4 years ago

The times here seem correct? Vertical levels are not specified, does this mean that your file is 2D (just single level)?

Could you also paste your example which is not working, and where you apply this reader? Seeding should work with:

>>> o.seed_elements(lon, lat, time=roms_file.start_time)
HugoDENISFR commented 4 years ago

Yes the time looks correct. No actually, I just noticed with this command that no level were included :

Here are the variables from the roms file I am using ( its a toy model), as you can see the variable 'h' specifies depth at rho points :

{'h': <class 'netCDF4._netCDF4.Variable'> float32 h(eta_rho, xi_rho) unlimited dimensions: current shape = (37, 25) filling on, default _FillValue of 9.969209968386869e+36 used, 'lat_rho': <class 'netCDF4._netCDF4.Variable'> float32 lat_rho(eta_rho, xi_rho) unlimited dimensions: current shape = (37, 25) filling on, default _FillValue of 9.969209968386869e+36 used, 'lon_rho': <class 'netCDF4._netCDF4.Variable'> float32 lon_rho(eta_rho, xi_rho) unlimited dimensions: current shape = (37, 25) filling on, default _FillValue of 9.969209968386869e+36 used, 'mask_rho': <class 'netCDF4._netCDF4.Variable'> float32 mask_rho(eta_rho, xi_rho) unlimited dimensions: current shape = (37, 25) filling on, default _FillValue of 9.969209968386869e+36 used, 'pm': <class 'netCDF4._netCDF4.Variable'> float32 pm(eta_rho, xi_rho) unlimited dimensions: current shape = (37, 25) filling on, default _FillValue of 9.969209968386869e+36 used, 'pn': <class 'netCDF4._netCDF4.Variable'> float32 pn(eta_rho, xi_rho) unlimited dimensions: current shape = (37, 25) filling on, default _FillValue of 9.969209968386869e+36 used, 'salt': <class 'netCDF4._netCDF4.Variable'> float32 salt(time, s_rho, eta_rho, xi_rho) unlimited dimensions: time current shape = (10, 32, 37, 25) filling on, default _FillValue of 9.969209968386869e+36 used, 'time': <class 'netCDF4._netCDF4.Variable'> float32 time(time) units: seconds since 2000-01-01 00:00:00.0 unlimited dimensions: time current shape = (10,) filling on, default _FillValue of 9.969209968386869e+36 used, 'temp': <class 'netCDF4._netCDF4.Variable'> float32 temp(time, s_rho, eta_rho, xi_rho) unlimited dimensions: time current shape = (10, 32, 37, 25) filling on, default _FillValue of 9.969209968386869e+36 used, 'u': <class 'netCDF4._netCDF4.Variable'> float32 u(time, s_rho, eta_rho, xi_u) unlimited dimensions: time current shape = (10, 32, 37, 24) filling on, default _FillValue of 9.969209968386869e+36 used, 'ubar': <class 'netCDF4._netCDF4.Variable'> float32 ubar(time, eta_rho, xi_u) unlimited dimensions: time current shape = (10, 37, 24) filling on, default _FillValue of 9.969209968386869e+36 used, 'v': <class 'netCDF4._netCDF4.Variable'> float32 v(time, s_rho, eta_v, xi_rho) unlimited dimensions: time current shape = (10, 32, 36, 25) filling on, default _FillValue of 9.969209968386869e+36 used, 'vbar': <class 'netCDF4._netCDF4.Variable'> float32 vbar(time, eta_v, xi_rho) unlimited dimensions: time current shape = (10, 36, 25) filling on, default _FillValue of 9.969209968386869e+36 used, 'zeta': <class 'netCDF4._netCDF4.Variable'> float32 zeta(time, eta_rho, xi_rho) unlimited dimensions: time current shape = (10, 37, 25) filling on, default _FillValue of 9.969209968386869e+36 used}

Here are the command I used to run the simulation : init_lon, init_lat are arrays that contain initial positions of my particles.

o.seed_elements(lon=init_lon,lat=init_lat,time=roms_file.start_time) o.set_config('drift:scheme', 'runge-kutta') o.run(time_step=7200,duration=delta(days=15),outfile=path+'traj_test_opendrift.nc',time_step_output=21600)

If it is easier for you I can also send you my roms data file and python script.

knutfrode commented 4 years ago

Yes, please send me the file and script (knutfd@met.no).

knutfrode commented 4 years ago

It seems that your ROMS files misses an essential variable: the angle between the x-direction (eta) and east. Without this one it is not possible to orientate vectors (i.e. currents).

HugoDENISFR commented 4 years ago

I see, this is a toy model that comes with another lagrangian model (Ichthyop) and we would like to compare outputs of both models. This is why I was first trying to run simple tests on this dataset.

For instance on the example '2Feb2016_Nordic_sigma_3d/Nordic-4km_SLEVELS_avg_00_subset2Feb2016.nc' that comes with the tutorial, to which variable does this corresponds ?

knutfrode commented 4 years ago
$ ncdump -h Nordic-4km_SLEVELS_avg_00_subset2Feb2016.nc | grep -i angle

short angle(eta_rho, xi_rho) ;
        angle:long_name = "angle between XI-axis and EAST" ;
        angle:units = "radians" ;
        angle:coordinates = "lon_rho lat_rho" ;
        angle:field = "angle, scalar" ;
        angle:scale_factor = -4.42241597130484e-06 ;
        angle:add_offset = 0.77288618683815 ;
HugoDENISFR commented 4 years ago

Thanks a lot, I'll try to compute it myself then.

knutfrode commented 4 years ago

I believe this should be standard output from ROMS, but perhaps not from your toy version(?)

gauteh commented 4 years ago

Hi, was this issue resolved?

HugoDENISFR commented 4 years ago

Hi, considering the variable was missing which is indeed not common with new format of ROMS file we decided to change for a more up to date dataset and I was able to implement everything without particular issues. Thanks a lot !

gauteh commented 4 years ago

Great!