Skip to content

Commit

Permalink
update review part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
CindyvdVries committed Aug 6, 2024
1 parent c0f0921 commit 61ce875
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 10 additions & 5 deletions decoimpact/business/entities/rules/filter_extremes_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,15 @@ def validate(self, logger: ILogger) -> bool:
return self.settings.validate(self.name, logger)

def execute(self, value_array: _xr.DataArray, logger: ILogger) -> _xr.DataArray:
"""Retrieve the peak or through values
"""
Retrieve the extremes
extreme_type: Either retrieve the values at the peaks or troughs
mask: If False return the values at the peaks, otherwise return a
1 at the extreme locations.
Args:
value_array (DataArray): Values to filter at extremes
Returns:
DataArray: Filtered DataArray with only the extremes remaining
at all other times the values are set to NaN
Expand All @@ -92,15 +98,14 @@ def execute(self, value_array: _xr.DataArray, logger: ILogger) -> _xr.DataArray:
)

time_dim_name = get_time_dimension_name(value_array, logger)
old_dr = _xr.DataArray(value_array)
time = old_dr.time.values
time = value_array.time.values
timestep = (time[-1] - time[0]) / len(time)
width_time = _np.timedelta64(self.distance, time_scale)
distance = width_time / timestep

results = _xr.apply_ufunc(
self._process_peaks,
old_dr,
value_array,
input_core_dims=[[time_dim_name]],
output_core_dims=[[time_dim_name]],
vectorize=True,
Expand All @@ -111,7 +116,7 @@ def execute(self, value_array: _xr.DataArray, logger: ILogger) -> _xr.DataArray:
},
)

results = results.transpose(*old_dr.dims)
results = results.transpose(*value_array.dims)
return results

def _process_peaks(
Expand Down
2 changes: 1 addition & 1 deletion decoimpact/data/parsers/parser_filter_extremes_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def parse_dict(self, dictionary: Dict[str, Any], logger: ILogger) -> IRuleData:
]
output_variable_name: str = get_dict_element("output_variable", dictionary)
description: str = get_dict_element("description", dictionary, False) or ""
extreme_type: str = get_dict_element("extreme_type", dictionary)
extreme_type: str = get_dict_element("extreme_type", dictionary) or "peaks"
distance: int = get_dict_element("distance", dictionary) or 0
time_scale: str = get_dict_element("time_scale", dictionary) or "D"

Expand Down

0 comments on commit 61ce875

Please sign in to comment.