Skip to content
Snippets Groups Projects
Commit 2e51b667 authored by Aaron Spring's avatar Aaron Spring
Browse files

add logging cdo_post

parent f633f8d1
No related branches found
No related tags found
No related merge requests found
......@@ -6,6 +6,7 @@ import pandas as pd
import xarray as xr
import cdo
import logging
warnings.simplefilter('ignore')
xr.set_options(keep_attrs=True)
......@@ -29,7 +30,6 @@ def find_all_outdatatypes_in_exp(expid=expid, exppath=exppath, year=1990):
paths = glob.glob(path)
for f in paths:
file = os.path.basename(f)
# print(file)
# remove expid
file2 = file.strip(expid).strip('_')
parts = file2.split('_')
......@@ -45,7 +45,7 @@ def find_all_outdatatypes_in_exp(expid=expid, exppath=exppath, year=1990):
outdatatype = outdatatype.strip(f'{year}0101_{year}1231')
if outdatatype == 'co':
outdatatype = 'co2'
print(
logging.DEBUG(
f'Found file: model={model} outdatatype={outdatatype} '
f'ending={ending}'
)
......@@ -61,7 +61,7 @@ def read_all_outdatatype_files_to_ds(
ds_list = []
for outdatatype_id in outdatatypes:
try:
print(f'Read {outdatatype_id} to xr.Dataset.')
logging.INFO(f'Read {outdatatype_id} to xr.Dataset.')
parts = outdatatype_id.split('_')
model = parts[0]
outdatatype = '_'.join(parts[1:])
......@@ -101,7 +101,7 @@ def read_all_outdatatype_files_to_ds(
ds[v].attrs['dims'] = list(ds[v].dims)
ds_list.append(ds.isel(time=0).mean())
except Exception as e:
print(f'{outdatatype_id} failed: {e}')
logging.ERROR(f'{outdatatype_id} failed: {e}')
return xr.merge(ds_list, compat='override')
......@@ -136,7 +136,7 @@ def generate_output_df(
# standard path
path = outpath + 'MPI-ESM-1-2-LR_output.csv'
if not recalc and os.path.exists(path):
print(f'Read df from path: {path}')
logging.DEBUG(f'Read df from path: {path}')
output_df = (
pd.read_csv(path, index_col='varname')
.rename(columns={'Unnamed: 0': 'varname'})
......@@ -194,7 +194,7 @@ def load_var_cdo(
)
def load_cdo(var, path, options, sel=sel):
print(f'cdo {options} -select,name={var}{sel} {path}')
logging.DEBUG(f'cdo {options} -select,name={var}{sel} {path}')
return cdo.select(
f'name={var}{sel}',
input=path,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment