Skip to content

Commit

Permalink
Merge pull request #68 from tethys-ts/dev
Browse files Browse the repository at this point in the history
added temporal query for get_stations
  • Loading branch information
mullenkamp authored Sep 14, 2022
2 parents fe0abf3 + 2a94a14 commit 40bb876
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions tethysts/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,9 @@ def get_stations(self,
lat: float = None,
lon: float = None,
distance: float = None,
version_date: Union[str, datetime, pd.Timestamp] = None
version_date: Union[str, datetime, pd.Timestamp] = None,
from_date: Union[str, pd.Timestamp, datetime] = None,
to_date: Union[str, pd.Timestamp, datetime] = None
):
"""
Method to return the stations associated with a dataset.
Expand All @@ -220,6 +222,10 @@ def get_stations(self,
See lat description. This should be in decimal degrees not meters.
version_date: str in iso 8601 datetime format or None
The specific version of the stations data. None will return the latest version.
from_date : str, Timestamp, datetime, or None
The start date of the selection.
to_date : str, Timestamp, datetime, or None
The end date of the selection.
Returns
-------
Expand All @@ -244,13 +250,21 @@ def get_stations(self,
remote['obj_key'] = stn_key
stn_obj = get_object_s3(**remote)
stn_list = read_json_zstd(stn_obj)

stn_dict = {s['station_id']: s for s in stn_list if isinstance(s, dict)}
update_nested(self._stations, dataset_id, vd, stn_dict)
except:
print('No stations.json.zst file in S3 bucket')
return None

## Temporal queries
if isinstance(from_date, (str, pd.Timestamp, datetime)):
from_date1 = pd.Timestamp(from_date)
stn_dict = {s_id: s for s_id, s in stn_dict.items() if pd.Timestamp(s['time_range']['from_date']) >= from_date1}

if isinstance(to_date, (str, pd.Timestamp, datetime)):
to_date1 = pd.Timestamp(to_date)
stn_dict = {s_id: s for s_id, s in stn_dict.items() if pd.Timestamp(s['time_range']['to_date']) <= to_date1}

## Spatial query
stn_ids = spatial_query(stn_dict, geometry, lat, lon, distance)

Expand Down

0 comments on commit 40bb876

Please sign in to comment.