python-awips/data/grid/a2rdmdlXdr.py

92 lines
2.4 KiB
Python
Raw Normal View History

2015-06-18 10:45:58 -06:00
##
# 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 sys
def get_args():
return a2rdmdlCommon.get_parser().parse_args()
def main():
user_args = get_args()
try:
grid, xLen, yLen = a2rdmdlCommon.do_request(user_args)
except Exception as e:
print >> sys.stderr, str(e)
return
rawData = grid.getRawData()
msg = 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]
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"
print msg.strip() + "\t"
if __name__ == '__main__':
main()