Skip to content

Commit

Permalink
Updated support for Grace. Other fixes from Alper's repo for HR
Browse files Browse the repository at this point in the history
  • Loading branch information
Abishek Gopal committed Jul 12, 2021
1 parent 7830672 commit 83f0f4a
Show file tree
Hide file tree
Showing 8 changed files with 373 additions and 162 deletions.
18 changes: 11 additions & 7 deletions Machines/grace_modules
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,25 @@

echo "Loading modules for CESM_postprocessing tool..."

module purge

ml purge
export MODULEPATH=/scratch/group/ihesp/software/easybuild/eb/x86_64/mods/all/Core
ml intel/2019b
ml NCO
ml NCL
ml ANTLR
ml HDF5
#ml NCL/6.6.2
#ml NCO/4.7.9
#ml netCDF/4.6.1
ml Python/2.7.16

export NCARG_ROOT=/scratch/group/ihesp/software/share/ncl-6.6.2
export NCO_PATH=/scratch/group/ihesp/software/share/nco-4.9.4/nco-4.9.7
export NETCDF4_PATH=/scratch/group/ihesp/software/share/netcdf-c-4.7.4/install2019b_2
export LD_LIBRARY_PATH=$NCARG_ROOT/lib:$NCO_PATH/lib:$NETCDF4_PATH/lib:$LD_LIBRARY_PATH
export PATH=$NCARG_ROOT/bin:$NCO_PATH/bin:$NETCDF4_PATH/bin:$PATH

#export NCARG_ROOT=/scratch/group/ihesp/software/share/ncl-6.6.2
#export NCO_PATH=/scratch/group/ihesp/software/share/nco-4.9.4/nco-4.9.7
#export NETCDF4_PATH=/scratch/group/ihesp/software/share/netcdf-c-4.7.4/install2019b_2
#export NETCDFF_PATH=/scratch/group/ihesp/software/share/netcdf-fortran-4.5.3/install2019b_2
#export LD_LIBRARY_PATH=$NCARG_ROOT/lib:$NCO_PATH/lib:$NETCDF4_PATH/lib:$NETCDFF_PATH/lib:$LD_LIBRARY_PATH
#export PATH=$NCARG_ROOT/bin:$NCO_PATH/bin:$NETCDF4_PATH/bin:$NETCDFF_PATH/bin:$PATH

#source /ihesp/user/agopal/CESM_postprocessing/cesm-env2/bin/activate
#export PYTHONPATH=/ihesp/user/agopal/CESM_postprocessing/pynio/site-packages:$PYTHONPATH
Expand Down
5 changes: 3 additions & 2 deletions Machines/machine_postprocess.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
<module>export NCARG_ROOT=/scratch/group/ihesp/software/share/ncl-6.6.2</module>
<module>export NCO_PATH=/scratch/group/ihesp/software/share/nco-4.9.4/nco-4.9.7/install</module>
<module>export NETCDF4_PATH=/scratch/group/ihesp/software/share/netcdf-c-4.7.4/install2019b_2</module>
<module>export LD_LIBRARY_PATH=$NCARG_ROOT/lib:$NCO_PATH/lib:$NETCDF4_PATH/lib:$LD_LIBRARY_PATH</module>
<module>export PATH=$NCARG_ROOT/bin:$NCO_PATH/bin:$NETCDF4_PATH/bin:$PATH</module>
<module>export NETCDFF_PATH=/scratch/group/ihesp/software/share/netcdf-fortran-4.5.3/install2019b_2</module>
<module>export LD_LIBRARY_PATH=$NCARG_ROOT/lib:$NCO_PATH/lib:$NETCDF4_PATH/lib:$NETCDFF_PATH/lib:$LD_LIBRARY_PATH</module>
<module>export PATH=$NCARG_ROOT/bin:$NCO_PATH/bin:$NETCDF4_PATH/bin:$NETCDFF_PATH/bin:$PATH</module>
<module>export PYTHONPATH=/scratch/group/iheso/software/CESM_postprocessing/cesm-env2/lib/python2.7/site-packages/PyNIO:$PYTHONPATH</module>
<!-- <module>ml NCL/6.6.2-foss-2018b</module>
<module>ml NCO/4.7.9-foss-2018b</module>
Expand Down
8 changes: 4 additions & 4 deletions create_python_env
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,13 @@ export FC=gfortran F77=gfortran CC=gcc
export PYTHONPATH=$pp_dir/cesm-env2/lib/python2.7/site-packages
export PYNIOPATH=$pp_dir/cesm-env2/lib/python2.7/site-packages/PyNIO
export HAS_NETCDF4=1
export NETCDF4_PREFIX="/sw/eb/software/netCDF/4.6.1-foss-2018b-cdf5/"
export NETCDF4_PREFIX="/scratch/group/ihesp/software/share/netcdf-c-4.7.4/install2019b_2/"
export HAS_HDF5=1
export HDF5_PREFIX="/sw/eb/software/HDF5/1.10.2-foss-2018b/"
export HDF5_PREFIX="/sw/eb/sw/HDF5/1.10.5-iimpi-2019b"
export F2CLIBS=gfortran
export F2CLIBS_PREFIX="/software/easybuild/software/GCCcore/6.3.0/bin/gfortran"

