From bfef378ca996e0ff4efebfc6ee7731031556c9c5 Mon Sep 17 00:00:00 2001 From: Valentin Gebhart Date: Mon, 4 Nov 2024 16:20:45 +0100 Subject: [PATCH] changed deprecation warning to decorators --- climada/engine/impact.py | 25 ++++++++++++------------- climada/hazard/base.py | 13 +++++++------ climada/hazard/plot.py | 13 ++++++------- 3 files changed, 25 insertions(+), 26 deletions(-) diff --git a/climada/engine/impact.py b/climada/engine/impact.py index 16575cd65..26043290d 100644 --- a/climada/engine/impact.py +++ b/climada/engine/impact.py @@ -40,6 +40,7 @@ import numpy as np import pandas as pd import xlsxwriter +from deprecation import deprecated from pyproj import CRS as pyprojCRS from rasterio.crs import CRS as rasterioCRS # pylint: disable=no-name-in-module from scipy import sparse @@ -595,14 +596,14 @@ def local_exceedance_impact( return gdf, label, column_label + @deprecated( + details="The use of Impact.local_exceedance_imp is deprecated. Use " + "Impact.local_exceedance_impact instead. Some errors in the previous calculation " + "in Impact.local_exceedance_imp have been corrected. To reproduce data with the " + "previous calculation, use CLIMADA v5.0.0 or less." + ) def local_exceedance_imp(self, return_periods=(25, 50, 100, 250)): """This function is deprecated, use Impact.local_exceedance_impact instead.""" - LOGGER.warning( - "The use of Impact.local_exceedance_imp is deprecated. Use " - "Impact.local_exceedance_impact instead. Some errors in the previous calculation " - "in Impact.local_exceedance_imp have been corrected. To reproduce data with the " - "previous calculation, use CLIMADA v5.0.0 or less." - ) return ( self.local_exceedance_impact(return_periods)[0] @@ -1001,7 +1002,10 @@ def plot_basemap_impact_exposure( return axis - # TODO: replace with plot_from_gdf() + @deprecated( + details="The use of Impact.plot_rp_imp is deprecated." + "Use Impact.local_exceedance_impact and util.plot.plot_from_gdf instead." + ) def plot_rp_imp( self, return_periods=(25, 50, 100, 250), @@ -1013,13 +1017,8 @@ def plot_rp_imp( """ This function is deprecated, use Impact.local_exceedance_impact and util.plot.plot_from_gdf instead. - """ - LOGGER.warning( - "The use of Impact.plot_rp_imp is deprecated." - "Use Impact.local_exceedance_impact and util.plot.plot_from_gdf instead." - ) - """Compute and plot exceedance impact maps for different return periods. + Compute and plot exceedance impact maps for different return periods. Calls local_exceedance_imp. Parameters diff --git a/climada/hazard/base.py b/climada/hazard/base.py index 638fa90cd..bdb76c354 100644 --- a/climada/hazard/base.py +++ b/climada/hazard/base.py @@ -29,6 +29,7 @@ import geopandas as gpd import numpy as np +from deprecation import deprecated from pathos.pools import ProcessPool as Pool from scipy import sparse @@ -584,14 +585,14 @@ def local_exceedance_intensity( return gdf, label, column_label + @deprecated( + details="The use of Hazard.local_exceedance_inten is deprecated. Use " + "Hazard.local_exceedance_intensity instead. Some errors in the previous calculation " + "in Hazard.local_exceedance_inten have been corrected. To reproduce data with the " + "previous calculation, use CLIMADA v5.0.0 or less." + ) def local_exceedance_inten(self, return_period=(25, 50, 100, 250)): """This function is deprecated, use Hazard.local_exceedance_intensity instead.""" - LOGGER.warning( - "The use of Hazard.local_exceedance_inten is deprecated. Use " - "Hazard.local_exceedance_intensity instead. Some errors in the previous calculation " - "in Hazard.local_exceedance_inten have been corrected. To reproduce data with the " - "previous calculation, use CLIMADA v5.0.0 or less." - ) return ( self.local_exceedance_intensity(return_period)[0] .values[:, 1:] diff --git a/climada/hazard/plot.py b/climada/hazard/plot.py index ab9b9c4da..3ab1cec8b 100644 --- a/climada/hazard/plot.py +++ b/climada/hazard/plot.py @@ -23,6 +23,7 @@ import matplotlib.pyplot as plt import numpy as np +from deprecation import deprecated import climada.util.plot as u_plot @@ -36,7 +37,10 @@ class HazardPlot: Contains all plotting methods of the Hazard class """ - # TODO depreciating warning, to be replaced with plot_from_gdf + @deprecated( + details="The use of Hazard.plot_rp_intensity is deprecated." + "Use Hazard.local_exceedance_intensity and util.plot.plot_from_gdf instead." + ) def plot_rp_intensity( self, return_periods=(25, 50, 100, 250), @@ -49,13 +53,8 @@ def plot_rp_intensity( """ 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." - ) - """Compute and plot hazard exceedance intensity maps for different + Compute and plot hazard exceedance intensity maps for different return periods. Calls local_exceedance_inten. Parameters