parcels icon indicating copy to clipboard operation
parcels copied to clipboard

Sample UV velocities with a SummedField field, "eval" attribute has disapeared ?

Open slawchune opened this issue 2 years ago • 3 comments

Hi Eric and team !

I tried to sample UV velocities with a SummedField field and leaned on an error.

In [70]: ksample_UV = pset.Kernel(Sample_Velocity)

In [71]: pset.execute(ksample_UV, dt=0)
---------------------------------------------------------------------------
KernelError                               Traceback (most recent call last)
Input In [71], in <cell line: 1>()
----> 1 pset.execute(ksample_UV, dt=0)

File ~/.conda/envs/py3_parcels/lib/python3.10/site-packages/parcels/particleset/baseparticleset.py:458, in BaseParticleSet.execute(self, pyfunc, pyfunc_inter, endtime, runtime, dt, moviedt, recovery, output_file, movie_background_field, verbose_progress, postIterationCallbacks, callbackdt)
    456 # If we don't perform interaction, only execute the normal kernel efficiently.
    457 if self.interaction_kernel is None:
--> 458     self.kernel.execute(self, endtime=next_time, dt=dt, recovery=recovery, output_file=output_file,
    459                         execute_once=execute_once)
    460 # Interaction: interleave the interaction and non-interaction kernel for each time step.
    461 # E.g. Inter -> Normal -> Inter -> Normal if endtime-time == 2*dt
    462 else:
    463     cur_time = time

File ~/.conda/envs/py3_parcels/lib/python3.10/site-packages/parcels/kernel/kernelsoa.py:227, in KernelSOA.execute(self, pset, endtime, dt, recovery, output_file, execute_once)
    225 recovery_kernel = recovery_map[p.state]
    226 p.set_state(StateCode.Success)
--> 227 recovery_kernel(p, self.fieldset, p.time)
    228 if p.isComputed():
    229     p.reset_state()

File ~/.conda/envs/py3_parcels/lib/python3.10/site-packages/parcels/tools/statuscodes.py:121, in recovery_kernel_error(particle, fieldset, time)
    119 """Default error kernel that throws exception"""
    120 msg = "Error: %s" % particle.exception if particle.exception else None
--> 121 raise KernelError(particle, fieldset=fieldset, msg=msg)

KernelError: 0
Particle P[0](lon=-163.101532, lat=-14.612890, depth=0.000000, U=0.000000, V=0.000000, time=127800.000000)
Time: 2018-03-05T12:00:00.000000000,	timestep dt: 0.000000
Error: 'SummedField' object has no attribute 'eval'
 

The fieldset was created through a simple addition :

        Create a new field that combines a fraction of stokes  and fieldset from currents
        '''
        fieldset = FieldSet(U=fieldset_current.U+fieldset_add.U, V=fieldset_current.V+fieldset_add.V)

the sampling kernel is very simple as well :


########################################################################################
def Sample_Velocity(particle, fieldset, time):
    # sample velocity in m/s instead of °/s 
    particle.U, particle.V  = fieldset.UV.eval(time, particle.depth, particle.lat, particle.lon, applyConversion=False)

########################################################################################

Is there a special workaround for this ? Cheers !

Stéphane

slawchune avatar Jun 30 '22 09:06 slawchune

Thanks for reporting, @slawchune. Which version of Parcels are you using, because this should have been fixed in https://github.com/OceanParcels/parcels/pull/1175, which was merged in the master branch last month?

erikvansebille avatar Jun 30 '22 09:06 erikvansebille

Thanks for you quick reply Eric, I use the regular conda-forge one. I'll try with the up-to-date github one then =)

slawchune avatar Jun 30 '22 10:06 slawchune

This should now be fixed in #1200

erikvansebille avatar Jul 22 '22 14:07 erikvansebille