Adding both an xarray.dataset and a dict-of-numpy-arrays for the particle-data#2097
Closed
erikvansebille wants to merge 4 commits intoparticledata_as_dictfrom
Closed
Adding both an xarray.dataset and a dict-of-numpy-arrays for the particle-data#2097erikvansebille wants to merge 4 commits intoparticledata_as_dictfrom
erikvansebille wants to merge 4 commits intoparticledata_as_dictfrom
Conversation
Contributor
|
I think a difficulty with this is that once a new array is created (e..g, from the deletion of particles), then there will be drift between these two data structures. I don't think this is currently working as intended. Here's a test: def test_pset_remove_indices(fieldset):
npart = 10
lon_start = np.linspace(0, 1, npart)
lat_start = np.linspace(1, 0, npart)
pset = ParticleSet(fieldset, lon=np.linspace(0, 1, npart), lat=np.linspace(1, 0, npart))
assert len(pset._ds.lon) == len(pset._data["lon"]) == npart
pset.remove_indices([0])
assert len(pset._ds.lon) == len(pset._data["lon"]) == npart - 1 |
Member
Author
|
Ah, good catch! I hadn't realised that deleting a particle would create a new dataset, indeed. And so would adding two ParticleSets. We could change the code to all update the dict-of-numpy-arrays whenever we change the dataset; or is that too prone to errors? |
Adding @VeckoTheGecko's failing test showing that the dict-of-numpys does not track the xarray dataset anymore after a deletion
Member
Author
|
I just added the test above to the unit tests suite, so that we got failing CI and don't accidentally merge this PR |
Member
Author
|
Clsogn this PR, as the combination of a dict-of-numpy-arrays and an xarray Dataset does not seem robust enough (see #2097 (comment)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR builds on #2094, following @VeckoTheGecko's suggestion at Parcels-code/parcels-benchmarks#1 (comment) to keep the ParticleData in both an xarray.DataSet structure (
ParticleSet._ds) and a dict-of-numpy-arrays (ParticleSet._data).This new branch has the same performance as #2094 (see Parcels-code/parcels-benchmarks#1 (comment)), but advantage is that users can also access the data as a
xarray.DataSet.This will be useful e.g. in the
__repr__(to be implemented) and the new implementation ofParticleFileparticledata_as_dict)