Beispiel #1
0
 def testFilterOnInvalidLocationThrowsIncompatibleRequestException(self):
     req = DAL.newDataRequest()
     req.setDatatype(self.datatype)
     req.setParameters('id')
     req.setLocationNames(') and 0=1')
     with self.assertRaises(Exception) as cm:
         DAL.getGeometryData(req)
     self.assertIn('IncompatibleRequestException', str(cm.exception))
Beispiel #2
0
 def testFilterOnInvalidLocationThrowsIncompatibleRequestException(self):
     req = DAL.newDataRequest()
     req.setDatatype(self.datatype)
     req.setParameters('id')
     req.setLocationNames(') and 0=1')
     with self.assertRaises(Exception) as cm:
         DAL.getGeometryData(req)
     self.assertIn('IncompatibleRequestException', str(cm.exception))
Beispiel #3
0
    def testGetGeometryData(self):
        req = DAL.newDataRequest(self.datatype)
        req.setLocationNames(self.location)
        req.addIdentifier("reportType", "2020")
        req.setParameters("sfcPressure", "staName", "rptType", "tdMan")

        print("Testing getGeometryData()")

        geomData = DAL.getGeometryData(req)
        self.assertIsNotNone(geomData)
        print("Number of geometry records: " + str(len(geomData)))
        print("Sample geometry data:")
        for record in geomData[:self.sampleDataLimit]:
            print("level=", record.getLevel(), end="")
            # One dimensional parameters are reported on the 0.0UNKNOWN level.
            # 2D parameters are reported on MB levels from pressure.
            if record.getLevel() == "0.0UNKNOWN":
                print(" sfcPressure=" + record.getString("sfcPressure") + record.getUnit("sfcPressure"), end="")
                print(" staName=" + record.getString("staName"), end="")
                print(" rptType=" + record.getString("rptType") + record.getUnit("rptType"), end="")
            else:
                print(" tdMan=" + str(record.getNumber("tdMan")) + record.getUnit("tdMan"), end="")
            print(" geometry=", record.getGeometry())

        print("getGeometryData() complete\n\n")
Beispiel #4
0
    def testGetGeometryData(self):
        req = DAL.newDataRequest(self.datatype)
        req.setLocationNames(self.location)
        req.addIdentifier("reportType", "2020")
        req.setParameters("sfcPressure", "staName", "rptType", "tdMan")

        print("Testing getGeometryData()")

        geomData = DAL.getGeometryData(req)
        self.assertIsNotNone(geomData)
        print("Number of geometry records: " + str(len(geomData)))
        print("Sample geometry data:")
        for record in geomData[:self.sampleDataLimit]:
            print("level=", record.getLevel(), end="")
            # One dimensional parameters are reported on the 0.0UNKNOWN level.
            # 2D parameters are reported on MB levels from pressure.
            if record.getLevel() == "0.0UNKNOWN":
                print(" sfcPressure=" + record.getString("sfcPressure") +
                      record.getUnit("sfcPressure"),
                      end="")
                print(" staName=" + record.getString("staName"), end="")
                print(" rptType=" + record.getString("rptType") +
                      record.getUnit("rptType"),
                      end="")
            else:
                print(" tdMan=" + str(record.getNumber("tdMan")) +
                      record.getUnit("tdMan"),
                      end="")
            print(" geometry=", record.getGeometry())

        print("getGeometryData() complete\n\n")
Beispiel #5
0
    def testGetGeometryData(self):
        req = DAL.newDataRequest(self.datatype)
        req.setParameters("temperature", "pressure", "uComponent",
                          "vComponent")

        print("Testing getGeometryData()")

        geomData = DAL.getGeometryData(req)
        self.assertIsNotNone(geomData)
        print("Number of geometry records: " + str(len(geomData)))
        print("Sample geometry data:")
        for record in geomData[:self.sampleDataLimit]:
            print("level:", record.getLevel(), end="")
            # One dimensional parameters are reported on the 0.0UNKNOWN level.
            # 2D parameters are reported on MB levels from pressure.
            if record.getLevel() == "0.0UNKNOWN":
                print(" temperature=" + record.getString("temperature") +
                      record.getUnit("temperature"),
                      end="")
                print(" pressure=" + record.getString("pressure") +
                      record.getUnit("pressure"),
                      end="")
            else:
                print(" uComponent=" + record.getString("uComponent") +
                      record.getUnit("uComponent"),
                      end="")
                print(" vComponent=" + record.getString("vComponent") +
                      record.getUnit("vComponent"),
                      end="")
            print(" geometry:", record.getGeometry())

        print("getGeometryData() complete\n\n")
 def testGetGeometryData(self):
     req = DAL.newDataRequest(self.datatype)
     req.addIdentifier("reportType", self.reporttype)
     req.setLocationNames(params.OBS_STATION)
     req.setParameters("temperature", "pressure", "specHum", "sfcPress", "temp2", "q2")
     print("Testing getGeometryData()")
     geomData = DAL.getGeometryData(req)
     print("Number of geometry records: " + str(len(geomData)))
     print("Sample geometry data:")
     for record in geomData[:self.sampleDataLimit]:
         print("level=" + record.getLevel(), end="")
         # One dimensional parameters are reported on the 0.0UNKNOWN level.
         # 2D parameters are reported on MB levels from pressure.
         if record.getLevel() == "0.0UNKNOWN":
             print(" sfcPress=" + record.getString("sfcPress") +
                   record.getUnit("sfcPress"), end="")
             print(" temp2=" + record.getString("temp2") +
                   record.getUnit("temp2"), end="")
             print(" q2=" + record.getString("q2") +
                   record.getUnit("q2"), end="")
         else:
             print(" pressure=" + record.getString("pressure") +
                   record.getUnit("pressure"), end="")
             print(" temperature=" + record.getString("temperature") +
                   record.getUnit("temperature"), end="")
             print(" specHum=" + record.getString("specHum") +
                   record.getUnit("specHum"), end="")
         print(" geometry=" + str(record.getGeometry()))
     print("getGeometryData() complete\n\n")
Beispiel #7
0
def getSounding(modelName, weatherElements, levels, samplePoint, timeRange=None):
    """
    Performs a series of Data Access Framework requests to retrieve a sounding object
    based on the specified request parameters.

    Args:
        modelName: the grid model datasetid to use as the basis of the sounding.
        weatherElements: a list of parameters to return in the sounding.
        levels: a list of levels to sample the given weather elements at
        samplePoint: a lat/lon pair to perform the sampling of data at.
        timeRange: (optional) a list of times, or a TimeRange to specify
        which forecast hours to use. If not specified, will default to all forecast hours.

    Returns:
        A _SoundingCube instance, which acts a 3-tiered dictionary, keyed
        by DataTime, then by level and finally by weather element. If no
        data is available for the given request parameters, None is returned.

    """

    (locationNames, parameters, levels, envelope, timeRange) = \
        __sanitizeInputs(modelName, weatherElements, levels, samplePoint, timeRange)

    requestArgs = {'datatype': 'grid', 'locationNames': locationNames,
                   'parameters': parameters, 'levels': levels, 'envelope': envelope}

    req = DataAccessLayer.newDataRequest(**requestArgs)
    response = DataAccessLayer.getGeometryData(req, timeRange)
    soundingObject = _SoundingCube(response)

    return soundingObject
Beispiel #8
0
 def testGetGeometryData(self):
     req = DAL.newDataRequest(self.datatype)
     req.addIdentifier("reportType", "ETA")
     req.setLocationNames(params.OBS_STATION)
     req.setParameters("temperature", "pressure", "specHum", "sfcPress",
                       "temp2", "q2")
     print("Testing getGeometryData()")
     geomData = DAL.getGeometryData(req)
     print("Number of geometry records: " + str(len(geomData)))
     print("Sample geometry data:")
     for record in geomData[:self.sampleDataLimit]:
         print("level=" + record.getLevel(), end="")
         # One dimensional parameters are reported on the 0.0UNKNOWN level.
         # 2D parameters are reported on MB levels from pressure.
         if record.getLevel() == "0.0UNKNOWN":
             print(" sfcPress=" + record.getString("sfcPress") +
                   record.getUnit("sfcPress"),
                   end="")
             print(" temp2=" + record.getString("temp2") +
                   record.getUnit("temp2"),
                   end="")
             print(" q2=" + record.getString("q2") + record.getUnit("q2"),
                   end="")
         else:
             print(" pressure=" + record.getString("pressure") +
                   record.getUnit("pressure"),
                   end="")
             print(" temperature=" + record.getString("temperature") +
                   record.getUnit("temperature"),
                   end="")
             print(" specHum=" + record.getString("specHum") +
                   record.getUnit("specHum"),
                   end="")
         print(" geometry=" + str(record.getGeometry()))
     print("getGeometryData() complete\n\n")
