Skip to content

Commit

Permalink
update environment variables in EOF_500hpa ncl files (#603)
Browse files Browse the repository at this point in the history
fix file formatting
change axis def to uppercase in pod settings file
  • Loading branch information
wrongkindofdoctor authored Jul 8, 2024
1 parent 296c8c0 commit 315ccba
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 37 deletions.
57 changes: 30 additions & 27 deletions diagnostics/EOF_500hPa/EOF_500hPa.py
Original file line number Diff line number Diff line change
@@ -1,70 +1,73 @@
# This file is part of the EOF_500hPa module of the MDTF code package (see LICENSE.txt)

#============================================================
# ============================================================
# EOF of 500hPa Height Diagnostics
# Sample code to call NCL from python
#============================================================
# ============================================================

import os
import subprocess
import time

#============================================================

# ============================================================
# generate_ncl_plots - call a nclPlotFile via subprocess call
#============================================================
# ============================================================


def generate_ncl_plots(nclPlotFile):
"""generate_plots_call - call a nclPlotFile via subprocess call
Arguments:
nclPlotFile (string) - full path to ncl plotting file name
"""
# check if the nclPlotFile exists -
# don't exit if it does not exists just print a warning.
# don't exit if it does not exist just print a warning.
try:
pipe = subprocess.Popen(['ncl {0}'.format(nclPlotFile)], shell=True, stdout=subprocess.PIPE)
output = pipe.communicate()[0].decode()
print('NCL routine {0} \n {1}'.format(nclPlotFile,output))
print('NCL routine {0} \n {1}'.format(nclPlotFile, output))
while pipe.poll() is None:
time.sleep(0.5)
except OSError as e:
print('WARNING',e.errno,e.strerror)
print('WARNING', e.errno, e.strerror)

return 0

print("Entered "+__file__)

print("Entered " + __file__)
filename1 = os.environ["ZG_FILE"]
filename2a = os.environ["ZG_HYBRID_SIGMA_FILE"]
filename2b = os.environ["PS_FILE"]
print("Looking for "+filename1)
if not os.path.isfile( filename1 ):
print("ERROR missing file "+filename1)
print("Looking for " + filename1)
if not os.path.isfile(filename1):
print("ERROR missing file " + filename1)
os.environ['USE_HYBRID_SIGMA'] = "1"
print("Looking for "+filename2a)
if not os.path.isfile( filename2a ):
print("ERROR missing file "+filename2a)
print("Looking for " + filename2a)
if not os.path.isfile(filename2a):
print("ERROR missing file " + filename2a)
os.environ['USE_HYBRID_SIGMA'] = "0"
print("Looking for "+filename2b)
if not os.path.isfile( filename2b ):
print("ERROR missing file "+filename2b)

print("Looking for " + filename2b)
if not os.path.isfile(filename2b):
print("ERROR missing file " + filename2b)

if os.path.isfile(filename1) \
or (os.path.isfile(filename2a) and os.path.isfile(filename2b)):
print("height and surface pressure files found")
or (os.path.isfile(filename2a) and os.path.isfile(filename2b)):
print("height and surface pressure files found")
print("computing EOF of geopotential height anomalies of 500 hPa")

#============================================================
# Call NCL code here
#============================================================
# ============================================================
# Call NCL code here
# ============================================================
print("COMPUTING ANOMALIES")
generate_ncl_plots(os.environ["POD_HOME"]+"/compute_anomalies.ncl")
generate_ncl_plots(os.environ["POD_HOME"] + "/compute_anomalies.ncl")

print(" N ATLANTIC EOF PLOT")
generate_ncl_plots(os.environ["POD_HOME"]+"/eof_natlantic.ncl")
generate_ncl_plots(os.environ["POD_HOME"] + "/eof_natlantic.ncl")

print(" N PACIFIC EOF PLOT")
generate_ncl_plots(os.environ["POD_HOME"]+"/eof_npacific.ncl")
generate_ncl_plots(os.environ["POD_HOME"] + "/eof_npacific.ncl")


else:
print("height and surface pressure files NOT found, skip EOF of geopotential height anomalies of 500 hPa")
print("height and surface pressure files NOT found, skip EOF of geopotential height anomalies of 500 hPa")
6 changes: 3 additions & 3 deletions diagnostics/EOF_500hPa/compute_anomalies.ncl
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ begin

setfileoption("nc", "Format", getenv("MDTF_NC_FORMAT"))

wk_dir = getenv("WK_DIR")
wk_dir = getenv("WORK_DIR")
casename = getenv("CASENAME")
yr1 = getenv("FIRSTYR")
yr2 = getenv("LASTYR")
yr1 = getenv("startdate")
yr2 = getenv("enddate")
date_off = getenv("date_int_offset")
use_hybrid_sigma = (getenv("USE_HYBRID_SIGMA").eq."1")

Expand Down
6 changes: 3 additions & 3 deletions diagnostics/EOF_500hPa/eof_natlantic.ncl
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
setfileoption("nc", "Format", getenv("MDTF_NC_FORMAT"))

begin
yr1 = getenv("FIRSTYR")
yr2 = getenv("LASTYR")
yr1 = getenv("startdate")
yr2 = getenv("enddate")
rgb = getenv("RGB")
wk_dir = getenv("WK_DIR")
wk_dir = getenv("WORK_DIR")
casename = getenv("CASENAME")

firstyr = stringtointeger(yr1)
Expand Down
6 changes: 3 additions & 3 deletions diagnostics/EOF_500hPa/eof_npacific.ncl
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
setfileoption("nc", "Format", getenv("MDTF_NC_FORMAT"))

begin
yr1 = getenv("FIRSTYR")
yr2 = getenv("LASTYR")
yr1 = getenv("startdate")
yr2 = getenv("enddate")
rgb = getenv("RGB")
wk_dir = getenv("WK_DIR")
wk_dir = getenv("WORK_DIR")
casename = getenv("CASENAME")

firstyr = stringtointeger(yr1)
Expand Down
2 changes: 1 addition & 1 deletion diagnostics/EOF_500hPa/settings.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"lon": {
"standard_name": "longitude",
"units": "degrees_east",
"axis": "x"
"axis": "X"
},
"plev": {
"standard_name": "air_pressure",
Expand Down

0 comments on commit 315ccba

Please sign in to comment.