diff --git a/CHANGELOG.md b/CHANGELOG.md index d2c238a094..3820756fd3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,9 @@ Code freeze date: YYYY-MM-DD - `Hazard.from_raster_xarray` now returns a sparse matrix instead of a sparse array [#1261](https://github.com/CLIMADA-project/climada_python/pull/1261). - `ImpactCalc.impact` now raises a clear `ValueError` when the supplied `Hazard` contains no events, instead of failing later inside `np.array_split` with an obscure message [#814](https://github.com/CLIMADA-project/climada_python/issues/814). - Fix TCTracks.from_FAST duplicate loading from year loop [#1269](github.com/CLIMADA-project/climada_python/pull/1269) +- `TropCyclone.apply_climate_scenario_knu` now raises its `ValueError` for negative frequencies (the check `any(x) < 0` never triggered) [#1338](https://github.com/CLIMADA-project/climada_python/pull/1338). +- Fix missing spaces and `f` prefixes in warning and error messages [#1338](https://github.com/CLIMADA-project/climada_python/pull/1338). +- Remove debug `print` calls [#1338](https://github.com/CLIMADA-project/climada_python/pull/1338). ### Deprecated - `Impact.calc_freq_curve()` should not be given the parameter `return_per`. Use the parameter `return_periods` in `Impact.calc_freq_curve().interpolate()` instead. diff --git a/climada/engine/calibration_opt.py b/climada/engine/calibration_opt.py index a443f00a09..d9fc8976a6 100644 --- a/climada/engine/calibration_opt.py +++ b/climada/engine/calibration_opt.py @@ -221,7 +221,7 @@ def change_impf(impf_instance, param_dict): ) else: raise AttributeError( - "keys in param_dict not recognized. Use only:" + "keys in param_dict not recognized. Use only: " "paa_shift, paa_scale, mdd_shift, mdd_scale" ) @@ -394,7 +394,6 @@ def calib_all( for x in itertools.product(*param_full_dict.values()) ) for param_dict in params_generator: - print(param_dict) df_out = copy.deepcopy(df_impact_data) impact_func_final, df_out = init_impf(impf_name_or_instance, param_dict, df_out) df_out = calib_instance( @@ -475,7 +474,6 @@ def calib_optimize( # definie specific function to def specific_calib(values): param_dict_temp = dict(zip(param_dict.keys(), values)) - print(param_dict_temp) return calib_instance( hazard, exposure, @@ -519,7 +517,7 @@ def specific_calib(values): else: LOGGER.info( "Opimization did not finish successfully. Check you input" - " or consult the detailed returns (with argument" + " or consult the detailed returns (with argument " "show_details=True) for further information." ) diff --git a/climada/engine/impact.py b/climada/engine/impact.py index a4755c42e7..e029d137e1 100644 --- a/climada/engine/impact.py +++ b/climada/engine/impact.py @@ -283,7 +283,7 @@ def tot_value(self): instead. """ LOGGER.warning( - "The Impact.tot_value attribute is deprecated." + "The Impact.tot_value attribute is deprecated. " "Use Exposures.affected_total_value to calculate the affected " "total exposure value based on a specific hazard intensity " "threshold" @@ -294,7 +294,7 @@ def tot_value(self): def tot_value(self, value): """Set the total exposure value close to a hazard""" LOGGER.warning( - "The Impact.tot_value attribute is deprecated." + "The Impact.tot_value attribute is deprecated. " "Use Exposures.affected_total_value to calculate the affected " "total exposure value based on a specific hazard intensity " "threshold" @@ -485,7 +485,7 @@ def impact_at_reg(self, agg_regions=None): def calc_impact_year_set(self, all_years=True, year_range=None): """This function is deprecated, use Impact.impact_per_year instead.""" LOGGER.warning( - "The use of Impact.calc_impact_year_set is deprecated." + "The use of Impact.calc_impact_year_set is deprecated. " "Use Impact.impact_per_year instead." ) return self.impact_per_year(all_years=all_years, year_range=year_range) @@ -566,7 +566,7 @@ def local_exceedance_impact( ) if self.imp_mat.size == 0: raise ValueError( - "Attribute imp_mat is empty. Recalculate Impact" + "Attribute imp_mat is empty. Recalculate Impact " "instance with parameter save_mat=True" ) @@ -713,7 +713,7 @@ def local_return_period( LOGGER.info("Computing return period map for impacts: %s", threshold_impact) if self.imp_mat.size == 0: raise ValueError( - "Attribute imp_mat is empty. Recalculate Impact" + "Attribute imp_mat is empty. Recalculate Impact " "instance with parameter save_mat=True" ) @@ -1077,7 +1077,7 @@ def plot_hexbin_impact_exposure( """ if self.imp_mat.size == 0: raise ValueError( - "Attribute imp_mat is empty. Recalculate Impact" + "Attribute imp_mat is empty. Recalculate Impact " "instance with parameter save_mat=True" ) if "cmap" not in kwargs: @@ -1145,7 +1145,7 @@ def plot_basemap_impact_exposure( """ if self.imp_mat.size == 0: raise ValueError( - "Attribute imp_mat is empty. Recalculate Impact" + "Attribute imp_mat is empty. Recalculate Impact " "instance with parameter save_mat=True" ) diff --git a/climada/engine/impact_calc.py b/climada/engine/impact_calc.py index 1e274ce445..41e7c01580 100644 --- a/climada/engine/impact_calc.py +++ b/climada/engine/impact_calc.py @@ -252,7 +252,7 @@ def _return_impact(self, imp_mat_gen, save_mat): else: if isinstance(self.hazard, HazardForecast): raise ValueError( - "Saving impact matrix is required when using HazardForecast." + "Saving impact matrix is required when using HazardForecast. " "Please set save_mat=True." ) imp_mat = None diff --git a/climada/engine/impact_data.py b/climada/engine/impact_data.py index 56f16a84ad..3f03033f9c 100644 --- a/climada/engine/impact_data.py +++ b/climada/engine/impact_data.py @@ -898,7 +898,6 @@ def scale_impact2refyear(impact_values, year_values, iso3a_values, reference_yea # get GDP value for each country and year: gdp_years[country] = dict() years_country = np.unique(year_values[iso3a_values == country]) - print(years_country) for year in years_country: gdp_years[country][year] = gdp(country, year)[1] # loop through each value and apply scaling: diff --git a/climada/engine/unsequa/calc_base.py b/climada/engine/unsequa/calc_base.py index 70151d8485..16dcdbcb7f 100644 --- a/climada/engine/unsequa/calc_base.py +++ b/climada/engine/unsequa/calc_base.py @@ -173,7 +173,7 @@ def est_comp_time(self, n_samples, time_one_run, processes=None): if time_one_run > 5: LOGGER.warning( "Computation time for one set of parameters is " - "%.2fs. This is rather long." + "%.2fs. This is rather long. " "Potential reasons: InputVars are loading data, centroids have " "been assigned to exp before defining input_var, ..." "\n If computation cannot be reduced, consider using" @@ -249,7 +249,7 @@ def make_sample(self, N, sampling_method="saltelli", sampling_kwargs=None): if sampling_method == "ff": LOGGER.warning( "You are using the 'ff' sampler which does not require " - "a value for N. The entered N value will be ignored" + "a value for N. The entered N value will be ignored " "in the sampling process." ) uniform_base_sample = self._make_uniform_base_sample( diff --git a/climada/engine/unsequa/calc_delta_climate.py b/climada/engine/unsequa/calc_delta_climate.py index 97d45e8258..8e0053b345 100644 --- a/climada/engine/unsequa/calc_delta_climate.py +++ b/climada/engine/unsequa/calc_delta_climate.py @@ -235,7 +235,7 @@ def uncertainty( if unc_sample.samples_df.empty: raise ValueError( - "No sample was found. Please create one first" + "No sample was found. Please create one first " "using UncImpact.make_sample(N)" ) diff --git a/climada/engine/unsequa/calc_impact.py b/climada/engine/unsequa/calc_impact.py index 93d3fc6584..5b96c17254 100644 --- a/climada/engine/unsequa/calc_impact.py +++ b/climada/engine/unsequa/calc_impact.py @@ -197,7 +197,7 @@ def uncertainty( if unc_sample.samples_df.empty: raise ValueError( - "No sample was found. Please create one first" + "No sample was found. Please create one first " "using UncImpact.make_sample(N)" ) diff --git a/climada/entity/_legacy_measures/measure_set.py b/climada/entity/_legacy_measures/measure_set.py index 228788ba15..dbdaf386fa 100755 --- a/climada/entity/_legacy_measures/measure_set.py +++ b/climada/entity/_legacy_measures/measure_set.py @@ -451,7 +451,7 @@ def read_att_mat(measures, data, file_name, var_names): def read_mat(self, *args, **kwargs): """This function is deprecated, use MeasureSet.from_mat instead.""" LOGGER.warning( - "The use of MeasureSet.read_mat is deprecated." + "The use of MeasureSet.read_mat is deprecated. " "Use MeasureSet.from_mat instead." ) self.__dict__ = MeasureSet.from_mat(*args, **kwargs).__dict__ @@ -557,7 +557,7 @@ def read_att_excel(measures, dfr, var_names): def read_excel(self, *args, **kwargs): """This function is deprecated, use MeasureSet.from_excel instead.""" LOGGER.warning( - "The use ofMeasureSet.read_excel is deprecated." + "The use of MeasureSet.read_excel is deprecated. " "Use MeasureSet.from_excel instead." ) self.__dict__ = MeasureSet.from_excel(*args, **kwargs).__dict__ diff --git a/climada/entity/disc_rates/base.py b/climada/entity/disc_rates/base.py index e18daaf919..09513e7d36 100755 --- a/climada/entity/disc_rates/base.py +++ b/climada/entity/disc_rates/base.py @@ -259,7 +259,7 @@ def from_mat(cls, file_name, var_names=None): def read_mat(self, *args, **kwargs): """This function is deprecated, use ``DiscRates.from_mat`` instead.""" LOGGER.warning( - "The use of DiscRates.read_mat is deprecated." + "The use of DiscRates.read_mat is deprecated. " "Use DiscRates.from_mat instead." ) self.__dict__ = DiscRates.from_mat(*args, **kwargs).__dict__ @@ -305,7 +305,7 @@ def from_excel(cls, file_name, var_names=None): def read_excel(self, *args, **kwargs): """This function is deprecated, use DiscRates.from_excel instead.""" LOGGER.warning( - "The use of DiscRates.read_excel is deprecated." + "The use of DiscRates.read_excel is deprecated. " "Use DiscRates.from_excel instead." ) self.__dict__ = DiscRates.from_excel(*args, **kwargs).__dict__ diff --git a/climada/entity/entity_def.py b/climada/entity/entity_def.py index c1bc3b2550..634adb1038 100755 --- a/climada/entity/entity_def.py +++ b/climada/entity/entity_def.py @@ -105,7 +105,7 @@ def from_mat(cls, file_name): def read_mat(self, *args, **kwargs): """This function is deprecated, use Entity.from_mat instead.""" LOGGER.warning( - "The use of Entity.read_mat is deprecated." "Use Entity.from_mat instead." + "The use of Entity.read_mat is deprecated. Use Entity.from_mat instead." ) self.__dict__ = Entity.from_mat(*args, **kwargs).__dict__ diff --git a/climada/entity/exposures/base.py b/climada/entity/exposures/base.py index 1989e0fd80..04a4c276e7 100644 --- a/climada/entity/exposures/base.py +++ b/climada/entity/exposures/base.py @@ -1180,7 +1180,7 @@ def write_hdf5(self, file_name): def read_hdf5(self, *args, **kwargs): """This function is deprecated, use Exposures.from_hdf5 instead.""" LOGGER.warning( - "The use of Exposures.read_hdf5 is deprecated." + "The use of Exposures.read_hdf5 is deprecated. " "Use Exposures.from_hdf5 instead." ) self.__dict__ = Exposures.from_hdf5(*args, **kwargs).__dict__ @@ -1233,7 +1233,7 @@ def from_hdf5(cls, file_name): def read_mat(self, *args, **kwargs): """This function is deprecated, use Exposures.from_mat instead.""" LOGGER.warning( - "The use of Exposures.read_mat is deprecated." + "The use of Exposures.read_mat is deprecated. " "Use Exposures.from_mat instead." ) self.__dict__ = Exposures.from_mat(*args, **kwargs).__dict__ diff --git a/climada/entity/exposures/litpop/litpop.py b/climada/entity/exposures/litpop/litpop.py index ef28b3ba5d..9d1d5ad5b7 100644 --- a/climada/entity/exposures/litpop/litpop.py +++ b/climada/entity/exposures/litpop/litpop.py @@ -94,7 +94,7 @@ def __init__( def set_countries(self, *args, **kwargs): """This function is deprecated, use LitPop.from_countries instead.""" LOGGER.warning( - "The use of LitPop.set_countries is deprecated." + "The use of LitPop.set_countries is deprecated. " "Use LitPop.from_countries instead." ) self.__dict__ = LitPop.from_countries(*args, **kwargs).__dict__ @@ -307,7 +307,7 @@ def from_countries( def set_nightlight_intensity(self, *args, **kwargs): """This function is deprecated, use LitPop.from_nightlight_intensity instead.""" LOGGER.warning( - "The use of LitPop.set_nightlight_intensity is deprecated." + "The use of LitPop.set_nightlight_intensity is deprecated. " "Use LitPop.from_nightlight_intensity instead." ) self.__dict__ = LitPop.from_nightlight_intensity(*args, **kwargs).__dict__ @@ -409,7 +409,7 @@ def from_nightlight_intensity( def set_population(self, *args, **kwargs): """This function is deprecated, use LitPop.from_population instead.""" LOGGER.warning( - "The use of LitPop.set_population is deprecated." + "The use of LitPop.set_population is deprecated. " "Use LitPop.from_population instead." ) self.__dict__ = LitPop.from_population(*args, **kwargs).__dict__ @@ -510,7 +510,7 @@ def from_population( def set_custom_shape_from_countries(self, *args, **kwargs): """This function is deprecated, use LitPop.from_shape_and_countries instead.""" LOGGER.warning( - "The use of LitPop.set_custom_shape_from_countries is deprecated." + "The use of LitPop.set_custom_shape_from_countries is deprecated. " "Use LitPop.from_shape_and_countries instead." ) self.__dict__ = LitPop.from_shape_and_countries(*args, **kwargs).__dict__ @@ -646,7 +646,7 @@ def from_shape_and_countries( gdf = exp.gdf.loc[idx] else: raise NotImplementedError( - "Not implemented for `shape` of type {type(shape)}" + f"Not implemented for `shape` of type {type(shape)}" ) exp.description = ( @@ -681,7 +681,7 @@ def from_shape_and_countries( def set_custom_shape(self, *args, **kwargs): """This function is deprecated, use LitPop.from_shape instead.""" LOGGER.warning( - "The use of LitPop.set_custom_shape is deprecated." + "The use of LitPop.set_custom_shape is deprecated. " "Use LitPop.from_shape instead." ) self.__dict__ = LitPop.from_shape(*args, **kwargs).__dict__ diff --git a/climada/entity/impact_funcs/base.py b/climada/entity/impact_funcs/base.py index 3642eed7a8..ff7a7c2482 100644 --- a/climada/entity/impact_funcs/base.py +++ b/climada/entity/impact_funcs/base.py @@ -306,7 +306,7 @@ def from_sigmoid_impf( def set_sigmoid_impf(self, *args, **kwargs): """This function is deprecated, use LitPop.from_countries instead.""" LOGGER.warning( - "The use of ImpactFunc.set_sigmoid_impf is deprecated." + "The use of ImpactFunc.set_sigmoid_impf is deprecated. " "Use ImpactFunc.from_sigmoid_impf instead." ) self.__dict__ = ImpactFunc.from_sigmoid_impf(*args, **kwargs).__dict__ diff --git a/climada/entity/impact_funcs/impact_func_set.py b/climada/entity/impact_funcs/impact_func_set.py index b6f4cf73d7..6c6ccd13e6 100755 --- a/climada/entity/impact_funcs/impact_func_set.py +++ b/climada/entity/impact_funcs/impact_func_set.py @@ -535,7 +535,7 @@ def _get_hdf5_str(imp, idxs, file_name, var_name): def read_mat(self, *args, **kwargs): """This function is deprecated, use ImpactFuncSet.from_mat instead.""" LOGGER.warning( - "The use of ImpactFuncSet.read_mat is deprecated." + "The use of ImpactFuncSet.read_mat is deprecated. " "Use ImpactFuncSet.from_mat instead." ) self.__dict__ = ImpactFuncSet.from_mat(*args, **kwargs).__dict__ diff --git a/climada/entity/impact_funcs/storm_europe.py b/climada/entity/impact_funcs/storm_europe.py index 76973c3df2..9f4a0588f5 100644 --- a/climada/entity/impact_funcs/storm_europe.py +++ b/climada/entity/impact_funcs/storm_europe.py @@ -118,7 +118,7 @@ def set_schwierz(self, impf_id=1): instead. """ LOGGER.warning( - "The use of ImpfStormEurope.set_schwierz is deprecated." + "The use of ImpfStormEurope.set_schwierz is deprecated. " "Use ImpfStormEurope.from_schwierz instead." ) self.__dict__ = ImpfStormEurope.from_schwierz(impf_id=impf_id).__dict__ @@ -129,7 +129,7 @@ def set_welker(self, impf_id=1): instead. """ LOGGER.warning( - "The use of ImpfStormEurope.set_welker is deprecated." + "The use of ImpfStormEurope.set_welker is deprecated. " "Use ImpfStormEurope.from_welker instead." ) self.__dict__ = ImpfStormEurope.from_welker(impf_id=impf_id).__dict__ diff --git a/climada/entity/impact_funcs/trop_cyclone.py b/climada/entity/impact_funcs/trop_cyclone.py index ac578fde1e..45fdd3447e 100644 --- a/climada/entity/impact_funcs/trop_cyclone.py +++ b/climada/entity/impact_funcs/trop_cyclone.py @@ -135,7 +135,7 @@ def __init__(self): def set_emanuel_usa(self, *args, **kwargs): """This function is deprecated, use from_emanuel_usa() instead.""" LOGGER.warning( - "The use of ImpfTropCyclone.set_emanuel_usa is deprecated." + "The use of ImpfTropCyclone.set_emanuel_usa is deprecated. " "Use ImpfTropCyclone.from_emanuel_usa instead." ) self.__dict__ = ImpfTropCyclone.from_emanuel_usa(*args, **kwargs).__dict__ @@ -210,7 +210,7 @@ def __init__(self): def set_calibrated_regional_ImpfSet(self, *args, **kwargs): """This function is deprecated, use from_calibrated_regional_ImpfSet() instead.""" LOGGER.warning( - "ImpfSetTropCyclone.set_calibrated_regional_ImpfSet is deprecated." + "ImpfSetTropCyclone.set_calibrated_regional_ImpfSet is deprecated. " "Use ImpfSetTropCyclone.from_calibrated_regional_ImpfSet instead." ) self.__dict__ = ImpfSetTropCyclone.from_calibrated_regional_ImpfSet( diff --git a/climada/hazard/base.py b/climada/hazard/base.py index b06c22e989..8aa875fd39 100644 --- a/climada/hazard/base.py +++ b/climada/hazard/base.py @@ -855,7 +855,7 @@ def set_frequency(self, yearrange=None): """ if self.frequency_unit not in ["1/year", "annual", "1/y", "1/a"]: LOGGER.warning( - "setting the frequency on a hazard object who's frequency unit" + "setting the frequency on a hazard object who's frequency unit " "is %s and not %s will most likely lead to unexpected results", self.frequency_unit, u_const.DEF_FREQ_UNIT, @@ -1208,8 +1208,8 @@ def get_mdr(self, cent_idx, impf): mdr.data = impf.calc_mdr(mdr.data) else: LOGGER.warning( - "Impact function id=%d has mdr(0) != 0." - "The mean damage ratio must thus be computed for all values of" + "Impact function id=%d has mdr(0) != 0. " + "The mean damage ratio must thus be computed for all values of " "hazard intensity including 0 which can be very time consuming.", impf.id, ) diff --git a/climada/hazard/centroids/centr.py b/climada/hazard/centroids/centr.py index 7fcc769b52..a2e08b26c4 100644 --- a/climada/hazard/centroids/centr.py +++ b/climada/hazard/centroids/centr.py @@ -1091,7 +1091,7 @@ def _ne_crs_geom(self): @classmethod @deprecated( - details="Reading Centroids data from matlab files is not supported anymore." + details="Reading Centroids data from matlab files is not supported anymore. " "This method has been removed with climada 5.0" ) def from_mat(cls, file_name, var_names=None): diff --git a/climada/hazard/io.py b/climada/hazard/io.py index 03e608d050..dc99057694 100644 --- a/climada/hazard/io.py +++ b/climada/hazard/io.py @@ -98,7 +98,7 @@ class HazardIO: def set_raster(self, *args, **kwargs): """This function is deprecated, use Hazard.from_raster.""" LOGGER.warning( - "The use of Hazard.set_raster is deprecated." + "The use of Hazard.set_raster is deprecated. " "Use Hazard.from_raster instead." ) self.__dict__ = self.__class__.from_raster(*args, **kwargs).__dict__ @@ -783,7 +783,7 @@ def _attrs_to_kwargs(attrs: Dict[str, Any], num_events: int) -> Dict[str, Any]: def read_excel(self, *args, **kwargs): """This function is deprecated, use Hazard.from_excel.""" LOGGER.warning( - "The use of Hazard.read_excel is deprecated." + "The use of Hazard.read_excel is deprecated. " "Use Hazard.from_excel instead." ) self.__dict__ = self.__class__.from_excel(*args, **kwargs).__dict__ @@ -961,7 +961,8 @@ def write_hdf5(self, file_name, todense=False): def read_hdf5(self, *args, **kwargs): """This function is deprecated, use Hazard.from_hdf5.""" LOGGER.warning( - "The use of Hazard.read_hdf5 is deprecated." "Use Hazard.from_hdf5 instead." + "The use of Hazard.read_hdf5 is deprecated. " + "Use Hazard.from_hdf5 instead." ) self.__dict__ = self.__class__.from_hdf5(*args, **kwargs).__dict__ diff --git a/climada/hazard/storm_europe.py b/climada/hazard/storm_europe.py index 2fe7c6c861..23a50fc946 100644 --- a/climada/hazard/storm_europe.py +++ b/climada/hazard/storm_europe.py @@ -130,7 +130,7 @@ def __init__( def read_footprints(self, *args, **kwargs): """This function is deprecated, use StormEurope.from_footprints instead.""" LOGGER.warning( - "The use of StormEurope.read_footprints is deprecated." + "The use of StormEurope.read_footprints is deprecated. " "Use StormEurope.from_footprints instead." ) self.__dict__ = StormEurope.from_footprints(*args, **kwargs).__dict__ @@ -288,7 +288,7 @@ def _read_one_nc(cls, file_name, centroids, intensity_thres): def read_cosmoe_file(self, *args, **kwargs): """This function is deprecated, use StormEurope.from_cosmoe_file instead.""" LOGGER.warning( - "The use of StormEurope.read_cosmoe_file is deprecated." + "The use of StormEurope.read_cosmoe_file is deprecated. " "Use StormEurope.from_cosmoe_file instead." ) self.__dict__ = StormEurope.from_cosmoe_file(*args, **kwargs).__dict__ @@ -357,7 +357,7 @@ def from_cosmoe_file( "Extraction of date and coordinates failed. This is most likely " "because the selected event_date " f'{event_date.strftime("%Y-%m-%d")} is not contained in the ' - "weather forecast selected by fp_file {fp_file}. Please adjust " + f"weather forecast selected by fp_file {fp_file}. Please adjust " f"event_date or fp_file." ) from ker considered_dates = np.datetime64(event_date) @@ -419,7 +419,7 @@ def from_cosmoe_file( def read_icon_grib(self, *args, **kwargs): """This function is deprecated, use StormEurope.from_icon_grib instead.""" LOGGER.warning( - "The use of StormEurope.read_icon_grib is deprecated." + "The use of StormEurope.read_icon_grib is deprecated. " "Use StormEurope.from_icon_grib instead." ) self.__dict__ = StormEurope.from_icon_grib(*args, **kwargs).__dict__ diff --git a/climada/hazard/tc_clim_change.py b/climada/hazard/tc_clim_change.py index 1745c43f3e..2848431251 100644 --- a/climada/hazard/tc_clim_change.py +++ b/climada/hazard/tc_clim_change.py @@ -135,7 +135,7 @@ def get_knutson_scaling_factor( ): raise ValueError( - "The selected historical baseline falls outside" + "The selected historical baseline falls outside " f"the GMST data period {gmst_info['gmst_start_year']}" f"-{gmst_info['gmst_end_year']}" ) @@ -160,7 +160,7 @@ def get_knutson_scaling_factor( except KeyError: LOGGER.warning( - f"No scaling factors are defined for basin {basin} therefore" + f"No scaling factors are defined for basin {basin} therefore " "no change will be projected for tracks in this basin" ) return pd.DataFrame( diff --git a/climada/hazard/tc_tracks.py b/climada/hazard/tc_tracks.py index 71b9c69558..c0b75d9816 100644 --- a/climada/hazard/tc_tracks.py +++ b/climada/hazard/tc_tracks.py @@ -1677,7 +1677,7 @@ def equal_timestep(self, time_step_h=1, land_params=False, pool=None): def calc_random_walk(self, **kwargs): """Deprecated. Use `TCTracks.calc_perturbed_trajectories` instead.""" LOGGER.warning( - "The use of TCTracks.calc_random_walk is deprecated." + "The use of TCTracks.calc_random_walk is deprecated. " "Use TCTracks.calc_perturbed_trajectories instead." ) if kwargs.get("ens_size"): diff --git a/climada/hazard/test/test_trop_cyclone.py b/climada/hazard/test/test_trop_cyclone.py index b04ae3420c..c4a3f9cd0c 100644 --- a/climada/hazard/test/test_trop_cyclone.py +++ b/climada/hazard/test/test_trop_cyclone.py @@ -475,6 +475,16 @@ def test_apply_climate_scenario_knu_calculations(self): future_tc.frequency[cat45_sel & basin_sel], ) + def test_knu_negative_frequency(self): + """A scenario that makes a frequency negative must raise.""" + self.create_tc() + # Mostly intense storms: the weak storms would need to lose more than 100% of their frequency. + self.tc.category = np.array([4, 4, 0, 1]) + with self.assertRaises(ValueError): + self.tc.apply_climate_scenario_knu( + percentile="90/95", scenario="8.5", target_year=2100 + ) + def test_apply_climate_scenario_knu_target_year_out_of_range(self): self.create_tc() with self.assertRaises(KeyError): diff --git a/climada/hazard/trop_cyclone/trop_cyclone.py b/climada/hazard/trop_cyclone/trop_cyclone.py index a42c226e28..3455485d26 100644 --- a/climada/hazard/trop_cyclone/trop_cyclone.py +++ b/climada/hazard/trop_cyclone/trop_cyclone.py @@ -435,8 +435,8 @@ def apply_climate_scenario_knu( if self.category.size == 0: LOGGER.warning( - "Tropical cyclone categories are missing and" - "no effect of climate change can be modelled." + "Tropical cyclone categories are missing and " + "no effect of climate change can be modelled. " "The original event set is returned" ) return self @@ -478,7 +478,7 @@ def apply_climate_scenario_knu( tc_cc.frequency[sel_cat03 & bas_sel] *= 1 + scale_year_rcp_03 / 100 tc_cc.frequency[sel_cat45 & bas_sel] *= 1 + scale_year_rcp_45 / 100 - if any(tc_cc.frequency) < 0: + if np.any(tc_cc.frequency < 0): raise ValueError( " The application of the climate scenario leads to " " negative frequencies. One solution - if appropriate -" @@ -490,7 +490,7 @@ def apply_climate_scenario_knu( def set_climate_scenario_knu(self, *args, **kwargs): """This function is deprecated, use TropCyclone.apply_climate_scenario_knu instead.""" LOGGER.warning( - "The use of TropCyclone.set_climate_scenario_knu is deprecated." + "The use of TropCyclone.set_climate_scenario_knu is deprecated. " "Use TropCyclone.apply_climate_scenario_knu instead." ) return self.apply_climate_scenario_knu(*args, **kwargs) @@ -785,7 +785,7 @@ def _apply_knutson_criterion(self, chg_int_freq: List, scaling_rcp_year: float): if (tc_cc.frequency < 0).any(): raise ValueError( - "The application of the given climate scenario" + "The application of the given climate scenario " "resulted in at least one negative frequency." ) diff --git a/climada/hazard/trop_cyclone/trop_cyclone_windfields.py b/climada/hazard/trop_cyclone/trop_cyclone_windfields.py index a33ac6bf25..db46319c25 100644 --- a/climada/hazard/trop_cyclone/trop_cyclone_windfields.py +++ b/climada/hazard/trop_cyclone/trop_cyclone_windfields.py @@ -131,7 +131,7 @@ def compute_angular_windspeeds( if cyclostrophic is not None: warnings.warn( - "The 'cyclostrophic' argument is deprecated and will be removed in a future" + "The 'cyclostrophic' argument is deprecated and will be removed in a future " "release. Include it in 'model_kwargs' instead.", DeprecationWarning, ) diff --git a/climada/util/coordinates.py b/climada/util/coordinates.py index 2c6320383c..ff50b3b3a7 100644 --- a/climada/util/coordinates.py +++ b/climada/util/coordinates.py @@ -1128,7 +1128,7 @@ def estimate_matching_threshold(coords_to_assign): """ if len(coords_to_assign) < 2: raise ValueError( - "The coordinate assignement threshold cannot be" + "The coordinate assignement threshold cannot be " "estimated for a single coordinate. Please set the threshold explicitly" ) return 2 * max(abs(r) for r in get_resolution(coords_to_assign.T)) diff --git a/climada/util/interpolation.py b/climada/util/interpolation.py index bf64f37cd7..87b9fc0a3b 100644 --- a/climada/util/interpolation.py +++ b/climada/util/interpolation.py @@ -392,7 +392,7 @@ def _group_frequency(frequency, value, bin_decimals): if value_unique.size != frequency.size: if not all(sorted(start_indices) == start_indices): LOGGER.warning( - "After grouping values using to their decimals, the value array is not sorted." + "After grouping values using to their decimals, the value array is not sorted. " "The values are not binned. This might be due to floating point error while " "binning. Please choose a larger value of bin_decimals=%s.", bin_decimals, diff --git a/climada/util/lines_polys_handler.py b/climada/util/lines_polys_handler.py index 8bcfd7899f..49c2e90696 100755 --- a/climada/util/lines_polys_handler.py +++ b/climada/util/lines_polys_handler.py @@ -604,7 +604,7 @@ def gdf_to_grid(gdf, grid): if line_mask.any() or pnt_mask.any(): raise AttributeError( - "The dataframe contains lines and/or polygons." + "The dataframe contains lines and/or polygons. " "Currently only polygon dataframes can be " "disaggregated onto a fixed grid." ) diff --git a/climada/util/test/test_coordinates.py b/climada/util/test/test_coordinates.py index b0703c568a..b9a24a4760 100644 --- a/climada/util/test/test_coordinates.py +++ b/climada/util/test/test_coordinates.py @@ -446,7 +446,7 @@ def test_estimate_matching_threshold(self): with self.assertRaises(ValueError) as cm: u_coord.estimate_matching_threshold(coords_fail) self.assertIn( - "The coordinate assignement threshold cannot be" + "The coordinate assignement threshold cannot be " "estimated for a single coordinate. Please set the threshold explicitly", str(cm.exception), )