def process_NEXRAD(start_hour, end_hour, csv=False):
    # start_hour = datetime(2015, 06, 2, 12, 0, 0)
    # end_hour = datetime(2015, 06, 2, 13, 0, 0)
    td = timedelta(hours=1)

    while start_hour < end_hour:

        for i, site in enumerate(radars):

            # Setup output directories
            image_dir = "%s/images/%s/%s" % (os.getcwd(), site, start_hour.strftime("%Y%m%d"))
            csv_dir = "%s/csv_vad/%s/%s" % (os.getcwd(), site, start_hour.strftime("%Y%m%d"))

            if not os.path.isdir(image_dir):
                os.makedirs(image_dir)

            if not os.path.isdir(csv_dir):
                os.makedirs(csv_dir)

            d = 'D:\\TMBell\\projects\\VADAnalysis\\data\\%s\\raw\\%s' % (site, start_hour.strftime("%Y%m%d"))
            file_glob = "%s%s" % (site, start_hour.strftime("%Y%m%d_%H*"))
            in_files = glob(os.path.join(d, file_glob))

            for in_file in in_files:
                logging.info(in_file)

                try:
                    # Read in the file and dealias
                    radar = io.nexrad_archive.read_nexrad_archive(in_file)
                    logging.info("Dealiasing %s using PyART package..." % in_file)
                    VEL2 = correct.dealias_unwrap_phase(radar)
                    radar.add_field('VEL2', VEL2)

                    # Get some parameters
                    time = datetime_from_radar(radar)
                    time_str = "%s_%s" % (site, time.strftime("%Y%m%d_%H%M%S"))
                    elevs = utils.get_elevs(radar)
                    radar_elev = radar.altitude['data'][0]

                    # print "Trying 'our' method"
                    plt.figure(1, figsize=(15, 7))
                    our_u, our_v, hgt, gates = vad.get_uv_vs_hgt(radar, 'VEL2')
                    our_RMSE = utils.calc_RMSE(radar, 'VEL2', our_u, our_v)
                    display.u_v_rmse_plot(our_u, our_v, our_RMSE, hgt, title=time_str, elevs=elevs, radar_elev=radar_elev)

                    img_name = "%s_%s" % (time_str, 'fig1')
                    plt.savefig(os.path.join(image_dir, img_name))
                    plt.clf()

                    if csv:
                        csv_name = time_str + ".csv"
                        csv_name = os.path.join(csv_dir, csv_name)
                        logging.info("Exporting VAD as CSV: " + csv_name)
                        vad_csv.vad_to_csv(csv_name, site, radar, our_u, our_v, our_RMSE, hgt, elevs)

                except IOError:
                    logging.warning("Error Reading NEXRAD lvlII file: " + str(in_file))
                except KeyError, e:
                    logging.warning("Key not found " + str(e))
                except Exception, e:
                    logging.warning(e)
示例#2
0
def process_SR(in_dir, image_dir, csv=None):
    # image_dir = "/Users/tbupper90/Desktop/NEXRAD_BLISS/VADAnalysis/images/SR1_test/"

    if not os.path.isdir(image_dir):
        os.makedirs(image_dir)

    """
    """
    # d = '/Users/tbupper90/Desktop/NEXRAD_BLISS/data/SR1/pecan/SR1/20150619/corrected/'
    # d = '/Users/tbupper90/Desktop/NEXRAD_BLISS/data/SR1/pecan/SR1/20150619/corr2/'
    in_files = glob(os.path.join(in_dir, "*"))

    for in_file in in_files:
        print in_file

        try:
            radar = io.read_cfradial(in_file)
            # print "Dealiasing Radar using PyART package..."
            # VEL2 = correct.dealias_unwrap_phase(radar)
            # radar.add_field('VEL2', VEL2)

            # Get some parameters
            time = datetime_from_radar(radar)
            time_str = "SR2_%s" % (time.strftime("%Y%m%d_%H%M%S"))
            elevs = utils.get_elevs(radar)
            radar_elev = radar.altitude['data'][0]

            # Mask out the sector where the cab blocks the beam
            radar = utils.mask_sector(radar, 'VEL2', 250, 290)

            # plt.figure(111)
            # display.plot_velocity(radar, 'VEL2', sweep_number=3)
            # img_name = "%s_%s" % (time_str, 'fig2')
            # plt.savefig(os.path.join(image_dir, img_name))
            # plt.clf()

            print "Trying 'our' method"
            plt.figure(1, figsize=(15, 7))
            our_u, our_v, hgt, gates = vad.get_uv_vs_hgt(radar, 'VEL2')
            our_RMSE = utils.calc_RMSE(radar, 'VEL2', our_u, our_v)
            display.u_v_rmse_plot(our_u, our_v, our_RMSE, hgt, title="'Our' Method -- " + time_str, elevs=elevs,
                                  radar_elev=radar_elev)

            img_name = "%s_%s" % (time_str, 'fig1')
            plt.savefig(os.path.join(image_dir, img_name))
            plt.clf()

            if csv is True:
                csv_dir = 'D:\\TMBell\\projects\\VADAnalysis\\csv_vad2\\SR2\\{0}'
                csv_dir = csv_dir.format(time.strftime('%Y%m%d'))
                csv_name = time_str + ".csv"
                csv_name = os.path.join(csv_dir, csv_name)

                if not os.path.isdir(csv_dir): os.makedirs(csv_dir)
                vad_csv.vad_to_csv(csv_name, 'SR2', radar, our_u, our_v, our_RMSE, hgt, elevs)


        except IOError:
            print "Error Reading file"
        except KeyError, e:
            print "Key not found " + str(e)