Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix loading netcdf save by huracanpy losing track_id #36

Merged
merged 1 commit into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion huracanpy/_data/_netcdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ def load(filename, **kwargs):
for npoints, tr_id in zip(rowsize.data, trajectory_id.data):
trajectory_id_stretched.extend([tr_id] * npoints)

dataset = dataset.drop_vars([trajectory_id.name, rowsize.name])

dataset["track_id"] = (sample_dimension, trajectory_id_stretched)
# Keep attributes (including cf_role)
dataset["track_id"].attrs = trajectory_id.attrs

return dataset.drop_vars([trajectory_id.name, rowsize.name])
return dataset


def save(dataset, filename):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_huracanpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def test_save(filename, tracker, extension, tmp_path):
# Reload the data and check it is still the same
data_ = huracanpy.load(str(tmp_path / f"tmp_file.{extension}"))

for var in list(data_.variables) + list(data_.coords):
for var in list(data.variables) + list(data.coords):
# Work around for xarray inconsistent loading the data as float or double
# depending on fill_value and scale_factor
# np.testing.assert_allclose doesn't work for datetime64
Expand Down