How to solve the problem that particle trajectories always run to land #1428
Replies: 1 comment
-
Dear @wangkou-2019, thanks for your question. I had a quick look at your code above, and most likely is that your hydrodynamic data is not properly defined and/or that there is something wrong with the longitudes in your input files. However, it is very difficult, if not impossible, to answer this question without access to your system and information on your hydrodynamic data. Unless you can specify what exactly the bug is, I'm afraid I can't help you with a very general question like this. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am new to parcels. I tried to release some particles in the Arctic region, but these particles eventually ran to the land. Below is my code and results. I hope to get your help. Thank you very much.
`import math
from datetime import timedelta
from operator import attrgetter
import matplotlib.pyplot as plt
import numpy as np
import trajan as ta
import xarray as xr
from IPython.display import HTML
from matplotlib.animation import FuncAnimation
from parcels import (
AdvectionRK4,
FieldSet,
JITParticle,
ParticleSet,
Variable,
ErrorCode,
)
filepath = '/data/2015_1km_interpdata/2015Arctic*.nc'
filenames={
"U":filepath,
"V":filepath,
}
variables={
"U":"eastward_eulerian_current_velocity",
"V":"northward_eulerian_current_velocity",
}
dimensions={"lat":"lat","lon":"lon","time":"time"}
fieldset = FieldSet.from_netcdf(filenames,variables,dimensions,allow_time_extrapolation=True)
from scipy import interpolate
npart = 10
lat = (61.34, 70.06,71.50,70.70,67.81)
lon = (3.98,17.88,25.75,30.97,41.38)
nlon = np.linspace(3.98,41.38,npart,dtype=np.float32)
f1 =interpolate.interp1d(lon, lat, kind='linear')
nlat = f1(nlon)
pset = ParticleSet(fieldset=fieldset, pclass=JITParticle, lon=nlon, lat=nlat)
def DeleteParticle(particle, fieldset, time):
particle.delete()
output_path = '/Results/2015year/'
output_file = pset.ParticleFile(
name=output_path + '2015output.zarr',outputdt=timedelta(hours=12))
pset.execute(
AdvectionRK4,
runtime=timedelta(days=30),
dt=timedelta(hours=12),
recovery={ErrorCode.ErrorOutOfBounds: DeleteParticle},
output_file = output_file,
)
ds = xr.open_zarr(output_path + '2015output.zarr')
ds.traj.plot(margin=2)
plt.show()`
Beta Was this translation helpful? Give feedback.
All reactions