Skip to content

Combining several interpolation functions using a new util function #918

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

Merged
merged 67 commits into from
Nov 5, 2024

Conversation

ValentinGebhart
Copy link
Collaborator

@ValentinGebhart ValentinGebhart commented Jul 16, 2024

Changes proposed in this PR:

  • Adaption of the functions Impact.local_exceedance_impact, Hazard.local_exceedance_intensity, Hazard.local_return_period to use the new util module climada.util.interpolate and the three functions therein interpolate_ev, stepfunction_ev and group_frequency.
    This makes the functions local_exceedance_imp, loc_return_imp, _cen_return_imp, local_exceedance_inten, _loc_return_inten, _cen_return_inten and _loc_return_period obsolete.
  • A deprecation warning for the old versions Impact.local_exceedance_imp, Hazard.local_exceedance_inten is added.
  • All methods Impact.local_exceedance_impact, Hazard.local_exceedance_intensity, Hazard.local_return_period now output a geodataframe, such that one can use the util function plot_from_gdf for plotting. This makes the plotting functions Hazard.plot_rp_intensity and Impact.plot_rp_imp obsolete. A deprecation warning was added.
  • In the methods Impact.local_exceedance_imp, Hazard.local_exceedance_inten, Hazard.local_return_period, before interpolation, we group together values with the same intensity/impact (by summing their frequencies). This was not done in the functions before

Open questions/further possibilities:

  • Do we want to try a more efficient output type than gdf if the above function output gdfs with a lot of zeros (e.g. spare gdf etc)?
  • Could one do the fitting matrix-wise (or block-wise) instead of column-wise for better efficiency? Not clear due to requirements of underlying fit functions.
  • Future Option: PR to add a fit method (to some extreme value distribution, specified by the user).
  • Future Option: One could use the util method also in Impact.calc_freq_curve to give it a bit more flexibility. Not clear if needed.
  • Future Option: We could now easily add a method Impact.local_return_period, similar to the Hazard case. Not sure if needed.

This PR fixes #904, #915 and partially also #209

PR Author Checklist

PR Reviewer Checklist

@ValentinGebhart ValentinGebhart changed the title Combining several fit functions into a new util fit functions Combining several fit functions into a new util fit function Jul 16, 2024
)

# create the output GeoDataFrame
gdf = gpd.GeoDataFrame(geometry = [Point(x, y) for y, x in self.coord_exp], crs = self.crs)
Copy link
Member

Choose a reason for hiding this comment

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

@@ -813,7 +847,8 @@ def plot_basemap_impact_exposure(self, event_id=1, mask=None, ignore_zero=False,
buffer, extend, zoom, url, axis=axis, **kwargs)

return axis


# TODO: replace with subplots_from_gdf()
Copy link
Member

Choose a reason for hiding this comment

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

The name subplots_from_gdf is a bit confusing to me. Why would this be a subplot instead of a plot?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The subplots_from_gdf already exists, it is how we now plot local return periods for given hazard intensity thresholds. I named it subplots because it produces a plot with several subplots, each for a different column of the gdf. I am happy to change the name though, just "plot_from_gdf" or "plots_from_gdf"?

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 then prefer plot_from_gdf. Plot is quite clear, and can contain more than one. Plurals are in my opinion to be avoided as much as possible as they easily create confusion.

@ValentinGebhart ValentinGebhart marked this pull request as draft July 18, 2024 09:34
@ValentinGebhart ValentinGebhart marked this pull request as ready for review July 29, 2024 15:10
Copy link
Collaborator

@sarah-hlsn sarah-hlsn left a comment

Choose a reason for hiding this comment

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

I would add "impacts" to the examples given for values in the docstrings; since there are just two options for values I think we might as well mention both. Other than that everything looks good to me!

@@ -32,6 +36,7 @@ class HazardPlot:
Contains all plotting methods of the Hazard class
"""

# TODO depreciating warning, to be replaced with plot_from_gdf
Copy link
Collaborator

Choose a reason for hiding this comment

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

But strictly speaking this isn't a TODO anymore?

Comment on lines 49 to 56
"""
This function is deprecated,
use Impact.local_exceedance_impact and util.plot.plot_from_gdf instead.
"""
LOGGER.warning(
"The use of Hazard.plot_rp_intensity is deprecated."
"Use Hazard.local_exceedance_intensity and util.plot.plot_from_gdf instead."
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd suggest to use the @deprecated decorator instead, like e.g., in the climada.hazard.centr module.
I know, atm, the climada codebase is heterogeneous in this regard but in the long run the decorator is meant to take over.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

thank you, I didn't know about this. I changed this to decorators now

@emanuel-schmid
Copy link
Collaborator

emanuel-schmid commented Nov 4, 2024

are the changes in the plots of the Hazard tutorial relevant? If they aren't I'd suggest to undo them.
(@ValentinGebhart I already did, ready to push, just let me know.)

Comment on lines 233 to 235
def convert_frequency_unit_to_time_unit(frequency_unit):
"""Converts common frequency units to corresponding time units. Unknown frequency
units are converted to "years".
Copy link
Collaborator

Choose a reason for hiding this comment

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

wouldn't the climada.util.dates_times package be a better match for this method?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree, I will move the method there (and the unit test accordingly), thank you!

@emanuel-schmid
Copy link
Collaborator

Great Job! Many thanks!

@ValentinGebhart ValentinGebhart merged commit d195226 into develop Nov 5, 2024
18 checks passed
@ValentinGebhart ValentinGebhart deleted the feature/restructure_fitfuncs_exceedance branch November 5, 2024 08:14
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.

4 participants