OceanParcels / Parcels

Main code for Parcels (Probably A Really Computationally Efficient Lagrangian Simulator)
https://www.oceanparcels.org
MIT License
295 stars 136 forks source link

Problem using FieldSet.from_nemo #579

Closed ana-machado closed 5 years ago

ana-machado commented 5 years ago

Hello, I am trying to run parcels with some Nemo outputs, but I am getting this error:

NotImplementedError Traceback (most recent call last)

in () 21 'W': {'lon': 'glamf', 'lat': 'gphif', 'depth': 'depthw', 'time': 'time_counter'}} 22 ---> 23 fieldset = FieldSet.from_nemo(filenames, variables, dimensions) NotImplementedError: Vertically adaptive meshes not implemented for from_netcdf() Does anyone know what's wrong? The paths are correct. This is what I was doing: from parcels import FieldSet, ParticleSet, JITParticle, AdvectionRK4_3D from glob import glob import numpy as np from datetime import timedelta as delta from os import path data_path = '...' grd_path = '...' ufiles = sorted(glob(data_path+'*U.nc')) vfiles = sorted(glob(data_path+'*V.nc')) wfiles = sorted(glob(data_path+'*W.nc')) mesh_mask = grd_path + 'MEA12_mesh_hgr.nc' filenames = {'U': {'lon': mesh_mask, 'lat': mesh_mask, 'depth': wfiles[0], 'data': ufiles}, 'V': {'lon': mesh_mask, 'lat': mesh_mask, 'depth': wfiles[0], 'data': vfiles}, 'W': {'lon': mesh_mask, 'lat': mesh_mask, 'depth': wfiles[0], 'data': wfiles}} variables = {'U': 'vozocrtx', 'V': 'vomecrty', 'W': 'vovecrtz'} dimensions = {'U': {'lon': 'glamf', 'lat': 'gphif', 'depth': 'depthw', 'time': 'time_counter'}, 'V': {'lon': 'glamf', 'lat': 'gphif', 'depth': 'depthw', 'time': 'time_counter'}, 'W': {'lon': 'glamf', 'lat': 'gphif', 'depth': 'depthw', 'time': 'time_counter'}} fieldset = FieldSet.from_nemo(filenames, variables, dimensions) Thank you very much Ana
delandmeterp commented 5 years ago

Hi Ana,

This error comes when you give a series of file for the depth dimension, since we don't support adaptive meshes in the from_nemo function. But it seems you are using one single depth file, so it shouldn't be the problem.

We were facing a similar issue in the past, that we fixed in the latest version of Parcels. Coud you check if this error still occurs with latest Parcels version?

ana-machado commented 5 years ago

Hi Philippe Thank you! That solved the problem. I have been able to run simple experiments with few particles, but now I tryed to add more particles and I got another error, can you please help me? Thank you, Ana

In [32]: pset = ParticleSet.from_line(fieldset=fieldset, pclass=JITParticle, ...: size=10000, ...: start=(-30, 46), ...: finish=(-30, 60), ...: depth=1) ...:

In [33]: pfile = ParticleFile("nemo_particles", pset, outputdt=delta(days=1)) ...: kernels = pset.Kernel(AdvectionRK4_3D) ...:

In [34]: pset.execute(kernels, runtime=delta(days=40), dt=delta(hours=6),output_file=pfile)

INFO: Compiled JITParticleAdvectionRK4_3D ==> /tmp/parcels-1000/5d703a2f588120f6901c6b823c1fe919.so 50% (1728000.0 of 3456000.0) |#################### | Elapsed Time: 0:02:54 ETA: 0:05:05--------------------------------------------------------------------------- OutOfBoundsError Traceback (most recent call last)

in ----> 1 pset.execute(kernels, runtime=delta(days=40), dt=delta(hours=6),output_file=pfile) ~/anaconda3/envs/py3_parcels/lib/python3.7/site-packages/parcels/particleset.py in execute(self, pyfunc, endtime, runtime, dt, moviedt, recovery, output_file, movie_background_field, verbose_progress) 406 else: 407 time = max(next_prelease, next_input, next_output, next_movie, endtime) --> 408 self.kernel.execute(self, endtime=time, dt=dt, recovery=recovery, output_file=output_file) 409 if abs(time-next_prelease) < tol: 410 pset_new = ParticleSet(fieldset=self.fieldset, time=time, lon=self.repeatlon, ~/anaconda3/envs/py3_parcels/lib/python3.7/site-packages/parcels/kernel.py in execute(self, pset, endtime, dt, recovery, output_file) 295 recovery_kernel = recovery_map[p.state] 296 p.state = ErrorCode.Success --> 297 recovery_kernel(p, self.fieldset, p.time) 298 299 # Remove all particles that signalled deletion ~/anaconda3/envs/py3_parcels/lib/python3.7/site-packages/parcels/tools/error.py in recovery_kernel_out_of_bounds(particle, fieldset, time) 101 # TODO: JIT does not yet provide the context that created 102 # the exception. We need to pass that info back from C. --> 103 raise OutOfBoundsError(particle, fieldset) 104 else: 105 error = particle.exception OutOfBoundsError: 0 Particle P[4381](lon=-29.129885, lat=51.161136, depth=0.000148, time=1728000.000000) Time: 0072-01-23 11:58:56, timestep dt: 21600.000000 Out-of-bounds sampling by particle at (-29.129885, 51.161136, 0.000148)
delandmeterp commented 5 years ago

The error is written in your error message:

OutOfBoundsError: 0 Particle P[4381](lon=-29.129885, lat=51.161136, depth=0.000148, time=1728000.000000) Time: 0072-01-23 11:58:56, timestep dt: 21600.000000 Out-of-bounds sampling by particle at (-29.129885, 51.161136, 0.000148)

Your particle is out-of-bound. You see in the log message where did it happen. Why is it the case? Check the boundaries of your domain (lon, lat and depth)

Then you can use recovery kernels as it is showed in the tutorials https://github.com/OceanParcels/parcels/blob/master/parcels/examples/tutorial_Agulhasparticles.ipynb

With a recovery kernel, you can either delete a particle (as it is shown in the tutorial), or edit particle coordinates and variables, for example the depth (push back the particle to water if the particle has gone through the surface. Do some simple tests at the given location of the error to obtain what you want.

erikvansebille commented 5 years ago

Closing this Issue now, as the originally reported problem was fixed by updating to the latest version of Parcels