-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #138 from Deltares/fix/DEI-255_fix_dependencies
Fix/dei 255 fix dependencies
- Loading branch information
Showing
11 changed files
with
591 additions
and
639 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.