Skip to content

Commit

Permalink
Merge pull request #15 from RENCI/oneTwenty
Browse files Browse the repository at this point in the history
Added check for length of observation_name
  • Loading branch information
PhillipsOwen authored Jul 22, 2024
2 parents 05c27f8 + fb4a551 commit 650d8dc
Showing 1 changed file with 27 additions and 19 deletions.
46 changes: 27 additions & 19 deletions src/common/pg_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,34 +328,24 @@ def get_station_data(self, **kwargs) -> str:
# get nowcast data
nowcast_data = self.get_nowcast_station_data(kwargs['station_name'], start_date, end_date, nowcast_source, kwargs['instance_name'])

# If nowcast data exists, merge it with obs data
# If nowcast data exists merge it with obs data
if not nowcast_data.empty:
# check if obs_data is empty
if not obs_data.empty:
# check if obs_data.columns id buoy. If it is search for wave_height, else search for water_level
if 'ocean_buoy_wave_height' in obs_data.columns:
observation_name = [s for s in obs_data.columns.values if 'wave_height' in s][0]
elif 'water_level' in obs_data.columns:
observation_name = [s for s in obs_data.columns.values if 'water_level' in s][0]
else:
observation_name = None

# Merge nowcast_data with obs_data
# Check if for type of observations name and make appropiate changes
observation_name = getObsDataName(obs_data)

# Merge nowcast data with Obs data
obs_data = obs_data.merge(nowcast_data, on='time_stamp', how='outer')
else:
# if obs data is empty, just nowcast data become obs_data, and observation_name is None
# Just use nowcast data as obs data in cases where there is no obs data
obs_data = nowcast_data
observation_name = None
else:
# if nowcast data is empty, check if obs_data is also empty
if not obs_data.empty:
# check if obs_data.columns id buoy. If it is search for wave_height, else search for water_level
if 'ocean_buoy_wave_height' in obs_data.columns:
observation_name = [s for s in obs_data.columns.values if 'wave_height' in s][0]
else:
observation_name = [s for s in obs_data.columns.values if 'water_level' in s][0]
# Check if for type of observations name and make appropiate changes
observation_name = getObsDataName(obs_data)
else:
# if obs_data is empty, observation_name is None
# if obs_data empty observation_name = None
observation_name = None

# replace any None values with np.nan, in both DataFrames
Expand Down Expand Up @@ -477,6 +467,24 @@ def get_nowcast_station_data(self, station_name, start_date, end_date, data_sour
# Return Pandas dataframe
return ret_val

def getObsDataName(obs_data):
"""
Gets the observed name.
:param obs_data:
:return: observation_name
"""
if 'ocean_buoy_wave_height' in obs_data.columns:
observation_name = [s for s in obs_data.columns.values if 'wave_height' in s][0]
else:
observation_name = [s for s in obs_data.columns.values if 'water_level' in s]
if len(observation_name) == 0:
observation_name = None
else:
observation_name = observation_name[0]

return(observation_name)

def get_obs_station_data(self, station_name, start_date, end_date) -> pd.DataFrame:
"""
Gets the observed station data.
Expand Down

0 comments on commit 650d8dc

Please sign in to comment.