Skip to content

Commit

Permalink
Added index descriptions and input data to Handler
Browse files Browse the repository at this point in the history
  • Loading branch information
DahyannAraya committed Sep 24, 2024
1 parent a272ffe commit 153bfcb
Show file tree
Hide file tree
Showing 2 changed files with 501 additions and 434 deletions.
56 changes: 56 additions & 0 deletions climada_petals/hazard/copernicus_forecast/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,62 @@ def __init__(self, data_dir='.', URL = None, KEY = None):
self.URL = URL

Check warning on line 82 in climada_petals/hazard/copernicus_forecast/handler.py

View check run for this annotation

Jenkins - WCR / Pylint

invalid-name

LOW: Attribute name "URL" doesn't conform to '(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$' pattern
Raw output
Used when the name doesn't match the regular expression associated to its type(constant, variable, class...).

Check warning on line 83 in climada_petals/hazard/copernicus_forecast/handler.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.

# Dictionary with explanations and input data for each index
self.index_explanations = {
"HIA": {
"explanation": "Heat Index Adjusted: This indicator measures apparent temperature, considering both air temperature and humidity, providing a more accurate perception of how hot it feels.",

Check warning on line 88 in climada_petals/hazard/copernicus_forecast/handler.py

View check run for this annotation

Jenkins - WCR / Pylint

line-too-long

LOW: Line too long (205/100)
Raw output
Used when a line is longer than a given number of characters.
"input_data": ["2m temperature (t2m)", "2m dewpoint temperature (d2m)"]
},
"HIS": {
"explanation": "Heat Index Simplified: This indicator is a simpler version of the Heat Index, focusing on a quick estimate of perceived heat based on temperature and humidity.",

Check warning on line 92 in climada_petals/hazard/copernicus_forecast/handler.py

View check run for this annotation

Jenkins - WCR / Pylint

line-too-long

LOW: Line too long (193/100)
Raw output
Used when a line is longer than a given number of characters.
"input_data": ["2m temperature (t2m)", "2m dewpoint temperature (d2m)"]
},
"Tmean": {
"explanation": "Mean Temperature: This indicator calculates the average temperature over the specified period.",

Check warning on line 96 in climada_petals/hazard/copernicus_forecast/handler.py

View check run for this annotation

Jenkins - WCR / Pylint

line-too-long

LOW: Line too long (128/100)
Raw output
Used when a line is longer than a given number of characters.
"input_data": ["2m temperature (t2m)"]
},
"Tmin": {
"explanation": "Minimum Temperature: This indicator tracks the lowest temperature recorded over a specified period.",

Check warning on line 100 in climada_petals/hazard/copernicus_forecast/handler.py

View check run for this annotation

Jenkins - WCR / Pylint

line-too-long

LOW: Line too long (133/100)
Raw output
Used when a line is longer than a given number of characters.
"input_data": ["2m temperature (t2m)"]
},
"Tmax": {
"explanation": "Maximum Temperature: This indicator tracks the highest temperature recorded over a specified period.",

Check warning on line 104 in climada_petals/hazard/copernicus_forecast/handler.py

View check run for this annotation

Jenkins - WCR / Pylint

line-too-long

LOW: Line too long (134/100)
Raw output
Used when a line is longer than a given number of characters.
"input_data": ["2m temperature (t2m)"]
},
"HW": {
"explanation": "Heat Wave: This indicator identifies heat waves, defined as at least 3 consecutive days with temperatures exceeding a certain threshold.",

Check warning on line 108 in climada_petals/hazard/copernicus_forecast/handler.py

View check run for this annotation

Jenkins - WCR / Pylint

line-too-long

LOW: Line too long (170/100)
Raw output
Used when a line is longer than a given number of characters.
"input_data": ["2m temperature (t2m)"]
},
"TR": {
"explanation": "Tropical Nights: This indicator counts the number of nights where the minimum temperature remains above a certain threshold, typically 20°C.",

Check warning on line 112 in climada_petals/hazard/copernicus_forecast/handler.py

View check run for this annotation

Jenkins - WCR / Pylint

line-too-long

LOW: Line too long (174/100)
Raw output
Used when a line is longer than a given number of characters.
"input_data": ["2m temperature (t2m)"]
},
"HotDays": {
"explanation": "Hot Days: This indicator counts the number of days where the maximum temperature exceeds 30°C.",

Check warning on line 116 in climada_petals/hazard/copernicus_forecast/handler.py

View check run for this annotation

Jenkins - WCR / Pylint

line-too-long

LOW: Line too long (128/100)
Raw output
Used when a line is longer than a given number of characters.
"input_data": ["2m temperature (t2m)"]
}
}

def explain_index(self, tf_index):
"""
Provides an explanation and input data for the selected index.
Parameters:
tf_index (str): The climate index identifier.
Returns:
str: A description of the selected index, its input data, or an error message if the index is invalid.

Check warning on line 129 in climada_petals/hazard/copernicus_forecast/handler.py

View check run for this annotation

Jenkins - WCR / Pylint

line-too-long

LOW: Line too long (110/100)
Raw output
Used when a line is longer than a given number of characters.
"""
if tf_index in self.index_explanations:
explanation = f"Selected Index: {tf_index}\n"
explanation += f"Explanation: {self.index_explanations[tf_index]['explanation']}\n"
explanation += f"Input Data: {', '.join(self.index_explanations[tf_index]['input_data'])}"

Check warning on line 134 in climada_petals/hazard/copernicus_forecast/handler.py

View check run for this annotation

Jenkins - WCR / Pylint

line-too-long

LOW: Line too long (102/100)
Raw output
Used when a line is longer than a given number of characters.
else:
explanation = f"Error: {tf_index} is not a valid index. Please choose from {list(self.index_explanations.keys())}"

Check warning on line 136 in climada_petals/hazard/copernicus_forecast/handler.py

View check run for this annotation

Jenkins - WCR / Pylint

line-too-long

LOW: Line too long (126/100)
Raw output
Used when a line is longer than a given number of characters.

return explanation

Check warning on line 139 in climada_petals/hazard/copernicus_forecast/handler.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.

def calc_min_max_lead(self, year, month, leadtime_months=1):

Check warning on line 141 in climada_petals/hazard/copernicus_forecast/handler.py

View check run for this annotation

Jenkins - WCR / Pylint

no-self-use

LOW: Method could be a function
Raw output
Used when a method doesn't use its bound instance, and so could be written asa function.
"""
Calculates the minimum and maximum lead time in hours for a given starting date.
Expand Down
Loading

0 comments on commit 153bfcb

Please sign in to comment.