Commit ee938b7a authored by Carl Schreck's avatar Carl Schreck

Working version of calc_prism_diff.py

parent b0468758
#!/bin/bash --login
#if [ -z "$1" ]; then
# QUEUE=`pick_queue`
#else
# QUEUE=$1
#fi
QUEUE=allnodes
echo $QUEUE
PY_DIR=`pwd`
PY_SCRIPT=calc_prism_diff
LOG_DIR=$PY_DIR/log
mkdir -p $LOG_DIR
for month in {1..12}
do
for var_name in tmin tmax tmean ppt
# for var_name in tmean ppt
do
JOB_NAME=$PY_SCRIPT"_"$var_name"_"$month
echo $JOB_NAME `date`
LOG_FILE=$LOG_DIR/$JOB_NAME.log
ERR_FILE=$LOG_DIR/$JOB_NAME.err
PY_OPTION="--var_name "$var_name" --month "$month
rm $LOG_FILE $ERR_FILE
bsub \
-J $JOB_NAME \
-o $LOG_FILE \
-e $ERR_FILE \
-q $QUEUE \
-n 1 -R "span[hosts=1]" -W 48:00 \
-sp 75 \
~/template/run_py.sh $PY_DIR $PY_SCRIPT "$PY_OPTION"
done
done
......@@ -7,6 +7,7 @@ __license__ = "BSD-3.0"
import xarray as xr
import sys
import numpy as np
import argparse
import os
import cjs # '~carl/lib/python'
......@@ -18,8 +19,11 @@ parser.add_argument('--var_name', default='tavg')
parser.add_argument('--month', default=9)
args = parser.parse_args()
var_name = args.var_name
month = int(args.month)
years = range(1981,1982+1)
cjs.tstamp(f'{var_name} -- {month}')
years = range(1981,2018+1)
ncg_var_to_prism_var = {
'tmin': 'tmin',
......@@ -37,11 +41,31 @@ for year in years:
f'PRISM_{prism_var}_{year}{month:02}.nc'
ncg_ds = xr.open_dataset(ncg_path)
prism_ds = xr.open_dataset(prism_path)
sub_prism = prism_ds.sel(lat=ncg_ds.lat, lon=ncg_ds.lon, method='nearest')
sub_prism['lat'] = ncg_ds.lat
sub_prism['lon'] = ncg_ds.lon
if year == years[0]:
ncg_lat = ncg_ds.lat
ncg_lon = ncg_ds.lon
# make output vars that look like ncg
# sub_prism = subset using ncg lat/lon
cjs.tstamp(year)
bias = ((ncg_ds[ncg_var] - sub_prism[prism_var]).mean(dim='time')
/ len(years))
absdiff = (abs(ncg_ds[ncg_var] - sub_prism[prism_var]).mean(dim='time')
/ len(years))
else:
cjs.tstamp(year)
bias += ((ncg_ds[ncg_var] - sub_prism[prism_var]).mean(dim='time')
/ len(years))
absdiff += (abs(ncg_ds[ncg_var] - sub_prism[prism_var]).mean(dim='time')
/ len(years))
cjs.tstamp('Writing')
bias.attrs['long_name'] = 'Bias ncg - prism'
bias.attrs['units'] = ncg_ds[ncg_var].attrs['units']
absdiff.attrs['long_name'] = 'Absolute difference ncg - prism'
absdiff.attrs['units'] = ncg_ds[ncg_var].attrs['units']
ds = xr.Dataset(data_vars={'bias': bias, 'absdiff': absdiff})
out_path = f'{os.environ["DATA_DIR"]}/nclimgrid/beta/compare/' \
f'{ncg_var}-prism-{month:02}.nc'
ds.to_netcdf(out_path)
cjs.tstamp('Thank you, come again.')
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment