Merge "Omaha #3596 Adding original, unaltered satellite scripts." into omaha_14.4.1

Former-commit-id: 629ab024dc [formerly 7c5b340168 [formerly e0f436a866f2a736b793c3fb2b4fbe770208c6c0]]
Former-commit-id: 7c5b340168
Former-commit-id: 7a1508ac90
This commit is contained in:
Nate Jensen 2014-10-01 11:46:51 -05:00 committed by Gerrit Code Review
commit 8eb01b18bc
2 changed files with 321 additions and 0 deletions

View file

@ -0,0 +1,197 @@
#!/bin/csh
#
# A script wrapper that is meant to get data for a single satellite sector
# from the A-II database. The result is output to stdout as ASCII.
# The first line returned has the dimensions of the image, the time, and the
# source satellite of the data set returned. The rest is one line per row
# of satellite data. The data for each row undergoes second order compression
# Each pixel value of 0 or 255 is encoded as @ or #, respectively. Otherwise
# the first pixel on the row and any pixel that is more than 20 counts
# different than the previous one is encoded as two hex digits. Pixels the
# same as the previous are encoded as a period, pixels from 1 to 20 counts less
# than the previous are encoded as G through Z, and pixels from 1 to 20 counts
# more than the previous are encoded as g through z. There are no delimeters
# between the encoding for each pixel.
#
# This version can adapt to use a python stub that calls the
# data access framework.
#
# Usage:
#
# a2rdsat.csh {p} {h|i} sector channel {satid} date time {slop} {partition}
#
# p - (optional) A literal p.
# h|i - (optional) A literal h or literal i.
# Output pure undelimited hex or delimited integer values.
# sector - sector id
# channel - channel id
# satid - (optional) satellite id
# date - yyyy-mm-dd
# time - hh:mm
# slop - seconds of slop either side, defaults to 180
# partition - (optional) upper case letter indicating partition to get. For
# very large images data may need to be returned in pieces.
# Allowable partitions are A through D.
#
# The ids can be either D-2D integer ids, or AWIPS-II ascii ids, in which
# case they may need to be quoted on the command line.
#
# Integer ids can be looked up in a2satInfo.txt, channel id corresponds to
# the physicalElement, and satid corresponds to the creatingEntity.
#
# 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/a2rdsatNNNNN.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.
#
#
set rmpy = yes
if ( "$1" == "p" ) then
set rmpy = no
shift
endif
set encoding = 2
if ( "$1" == "h" ) then
set encoding = 1
shift
endif
if ( "$1" == "i" ) then
set encoding = 0
shift
endif
if ( "$1" == "p" ) then
set rmpy = no
shift
endif
#
# Identify directory this script is in, will be one of the directories we
# search for other files in.
#
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
#
# Locate python stub that we will modify to create the final python logic.
#
if ( -e ./a2rdsatStub.py ) then
set stubpy = ./a2rdsatStub.py
else if ( -e $mydir/a2rdsatStub.py ) then
set stubpy = $mydir/a2rdsatStub.py
else if ( -e $FXA_HOME/src/dm/sat/a2rdsatStub.py ) then
set stubpy = $FXA_HOME/src/dm/sat/a2rdsatStub.py
else if ( -e $FXA_HOME/bin/a2rdsatStub.py ) then
set stubpy = $FXA_HOME/bin/a2rdsatStub.py
else
bash -c "echo could not find a2rdsatStub.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
#
# Locate file containing mapping between D-2D interger ids and AWIPS-II ascii
# ids for sectors, channels, and satellites.
#
if ( -e ./a2satInfo.txt ) then
set satInf = ./a2satInfo.txt
else if ( -e $mydir/a2satInfo.txt ) then
set satInf = $mydir/a2satInfo.txt
else if ( -e $FXA_HOME/src/dm/sat/a2satInfo.txt ) then
set satInf = $FXA_HOME/src/dm/sat/a2satInfo.txt
else if ( -e $FXA_HOME/data/a2satInfo.txt ) then
set satInf = $FXA_HOME/data/a2satInfo.txt
else
bash -c "echo could not find a2satInfo.txt 1>&2"
exit
endif
#
#
set sss = `grep "^ *$1|.*sectorID" $satInf | cut '-d|' -f3`
if ( "$sss" == "" ) set sss = "$1"
set ccc = `grep "^ *$2|.*physicalElement" $satInf | cut '-d|' -f3`
if ( "$ccc" == "" ) set ccc = "$2"
shift
shift
#
# Get program that can do math with ascii time string, then use this to
# properly encode range of times for which we look for data.
#
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
set eee = `echo $1 | grep -v '.*-'`
if ( "$eee" != "" ) shift
set slop = `echo $3 | grep '[0-9]'`
if ( "$slop" == "" ) set slop = 180
set aaa = `$gtasUtil = $1 $2 -$slop`
set bbb = `$gtasUtil = $1 $2 $slop`
set ppp = `echo $argv[$#argv] | grep '^[A-Z]$'`
if ( "$ppp" == "" ) set ppp = 0
#
# Modify the text of special tags in stub to create finalized script.
#
set specpy = /tmp/a2rdsat${$}.py
rm -rf $specpy >& /dev/null
touch $specpy
chmod 775 $specpy
if ( "$eee" == "" ) then
cat $stubpy | sed "s/SSSSS/$sss/g" | sed "s/CCCCC/$ccc/g" | \
sed "s/AAAAA/$aaa/g" | sed "s/BBBBB/$bbb/g" | \
sed 's/^.*EEEEE.*$//g'| sed "s/PPPPP/$ppp/g" | \
sed "s/XXXXX/$encoding/g" >> $specpy
else
set eee = `grep "^ *$eee|.*creatingEntity" $satInf | cut '-d|' -f3`
cat $stubpy | sed "s/SSSSS/$sss/g" | sed "s/CCCCC/$ccc/g" | \
sed "s/AAAAA/$aaa/g" | sed "s/BBBBB/$bbb/g" | \
sed "s/EEEEE/$eee/g" | sed "s/PPPPP/$ppp/g" | \
sed "s/XXXXX/$encoding/g" >> $specpy
endif
#
# Submit the temporary python script stripping 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,124 @@
import BaseRequest
from com.raytheon.uf.common.message.response import ResponseMessageGeneric
from com.raytheon.edex.plugin.satellite.dao import SatelliteDao
# Perform a satellite request for data of interest
sr = BaseRequest.BaseRequest("satellite")
sr.addParameter("creatingEntity","EEEEE","=")
sr.addParameter("sectorID","SSSSS","=")
sr.addParameter("physicalElement","CCCCC","=")
sr.addParameter("dataTime","AAAAA",">=")
sr.addParameter("dataTime","BBBBB","<=")
result = sr.execute()
size = result.size()
if size == 0:
return ResponseMessageGeneric("Data not available")
# ResponseMessageGeneric. Payload is SatelliteRecord
rmg = result.get(0)
part = "PPPPP"
encoding = XXXXX
# SatelliteRecord
srec = rmg.getContents()
mytime = srec.getDataURI().split('/',4)[2]
myent = srec.getCreatingEntity()
# SatelliteDao. Inherits from PluginDao, which has a getHDF5Data method,
# which takes a PluginDataObject as an arg.
satdao = SatelliteDao("satellite")
# returns IDataRecord[]. IDataRecord is implemented by only one class --
# AbstractStorageRecord. ASR is extended by a few *DataRecord classes; one
# of them is ByteDataRecord
idra = satdao.getHDF5Data(srec,-1)
msg = "No data."
if len(idra) > 0:
# pick an arbitrary datarecord
idr = idra[0]
# this hints at the IDR's concrete class: ByteDataRecord
#print "true type of IDataRecord:", idr.getDataObject().toString()
dim = idr.getDimension()
if dim != 2:
return ResponseMessageGeneric(msg)
xLen = idr.getSizes()[0]
yLen = idr.getSizes()[1]
# byte[] -- the raw data
barray = idr.getByteData()
barraySize = len(barray)
if xLen * yLen != barraySize:
return ResponseMessageGeneric(msg)
plus = " ghijklmnopqrstuvwxyz"
minus = " GHIJKLMNOPQRSTUVWXYZ"
limit = 10000000
if encoding == 1 :
limit = limit/2
elif encoding == 0 :
limit = limit/8
k = xLen * ( yLen / 4 )
j = 0
nxy = yLen*xLen
if part=="D" :
j = k+k+k
elif part=="C" :
j = k+k
nxy = j+k
elif part=="B" :
j = k
nxy = j+k
elif part=="A" or nxy>limit :
nxy = k
msg = "\n"
if part<="A" :
msg += str(xLen) + " " + str(yLen) + " "
msg += mytime + " " + myent + "\n"
while j<nxy :
i = 0
kk = barray[i+j]
if kk<0 : kk += 256
if encoding == 0 :
msg += str(kk)
elif encoding == 1 :
msg += "%2.2x"%kk
elif kk == 0 :
msg += "@"
elif kk == 255 :
msg += "#"
else :
msg += "%2.2x"%kk
i += 1
while i<xLen :
k = barray[i+j]
if k<0 : k += 256
if encoding == 0 :
msg += " "+str(k)
elif encoding == 1 :
msg += "%2.2x"%k
elif k==0 :
msg += "@"
elif k == 255 :
msg += "#"
elif k==kk :
msg += "."
elif k>kk+20 or k<kk-20 :
msg += "%2.2x"%k
elif k>kk :
msg += plus[k-kk]
else :
msg += minus[kk-k]
kk = k
i += 1
msg += "\n"
j += xLen
return ResponseMessageGeneric(msg)