def test_pset_remove_particle(fieldset, mode, npart=100): lon = np.linspace(0, 1, npart) lat = np.linspace(1, 0, npart) pset = ParticleSet(fieldset, lon=lon, lat=lat, pclass=ptype[mode]) for ilon, ilat in zip(lon[::-1], lat[::-1]): assert(pset.lon[-1] == ilon) assert(pset.lat[-1] == ilat) pset.remove_indices(pset[-1]) assert(pset.size == 0)
def test_pfile_array_remove_particles(fieldset, mode, tmpdir, npart=10): filepath = tmpdir.join("pfile_array_remove_particles.nc") pset = ParticleSet(fieldset, pclass=ptype[mode], lon=np.linspace(0, 1, npart), lat=0.5 * np.ones(npart)) pfile = pset.ParticleFile(filepath) pfile.write(pset, 0) pset.remove_indices(3) pfile.write(pset, 1) ncfile = close_and_compare_netcdffiles(filepath, pfile) ncfile.close()
def test_pset_multi_execute_delete(fieldset, mode, npart=10, n=5): def AddLat(particle, fieldset, time): particle.lat += 0.1 pset = ParticleSet(fieldset, pclass=ptype[mode], lon=np.linspace(0, 1, npart), lat=np.zeros(npart)) k_add = pset.Kernel(AddLat) for _ in range(n): pset.execute(k_add, runtime=1., dt=1.0) pset.remove_indices(-1) assert np.allclose([p.lat - n*0.1 for p in pset], np.zeros(npart - n), rtol=1e-12)
def test_pset_remove_index(fieldset, mode, npart=100): lon = np.linspace(0, 1, npart) lat = np.linspace(1, 0, npart) pset = ParticleSet(fieldset, lon=lon, lat=lat, pclass=ptype[mode], lonlatdepth_dtype=np.float64) for ilon, ilat in zip(lon[::-1], lat[::-1]): assert (pset[-1].lon == ilon) assert (pset[-1].lat == ilat) pset.remove_indices(-1) assert (pset.size == 0)