Skip to content

Commit ae4c7a0

Browse files
committed
fix bug of CTD order (filenames)
1 parent 48aac1c commit ae4c7a0

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

virtualship.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ def SampleT(particle, fieldset, time):
351351
pset_CTD = ParticleSet(fieldset=fieldset, pclass=CTDParticle, lon=sample_lons[i], lat=sample_lats[i], depth=fieldset.mindepth, time=total_time)
352352

353353
# create a ParticleFile to store the CTD output
354-
ctd_output_file = pset_CTD.ParticleFile(name=f"{os.path.join('results','CTDs','CTD_')}{ctd}.zarr", outputdt=ctd_dt)
354+
ctd_output_file = pset_CTD.ParticleFile(name=f"{os.path.join('results','CTDs','CTD_')}{ctd:03d}.zarr", outputdt=ctd_dt)
355355

356356
# record the temperature and salinity of the particle
357357
pset_CTD.execute([SampleS, SampleT, CTDcast], runtime=timedelta(hours=8), dt=ctd_dt, output_file=ctd_output_file, verbose_progress=False)
@@ -536,13 +536,13 @@ def postprocess():
536536

537537
if os.path.isdir(os.path.join("results","CTDs")):
538538
i = 0
539-
for filename in os.scandir(os.path.join("results","CTDs")):
540-
# TODO not so happy about using filename and i as they might not be identical
541-
if filename.path.endswith(".zarr"):
539+
filenames = os.listdir(os.path.join("results","CTDs"))
540+
for filename in sorted(filenames):
541+
if filename.endswith(".zarr"):
542542
try: #too many errors, just skip the faulty zarr files
543543
i += 1
544544
# Open output and read to x, y, z
545-
ds = xr.open_zarr(filename.path)
545+
ds = xr.open_zarr(os.path.join("results","CTDs",filename))
546546
x = ds["lon"][:].squeeze()
547547
y = ds["lat"][:].squeeze()
548548
z = ds["z"][:].squeeze()

0 commit comments

Comments
 (0)