Beispiel #9
0
 def testGetGeometryDataWithEnvelope(self):
     req = DAL.newDataRequest(self.datatype)
     req.setParameters("temperature", "windSpeed", "hazardType", "turbType")
     req.setEnvelope(params.ENVELOPE)
     print("Testing getGeometryData()")
     data = DAL.getGeometryData(req)
     for item in data:
         self.assertTrue(params.ENVELOPE.contains(item.getGeometry()))
Beispiel #10
0
def main():
    user_args = get_args()

    if user_args.host:
        DataAccessLayer.changeEDEXHost(user_args.host)

    start = user_args.start
    end = user_args.end

    if not start or not end:
        print >> sys.stderr, "Start or End date not provided"
        return

    beginRange = datetime.strptime(start + ":00.0", "%Y-%m-%d %H:%M:%S.%f")
    endRange = datetime.strptime(end + ":59.9", "%Y-%m-%d %H:%M:%S.%f")
    timerange = TimeRange(beginRange, endRange)

    req = DataAccessLayer.newDataRequest("sfcobs")
    req.setParameters("stationId", "timeObs", "elevation", "seaLevelPress",
                      "stationPress", "temperature", "dewpoint", "windDir",
                      "windSpeed", "pressChange3Hour")
    geometries = DataAccessLayer.getGeometryData(req, timerange)

    if not geometries:
        #        print "No data available."
        return

    msg = ""
    for geo in geometries:
        lon = geo.getGeometry().x
        lat = geo.getGeometry().y

        sName = geo.getString("stationId")
        tobs = geo.getNumber("timeObs")
        elev = geo.getNumber("elevation")
        msl = geo.getNumber("seaLevelPress")
        p = geo.getNumber("stationPress")
        temp = geo.getNumber("temperature")
        dpt = geo.getNumber("dewpoint")
        dir = geo.getNumber("windDir")
        spd = geo.getNumber("windSpeed")
        pchg = geo.getNumber("pressChange3Hour")

        msg += sName + ","
        msg += str(tobs / 1000) + ","
        msg += "%.4f" % lat + ","
        msg += "%.4f" % lon + ","
        msg += "%.0f" % elev + ","
        msg += "%.2f" % msl + ","
        msg += "%.2f" % p + ","
        msg += "%.1f" % temp + ","
        msg += "%.1f" % dpt + ","
        msg += "%.0f" % dir + ","
        msg += "%.1f" % spd + ","
        msg += "%.0f" % pchg + "\n"

    print msg.strip()
 def testGetGeometryDataWithEnvelope(self):
     req = DAL.newDataRequest(self.datatype)
     req.addIdentifier("reportType", self.reporttype)
     req.setEnvelope(params.ENVELOPE)
     req.setParameters("temperature", "pressure", "specHum", "sfcPress", "temp2", "q2")
     print("Testing getGeometryData()")
     data = DAL.getGeometryData(req)
     for item in data:
         self.assertTrue(params.ENVELOPE.contains(item.getGeometry()))
Beispiel #12
0
 def testGetGeometryDataWithEnvelope(self):
     req = DAL.newDataRequest(self.datatype)
     req.addIdentifier("reportType", "ETA")
     req.setEnvelope(params.ENVELOPE)
     req.setParameters("temperature", "pressure", "specHum", "sfcPress",
                       "temp2", "q2")
     print("Testing getGeometryData()")
     data = DAL.getGeometryData(req)
     for item in data:
         self.assertTrue(params.ENVELOPE.contains(item.getGeometry()))
Beispiel #13
0
 def testNoDuplicateData(self):
     req = DAL.newDataRequest(self.datatype)
     req.addIdentifier('table', 'public.cli_asos_monthly')
     req.setLocationNames('KOMA')
     req.setParameters('maxtemp_day1')
     rows = DAL.getGeometryData(req, DAL.getAvailableTimes(req)[0:5])
     for i in range(len(rows)):
         for j in range(len(rows)):
             if i != j:
                 self.assertNotEqual(rows[i].__dict__, rows[j].__dict__)
Beispiel #14
0
 def testNoDuplicateData(self):
     req = DAL.newDataRequest(self.datatype)
     req.addIdentifier('table', 'public.cli_asos_monthly')
     req.setLocationNames('KOMA')
     req.setParameters('maxtemp_day1')
     rows = DAL.getGeometryData(req, DAL.getAvailableTimes(req)[0:5])
     for i in range(len(rows)):
         for j in range(len(rows)):
             if i != j:
                 self.assertNotEqual(rows[i].__dict__, rows[j].__dict__)
 def runGeometryDataTestWithTimeRange(self, req, timeRange):
     """
     Test that we are able to successfully retrieve geometry data for the
     given request.
     """
     geomData = DAL.getGeometryData(req, timeRange)
     self.assertIsNotNone(geomData)
     if not geomData:
         raise unittest.SkipTest("No data available")
     print("Number of geometry records: " + str(len(geomData)))
     return geomData
Beispiel #16
0
 def runGeometryDataTestWithTimeRange(self, req, timeRange):
     """
     Test that we are able to successfully retrieve geometry data for the
     given request.
     """
     geomData = DAL.getGeometryData(req, timeRange)
     self.assertIsNotNone(geomData)
     if not geomData:
         raise unittest.SkipTest("No data available")
     print("Number of geometry records: " + str(len(geomData)))
     return geomData
 def runGeometryDataTest(self, req, checkDataTimes=True):
     """
     Test that we are able to successfully retrieve geometry data for the
     given request.
     """
     times = DafTestCase.getTimesIfSupported(req)
     geomData = DAL.getGeometryData(req, times[:self.numTimesToLimit])
     self.assertIsNotNone(geomData)
     if not geomData:
         raise unittest.SkipTest("No data available")
     print("Number of geometry records: " + str(len(geomData)))
     return geomData
Beispiel #18
0
 def runGeometryDataTest(self, req, checkDataTimes=True):
     """
     Test that we are able to successfully retrieve geometry data for the
     given request.
     """
     times = DafTestCase.getTimesIfSupported(req)
     geomData = DAL.getGeometryData(req, times[:self.numTimesToLimit])
     self.assertIsNotNone(geomData)
     if not geomData:
         raise unittest.SkipTest("No data available")
     print("Number of geometry records: " + str(len(geomData)))
     return geomData
Beispiel #19
0
 def testFilterOnLocationName(self):
     allLocationNames = self._getLocationNames()
     if len(allLocationNames) == 0:
         errmsg = "No {0} data exists on {1}. Try again with {0} data."
         raise unittest.SkipTest(errmsg.format(self.datatype, DAL.THRIFT_HOST))
     testCount = 3  # number of different location names to test
     for locationName in allLocationNames[:testCount]:
         req = DAL.newDataRequest()
         req.setDatatype(self.datatype)
         req.setParameters('id')
         req.setLocationNames(locationName)
         geomData = DAL.getGeometryData(req)
         for geom in geomData:
             self.assertEqual(geom.getLocationName(), locationName)
 def testFilterOnLocationName(self):
     allLocationNames = self._getLocationNames()
     if len(allLocationNames) == 0:
         errmsg = "No {0} data exists on {1}. Try again with {0} data."
         raise unittest.SkipTest(
             errmsg.format(self.datatype, DAL.THRIFT_HOST))
     testCount = 3  # number of different location names to test
     for locationName in allLocationNames[:testCount]:
         req = DAL.newDataRequest()
         req.setDatatype(self.datatype)
         req.setParameters('id')
         req.setLocationNames(locationName)
         geomData = DAL.getGeometryData(req)
         for geom in geomData:
             self.assertEqual(geom.getLocationName(), locationName)
Beispiel #21
0
    def findWfoZones(self, wfo):

        #  Construct the SQL to get these attributes from the maps database
        reqParms = {
            'datatype': 'maps',
            'table': 'mapdata.zone',
            'locationField': 'cwa',
            'geomField': 'the_geom',
            'locationNames': [wfo.strip()],
            'parameters': ['state', 'zone'],
        }

        #  Create the Data Access request
        req = DataAccessLayer.newDataRequest(**reqParms)

        #  Process the response
        result = DataAccessLayer.getGeometryData(req)

        #  Check if we got a response
        if not result:
            # TODO need better error message
            # What should be done in this case?
            print "What!??!"

        #  Get ready to track matching zones
        zoneSet = set()

        #  Process the response contents
        for record in result:

            #  Retrieve state and zone
            state = record.getString('state')
            zone = record.getString('zone')

            #             print "*"*(80)
            #             print "state = {}   zone = {}".format(state, zone)

            #  If this is ALY - only keep CT and MA zones
            if wfo == "ALY" and state not in ["MA", "CT"]:
                continue

            #  Construct a UGC code and store it for later
            zoneSet.add(state + "Z" + zone)

