Skip to content

Commit

Permalink
Recalculate RAOB from Wyoming
Browse files Browse the repository at this point in the history
This change allows for a user to request that the RAOB is
"Recalculated." This can be required if an earlier user of the
site requests the observation before the entire observation is
available. This results in an incomplete observation being cached.
Recalculation requires additional resources, so the default is to
not recalculate.
  • Loading branch information
tmharty authored and dopplershift committed Dec 12, 2024
1 parent 2200fb1 commit a7dc9a2
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/siphon/simplewebservice/wyoming.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(self):
super().__init__('http://weather.uwyo.edu/cgi-bin/sounding')

@classmethod
def request_data(cls, time, site_id, **kwargs):
def request_data(cls, time, site_id, recalc=False, **kwargs):
r"""Retrieve upper air observations from the Wyoming archive.
Parameters
Expand All @@ -40,6 +40,11 @@ def request_data(cls, time, site_id, **kwargs):
The three letter ICAO identifier of the station for which data should be
downloaded.
recalc : bool
Whether to request the server recalculate the data (i.e. ignore its cache) before
returning it. Defaults to False. NOTE: This should be used sparingly because it
will increase the load on the service.
kwargs
Arbitrary keyword arguments to use to initialize source
Expand All @@ -50,10 +55,10 @@ def request_data(cls, time, site_id, **kwargs):
"""
endpoint = cls()
df = endpoint._get_data(time, site_id)
df = endpoint._get_data(time, site_id, recalc=recalc)
return df

def _get_data(self, time, site_id):
def _get_data(self, time, site_id, recalc=False):
r"""Download and parse upper air observations from an online archive.
Parameters
Expand All @@ -65,12 +70,15 @@ def _get_data(self, time, site_id):
The three letter ICAO identifier of the station for which data should be
downloaded.
recalc : bool
Returns recalculated data if True. Defaults to False.
Returns
-------
`pandas.DataFrame`
"""
raw_data = self._get_data_raw(time, site_id)
raw_data = self._get_data_raw(time, site_id, recalc=recalc)
soup = BeautifulSoup(raw_data, 'html.parser')
tabular_data = StringIO(soup.find_all('pre')[0].contents[0])
col_names = ['pressure', 'height', 'temperature', 'dewpoint', 'direction', 'speed']
Expand Down Expand Up @@ -129,7 +137,7 @@ def _get_data(self, time, site_id):

return df

def _get_data_raw(self, time, site_id):
def _get_data_raw(self, time, site_id, recalc=False):
"""Download data from the University of Wyoming's upper air archive.
Parameters
Expand All @@ -138,6 +146,8 @@ def _get_data_raw(self, time, site_id):
Date and time for which data should be downloaded
site_id : str
Site id for which data should be downloaded
recalc : bool
Returns recalculated data if True. Defaults to False.
Returns
-------
Expand All @@ -148,6 +158,8 @@ def _get_data_raw(self, time, site_id):
path = ('?region=naconf&TYPE=TEXT%3ALIST'
f'&YEAR={time:%Y}&MONTH={time:%m}&FROM={time:%d%H}&TO={time:%d%H}'
f'&STNM={site_id}')
if recalc:
path += '&REPLOT=1'

resp = self.get_path(path)
# See if the return is valid, but has no data
Expand Down

0 comments on commit a7dc9a2

Please sign in to comment.