def getGridSlices(db, databaseIds, parmIds, startTime, endTime, coordConversionString): logEvent("Getting Grids from ifpServer") request = GetASCIIGridsRequest() request.setDatabaseIds(databaseIds) request.setParmIds(parmIds) tr = TimeRange() tr.setStart(startTime) tr.setEnd(endTime) request.setTimeRange(tr) request.setCoordConversionString(coordConversionString) request.setWorkstationID(__WsId()) request.setSiteID(databaseIds[0].getSiteId()) try: serverResponse = db.sendRequest(request) except: logException("Unhandled exception thrown:") return ("", False) if (not serverResponse.isOkay()): logProblem("Problem getting grids from db: " + str(serverResponse.message())) return ("", False) return (serverResponse.getPayload(), True)
def download(site: str): # %% SITE site = site.lower() DataAccessLayer.changeEDEXHost('edex-cloud.unidata.ucar.edu') request = DataAccessLayer.newDataRequest() request.setDatatype('radar') request.setLocationNames(site) # %% TIME times = DataAccessLayer.getAvailableTimes(request) times = [parse(str(t)) for t in times] timerange = TimeRange(times[0], times[-1]) # %% REQUEST client = ThriftClient.ThriftClient('edex-cloud.unidata.ucar.edu') request = GetRadarDataRecordRequest() request.setTimeRange(timerange) request.setRadarId(site) code = 'N0Q' request.setProductCode(nexrad[code]['id']) request.setPrimaryElevationAngle(nexrad[code]['elev']) response = client.sendRequest(request) records = response.getData() print(f'found {len(records)} records at {site}') if not response.getData(): raise OSError(f'data not available {timerange}') for rec in records: idra = rec.getHdf5Data() rdat, azdat, depVals, threshVals = RadarCommon.get_hdf5_data(idra) # dim = rdat.getDimension() lat, lon = float(rec.getLatitude()), float(rec.getLongitude()) radials, rangeGates = rdat.getSizes() # Convert raw byte to pixel value array = np.array(rdat.getByteData()) array[array < 0] = array[array < 0] + 256 if azdat: azVals = azdat.getFloatData() az = np.array(RadarCommon.encode_radial(azVals)) # dattyp = RadarCommon.get_data_type(azdat) az = np.append(az, az[-1]) # header = RadarCommon.get_header(rec, format, rangeGates, radials, azdat, 'description') rng = np.linspace(0, rangeGates, rangeGates + 1) * nexrad[code]['res'] lats = np.empty((rng.size, az.size)) lons = np.empty_like(lats) for i, a in enumerate(az): lats, lons, _ = vreckon(lat, lon, rng, a)
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 testGetDataWithTimeRangeWithYearAndDayOfYear3(self): req = DAL.newDataRequest(self.datatype) req.addIdentifier('table', 'public.cli_asos_daily') req.setLocationNames('KFNB') req.setParameters('maxtemp_cal', 'min_press') startTime = datetime.datetime(2007, 7, 1) endTime = datetime.datetime(2009, 3, 31) tr = TimeRange(startTime, endTime) self.runGeometryDataTestWithTimeRange(req, tr)
def testGetDataWithTimeRangeWithForDateTable(self): req = DAL.newDataRequest(self.datatype) req.addIdentifier('table', 'public.daily_climate') req.setLocationNames('KFNB') req.setParameters('max_temp', 'precip', 'avg_wind_speed') startTime = datetime.datetime(2007, 7, 1) endTime = datetime.datetime(2009, 3, 31) tr = TimeRange(startTime, endTime) self.runGeometryDataTestWithTimeRange(req, tr)
def testGetDataWithTimeRangeWithPeriodTable(self): req = DAL.newDataRequest(self.datatype) req.addIdentifier('table', 'public.cli_mon_season_yr') req.setLocationNames('KFNB') req.setParameters('max_temp', 'precip_total') startTime = datetime.datetime(2007, 7, 1) endTime = datetime.datetime(2009, 3, 31) tr = TimeRange(startTime, endTime) self.runGeometryDataTestWithTimeRange(req, tr)
def testGetDataWithTimeRange(self): req = DAL.newDataRequest(self.datatype) req.addIdentifier('table', 'height') req.addIdentifier('ts', 'RG') req.setParameters('value', 'lid', 'quality_code') times = DAL.getAvailableTimes(req) limitTimes = times[-self.numTimesToLimit:] startTime = datetime.datetime.utcfromtimestamp( limitTimes[0].getRefTime().getTime() / 1000) endTime = datetime.datetime.utcnow() tr = TimeRange(startTime, endTime) self.runGeometryDataTestWithTimeRange(req, tr)
def deserialize(context): startTime = context.readI64() endTime = context.readI64() timeRange = TimeRange() # java uses milliseconds, python uses microseconds startSeconds = startTime // MILLIS_IN_SECOND endSeconds = endTime // MILLIS_IN_SECOND startExtraMicros = (startTime % MILLIS_IN_SECOND) * MICROS_IN_MILLISECOND endExtraMicros = (endTime % MILLIS_IN_SECOND) * MICROS_IN_MILLISECOND timeRange.setStart(startSeconds, startExtraMicros) timeRange.setEnd(endSeconds, endExtraMicros) return timeRange
def send_request(user_args): slop = user_args.slop dateTimeStr = user_args.datetime if not dateTimeStr: print >> sys.stderr, "DateTime not provided" return dateTime = datetime.strptime(dateTimeStr, "%Y-%m-%d %H:%M") beginRange = dateTime - timedelta(0, slop) endRange = dateTime + timedelta(0, slop) timerange = TimeRange(beginRange, endRange) radar = user_args.radar if not radar: print >> sys.stderr, "Radar code not provided" return code = user_args.code if not code: print >> sys.stderr, "Product code not provided" return angle = user_args.angle slop = int(user_args.slop) host = user_args.host if not host: host = get_default_host() client = ThriftClient.ThriftClient(host) # Perform a GetRadarHDF5Request req = GetRadarDataRecordRequest() req.setRadarId(radar) req.setPrimaryElevationAngle(float(angle)) req.setTimeRange(timerange) req.setProductCode(int(code)) response = client.sendRequest(req) if response is None: # print "Data not available" return records = response.getData() return records
def constructTimeRange(*args): """ Builds a python dynamicserialize TimeRange object from the given arguments. :param args*: must be a TimeRange or a pair of objects that can be converted to a datetime via convertToDateTime(). :returns: A TimeRange. """ if len(args) == 1 and isinstance(args[0], TimeRange): return args[0] if len(args) != 2: raise TypeError("constructTimeRange takes exactly 2 arguments, " + str(len(args)) + " provided.") startTime = convertToDateTime(args[0]) endTime = convertToDateTime(args[1]) return TimeRange(startTime, endTime)
def getStationData(self): """ Sends ThriftClient request and writes out received files.""" dtime = datetime.strptime(self.refTime, "%y%m%d/%H%M") trange = TimeRange() trange.setStart(dtime) trange.setEnd(dtime) dataTime = DataTime(refTime=dtime, validPeriod=trange) req = StationDataRequest() req.setPluginName(self.pluginName) req.setStationId(self.stationId) req.setRefTime(dataTime) req.setParmList(self.parmList) req.setPartNumber(self.partNumber) resp = self.client.sendRequest(req) for i, rec in enumerate(resp): resp[i] = { key.decode() if isinstance(key, bytes) else key: val.decode() if isinstance(val, bytes) else val for key, val in rec.items() } return resp
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()
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()
def main(): user_args = get_args() if user_args.host: DataAccessLayer.changeEDEXHost(user_args.host) if (user_args.date and not user_args.time) or (user_args.time and not user_args.date): print >> sys.stderr, "date and time must be provided together" return # If a time range is provided, results will be filtered based on available times timeRange = None if user_args.date: midRange = datetime.strptime( user_args.date + " " + user_args.time, "%Y-%m-%d %H:%M") beginRange = midRange - timedelta(0, 60) endRange = midRange + timedelta(0, 60) timeRange = TimeRange(beginRange, endRange) req = create_request(user_args) if user_args.icao: if user_args.productCode: # retrieve available times and/or true or primary elevation angles if timeRange: tr = timeRange else: tr = None lines = set() if user_args.outputAngle: levels = DataAccessLayer.getAvailableLevels(req) for level in levels: line = "" req.setLevels(level) if user_args.outputDate: times = DataAccessLayer.getAvailableTimes(req) for time in times: if not tr or tr.contains(time.getValidPeriod()): line = str(time) + ".0" line += " " if user_args.outputAngle == "true": line += "%.1f"%level.getLeveltwovalue() else: line += "%.1f"%level.getLevelonevalue() lines.add(line) else: if not tr or data_in_time_range(req, tr): if user_args.outputAngle == "true": line = "%.1f"%level.getLeveltwovalue() else: line = "%.1f"%level.getLevelonevalue() lines.add(line) else : # just output time times = DataAccessLayer.getAvailableTimes(req) for time in times: if not tr or tr.contains(time.getValidPeriod()): lines.add(str(time) + ".0") msg = "\n".join(lines) else: #retrieve available product codes unfiltered = DataAccessLayer.getAvailableParameters(req) productCodes = [] for parameter in unfiltered: #filter to just productCodes if parameter.isdigit(): productCodes.append(parameter) if timeRange: unfiltered = productCodes productCodes = [] for productCode in unfiltered: req = create_request(user_args) req.setParameters(productCode) if data_in_time_range(req, timeRange): productCodes.append(productCode) msg = "\n".join(productCodes) else: # retrieve available icaos icaos = DataAccessLayer.getAvailableLocationNames(req) if timeRange: unfiltered = icaos icaos = [] for icao in unfiltered: req = create_request(user_args) req.addIdentifier("icao", icao) if data_in_time_range(req, timeRange): icaos.append(icao) msg = "\n".join(icaos) print msg.strip()
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()
def do_request(user_args): if user_args.host: DataAccessLayer.changeEDEXHost(user_args.host) srcId = user_args.srcId varAbrev = user_args.varAbrev if not srcId or not varAbrev: raise Exception("srcId or varAbrev not provided") return date = user_args.date hour = user_args.hour fcst = user_args.fcst if not date or not hour or not fcst: raise Exception("date, hour, or fcst not provided") return dt = datetime.strptime( str(date) + " " + str(hour) + ":00:00.0", "%Y-%m-%d %H:%M:%S.%f") # check for and build date range if necessary daterange = None if varAbrev.endswith("hr"): import re matches = re.findall(r'\d+', varAbrev) if matches: from datetime import timedelta hourRange = int(matches[-1]) endDate = dt + timedelta(hours=int(fcst)) beginDate = endDate - timedelta(hours=hourRange) daterange = TimeRange(beginDate, endDate) # convert hours to seconds because DataTime does the reverse time = DataTime(dt, int(fcst) * 3600, daterange) req = DataAccessLayer.newDataRequest("grid") req.setParameters(varAbrev) req.addIdentifier("info.datasetId", srcId) # To handle partial level matches, use identifiers instead of a Level. if user_args.lvlName is not None: req.addIdentifier("info.level.masterLevel.name", user_args.lvlName) if user_args.lvlOne is not None: req.addIdentifier("info.level.levelonevalue", numpy.float64(user_args.lvlOne)) if user_args.lvlTwo is not None: req.addIdentifier("info.level.leveltwovalue", numpy.float64(user_args.lvlTwo)) times = [time] # If fcst is 0, also query for times with FCST_USED flag if fcst == '0': time = DataTime(dt, int(fcst) * 3600, daterange) time.utilityFlags.add("FCST_USED") times.append(time) grids = DataAccessLayer.getGridData(req, times) if not grids: # print "Data not available" raise Exception("") grid = grids[0] rawData = grid.getRawData() yLen, xLen = rawData.shape return grid, xLen, yLen
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
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()
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()
def getTimeRange(self): if not self.timeRange: start = self.startTime / 1000.0 end = self.endTime / 1000.0 self.timeRange = TimeRange(start, end) return self.timeRange
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()
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()
def main(): user_args = get_args() if user_args.host: DataAccessLayer.changeEDEXHost(user_args.host) slop = user_args.slop dateTimeStr = user_args.datetime if not dateTimeStr: print >> sys.stderr, "DateTime not provided" return physicalElement = user_args.physical if not physicalElement: print >> sys.stderr, "PhysicalElement not provided" return sectorID = user_args.sector if not sectorID: print >> sys.stderr, "SectorID not provided" return creatingEntity = user_args.entity part = user_args.partition encoding = user_args.encoding dateTime = datetime.strptime(dateTimeStr, "%Y-%m-%d %H:%M") beginRange = dateTime - timedelta(0, slop) endRange = dateTime + timedelta(0, slop) timerange = TimeRange(beginRange, endRange) req = DataAccessLayer.newDataRequest("satellite") req.setParameters(physicalElement) req.setLocationNames(sectorID) if creatingEntity: req.addIdentifier("creatingEntity", creatingEntity) grids = DataAccessLayer.getGridData(req, timerange) if not grids: # print "Data not available" return grid = grids[0] data = grid.getRawData() myent = grid.getAttribute("creatingEntity") mytime = a2dafcommon.datatime_to_string(grid.getDataTime()) + ".0" if data is None or len(data) == 0: # print "No data." return data[numpy.isnan(data)] = 0 yLen, xLen = data.shape plus = " ghijklmnopqrstuvwxyz" minus = " GHIJKLMNOPQRSTUVWXYZ" limit = 10000000 if encoding == 1: limit = limit / 2 elif encoding == 0: limit = limit / 8 k = xLen * (yLen / 4) j = 0 nxy = yLen * xLen if part == "D": j = k + k + k elif part == "C": j = k + k nxy = j + k elif part == "B": j = k nxy = j + k elif part == "A" or nxy > limit: nxy = k msg = "" if part <= "A": msg += str(xLen) + " " + str(yLen) + " " msg += mytime + " " + myent + "\n" i = 0 kk = None while j < yLen: i = 0 kk = int(data[j, i]) if kk < 0: kk += 256 if encoding == 0: msg += str(kk) elif encoding == 1: msg += "%2.2x" % kk elif kk == 0: msg += "@" elif kk == 255: msg += "#" else: msg += "%2.2x" % kk i += 1 while i < xLen: k = int(data[j, i]) if k < 0: k += 256 if encoding == 0: msg += " " + str(k) elif encoding == 1: msg += "%2.2x" % k elif k == 0: msg += "@" elif k == 255: msg += "#" elif k == kk: msg += "." elif k > kk + 20 or k < kk - 20: msg += "%2.2x" % k elif k > kk: msg += plus[k - kk] else: msg += minus[kk - k] kk = k i += 1 msg += "\n" j += 1 print msg.strip()