#         print "zoneSet =", repr(zoneSet)

#  Return the completed zone set
        return zoneSet
Beispiel #22
0
def getSounding(modelName,
                weatherElements,
                levels,
                samplePoint,
                refTime=None,
                timeRange=None):
    """"
    Performs a series of Data Access Framework requests to retrieve a sounding object
    based on the specified request parameters.

    Args:
            modelName: the grid model datasetid to use as the basis of the sounding.
            weatherElements: a list of parameters to return in the sounding.
            levels: a list of levels to sample the given weather elements at
            samplePoint: a lat/lon pair to perform the sampling of data at.
            refTime: (optional) the grid model reference time to use for the sounding.
                     If not specified, the latest ref time in the system will be used.
            timeRange: (optional) a TimeRange to specify which forecast hours to use.
                     If not specified, will default to all forecast hours.

    Returns:
            A _SoundingCube instance, which acts a 3-tiered dictionary, keyed
            by DataTime, then by level and finally by weather element. If no
            data is available for the given request parameters, None is returned.
    """

    (locationNames, parameters, levels, envelope, refTime, timeRange) = \
        __sanitizeInputs(modelName, weatherElements, levels, samplePoint, refTime, timeRange)

    requestArgs = {
        'datatype': 'grid',
        'locationNames': locationNames,
        'parameters': parameters,
        'levels': levels,
        'envelope': envelope,
    }

    req = DataAccessLayer.newDataRequest(**requestArgs)

    forecastHours = __determineForecastHours(req, refTime, timeRange)
    if not forecastHours:
        return None

    response = DataAccessLayer.getGeometryData(req, forecastHours)
    soundingObject = _SoundingCube(response)

    return soundingObject
Beispiel #23
0
 def runGeometryDataTestWithTimeRange(self, req, timeRange):
     """
     Test that we are able to successfully retrieve geometry data for the
     given request.
     """
     geomData = DAL.getGeometryData(req, timeRange)
     self.assertIsNotNone(geomData)
     print("Number of geometry records: " + str(len(geomData)))
     print("Sample geometry data:")
     for record in geomData[:self.sampleDataLimit]:
         self.assertGreaterEqual(record.getDataTime().getRefTime().getTime(), timeRange.getStartInMillis())
         self.assertLessEqual(record.getDataTime().getRefTime().getTime(), timeRange.getEndInMillis())
         print("geometry=" + str(record.getGeometry()), end="")
         for p in req.getParameters():
             print(" " + p + "=" + record.getString(p), end="")
         print()
     return geomData
 def runGeometryDataTestWithTimeRange(self, req, timeRange):
     """
     Test that we are able to successfully retrieve geometry data for the
     given request.
     """
     geomData = DAL.getGeometryData(req, timeRange)
     self.assertIsNotNone(geomData)
     if not geomData:
         raise unittest.SkipTest("No data available")
     print("Number of geometry records: " + str(len(geomData)))
     print("Sample geometry data:")
     for record in geomData[:self.sampleDataLimit]:
         self.assertGreaterEqual(record.getDataTime().getRefTime().getTime(), timeRange.getStartInMillis())
         self.assertLessEqual(record.getDataTime().getRefTime().getTime(), timeRange.getEndInMillis())
         print("geometry=" + str(record.getGeometry()), end="")
         for p in req.getParameters():
             print(" " + p + "=" + record.getString(p), end="")
         print()
     return geomData
Beispiel #25
0
 def runGeometryDataTest(self, req, checkDataTimes=True):
     """
     Test that we are able to successfully retrieve geometry data for the
     given request.
     """
     times = DafTestCase.getTimesIfSupported(req)
     geomData = DAL.getGeometryData(req, times[:self.numTimesToLimit])
     self.assertIsNotNone(geomData)
     if times:
         self.assertNotEqual(len(geomData), 0)
     print("Number of geometry records: " + str(len(geomData)))
     print("Sample geometry data:")
     for record in geomData[:self.sampleDataLimit]:
         if checkDataTimes and times:
             self.assertIn(record.getDataTime(), times[:self.numTimesToLimit])
         print("geometry=" + str(record.getGeometry()), end="")
         for p in req.getParameters():
             print(" " + p + "=" + record.getString(p), end="")
         print()
     return geomData
 def runGeometryDataTest(self, req, checkDataTimes=True):
     """
     Test that we are able to successfully retrieve geometry data for the
     given request.
     """
     times = DafTestCase.getTimesIfSupported(req)
     geomData = DAL.getGeometryData(req, times[:self.numTimesToLimit])
     self.assertIsNotNone(geomData)
     #if times:
     #    self.assertNotEqual(len(geomData), 0)
     if not geomData:
         raise unittest.SkipTest("No data available")
     print("Number of geometry records: " + str(len(geomData)))
     print("Sample geometry data:")
     for record in geomData[:self.sampleDataLimit]:
         if (checkDataTimes and times and
                 "PERIOD_USED" not in record.getDataTime().getUtilityFlags()):
             self.assertIn(record.getDataTime(), times[:self.numTimesToLimit])
         print("geometry=" + str(record.getGeometry()), end="")
         for p in req.getParameters():
             print(" " + p + "=" + str(record.getString(p)), end="")
         print()
     return geomData
Beispiel #27
0
    def testGetGeometryData(self):
        req = DAL.newDataRequest(self.datatype)
        req.setParameters("temperature", "pressure", "uComponent", "vComponent")

        print("Testing getGeometryData()")

        geomData = DAL.getGeometryData(req)
        self.assertIsNotNone(geomData)
        print("Number of geometry records: " + str(len(geomData)))
        print("Sample geometry data:")
        for record in geomData[:self.sampleDataLimit]:
            print("level:", record.getLevel(), end="")
            # One dimensional parameters are reported on the 0.0UNKNOWN level.
            # 2D parameters are reported on MB levels from pressure.
            if record.getLevel() == "0.0UNKNOWN":
                print(" temperature=" + record.getString("temperature") + record.getUnit("temperature"), end="")
                print(" pressure=" + record.getString("pressure") + record.getUnit("pressure"), end="")
            else:
                print(" uComponent=" + record.getString("uComponent") + record.getUnit("uComponent"), end="")
                print(" vComponent=" + record.getString("vComponent") + record.getUnit("vComponent"), end="")
            print(" geometry:", record.getGeometry())

        print("getGeometryData() complete\n\n")
