From caf753bd25b7f7e95ec137741af926bee00f3b82 Mon Sep 17 00:00:00 2001 From: leufen1 <l.leufen@fz-juelich.de> Date: Wed, 27 Jan 2021 14:43:49 +0100 Subject: [PATCH] set experiment name now can handle strings and tuples of strings, /close #263 --- mlair/configuration/path_config.py | 9 +++++---- test/test_configuration/test_path_config.py | 8 ++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/mlair/configuration/path_config.py b/mlair/configuration/path_config.py index 67c6bce4..e7418b98 100644 --- a/mlair/configuration/path_config.py +++ b/mlair/configuration/path_config.py @@ -4,13 +4,13 @@ import logging import os import re import socket -from typing import Tuple +from typing import Union # ROOT_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")) ROOT_PATH = os.getcwd() -def prepare_host(create_new=True, data_path=None, sampling="daily") -> str: +def prepare_host(create_new=True, data_path=None) -> str: """ Set up host path. @@ -20,7 +20,6 @@ def prepare_host(create_new=True, data_path=None, sampling="daily") -> str: :param create_new: Create new path if enabled :param data_path: Parse your custom path (and therefore ignore preset paths fitting to known hosts) - :param sampling: sampling rate to separate data physically by temporal resolution (deprecated) :return: full path to data """ @@ -73,7 +72,7 @@ def set_experiment_path(name: str, path: str = None) -> str: return experiment_path -def set_experiment_name(name: str = None, sampling: str = None) -> str: +def set_experiment_name(name: str = None, sampling: Union[str, tuple] = None) -> str: """ Set name of experiment and its path. @@ -90,6 +89,8 @@ def set_experiment_name(name: str = None, sampling: str = None) -> str: else: experiment_name = f"{name}_network" if sampling is not None: + if not isinstance(sampling, str): + sampling = sampling[-1] experiment_name += f"_{sampling}" return experiment_name diff --git a/test/test_configuration/test_path_config.py b/test/test_configuration/test_path_config.py index fb8a2b19..996550bf 100644 --- a/test/test_configuration/test_path_config.py +++ b/test/test_configuration/test_path_config.py @@ -68,6 +68,14 @@ class TestSetExperimentName: exp_name = set_experiment_name(sampling="daily") assert exp_name == "TestExperiment_daily" + def test_set_experiment_name_tuple_sampling(self): + exp_name = set_experiment_name(sampling=("hourly")) + assert exp_name == "TestExperiment_hourly" + exp_name = set_experiment_name(sampling=("hourly", "daily")) + assert exp_name == "TestExperiment_daily" + exp_name = set_experiment_name(sampling=("hourly", "dummy", "daily")) + assert exp_name == "TestExperiment_daily" + def test_set_experiment_path(self): exp_path = set_experiment_path("TestExperiment") assert exp_path == os.path.abspath(os.path.join(ROOT_PATH, "TestExperiment")) -- GitLab