CLIMADA-project / climada_python

Python (3.8+) version of CLIMADA
GNU General Public License v3.0
319 stars 125 forks source link

haz.from_hdf5() does not mimic haz.read_hdf5() #970

Closed afarias90 closed 1 week ago

afarias90 commented 1 week ago

read_hdf5() works correctly, but will be deprecated. from_hdf5() does not read in file correctly it seems

To Reproduce Steps to reproduce the behavior/error:

  1. Write a hazard object to an .hdf5 file, with the argument todense=True.
  2. Read it back in using the from_hdf5() method and then run haz.plot_rp_intensity(). I get an empty csr_matrix.
  3. Read it back in using the read_hdf5() method and then run haz.plot_rp_intensity(). A deprecation warning is given and the correct plots are generated.

Code example:

tc_hazard_hdf5 = TropCyclone()
tc_hazard_hdf5.read_hdf5("./synthetic_tropical_cyclone_catalog_on_exp_points.hdf5")

tc_hazard_hdf5.plot_rp_intensity()

This works fine. 

This does not work:
tc_hazard_hdf5 = TropCyclone()
tc_hazard_hdf5.from_hdf5("./synthetic_tropical_cyclone_catalog_on_exp_points.hdf5")

tc_hazard_hdf5.plot_rp_intensity()

Expected behavior reading in a hazard object using from_hdf5() should read it in such that functions like plot_rp_intensity() work OK.

Screenshots If applicable, add screenshots to help explain your problem.

image image

Climada Version: [Version or branch]

chahank commented 1 week ago

Dear @afarias90 , please mind the change in how you should use the method. The below should fix your problem.

tc_hazard_hdf5 = TropCyclone.from_hdf5("./synthetic_tropical_cyclone_catalog_on_exp_points.hdf5")

tc_hazard_hdf5.plot_rp_intensity()
afarias90 commented 1 week ago

Dear @chahank, thank you so much for clarifying, I had indeed missed that change in how the method is used. It works as expected with your change.

chahank commented 1 week ago

Excellent, thanks for giving feedback!