Skip to content

Commit

Permalink
Fix cscript() call for Ncl scripts, and fix those scripts re. decodin…
Browse files Browse the repository at this point in the history
…g "true"
  • Loading branch information
senesis committed Jan 30, 2024
1 parent d446a02 commit f779b82
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 52 deletions.
7 changes: 4 additions & 3 deletions climaf/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,15 @@ def do_move(crs, filename, outfilename):

global dropped_crs
#
# It appears that we have to let some time to the file system for updating its inode tables
# It appears that we have to let some time to the file system
# for updating its inode tables
waited = 0
while waited < 50 and not os.path.exists(filename):
time.sleep(0.1)
waited += 1
if not os.path.exists(filename):
raise Climaf_Cache_Error("File %s wasn't created upstream (or not quick enough). It represents %s" %
(filename, crs))
raise Climaf_Cache_Error("File %s wasn't created upstream " % filename +
"(or not quick enough). It represents %s" % crs)
else:
if stamping is False:
clogger.debug('No stamping')
Expand Down
57 changes: 28 additions & 29 deletions climaf/standard_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,20 +137,20 @@ def load_standard_operators():
#
cscript('plot', '(ncl -Q ' + scriptpath + 'gplot.ncl main_file=\'"${in}"\' aux_file=\'"${in_2}"\' '
'u_file=\'"${in_3}"\' v_file=\'"${in_4}"\' rotation=${rotation} '
'plotname=\'"${out}"\' colormap=\'"${color}\' vmin=${min} '
'plotname=\'"${out}"\' colormap=\'${color}\' vmin=${min} '
'vmax=${max} vdelta=${delta} main_var=\'"${Var}"\' '
'aux_var=\'"${var_2}"\' u_var=\'"${var_3}"\' v_var=\'"${var_4}"\' '
'title=\'${title}\' myscale=${scale} myoffset=${offset} '
'mpCenterLonF=${mpCenterLonF} vcRefMagnitudeF=${vcRefMagnitudeF} '
'vcRefLengthF=${vcRefLengthF} vcMinDistanceF=${vcMinDistanceF} '
'vcGlyphStyle=\'${vcGlyphStyle}\' '
'vcLineArrowColor=\'${vcLineArrowColor}\' units=\'"${units}"\' '
'vcLineArrowColor=\'${vcLineArrowColor}\' units=\'${units}\' '
'y=\'${y}\' ccolors=\'${colors}\' level=${level} time=${time} '
'date=\'${date}\' proj=\'${proj}\' contours=\'${contours}\' '
'date=\'"${date}"\' proj=\'${proj}\' contours=\'${contours}\' '
'focus=\'${focus}\' type=\'${format}\' '
'resolution=\'${resolution}\' trim=${trim} fmt=\'${fmt}\' '
'vcb=${vcb} lbLabelFontHeightF=${lbLabelFontHeightF} invXY=${invXY} '
'reverse=${reverse} tmYLLabelFontHeightF=${tmYLLabelFontHeightF} '
'resolution=\'${resolution}\' trim=\'"${trim}"\' fmt=\'${fmt}\' '
'vcb=\'"${vcb}"\' lbLabelFontHeightF=${lbLabelFontHeightF} invXY=\'"${invXY}"\' '
'reverse=\'"${reverse}"\' tmYLLabelFontHeightF=${tmYLLabelFontHeightF} '
'tmXBLabelFontHeightF=${tmXBLabelFontHeightF} '
'tmYRLabelFontHeightF=${tmYRLabelFontHeightF} '
'tiXAxisFontHeightF=${tiXAxisFontHeightF} '
Expand All @@ -165,41 +165,40 @@ def load_standard_operators():
'gsnStringFontHeightF=${gsnStringFontHeightF} '
'shade_below=${shade_below} shade_above=${shade_above} '
'options=\'${options}\' aux_options=\'${aux_options}\' '
'shade2_options=\'\${shade2_options}\"\' shade2_var=\'\"${var_5}\"\' '
'shade2_file=\'\"${in_5}\"\' '
'shade2_below=\'\${shade2_below}\"\' '
'shade2_above=\'\${shade2_above}\"\' '
'shading_options=\'\${shading_options}\"\' myscale_aux=${scale_aux} '
'myoffset_aux=${offset_aux} xpolyline=\'\${xpolyline}\"\' '
'ypolyline=\'\${ypolyline}\"\' '
'polyline_options=\'\${polyline_options}\"\' )',
'shade2_options=\'${shade2_options}\' shade2_var=\'${var_5}\' '
'shade2_file=\'"${in_5}"\' '
'shade2_below=\'${shade2_below}\' '
'shade2_above=\'${shade2_above}\' '
'shading_options=\'${shading_options}\' myscale_aux=${scale_aux} '
'myoffset_aux=${offset_aux} xpolyline=\'${xpolyline}\' '
'ypolyline=\'${ypolyline}\' '
'polyline_options=\'${polyline_options}\' )',
format="graph")
#
# curves: plot a series of xy curves (along time, lat, lon or pressure/z_index) for an ensemble
#
cscript('curves', '(ncl -Q ' + scriptpath + 'curves.ncl infile=\'\${mmin}\"\' '
'plotname=\'\"${out}\"\' var=\'\"${Var}\"\' title=\'\${title}\"\' '
'y=\'\${y}\"\' labels=\'\${labels}\"\' colors=\'\${colors}\"\' '
'units=\'\"${units}\"\' X_axis=\'\${X_axis}\"\' fmt=\'\${fmt}\"\' '
'options=\'\${options}\"\' aux_options=\'\${aux_options}\"\' '
cscript('curves', '(ncl -Q ' + scriptpath + 'curves.ncl infile=\'"${mmin}"\' '
'plotname=\'"${out}"\' var=\'"${Var}"\' title=\'${title}\' '
'y=\'${y}\' labels=\'${labels}\' colors=\'${colors}\' '
'units=\'${units}\' X_axis=\'${X_axis}\"\' fmt=\'${fmt}\' '
'options=\'${options}\' aux_options=\'${aux_options}\' '
'lgcols=${lgcols} myscale=${scale} myoffset=${offset} '
'type=\'\${format}\"\' resolution=\'\${resolution}\"\' trim=${trim} '
'invXY=${invXY} vmin=${min} vmax=${max} myscale_aux=${scale_aux} '
'type=\'${format}\' resolution=\'${resolution}\' trim=\'"${trim}"\' '
'invXY=\'"${invXY}"\' vmin=${min} vmax=${max} myscale_aux=${scale_aux} '
'myoffset_aux=${offset_aux} )',
format="graph")
#
# hovm : to plot Hovmoller diagrams
#
cscript('hovm',
'(ncl -Q ' + scriptpath +
'hovmoller.ncl infile=\'\${in}\"\' plotname=\'\${out}\"\' var=\'\${Var}\"\' '
' invXY=${invXY} latS=\'\${latS}\"\' latN=\'\${latN}\"\' lonW=\'\${lonW}\"\' '
'lonE=\'\${lonE}\"\' '
' colormap=\'\${color}\"\' myscale=${scale} myoffset=${offset} '
'units=\'\"${units}\"\' reverse=${reverse} mean_axis=\'\${mean_axis}\"\' '
'xpoint=${xpoint} ypoint=${ypoint} zpoint=${zpoint} title=\'\${title}\"\' '
' type=\'\${format}\"\' resolution=\'\${resolution}\"\' trim=${trim} '
'options=\'\${options}\"\' fmt=\'\${fmt}\"\' )',
'hovmoller.ncl infile=\'"${in}"\' plotname=\'"${out}"\' var=\'"${Var}"\' '
' invXY=\'"${invXY}"\' latS=${latS} latN=${latN} lonW=${lonW} lonE=${lonE} '
' colormap=\'${color}\' myscale=${scale} myoffset=${offset} '
'units=\'${units}\' reverse=\'"${reverse}"\' mean_axis=\'${mean_axis}\' '
'xpoint=${xpoint} ypoint=${ypoint} zpoint=${zpoint} title=\'${title}\' '
' type=\'${format}\' resolution=\'${resolution}\' trim=\'"${trim}"\' '
'options=\'${options}\' fmt=\'${fmt}\' )',
format="graph")
#
# cpdfcrop : pdfcrop by preserving metadata
Expand Down
Binary file modified examples/data/sfcWind_aladin_ext.nc
Binary file not shown.
22 changes: 18 additions & 4 deletions scripts/curves.ncl
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ function str_convert(str:string)
local val, valf
begin

if .not. ismissing(str_match(str,"True")) then
if .not. ismissing(str_match(str,"true")) then
return(True)
else
if .not. ismissing(str_match(str,"False")) then
if .not. ismissing(str_match(str,"false")) then
return(False)
else

Expand Down Expand Up @@ -153,8 +153,22 @@ begin
if (.not. isvar("myscale_aux")) then myscale_aux=1.0 end if
if (.not. isvar("myoffset_aux")) then myoffset_aux=0.0 end if
if (.not. isvar("type")) then type="png" end if
if (.not. isvar("trim")) then trim=True end if
if (.not. isvar("invXY")) then invXY=False end if

if (.not. isvar("invXY")) then
invXY=False
else
inv=str_convert(invXY)
delete(invXY)
invXY=inv
end if

if (.not. isvar("trim")) then
trim=True
else
inv=str_convert(trim)
delete(trim)
trim=inv
end if

files=str_split(infile," ")
n=dimsizes(files)
Expand Down
48 changes: 37 additions & 11 deletions scripts/gplot.ncl
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ function str_convert(str:string)

local val, valf
begin

if .not. ismissing(str_match(str,"True")) then
if .not. ismissing(str_match(str,"true")) then
return(True)
else
if .not. ismissing(str_match(str,"False")) then
if .not. ismissing(str_match(str,"false")) then
return(False)
else

Expand Down Expand Up @@ -768,8 +767,38 @@ begin
if (.not. isvar("myscale_aux")) then myscale_aux=1.0 end if
if (.not. isvar("myoffset_aux")) then myoffset_aux=0.0 end if
if (.not. isvar("type")) then type="png" end if
if (.not. isvar("trim")) then trim=True end if
if (.not. isvar("invXY")) then invXY=False end if

if (.not. isvar("trim")) then
trim=True
else
inv=str_convert(trim)
delete(trim)
trim=inv
end if

if (.not. isvar("invXY")) then
invXY=False
else
inv=str_convert(invXY)
delete(invXY)
invXY=inv
end if

if (.not. isvar("vcb")) then
vcb=True
else
inv=str_convert(vcb)
delete(vcb)
vcb=inv
end if

if (.not. isvar("reverse")) then
reverse=False
else
inv=str_convert(reverse)
delete(reverse)
reverse=inv
end if

LABELON=False
RASTER=True
Expand Down Expand Up @@ -917,7 +946,6 @@ begin
end if
else
power10=floattoint(log10(dim_max(ndtooned(tofloat(fld)))))
print(power10)
if ismissing(power10) then
print("Field has only missing values" )
power10=1
Expand Down Expand Up @@ -1104,7 +1132,7 @@ begin

i = NhlNewColor(wks,0.8,0.8,0.8)
; reverse colormap
if (isvar("reverse") .and. reverse) then gsn_reverse_colormap(wks) end if
if reverse then gsn_reverse_colormap(wks) end if

; main field resources
res=True
Expand Down Expand Up @@ -1181,12 +1209,10 @@ begin
res@lbLabelFontThicknessF= 3.0
res@lbTitleFontThicknessF= 3.0
res@lbLabelAutoStride = True
if ( .not. isvar("vcb") .or. (isvar("vcb") .and. vcb) ) then
if vcb then
res@lbOrientation = "vertical"
else
if ( isvar("vcb") .and. (.not. vcb) ) then
res@lbOrientation = "horizontal"
end if
res@lbOrientation = "horizontal"
end if

; Axis Label
Expand Down
31 changes: 26 additions & 5 deletions scripts/hovmoller.ncl
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ function str_convert(str:string)
local val, valf
begin

if .not. ismissing(str_match(str,"True")) then
if .not. ismissing(str_match(str,"true")) then
return(True)
else
if .not. ismissing(str_match(str,"False")) then
if .not. ismissing(str_match(str,"false")) then
return(False)
else

Expand Down Expand Up @@ -581,12 +581,33 @@ begin
end if

if (.not.isvar("colormap")) then colormap="amwg256" end if
if (.not.isvar("reverse")) then reverse=False end if
if (.not.isvar("myscale")) then myscale=1.0 end if
if (.not.isvar("myoffset")) then myoffset=0.0 end if
if (.not.isvar("type")) then type="png" end if
if (.not. isvar("invXY")) then invXY=False end if
if (.not.isvar("trim")) then trim=True end if

if (.not. isvar("trim")) then
trim=True
else
inv=str_convert(trim)
delete(trim)
trim=inv
end if

if (.not. isvar("invXY")) then
invXY=False
else
inv=str_convert(invXY)
delete(invXY)
invXY=inv
end if

if (.not. isvar("reverse")) then
reverse=False
else
inv=str_convert(reverse)
delete(reverse)
reverse=inv
end if
;
;---Defining data to plot
;
Expand Down

0 comments on commit f779b82

Please sign in to comment.