Skip to content

Commit

Permalink
updated docstrings and variable frequency unit
Browse files Browse the repository at this point in the history
  • Loading branch information
ValentinGebhart committed Jul 11, 2024
1 parent f228918 commit 5198646
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 24 deletions.
31 changes: 21 additions & 10 deletions climada/hazard/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,19 +458,29 @@ def local_return_period(self, threshold_intensities):
Parameters
----------
threshold_intensities : np.array
Hazard intensities to consider.
User-specified hazard intensities for which the return period should be calculated

Check warning on line 461 in climada/hazard/base.py

View check run for this annotation

Jenkins - WCR / Pylint

trailing-whitespace

LOW: Trailing whitespace
Raw output
Used when there is whitespace between the end of a line and the newline.
locally (at each centroid)

Check warning on line 463 in climada/hazard/base.py

View check run for this annotation

Jenkins - WCR / Pylint

trailing-whitespace

LOW: Trailing whitespace
Raw output
Used when there is whitespace between the end of a line and the newline.
Returns
-------
gdf : gpd.GeoDataFrame
GeoDataFrame containing return periods for given threshold intensity
description of units of values and threshold intensities in gdf.columns.name
GeoDataFrame containing return periods for given threshold intensities. Each column

Check warning on line 467 in climada/hazard/base.py

View check run for this annotation

Jenkins - WCR / Pylint

trailing-whitespace

LOW: Trailing whitespace
Raw output
Used when there is whitespace between the end of a line and the newline.
corresponds to a threshold_intensity value, each row corresponds to a centroid. Values
in the gdf correspond to the return period for the given centroid and threshold_intensity value

Check warning on line 469 in climada/hazard/base.py

View check run for this annotation

Jenkins - WCR / Pylint

line-too-long

LOW: Line too long (107/100)
Raw output
Used when a line is longer than a given number of characters.
gdf_meta : climada.util.plot.GdfMeta
named tuple providing meta data of which quantities (and their units) are written the gdf

Check warning on line 471 in climada/hazard/base.py

View check run for this annotation

Jenkins - WCR / Pylint

line-too-long

LOW: Line too long (101/100)
Raw output
Used when a line is longer than a given number of characters.
"""
#check frequency unit
if self.frequency_unit not in ['1/year', 'annual', '1/y', '1/a']:
LOGGER.warning("The Hazard's frequency unit is %s and not %s which "
"most likely leads to incorrect results",
self.frequency_unit, u_const.DEF_FREQ_UNIT)
if self.frequency_unit in ['1/year', 'annual', '1/y', '1/a']:
rp_unit = 'Years'

Check warning on line 475 in climada/hazard/base.py

View check run for this annotation

Jenkins - WCR / Code Coverage

Not covered line

Line 475 is not covered by tests
elif self.frequency_unit in ['1/month', 'monthly', '1/m']:
rp_unit = 'Months'

Check warning on line 477 in climada/hazard/base.py

View check run for this annotation

Jenkins - WCR / Code Coverage

Not covered line

Line 477 is not covered by tests
elif self.frequency_unit in ['1/week', 'weekly', '1/w']:
rp_unit = 'Weeks'
else:
LOGGER.warning(f"Hazard's frequency unit {self.frequency_unit} is not known, "

Check warning on line 481 in climada/hazard/base.py

View check run for this annotation

Jenkins - WCR / Pylint

logging-fstring-interpolation

NORMAL: Use lazy % formatting in logging functions
Raw output
no description found
"years will be used as return period unit.")
rp_unit = 'Years'

Check warning on line 483 in climada/hazard/base.py

View check run for this annotation

Jenkins - WCR / Code Coverage

Not covered lines

Lines 481-483 are not covered by tests

# Ensure threshold_intensities is a numpy array
threshold_intensities = np.array(threshold_intensities)
Expand Down Expand Up @@ -499,7 +509,7 @@ def local_return_period(self, threshold_intensities):
#create gdf meta data
gdf_meta = GdfMeta(
name = 'Return Period',
unit = 'Years',
unit = rp_unit,
col_name = 'Threshold Intensity',
col_unit = self.units
)
Expand Down Expand Up @@ -676,9 +686,10 @@ def _loc_return_period(self, threshold_intensities, inten):
Parameters
----------
threshold_intensities: np.array
Given hazard intensities for which to calculate return periods.
Test hazard intensities for which to calculate return periods at each centroid.
inten: np.array
The intensity array for a specific chunk of data.
subarray of full hazard intensities corresponding to a subset of the centroids (rows corresponds to

Check warning on line 691 in climada/hazard/base.py

View check run for this annotation

Jenkins - WCR / Pylint

line-too-long

LOW: Line too long (111/100)
Raw output
Used when a line is longer than a given number of characters.
events, columns correspond to centroids)
Returns
-------
Expand Down
2 changes: 0 additions & 2 deletions climada/hazard/test/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@
import unittest
from unittest.mock import patch
import datetime as dt
import os
from pathlib import Path
from tempfile import TemporaryDirectory
import rasterio

from pyproj import CRS
import numpy as np
Expand Down
8 changes: 0 additions & 8 deletions climada/test/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,6 @@ def test_hazard_rp_intensity(self):
(axis1, axis2), _ = hazard.plot_rp_intensity([25, 50])
self.assertEqual('Return period: 25 years', axis1.get_title())
self.assertEqual('Return period: 50 years', axis2.get_title())

# def test_plot_local_rp(self):
# """"Plot local return period maps for different hazard intensities"""
# hazard = Hazard.from_hdf5(HAZ_TEST_TC)
# (axis1, axis2), return_stats = hazard.plot_local_rp([10., 20.])
# self.assertEqual('Intensity: 10.0 m/s', axis1.get_title())
# self.assertEqual('Intensity: 20.0 m/s', axis2.get_title())
# np.testing.assert_array_equal(return_stats.shape, (2, 100))

def test_exposures_value_pass(self):
"""Plot exposures values."""
Expand Down
3 changes: 1 addition & 2 deletions climada/util/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -887,8 +887,7 @@ def subplots_from_gdf(gdf: GeoDataFrame, gdf_meta: GdfMeta = None, smooth=True,
----------
gdf: gpd.GeoDataFrame
return periods per threshold intensity
gdf_meta:
climada.util.plot.GdfMeta
gdf_meta: climada.util.plot.GdfMeta
gdf meta data in named tuple with attributes 'name' (quantity in gdf), 'unit', (unit thereof)

Check warning on line 891 in climada/util/plot.py

View check run for this annotation

Jenkins - WCR / Pylint

line-too-long

LOW: Line too long (105/100)
Raw output
Used when a line is longer than a given number of characters.
'col_name' (quantity in column labels), 'col_unit' (unit thereof)
smooth: bool, optional
Expand Down
4 changes: 2 additions & 2 deletions climada/util/test/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import matplotlib.pyplot as plt
from matplotlib import colormaps as cm
import cartopy.crs as ccrs
from geopandas import GeoDataFrame
import geopandas as gpd
from shapely import Point

import climada.util.plot as u_plot
Expand Down Expand Up @@ -153,7 +153,7 @@ def test_geo_im_from_array(self):
plt.close()

def test_subplots_from_gdf(self):
return_periods = GeoDataFrame(
return_periods = gpd.GeoDataFrame(
data = ((2., 5.), (3., 6.), (None, 2.), (1., 7.)),
columns = ('10.0', '20.0')
)
Expand Down

0 comments on commit 5198646

Please sign in to comment.