Skip to content

Commit

Permalink
adding GlacioBasis folder to inputs and appending
Browse files Browse the repository at this point in the history
  • Loading branch information
BaptisteVandecrux committed Sep 3, 2024
1 parent 8e61923 commit aeefc29
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/pypromice/process/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ def __init__(
"""
assert os.path.isfile(config_file), "cannot find " + config_file
assert os.path.isdir(inpath), "cannot find " + inpath
logger.info(

logger.debug(
"AWS("
f"config_file={config_file},"
f" inpath={inpath},"
Expand Down
50 changes: 44 additions & 6 deletions src/pypromice/process/join_l3.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ def parse_arguments_joinl3(debug_args=None):
required=False,
help="Path to GC-Net historical L1 folder",
)
parser.add_argument(
"-gb",
"--folder_glaciobasis",
type=str,
required=False,
help="Path to GlacioBasis historical data folder",
)

parser.add_argument(
"-o",
Expand Down Expand Up @@ -147,7 +154,7 @@ def readNead(infile):
ds = df.to_xarray()
ds.attrs = meta

# renaming variables
# renaming variables if GC-Net
file_path = pypromice.resources.DEFAULT_VARIABLES_ALIASES_GCNET_PATH
var_name = pd.read_csv(file_path)
var_name = var_name.set_index("old_name").GEUS_name
Expand All @@ -160,7 +167,7 @@ def readNead(infile):

# renaming variables to the GEUS names
ds = ds.rename(var_name)

# variables always dropped from the historical GC-Net files
# could be move to the config files at some point
standard_vars_to_drop = [
Expand Down Expand Up @@ -201,6 +208,28 @@ def loadArr(infile, isNead):
df = pd.read_csv(infile)
df["time"] = pd.to_datetime(df["time"]).dt.tz_localize(None)
df = df.set_index("time")

# renaming variables if GlacioBasis
file_path = pypromice.resources.DEFAULT_VARIABLES_ALIASES_GLACIOBASIS_PATH
var_name = pd.read_csv(file_path)
var_name = var_name.set_index("old_name").GEUS_name
msk = [v for v in var_name.index if v in df.columns]
var_name = var_name.loc[msk].to_dict()

# postprocessing for glaciobasis
if 'ice_ablation' in df.columns:
df['ice_ablation'] = (-df['ice_ablation'].diff()).cumsum()
df['z_surf_combined'] = df['ice_ablation'].values

# renaming variables to the GEUS names
df = df.rename(columns=var_name)

# variables always dropped from the historical GC-Net files
# could be move to the config files at some point
standard_vars_to_drop = ["I"]

# Drop the variables if they are present in the dataset
df = df.drop(columns=[var for var in standard_vars_to_drop if var in df.columns])
ds = xr.Dataset.from_dataframe(df)

elif infile.split(".")[-1].lower() in "nc":
Expand Down Expand Up @@ -366,7 +395,7 @@ def build_station_list(config_folder: str, target_station_site: str) -> list:
return station_info_list


def join_l3(config_folder, site, folder_l3, folder_gcnet, outpath, variables, metadata):
def join_l3(config_folder, site, folder_l3, folder_gcnet, folder_glaciobasis, outpath, variables, metadata):
# Get the list of station information dictionaries associated with the given site
list_station_info = build_station_list(config_folder, site)

Expand All @@ -377,9 +406,17 @@ def join_l3(config_folder, site, folder_l3, folder_gcnet, outpath, variables, me

filepath = os.path.join(folder_l3, stid, stid + "_hour.nc")
isNead = False
if station_info["project"].lower() in ["historical gc-net"]:
filepath = os.path.join(folder_gcnet, stid + ".csv")
isNead = True

if not os.path.isfile(filepath):
if station_info["project"].lower() in ["historical gc-net"]:
filepath = os.path.join(folder_gcnet, stid + ".csv")
isNead = True

if station_info["project"].lower() in ["glaciobasis"]:
filepath = os.path.join(folder_glaciobasis, stid + ".csv")
isNead = False

# import pdb; pdb.set_trace()
if not os.path.isfile(filepath):
logger.error(
"\n***\n"
Expand Down Expand Up @@ -551,6 +588,7 @@ def main():
args.site,
args.folder_l3,
args.folder_gcnet,
args.folder_glaciobasis,
args.outpath,
args.variables,
args.metadata,
Expand Down
1 change: 1 addition & 0 deletions src/pypromice/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
DEFAULT_METADATA_PATH = (Path(__file__).parent / "file_attributes.csv").absolute()
DEFAULT_VARIABLES_PATH = (Path(__file__).parent / "variables.csv").absolute()
DEFAULT_VARIABLES_ALIASES_GCNET_PATH = (Path(__file__).parent / "variable_aliases_GC-Net.csv").absolute()
DEFAULT_VARIABLES_ALIASES_GLACIOBASIS_PATH = (Path(__file__).parent / "variable_aliases_GlacioBasis.csv").absolute()

def load_metadata(path: Union[None, str, Path] = None) -> Dict[str, str]:
"""
Expand Down
8 changes: 8 additions & 0 deletions src/pypromice/resources/variable_aliases_GlacioBasis.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
GEUS_name,old_name
wspd_u,wspd
rh_u_cor,rh_u_corr
dsr_cor,dsr_corr
usr_cor,usr_corr
cc,cloud_cover
z_boom_u,z_boom
z_ice_surf,ice_ablation

0 comments on commit aeefc29

Please sign in to comment.