export F2CLIBS_PREFIX="/sw/eb/sw/GCCcore/8.3.0/bin/gfortran"

export NETCDF_PREFIX=/scratch/group/ihesp/software/share/netcdf-c-4.7.4/install2019b_2
rm -rf pynio ASAPPyTools
git clone https://github.com/NCAR/pynio.git
cd pynio
Expand Down
27 changes: 16 additions & 11 deletions diag_utils/diag_utils/diagUtilsLib.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import subprocess
import sys
import time
from timeout_mod import timeout, TimeoutError

from cesm_utils import cesmEnvLib

Expand All @@ -40,8 +41,11 @@ def check_ncl_nco(envDict):

cmd = ['ncks', '--version']
try:
pipe = subprocess.Popen(cmd , env=envDict)
pipe.wait()
with timeout(seconds=900):
pipe = subprocess.Popen(cmd , env=envDict)
pipe.wait()
except TimeoutError:
print("WARNING: timeout at "+__file__)
except OSError as e:
print('NCO ncks is required to run the ocean diagnostics package')
print('ERROR: {0} call to "{1}" failed with error:'.format('check_ncl_nco', ' '.join(cmd)))
Expand All @@ -65,11 +69,14 @@ def generate_ncl_plots(env, nclPlotFile):
rc, err_msg = cesmEnvLib.checkFile(nclFile, 'read')
if rc:
try:
pipe = subprocess.Popen(['ncl {0}'.format(nclFile)], cwd=env['WORKDIR'], env=env, shell=True, stdout=subprocess.PIPE)
output = pipe.communicate()[0]
print('NCL routine {0} \n {1}'.format(nclFile,output))
while pipe.poll() is None:
time.sleep(0.5)
with timeout(seconds=900):
pipe = subprocess.Popen(['ncl {0}'.format(nclFile)], cwd=env['WORKDIR'], env=env, shell=True, stdout=subprocess.PIPE)
output = pipe.communicate()[0]
print('NCL routine {0} \n {1}'.format(nclFile,output))
while pipe.poll() is None:
time.sleep(0.5)
except TimeoutError:
print("WARNING: timeout at "+__file__)
except OSError as e:
print('WARNING',e.errno,e.strerror)
else:
Expand Down Expand Up @@ -200,12 +207,11 @@ def checkHistoryFiles(tseries, dout_s_root, case, rstart_year, rstop_year, comp,
"""
if tseries.upper() in ['T','TRUE'] :
htype = 'series'
## in_dir = '{0}/{1}/proc/tseries/month_1'.format(dout_s_root, comp)
else :
htype = 'slice'
## in_dir = '{0}/{1}/hist'.format(dout_s_root, comp)

# make sure subdir does not include a trailing "/"
if subdir.endswith('/'):
subdir = subdir[:-1]
in_dir = '{0}/{1}/{2}'.format(dout_s_root, comp, subdir)

# check the in_dir directory exists
Expand Down Expand Up @@ -499,7 +505,6 @@ def lnd_regrid(climo_file, regrid_script, t, outdir, ext_dir, env):
env['area_file']= env['new_res_'+t]+'_area.nc'
env['procDir'] = tmp_outdir
env['oldres'] = env['old_res_'+t]
env['newres'] = env['new_res_'+t]
env['InFile'] = os.path.basename(climo_file)
env['OutFile'] = env['new_res_'+t]+'_'+os.path.basename(climo_file)
env['newfn'] = env['old_res_'+t]+'_'+os.path.basename(climo_file)
Expand Down
15 changes: 15 additions & 0 deletions diag_utils/diag_utils/timeout_mod.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import signal
class timeout:
def __init__(self, seconds=1, error_message='Timeout'):
self.seconds = seconds
self.error_message = error_message
def handle_timeout(self, signum, frame):
raise TimeoutError(self.error_message)
def __enter__(self):
signal.signal(signal.SIGALRM, self.handle_timeout)
signal.alarm(self.seconds)
def __exit__(self, type, value, traceback):
signal.alarm(0)

class TimeoutError(Exception):
pass
201 changes: 98 additions & 103 deletions ocn_diag/ncl_lib/iagez.ncl
Original file line number Diff line number Diff line change
Expand Up @@ -6,110 +6,105 @@ load "$NCLPATH/contour_plot.ncl"

begin

print( " plotting IAGE at "+ n_depth + " depth levels")

fileid = addfile(file_netcdf,"r")

if (isfilevar(fileid,"IAGE"))
iage = fileid->IAGE
else
return
end if

if (isatt(iage,"_FillValue"))
missing = iage@_FillValue
else
missing = 1e30
end if
units = iage@units

tlon = fileid->TLONG
tlat = fileid->TLAT
size = dimsizes(tlon)
nx = size(1)
ny = size(0)
ulon = fileid->ULONG
ulat = fileid->ULAT
kmt = fileid->KMT
kmu = fileid->KMU
region_mask = fileid->REGION_MASK
tarea = fileid->TAREA
uarea = fileid->UAREA
angle = fileid->ANGLE
anglet = fileid->ANGLET
z_t = fileid->z_t
nz = dimsizes(z_t)
z_t = z_t / 100.

nlev = 21
coltab = new(nlev + 1,"integer")
color1 = 2
coltab(1:) = ((color2-color1+1)/(nlev-1))*ispan(0,nlev-1,1)+color1
coltab(0) = 0

do l=0, n_depth-1

dep = depth(l)
min_diff = min(abs(z_t - dep))
klev_arr = ind(abs(dep-z_t) .eq. min_diff) ; if 2 depth are equally distant you get an array
klev = klev_arr(0)
delete(klev_arr)
zdep = z_t(klev)
if (dimsizes(dimsizes(iage)) .eq. 4) then
field = iage(0,klev,:,:)
else
field = iage(klev,:,:)
end if

; print( " plotting IAGE at "+ n_depth + " depth levels")
;
; fileid = addfile(file_netcdf,"r")
; iage = fileid->IAGE
; if (isatt(iage,"_FillValue"))
; missing = iage@_FillValue
; else
; missing = 1e30
; end if
; units = iage@units
;
; tlon = fileid->TLONG
; tlat = fileid->TLAT
; size = dimsizes(tlon)
; nx = size(1)
; ny = size(0)
; ulon = fileid->ULONG
; ulat = fileid->ULAT
; kmt = fileid->KMT
; kmu = fileid->KMU
; region_mask = fileid->REGION_MASK
; tarea = fileid->TAREA
; uarea = fileid->UAREA
; angle = fileid->ANGLE
; anglet = fileid->ANGLET
; z_t = fileid->z_t
; nz = dimsizes(z_t)
; z_t = z_t / 100.
;
; "gauss" level type not supported yet
; nlev = 21
; coltab = new(nlev + 1,"integer")
; color1 = 2
; coltab(1:) = ((color2-color1+1)/(nlev-1))*ispan(0,nlev-1,1)+color1
; coltab(0) = 0
;
if (cntrlvls .eq. "gauss") then
print ("'gauss' CNTRLVLS not currently supported in NCL version of OMWG: using 'std' method")
end if
dmin = min (field)
dmax = max (field)
if ( dmax-dmin .le. 20. ) then
dlev = 20. / (nlev-1)
else if (dmax-dmin .le. 50.) then
dlev = 50. / (nlev-1)
else if (dmax-dmin .le. 100.) then
dlev = 100. / (nlev-1)
else if (dmax-dmin .le. 500.) then
dlev = 500. / (nlev-1)
else if (dmax-dmin .le. 1000.) then
dlev = 1000. / (nlev-1)
else if (dmax-dmin .le. 5000.) then
dlev = 5000. / (nlev-1)
end if
end if
end if
end if
end if
end if
dmin = tointeger(dmin/dlev)*dlev
if ( dmin .lt. 0. ) then
dmin = dmin - dlev
end if
lev = dmin + ispan(0,nlev-1,1)*dlev

depstr = sprintf("%.0f",dep)
zdepstr = sprintf("%6.1fm",zdep)
case_info = "IAGE at z="+zdepstr+", " + case_number + " " + time_info

; wks = gsn_open_wks("x11","IAGE"+depstr)
wks = gsn_open_wks(img_format,"IAGE"+depstr)
gsn_define_colormap(wks,"table42")

opt = True
opt@charsize = 0.9
opt@landcolor = lndcolor
opt@contourline = 2
opt@xrange = (/ xr0,xr1/)
opt@yrange = (/ yr0,yr1/)
plot1 = contour_plot(wks, field, tlon, tlat, kmt, region_mask, tarea, case_info, \
missing, units, dlev, lev, coltab, opt)
end do
; do l=0, n_depth-1
;
; dep = depth(l)
; min_diff = min(abs(z_t - dep))
; klev_arr = ind(abs(dep-z_t) .eq. min_diff) ; if 2 depth are equally distant you get an array
; klev = klev_arr(0)
; delete(klev_arr)
; zdep = z_t(klev)
; if (dimsizes(dimsizes(iage)) .eq. 4) then
; field = iage(0,klev,:,:)
; else
; field = iage(klev,:,:)
; end if
;
;;
;; "gauss" level type not supported yet
;;
; if (cntrlvls .eq. "gauss") then
; print ("'gauss' CNTRLVLS not currently supported in NCL version of OMWG: using 'std' method")
; end if
; dmin = min (field)
; dmax = max (field)
; if ( dmax-dmin .le. 20. ) then
; dlev = 20. / (nlev-1)
; else if (dmax-dmin .le. 50.) then
; dlev = 50. / (nlev-1)
; else if (dmax-dmin .le. 100.) then
; dlev = 100. / (nlev-1)
; else if (dmax-dmin .le. 500.) then
; dlev = 500. / (nlev-1)
; else if (dmax-dmin .le. 1000.) then
; dlev = 1000. / (nlev-1)
; else if (dmax-dmin .le. 5000.) then
; dlev = 5000. / (nlev-1)
; end if
; end if
; end if
; end if
; end if
; end if
; dmin = tointeger(dmin/dlev)*dlev
; if ( dmin .lt. 0. ) then
; dmin = dmin - dlev
; end if
; lev = dmin + ispan(0,nlev-1,1)*dlev
;
; depstr = sprintf("%.0f",dep)
; zdepstr = sprintf("%6.1fm",zdep)
; case_info = "IAGE at z="+zdepstr+", " + case_number + " " + time_info
;
; ; wks = gsn_open_wks("x11","IAGE"+depstr)
; wks = gsn_open_wks(img_format,"IAGE"+depstr)
; gsn_define_colormap(wks,"table42")
;
; opt = True
; opt@charsize = 0.9
; opt@landcolor = lndcolor
; opt@contourline = 2
; opt@xrange = (/ xr0,xr1/)
; opt@yrange = (/ yr0,yr1/)
; plot1 = contour_plot(wks, field, tlon, tlat, kmt, region_mask, tarea, case_info, \
; missing, units, dlev, lev, coltab, opt)
; end do

exit()

end

Loading

0 comments on commit 83f0f4a

Please sign in to comment.