awips2/edexOsgi/com.raytheon.uf.common.aviation/utility/common_static/base/aviation/python/LLWSData.py
2022-05-05 12:34:50 -05:00

143 lines
4.8 KiB
Python

##
# 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.
##
#
# Name:
# LLWSData.py
# GFS1-NHD:A8108.0000-SCRIPT;1.3
#
# Status:
# DELIVERED
#
# History:
# Revision 1.3 (DELIVERED)
# Created: 09-OCT-2009 21:21:16 OBERFIEL
# Downgraded log message severity to DEBUG when TAF LLWS file
# is not found.
#
# Revision 1.2 (DELIVERED)
# Created: 07-MAY-2005 11:34:31 OBERFIEL
# Added Item Header Block
#
# Revision 1.1 (DELIVERED)
# Created: 02-NOV-2004 16:35:54 OBERFIEL
# date and time created 11/02/04 16:35:42 by oberfiel
#
# Change Document History:
# 1:
# Change Document: GFS1-NHD_SPR_7430
# Action Date: 21-OCT-2009 08:03:43
# Relationship Type: In Response to
# Status: CLOSED
# Title: AvnFPS: Incorrect file permission on ISH files
#
#
#
# SOFTWARE HISTORY
# Date Ticket# Engineer Description
# ------------ ---------- ----------- --------------------------
# Initial creation.
# Mar 25, 2013 1735 rferrel Retrieve only the last 24 hours of acars records.
# Feb 21, 2018 5697 mapeters Fix errors from removing profiler plugins
# Sep 07, 2018 7445 tgurney Change missing data message to debug level
##
##
# This is a base file that is not intended to be overridden.
##
from com.raytheon.viz.aviation.monitor import LlwsManager
import logging, os, time
import LLWSThread, Avn
import NoDataException
_Logger = logging.getLogger(Avn.CATEGORY)
#################################################################################
def readLLWS(ident):
d = {}
try:
fpath = os.path.join('data', 'llws', ident)
with open(fpath) as f:
for line in f:
if not line.strip():
break
radarid, rpttime, value, wsstring = line.split()
d[radarid] = {'time': float(rpttime),
'value': float(value),
'str': wsstring
}
return d
except IOError:
_Logger.debug('Cannot access LLWS file for %s', ident)
except (IndexError, ValueError):
_Logger.error('Cannot parse LLWS file for %s', ident)
return {}
def writeLLWS(ident, data):
try:
fpath = os.path.join('data', 'llws', ident)
with open (fpath, 'w') as f:
for radarid in data:
llws = data[radarid]
f.write('%s %.0f %.3f %s\n' % (radarid, llws['time'], llws['value'], llws['str']))
except IOError:
_Logger.error('Cannot write LLWS file for %s', ident)
def retrieve(siteID, info):
from datetime import timedelta
day = timedelta(days=1)
secondsPerDay = day.total_seconds()
msPerSecond = 1000.0
th = LLWSThread.Server(info)
d = {}
try:
th.processMetarData(siteID)
except NoDataException.NoDataException:
raise NoDataException.NoDataException("No METAR data available for site %s" % siteID)
# This gets all acarsRec in the database since 0 retrieves from the epoch.
# This may be ok if database is purged frequently.
# How far back should it go 1, 6, 12, 24 hours?
# acarsRec = LlwsManager.getAcarsRecord(siteID, 0)
refTime = int((time.time() - secondsPerDay) * msPerSecond)
acarsRec = LlwsManager.getAcarsRecord(siteID, refTime)
if acarsRec:
acarsId = siteID[1:]
th.processAcarsData(acarsId,acarsRec)
try:
shear = th.genShear(siteID, acarsId)
d[acarsId] = shear
except LLWSThread.InValid:
pass
else:
_Logger.debug('Missing ACARS Sounding data for %s.', siteID)
radars = info['sites']['radars']
for radar in radars:
vwp = LlwsManager.getVerticalWindProfile(radar, 0)
if vwp.size() == 0:
return None
th.processRadarData(radar, vwp)
try:
shear = th.genShear(siteID, radar)
d[radar] = shear
except LLWSThread.InValid:
pass
return d