Parcels version
v4
Description
While #2622 implemented sampling of a Field directly with a particleset (var = fieldset.field[pset]) I now realise that this does not work if the particle times are not set explicitly.
In that case, (because time is set to NaN) the interpolation returns zero - without warning!
Code sample
fieldset.U.data[:] = 2.
pset = ParticleSet(fieldset, x=0., y=0.)
pset.sample, _ = fieldset.UV[pset] # Sample initial value
np.testing.assert_allclose(pset.sample, 2.0, rtol=1e-12)
AssertionError:
E Not equal to tolerance rtol=1e-12, atol=0
E
E Mismatched elements: 1 / 1 (100%)
E Max absolute difference among violations: 2.
E Max relative difference among violations: 1.
E ACTUAL: array(0)
E DESIRED: array(2.)
Note that the test above passes if we change
- pset = ParticleSet(fieldset, x=0., y=0.)
+ pset = ParticleSet(fieldset, x=0., y=0., t=np.timedelta64(0, "s")
Parcels version
v4
Description
While #2622 implemented sampling of a Field directly with a particleset (
var = fieldset.field[pset]) I now realise that this does not work if the particle times are not set explicitly.In that case, (because time is set to NaN) the interpolation returns zero - without warning!
Code sample
Note that the test above passes if we change