Skip to content

Commit

Permalink
update jira
Browse files Browse the repository at this point in the history
  • Loading branch information
CindyvdVries committed Aug 13, 2024
1 parent 1f271d9 commit 54346b3
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 19 deletions.
29 changes: 15 additions & 14 deletions decoimpact/business/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,23 +84,11 @@ def run(self, input_path: Path):

# build model
for dataset in model_data.datasets:
input_files = self._da_layer.retrieve_partitioned_file_names(
dataset.path
)
input_files = self._da_layer.retrieve_file_names(dataset.path)
output_path_base = Path(model_data.output_path)
for key, file_name in input_files.items():
dataset.path = file_name
if "*" in output_path_base.stem:
output_path = Path(str(output_path_base).replace("*", key))
else:
partition_part = ""
if key:
partition_part = f"_{key}"
output_path = Path.joinpath(
output_path_base.parent,
f"{output_path_base.stem}{partition_part}"
f"{output_path_base.suffix}",
)
output_path = self._generate_output_path(output_path_base, key)

model_data.partition = key
model = self._model_builder.build_model(model_data)
Expand All @@ -121,3 +109,16 @@ def run(self, input_path: Path):

except Exception as exc: # pylint: disable=broad-except
self._logger.log_error(f"Exiting application after error: {exc}")

def _generate_output_path(self, output_path_base, key):
if "*" in output_path_base.stem:
output_path = Path(str(output_path_base).replace("*", key))
else:
partition_part = ""
if key:
partition_part = f"_{key}"
output_path = Path.joinpath(
output_path_base.parent,
f"{output_path_base.stem}{partition_part}" f"{output_path_base.suffix}",
)
return output_path
2 changes: 1 addition & 1 deletion decoimpact/data/api/i_data_access_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class IDataAccessLayer(ABC):
"""Interface for the data layer"""

@abstractmethod
def retrieve_partitioned_file_names(self, path: Path) -> dict:
def retrieve_file_names(self, path: Path) -> dict:
"""
Find all files according to the pattern in the path string
Expand Down
5 changes: 4 additions & 1 deletion decoimpact/data/entities/data_access_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@ class DataAccessLayer(IDataAccessLayer):
def __init__(self, logger: ILogger):
self._logger = logger

def retrieve_partitioned_file_names(self, path: Path) -> dict:
def retrieve_file_names(self, path: Path) -> dict:
"""
Find all files according to the pattern in the path string
If the user gives one filename, one file is returned. The user
can give in a * in the filename and all files that correspond to
that pattern will be retrieved.
Args:
path (str): path to input file (with * for generic part)
Expand Down
2 changes: 1 addition & 1 deletion tests/business/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_running_application():
model.partition = ""
model_builder.build_model.return_value = model
data_layer.read_input_file.return_value = model_data
data_layer.retrieve_partitioned_file_names.return_value = {"": "Test.nc"}
data_layer.retrieve_file_names.return_value = {"": "Test.nc"}
model_data.version = [0, 0, 0]
model_data.datasets = [dataset]
model_data.output_path = "Result_test.nc"
Expand Down
Binary file modified tests/data/entities/test_data_access_layer_data/results.nc
Binary file not shown.
5 changes: 3 additions & 2 deletions tests_acceptance/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@
import pytest
import xarray as _xr
import yaml
import yaml_include


class SafeLoaderIgnoreUnknown(yaml.SafeLoader):
def ignore_unknown(self, node):
return None


SafeLoaderIgnoreUnknown.add_constructor(None, SafeLoaderIgnoreUnknown.ignore_unknown)
SafeLoaderIgnoreUnknown.add_constructor(
"!include", SafeLoaderIgnoreUnknown.ignore_unknown
)

parent_path = Path(__file__).parent

Expand Down

0 comments on commit 54346b3

Please sign in to comment.