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

Attribute error due to custom kernel tracking particle velocity in m/s #568

Closed judithmarinaewald closed 5 years ago

judithmarinaewald commented 5 years ago
kernels = pset.Kernel(AdvectionRK4) + TrackVelocity2D

The custom kernel TrackVelocity2D is to track 2D particle velocities in m/s instead of degree/s.

with TrackVelocity2D:

def TrackVelocity2D(particle, fieldset, time):
    (u1, v1) = fieldset.UV[time, particle.depth, particle.lat, particle.lon]
    particle.u = u1  * math.cos(particle.lat * 1852. * 60.)
    particle.v = v1 * 1852. * 60.

gives attribute error:

AttributeError: Particle type {particle_type} does not define attribute "u". Please add 'u' to {particle_type}.users_vars or define an appropriate sub-class.

With {particle_type} replaced for PType<JITParticle>::[PVar<time|<class 'numpy.float64'>>, PVar<cxi|uint64>, PVar<cyi|uint64>, PVar<czi|uint64>, PVar<cti|uint64>, PVar<lon|<class 'numpy.float32'>>, PVar<lat|<class 'numpy.float32'>>, PVar<depth|<class 'numpy.float32'>>, PVar<id|<class 'numpy.int32'>>, PVar<fileid|<class 'numpy.int32'>>, PVar<dt|<class 'numpy.float32'>>, PVar<state|<class 'numpy.int32'>>]

judithmarinaewald commented 5 years ago

ParticleSet created as:

pset = ParticleSet.from_line(fieldset=fieldset_nemo, pclass=JITParticle,
                             size=10,           # releasing 10 particles
                             start=(-10, 45),   # releasing on a line: the start longitude and latitude
                             finish=(-11, 40))  # releasing on a line: the end longitude and latitude

with fieldset

ddir = '/data2/imau/oceanparcels/hydrodynamic_data/NEMO-MEDUSA/ORCA0083-N006/'
ufiles = sorted(glob(ddir+'means/ORCA0083-N06_2010????d05U.nc'))
vfiles = [u.replace('05U.nc', '05V.nc') for u in ufiles]
meshfile = glob(ddir+'domain/coordinates.nc')

filenames = {'U': {'lon': meshfile, 'lat': meshfile, 'data': ufiles},
             'V': {'lon': meshfile, 'lat': meshfile, 'data': vfiles}}
variables = {'U': 'uo', 'V': 'vo'}
dimensions = {'lon': 'glamf', 'lat': 'gphif', 'time': 'time_counter'}

indices = {'lon': range(2365, 3325), 'lat': range(1500, 3000)}
fieldset_nemo = FieldSet.from_nemo(filenames, variables, dimensions, indices = indices)
delandmeterp commented 5 years ago

particle.u and particle.v do not unless you specify those variables.

See cell 2 in the Argo tutorial, where some variables are created in the ArgoParticle class.