Skip to content

Commit 1cac4f7

Browse files
committed
make timezone conversion optional for gridded
1 parent f5bd573 commit 1cac4f7

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

dweather_client/client.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from dweather_client.aliases_and_units import \
66
lookup_station_alias, STATION_UNITS_LOOKUP as SUL, METRIC_TO_IMPERIAL as M2I, IMPERIAL_TO_METRIC as I2M, UNIT_ALIASES
77
from dweather_client.struct_utils import tupleify, convert_nans_to_none
8-
from dweather_client.df_loader import get_atcf_hurricane_df, get_historical_hurricane_df, get_simulated_hurricane_df
98
import datetime, pytz, csv, inspect
109
from astropy import units as u
1110
import numpy as np
@@ -30,6 +29,7 @@ def get_gridcell_history(
3029
also_return_snapped_coordinates=False,
3130
also_return_metadata=False,
3231
use_imperial_units=True,
32+
convert_to_local_time=True,
3333
ipfs_timeout=None):
3434
"""
3535
Get the historical timeseries data for a gridded dataset in a dictionary
@@ -69,18 +69,19 @@ def get_gridcell_history(
6969
raise DatasetError("No such dataset in dClimate")
7070

7171
try:
72-
(lat, lon), resp_series = GRIDDED_DATASETS[dataset](ipfs_timeout=ipfs_timeout).get_data(lat, lon)
72+
(lat, lon), resp_series = dataset_obj.get_data(lat, lon)
7373

7474
except (ipfshttpclient.exceptions.ErrorResponse, ipfshttpclient.exceptions.TimeoutError, KeyError, FileNotFoundError) as e:
7575
raise CoordinateNotFoundError("Invalid coordinate for dataset")
7676

7777
# try a timezone-based transformation on the times in case we're using an hourly set.
78-
try:
79-
tf = TimezoneFinder()
80-
local_tz = pytz.timezone(tf.timezone_at(lng=lon, lat=lat))
81-
resp_series = resp_series.tz_localize("UTC").tz_convert(local_tz)
82-
except (AttributeError, TypeError): # datetime.date (daily sets) doesn't work with this, only datetime.datetime (hourly sets)
83-
pass
78+
if convert_to_local_time:
79+
try:
80+
tf = TimezoneFinder()
81+
local_tz = pytz.timezone(tf.timezone_at(lng=lon, lat=lat))
82+
resp_series = resp_series.tz_localize("UTC").tz_convert(local_tz)
83+
except (AttributeError, TypeError): # datetime.date (daily sets) doesn't work with this, only datetime.datetime (hourly sets)
84+
pass
8485

8586
if type(missing_value) == str:
8687
resp_series = resp_series.replace(missing_value, np.NaN).astype(float)

0 commit comments

Comments
 (0)