Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/dei 255 fix dependencies #138

Merged
merged 15 commits into from
Feb 18, 2025
1 change: 1 addition & 0 deletions decoimpact/business/entities/rule_based_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class RuleBasedModel(IModel):
"""Model class for models based on rules"""

# pylint: disable=too-many-arguments
# pylint: disable=too-many-positional-arguments
# pylint: disable=too-many-instance-attributes
def __init__(
self,
Expand Down
2 changes: 1 addition & 1 deletion decoimpact/business/entities/rules/combine_results_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def execute(

def _create_operations(self) -> dict[MultiArrayOperationType, Callable]:
return {
MultiArrayOperationType.MULTIPLY: lambda npa: _np.product(npa, axis=0),
MultiArrayOperationType.MULTIPLY: lambda npa: _np.prod(npa, axis=0),
MultiArrayOperationType.MIN: lambda npa: _np.min(npa, axis=0),
MultiArrayOperationType.MAX: lambda npa: _np.max(npa, axis=0),
MultiArrayOperationType.AVERAGE: lambda npa: _np.average(npa, axis=0),
Expand Down
3 changes: 2 additions & 1 deletion decoimpact/business/entities/rules/filter_extremes_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

from typing import List

import numpy as _np
import xarray as _xr
from scipy import signal
import numpy as _np

from decoimpact.business.entities.rules.i_array_based_rule import IArrayBasedRule
from decoimpact.business.entities.rules.options.options_filter_extreme_rule import (
Expand All @@ -34,6 +34,7 @@ class FilterExtremesRule(RuleBase, IArrayBasedRule):
"""Implementation for the filter extremes rule"""

# pylint: disable=too-many-arguments
# pylint: disable=too-many-positional-arguments
def __init__(
self,
name: str,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ def _perform_operation(
elif time_scale == "D":
operation_time_delta = _dt.timedelta(days=self._period)
else:
logger.log_error(f"Invalid time scale provided : '{time_scale}'.")
error_message = f"Invalid time scale provided : '{time_scale}'."
logger.log_error(error_message)
raise ValueError(error_message)

time_delta_ms = _np.array([operation_time_delta], dtype="timedelta64[ms]")[0]
last_timestamp = values.time.isel(time=-1).values
Expand Down
70 changes: 36 additions & 34 deletions decoimpact/business/utils/data_array_utils.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
# This file is part of D-EcoImpact
# Copyright (C) 2022-2024 Stichting Deltares
# This program is free software distributed under the
# GNU Affero General Public License version 3.0
# A copy of the GNU Affero General Public License can be found at
# https://github.com/Deltares/D-EcoImpact/blob/main/LICENSE.md
"""Library for utility functions regarding an xarray data-arrays"""

import xarray as _xr

from decoimpact.crosscutting.i_logger import ILogger


def get_time_dimension_name(variable: _xr.DataArray, logger: ILogger) -> str:
"""Retrieves the dimension name

Args:
value_array (DataArray): values to get time dimension

Raises:
ValueError: If time dimension could not be found

Returns:
str: time dimension name
"""

for dim in variable.dims:
dim_values = variable[dim]
if dim_values.dtype.name == "datetime64[ns]":
return str(dim)

message = f"No time dimension found for {variable.name}"
logger.log_error(message)
raise ValueError(message)
# This file is part of D-EcoImpact
# Copyright (C) 2022-2024 Stichting Deltares
# This program is free software distributed under the
# GNU Affero General Public License version 3.0
# A copy of the GNU Affero General Public License can be found at
# https://github.com/Deltares/D-EcoImpact/blob/main/LICENSE.md
"""Library for utility functions regarding an xarray data-arrays"""

import xarray as _xr

from decoimpact.crosscutting.i_logger import ILogger


def get_time_dimension_name(variable: _xr.DataArray, logger: ILogger) -> str:
"""Retrieves the dimension name

Args:
value_array (DataArray): values to get time dimension

Raises:
ValueError: If time dimension could not be found

Returns:
str: time dimension name
"""

for dim in variable.dims:
dim_values = variable[dim]

# check if the dimension type is a datetime type
if dim_values.dtype.name.startswith("datetime64"):
return str(dim)

message = f"No time dimension found for {variable.name}"
logger.log_error(message)
raise ValueError(message)
4 changes: 2 additions & 2 deletions decoimpact/crosscutting/logger_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
"""


from decoimpact.crosscutting.logging_logger import LoggingLogger
from decoimpact.crosscutting.i_logger import ILogger
from decoimpact.crosscutting.logging_logger import LoggingLogger


class LoggerFactory:
"""Factory for creating loggers"""

@ staticmethod
@staticmethod
def create_logger() -> ILogger:
"""Creates a logger

Expand Down
1 change: 1 addition & 0 deletions decoimpact/data/entities/filter_extremes_rule_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class FilterExtremesRuleData(IFilterExtremesRuleData, RuleData):
"""Class for storing data related to filter extremes rule"""

# pylint: disable=too-many-arguments
# pylint: disable=too-many-positional-arguments
def __init__(
self,
name: str,
Expand Down
19 changes: 6 additions & 13 deletions decoimpact/data/parsers/criteria_table_validaton_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,14 @@ def _divide_table_in_unique_chunks(
conditions[key] = unique_c

# Send the remaining filtered parameters back into the function
for message in _divide_table_in_unique_chunks(
yield from _divide_table_in_unique_chunks(
new_crit_table, logger, conditions
):
yield message
)

else:
# If there is only one variable, check on all conditions for coverage
name, criteria = list(criteria_table.items())[0]
for message in _check_variable_conditions(name, criteria, conditions, unique):
yield message
yield from _check_variable_conditions(name, criteria, conditions, unique)


def _check_variable_conditions(
Expand All @@ -201,8 +199,7 @@ def _check_variable_conditions(
criteria = _np.unique(criteria)

# WHen there is only one parameter left in the given table ()
for message in _validate_criteria_on_overlap_and_gaps(name, criteria, cond_str):
yield message
yield from _validate_criteria_on_overlap_and_gaps(name, criteria, cond_str)


def _convert_to_range(val: Any) -> _Range:
Expand Down Expand Up @@ -264,10 +261,7 @@ def _validate_criteria_on_overlap_and_gaps(

# Check if there are multiple larger or larger and equal comparison values are
# present, this will cause overlap
for message in _check_for_multiple_inf_values(
name, pre_warn, sorted_range_criteria
):
yield message
yield from _check_for_multiple_inf_values(name, pre_warn, sorted_range_criteria)

if len(sorted_range_criteria) > 0 and (
sorted_range_criteria[0].start != float("-inf")
Expand All @@ -279,8 +273,7 @@ def _validate_criteria_on_overlap_and_gaps(
"Gap",
)

for message in _check_ranges(name, pre_warn, sorted_range_criteria):
yield message
yield from _check_ranges(name, pre_warn, sorted_range_criteria)

# Create the final check over the not_covered_values and the covered_numbers
# Send warning with the combined messages
Expand Down
Loading