-
QuestionQuestionI'm trying to simulate some virtual Argo Floats and have starting by replicating the ArgoVerticalMovement example. However I'm running into some problems:
I've only recently updated to Parcels version 3 (it's been a while since I've run simulations!) so it's possible I've missed some key updates/understanding of what's changed. This code was run using version 3.1.0. Any pointers are much appreciated, thank you. Supporting code/error messagesfrom parcels import FieldSet, ParticleSet, Variable, JITParticle, ScipyParticle, AdvectionRK4
output_directory = '/scratch/e14/hd4873/particle_tracking/virtual_floats/logistically_feasible/'
mesh_mask = output_directory + '/ocean.nc'
# Define the files containing the U and V files (2D advection).
data_path = '/g/data/cj50/access-om2/raw-output/access-om2-01/01deg_jra55v140_iaf/'
ufiles = sorted(glob(data_path + f'output*/ocean/ocean-3d-u-1-daily-mean-ym_*.nc'))
vfiles = sorted(glob(data_path + f'output*/ocean/ocean-3d-v-1-daily-mean-ym_*.nc'))
filenames = {
'U': {'lon': mesh_mask, 'lat': mesh_mask, 'depth': mesh_mask, 'data': ufiles},
'V': {'lon': mesh_mask, 'lat': mesh_mask, 'depth': mesh_mask, 'data': vfiles},
}
variables = {'U': 'u', 'V': 'v'}
dimensions = {'U': {'lon': 'xu_ocean', 'lat': 'yu_ocean', 'depth': 'sw_ocean', 'time': 'time'},
'V': {'lon': 'xu_ocean', 'lat': 'yu_ocean', 'depth': 'sw_ocean', 'time': 'time'},
}
cs = {"U": {"lon": ("xu_ocean", 400), "lat": ("yu_ocean", 300), "depth": ("st_ocean", 2), "time": ("time", 1)},
"V": {"lon": ("xu_ocean", 400), "lat": ("yu_ocean", 300), "depth": ("st_ocean", 2), "time": ("time", 1)},
}
fieldset = FieldSet.from_mom5(filenames, variables, dimensions,
mesh = 'spherical',
chunksize = cs,
tracer_interp_method = 'bgrid_tracer',
)
# Set a minimum depth == the uppermost layer in the hydrodynamic data
fieldset.mindepth = fieldset.U.depth[0]
print(fieldset.mindepth)
# this is 1.08 m
# Define a new Particle type including extra Variables
ArgoParticle = parcels.JITParticle.add_variables(
[
parcels.Variable("cycle_phase", dtype=np.int32, initial=0.0),
parcels.Variable("cycle_age", dtype=np.float32, initial=0.0),
parcels.Variable("drift_age", dtype=np.float32, initial=0.0),
]
)
def ArgoVerticalMovement(particle, fieldset, time):
driftdepth = 300 # drifting depth in m
vertical_speed = 0.1 # sink and rise rate in m/s
cycletime = 4 * 86400 # Just using 4 days for now
drifttime = cycletime - (5*60*60) # given the shallow drifting depth, just allowing for 5 hour rise/rall rate for the purposes of this test
# Phase 0: sinking to drift depth with vertical_speed
if particle.cycle_phase == 0:
particle_ddepth += vertical_speed * particle.dt
if particle.depth + particle_ddepth >= driftdepth:
# Note: This code did not work, so updating particle depth directly in next loop
particle_ddepth = driftdepth - particle.depth
particle.cycle_phase = 1
# Phase 1: Drifting at depth for drifttime seconds
elif particle.cycle_phase == 1:
# updates to depth at end of cycle_phase 0 don't seem to be working, so updating directly here instead
particle.depth = driftdepth
particle_ddepth = 0
particle.drift_age += particle.dt
if particle.drift_age >= drifttime:
particle.drift_age = 0 # reset drift_age for next cycle
particle.cycle_phase = 3
# Skipping Phase 2 (second descent phase) for testing purposes
# Phase 3: Rising with vertical_speed until at surface
elif particle.cycle_phase == 3:
particle_ddepth -= vertical_speed * particle.dt
if particle.depth + particle_ddepth <= fieldset.mindepth:
particle_ddepth = fieldset.mindepth - particle.depth
particle.cycle_phase = 4
# Phase 4: Transmitting at surface until cycletime is reached
elif particle.cycle_phase == 4:
# updates to depth at end of cycle_phase 3 don't seem to be working, so updating directly here instead
particle.depth = fieldset.mindepth
particle_ddepth = 0
if particle.cycle_age > cycletime:
particle.cycle_phase = 0
particle.cycle_age = 0
# update cycle_age
if particle.state == StatusCode.Evaluate:
particle.cycle_age += particle.dt
lons = np.array(77.)
lats = np.array(-68.24674827)
depths = np.array(1.0825615)
pset = ParticleSet.from_list(fieldset=fieldset,
pclass=ArgoParticle,
lon=lons,
lat=lats,
depth=depths,
)
output_filename = 'TestArgoParticle_MinimalExample.zarr'
# Save to file at same timestep as advection kernels
output_file = pset.ParticleFile(
name=output_directory + output_filename,
outputdt=timedelta(minutes=15),
chunks=(1, 500),
)
kernels = [ArgoVerticalMovement, AdvectionRK4]
pset.execute(
kernels,
runtime=timedelta(days=7), # short run time for example
dt=timedelta(minutes=15),
output_file=output_file,
)
Then, reading in the output:
![]()
![]()
![]()
|
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 4 replies
-
Hi @hrsdawson, thanks for reaching out with this question! It could be that the version of the Argo kernel that you're using is a bit outdated. I remember that we had to make some updates to the Kernel when we were developing our Virtual Ship Classroom. Could you check the code at https://github.com/OceanParcels/virtualship/blob/main/src/virtualship/instruments/argo_float.py and see if that does work? If so, we may need to update the example here in the Parcels repo too |
Beta Was this translation helpful? Give feedback.
-
Hi @erikvansebille, thanks for the quick response. I've tried the code you linked and unfortunately that doesn't work for me either. It increased the cycle_age increment during the cycle 3 phase due to this code Since my problem is the cycle_age incrementing too fast, I changed the code to subtract the timestep ( Note: I had to switch the cycle 1 if statement in the virtual ship code from |
Beta Was this translation helpful? Give feedback.
-
Hi @hrsdawson, frustrating that you still have the issue with the depths. Could it be that the virtualship code indeed expects depths to be negative (since it's an educational tool, we want to be strict in our right-hand cartesian coordinate system). We use Lines 117 to 124 in f3a987e Can you try whether it works if you also negate the depth in your simulation? |
Beta Was this translation helpful? Give feedback.
-
Hmm, I tried negating the depths but got this error: |
Beta Was this translation helpful? Give feedback.
-
Thanks @erikvansebille. I just sent you some hydrodynamic files via WeTransfer, which I'd subsetted to a small geographic domain (too big to send otherwise). Intriguingly, my issues disappeared when using that subsetted field. After some digging I've discovered the problem was the chunk size I was giving Parcels for the depth dimension of the hydrodynamic fields. I was originally using a chunk size of 2 which causes the cycle age and depth problems to occur, but if I increase the chunk size to something much larger (e.g. 38 - half the length of the depth dimension) then the cycle_age and depth issues disappear. Is this a bug, or should I have known better re the chunk sizes? I've just sent you an example script via email that illustrates the problem when using small chunk in depth, but if it's not a bug and you don't wish to dig further, then the problem is simply solved by increasing the depth chunk size! |
Beta Was this translation helpful? Give feedback.
Thanks @erikvansebille. I just sent you some hydrodynamic files via WeTransfer, which I'd subsetted to a small geographic domain (too big to send otherwise). Intriguingly, my issues disappeared when using that subsetted field. After some digging I've discovered the problem was the chunk size I was giving Parcels for the depth dimension of the hydrodynamic fields. I was originally using a chunk size of 2 which causes the cycle age and depth problems to occur, but if I increase the chunk size to something much larger (e.g. 38 - half the length of the depth dimension) then the cycle_age and depth issues disappear.
Is this a bug, or should I have known better re the chunk sizes? I've just sen…