Beispiel #28
0
def main():
    # The multi-dimensional parameters.
    MAN_PARAMS = set(['prMan', 'htMan', 'tpMan', 'tdMan', 'wdMan', 'wsMan'])
    TROP_PARAMS = set(['prTrop', 'tpTrop', 'tdTrop', 'wdTrop', 'wsTrop'])
    MAXW_PARAMS = set(['prMaxW', 'wdMaxW', 'wsMaxW'])
    SIGT_PARAMS = set(['prSigT', 'tpSigT', 'tdSigT'])
    SIGW_PARAMS = set(['htSigW', 'wdSigW', 'wsSigW'])

    user_args = get_args()

    if user_args.host:
        DataAccessLayer.changeEDEXHost(user_args.host)

    start = user_args.start
    end = user_args.end

    if not start or not end:
        print >> sys.stderr, "Start or End date not provided"
        return

    beginRange = datetime.strptime(start + ":00.0", "%Y-%m-%d %H:%M:%S.%f")
    endRange = datetime.strptime(end + ":59.9", "%Y-%m-%d %H:%M:%S.%f")
    timerange = TimeRange(beginRange, endRange)

    req = DataAccessLayer.newDataRequest("bufrua")
    req.setParameters("wmoStaNum", "validTime", "rptType", "staElev",
                      "numMand", "numSigT", "numSigW", "numTrop", "numMwnd",
                      "staName")
    req.getParameters().extend(MAN_PARAMS)
    req.getParameters().extend(TROP_PARAMS)
    req.getParameters().extend(MAXW_PARAMS)
    req.getParameters().extend(SIGT_PARAMS)
    req.getParameters().extend(SIGW_PARAMS)

    geometries = DataAccessLayer.getGeometryData(req, timerange)

    if not geometries:
        #        print "couldn't get data"
        return

    manGeos = []
    tropGeos = []
    maxwGeos = []
    sigtGeos = []
    sigwGeos = []
    # D-2D format files expect depression
    tdman = []
    tdsigt = []
    tdtrop = []
    msg = ""
    for geoData in geometries:
        if set(geoData.getParameters()) & MAN_PARAMS:
            manGeos.append(geoData)
            td = geoData.getNumber("tdMan")
            tp = geoData.getNumber("tpMan")
            if td > 150 and td <= tp:
                tdman.append(tp - td)
            else:
                tdman.append(-9999.0)
            continue
        if set(geoData.getParameters()) & TROP_PARAMS:
            tropGeos.append(geoData)
            td = geoData.getNumber("tdTrop")
            tp = geoData.getNumber("tpTrop")
            if td > 150 and td <= tp:
                tdtrop.append(tp - td)
            else:
                tdtrop.append(-9999.0)
            continue
        if set(geoData.getParameters()) & MAXW_PARAMS:
            maxwGeos.append(geoData)
            continue
        if set(geoData.getParameters()) & SIGT_PARAMS:
            sigtGeos.append(geoData)
            td = geoData.getNumber("tdSigT")
            tp = geoData.getNumber("tpSigT")
            if td > 150 and td <= tp:
                tdsigt.append(tp - td)
            else:
                tdsigt.append(-9999.0)
            continue
        if set(geoData.getParameters()) & SIGW_PARAMS:
            sigwGeos.append(geoData)
            continue

        if len(manGeos) == 0 and len(sigtGeos) == 0 and len(
                sigwGeos) == 0 or geoData.getNumber("rptType") > 2022:
            manGeos = []
            tropGeos = []
            maxwGeos = []
            sigtGeos = []
            sigwGeos = []
            tdman = []
            tdsigt = []
            tdtrop = []
            continue

        if user_args.stationname and geoData.getString("staName"):
            msg += geoData.getString("staName") + ","
        else:
            msg += geoData.getString("wmoStaNum") + ","
        msg += str(geoData.getNumber("validTime") / 1000) + ","
        msg += "%.4f" % geoData.getGeometry().y + ","
        msg += "%.4f" % geoData.getGeometry().x + ","
        msg += "%.0f" % geoData.getNumber("staElev") + ","
        msg += geoData.getString("wmoStaNum") + ","

        kk = len(manGeos)
        msg += str(kk) + ","
        if kk > 0:
            msg += "%.1f" % manGeos[0].getNumber("prMan")
            k = 1
            while k < kk:
                msg += "|" + "%.1f" % manGeos[k].getNumber("prMan")
                k += 1
            msg += ","

            msg += "%.1f" % geoData.getNumber("staElev")
            k = 1
            while k < kk:
                msg += "|" + "%.1f" % manGeos[k].getNumber("htMan")
                k += 1
            msg += ","

            msg += "%.1f" % manGeos[0].getNumber("tpMan")
            k = 1
            while k < kk:
                msg += "|" + "%.1f" % manGeos[k].getNumber("tpMan")
                k += 1
            msg += ","

            msg += "%.1f" % tdman[0]
            k = 1
            while k < kk:
                msg += "|" + "%.1f" % tdman[k]
                k += 1
            msg += ","

            msg += "%.1f" % manGeos[0].getNumber("wsMan")
            k = 1
            while k < kk:
                msg += "|" + "%.1f" % manGeos[k].getNumber("wsMan")
                k += 1
            msg += ","

            msg += "%.1f" % manGeos[0].getNumber("wdMan")
            k = 1
            while k < kk:
                msg += "|" + "%.1f" % manGeos[k].getNumber("wdMan")
                k += 1
            msg += ","
        else:
            msg += ",,,,,,"

        kk = len(sigtGeos)
        msg += str(kk) + ","
        if kk > 0:
            msg += "%.1f" % sigtGeos[0].getNumber("prSigT")
            k = 1
            while k < kk:
                msg += "|" + "%.1f" % sigtGeos[k].getNumber("prSigT")
                k += 1
            msg += ","

            msg += "%.1f" % sigtGeos[0].getNumber("tpSigT")
            k = 1
            while k < kk:
                msg += "|" + "%.1f" % sigtGeos[k].getNumber("tpSigT")
                k += 1
            msg += ","

            msg += "%.1f" % tdsigt[0]
            k = 1
            while k < kk:
                msg += "|" + "%.1f" % tdsigt[k]
                k += 1
            msg += ","
        else:
            msg += ",,,"

        kk = len(sigwGeos)
        msg += str(kk) + ","
        if kk > 0:
            msg += "%.1f" % sigwGeos[0].getNumber("htSigW")
            k = 1
            while k < kk:
                msg += "|" + "%.1f" % sigwGeos[k].getNumber("htSigW")
                k += 1
            msg += ","

            msg += "%.1f" % sigwGeos[0].getNumber("wsSigW")
            k = 1
            while k < kk:
                msg += "|" + "%.1f" % sigwGeos[k].getNumber("wsSigW")
                k += 1
            msg += ","

            msg += "%.1f" % sigwGeos[0].getNumber("wdSigW")
            k = 1
            while k < kk:
                msg += "|" + "%.1f" % sigwGeos[k].getNumber("wdSigW")
                k += 1
            msg += ","
        else:
            msg += ",,,"

        kk = len(tropGeos)
        msg += str(kk) + ","
        if kk > 0:
            msg += "%.1f" % tropGeos[0].getNumber("prTrop")
            k = 1
            while k < kk:
                msg += "|" + "%.1f" % tropGeos[k].getNumber("prTrop")
                k += 1
            msg += ","

            msg += "%.1f" % tropGeos[0].getNumber("tpTrop")
            k = 1
            while k < kk:
                msg += "|" + "%.1f" % tropGeos[k].getNumber("tpTrop")
                k += 1
            msg += ","

            msg += "%.1f" % tdtrop[0]
            k = 1
            while k < kk:
                msg += "|" + "%.1f" % tdtrop[k]
                k += 1
            msg += ","

            msg += "%.1f" % tropGeos[0].getNumber("wsTrop")
            k = 1
            while k < kk:
                msg += "|" + "%.1f" % tropGeos[k].getNumber("wsTrop")
                k += 1
            msg += ","

            msg += "%.1f" % tropGeos[0].getNumber("wdTrop")
            k = 1
            while k < kk:
                msg += "|" + "%.1f" % tropGeos[k].getNumber("wdTrop")
                k += 1
            msg += ","
        else:
            msg += ",,,,,"

        kk = len(maxwGeos)
        msg += str(kk) + ","
        if kk > 0:
            msg += "%.1f" % maxwGeos[0].getNumber("prMaxW")
            k = 1
            while k < kk:
                msg += "|" + "%.1f" % maxwGeos[k].getNumber("prMaxW")
                k += 1
            msg += ","

            msg += "%.1f" % maxwGeos[0].getNumber("wsMaxW")
            k = 1
            while k < kk:
                msg += "|" + "%.1f" % maxwGeos[k].getNumber("wsMaxW")
                k += 1
            msg += ","

            msg += "%.1f" % maxwGeos[0].getNumber("wdMaxW")
            k = 1
            while k < kk:
                msg += "|" + "%.1f" % maxwGeos[k].getNumber("wdMaxW")
                k += 1
        else:
            msg += ",,"
        msg += "\n"

        manGeos = []
        tropGeos = []
        maxwGeos = []
        sigtGeos = []
        sigwGeos = []
        tdman = []
        tdsigt = []
        tdtrop = []

    print msg.strip()
Beispiel #29
0
 def _getAllRecords(self):
     req = DAL.newDataRequest()
     req.setDatatype(self.datatype)
     req.setParameters('id')
     return DAL.getGeometryData(req)
Beispiel #30
0
 def testFilterOnNonexistentLocationReturnsEmpty(self):
     req = DAL.newDataRequest()
     req.setDatatype(self.datatype)
     req.setParameters('id')
     req.setLocationNames('ZZZZ')
     self.assertEqual(len(DAL.getGeometryData(req)), 0)
Beispiel #31
0
def main():
    # The multi-dimensional parameters.
    MULTI_DIM_PARAMS = set(['vComponent', 'uComponent', 'peakPower', 
                            'levelMode', 'uvQualityCode', 'consensusNum', 
                            'HorizSpStdDev', 'wComponent', 'height', 
                            'VertSpStdDev'])

    user_args = get_args()

    if user_args.host:
        DataAccessLayer.changeEDEXHost(user_args.host)

    start = user_args.start
    end = user_args.end

    if not start or not end:
        print >> sys.stderr, "Start or End date not provided"
        return

    beginRange = datetime.strptime( start + ":00.0", "%Y-%m-%d %H:%M:%S.%f")
    endRange = datetime.strptime( end + ":59.9", "%Y-%m-%d %H:%M:%S.%f")
    timerange = TimeRange(beginRange, endRange)

    req = DataAccessLayer.newDataRequest("profiler")
    req.setParameters('numProfLvls', 'elevation', 'windDirSfc', 'validTime', 
                      'windSpeedSfc', 'pressure', 'submode', 'relHumidity', 
                      'profilerId', 'rainRate', 'temperature')
    req.getParameters().extend(MULTI_DIM_PARAMS)

    geometries = DataAccessLayer.getGeometryData(req, timerange)

    if not geometries :
