From e5cc02501f629c96641dfd1bcd1f7fcfd0d55462 Mon Sep 17 00:00:00 2001 From: junos Date: Wed, 15 Dec 2021 18:09:30 +0100 Subject: [PATCH] Set the timezone.csv path in config. Take into account that TZCODES_FILE can be created with a rule. --- config.yaml | 1 + rules/common.smk | 11 ++++++++++- rules/preprocessing.smk | 4 ++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/config.yaml b/config.yaml index c5f15a9f..2ba8256c 100644 --- a/config.yaml +++ b/config.yaml @@ -31,6 +31,7 @@ TIMEZONE: SINGLE: TZCODE: Europe/Ljubljana MULTIPLE: + TZ_FILE: data/external/timezone.csv TZCODES_FILE: data/external/multiple_timezones.csv IF_MISSING_TZCODE: USE_DEFAULT DEFAULT_TZCODE: Europe/Ljubljana diff --git a/rules/common.smk b/rules/common.smk index 017330c1..63728d3f 100644 --- a/rules/common.smk +++ b/rules/common.smk @@ -114,7 +114,16 @@ def input_tzcodes_file(wilcards): if not config["TIMEZONE"]["MULTIPLE"]["TZCODES_FILE"].lower().endswith(".csv"): raise ValueError("[TIMEZONE][MULTIPLE][TZCODES_FILE] should point to a CSV file, instead you typed: " + config["TIMEZONE"]["MULTIPLE"]["TZCODES_FILE"]) if not Path(config["TIMEZONE"]["MULTIPLE"]["TZCODES_FILE"]).exists(): - raise ValueError("[TIMEZONE][MULTIPLE][TZCODES_FILE] should point to a CSV file, the file in the path you typed does not exist: " + config["TIMEZONE"]["MULTIPLE"]["TZCODES_FILE"]) + try: + config["TIMEZONE"]["MULTIPLE"]["TZ_FILE"] + except KeyError: + raise ValueError("To create TZCODES_FILE, a list of timezones should be created " + + "with the rule preprocessing.smk/prepare_tzcodes_file " + + "which will create a file specified as config['TIMEZONE']['MULTIPLE']['TZ_FILE']." + + "\n An alternative is to provide the file manually:" + + "[TIMEZONE][MULTIPLE][TZCODES_FILE] should point to a CSV file," + + "but the file in the path you typed does not exist: " + + config["TIMEZONE"]["MULTIPLE"]["TZCODES_FILE"]) return [config["TIMEZONE"]["MULTIPLE"]["TZCODES_FILE"]] return [] diff --git a/rules/preprocessing.smk b/rules/preprocessing.smk index fdce6f09..cb2e874a 100644 --- a/rules/preprocessing.smk +++ b/rules/preprocessing.smk @@ -9,13 +9,13 @@ rule query_usernames_device_empatica_ids: baseline_folder = "/mnt/e/STRAWbaseline/" output: usernames_file = config["CREATE_PARTICIPANT_FILES"]["USERNAMES_CSV"], - timezone_file = "data/external/timezone.csv" + timezone_file = config["TIMEZONE"]["MULTIPLE"]["TZ_FILE"] script: "../../participants/prepare_usernames_file.py" rule prepare_tzcodes_file: input: - timezone_file = "data/external/timezone.csv" + timezone_file = config["TIMEZONE"]["MULTIPLE"]["TZ_FILE"] output: tzcodes_file = config["TIMEZONE"]["MULTIPLE"]["TZCODES_FILE"] script: