Omaha #3598 Update grid scripts to use DAF. Accept level information in request identifiers.
Change-Id: I18011b95dc7dc2a0d92d41ce6e7864d3aaa1afbf Former-commit-id:0d9689b67f
[formerly13847affbe
] [formerly679c836fdc
] [formerly679c836fdc
[formerlyd9f75f5adc
]] [formerly1ff018ccdf
[formerly679c836fdc
[formerlyd9f75f5adc
] [formerly1ff018ccdf
[formerly 8b001934bef0d672bce4739accf994eba497b32c]]]] Former-commit-id:1ff018ccdf
Former-commit-id: 977dcd6801a22609734f368763c01300e2539785 [formerly b988090e50ef8a0a1762d20eee5f1c4b63a30f77] [formerly674b6c2dcc
[formerly23950384ee
]] Former-commit-id:674b6c2dcc
Former-commit-id:43cae5f6da
This commit is contained in:
parent
3e3d0b0be1
commit
e4d5c8679f
5 changed files with 536 additions and 264 deletions
|
@ -1,19 +1,19 @@
|
|||
/**
|
||||
* This software was developed and / or modified by Raytheon Company,
|
||||
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||
*
|
||||
*
|
||||
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||
* This software product contains export-restricted data whose
|
||||
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||
* to non-U.S. persons whether in the United States or abroad requires
|
||||
* an export license or other authorization.
|
||||
*
|
||||
*
|
||||
* Contractor Name: Raytheon Company
|
||||
* Contractor Address: 6825 Pine Street, Suite 340
|
||||
* Mail Stop B8
|
||||
* Omaha, NE 68106
|
||||
* 402.291.0100
|
||||
*
|
||||
*
|
||||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
|
@ -53,11 +53,11 @@ import com.raytheon.uf.common.util.mapping.Mapper;
|
|||
|
||||
/**
|
||||
* Data access factory for accessing data from the Grid plugin as grid types.
|
||||
*
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------- -------- ----------- --------------------------
|
||||
* Jan 17, 2013 bsteffen Initial creation
|
||||
|
@ -66,10 +66,11 @@ import com.raytheon.uf.common.util.mapping.Mapper;
|
|||
* Feb 04, 2014 2672 bsteffen Enable requesting subgrids.
|
||||
* Jul 30, 2014 3184 njensen Renamed valid identifiers to optional
|
||||
* Sep 09, 2014 3356 njensen Remove CommunicationException
|
||||
*
|
||||
*
|
||||
* Oct 16, 2014 3598 nabowle Accept level identifiers.
|
||||
*
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* @author bsteffen
|
||||
* @version 1.0
|
||||
*/
|
||||
|
@ -81,7 +82,9 @@ public class GridDataAccessFactory extends AbstractGridDataPluginFactory
|
|||
|
||||
private static final String[] VALID_IDENTIFIERS = {
|
||||
GridConstants.DATASET_ID, GridConstants.SECONDARY_ID,
|
||||
GridConstants.ENSEMBLE_ID, NAMESPACE };
|
||||
GridConstants.ENSEMBLE_ID, NAMESPACE,
|
||||
GridConstants.MASTER_LEVEL_NAME, GridConstants.LEVEL_ONE,
|
||||
GridConstants.LEVEL_TWO };
|
||||
|
||||
@Override
|
||||
public String[] getOptionalIdentifiers() {
|
||||
|
@ -109,6 +112,9 @@ public class GridDataAccessFactory extends AbstractGridDataPluginFactory
|
|||
}
|
||||
|
||||
if (request.getLevels() != null) {
|
||||
checkForLevelConflict(request.getLevels(),
|
||||
request.getIdentifiers());
|
||||
|
||||
for (Level level : request.getLevels()) {
|
||||
assembler.setMasterLevelName(level.getMasterLevel()
|
||||
.getName());
|
||||
|
@ -152,6 +158,18 @@ public class GridDataAccessFactory extends AbstractGridDataPluginFactory
|
|||
assembler.setSecondaryId(identifiers.get(
|
||||
GridConstants.SECONDARY_ID).toString());
|
||||
}
|
||||
if (identifiers.containsKey(GridConstants.MASTER_LEVEL_NAME)) {
|
||||
assembler.setMasterLevelName(identifiers.get(
|
||||
GridConstants.MASTER_LEVEL_NAME).toString());
|
||||
}
|
||||
if (identifiers.containsKey(GridConstants.LEVEL_ONE)) {
|
||||
assembler.setLevelOneValue((Double) identifiers
|
||||
.get(GridConstants.LEVEL_ONE));
|
||||
}
|
||||
if (identifiers.containsKey(GridConstants.LEVEL_TWO)) {
|
||||
assembler.setLevelTwoValue((Double) identifiers
|
||||
.get(GridConstants.LEVEL_TWO));
|
||||
}
|
||||
}
|
||||
mergeConstraintMaps(assembler.getConstraintMap(), result);
|
||||
} catch (CommunicationException e) {
|
||||
|
@ -160,10 +178,37 @@ public class GridDataAccessFactory extends AbstractGridDataPluginFactory
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for possible level conflicts.
|
||||
*
|
||||
* @param levels
|
||||
* The request levels. Assumed to not be null.
|
||||
* @param identifiers
|
||||
* The request identifiers.
|
||||
* @throws DataRetrievalException
|
||||
* if levels is not empty and at least one of the
|
||||
* {@link GridConstants#MASTER_LEVEL_NAME},
|
||||
* {@link GridConstants#LEVEL_ONE}, or
|
||||
* {@link GridConstants#LEVEL_TWO} identifiers is specified.
|
||||
*/
|
||||
private void checkForLevelConflict(Level[] levels,
|
||||
Map<String, Object> identifiers) {
|
||||
if (levels.length > 0
|
||||
&& identifiers != null
|
||||
&& (identifiers.containsKey(GridConstants.MASTER_LEVEL_NAME)
|
||||
|| identifiers.containsKey(GridConstants.LEVEL_ONE) || identifiers
|
||||
.containsKey(GridConstants.LEVEL_TWO))) {
|
||||
throw new DataRetrievalException(
|
||||
"Conflict between the request levels and request "
|
||||
+ "identifiers. Please set the levels either as"
|
||||
+ " identifiers or as levels, not both.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy all constraints from source to target. If target already contains a
|
||||
* constraint for a key then merge the values into target.
|
||||
*
|
||||
*
|
||||
* @param target
|
||||
* @param source
|
||||
*/
|
||||
|
|
|
@ -1,4 +1,33 @@
|
|||
#!/bin/csh -f
|
||||
##
|
||||
# This software was developed and / or modified by Raytheon Company,
|
||||
# pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||
#
|
||||
# U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||
# This software product contains export-restricted data whose
|
||||
# export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||
# to non-U.S. persons whether in the United States or abroad requires
|
||||
# an export license or other authorization.
|
||||
#
|
||||
# Contractor Name: Raytheon Company
|
||||
# Contractor Address: 6825 Pine Street, Suite 340
|
||||
# Mail Stop B8
|
||||
# Omaha, NE 68106
|
||||
# 402.291.0100
|
||||
#
|
||||
# See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
# further licensing information.
|
||||
##
|
||||
|
||||
# Gets all available raob data in the A-II database over a specified range of
|
||||
# times. The data is output to stdout as ASCII.
|
||||
#
|
||||
# SOFTWARE HISTORY
|
||||
#
|
||||
# Date Ticket# Engineer Description
|
||||
# ------------ ---------- ----------- --------------------------
|
||||
# 2014-10-16 3598 nabowle Initial modification. Changed to handle DataAccessLayer.
|
||||
#
|
||||
#
|
||||
# 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.
|
||||
|
@ -150,36 +179,10 @@ if ( $status == 0 || $#ids > 1 ) then
|
|||
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.
|
||||
#
|
||||
|
@ -200,12 +203,25 @@ endif
|
|||
#
|
||||
grep DataAccessLayer $stubpy >& /dev/null
|
||||
if ( $status == 0 ) then
|
||||
set method = "daf"
|
||||
set userArgs = "--srcId $sss --varAbrev $vvvvv"
|
||||
if ( ( "$dimStr" != "dimStr" ) && ( "$specpyName" != "a2rdmdlXdr" ) ) then
|
||||
set userArgs = "$userArgs --dimLine"
|
||||
endif
|
||||
|
||||
if ( "$5" == "" ) then
|
||||
set userArgs = "$userArgs --date $2 --hour $3 --fcst $4"
|
||||
else if ( "$6" == "" ) then
|
||||
set userArgs = "$userArgs --lvlName $1 --date $3 --hour $4 --fcst $5"
|
||||
else if ( "$7" == "" ) then
|
||||
set userArgs = "$userArgs --lvlName $1 --lvlOne $2 --date $4 --hour $5 --fcst $6"
|
||||
else
|
||||
set userArgs = "$userArgs --lvlName $1 --lvlOne $2 --lvlTwo $3 --date $5 --hour $6 --fcst $7"
|
||||
endif
|
||||
python $stubpy $userArgs
|
||||
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
|
||||
|
@ -219,47 +235,71 @@ else
|
|||
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
|
||||
|
||||
set rrrrr = ""
|
||||
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
|
||||
|
||||
#
|
||||
# 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
|
||||
#
|
||||
cd $UE_BIN_PATH
|
||||
( uengine -r python < $specpy ) | grep -v '<' | grep -v Response
|
||||
if ( "$rmpy" == "yes" ) rm -rf $specpy >& /dev/null
|
||||
endif
|
||||
if ( "$rmpy" == "yes" ) rm -rf $specpy >& /dev/null
|
||||
#
|
||||
|
|
132
pythonPackages/msaslaps/grid/a2rdmdlCommon.py
Normal file
132
pythonPackages/msaslaps/grid/a2rdmdlCommon.py
Normal file
|
@ -0,0 +1,132 @@
|
|||
##
|
||||
# This software was developed and / or modified by Raytheon Company,
|
||||
# pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||
#
|
||||
# U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||
# This software product contains export-restricted data whose
|
||||
# export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||
# to non-U.S. persons whether in the United States or abroad requires
|
||||
# an export license or other authorization.
|
||||
#
|
||||
# Contractor Name: Raytheon Company
|
||||
# Contractor Address: 6825 Pine Street, Suite 340
|
||||
# Mail Stop B8
|
||||
# Omaha, NE 68106
|
||||
# 402.291.0100
|
||||
#
|
||||
# See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
# further licensing information.
|
||||
##
|
||||
|
||||
# Gets all available raob data in the A-II database over a specified range of
|
||||
# times. The data is output to stdout as ASCII.
|
||||
#
|
||||
# SOFTWARE HISTORY
|
||||
#
|
||||
# Date Ticket# Engineer Description
|
||||
# ------------ ---------- ----------- --------------------------
|
||||
# 2014-10-15 3598 nabowle Initial creation. Extracted common code from a2rdmdl*.py
|
||||
#
|
||||
|
||||
import argparse
|
||||
import numpy
|
||||
|
||||
from datetime import datetime
|
||||
from ufpy.dataaccess import DataAccessLayer
|
||||
from dynamicserialize.dstypes.com.raytheon.uf.common.time import DataTime
|
||||
from dynamicserialize.dstypes.com.raytheon.uf.common.time import TimeRange
|
||||
|
||||
def get_parser():
|
||||
parser = argparse.ArgumentParser(conflict_handler="resolve")
|
||||
parser.add_argument("-h", action="store", dest="host",
|
||||
help="EDEX server hostname (optional)", metavar="hostname")
|
||||
parser.add_argument("--date", action="store", dest="date",
|
||||
help="The date in YYYY-MM-DD", metavar="date")
|
||||
parser.add_argument("--hour", action="store", dest="hour",
|
||||
help="The hour in HH", metavar="hour")
|
||||
parser.add_argument("--fcst", action="store", dest="fcst",
|
||||
help="The forecast time in hours", metavar="fcst")
|
||||
parser.add_argument("--srcId", action="store", dest="srcId",
|
||||
help="Unique alphanumeric name for gridded data source",
|
||||
metavar="srcId")
|
||||
parser.add_argument("--varAbrev", action="store", dest="varAbrev",
|
||||
help="Variable abreviation", metavar="varAbrev")
|
||||
parser.add_argument("--lvlOne", action="store", dest="lvlOne",
|
||||
help="Level One value", metavar="lvlOne", type=float)
|
||||
parser.add_argument("--lvlTwo", action="store", dest="lvlTwo",
|
||||
help="Level Two value", metavar="lvlTwo", type=float)
|
||||
parser.add_argument("--lvlName", action="store", dest="lvlName",
|
||||
help="Master level name", metavar="lvlName")
|
||||
return parser
|
||||
|
||||
def do_request(user_args):
|
||||
if user_args.host:
|
||||
DataAccessLayer.changeEDEXHost(user_args.host)
|
||||
|
||||
srcId = user_args.srcId
|
||||
varAbrev = user_args.varAbrev
|
||||
|
||||
if not srcId or not varAbrev:
|
||||
raise Exception("srcId or varAbrev not provided")
|
||||
return
|
||||
|
||||
date = user_args.date
|
||||
hour = user_args.hour
|
||||
fcst = user_args.fcst
|
||||
|
||||
if not date or not hour or not fcst:
|
||||
raise Exception("date, hour, or fcst not provided")
|
||||
return
|
||||
|
||||
dt = datetime.strptime( str(date) + " " + str(hour) + ":00:00.0", "%Y-%m-%d %H:%M:%S.%f")
|
||||
|
||||
# check for and build date range if necessary
|
||||
daterange = None
|
||||
if varAbrev.endswith("hr"):
|
||||
import re
|
||||
matches = re.findall(r'\d+', varAbrev)
|
||||
if matches:
|
||||
from datetime import timedelta
|
||||
hourRange = int(matches[-1])
|
||||
endDate = dt + timedelta(hours=int(fcst))
|
||||
beginDate = endDate - timedelta(hours=hourRange)
|
||||
daterange = TimeRange(beginDate, endDate)
|
||||
|
||||
# convert hours to seconds because DataTime does the reverse
|
||||
time = DataTime(dt, int(fcst)*3600, daterange)
|
||||
|
||||
req = DataAccessLayer.newDataRequest("grid")
|
||||
req.setParameters(varAbrev)
|
||||
req.addIdentifier("info.datasetId", srcId)
|
||||
|
||||
# To handle partial level matches, use identifiers instead of a Level.
|
||||
if user_args.lvlName is not None:
|
||||
req.addIdentifier("info.level.masterLevel.name", user_args.lvlName)
|
||||
if user_args.lvlOne is not None:
|
||||
req.addIdentifier("info.level.levelonevalue", numpy.float64(user_args.lvlOne))
|
||||
if user_args.lvlTwo is not None:
|
||||
req.addIdentifier("info.level.leveltwovalue", numpy.float64(user_args.lvlTwo))
|
||||
|
||||
grids = DataAccessLayer.getGridData(req, [time])
|
||||
|
||||
if not grids:
|
||||
# print "Data not available"
|
||||
raise Exception("")
|
||||
|
||||
grid = grids[0]
|
||||
rawData = grid.getRawData()
|
||||
|
||||
yLen = len(rawData[0])
|
||||
xLen = len(rawData)
|
||||
|
||||
return grid, xLen, yLen
|
||||
|
||||
def get_indices(j, rowLen):
|
||||
# the lengths are reversed from how getRawData() returns the data and forces
|
||||
# the need to calculate the dataIdx and arrIdx instead of
|
||||
# for row in reversed(rawData): for k in row: ...
|
||||
# it's important to check that arrIdx < len(arr) when arrIdx is incremented
|
||||
dataIdx = int(j / rowLen) # index into rawData
|
||||
arrIdx = j % rowLen # index into rawData[dataIdx]
|
||||
return dataIdx, arrIdx
|
||||
|
|
@ -1,139 +1,167 @@
|
|||
# Example to retrieve a single grid point
|
||||
##
|
||||
# This software was developed and / or modified by Raytheon Company,
|
||||
# pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||
#
|
||||
# U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||
# This software product contains export-restricted data whose
|
||||
# export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||
# to non-U.S. persons whether in the United States or abroad requires
|
||||
# an export license or other authorization.
|
||||
#
|
||||
# Contractor Name: Raytheon Company
|
||||
# Contractor Address: 6825 Pine Street, Suite 340
|
||||
# Mail Stop B8
|
||||
# Omaha, NE 68106
|
||||
# 402.291.0100
|
||||
#
|
||||
# See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
# further licensing information.
|
||||
##
|
||||
|
||||
import GridRequest
|
||||
from com.raytheon.uf.common.message.response import ResponseMessageGeneric
|
||||
from com.raytheon.edex.uengine.tasks.decode import FileIn
|
||||
# Gets all available raob data in the A-II database over a specified range of
|
||||
# times. The data is output to stdout as ASCII.
|
||||
#
|
||||
# SOFTWARE HISTORY
|
||||
#
|
||||
# Date Ticket# Engineer Description
|
||||
# ------------ ---------- ----------- --------------------------
|
||||
# 2014-10-14 3598 nabowle Initial modification. Changed to use DataAccessLayer.
|
||||
#
|
||||
|
||||
# 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")
|
||||
import a2rdmdlCommon
|
||||
import argparse
|
||||
import numpy
|
||||
import sys
|
||||
|
||||
result = gr.query.execute()
|
||||
size = result.size()
|
||||
if size == 0:
|
||||
return ResponseMessageGeneric("Data not available")
|
||||
def get_args():
|
||||
parser = a2rdmdlCommon.get_parser()
|
||||
parser.add_argument("--dimLine", action="store_true", dest="dimLine",
|
||||
help="Output dimensions", default=False)
|
||||
return parser.parse_args()
|
||||
|
||||
# For the purposes of this script, take the first response
|
||||
currentQuery = result.get(0)
|
||||
def main():
|
||||
user_args = get_args()
|
||||
|
||||
# Get the data in memory
|
||||
fileIn = FileIn("grid", currentQuery)
|
||||
data = fileIn.execute()
|
||||
try:
|
||||
grid, xLen, yLen = a2rdmdlCommon.do_request(user_args)
|
||||
except Exception as e:
|
||||
print >> sys.stderr, str(e)
|
||||
return
|
||||
|
||||
rawData = grid.getRawData()
|
||||
|
||||
if data:
|
||||
msg = ""
|
||||
if user_args.dimLine:
|
||||
msg += str(xLen) + " " + str(yLen) + "\n"
|
||||
|
||||
# Pull out float[] and get sizes
|
||||
rawData = data.getFloatData()
|
||||
xLen = data.getSizes()[0]
|
||||
yLen = data.getSizes()[1]
|
||||
dimStr = str(xLen) + " " + str(yLen) + "\n"
|
||||
nxy = yLen*xLen
|
||||
j = nxy-xLen
|
||||
while j>=0 :
|
||||
dataIdx, arrIdx = a2rdmdlCommon.get_indices(j, yLen)
|
||||
arr = rawData[dataIdx]
|
||||
i = 0
|
||||
while i<xLen:
|
||||
if arrIdx >= yLen:
|
||||
arrIdx = 0
|
||||
dataIdx += 1
|
||||
arr = rawData[dataIdx]
|
||||
|
||||
# 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) :
|
||||
k = arr[arrIdx]
|
||||
if numpy.isnan(k) :
|
||||
k = 0
|
||||
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 + " "
|
||||
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")
|
||||
i += 1
|
||||
arrIdx += 1
|
||||
|
||||
msg += "\n"
|
||||
j -= xLen
|
||||
|
||||
print msg.strip() + " "
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -1,64 +1,91 @@
|
|||
# Example to retrieve a single grid point
|
||||
##
|
||||
# This software was developed and / or modified by Raytheon Company,
|
||||
# pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||
#
|
||||
# U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||
# This software product contains export-restricted data whose
|
||||
# export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||
# to non-U.S. persons whether in the United States or abroad requires
|
||||
# an export license or other authorization.
|
||||
#
|
||||
# Contractor Name: Raytheon Company
|
||||
# Contractor Address: 6825 Pine Street, Suite 340
|
||||
# Mail Stop B8
|
||||
# Omaha, NE 68106
|
||||
# 402.291.0100
|
||||
#
|
||||
# See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
# further licensing information.
|
||||
##
|
||||
|
||||
# Gets all available raob data in the A-II database over a specified range of
|
||||
# times. The data is output to stdout as ASCII.
|
||||
#
|
||||
# SOFTWARE HISTORY
|
||||
#
|
||||
# Date Ticket# Engineer Description
|
||||
# ------------ ---------- ----------- --------------------------
|
||||
# 2014-10-15 3598 nabowle Initial modification. Changed to use DataAccessLayer.
|
||||
#
|
||||
|
||||
import a2rdmdlCommon
|
||||
import argparse
|
||||
import numpy
|
||||
import xdrlib
|
||||
import bz2
|
||||
import GridRequest
|
||||
from com.raytheon.uf.common.message.response import ResponseMessageGeneric
|
||||
from com.raytheon.edex.uengine.tasks.decode import FileIn
|
||||
import sys
|
||||
|
||||
# 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")
|
||||
def get_args():
|
||||
return a2rdmdlCommon.get_parser().parse_args()
|
||||
|
||||
result = gr.query.execute()
|
||||
size = result.size()
|
||||
if size == 0:
|
||||
return ResponseMessageGeneric("Data not available")
|
||||
def main():
|
||||
user_args = get_args()
|
||||
|
||||
# For the purposes of this script, take the first response
|
||||
currentQuery = result.get(0)
|
||||
try:
|
||||
grid, xLen, yLen = a2rdmdlCommon.do_request(user_args)
|
||||
except Exception as e:
|
||||
print >> sys.stderr, str(e)
|
||||
return
|
||||
|
||||
# Get the data in memory
|
||||
fileIn = FileIn("grid", currentQuery)
|
||||
data = fileIn.execute()
|
||||
rawData = grid.getRawData()
|
||||
|
||||
if data:
|
||||
msg = str(xLen) + " " + str(yLen) + "\n"
|
||||
|
||||
# Pull out float[] and get sizes
|
||||
rawData = data.getFloatData()
|
||||
xLen = data.getSizes()[0]
|
||||
yLen = data.getSizes()[1]
|
||||
dimStr = str(xLen) + " " + str(yLen) + "\n"
|
||||
nxy = yLen*xLen
|
||||
j = nxy-xLen
|
||||
mypacker = xdrlib.Packer()
|
||||
mypacker.reset()
|
||||
while j>=0 :
|
||||
dataIdx, arrIdx = a2rdmdlCommon.get_indices(j, yLen)
|
||||
arr = rawData[dataIdx]
|
||||
i = 0
|
||||
while i<xLen:
|
||||
if arrIdx >= yLen:
|
||||
arrIdx = 0
|
||||
dataIdx += 1
|
||||
arr = rawData[dataIdx]
|
||||
|
||||
# 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 :
|
||||
k = arr[arrIdx]
|
||||
if numpy.isnan(k) :
|
||||
k = 0
|
||||
|
||||
mypacker.pack_float(float(k))
|
||||
i += 1
|
||||
arrIdx += 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)
|
||||
msg += "\t\n"
|
||||
|
||||
return ResponseMessageGeneric("Data not available")
|
||||
print msg.strip() + "\t"
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
Loading…
Add table
Reference in a new issue