#        print "couldn't get data"
        return

    
    subgeos = []
    msg = ""
    for geoData in geometries :
        if set(geoData.getParameters()) & MULTI_DIM_PARAMS :
            subgeos.append(geoData)
            continue

        elev = geoData.getNumber("elevation")
        msg += geoData.getString("profilerId") + ","
        msg += str(geoData.getNumber("validTime")/1000) + ","
        msg += "%.4f"%geoData.getGeometry().y + ","
        msg += "%.4f"%geoData.getGeometry().x + ","
        msg += "%.0f"%elev + ","
        msg += "%.1f"%geoData.getNumber("pressure") + ","
        msg += "%.1f"%geoData.getNumber("temperature") + ","
        msg += "%.1f"%geoData.getNumber("relHumidity") + ","
        msg += "%.0f"%geoData.getNumber("windDirSfc") + ","
        msg += "%.1f"%geoData.getNumber("windSpeedSfc") + ","
        msg += "%.1f"%geoData.getNumber("rainRate") + ","
        msg += str(geoData.getNumber("submode")) + ","

        kk = len(subgeos)
#        msg += str(kk) + ","

        subgeos[0].getString("consensusNum")
        if kk>0 : msg += "%.0f"%(subgeos[0].getNumber("height")-elev)
        k = 1
        while k < kk :
            msg += "|" + "%.0f"%(subgeos[k].getNumber("height")-elev)
            k += 1
        msg += ","
        if kk>0 : msg += str(subgeos[0].getNumber("levelMode"))
        k = 1
        while k < kk :
            msg += "|" + str(subgeos[k].getNumber("levelMode"))
            k += 1
        msg += ","

        if kk>0 : msg += "%.1f"%subgeos[0].getNumber("uComponent")
        k = 1
        while k < kk :
            msg += "|" + "%.1f"%subgeos[k].getNumber("uComponent")
            k += 1
        msg += ","
        if kk>0 : msg += "%.1f"%subgeos[0].getNumber("vComponent")
        k = 1
        while k < kk :
            msg += "|" + "%.1f"%subgeos[k].getNumber("vComponent")
            k += 1
        msg += ","
        if kk>0 : msg += "%.2f"%subgeos[0].getNumber("wComponent")
        k = 1
        while k < kk :
            msg += "|" + "%.2f"%subgeos[k].getNumber("wComponent")
            k += 1
        msg += ","

        if kk>0 : msg += "%.1f"%subgeos[0].getNumber("peakPower")
        k = 1
        while k < kk :
            msg += "|" + "%.1f"%subgeos[k].getNumber("peakPower")
            k += 1
        msg += ","
        if kk>0 : msg += "%.1f"%subgeos[0].getNumber("HorizSpStdDev")
        k = 1
        while k < kk :
            msg += "|" + "%.1f"%subgeos[k].getNumber("HorizSpStdDev")
            k += 1
        msg += ","
        if kk>0 : msg += "%.1f"%subgeos[0].getNumber("VertSpStdDev")
        k = 1
        while k < kk :
            msg += "|" + "%.1f"%subgeos[k].getNumber("VertSpStdDev")
            k += 1
        msg += ","

        if kk>0 : msg += subgeos[0].getString("uvQualityCode")
        k = 1
        while k < kk :
            msg += "|" + subgeos[k].getString("uvQualityCode")
            k += 1
        msg += ","
        if kk>0 : msg += subgeos[0].getString("consensusNum")
        k = 1
        while k < kk :
            msg += "|" + subgeos[k].getString("consensusNum")
            k += 1
        msg += "\n"
        subgeos = []

    print msg.strip()
Beispiel #32
0
 def testFilterOnNonexistentLocationReturnsEmpty(self):
     req = DAL.newDataRequest()
     req.setDatatype(self.datatype)
     req.setParameters('id')
     req.setLocationNames('ZZZZ')
     self.assertEqual(len(DAL.getGeometryData(req)), 0)
Beispiel #33
0
    ax.set_extent(bbox)
    gl = ax.gridlines(draw_labels=True)
    gl.xlabels_top = gl.ylabels_right = False
    gl.xformatter = LONGITUDE_FORMATTER
    gl.yformatter = LATITUDE_FORMATTER
    return fig, ax


DataAccessLayer.changeEDEXHost("edex-cloud.unidata.ucar.edu")
request = DataAccessLayer.newDataRequest()
request.setDatatype("warning")
request.setParameters('phensig')
times = DataAccessLayer.getAvailableTimes(request)

# Get records for last 50 available times
response = DataAccessLayer.getGeometryData(request, times[-50:-1])
print("Using " + str(len(response)) + " records")

# Each record will have a numpy array the length of the number of "parameters"
# Default is 1 (request.setParameters('phensig'))
parameters = {}
for x in request.getParameters():
    parameters[x] = np.array([])
print(parameters)

bbox = [-125, -65, 20, 50]
fig, ax = make_map(bbox=bbox)

siteids = np.array([])
periods = np.array([])
reftimes = np.array([])
Beispiel #34
0
def main():
    user_args = get_args()

    if user_args.host:
        DataAccessLayer.changeEDEXHost(user_args.host)

    start = user_args.start
    end = user_args.end

    if not start or not end:
        print >> sys.stderr, "Start or End date not provided"
        return

    beginRange = datetime.strptime(start + ":00.0", "%Y-%m-%d %H:%M:%S.%f")
    endRange = datetime.strptime(end + ":59.9", "%Y-%m-%d %H:%M:%S.%f")
    timerange = TimeRange(beginRange, endRange)

    req = DataAccessLayer.newDataRequest("sfcobs")
    req.setParameters("stationId", "timeObs", "elevation", "reportType",
                      "wx_present", "visibility", "seaLevelPress",
                      "stationPress", "pressChange3Hour", "pressChangeChar",
                      "temperature", "dewpoint", "seaSurfaceTemp", "wetBulb",
                      "windDir", "windSpeed", "equivWindSpeed10m", "windGust",
                      "precip1Hour", "precip6Hour", "precip24Hour")
    geometries = DataAccessLayer.getGeometryData(req, timerange)

    if not geometries:
        #        print "No data available."
        return

    # Initialize conversion array for wx.
    wxstr = [ " ", " ", " ", " ", "FU", "HZ", "DU", "BLSA", "PO", "VCSS", \
        "BR", "BCFG", "MIFG", "VCTS", "VCSH", "VCSH", "VCSH", " ", "SQ", "+FC", \
        "DZ", "RA", "SN", "RA SN", "FZRA", "SHRA", "SHRA SHSN", "SHGR", "FG FZFG", "TS", \
        "SS", "SS", "SS", "+SS", "+SS", "+SS", "DRSN", " ", "BLSN", "+BLSN", \
        "VCFG", "BCFG", "FG FZFG", "FG FZFG", "FG FZFG", "FG FZFG", "FG FZFG", "FG FZFG", "FZFG", "FZFG", \
        "-DZ", "-DZ", "DZ", "DZ", "+DZ", "+DZ", "-FZDZ", "FZDZ", "-DZ -RA", "DZ RA", \
        "-RA", "-RA", "RA", "RA", "+RA", "+RA", "-FZRA", "FZRA", "-RA -SN", "RA SN", \
        "-SN", "-SN", "SN", "SN", "+SN", "+SN", "IC", "SG", "IC", "PE", \
        "-SHRA", "SHRA", "+SHRA", "-SHSN -SHRA", "SHSN SHRA", "-SNSN", "SHSN", "-SHPE", "SHPE", " ", \
        "SHGR", "-RA", "+RA", "-RA -SN -GR", "+RA +SN +GR", "TSRA", "TSPE", "+TSRA", " ", "+TSPE" ]

    msg = ""
    for geo in geometries:
        lon = geo.getGeometry().x
        lat = geo.getGeometry().y

        sName = geo.getString("stationId")
        tobs = geo.getNumber("timeObs")
        elev = geo.getNumber("elevation")
        typ = geo.getNumber("reportType")
        wx = geo.getNumber("wx_present")
        vis = geo.getNumber("visibility")
        msl = geo.getNumber("seaLevelPress")
        p = geo.getNumber("stationPress")
        pchg = geo.getNumber("pressChange3Hour")
        pchr = geo.getNumber("pressChangeChar")
        temp = geo.getNumber("temperature")
        dpt = geo.getNumber("dewpoint")
        th2o = geo.getNumber("seaSurfaceTemp")
        tw = geo.getNumber("wetBulb")
        dir = geo.getNumber("windDir")
        spd = geo.getNumber("windSpeed")
        s10 = geo.getNumber("equivWindSpeed10m")
        gust = geo.getNumber("windGust")
        pr1 = geo.getNumber("precip1Hour")
        pr6 = geo.getNumber("precip6Hour")
        pr24 = geo.getNumber("precip24Hour")

        msg += sName + ","
        msg += str(tobs / 1000) + ","
        msg += "%.4f" % lat + ","
        msg += "%.4f" % lon + ","
        msg += "%.0f" % elev + ","
        if typ < 1001 or typ > 1007:
            msg += "-32767,"
        elif typ == 1001 or typ == 1004 or typ == 1005:
            msg += "0,"
        else:
            msg += "1,"
        if wx < 0 or wx > 99:
            msg += " ,"
        else:
            msg += wxstr[wx] + ","
        msg += str(vis) + ","
        msg += "%.2f" % msl + ","
        msg += "%.2f" % p + ","
        msg += "%.0f" % pchg + ","
        if pchr <= -9999:
            pchr = -32767
        msg += str(pchr) + " ,"
        msg += "%.1f" % temp + ","
        msg += "%.1f" % dpt + ","
        msg += "%.1f" % th2o + ","
        msg += "%.1f" % tw + ","
        msg += "%.0f" % dir + ","
        msg += "%.1f" % spd + ","
        msg += "%.1f" % s10 + ","
        msg += "%.1f" % gust + ","
        msg += "%.2f" % pr1 + ","
        msg += "%.2f" % pr6 + ","
        msg += "%.2f" % pr24 + "\n"

    print msg.strip()
