Skip to content

Commit

Permalink
forgot to pass on the station_config dictionary
Browse files Browse the repository at this point in the history
  • Loading branch information
BaptisteVandecrux committed Jul 4, 2024
1 parent 1366335 commit 73f6359
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions src/pypromice/process/L2toL3.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import logging
logger = logging.getLogger(__name__)

def toL3(L2, config_folder={}, T_0=273.15):
def toL3(L2, station_config={}, T_0=273.15):
'''Process one Level 2 (L2) product to Level 3 (L3) meaning calculating all
derived variables:
- Turbulent fluxes
Expand All @@ -22,7 +22,7 @@ def toL3(L2, config_folder={}, T_0=273.15):
----------
L2 : xarray:Dataset
L2 AWS data
config_folder : Dict
station_config : Dict
Dictionary containing the information necessary for the processing of
L3 variables (relocation dates for coordinates processing, or thermistor
string maintenance date for the thermistors depth)
Expand Down Expand Up @@ -99,14 +99,14 @@ def toL3(L2, config_folder={}, T_0=273.15):

# Smoothing and inter/extrapolation of GPS coordinates
for var in ['gps_lat', 'gps_lon', 'gps_alt']:
ds[var.replace('gps_','')] = ('time', gpsCoordinatePostprocessing(ds, var))
ds[var.replace('gps_','')] = ('time', gpsCoordinatePostprocessing(ds, var, station_config))

# adding average coordinate as attribute
for v in ['lat','lon','alt']:
ds.attrs[v+'_avg'] = ds[v].mean(dim='time').item()
return ds

def gpsCoordinatePostprocessing(ds, var, config_folder='../aws-l0/metadata/station_configurations/'):
def gpsCoordinatePostprocessing(ds, var, station_config={}):
# saving the static value of 'lat','lon' or 'alt' stored in attribute
# as it might be the only coordinate available for certain stations (e.g. bedrock)
var_out = var.replace('gps_','')
Expand All @@ -129,18 +129,8 @@ def gpsCoordinatePostprocessing(ds, var, config_folder='../aws-l0/metadata/stati
print('no',var,'at',ds.attrs['station_id'])
return np.ones_like(ds['t_u'].data)*static_value

# fetching the station relocation dates at which the coordinates will/should
# have a break
config_file = config_folder +"/" + ds.attrs['station_id'] + ".toml"
if os.path.isfile(config_file):
with open(config_file, "r") as f:
config_data = toml.load(f)

# Extract station relocations from the TOML data
station_relocations = config_data.get("station_relocation", [])
else:
station_relocations = []
logger.warning('Did not find config file for '+ds.attrs['station_id']+'. Assuming no station relocation.')
# Extract station relocations from the TOML data
station_relocations = station_config.get("station_relocation", [])

# Convert the ISO8601 strings to pandas datetime objects
breaks = [pd.to_datetime(date_str) for date_str in station_relocations]
Expand Down

0 comments on commit 73f6359

Please sign in to comment.