@@ -165,6 +165,25 @@ def set_dataset(self):
165165 self .ncss = NCSS (self .access_url )
166166 self .query = self .ncss .query ()
167167
168+ def set_query_time_range (self , start , end ):
169+ """
170+ Parameters
171+ ----------
172+ start : datetime.datetime, pandas.Timestamp
173+ Must be tz-localized.
174+ end : datetime.datetime, pandas.Timestamp
175+ Must be tz-localized.
176+
177+ Notes
178+ -----
179+ Assigns ``self.start``, ``self.end``. Modifies ``self.query``
180+ """
181+ self .start = pd .Timestamp (start )
182+ self .end = pd .Timestamp (end )
183+ if self .start .tz is None or self .end .tz is None :
184+ raise TypeError ('start and end must be tz-localized' )
185+ self .query .time_range (self .start , self .end )
186+
168187 def set_query_latlon (self ):
169188 '''
170189 Sets the NCSS query location latitude and longitude.
@@ -180,24 +199,24 @@ def set_query_latlon(self):
180199 self .lbox = False
181200 self .query .lonlat_point (self .longitude , self .latitude )
182201
183- def set_location (self , time , latitude , longitude ):
202+ def set_location (self , tz , latitude , longitude ):
184203 '''
185204 Sets the location for the query.
186205
187206 Parameters
188207 ----------
189- time: datetime or DatetimeIndex
190- Time range of the query.
191- '''
192- if isinstance (time , datetime .datetime ):
193- tzinfo = time .tzinfo
194- else :
195- tzinfo = time .tz
208+ tz: tzinfo
209+ Timezone of the query
210+ latitude: float
211+ Latitude of the query
212+ longitude: float
213+ Longitude of the query
196214
197- if tzinfo is None :
198- self .location = Location (latitude , longitude )
199- else :
200- self .location = Location (latitude , longitude , tz = tzinfo )
215+ Notes
216+ -----
217+ Assigns ``self.location``.
218+ '''
219+ self .location = Location (latitude , longitude , tz = tz )
201220
202221 def get_data (self , latitude , longitude , start , end ,
203222 vert_level = None , query_variables = None ,
@@ -243,14 +262,12 @@ def get_data(self, latitude, longitude, start, end,
243262 else :
244263 self .query_variables = query_variables
245264
265+ self .set_query_time_range (start , end )
266+
246267 self .latitude = latitude
247268 self .longitude = longitude
248269 self .set_query_latlon () # modifies self.query
249- self .set_location (start , latitude , longitude )
250-
251- self .start = start
252- self .end = end
253- self .query .time_range (self .start , self .end )
270+ self .set_location (self .start .tz , latitude , longitude )
254271
255272 if self .vert_level is not None :
256273 self .query .vertical_level (self .vert_level )
0 commit comments