Beispiel #1
0
def vad_json(radar_id,
             vwp_time=None,
             file_id=None,
             local_path=None,
             output='.',
             gzip=False):
    if local_path is None:
        vad = download_vad(radar_id, time=vwp_time, file_id=file_id)
    else:
        iname = build_has_name(radar_id, vwp_time)
        vad = VADFile(open("%s/%s" % (local_path, iname), 'rb'))

    output_dt = vad['time']

    vwp = {
        'radar_id': radar_id,
        'datetime': output_dt.strftime("%Y-%m-%dT%H:%M:%SZ"),
        'data': {
            var: list(vad[var])
            for var in ['wind_dir', 'wind_spd', 'altitude', 'rms_error']
        },
    }

    #   out_fname = f'{output}/{radar_id}_{output_dt:%Y%m%d_%H%M}.json'
    out_fname = f'{output}/{radar_id}_{file_id:04d}.json'
    if gzip:
        out_fname = f'{out_fname}.gz'
        with gzip.open(out_fname, 'wb') as fjson:
            fjson.write(json.dumps(vwp).encode('utf-8'))
    else:
        with open(out_fname, 'w') as fjson:
            fjson.write(json.dumps(vwp))

    output = {'filename': out_fname}
    print(json.dumps(output))
Beispiel #2
0
def vad_plotter(radar_id,
                storm_motion='right-mover',
                sfc_wind=None,
                time=None,
                fname=None,
                local_path=None,
                web=False,
                fixed=False):
    plot_time = None
    if time:
        plot_time = parse_time(time)
    elif local_path is not None:
        raise ValueError(
            "'-t' ('--time') argument is required when loading from the local disk."
        )

    if not web:
        print("Plotting VAD for %s ..." % radar_id)

    if local_path is None:
        vad = download_vad(radar_id, time=plot_time)
    else:

        iname = "%s/K%s%s_SDUS34_NVW%s_%s" % (local_path, radar_id[0][1:],
                                              nwswfos[radar_id], radar_id[1:],
                                              plot_time.strftime("%Y%m%d%H%M"))
        vad = VADFile(open(iname, 'rb'))

    vad.rid = radar_id

    if not web:
        print("Valid time:", vad['time'].strftime("%d %B %Y %H%M UTC"))

    if sfc_wind:
        sfc_wind = parse_vector(sfc_wind)
        vad.add_surface_wind(sfc_wind)

    params = compute_parameters(vad, storm_motion)
    plot_hodograph(vad,
                   params,
                   fname=fname,
                   web=web,
                   fixed=fixed,
                   archive=(local_path is not None))
Beispiel #3
0
def main():
    ap = argparse.ArgumentParser()
    ap.add_argument('radar_id', help="The 4-character identifier for the radar (e.g. KTLX, KFWS, etc.)")
    ap.add_argument('-m', dest='storm_motion', help="Storm motion vector. It takes one of two forms. The first is either 'BRM' for the Bunkers right mover vector, or 'BLM' for the Bunkers left mover vector. The second is the form DDD/SS, where DDD is the direction the storm is coming from, and SS is the speed in knots (e.g. 240/25).", default='right-mover')
    ap.add_argument('-s', dest='sfc_wind', help="Surface wind vector. It takes the form DDD/SS, where DDD is the direction the storm is coming from, and SS is the speed in knots (e.g. 240/25).")
    ap.add_argument('-t', dest='time', help="Time to plot. Takes the form DD/HHMM, where DD is the day, HH is the hour, and MM is the minute.")
    args = ap.parse_args()

    np.seterr(all='ignore')

    plot_time = None
    if args.time:
        now = datetime.utcnow()
        year = now.year
        month = now.month

        plot_time = datetime.strptime("%d %d %s" % (year, month, args.time), "%Y %m %d/%H%M")
        if plot_time > now:
            if month == 1:
                month = 12
                year -= 1
            else:
                month -= 1
            plot_time = datetime.strptime("%d %d %s" % (year, month, args.time), "%Y %m %d/%H%M")

    print "Plotting VAD for %s ..." % args.radar_id
    try:
        vad = download_vad(args.radar_id, time=plot_time)
    except ValueError as e:
        print e
        sys.exit()

    print "Valid time:", vad['time'].strftime("%d %B %Y %H%M UTC")

    if args.sfc_wind:
        sfc_wind = parse_vector(args.sfc_wind)
        vad.add_surface_wind(sfc_wind)

    params = compute_parameters(vad, args.storm_motion)
    plot_hodograph(vad, params)