Beispiel #35
0
def main():
    user_args = get_args()

    if user_args.host:
        DataAccessLayer.changeEDEXHost(user_args.host)

    start = user_args.start
    end = user_args.end

    if not start or not end:
        print >> sys.stderr, "Start or End date not provided"
        return

    beginRange = datetime.strptime(start + ":00.0", "%Y-%m-%d %H:%M:%S.%f")
    endRange = datetime.strptime(end + ":59.9", "%Y-%m-%d %H:%M:%S.%f")
    timerange = TimeRange(beginRange, endRange)

    req = DataAccessLayer.newDataRequest("airep")
    req.setParameters("id", "flightLevel", "temp", "windDirection",
                      "windSpeed", "flightWeather", "flightHazard",
                      "flightConditions")
    geometries = DataAccessLayer.getGeometryData(req, timerange)

    if not geometries:
        #        print "No data available."
        return

    msg = ""

    geometries.sort(key=lambda geo: str(geo.getDataTime()))
    for geoData in geometries:
        mytime = geoData.getDataTime()
        if not mytime:
            continue
        mytime = a2dafcommon.datatime_to_string(mytime)

        geo = geoData.getGeometry()
        if not geo:
            continue

        mylon = geo.x
        mylat = geo.y
        if a2dafcommon.is_no_data(mylat) or a2dafcommon.is_no_data(mylon):
            continue
        mylat = "%.4f" % mylat
        mylon = "%.4f" % mylon

        myflvl = geoData.getNumber("flightLevel")
        if a2dafcommon.is_no_data(myflvl):
            myflvl = "1e37"
        else:
            myflvl = "%d" % myflvl


#        Temp is not stored.
#        mytemp = geoData.getString("temp")
#        if a2dafcommon.is_no_data(mytemp) :
#            mytemp = "1e37"
#        else :
#            mytemp = "%.1f"%float(mytemp)
        mytemp = "1e37"

        #        Wind Direction is not stored.
        #        mydir = geoData.getString("windDirection")
        #        if a2dafcommon.is_no_data(mydir) :
        #            mydir = "1e37"
        #        else :
        #            mydir = "%d"%int(mydir)
        mydir = "1e37"

        myspd = geoData.getNumber("windSpeed")
        if a2dafcommon.is_no_data(myspd):
            myspd = "1e37"
        else:
            myspd = "%.1f" % myspd

        myfwx = geoData.getNumber("flightWeather")
        if myfwx:
            myfwx = "-1"
        else:
            myfwx = "%d" % myfwx

        myhaz = geoData.getNumber("flightHazard")
        if a2dafcommon.is_no_data(myhaz):
            myhaz = "-1"
        else:
            myhaz = "%d" % myhaz

        mycond = geoData.getNumber("flightConditions")
        if a2dafcommon.is_no_data(mycond):
            mycond = "-1"
        else:
            mycond = "%d" % mycond

        if user_args.match:
            #           Wind Speed not returned to legacy script.
            myspd = "1e37"

        msg += mylat + "|" + mylon + "," + mytime + "," + myflvl + ",AIREP,," + \
            mytemp + "," + mydir + "," + myspd + ",1e37," + \
            myfwx + "," + myhaz + "," + mycond + ",,0,,,,0,,,,,0,,,,\n"

    print msg.strip()
Beispiel #36
0
def main():
    MULTI_DIM_PARAMS = set(["hazardType", 
                            "turbType", "turbBaseHeight", "turbTopHeight",
                            "iceType", "iceBaseHeight", "iceTopHeight",
                            "skyCover1", "skyCover2", "skyBaseHeight", "skyTopHeight"
                            ])

    user_args = get_args()

    if user_args.host:
        DataAccessLayer.changeEDEXHost(user_args.host)

    start = user_args.start
    end = user_args.end

    if not start or not end:
        print >> sys.stderr, "Start or End date not provided"
        return

    beginRange = datetime.strptime( start + ":00.0", "%Y-%m-%d %H:%M:%S.%f")
    endRange = datetime.strptime( end + ":59.9", "%Y-%m-%d %H:%M:%S.%f")
    timerange = TimeRange(beginRange, endRange)

    req = DataAccessLayer.newDataRequest("pirep")
    req.setParameters('id', 'flightLevel', 'temp', 'windDirection', 'windSpeed',
                      'horzVisibility', 'aircraftType', 'weatherGroup')
    req.getParameters().extend(MULTI_DIM_PARAMS)
    geometries = DataAccessLayer.getGeometryData(req, timerange)

    if not geometries :
#        print "No data available."
        return

    typecode = user_args.typecode
    match = user_args.match
    msg = ""
    layerData = []
    combinedGeos = []
    for geoData in geometries :
#       The DAF returns multi-dimensional parameters as separate results before
#       the base result that contain the single-dimensional parameters.
#       Because of the separation of parameters and known ordering of result
#       types, we can easily figure out what each result is and correlate the
#       ancillary data with the base data.
        if set(geoData.getParameters()) & MULTI_DIM_PARAMS :
            layerData.append(geoData)
            continue

        combinedGeos.append({"base":geoData, "layers":layerData})
        layerData = []

    combinedGeos.sort(key=lambda geoMap: str(geoMap['base'].getDataTime()))

    for geoMap in combinedGeos :
        geoData = geoMap['base']
        layerData = geoMap['layers']

        mytime = geoData.getDataTime()
        if not mytime:
            continue
        mytime = mytime = a2dafcommon.datatime_to_string(mytime)

        geo = geoData.getGeometry()
        if not geo:
            continue

        mylon = geo.x
        mylat = geo.y
        if a2dafcommon.is_no_data(mylat) or a2dafcommon.is_no_data(mylon) :
            continue
        mylat = "%.4f"%mylat
        mylon = "%.4f"%mylon

        myflvl = geoData.getNumber("flightLevel")
        if a2dafcommon.is_no_data(myflvl) :
            myflvl = "1e37"
        else :
            myflvl = "%d"%myflvl

#        Temp is not stored.
#        mytemp = geoData.getNumber("temp")
#        if a2dafcommon.is_no_data(mytemp) :
#            mytemp = "1e37"
#        else :
#            mytemp = "%.1f"%float(mytemp)
        mytemp = "1e37"

#        Wind Direction is not stored.
#        mydir = geoData.getString("windDirection")
#        if a2dafcommon.is_no_data(mydir) :
#            mydir = "1e37"
#        else :
#            mydir = "%d"%int(mydir)
        mydir = "1e37"

        myspd = geoData.getNumber("windSpeed")
        if a2dafcommon.is_no_data(myspd) :
            myspd = "1e37"
        else :
            myspd = "%.1f"%myspd

        myvis = geoData.getNumber("horzVisibility")
        if a2dafcommon.is_no_data(myvis) :
            myvis = "1e37"
        else :
            myvis = "%.1f"%myvis

        mycraft = geoData.getString("aircraftType")
        if a2dafcommon.is_no_data(mycraft) :
            mycraft = ""

        mywx = geoData.getString("weatherGroup")
        if a2dafcommon.is_no_data(mywx) :
            mywx = ""


        cc = 0
        cldBas = ""
        cldTop = ""
        cldVal = ""
        ii = 0
        icgBas = ""
        icgTop = ""
        icgTyp = ""
        icgVal = ""
        tt = 0
        trbBas = ""
        trbTop = ""
        trbTyp = ""
        trbVal = ""

        if match :
