Skip to content

Commit

Permalink
read config file in get_l2tol3 and pass only dictionary to L2toL3.py
Browse files Browse the repository at this point in the history
+ fixed doc on L2toL3.py
+ better reverse of L1 dataset list in aws.py
  • Loading branch information
BaptisteVandecrux committed Jul 3, 2024
1 parent f66251f commit 1a0975a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 24 deletions.
32 changes: 12 additions & 20 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='../aws-l0/metadata/station_configurations/', T_0=273.15):
def toL3(L2, config_folder={}, T_0=273.15):
'''Process one Level 2 (L2) product to Level 3 (L3) meaning calculating all
derived variables:
- Turbulent fluxes
Expand All @@ -23,7 +23,7 @@ def toL3(L2, config_folder='../aws-l0/metadata/station_configurations/', T_0=273
L2 : xarray:Dataset
L2 AWS data
T_0 : int
Steam point temperature. Default is 273.15.
Freezing point temperature. Default is 273.15.
'''
ds = L2
ds.attrs['level'] = 'L3'
Expand Down Expand Up @@ -158,7 +158,7 @@ def calcHeatFlux(T_0, T_h, Tsurf_h, WS_h, z_WS, z_T, q_h, p_h,
Parameters
----------
T_0 : int
Steam point temperature
Freezing point temperature
T_h : xarray.DataArray
Air temperature
Tsurf_h : xarray.DataArray
Expand All @@ -171,8 +171,6 @@ def calcHeatFlux(T_0, T_h, Tsurf_h, WS_h, z_WS, z_T, q_h, p_h,
Height of anemometer
z_T : float
Height of thermometer
nu : float
Kinematic viscosity of air
q_h : xarray.DataArray
Specific humidity
p_h : xarray.DataArray
Expand All @@ -187,14 +185,9 @@ def calcHeatFlux(T_0, T_h, Tsurf_h, WS_h, z_WS, z_T, q_h, p_h,
g : int
Gravitational acceleration (m/s2). Default is 9.82.
es_0 : int
Saturation vapour pressure at the melting point (hPa). Default is 6.1071.
es_100 : int
Saturation vapour pressure at steam point temperature (hPa). Default is
1013.246.
Saturation vapour pressure at the melting point (hPa). Default is 6.1071.
eps : int
Ratio of molar masses of vapor and dry air (0.622).
R_d : int
Gas constant of dry air. Default is 287.05.
gamma : int
Flux profile correction (Paulson & Dyer). Default is 16..
L_sub : int
Expand All @@ -215,9 +208,8 @@ def calcHeatFlux(T_0, T_h, Tsurf_h, WS_h, z_WS, z_T, q_h, p_h,
dd : int
Flux profile correction constants (Holtslag & De Bruin '88). Default is
0.35.
z_0 : int
Aerodynamic surface roughness length for momention, assumed constant
for all ice/snow surfaces. Default is 0.001.
R_d : int
Gas constant of dry air. Default is 287.05.
Returns
-------
Expand Down Expand Up @@ -354,16 +346,16 @@ def calcSpHumid(T_0, T_100, T_h, p_h, RH_cor_h, es_0=6.1071, es_100=1013.246, ep
Steam point temperature in Kelvin
T_h : xarray.DataArray
Air temperature
eps : int
ratio of molar masses of vapor and dry air (0.622)
es_0 : float
Saturation vapour pressure at the melting point (hPa)
es_100 : float
Saturation vapour pressure at steam point temperature (hPa)
p_h : xarray.DataArray
Air pressure
RH_cor_h : xarray.DataArray
Relative humidity corrected
es_0 : float
Saturation vapour pressure at the melting point (hPa)
es_100 : float
Saturation vapour pressure at steam point temperature (hPa)
eps : int
ratio of molar masses of vapor and dry air (0.622)
Returns
-------
Expand Down
3 changes: 1 addition & 2 deletions src/pypromice/process/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ def getL1(self):
logger.info('Level 1 processing...')
self.L0 = [utilities.addBasicMeta(item, self.vars) for item in self.L0]
self.L1 = [toL1(item, self.vars) for item in self.L0]
self.L1.reverse()
self.L1A = reduce(xr.Dataset.combine_first, self.L1)
self.L1A = reduce(xr.Dataset.combine_first, reversed(self.L1))

def getL2(self):
'''Perform L1 to L2 data processing'''
Expand Down
9 changes: 7 additions & 2 deletions src/pypromice/process/get_l2tol3.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python
import os, logging, sys
import os, logging, sys, toml
import xarray as xr
from argparse import ArgumentParser
import pypromice
Expand All @@ -13,6 +13,7 @@ def parse_arguments_l2tol3(debug_args=None):
"data from L2. An hourly, daily and monthly L3 "+
"data product is outputted to the defined output path")
parser.add_argument('-c', '--config_folder', type=str, required=True,
default='../aws-l0/metadata/station_configurations/',
help='Path to folder with sites configuration (TOML) files')
parser.add_argument('-i', '--inpath', type=str, required=True,
help='Path to Level 2 .nc data file')
Expand Down Expand Up @@ -47,8 +48,12 @@ def get_l2tol3(config_folder, inpath, outpath, variables, metadata):
if 'number_of_booms' in l2.attrs.keys():
l2.attrs['number_of_booms'] = int(l2.attrs['number_of_booms'])

# importing station_config (dict) from config_folder (str path)
config_file = config_folder+l2.attrs['station_id']+'.toml'
with open(config_file) as fp:
station_config = toml.load(fp)
# Perform Level 3 processing
l3 = toL3(l2, config_folder)
l3 = toL3(l2, station_config)

# Write Level 3 dataset to file if output directory given
v = getVars(variables)
Expand Down

0 comments on commit 1a0975a

Please sign in to comment.