Skip to content

Commit

Permalink
fixed logging & some attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
BaptisteVandecrux committed Jun 15, 2024
1 parent a903538 commit 283a8d8
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/pypromice/process/L0toL1.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import numpy as np
import pandas as pd
import xarray as xr
import re

import re, logging
from pypromice.process.value_clipping import clip_values
logger = logging.getLogger(__name__)


def toL1(L0, vars_df, T_0=273.15, tilt_threshold=-100):
Expand All @@ -28,7 +28,7 @@ def toL1(L0, vars_df, T_0=273.15, tilt_threshold=-100):
-------
ds : xarray.Dataset
Level 1 dataset
'''
'''
assert(type(L0) == xr.Dataset)
ds = L0
ds.attrs['level'] = 'L1'
Expand Down
1 change: 1 addition & 0 deletions src/pypromice/process/join_l2.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def join_l2():
logger.info(f'Invalid files {args.file1}, {args.file2}')
exit()

all_ds.attrs['format'] = 'merged RAW and TX'

# Resample to hourly, daily and monthly datasets and write to file
prepare_and_write(all_ds, args.outpath, args.variables, args.metadata, resample = False)
Expand Down
2 changes: 1 addition & 1 deletion src/pypromice/process/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def getL0(infile, nodata, cols, skiprows, file_version,
try:
df.index = pd.to_datetime(df.index)
except ValueError as e:
logger.info("\n", infile)
logger.info("\n"+ infile)
logger.info("\nValueError:")
logger.info(e)
logger.info('\t\t> Trying pd.to_datetime with format=mixed')
Expand Down
7 changes: 4 additions & 3 deletions src/pypromice/process/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def resample_dataset(ds_h, t):
df_d[var] = _calcWindDir(df_d['wspd_x_'+var.split('_')[1]],
df_d['wspd_y_'+var.split('_')[1]])
else:
logger.info(var,'in dataframe but not','wspd_x_'+var.split('_')[1],'wspd_x_'+var.split('_')[1])
logger.info(var+' in dataframe but not wspd_x_'+var.split('_')[1]+' nor wspd_x_'+var.split('_')[1])

# recalculating relative humidity from average vapour pressure and average
# saturation vapor pressure
Expand All @@ -53,8 +53,9 @@ def resample_dataset(ds_h, t):

df_d[var] = (p_vap.to_series().resample(t).mean() \
/ es_wtr.to_series().resample(t).mean())*100
df_d[var+'_cor'] = (p_vap.to_series().resample(t).mean() \
/ es_cor.to_series().resample(t).mean())*100
if var+'_cor' in df_d.keys():
df_d[var+'_cor'] = (p_vap.to_series().resample(t).mean() \
/ es_cor.to_series().resample(t).mean())*100

vals = [xr.DataArray(data=df_d[c], dims=['time'],
coords={'time':df_d.index}, attrs=ds_h[c].attrs) for c in df_d.columns]
Expand Down
13 changes: 7 additions & 6 deletions src/pypromice/process/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,15 @@ def addMeta(ds, meta):
ds : xarray.Dataset
Dataset with metadata
'''
ds['lon'] = ds['gps_lon'].mean()
ds['lon'].attrs = ds['gps_lon'].attrs
if 'gps_lon' in ds.keys():
ds['lon'] = ds['gps_lon'].mean()
ds['lon'].attrs = ds['gps_lon'].attrs

ds['lat'] = ds['gps_lat'].mean()
ds['lat'].attrs = ds['gps_lat'].attrs
ds['lat'] = ds['gps_lat'].mean()
ds['lat'].attrs = ds['gps_lat'].attrs

ds['alt'] = ds['gps_alt'].mean()
ds['alt'].attrs = ds['gps_alt'].attrs
ds['alt'] = ds['gps_alt'].mean()
ds['alt'].attrs = ds['gps_alt'].attrs

# for k in ds.keys(): # for each var
# if 'units' in ds[k].attrs:
Expand Down
2 changes: 2 additions & 0 deletions src/pypromice/process/write.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ def writeNC(outfile, Lx, col_names=None):
names = [c for c in col_names if c in list(Lx.keys())]
else:
names = list(Lx.keys())
for var in names:
Lx[var].encoding = {}
Lx[names].to_netcdf(outfile, mode='w', format='NETCDF4', compute=True)

def getColNames(vars_df, ds, remove_nan_fields=False):
Expand Down

0 comments on commit 283a8d8

Please sign in to comment.