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