Skip to content

Conversation

@VeckoTheGecko
Copy link
Contributor

@VeckoTheGecko VeckoTheGecko commented Aug 8, 2025

  • Chose the correct base branch (v4-dev for v4 changes)
  • Fixes None
  • Added tests (WIP)
  • Added documentation - no, will leave updating docstrings for a later PR

This PR brings back particlefile writing into the Parcels codebase, making it compatible with v4-dev.

Changes:

  • Update ParticleFile
    • Eliminate coupling with ParticleSet
    • Decouple metadata writing from the class attributes
  • Migrate test suite from v3 to v4-dev
  • Define particle variable metadata on the Particle object itself

I think that this can be significantly improved in future (namely by working natively with zarr rather than intializing with xarray first then "extending" with zarr) making the code cleaner and more robust.

Previous description

@erikvansebille Just thought I would send you a quick update on my progress on the PariticleFile writing. PR is very much WIP (no review needed), and I will edit this description again once finalized.

  • I have done a bunch of refactoring/clearing up to decouple ParticleFile from the ParticleSet itself (its already a much leaner class, which helps with unit testing)
  • I have looked into Zarr - I think the best way forward is to natively work with zarr (not use xarray to initialize, and Zarr to extend) - this simplifies the execution path and helps with testability. We just need to follow the Xarray Zarr encoding spec
  • I think I have identified a fix for the extend dimensions (see branch pfile-native-zarr - this will make its way into this PR). I think we can work with zarr and extend the size when we encounter out of bounds. I still need to properly test this (and perhaps report a bug to Zarr) since I was encountering irregularities in the produced dataset using with the exact code I had (observations written at the end of the chunk and not the beginning).

Bad news is that this has taken longer than I hoped. I was having some difficulty working with v3 test_particlefile.py file - since its more of an integration test suite, and there have been a lot of changes since branching off main, the errors weren't informative. I have now taken a step back to build up the test suite using unit tests and using that to guide refactoring - but ran out of time today.

I'll get back to this once I'm back online.

@VeckoTheGecko VeckoTheGecko marked this pull request as draft August 8, 2025 13:18
@VeckoTheGecko VeckoTheGecko force-pushed the pfile-rework branch 3 times, most recently from 0929bc5 to 7bb4f89 Compare September 4, 2025 07:13
@VeckoTheGecko VeckoTheGecko changed the title ParticleFile rework ParticleFile refactor and re-integration into v4-dev Sep 4, 2025
Comment on lines 96 to 98
def name(self):
return f"{self._ptype.name}{self.funcname}"
# return f"{self._ptype.name}{self.funcname}" # TODO v4: Should we propogate the name of the particle to the metadata? At the moment we don't have the concept of naming particles (somewhat incompatible with the .add_variable() API?)
return f"{self.funcname}"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^
Should we force users to name their particles @erikvansebille ? IIRC in v3 particles created with add_variable were called NewParticle?

@VeckoTheGecko VeckoTheGecko marked this pull request as ready for review September 4, 2025 09:06
@VeckoTheGecko
Copy link
Contributor Author

Still need to fix the tests

Variable(
"time",
dtype=_SAME_AS_FIELDSET_TIME_INTERVAL.VALUE,
attrs={"long_name": "", "standard_name": "time", "units": "seconds", "axis": "T"},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the units here always in seconds? Does that not depend on the type of time?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When serialized out, this gets updated to seconds since ... for datetime objects

Looking at time_nextloop instead. We might rework the kernel loop in future (and the responsibilities of time, time_nextloop, as well as their effect on particle writing).
Not sure how that got in there.... Typo
- Set metadata in file
- Remove temp pytest marker
Also flag tests that should be looked at later - as they are out of scope for this PR (or may be able to be tested another way)
In favour of directly using the ParticleFile object
@VeckoTheGecko VeckoTheGecko merged commit 910fe2a into v4-dev Sep 8, 2025
9 checks passed
@VeckoTheGecko VeckoTheGecko deleted the pfile-rework branch September 8, 2025 08:21
@github-project-automation github-project-automation bot moved this from Backlog to Done in Parcels development Sep 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants