-
Notifications
You must be signed in to change notification settings - Fork 129
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
Combining several interpolation functions using a new util function #918
Conversation
climada/engine/impact.py
Outdated
) | ||
|
||
# create the output GeoDataFrame | ||
gdf = gpd.GeoDataFrame(geometry = [Point(x, y) for y, x in self.coord_exp], crs = self.crs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the following is more efficient and clean:
https://geopandas.org/en/stable/docs/reference/api/geopandas.points_from_xy.html
climada/engine/impact.py
Outdated
@@ -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() |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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"?
There was a problem hiding this comment.
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.
# Conflicts: # CHANGELOG.md
in order to avoid circular imports
There was a problem hiding this 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!
Co-authored-by: Sarah Hülsen <[email protected]>
climada/hazard/plot.py
Outdated
@@ -32,6 +36,7 @@ class HazardPlot: | |||
Contains all plotting methods of the Hazard class | |||
""" | |||
|
|||
# TODO depreciating warning, to be replaced with plot_from_gdf |
There was a problem hiding this comment.
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?
climada/hazard/plot.py
Outdated
""" | ||
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." | ||
) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
are the changes in the plots of the Hazard tutorial relevant? If they aren't I'd suggest to undo them. |
climada/util/checker.py
Outdated
def convert_frequency_unit_to_time_unit(frequency_unit): | ||
"""Converts common frequency units to corresponding time units. Unknown frequency | ||
units are converted to "years". |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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!
Great Job! Many thanks! |
Changes proposed in this PR:
Impact.local_exceedance_impact
,Hazard.local_exceedance_intensity
,Hazard.local_return_period
to use the new util moduleclimada.util.interpolate
and the three functions thereininterpolate_ev
,stepfunction_ev
andgroup_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.Impact.local_exceedance_imp
,Hazard.local_exceedance_inten
is added.Impact.local_exceedance_impact
,Hazard.local_exceedance_intensity
,Hazard.local_return_period
now output a geodataframe, such that one can use the util functionplot_from_gdf
for plotting. This makes the plotting functionsHazard.plot_rp_intensity
andImpact.plot_rp_imp
obsolete. A deprecation warning was added.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 beforeOpen questions/further possibilities:
Impact.calc_freq_curve
to give it a bit more flexibility. Not clear if needed.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
develop
)PR Reviewer Checklist