#           Speed, Horizontal Visibility, aircraft type, and weather group are
#           not returned to the legacy script. Flightlevel of -9999 is output
#           as such instead of being replaced by "1e37"
            myspd = "1e37"
            myvis = "-9999998.0"
            mycraft = ""
            mywx = ""
            if geoData.getNumber("flightLevel") == -9999:
                myflvl = "-9999"
        else :
            for pld in layerData:
                sep = ""
                ltyp = pld.getString("hazardType")
                if a2dafcommon.is_no_data(ltyp) :
                    continue

                fval = pld.getString("skyCover1")
                if fval ==  "None" :
                    fval = ""

                sval = pld.getString("skyCover2")
                if sval ==  "None" :
                    sval = ""
                if ltyp == "CLOUD" :
                    if fval == "TOP" :
                        fval = ""
                    if sval == "TOP" :
                        sval = ""
                    if sval != "" :
                        fval += "-"+sval
                    if typecode :
                        if fval == "CLR" :
                            fval = "0"
                        elif fval == "OVC" :
                            fval = "8"
                        elif fval == "SCT" :
                            fval = "11"
                        elif fval == "BKN" :
                            fval = "12"
                        elif fval == "FEW" :
                            fval = "13"
                        else :
                            continue
                    if cldBas != "" :
                        sep = "|"

                    base = pld.getNumber("skyBaseHeight")
                    if a2dafcommon.is_no_data(base) or base == 99999 :
                        base = "1e37"
                    else :
                        base = "%.0f"%float(base)

                    top = pld.getNumber("skyTopHeight")
                    if a2dafcommon.is_no_data(top) or top == 99999 :
                        top = "1e37"
                    else :
                        top = "%.0f"%float(top)

                    cldBas += sep+base
                    cldTop += sep+top
                    cldVal += sep+fval
                    cc += 1
                elif ltyp == "ICING" :
                    dtyp = pld.getString("iceType")
                    if a2dafcommon.is_no_data(dtyp) :
                        dtyp = ""

                    if sval != "" :
                        fval += "-"+sval
                    if icgBas != "" :
                        sep = "|"
                    if typecode :
                        if dtyp == "RIME" :
                            dtyp = "1"
                        elif dtyp == "CLR" :
                            dtyp = "2"
                        elif dtyp == "MXD" :
                            dtyp = "3"
                        else :
                            dtyp = "-9999"
                        if fval == "NEG" :
                            fval = "0";
                        elif fval == "TRACE" :
                            fval = "1"
                        elif fval == "TRACE-LGT" :
                            fval = "2"
                        elif fval == "LGT" :
                            fval = "3"
                        elif fval == "LGT-MOD" :
                            fval = "4"
                        elif fval == "MOD" :
                            fval = "5"
                        elif fval == "MOD-SEV" :
                            fval = "7"
                        elif fval == "SEV" :
                            fval = "8"
                        else :
                            fval = "-9999"
                        if fval == "-9999" and dtyp == "-9999" :
                            continue

                    base = pld.getNumber("iceBaseHeight")
                    if a2dafcommon.is_no_data(base) or base == 99999 :
                        base = "1e37"
                    else :
                        base = "%.0f"%float(base)

                    top = pld.getNumber("iceTopHeight")
                    if a2dafcommon.is_no_data(top) or top == 99999 :
                        top = "1e37"
                    else :
                        top = "%.0f"%float(top)

                    icgBas += sep+base
                    icgTop += sep+top
                    icgTyp += sep+dtyp
                    icgVal += sep+fval
                    ii += 1
                elif ltyp == "TURBC" :
                    dtyp = pld.getString("turbType")
                    if a2dafcommon.is_no_data(dtyp) :
                        dtyp = ""

                    if sval != "" :
                        fval += "-"+sval
                    if typecode :
                        if dtyp == "CAT" :
                            dtyp = "1"
                        elif dtyp == "CHOP" :
                            dtyp = "2"
                        else :
                            dtyp = "-9999"
                        if fval == "NEG" :
                            fval = "0";
                        elif fval == "LGT" :
                            fval = "2"
                        elif fval == "LGT-MOD" :
                            fval = "3"
                        elif fval == "MOD" :
                            fval = "4"
                        elif fval == "MOD-SEV" :
                            fval = "5"
                        elif fval == "SEV" :
                            fval = "6"
                        elif fval == "EXTRM" :
                            fval = "8"
                        else :
                            fval = "-9999"
                        if fval == "-9999" and dtyp == "-9999" :
                            continue
                    if trbBas != "" :
                        sep = "|"

                    base = pld.getNumber("turbBaseHeight")
                    if a2dafcommon.is_no_data(base) or base == 99999 :
                        base = "1e37"
                    else :
                        base = "%.0f"%float(base)

                    top = pld.getNumber("turbTopHeight")
                    if a2dafcommon.is_no_data(top) or top == 99999 :
                        top = "1e37"
                    else :
                        top = "%.0f"%float(top)

                    trbBas += sep+base
                    trbTop += sep+top
                    trbTyp += sep+dtyp
                    trbVal += sep+fval
                    tt += 1

        msg += mylat + "|" + mylon + "," + mytime + "," + myflvl + ",PIREP," + \
            mycraft + "," + mytemp + "," + mydir + "," + myspd + "," + \
            myvis + ",-1,-1,-1," + mywx + "," + \
            str(cc) + "," + cldBas + "," + cldTop + "," + cldVal + "," + \
            str(ii) + "," + icgBas + "," + icgTop + "," + \
            icgTyp + "," + icgVal + "," + \
            str(tt) + "," + trbBas + "," + trbTop + "," + \
            trbTyp + "," + trbVal + "\n"

    print msg.strip()
Beispiel #37
0
def main():
    user_args = get_args()

    if user_args.host:
        DataAccessLayer.changeEDEXHost(user_args.host)

    start = user_args.start
    end = user_args.end

    if not start or not end:
        print >> sys.stderr, "Start or End date not provided"
        return

    latMin = user_args.latMin
    latMax = user_args.latMax
    lonMin = user_args.lonMin
    lonMax = user_args.lonMax

    beginRange = datetime.strptime( start + ":00.0", "%Y-%m-%d %H:%M:%S.%f")
    endRange = datetime.strptime( end + ":59.9", "%Y-%m-%d %H:%M:%S.%f")
    timerange = TimeRange(beginRange, endRange)

    req = DataAccessLayer.newDataRequest("obs")
    req.setParameters("stationName","timeObs","wmoId","autoStationType",
                      "elevation","seaLevelPress","temperature","dewpoint",
                      "windDir","windSpeed","altimeter" )
    geometries = DataAccessLayer.getGeometryData(req, timerange)

    if not geometries :
#        print "No data available."
        return

    msg = ""
    for geo in geometries :
        lon = geo.getGeometry().x
        lat = geo.getGeometry().y
        if lon < lonMin or lon > lonMax or lat < latMin or lat > latMax:
            continue

        sName = geo.getString("stationName")
        tobs = geo.getNumber("timeObs")
        elev = geo.getNumber("elevation")
        ista = geo.getString("wmoId")
        atype = geo.getString("autoStationType")
        msl = geo.getNumber("seaLevelPress")
        temp = geo.getNumber("temperature")
        dpt = geo.getNumber("dewpoint")
        dir = geo.getNumber("windDir")
        spd = geo.getNumber("windSpeed")
        alt = geo.getNumber("altimeter")

        msg += sName + ","
        msg += str(tobs/1000) + ","
        msg += "%.4f"%lat + ","
        msg += "%.4f"%lon + ","
        msg += "%.0f"%elev + ","
        msg += str(ista) + ","
        msg += atype + " ,"
        msg += "%.2f"%msl + ","
        msg += "%.1f"%temp + ","
        msg += "%.1f"%dpt + ","
        msg += "%.0f"%dir + ","
        msg += "%.1f"%spd + ","
        msg += "%.2f"%alt + "\n"

    print msg.strip()
Beispiel #38
0
 def _getAllRecords(self):
     req = DAL.newDataRequest()
     req.setDatatype(self.datatype)
     req.setParameters('id')
     return DAL.getGeometryData(req)
