mirror of
https://github.com/Unidata/python-awips.git
synced 2025-02-23 22:57:56 -05:00
further code cleanup, remove semicolons, isinstance() rather than type(), logical tidiness
This commit is contained in:
parent
d0f18561ea
commit
0b9a06851f
13 changed files with 45 additions and 52 deletions
|
@ -98,9 +98,6 @@ Examples
|
||||||
.. image:: https://python-awips.readthedocs.io/en/latest/_images/AWIPS_Grids_and_Cartopy_3_0.png
|
.. image:: https://python-awips.readthedocs.io/en/latest/_images/AWIPS_Grids_and_Cartopy_3_0.png
|
||||||
:target: https://python-awips.readthedocs.io/en/latest/examples/generated/Grid_Levels_and_Parameters.html
|
:target: https://python-awips.readthedocs.io/en/latest/examples/generated/Grid_Levels_and_Parameters.html
|
||||||
:height: 192px
|
:height: 192px
|
||||||
.. image:: https://python-awips.readthedocs.io/en/latest/_images/NEXRAD_Level_3_Plot_with_Matplotlib_3_0.png
|
|
||||||
:target: https://python-awips.readthedocs.io/en/latest/examples/generated/NEXRAD_Level_3_Plot_with_Matplotlib.html
|
|
||||||
:height: 192px
|
|
||||||
.. image:: https://python-awips.readthedocs.io/en/latest/_images/Upper_Air_BUFR_Soundings_1_0.png
|
.. image:: https://python-awips.readthedocs.io/en/latest/_images/Upper_Air_BUFR_Soundings_1_0.png
|
||||||
:target: https://python-awips.readthedocs.io/en/latest/examples/generated/Upper_Air_BUFR_Soundings.html
|
:target: https://python-awips.readthedocs.io/en/latest/examples/generated/Upper_Air_BUFR_Soundings.html
|
||||||
:height: 192px
|
:height: 192px
|
||||||
|
|
|
@ -29,7 +29,7 @@ class QpidSubscriber:
|
||||||
def __init__(self, host='127.0.0.1', port=5672, decompress=False, ssl=None):
|
def __init__(self, host='127.0.0.1', port=5672, decompress=False, ssl=None):
|
||||||
self.host = host
|
self.host = host
|
||||||
self.port = port
|
self.port = port
|
||||||
self.decompress = decompress;
|
self.decompress = decompress
|
||||||
socket = qpid.util.connect(host, port)
|
socket = qpid.util.connect(host, port)
|
||||||
if "QPID_SSL_CERT_DB" in os.environ:
|
if "QPID_SSL_CERT_DB" in os.environ:
|
||||||
certdb = os.environ["QPID_SSL_CERT_DB"]
|
certdb = os.environ["QPID_SSL_CERT_DB"]
|
||||||
|
|
|
@ -32,7 +32,7 @@ class CombinedTimeQueryTestCase(unittest.TestCase):
|
||||||
req.setLocationNames('RUC130')
|
req.setLocationNames('RUC130')
|
||||||
req.setParameters('T','GH')
|
req.setParameters('T','GH')
|
||||||
req.setLevels('300MB', '500MB','700MB')
|
req.setLevels('300MB', '500MB','700MB')
|
||||||
times = CTQ.getAvailableTimes(req);
|
times = CTQ.getAvailableTimes(req)
|
||||||
self.assertNotEqual(len(times), 0)
|
self.assertNotEqual(len(times), 0)
|
||||||
|
|
||||||
def testNonIntersectingQuery(self):
|
def testNonIntersectingQuery(self):
|
||||||
|
@ -43,5 +43,5 @@ class CombinedTimeQueryTestCase(unittest.TestCase):
|
||||||
req.setLocationNames('RUC130')
|
req.setLocationNames('RUC130')
|
||||||
req.setParameters('T','GH', 'LgSP1hr')
|
req.setParameters('T','GH', 'LgSP1hr')
|
||||||
req.setLevels('300MB', '500MB','700MB','0.0SFC')
|
req.setLevels('300MB', '500MB','700MB','0.0SFC')
|
||||||
times = CTQ.getAvailableTimes(req);
|
times = CTQ.getAvailableTimes(req)
|
||||||
self.assertEqual(len(times), 0)
|
self.assertEqual(len(times), 0)
|
||||||
|
|
|
@ -21,12 +21,12 @@
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
from thrift.Thrift import TType
|
|
||||||
import inspect
|
import inspect
|
||||||
import sys
|
import sys
|
||||||
import types
|
import types
|
||||||
import six
|
import six
|
||||||
import numpy
|
import numpy
|
||||||
|
from thrift.Thrift import TType
|
||||||
import dynamicserialize
|
import dynamicserialize
|
||||||
from dynamicserialize import dstypes, adapters
|
from dynamicserialize import dstypes, adapters
|
||||||
from dynamicserialize import SelfDescribingBinaryProtocol
|
from dynamicserialize import SelfDescribingBinaryProtocol
|
||||||
|
@ -177,7 +177,8 @@ class ThriftSerializationContext(object):
|
||||||
# special
|
# special
|
||||||
fieldName, fieldType, fieldId = self.protocol.readFieldBegin()
|
fieldName, fieldType, fieldId = self.protocol.readFieldBegin()
|
||||||
if fieldName.decode('utf8') != '__enumValue__':
|
if fieldName.decode('utf8') != '__enumValue__':
|
||||||
raise dynamicserialize.SerializationException("Expected to find enum payload. Found: " + fieldName)
|
raise dynamicserialize.SerializationException(
|
||||||
|
"Expected to find enum payload. Found: " + fieldName)
|
||||||
obj = self.protocol.readString()
|
obj = self.protocol.readString()
|
||||||
self.protocol.readFieldEnd()
|
self.protocol.readFieldEnd()
|
||||||
return obj
|
return obj
|
||||||
|
@ -185,7 +186,7 @@ class ThriftSerializationContext(object):
|
||||||
clz = dsObjTypes[name]
|
clz = dsObjTypes[name]
|
||||||
obj = clz()
|
obj = clz()
|
||||||
|
|
||||||
while self._deserializeField(name, obj):
|
while self._deserializeField(obj):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
self.protocol.readStructEnd()
|
self.protocol.readStructEnd()
|
||||||
|
@ -198,7 +199,7 @@ class ThriftSerializationContext(object):
|
||||||
raise dynamicserialize.SerializationException(
|
raise dynamicserialize.SerializationException(
|
||||||
"Unsupported type value " + str(b))
|
"Unsupported type value " + str(b))
|
||||||
|
|
||||||
def _deserializeField(self, structname, obj):
|
def _deserializeField(self, obj):
|
||||||
fieldName, fieldType, fieldId = self.protocol.readFieldBegin()
|
fieldName, fieldType, fieldId = self.protocol.readFieldBegin()
|
||||||
if fieldType == TType.STOP:
|
if fieldType == TType.STOP:
|
||||||
return False
|
return False
|
||||||
|
@ -254,12 +255,8 @@ class ThriftSerializationContext(object):
|
||||||
if pyt in pythonToThriftMap:
|
if pyt in pythonToThriftMap:
|
||||||
return pythonToThriftMap[pyt]
|
return pythonToThriftMap[pyt]
|
||||||
elif pyt.__module__[:DS_LEN - 1] == ('dynamicserialize.dstypes'):
|
elif pyt.__module__[:DS_LEN - 1] == ('dynamicserialize.dstypes'):
|
||||||
if six.PY2:
|
return pythonToThriftMap[object]
|
||||||
return pythonToThriftMap[types.InstanceType]
|
raise dynamicserialize.SerializationException(
|
||||||
else:
|
|
||||||
return pythonToThriftMap[object]
|
|
||||||
else:
|
|
||||||
raise dynamicserialize.SerializationException(
|
|
||||||
"Don't know how to serialize object of type: " + str(pyt))
|
"Don't know how to serialize object of type: " + str(pyt))
|
||||||
|
|
||||||
def serializeMessage(self, obj):
|
def serializeMessage(self, obj):
|
||||||
|
@ -316,7 +313,7 @@ class ThriftSerializationContext(object):
|
||||||
def _serializeArray(self, obj):
|
def _serializeArray(self, obj):
|
||||||
size = len(obj)
|
size = len(obj)
|
||||||
if size:
|
if size:
|
||||||
if type(obj) is numpy.ndarray:
|
if isinstance(obj, numpy.ndarray):
|
||||||
t = pythonToThriftMap[obj.dtype.type]
|
t = pythonToThriftMap[obj.dtype.type]
|
||||||
size = obj.size
|
size = obj.size
|
||||||
else:
|
else:
|
||||||
|
@ -325,7 +322,7 @@ class ThriftSerializationContext(object):
|
||||||
t = TType.STRUCT
|
t = TType.STRUCT
|
||||||
self.protocol.writeListBegin(t, size)
|
self.protocol.writeListBegin(t, size)
|
||||||
if t == TType.STRING:
|
if t == TType.STRING:
|
||||||
if type(obj) is numpy.ndarray:
|
if isinstance(obj, numpy.ndarray):
|
||||||
if len(obj.shape) == 1:
|
if len(obj.shape) == 1:
|
||||||
for x in obj:
|
for x in obj:
|
||||||
s = str(x).strip()
|
s = str(x).strip()
|
||||||
|
|
|
@ -20,7 +20,7 @@ ClassAdapter = [
|
||||||
def serialize(context, level):
|
def serialize(context, level):
|
||||||
context.writeString(level.getText())
|
context.writeString(level.getText())
|
||||||
context.writeI32(level.getOrder())
|
context.writeI32(level.getOrder())
|
||||||
context.writeBool(level.isSystemLevel());
|
context.writeBool(level.isSystemLevel())
|
||||||
|
|
||||||
|
|
||||||
def deserialize(context):
|
def deserialize(context):
|
||||||
|
|
|
@ -15,9 +15,9 @@ ClassAdapter = 'com.raytheon.uf.common.dataplugin.gfe.db.objects.TimeConstraints
|
||||||
|
|
||||||
|
|
||||||
def serialize(context, timeConstraints):
|
def serialize(context, timeConstraints):
|
||||||
context.writeI32(timeConstraints.getDuration());
|
context.writeI32(timeConstraints.getDuration())
|
||||||
context.writeI32(timeConstraints.getRepeatInterval());
|
context.writeI32(timeConstraints.getRepeatInterval())
|
||||||
context.writeI32(timeConstraints.getStartTime());
|
context.writeI32(timeConstraints.getStartTime())
|
||||||
|
|
||||||
|
|
||||||
def deserialize(context):
|
def deserialize(context):
|
||||||
|
|
|
@ -40,9 +40,9 @@ class DefaultDataRequest(IDataRequest):
|
||||||
self.levels = list(map(self.__makeLevel, levels))
|
self.levels = list(map(self.__makeLevel, levels))
|
||||||
|
|
||||||
def __makeLevel(self, level):
|
def __makeLevel(self, level):
|
||||||
if type(level) is Level:
|
if isinstance(level, Level):
|
||||||
return level
|
return level
|
||||||
elif type(level) is str:
|
elif isinstance(level, str):
|
||||||
return Level(level)
|
return Level(level)
|
||||||
else:
|
else:
|
||||||
raise TypeError("Invalid object type specified for level.")
|
raise TypeError("Invalid object type specified for level.")
|
||||||
|
|
|
@ -35,4 +35,4 @@ class GetGridDataRequest(AbstractDataAccessRequest):
|
||||||
return self.includeLatLonData
|
return self.includeLatLonData
|
||||||
|
|
||||||
def setIncludeLatLonData(self, includeLatLonData):
|
def setIncludeLatLonData(self, includeLatLonData):
|
||||||
self.includeLatLonData = includeLatLonData;
|
self.includeLatLonData = includeLatLonData
|
||||||
|
|
|
@ -14,7 +14,7 @@ class DatabaseID(object):
|
||||||
self.modelId = None
|
self.modelId = None
|
||||||
self.shortModelId = None
|
self.shortModelId = None
|
||||||
if dbIdentifier is not None:
|
if dbIdentifier is not None:
|
||||||
if (self.__decodeIdentifier(dbIdentifier)):
|
if self.__decodeIdentifier(dbIdentifier):
|
||||||
self.__encodeIdentifier()
|
self.__encodeIdentifier()
|
||||||
else:
|
else:
|
||||||
self.format = "NONE"
|
self.format = "NONE"
|
||||||
|
@ -25,8 +25,8 @@ class DatabaseID(object):
|
||||||
self.modelId = ""
|
self.modelId = ""
|
||||||
self.shortModelId = ""
|
self.shortModelId = ""
|
||||||
|
|
||||||
def isValid(self) :
|
def isValid(self):
|
||||||
return self.format != "NONE";
|
return self.format != "NONE"
|
||||||
|
|
||||||
def getSiteId(self):
|
def getSiteId(self):
|
||||||
return self.siteId
|
return self.siteId
|
||||||
|
@ -37,8 +37,8 @@ class DatabaseID(object):
|
||||||
def getFormat(self):
|
def getFormat(self):
|
||||||
return self.format
|
return self.format
|
||||||
|
|
||||||
def setFormat(self, format):
|
def setFormat(self, dbformat):
|
||||||
self.format = format
|
self.format = dbformat
|
||||||
|
|
||||||
def getDbType(self):
|
def getDbType(self):
|
||||||
return self.dbType
|
return self.dbType
|
||||||
|
@ -81,7 +81,7 @@ class DatabaseID(object):
|
||||||
self.shortModelId += "_" + self.dbType
|
self.shortModelId += "_" + self.dbType
|
||||||
|
|
||||||
if self.modelTime != "00000000_0000":
|
if self.modelTime != "00000000_0000":
|
||||||
self.modelId += "_" + self.modelTime;
|
self.modelId += "_" + self.modelTime
|
||||||
self.shortModelId += "_" + self.modelTime[6:8] + self.modelTime[9:11]
|
self.shortModelId += "_" + self.modelTime[6:8] + self.modelTime[9:11]
|
||||||
else:
|
else:
|
||||||
self.modelId += "_" + "00000000_0000"
|
self.modelId += "_" + "00000000_0000"
|
||||||
|
@ -96,7 +96,7 @@ class DatabaseID(object):
|
||||||
self.modelTime = "00000000_0000"
|
self.modelTime = "00000000_0000"
|
||||||
|
|
||||||
# parse into '_' separated strings
|
# parse into '_' separated strings
|
||||||
strings = dbIdentifier.split("_");
|
strings = dbIdentifier.split("_")
|
||||||
if len(strings) != 6:
|
if len(strings) != 6:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ class DatabaseID(object):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# make sure the digits are there
|
# make sure the digits are there
|
||||||
dtg = strings[4] + '_' + strings[5]; # back together
|
dtg = strings[4] + '_' + strings[5] # back together
|
||||||
if dtg != "00000000_0000":
|
if dtg != "00000000_0000":
|
||||||
if not self.__decodeDtg(dtg):
|
if not self.__decodeDtg(dtg):
|
||||||
return False
|
return False
|
||||||
|
@ -152,14 +152,14 @@ class DatabaseID(object):
|
||||||
return self.modelId
|
return self.modelId
|
||||||
|
|
||||||
def __hash__(self):
|
def __hash__(self):
|
||||||
prime = 31;
|
prime = 31
|
||||||
result = 1;
|
result = 1
|
||||||
result = prime * result + (0 if self.dbType is None else hash(self.dbType))
|
result = prime * result + (0 if self.dbType is None else hash(self.dbType))
|
||||||
result = prime * result + (0 if self.format is None else hash(self.format))
|
result = prime * result + (0 if self.format is None else hash(self.format))
|
||||||
result = prime * result + (0 if self.modelId is None else hash(self.modelId))
|
result = prime * result + (0 if self.modelId is None else hash(self.modelId))
|
||||||
result = prime * result + (0 if self.modelTime is None else hash(self.modelTime))
|
result = prime * result + (0 if self.modelTime is None else hash(self.modelTime))
|
||||||
result = prime * result + (0 if self.siteId is None else hash(self.siteId))
|
result = prime * result + (0 if self.siteId is None else hash(self.siteId))
|
||||||
return result;
|
return result
|
||||||
|
|
||||||
def __cmp__(self, other):
|
def __cmp__(self, other):
|
||||||
if not isinstance(other, DatabaseID):
|
if not isinstance(other, DatabaseID):
|
||||||
|
|
|
@ -21,7 +21,7 @@ class GridLocation(object):
|
||||||
s = "[SiteID =" + self.siteId + ",ProjID=" + self.projection.getProjectionID() +\
|
s = "[SiteID =" + self.siteId + ",ProjID=" + self.projection.getProjectionID() +\
|
||||||
",gridSize=(" + str(self.nx) + ',' + str(self.ny) + ")"
|
",gridSize=(" + str(self.nx) + ',' + str(self.ny) + ")"
|
||||||
# TODO: Handle geometry in dynamicserialize
|
# TODO: Handle geometry in dynamicserialize
|
||||||
# ,loc=" + this.geometry.getGeometryType();
|
# ,loc=" + this.geometry.getGeometryType()
|
||||||
s += ']'
|
s += ']'
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,7 @@ class GridParmInfo(object):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def __ne__(self, other):
|
def __ne__(self, other):
|
||||||
return (not self.__eq__(other))
|
return not self.__eq__(other)
|
||||||
|
|
||||||
def __validCheck(self):
|
def __validCheck(self):
|
||||||
status = []
|
status = []
|
||||||
|
@ -90,14 +90,14 @@ class GridParmInfo(object):
|
||||||
status.append("GridParmInfo is invalid. There are time constraints" +
|
status.append("GridParmInfo is invalid. There are time constraints" +
|
||||||
" for a time independent parm. Constraints: " +
|
" for a time independent parm. Constraints: " +
|
||||||
str(self.timeConstraints))
|
str(self.timeConstraints))
|
||||||
if len(self.unitString) == 0:
|
if not self.unitString:
|
||||||
status.append("GridParmInfo.Units are not defined.")
|
status.append("GridParmInfo.Units are not defined.")
|
||||||
if self.precision < -2 or self.precision > 5:
|
if self.precision < -2 or self.precision > 5:
|
||||||
status.append("GridParmInfo is invalid. Precision out of limits." +
|
status.append("GridParmInfo is invalid. Precision out of limits." +
|
||||||
" Precision is: " + str(self.precision) + ". Must be between -2 and 5.")
|
" Precision is: " + str(self.precision) + ". Must be between -2 and 5.")
|
||||||
|
|
||||||
retVal = True
|
retVal = True
|
||||||
if len(status) > 0:
|
if status:
|
||||||
retVal = False
|
retVal = False
|
||||||
return (retVal, status)
|
return (retVal, status)
|
||||||
|
|
||||||
|
@ -183,4 +183,3 @@ class GridParmInfo(object):
|
||||||
|
|
||||||
def setTimeIndependentParm(self, timeIndependentParm):
|
def setTimeIndependentParm(self, timeIndependentParm):
|
||||||
self.timeIndependentParm = timeIndependentParm
|
self.timeIndependentParm = timeIndependentParm
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,8 @@
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
HOUR = 3600;
|
HOUR = 3600
|
||||||
DAY = 24 * HOUR;
|
DAY = 24 * HOUR
|
||||||
|
|
||||||
|
|
||||||
class TimeConstraints(object):
|
class TimeConstraints(object):
|
||||||
|
@ -15,18 +15,18 @@ class TimeConstraints(object):
|
||||||
repeatInterval = int(repeatInterval)
|
repeatInterval = int(repeatInterval)
|
||||||
startTime = int(startTime)
|
startTime = int(startTime)
|
||||||
|
|
||||||
self.valid = False;
|
self.valid = False
|
||||||
if duration == 0 and repeatInterval == 0 and startTime == 0:
|
if duration == 0 and repeatInterval == 0 and startTime == 0:
|
||||||
self.valid = True;
|
self.valid = True
|
||||||
else:
|
else:
|
||||||
if self.isInvalidInterval(repeatInterval, duration, startTime):
|
if self.isInvalidInterval(repeatInterval, duration, startTime):
|
||||||
logging.warning("Bad init values for TimeConstraints: ", self);
|
logging.warning("Bad init values for TimeConstraints: ", self)
|
||||||
self.valid = False;
|
self.valid = False
|
||||||
duration = 0;
|
duration = 0
|
||||||
repeatInterval = 0;
|
repeatInterval = 0
|
||||||
startTime = 0;
|
startTime = 0
|
||||||
else:
|
else:
|
||||||
self.valid = True;
|
self.valid = True
|
||||||
|
|
||||||
self.duration = duration
|
self.duration = duration
|
||||||
self.repeatInterval = repeatInterval
|
self.repeatInterval = repeatInterval
|
||||||
|
|
|
@ -6,7 +6,7 @@ class WeatherKey(object):
|
||||||
|
|
||||||
def __init__(self, siteId="", subKeys=[]):
|
def __init__(self, siteId="", subKeys=[]):
|
||||||
self.siteId = siteId
|
self.siteId = siteId
|
||||||
if type(subKeys) is str:
|
if isinstance(subKeys, str):
|
||||||
self.__parseString(str(subKeys))
|
self.__parseString(str(subKeys))
|
||||||
else:
|
else:
|
||||||
self.subKeys = subKeys
|
self.subKeys = subKeys
|
||||||
|
|
Loading…
Add table
Reference in a new issue