Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Time zone capitilization #164

Merged
merged 5 commits into from
Jun 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/user_guide/auto_config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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*
|


Expand Down
5 changes: 4 additions & 1 deletion smrf/framework/CoreConfig.ini
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ description = Date and time to end the data distribution that can be parsed by p

time_zone:
default = UTC,
description = Time zone for all times provided and how the model will be run see pytz docs for information on what is accepted
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
en.wikipedia.org/wiki/List_of_tz_database_time_zones

################################################################################
# CSV section configurations
Expand Down
34 changes: 24 additions & 10 deletions smrf/utils/utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@

"""
20160104 Scott Havens

Collection of utility functions
"""

import copy
import os
import random
Expand All @@ -26,6 +19,7 @@

from .gitinfo import __gitVersion__


class CheckStation(CheckType):
"""
Custom check for ensuring our stations are always capitalized
Expand All @@ -39,15 +33,34 @@ 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
"""

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think this would be worth opening a ticket for and move into 'inicheck'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now we can flip a coin :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You got a lower number so you won!



def find_configs(directory):
"""
Searches through a directory and returns all the .ini fulll filenames.
Expand Down Expand Up @@ -282,7 +295,8 @@ 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/')
getgitinfo(),
'http://smrf.readthedocs.io/en/latest/')
return cfg_str


Expand Down
2 changes: 1 addition & 1 deletion tests/Lakes/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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


################################################################################
Expand Down
2 changes: 1 addition & 1 deletion tests/RME/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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


################################################################################
Expand Down
3 changes: 2 additions & 1 deletion tests/test_data_gridded.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 8 additions & 2 deletions tests/test_model_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,21 @@ class TestModelFrameworkMST(SMRFTestCase):
"""
Test timezone handling for MST.
"""
TIMEZONE = pytz.timezone('US/Mountain')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Little did I know that MST is the way to go and 'US/Mountain' is deprecated

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

US/Mountain will also apply daylight savings time so you can either miss an hour or double up.

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'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did this call need to b changed?
Or did you want to create a more 'real world' input scenario with it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a more real world application as we don't typically pass a pytz object. This will also test that the inicheck parser is working. Then TIMEZONE becomes what is checked against

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,
Expand Down