Merge "Omaha #3598 Add original, unaltered grid scripts." into omaha_14.4.1

Former-commit-id: 887b47cda1 [formerly 89d6e37d13413a7c8c8045c0c8d369e1cb61a2f4]
Former-commit-id: 9079801e98
This commit is contained in:
Nate Jensen 2014-10-20 11:50:40 -05:00 committed by Gerrit Code Review
commit 0ea89ff7bb
3 changed files with 468 additions and 0 deletions

View file

@ -0,0 +1,265 @@
#!/bin/csh -f
#
# A script wrapper that is meant to get a single slab of gridded data
# from the A-II database. The data is output to stdout as ASCII.
# This version can adapt to use a python stub that calls the
# data access framework.
#
# Usage:
#
# a2rdmdl.csh p n x srcid ctyp lval1 lval2 varAbrev date hour fcst
#
# p - A literal p. (optional)
# n - A literal n. (optional)
# x - A literal x. (optional)
# srcid - Unique alphanumeric name for gridded data source.
# ctyp - Level type id (optional)
# lval1 - First level value (optional)
# lval2 - Second level value (optional)
# varAbrev - Variable abreviation.
# date - Date of model run time as yyyy-mm-dd
# hour - Hour of model run time as hh
# fcst - Forecast time in hours
#
# Legacy usage, not supported in all cases:
#
# a2rdmdl.csh p n x gproc ggid ctyp lval1 lval2 varAbrev date hour fcst
#
# p - A literal p. (optional)
# n - A literal n. (optional)
# x - A literal x. (optional)
# gproc - GRIB process number (can be multiple comma delimited)
# ggid - GRIB grid number
# ctyp - Level type id (optional)
# lval1 - First level value (optional)
# lval2 - Second level value (optional)
# varAbrev - Variable abreviation.
# date - Date of model run time as yyyy-mm-dd
# hour - Hour of model run time as hh
# fcst - Forecast time in hours
#
# With the new unified GRIB decoder, instead of gproc ggid, it is best
# to supply the srcid, which is like ETA or GFS254; e.g. the directory
# under /awips2/edex/data/hdf5/grid where the data is stored.
#
# Note that now for sources with no <grid> tag in the associated <model>
# entry, the ggid must be supplied as a quoted empty string.
#
# The literal p option means preserve the final version of the python
# submitted to the UEngine instead of cleaning it up. The path to the
# finalized python is /tmp/a2rdmdlNNNNN.py where NNNNN is a unix process id.
# The literal n option means the first line of output is the dimension of
# the grid returned. The literal x option means return the data in xdr
# format; in this case the xdr data begins immediately after a tab-linefeed.
#
# Process any one character options.
#
set rmpy = yes
set dimStr = dimStr
set specpyName = a2rdmdlStub
while (1)
if ( "$1" == "p" ) then
set rmpy = no
else if ( "$1" == "n" ) then
set dimStr = qwertyuiop
else if ( "$1" == "x" ) then
set specpyName = a2rdmdlXdr
set dimStr = qwertyuiopx
else
break
endif
shift
end
#
# Identify directory this script is in, will be one of the directories we
# search for other files we need.
#
set mydir = `dirname $0`
set d1 = `echo $mydir | cut -c1`
if ( "$mydir" == '.' ) then
set mydir = $PWD
else if ( "$d1" != "/" ) then
set mydir = $PWD/$mydir
endif
set mydir = `(cd $mydir ; pwd)`
if ( ! $?FXA_HOME ) set FXA_HOME = xxxx
#
# Special case of topo, we will hard code it.
#
echo " $* " | grep " Topo " >& /dev/null
if ( $status == 0 ) then
set outfile = `find . -maxdepth 1 \
-name "$1.Topo" -o -name "$1.$2.Topo" -o -name "*,$1.$2.Topo" -o \
-name "$1,*.$2.Topo" -o -name "*,$1,*.$2.Topo"` >& /dev/null
if ( ( $#outfile != 1 ) && ( $mydir != $PWD ) ) then
set outfile = `find $mydir -maxdepth 1 \
-name "$1.Topo" -o -name "$1.$2.Topo" -o -name "*,$1.$2.Topo" -o \
-name "$1,*.$2.Topo" -o -name "*,$1,*.$2.Topo"` >& /dev/null
endif
if ( ( $#outfile != 1 ) && ( -d $FXA_HOME/data ) ) then
set outfile = `find $FXA_HOME/data -maxdepth 1 \
-name "$1.Topo" -o -name "$1.$2.Topo" -o -name "*,$1.$2.Topo" -o \
-name "$1,*.$2.Topo" -o -name "*,$1,*.$2.Topo"` >& /dev/null
endif
if ( $#outfile != 1 ) then
bash -c "echo No flat file available with topo for $1 $2 1>&2"
exit
endif
if ( "$dimStr" == "qwertyuiop" ) then
set nnn = `cat $outfile | wc`
set ny = $nnn[1]
@ nx = $nnn[2] / $ny
echo $nx $ny
endif
cat $outfile
exit
endif
#
# Primarily base stuff on source name, but try to use the old interface.
#
set sss = "$1"
shift
set ids = `echo $sss | tr ',' ' '`
echo "$ids[1]" | grep '^[0-9][0-9]*$' >& /dev/null
if ( $status == 0 || $#ids > 1 ) then
set mroot = /awips2/edex/data/utility/edex_static/base/grib/models
set ids = `echo $ids | tr ' ' '\n' | grep -v '^ *$' | \
sed 's#^#<id>#g' | sed 's#$#<|#g'`
set ids = `echo ${ids}quertyuiop | sed 's/ *//g'`
set ggg = "$1"
shift
if ( "$ggg" == "" ) then
set mmm = `find $mroot -name '*xml' ! -name '*ECMWF*' \
-exec cat '{}' \; | sed 's|-->|~|g' | \
tr '\t' ' ' | sed 's/ *//g' | sed 's|</model>|~|g' | \
tr '\n' ' ' | tr '~' '\n' | grep -E "$ids" | \
grep -v "<grid>" | sed 's/^.*<name>//g' | \
cut '-d<' -f1 | sort -u`
else
set mmm = `find $mroot -name '*xml' -exec cat '{}' \; | \
sed 's|-->|~|g' | \
tr '\t' ' ' | sed 's/ *//g' | sed 's|</model>|~|g' | \
tr '\n' ' ' | tr '~' '\n' | grep -E "$ids" | \
grep "<grid>$ggg<" | sed 's/^.*<name>//g' | \
cut '-d<' -f1 | sort -u`
endif
if ( $#mmm != 1 ) then
echo "$mmm"
echo "Could not look up model name based on $sss '$ggg'"
exit 1
endif
set sss = $mmm
endif
#
set rrrrr = ""
@ i = $#argv - 3
set vvvvv = $argv[$i]
set aaa = `echo $vvvvv | grep -E '^CP|^TP|^LgSP' | tr 'A-z' ' '`
set aaa = `echo $aaa`
#
# Special case of formatting the times for accumulated precip
#
if ( "$aaa" != "" ) then
if ( -x ./gtasUtil ) then
set gtasUtil = ./gtasUtil
else if ( -x $mydir/gtasUtil ) then
set gtasUtil = $mydir/gtasUtil
else if ( -x $FXA_HOME/src/dm/point/gtasUtil ) then
set gtasUtil = $FXA_HOME/src/dm/point/gtasUtil
else if ( -x $FXA_HOME/bin/gtasUtil ) then
set gtasUtil = $FXA_HOME/bin/gtasUtil
else
bash -c "echo could not find gtasUtil executable 1>&2"
exit
endif
@ i++
set t = `echo $* | cut '-d ' -f${i}-$#argv`
@ fff = $t[3] * 3600
set vt = `$gtasUtil = $t[1] ${t[2]}:00:00.0 $fff`
@ aaa = $aaa * 3600
set bt = `$gtasUtil = $vt -$aaa`
set rrrrr = "[$bt--$vt]"
endif
#
# Locate python stub that we will modify to create the final python logic.
#
if ( -e ./${specpyName}.py ) then
set stubpy = ./${specpyName}.py
else if ( -e $mydir/${specpyName}.py ) then
set stubpy = $mydir/${specpyName}.py
else if ( -e $FXA_HOME/src/dm/grid/${specpyName}.py ) then
set stubpy = $FXA_HOME/src/dm/grid/${specpyName}.py
else if ( -e $FXA_HOME/bin/${specpyName}.py ) then
set stubpy = $FXA_HOME/bin/${specpyName}.py
else
bash -c "echo could not find ${specpyName}.py 1>&2"
exit
endif
#
# Determine if we are using the data access framework or the uEngine.
#
grep DataAccessLayer $stubpy >& /dev/null
if ( $status == 0 ) then
set method = "daf"
else
#
# Set up the environment we need to run the UEngine.
#
set method = "uengine"
if ( -e ./UEngine.cshsrc ) then
set ueenv = ./UEngine.cshsrc
else if ( -e $mydir/UEngine.cshsrc ) then
set ueenv = $mydir/UEngine.cshsrc
else if ( -e $FXA_HOME/src/dm/point/UEngine.cshsrc ) then
set ueenv = $FXA_HOME/src/dm/point/UEngine.cshsrc
else if ( -e $FXA_HOME/bin/UEngine.cshsrc ) then
set ueenv = $FXA_HOME/bin/UEngine.cshsrc
else
bash -c "echo could not find UEngine.cshsrc 1>&2"
exit
endif
source $ueenv
endif
#
# Modify the text of special tags in stub to create finalized script.
#
set specpy = /tmp/a2rdmdl${$}.py
rm -rf $specpy >& /dev/null
touch $specpy
chmod 775 $specpy
if ( "$5" == "" ) then
cat $stubpy | grep -v $dimStr | sed "s/SSSSS/$sss/g" | \
sed 's/^.*TTTTT.*$//g' | sed 's/^.*LLLLL.*$//g' | \
sed 's/^.*22222.*$//g' | sed "s/VVVVV/$1/g" | sed "s/DDDDD/$2/g" | \
sed "s/HHHHH/$3/g" | sed "s/FFFFF/$4/g" | sed "s/RRRRR/$rrrrr/g" >> \
$specpy
else if ( "$6" == "" ) then
cat $stubpy | grep -v $dimStr | sed "s/SSSSS/$sss/g" | \
sed "s/TTTTT/$1/g" | sed 's/^.*LLLLL.*$//g' | sed 's/^.*22222.*$//g' | \
sed "s/VVVVV/$2/g" | sed "s/DDDDD/$3/g" | \
sed "s/HHHHH/$4/g" | sed "s/FFFFF/$5/g" | sed "s/RRRRR/$rrrrr/g" >> \
$specpy
else if ( "$7" == "" ) then
cat $stubpy | grep -v $dimStr | sed "s/SSSSS/$sss/g" | \
sed "s/TTTTT/$1/g" | sed "s/LLLLL/$2/g" | sed 's/^.*22222.*$//g' | \
sed "s/VVVVV/$3/g" | sed "s/DDDDD/$4/g" | \
sed "s/HHHHH/$5/g" | sed "s/FFFFF/$6/g" | sed "s/RRRRR/$rrrrr/g" >> \
$specpy
else
cat $stubpy | grep -v $dimStr | sed "s/SSSSS/$sss/g" | \
sed "s/TTTTT/$1/g" | sed "s/LLLLL/$2/g" | sed "s/22222/$3/g" | \
sed "s/VVVVV/$4/g" | sed "s/DDDDD/$5/g" | \
sed "s/HHHHH/$6/g" | sed "s/FFFFF/$7/g" | sed "s/RRRRR/$rrrrr/g" >> \
$specpy
endif
#
# Submit the temporary python script stripping any xml stuff, then remove it
#
if ( "$method" == "daf" ) then
/awips2/python/bin/python $specpy
else
cd $UE_BIN_PATH
( uengine -r python < $specpy ) | grep -v '<' | grep -v Response
endif
if ( "$rmpy" == "yes" ) rm -rf $specpy >& /dev/null
#

View file

@ -0,0 +1,139 @@
# Example to retrieve a single grid point
import GridRequest
from com.raytheon.uf.common.message.response import ResponseMessageGeneric
from com.raytheon.edex.uengine.tasks.decode import FileIn
# Perform a grid request for data of interest
gr = GridRequest.GridRequest("grid")
gr.addParameter("info.datasetId", "SSSSS")
gr.addParameter("info.level.masterLevel.name", "TTTTT")
gr.addParameter("info.level.levelonevalue", "LLLLL")
gr.addParameter("info.level.leveltwovalue", "22222")
gr.addParameter("info.parameter.abbreviation", "VVVVV")
gr.addParameter("dataTime", "DDDDD HHHHH:00:00.0 (FFFFF)RRRRR")
result = gr.query.execute()
size = result.size()
if size == 0:
return ResponseMessageGeneric("Data not available")
# For the purposes of this script, take the first response
currentQuery = result.get(0)
# Get the data in memory
fileIn = FileIn("grid", currentQuery)
data = fileIn.execute()
if data:
# Pull out float[] and get sizes
rawData = data.getFloatData()
xLen = data.getSizes()[0]
yLen = data.getSizes()[1]
dimStr = str(xLen) + " " + str(yLen) + "\n"
# Pull out float[] and get sizes
rawData = data.getFloatData()
xLen = data.getSizes()[0]
yLen = data.getSizes()[1]
msg = "\n"
msg += dimStr
nxy = yLen*xLen
j = nxy-xLen
while j>=0 :
i = 0
while i<xLen :
k = rawData[i+j]
if k<0 :
a = -k
else :
a = k
if a>=999998 :
msg += "1e37 "
elif a<0.00005 :
msg += "%g"%k + " "
elif a<0.0009 :
if round(k,8) == round(k,4) :
msg += "%.4f"%k + " "
elif round(k,8) == round(k,5) :
msg += "%.5f"%k + " "
elif round(k,8) == round(k,6) :
msg += "%.6f"%k + " "
elif round(k,8) == round(k,7) :
msg += "%.7f"%k + " "
else :
msg += "%.8f"%k + " "
elif a<0.009 :
if round(k,7) == round(k,3) :
msg += "%.3f"%k + " "
elif round(k,7) == round(k,4) :
msg += "%.4f"%k + " "
elif round(k,7) == round(k,5) :
msg += "%.5f"%k + " "
elif round(k,7) == round(k,6) :
msg += "%.6f"%k + " "
else :
msg += "%.7f"%k + " "
elif a<0.09 :
if round(k,6) == round(k,2) :
msg += "%.2f"%k + " "
elif round(k,6) == round(k,3) :
msg += "%.3f"%k + " "
elif round(k,6) == round(k,4) :
msg += "%.4f"%k + " "
elif round(k,6) == round(k,5) :
msg += "%.5f"%k + " "
else :
msg += "%.6f"%k + " "
elif a<0.9 :
if round(k,5) == round(k,1) :
msg += "%.1f"%k + " "
elif round(k,5) == round(k,2) :
msg += "%.2f"%k + " "
elif round(k,5) == round(k,3) :
msg += "%.3f"%k + " "
elif round(k,5) == round(k,4) :
msg += "%.4f"%k + " "
else :
msg += "%.5f"%k + " "
elif a<9 :
if round(k,4) == round(k,0) :
msg += "%.0f"%k + " "
elif round(k,4) == round(k,1) :
msg += "%.1f"%k + " "
elif round(k,4) == round(k,2) :
msg += "%.2f"%k + " "
elif round(k,4) == round(k,3) :
msg += "%.3f"%k + " "
else :
msg += "%.4f"%k + " "
elif a<99 :
if round(k,3) == round(k,0) :
msg += "%.0f"%k + " "
elif round(k,3) == round(k,1) :
msg += "%.1f"%k + " "
elif round(k,3) == round(k,2) :
msg += "%.2f"%k + " "
else :
msg += "%.3f"%k + " "
elif a<999 :
if round(k,2) == round(k,0) :
msg += "%.0f"%k + " "
elif round(k,2) == round(k,1) :
msg += "%.1f"%k + " "
else :
msg += "%.2f"%k + " "
elif a<9999 :
if round(k,1) == round(k,0) :
msg += "%.0f"%k + " "
else :
msg += "%.1f"%k + " "
else :
msg += "%.0f"%k + " "
i += 1
msg += "\n"
j -= xLen
return ResponseMessageGeneric(msg)
return ResponseMessageGeneric("Data not available")

View file

@ -0,0 +1,64 @@
# Example to retrieve a single grid point
import xdrlib
import bz2
import GridRequest
from com.raytheon.uf.common.message.response import ResponseMessageGeneric
from com.raytheon.edex.uengine.tasks.decode import FileIn
# Perform a grid request for data of interest
gr = GridRequest.GridRequest("grid")
gr.addParameter("info.datasetId", "SSSSS")
gr.addParameter("info.level.masterLevel.name", "TTTTT")
gr.addParameter("info.level.levelonevalue", "LLLLL")
gr.addParameter("info.level.leveltwovalue", "22222")
gr.addParameter("info.parameter.abbreviation", "VVVVV")
gr.addParameter("dataTime", "DDDDD HHHHH:00:00.0 (FFFFF)RRRRR")
result = gr.query.execute()
size = result.size()
if size == 0:
return ResponseMessageGeneric("Data not available")
# For the purposes of this script, take the first response
currentQuery = result.get(0)
# Get the data in memory
fileIn = FileIn("grid", currentQuery)
data = fileIn.execute()
if data:
# Pull out float[] and get sizes
rawData = data.getFloatData()
xLen = data.getSizes()[0]
yLen = data.getSizes()[1]
dimStr = str(xLen) + " " + str(yLen) + "\n"
# Pull out float[] and get sizes
rawData = data.getFloatData()
xLen = data.getSizes()[0]
yLen = data.getSizes()[1]
msg = "\n"
msg += dimStr
nxy = yLen*xLen
j = nxy-xLen
mypacker = xdrlib.Packer()
mypacker.reset()
while j>=0 :
i = 0
while i<xLen :
mypacker.pack_float(float(rawData[i+j]))
i += 1
j -= xLen
packLen = len(mypacker.get_buffer())
xdrbuf = bz2.compress(mypacker.get_buffer())
cmpLen = len(xdrbuf)
msg += str(packLen)+" "+str(cmpLen*2)+"\t\n"
i = 0
while i<cmpLen :
msg += "%2.2x"%ord(xdrbuf[i])
i += 1
msg += "\t\n"
return ResponseMessageGeneric(msg)
return ResponseMessageGeneric("Data not available")