diff --git a/metloom/__init__.py b/metloom/__init__.py index deb2751..1d74f00 100644 --- a/metloom/__init__.py +++ b/metloom/__init__.py @@ -2,4 +2,4 @@ __author__ = """M3Works""" __email__ = "m3worksllc@gmail.com" -__version__ = '0.9.1' +__version__ = '0.9.2' diff --git a/metloom/dataframe_utils.py b/metloom/dataframe_utils.py index 7684f29..c397760 100644 --- a/metloom/dataframe_utils.py +++ b/metloom/dataframe_utils.py @@ -116,6 +116,8 @@ def resample_df(raw_df: pd.DataFrame, desired interval """ name = variable.name + if interval == 'H': + interval = 'h' # pandas uses lowercase for hourly resampling if name in raw_df.columns: if variable.accumulated: result = raw_df[name].resample(interval).sum() diff --git a/metloom/pointdata/snotel_client.py b/metloom/pointdata/snotel_client.py index ff4451c..2ac381c 100644 --- a/metloom/pointdata/snotel_client.py +++ b/metloom/pointdata/snotel_client.py @@ -200,6 +200,35 @@ def get_data(self, element_cd: str, **extra_params): mapped_params = self._get_params(**extra_params) params = {**self.params, **mapped_params} data = self._make_request(**params) + + # In some cases, in particlular for snow course data prior to 2011, the collection dates + # are not included in the reponse for the SWE variable, but are included in the depth (SNWD). + # This is a workaround to make a second request if the collection data are missing. + if ( + (len(data) > 0) + and ("collectionDates" in data[0]) + and all(c is None for c in data[0]["collectionDates"]) + ): + data2 = self._make_request(**{**params, "elementCd": "SNWD"}) + data[0]["collectionDates"] = data2[0]["collectionDates"] + + # Furthermore, in some cases the collectionDates are not included at all, so we need to assume the collection dates. + # Based on our analsysis the target date is the first of the month. The API returns the beginDate and endData for the + # period. Thus, using the 'beginDate' and 'endDate' the range of dates can be estimated. The 'collectionDates' + # can then be estimated using the data with 'values' (i.e. not None). + if ( + (len(data) > 0) + and ("collectionDates" in data[0]) + and all(c is None for c in data[0]["collectionDates"]) + and data[0]["beginDate"] is not None + and data[0]["endDate"] is not None + ): + start_date = pd.to_datetime(data[0]["beginDate"]) + end_date = pd.to_datetime(data[0]["endDate"]) + date_list = pd.date_range(start=start_date, end=end_date, freq="MS") + collection_dates = [d for d in date_list for _ in range(2)] + data[0]["collectionDates"] = [collection_dates[i] if (v is not None) else None for i, v in enumerate(data[0]['values'])] + return self._parse_data(data) diff --git a/setup.cfg b/setup.cfg index 5b60b01..b832916 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.9.1 +current_version = 0.9.2 commit = True tag = True diff --git a/setup.py b/setup.py index e9d4725..0e8b1dd 100644 --- a/setup.py +++ b/setup.py @@ -54,6 +54,6 @@ test_suite='tests', tests_require=test_requirements, url='https://github.com/M3Works/metloom', - version='0.9.1', + version='0.9.2', zip_safe=False, )