Skip to content

Commit

Permalink
Fix image scaling for INDIGO
Browse files Browse the repository at this point in the history
  • Loading branch information
minomicetto committed Sep 21, 2016
1 parent dc1bc8e commit 37c314c
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 86 deletions.
30 changes: 19 additions & 11 deletions indigo/precip_trend_analisys/precip_trend_analysis.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "precip_trend_analysis",
"author": "CMCC Foundation",
"abstract": "Workflow for the analysis of precipitation trends related to different scenarios. ${1} is ncores; ${2} is the model (e.g. CMCC-CM); ${3} is the scenario (e.g. rcp85); ${4} is the frequency (e.g. day); ${5} is the percentile (e.g. 0.9); ${6} is the past time subset (e.g. 1976_2006); ${7} is the future time subset (e.g. 2071_2101); ${8} is the geographic subset (e.g. 30:45|0:40); ${9} is the grid of output map using the format r<lon>x<lat> (e.g. r360x180), i.e. a global regular lon/lat grid (this parameter is optional and by default the lon/lat grid of input file is adopted); ${10} import type, set to '1' in case only subsetting data have to be imported (optional).",
"abstract": "Workflow for the analysis of precipitation trends related to different scenarios. ${1} is ncores; ${2} is the model (e.g. CMCC-CM); ${3} is the scenario (e.g. rcp85); ${4} is the frequency (e.g. day); ${5} is the percentile (e.g. 0.9); ${6} is the past time subset (e.g. 1976_2006); ${7} is the future time subset (e.g. 2071_2101); ${8} is the geographic subset (e.g. 30:45|0:40); ${9} is the grid of output map using the format r<lon>x<lat> (e.g. r360x180), i.e. a global regular lon/lat grid (this parameter is optional and by default the lon/lat grid of input file is adopted); ${10} import type, set to '1' in case only subsetting data have to be imported (optional); ${11} I/O server type.",
"exec_mode": "sync",
"cwd": "/",
"ncores": "${1}",
Expand Down Expand Up @@ -50,7 +50,7 @@
},
{
"name": "Import Historical",
"operator": "oph_importnc",
"operator": "oph_importnc3",
"arguments": [
"container=historical",
"exp_dim=lat|lon",
Expand All @@ -69,7 +69,9 @@
"units=d",
"subset_dims=time|lat|lon",
"subset_filter=${6}|${8}",
"subset_type=coord"
"subset_type=coord",
"offset=0|2|2",
"ioserver=${11}"
],
"dependencies": [
{ "task": "Import Type Selection Historical" }
Expand All @@ -85,7 +87,7 @@
},
{
"name": "Import Historical Only",
"operator": "oph_importnc",
"operator": "oph_importnc3",
"arguments": [
"container=historical",
"exp_dim=lat|lon",
Expand All @@ -101,7 +103,8 @@
"nhost=1",
"import_metadata=yes",
"check_compliance=no",
"units=d"
"units=d",
"ioserver=${11}"
],
"dependencies": [
{ "task": "Import without subsetting Historical" }
Expand All @@ -112,7 +115,8 @@
"operator": "oph_subset2",
"arguments": [
"subset_dims=time|lat|lon",
"subset_filter=${6}|${8}"
"subset_filter=${6}|${8}",
"offset=0|2|2"
],
"dependencies": [
{ "task": "Import Historical Only", "type": "single" }
Expand Down Expand Up @@ -188,7 +192,7 @@
},
{
"name": "Import Scenario",
"operator": "oph_importnc",
"operator": "oph_importnc3",
"arguments": [
"container=scenario",
"exp_dim=lat|lon",
Expand All @@ -207,7 +211,9 @@
"units=d",
"subset_dims=time|lat|lon",
"subset_filter=${7}|${8}",
"subset_type=coord"
"subset_type=coord",
"offset=0|2|2",
"ioserver=${11}"
],
"dependencies": [
{ "task": "Import Type Selection Scenario" }
Expand All @@ -223,7 +229,7 @@
},
{
"name": "Import Scenario Only",
"operator": "oph_importnc",
"operator": "oph_importnc3",
"arguments": [
"container=scenario",
"exp_dim=lat|lon",
Expand All @@ -239,7 +245,8 @@
"nhost=1",
"import_metadata=yes",
"check_compliance=no",
"units=d"
"units=d",
"ioserver=${11}"
],
"dependencies": [
{ "task": "Import without subsetting Scenario" }
Expand All @@ -250,7 +257,8 @@
"operator": "oph_subset2",
"arguments": [
"subset_dims=time|lat|lon",
"subset_filter=${7}|${8}"
"subset_filter=${7}|${8}",
"offset=0|2|2"
],
"dependencies": [
{ "task": "Import Scenario Only", "type": "single" }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Ensemble analysis related to precipitation trend analysis",
"author": "CMCC",
"abstract": "Usage: /path/precip_trend_analysis_ensemble.json file1.nc|file2.nc. The parameter is the list of (OPeNDAP URLs to) NC files to be analyzed.",
"abstract": "Usage: /path/precip_trend_analysis_ensemble.json file1.nc|file2.nc <ioserver>. ${1} is the list of (OPeNDAP URLs to) NC files to be analyzed; ${2} is I/O server type.",
"exec_mode": "sync",
"ncores": "1",
"on_exit":"oph_delete",
Expand Down Expand Up @@ -51,15 +51,16 @@
},
{
"name": "import",
"operator": "oph_importnc2",
"operator": "oph_importnc3",
"arguments": [
"cwd=/",
"measure=precip_trend",
"src_path=@{name_file}",
"import_metadata=yes",
"nfrag=1",
"container=ensemble",
"grid=map"
"grid=map",
"ioserver=${2}"
],
"dependencies": [
{
Expand Down
50 changes: 15 additions & 35 deletions indigo/precip_trend_analisys/script/precip_trend_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
InFile = "/".join([DataDir, "precip_trend_analysis.nc"])
OutFile = "/".join([DataDir, "precip_trend_analysis.png"])

Lats = sys.argv[3]

Lons = sys.argv[4]

# Process file

f = cdms2.open(InFile)
Expand All @@ -39,39 +43,6 @@

iso.fillareacolors = cols
iso.legend = vcs.mklabels(numpy.arange(-3, 3.01, .375))
# iso.list()

# Prettify ticks
# bottom
iso.xticlabels1 = "Lon30" # vcs predefined list
# sub ticks
iso.xmtics1 = "lon10_0"
# left
dic = {}
for i in range(-90, 91, 30):
if i < 0:
dic[i] = "%iS" % (-i)
elif i > 0:
dic[i] = "%iN" % i
else:
dic[i] = "Eq"
iso.yticlabels1 = dic
iso.ymtics1 = "lat10_0"

# top
# First create dic with empty ticks
dic = {}
for i in range(-90, 370, 30):
dic[i] = ""
iso.xticlabels2 = dic
# right
iso.yticlabels2 = dic

dic = {}
for i in range(-100, 370, 10):
dic[i] = ""
iso.ymtics2 = dic
iso.xmtics2 = dic

# Now create a template to move things around a bit
t = x.createtemplate()
Expand All @@ -80,8 +51,17 @@
t.ymintic1.priority = 1 # turn on left sub ticks
t.ymintic2.priority = 1 # turn on right sub ticks

t.scale(.9, "x")
t.moveto(.05, .2)
if Lons < 1.2*Lats:
t.scale(.9 * Lons / (2 * Lats), "x")
t.scale(1.5, "y")
elif Lons < 2*Lats:
t.scale(.9, "x")
t.scale(1.8 * Lats / Lons, "y")
else:
t.scale(.9, "x")
t.scale(.9, "y")
t.moveto(.05, .1)

# Move legend
t.legend.x1 = t.data.x2 + .03
t.legend.x2 = t.legend.x1 + .03
Expand Down
13 changes: 10 additions & 3 deletions indigo/precip_trend_analisys/script/precip_trend_analysis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ RelWorkDir="`dirname \"$0\"`"
AbsWorkDir="`( cd \"$RelWorkDir\" && pwd )`"
InFile=$OPH_SCRIPT_SESSION_PATH/$OPH_SCRIPT_WORKFLOW_ID/$FileName

LATS=180
LONS=360

# Bilinear regridding
if [ "$NewGrid" != "" ]; then

Expand All @@ -29,8 +32,10 @@ XFIRST=${LonRange%%:*}
YFIRST=${LatRange%%:*}
XLAST=${LonRange##*:}
YLAST=${LatRange##*:}
XINC=`echo "(($XLAST)-($XFIRST))/($XSIZE)" | bc -l`
YINC=`echo "(($YLAST)-($YFIRST))/($YSIZE)" | bc -l`
LATS=`echo "($YLAST)-($YFIRST)" | bc -l`
LONS=`echo "($XLAST)-($XFIRST)" | bc -l`
XINC=`echo "($LONS)/($XSIZE)" | bc -l`
YINC=`echo "($LATS)/($YSIZE)" | bc -l`
let XSIZE+=1
let YSIZE+=1

Expand Down Expand Up @@ -66,8 +71,10 @@ cp $InFile $BasePath/$OPH_SCRIPT_SESSION_CODE/$OPH_SCRIPT_WORKFLOW_ID/ 2>&1 > /d

# Create and publish UV-CDAT map
source activate $UVCDATenv
python $AbsWorkDir/precip_trend_analysis.py $AbsWorkDir $OPH_SCRIPT_SESSION_PATH/$OPH_SCRIPT_WORKFLOW_ID/
python $AbsWorkDir/precip_trend_analysis.py $AbsWorkDir $OPH_SCRIPT_SESSION_PATH/$OPH_SCRIPT_WORKFLOW_ID/ $LATS $LONS
source deactivate

cp $OPH_SCRIPT_SESSION_PATH/$OPH_SCRIPT_WORKFLOW_ID/precip_trend_analysis.png $BasePath/$OPH_SCRIPT_SESSION_CODE/$OPH_SCRIPT_WORKFLOW_ID/

exit 0

Original file line number Diff line number Diff line change
Expand Up @@ -41,39 +41,6 @@

iso.fillareacolors = cols
iso.legend = vcs.mklabels(numpy.arange(-3, 3.01, .375))
# iso.list()

# Prettify ticks
# bottom
iso.xticlabels1 = "Lon30" # vcs predefined list
# sub ticks
iso.xmtics1 = "lon10_0"
# left
dic = {}
for i in range(-90, 91, 30):
if i < 0:
dic[i] = "%iS" % (-i)
elif i > 0:
dic[i] = "%iN" % i
else:
dic[i] = "Eq"
iso.yticlabels1 = dic
iso.ymtics1 = "lat10_0"

# top
# First create dic with empty ticks
dic = {}
for i in range(-90, 370, 30):
dic[i] = ""
iso.xticlabels2 = dic
# right
iso.yticlabels2 = dic

dic = {}
for i in range(-100, 370, 10):
dic[i] = ""
iso.ymtics2 = dic
iso.xmtics2 = dic

# Now create a template to move things around a bit
t = x.createtemplate()
Expand All @@ -83,7 +50,8 @@
t.ymintic2.priority = 1 # turn on right sub ticks

t.scale(.9, "x")
t.moveto(.05, .2)
t.scale(1.8, "y")
t.moveto(.05, .1)
# Move legend
t.legend.x1 = t.data.x2 + .03
t.legend.x2 = t.legend.x1 + .03
Expand Down

0 comments on commit 37c314c

Please sign in to comment.