Skip to content

Adapt Hazard from_hdf5 and write_hdf5 to forecast attributes#1181

Merged
ValentinGebhart merged 3 commits intoforecast-classfrom
adapt_hdf5_write_from
Dec 9, 2025
Merged

Adapt Hazard from_hdf5 and write_hdf5 to forecast attributes#1181
ValentinGebhart merged 3 commits intoforecast-classfrom
adapt_hdf5_write_from

Conversation

@ValentinGebhart
Copy link
Collaborator

Changes proposed in this PR:

  • adapted Hazard.io.from_hdf5 and Hazard.io.write_hdf5
  • add test

This PR fixes #1134

PR Author Checklist

PR Reviewer Checklist

Comment on lines 121 to 123
for key in haz_fc.__dict__.keys():
if key not in ["intensity", "fraction"]:
npt.assert_array_equal(haz_fc.__dict__[key], haz_fc_read.__dict__[key])
Copy link
Member

Choose a reason for hiding this comment

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

A bit confused. What about non array values? I would expect this to fail for units, haz_type, pool, etc.

Copy link
Member

Choose a reason for hiding this comment

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

I would thus also invert the if.

if key in [intensity, fraction]:
...
elif key in [...]. (arrays)
....
else. (non arrays)
....

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

np.testing.assert_array_equal also works with the other types of our hazards, right? e.g. these all pass:
np.testing.assert_array_equal(2.,2.)
np.testing.assert_array_equal([1,2], [1,2])

I will adapt the order of the if statement

haz_fc_read = HazardForecast.from_hdf5(file_name)

assert haz_fc_read.lead_time.dtype == np.dtype("timedelta64[ns]")
assert haz_fc_read.member.dtype == int
Copy link
Member

Choose a reason for hiding this comment

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

This test might lead to failure. The init of hazard forecast does not require integer. Just a numpy array of things.

@ValentinGebhart ValentinGebhart merged commit 48b6d40 into forecast-class Dec 9, 2025
11 of 14 checks passed
@ValentinGebhart ValentinGebhart deleted the adapt_hdf5_write_from branch December 9, 2025 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants