Skip to content

Commit

Permalink
adding method to get the datum level offset for an observation point
Browse files Browse the repository at this point in the history
  • Loading branch information
PhillipsOwen committed Oct 30, 2024
1 parent b9e3e64 commit e00baa4
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/common/pg_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,53 @@ def get_catalog_member_records(self, **kwargs) -> dict:
# return the data
return ret_val

def get_station_level_offset(self, station_id: int, instance_name: str) -> float:
"""
gets the offset level for a station
:param station_id:
:param instance_name:
:return:
"""
ret_val: float = 0.0

# create the SQL
sql: str = f"SELECT * FROM public.get_station_level_offset(_station_id := {station_id}, _instance_name := '{instance_name}');"

# get the layer list
ret_val = self.exec_sql('apsviz', sql)

# if the call was unsuccessful
if ret_val == -1:
ret_val = 0.0

# return to the caller
return ret_val

def add_datum_level_offset(self, station_id: int, instance_name: str, station_df: pd.DataFrame):
"""
add the level offset value for a station to the appropriate data columns
:param station_id:
:param instance_name:
:param station_df:
:return:
"""
# get the water level offsets at the location
offset: float = self.get_station_level_offset(station_id, instance_name)

# if there was level offset data found for that point
if offset != 0:
# define the target columns that get the treatment
cols: list = ['Observations', 'NOAA Tidal Predictions']

# for each target column
for col in cols:
# if the col exists
if col in station_df.columns:
# add in the level offset
station_df[col] = station_df[col] + offset

def get_station_data(self, **kwargs) -> str:
"""
gets the station data.
Expand Down Expand Up @@ -404,6 +451,9 @@ def get_station_data(self, **kwargs) -> str:
# else if observation name is None rename tidal_predictions
station_df.rename(columns={'time_stamp': 'time', 'tidal_predictions': 'NOAA Tidal Predictions'}, inplace=True)

# add the station level offsets (if they exist)
self.add_datum_level_offset(kwargs['station_name'], kwargs['instance_name'], station_df)

# return the data to the caller
return station_df.to_csv(index=False)

Expand Down

0 comments on commit e00baa4

Please sign in to comment.