Combining several interpolation functions using a new util function#918
Combining several interpolation functions using a new util function#918ValentinGebhart merged 67 commits intodevelopfrom
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.
I think the following is more efficient and clean:
climada/engine/impact.py
Outdated
| return axis | ||
|
|
||
|
|
||
| # TODO: replace with subplots_from_gdf() |
There was a problem hiding this comment.
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.
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.
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.
in order to avoid circular imports
sarah-hlsn
left a comment
There was a problem hiding this comment.
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
| 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.
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.
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.
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.
wouldn't the climada.util.dates_times package be a better match for this method?
There was a problem hiding this comment.
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_periodto use the new util moduleclimada.util.interpolateand the three functions thereininterpolate_ev,stepfunction_evandgroup_frequency.This makes the functions
local_exceedance_imp,loc_return_imp,_cen_return_imp,local_exceedance_inten,_loc_return_inten,_cen_return_intenand_loc_return_periodobsolete.Impact.local_exceedance_imp,Hazard.local_exceedance_intenis added.Impact.local_exceedance_impact,Hazard.local_exceedance_intensity,Hazard.local_return_periodnow output a geodataframe, such that one can use the util functionplot_from_gdffor plotting. This makes the plotting functionsHazard.plot_rp_intensityandImpact.plot_rp_impobsolete. 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_curveto 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