From e877a0d400750e0cf06a9199b11cf89b929d56f3 Mon Sep 17 00:00:00 2001 From: Scott Havens Date: Wed, 10 Jun 2020 15:01:16 -0600 Subject: [PATCH 1/4] made the time zone a raw string, fixing issue #96 --- smrf/framework/CoreConfig.ini | 1 + smrf/utils/utils.py | 20 ++++++++++++++++++++ tests/test_base_config.ini | 2 +- tests/test_model_framework.py | 10 ++++++++-- 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/smrf/framework/CoreConfig.ini b/smrf/framework/CoreConfig.ini index 9228d3e7..aee20e00 100755 --- a/smrf/framework/CoreConfig.ini +++ b/smrf/framework/CoreConfig.ini @@ -57,6 +57,7 @@ description = Date and time to end the data distribution that can be parsed by p time_zone: default = UTC, +type = RawString, description = Time zone for all times provided and how the model will be run see pytz docs for information on what is accepted ################################################################################ diff --git a/smrf/utils/utils.py b/smrf/utils/utils.py index bd08fed9..14da5001 100755 --- a/smrf/utils/utils.py +++ b/smrf/utils/utils.py @@ -48,6 +48,26 @@ def type_func(self, value): return value.upper() +class CheckRawString(CheckType): + """ + Custom `inicheck` checker that will not change the input string + """ + + def __init__(self, **kwargs): + super(CheckRawString, self).__init__(**kwargs) + + def type_func(self, value): + """ + Do not change the passed value at all + Args: + value: A single string + Returns: + value: A single string unchanged + """ + + return value + + def find_configs(directory): """ Searches through a directory and returns all the .ini fulll filenames. diff --git a/tests/test_base_config.ini b/tests/test_base_config.ini index e21b198f..1a607383 100644 --- a/tests/test_base_config.ini +++ b/tests/test_base_config.ini @@ -27,7 +27,7 @@ filename: ./RME/topo/topo.nc time_step: 60 start_date: 1998-01-14 15:00:00 end_date: 1998-01-14 19:00:00 -time_zone: utc +time_zone: UTC ################################################################################ diff --git a/tests/test_model_framework.py b/tests/test_model_framework.py index a6fa5d5a..f0b16662 100644 --- a/tests/test_model_framework.py +++ b/tests/test_model_framework.py @@ -53,15 +53,21 @@ class TestModelFrameworkMST(SMRFTestCase): """ Test timezone handling for MST. """ - TIMEZONE = pytz.timezone('US/Mountain') + TIMEZONE = pytz.timezone('MST') @classmethod def setUpClass(cls): super().setUpClass() base_config = copy.deepcopy(cls.base_config) - base_config.cfg['time']['time_zone'] = str(cls.TIMEZONE) + base_config.cfg['time']['time_zone'] = 'MST' cls.smrf = SMRF(base_config) + def test_timezone_error(self): + base_config = copy.deepcopy(self.base_config) + base_config.cfg['time']['time_zone'] = 'mst' + with self.assertRaises(Exception): + SMRF(base_config) + def test_start_date(self): self.assertEqual( self.smrf.start_date, From 2d709ff86225278a12f9c27b6a1da76135fd20ba Mon Sep 17 00:00:00 2001 From: Scott Havens Date: Thu, 11 Jun 2020 10:00:40 -0600 Subject: [PATCH 2/4] utc vs UTC in the tests, pytz has both but the gold files are in utc. fixes issue #96 --- tests/Lakes/config.ini | 2 +- tests/RME/config.ini | 2 +- tests/test_base_config.ini | 2 +- tests/test_data_gridded.py | 3 ++- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/Lakes/config.ini b/tests/Lakes/config.ini index 05396e21..47cfddf2 100644 --- a/tests/Lakes/config.ini +++ b/tests/Lakes/config.ini @@ -27,7 +27,7 @@ filename: ./topo/topo.nc time_step: 60 start_date: 2019-10-01 15:00 end_date: 2019-10-01 17:00 -time_zone: UTC +time_zone: utc ################################################################################ diff --git a/tests/RME/config.ini b/tests/RME/config.ini index deb9ab28..8514ad0e 100644 --- a/tests/RME/config.ini +++ b/tests/RME/config.ini @@ -27,7 +27,7 @@ filename: ./topo/topo.nc time_step: 60 start_date: 1998-01-14 15:00:00 end_date: 1998-01-14 19:00:00 -time_zone: UTC +time_zone: utc ################################################################################ diff --git a/tests/test_base_config.ini b/tests/test_base_config.ini index 1a607383..e21b198f 100644 --- a/tests/test_base_config.ini +++ b/tests/test_base_config.ini @@ -27,7 +27,7 @@ filename: ./RME/topo/topo.nc time_step: 60 start_date: 1998-01-14 15:00:00 end_date: 1998-01-14 19:00:00 -time_zone: UTC +time_zone: utc ################################################################################ diff --git a/tests/test_data_gridded.py b/tests/test_data_gridded.py index 0951a829..b5af6cec 100644 --- a/tests/test_data_gridded.py +++ b/tests/test_data_gridded.py @@ -95,7 +95,8 @@ def test_grid_hrrr_local(self): }, 'time': { 'start_date': '2018-07-22 16:00', - 'end_date': '2018-07-22 20:00' + 'end_date': '2018-07-22 20:00', + 'time_zone': 'utc' }, 'system': { 'threading': False, From f858d31d2ea8b53367f223e4282adc3f5d581a0e Mon Sep 17 00:00:00 2001 From: Scott Havens Date: Thu, 11 Jun 2020 13:18:48 -0600 Subject: [PATCH 3/4] updated core config time_zone description and flake8 on utils, fixes #96 --- smrf/framework/CoreConfig.ini | 4 +++- smrf/utils/utils.py | 41 +++++++++++++++-------------------- 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/smrf/framework/CoreConfig.ini b/smrf/framework/CoreConfig.ini index aee20e00..a57a438b 100755 --- a/smrf/framework/CoreConfig.ini +++ b/smrf/framework/CoreConfig.ini @@ -58,7 +58,9 @@ description = Date and time to end the data distribution that can be parsed by p time_zone: default = UTC, type = RawString, -description = Time zone for all times provided and how the model will be run see pytz docs for information on what is accepted +description = Case sensitive time zone for all times provided and how the model will be run. See + pytz docs for information on what is accepted. Full list can be found + https://en.wikipedia.org/wiki/List_of_tz_database_time_zones ################################################################################ # CSV section configurations diff --git a/smrf/utils/utils.py b/smrf/utils/utils.py index 14da5001..83e0f0bc 100755 --- a/smrf/utils/utils.py +++ b/smrf/utils/utils.py @@ -1,10 +1,3 @@ - -""" -20160104 Scott Havens - -Collection of utility functions -""" - import copy import os import random @@ -24,7 +17,7 @@ from smrf import __core_config__, __version__ -from .gitinfo import __gitPath__, __gitVersion__ +from .gitinfo import __gitVersion__ class CheckStation(CheckType): @@ -40,7 +33,7 @@ def type_func(self, value): Attempt to convert all the values to upper case. Args: - value: A single string in a a config entry representing a station name + value: A single string in config entry representing a station name Returns: value: A single station name all upper case """ @@ -103,8 +96,8 @@ def handle_run_script_options(config_option): configs = find_configs(config_option) if len(configs) > 1: - print("\nError: Multiple config files detected in {0} please ensure" - " only one is in the folder.\n".format(config_option)) + print("\nError: Multiple config files detected in {0} please" + " ensure only one is in the folder.\n".format(config_option)) sys.exit() else: @@ -154,9 +147,9 @@ def set_min_max(data, min_val, max_val): Returns: data: numpy array of data trimmed at min_val and max_val """ - if max_val == None: + if max_val is None: max_val = np.inf - if min_val == None: + if min_val is None: min_val = -np.inf ind = np.isnan(data) @@ -212,8 +205,8 @@ def is_leap_year(year): def backup_input(data, config_obj): """ - Backs up input data files so a user can rerun a run with the exact data used - for a run. + Backs up input data files so a user can rerun a run with the exact data + used for a run. Args: data: Pandas dataframe containing the station data @@ -227,7 +220,6 @@ def backup_input(data, config_obj): 'input_backup') if not os.path.isdir(backup_dir): os.mkdir(backup_dir) - csv_names = {} # Check config file for csv section and remove alternate data form config if 'csv' not in backup_config_obj.cfg.keys(): @@ -242,8 +234,8 @@ def backup_input(data, config_obj): del backup_config_obj.cfg['stations']['client'] # Output station data to CSV - csv_var = ['metadata', 'air_temp', 'vapor_pressure', 'precip', 'wind_speed', - 'wind_direction', 'cloud_factor'] + csv_var = ['metadata', 'air_temp', 'vapor_pressure', 'precip', + 'wind_speed', 'wind_direction', 'cloud_factor'] for k in csv_var: fname = os.path.join(backup_dir, k + '.csv') @@ -261,7 +253,7 @@ def backup_input(data, config_obj): if isinstance(src, list): src = mk_lst(src, unlst=True) # Avoid attempring to copy files that don't exist - if s not in ignore and src != None: + if s not in ignore and src is not None: dst = os.path.join(backup_dir, os.path.basename(src)) backup_config_obj.cfg["topo"][s] = dst copyfile(src, dst) @@ -301,7 +293,9 @@ def getConfigHeader(): cfg_str = ("Config File for SMRF {0}\n" "For more SMRF related help see:\n" - "{1}").format(getgitinfo(), 'http://smrf.readthedocs.io/en/latest/') + "{1}").format( + getgitinfo(), + 'http://smrf.readthedocs.io/en/latest/') return cfg_str @@ -318,7 +312,7 @@ def check_station_colocation(metadata_csv=None, metadata=None): Returns: repeat_sta: list of station primary_id that are colocated """ - if metadata_csv != None: + if metadata_csv is not None: metadata = pd.read_csv(metadata_csv) metadata.set_index('primary_id', inplace=True) @@ -421,8 +415,9 @@ def interp_weights(xy, uv, d=2): This routine follows the methods of scipy.interpolate.griddata as outlined here: https://stackoverflow.com/questions/20915502/speedup-scipy-griddata-for-multiple-interpolations-between-two-irregular-grids - This function finds the vertices and weights which is the most computationally - expensive part of the routine. The interpolateion can then be done quickly. + This function finds the vertices and weights which is the most + computationally expensive part of the routine. The interpolateion can then + be done quickly. Args: xy: n by 2 array of flattened meshgrid x and y coords of WindNinja grid From 78194cf71ba6f56a2dad16a8bb1221459f02d23b Mon Sep 17 00:00:00 2001 From: Scott Havens Date: Thu, 11 Jun 2020 13:58:59 -0600 Subject: [PATCH 4/4] cleaning up the merge --- docs/user_guide/auto_config.rst | 4 ++-- smrf/framework/CoreConfig.ini | 2 +- smrf/utils/utils.py | 4 ---- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/docs/user_guide/auto_config.rst b/docs/user_guide/auto_config.rst index f11137eb..5770d72f 100644 --- a/docs/user_guide/auto_config.rst +++ b/docs/user_guide/auto_config.rst @@ -54,9 +54,9 @@ time | | **time_zone** -| Time zone for all times provided and how the model will be run see pytz docs for information on what is accepted +| Case sensitive time zone for all times provided and how the model will be run. See pytz docs for information on what is accepted. Full list can be found en.wikipedia.org/wiki/List_of_tz_database_time_zones | *Default: UTC* -| *Type: string* +| *Type: rawstring* | diff --git a/smrf/framework/CoreConfig.ini b/smrf/framework/CoreConfig.ini index 3bd9bc92..4c3097fb 100755 --- a/smrf/framework/CoreConfig.ini +++ b/smrf/framework/CoreConfig.ini @@ -66,7 +66,7 @@ default = UTC, type = RawString, description = Case sensitive time zone for all times provided and how the model will be run. See pytz docs for information on what is accepted. Full list can be found - https://en.wikipedia.org/wiki/List_of_tz_database_time_zones + en.wikipedia.org/wiki/List_of_tz_database_time_zones ################################################################################ # CSV section configurations diff --git a/smrf/utils/utils.py b/smrf/utils/utils.py index e65e9c26..097eadbc 100755 --- a/smrf/utils/utils.py +++ b/smrf/utils/utils.py @@ -18,10 +18,6 @@ from smrf import __core_config__, __version__ from .gitinfo import __gitVersion__ -<< << << < HEAD - -== == == = ->>>>>> > upstream/master class CheckStation(CheckType):