Beispiel #39
0
def main():
    user_args = get_args()

    # Set the host in the DataAcessLayer if supplied
    if user_args.host:
        DataAccessLayer.changeEDEXHost(user_args.host)

    start = user_args.start
    end = user_args.end

    if not start or not end:
        print >> sys.stderr, "Start or End date not provided"
        return

    req = DataAccessLayer.newDataRequest("acars")
    req.setParameters("tailNumber", "receiver", "pressure", "flightPhase",
                      "rollAngleQuality", "temp", "windDirection", "windSpeed",
                      "humidity", "mixingRatio", "icing")

    beginRange = datetime.strptime(start + ":00.0", "%Y-%m-%d %H:%M:%S.%f")
    endRange = datetime.strptime(end + ":59.9", "%Y-%m-%d %H:%M:%S.%f")
    timerange = TimeRange(beginRange, endRange)

    geometries = DataAccessLayer.getGeometryData(req, timerange)

    if len(geometries) == 0:
        #       print("No data available.")
        return

    for geoData in geometries:
        mytail = geoData.getString("tailNumber")
        if a2dafcommon.is_no_data(mytail):
            mytail = ""
        else:
            mytail = mytail.strip()

        mytime = geoData.getDataTime()
        if mytime == None:
            continue
        #2014-07-16 00:00:00 (0) => 2014-07-16_00:00:00
        mytime = a2dafcommon.datatime_to_string(mytime)

        geo = geoData.getGeometry()
        if geo == None:
            continue
        mylon = geo.x
        mylat = geo.y
        if a2dafcommon.is_no_data(mylat) or a2dafcommon.is_no_data(mylon):
            continue
        mylat = "%.4f" % float(mylat)
        mylon = "%.4f" % float(mylon)

        myrec = geoData.getString("receiver")
        if a2dafcommon.is_no_data(myrec):
            myrec = ""
        else:
            myrec = myrec.strip()

        mypres = geoData.getNumber("pressure")
        if a2dafcommon.is_no_data(mypres):
            mypres = "1e37"
        else:
            mypres = "%.0f" % mypres

        myphs = geoData.getString("flightPhase")
        if a2dafcommon.is_no_data(myphs):
            myphs = "7"
        else:
            myphs = "%d" % int(myphs)

        myrol = geoData.getString("rollAngleQuality")
        if a2dafcommon.is_no_data(myrol):
            myrol = "3"
        else:
            myrol = "%d" % int(myrol)

        mytemp = geoData.getNumber("temp")
        if a2dafcommon.is_no_data(mytemp):
            mytemp = "1e37"
        else:
            mytemp = "%.1f" % mytemp

        mydir = geoData.getString("windDirection")
        if a2dafcommon.is_no_data(mydir):
            mydir = "1e37"
        else:
            mydir = "%d" % int(mydir)

        myspd = geoData.getNumber("windSpeed")
        if a2dafcommon.is_no_data(myspd):
            myspd = "1e37"
        else:
            myspd = "%.1f" % myspd

        myhum = geoData.getNumber("humidity")
        if a2dafcommon.is_no_data(myhum):
            myhum = "1e37"
        else:
            myhum = "%.0f" % myhum

        mymix = geoData.getNumber("mixingRatio")
        if a2dafcommon.is_no_data(mymix):
            mymix = "1e37"
        else:
            mymix = "%.2f" % mymix


# Icing was commented out of the uengine version
#       myicg = geoData.getString("icing")
#       if a2dafcommon.is_no_data(myicg):
#          myicg = "1e37"
#       else :
#          myicg = "%d"%int(myicg)

        msg = mytail + "," + mytime + "," + mylat + "," + mylon + "," + \
           myrec + "," + mypres + "," + myphs + "," + myrol + "," + \
           mytemp + "," + mydir + "," + myspd + "," + myhum + "," + mymix
        print msg
Beispiel #40
0
def main():
    # The multi-dimensional parameters.
    PRES_PARAMS = set(["presWeather"])
    SKY_PARAMS = set(["skyCover", "skyLayerBase"])

    user_args = get_args()

    if user_args.host:
        DataAccessLayer.changeEDEXHost(user_args.host)

    start = user_args.start
    end = user_args.end

    if not start or not end:
        print >> sys.stderr, "Start or End date not provided"
        return

    latMin = user_args.latMin
    latMax = user_args.latMax
    lonMin = user_args.lonMin
    lonMax = user_args.lonMax

    beginRange = datetime.strptime(start + ":00.0", "%Y-%m-%d %H:%M:%S.%f")
    endRange = datetime.strptime(end + ":59.9", "%Y-%m-%d %H:%M:%S.%f")
    timerange = TimeRange(beginRange, endRange)

    req = DataAccessLayer.newDataRequest("obs")
    req.setParameters("stationName", "timeObs", "wmoId", "autoStationType",
                      "elevation", "reportType", "presWeather", "visibility",
                      "skyCover", "skyLayerBase", "altimeter", "seaLevelPress",
                      "pressChange3Hour", "pressChangeChar", "temperature",
                      "tempFromTenths", "dewpoint", "dpFromTenths", "windDir",
                      "windSpeed", "windGust", "maxTemp24Hour", "minTemp24Hour"
                      "", "precip1Hour", "precip3Hour", "precip6Hour",
                      "precip24Hour")
    geometries = DataAccessLayer.getGeometryData(req, timerange)

    if not geometries:
        #        print "No data available."
        return

    msg = ""
    wx = []
    cvr = []
    bas = []
    for geoData in geometries:
        if set(geoData.getParameters()) & PRES_PARAMS:
            wx.append(geoData.getString("presWeather"))
            continue
        if set(geoData.getParameters()) & SKY_PARAMS:
            cvr.append(geoData.getString("skyCover"))
            bas.append(geoData.getNumber("skyLayerBase"))
            continue

        lon = geoData.getGeometry().x
        lat = geoData.getGeometry().y
        if lon < lonMin or lon > lonMax or lat < latMin or lat > latMax:
            wx = []
            cvr = []
            bas = []
            continue

        sName = geoData.getString("stationName")
        tobs = geoData.getNumber("timeObs")
        elev = geoData.getNumber("elevation")
        ista = geoData.getNumber("wmoId")
        atype = geoData.getString("autoStationType")
        repTyp = geoData.getString("reportType")
        vis = geoData.getNumber("visibility")
        alt = geoData.getNumber("altimeter")
        msl = geoData.getNumber("seaLevelPress")
        pchg = geoData.getNumber("pressChange3Hour")
        pchr = geoData.getString("pressChangeChar")
        temp = geoData.getNumber("temperature")
        t10 = geoData.getNumber("tempFromTenths")
        dpt = geoData.getNumber("dewpoint")
        td10 = geoData.getNumber("dpFromTenths")
        dir = geoData.getNumber("windDir")
        spd = geoData.getNumber("windSpeed")
        gust = geoData.getNumber("windGust")
        tmx = geoData.getNumber("maxTemp24Hour")
        tmn = geoData.getNumber("minTemp24Hour")
        pr1 = geoData.getNumber("precip1Hour")
        pr3 = geoData.getNumber("precip3Hour")
        pr6 = geoData.getNumber("precip6Hour")
        pr24 = geoData.getNumber("precip24Hour")

        msg += sName + ","
        msg += str(tobs / 1000) + ","
        msg += "%.4f" % lat + ","
        msg += "%.4f" % lon + ","
        msg += "%.0f" % elev + ","
        if ista < 0:
            msg += "-99,"
        else:
            msg += str(ista) + ","
        msg += atype + " ,"
        msg += repTyp + " ,"
        msg += wx[0] + " ,"
        msg += "%.3f" % vis + ","

        msg += cvr[0]
        kk = 5
        while kk > 0 and cvr[0 + kk] == "":
            kk -= 1
        k = 1
        while k <= kk:
            msg += "|" + cvr[0 + k]
            k += 1
        msg += " ,"
        msg += "%.1f" % bas[0]
        kk = 5
        while kk > 0 and bas[0 + kk] < -9998:
            kk -= 1
        k = 1
        while k <= kk:
            msg += "|" + "%.1f" % bas[0 + k]
            k += 1
        msg += ","

        msg += "%.2f" % alt + ","
        msg += "%.2f" % msl + ","
        msg += "%.0f" % pchg + ","
        msg += pchr + " ,"
        msg += "%.1f" % temp + ","
        msg += "%.1f" % t10 + ","
        msg += "%.1f" % dpt + ","
        msg += "%.1f" % td10 + ","
        msg += "%.0f" % dir + ","
        msg += "%.1f" % spd + ","
        msg += "%.1f" % gust + ","
        msg += "%.1f" % tmx + ","
        msg += "%.1f" % tmn + ","
        msg += "%.2f" % pr1 + ","
        msg += "%.2f" % pr3 + ","
        msg += "%.2f" % pr6 + ","
        msg += "%.2f" % pr24 + "\n"

        wx = []
        cvr = []
        bas = []

    print msg.strip()