Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/appending-ZAC-historical-data #299

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
adding GlacioBasis folder to inputs and appending
BaptisteVandecrux committed Sep 3, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit aeefc29846a807cb9373c6dd85c7c63859198638
3 changes: 2 additions & 1 deletion src/pypromice/process/aws.py
Original file line number Diff line number Diff line change
@@ -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},"
50 changes: 44 additions & 6 deletions src/pypromice/process/join_l3.py
Original file line number Diff line number Diff line change
@@ -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",
@@ -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
@@ -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 = [
@@ -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":
@@ -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)

@@ -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"
@@ -551,6 +588,7 @@ def main():
args.site,
args.folder_l3,
args.folder_gcnet,
args.folder_glaciobasis,
args.outpath,
args.variables,
args.metadata,
1 change: 1 addition & 0 deletions src/pypromice/resources/__init__.py
Original file line number Diff line number Diff line change
@@ -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]:
"""
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