Exemplo n.º 1
0
def multipanel(filename, outdir, dpi=100, verbose=False):
    """
    """

    # Set figure parameters
    rcParams['font.size'] = 14
    rcParams['font.weight'] = 'bold'
    rcParams['axes.titlesize'] = 14
    rcParams['axes.titleweight'] = 'bold'
    rcParams['axes.labelsize'] = 14
    rcParams['axes.labelweight'] = 'bold'
    rcParams['axes.linewidth'] = 1.5
    rcParams['xtick.major.size'] = 4
    rcParams['xtick.major.width'] = 1
    rcParams['xtick.minor.size'] = 2
    rcParams['xtick.minor.width'] = 1
    rcParams['ytick.major.size'] = 4
    rcParams['ytick.major.width'] = 1
    rcParams['ytick.minor.size'] = 2
    rcParams['ytick.minor.width'] = 1

    # Read radar data
    radar = read_cfradial(filename, exclude_fields=EXCLUDE_FIELDS)

    if verbose:
        print 'Plotting file: {}'.format(os.path.basename(filename))

    for i, hour in enumerate(HOURS):

        subs = {'xlim': (0, 60), 'ylim': (0, 14)}
        figs = {'figsize': (28, 20)}
        fig, ax = plt.subplots(nrows=4, ncols=2, subplot_kw=subs, **figs)
        plt.subplots_adjust(wspace=0.05, hspace=0.3)

        if verbose:
            print 'Plotting hour: {:02d}'.format(hour)

        # (a) Raw reflectivity (co-polar)
        _pcolormesh(
            radar, REFL_FIELD, hour=hour, cmap=REFL_CMAP, norm=REFL_NORM,
            ticks=REFL_TICKS, fig=fig, ax=ax[0,0])

        # (b) Raw Doppler velocity (co-polar)
        _pcolormesh(
            radar, VDOP_FIELD, hour=hour, cmap=VDOP_CMAP, norm=VDOP_NORM,
            ticks=VDOP_TICKS, fig=fig, ax=ax[0,1])

        # (c) Signal-to-noise ratio (co-polar)
        _pcolormesh(
            radar, SNR_FIELD, hour=hour, cmap=SNR_CMAP, norm=SNR_NORM,
            ticks=SNR_TICKS, fig=fig, ax=ax[1,0])

        # (d) Corrected Doppler velocity (co-polar)
        _pcolormesh(
            radar, CORR_VDOP_FIELD, hour=hour, cmap=VDOP_CMAP, norm=VDOP_NORM,
            ticks=VDOP_TICKS, fig=fig, ax=ax[1,1])

        # (e) Hildebrand noise mask
        _pcolormesh(
            radar, NOISE_FIELD, hour=hour, cmap=MASK_CMAP, norm=MASK_NORM,
            ticks=MASK_TICKS, fig=fig, ax=ax[2,0])

        # (f) Doppler velocity coherency mask
        _pcolormesh(
            radar, VDOP_COH_FIELD, hour=hour, cmap=MASK_CMAP, norm=MASK_NORM,
            ticks=MASK_TICKS, fig=fig, ax=ax[2,1])

        # (g) Radar significant detection mask
        _pcolormesh(
            radar, DETECT_FIELD, hour=hour, cmap=MASK_CMAP, norm=MASK_NORM,
            ticks=MASK_TICKS, fig=fig, ax=ax[3,0])

        # (h) Spectrum width (co-polar)
        _pcolormesh(
            radar, WIDTH_FIELD, hour=hour, cmap=WIDTH_CMAP, norm=WIDTH_NORM,
            ticks=WIDTH_TICKS, fig=fig, ax=ax[3,1])

        # Format axes
        for i, j in np.ndindex(ax.shape):
            ax[i,j].xaxis.set_major_locator(MultipleLocator(5))
            ax[i,j].xaxis.set_minor_locator(MultipleLocator(1))
            ax[i,j].yaxis.set_major_locator(MultipleLocator(1))
            ax[i,j].yaxis.set_minor_locator(MultipleLocator(0.5))
            ax[i,j].set_xlabel('Minutes of Hour {:02d} (UTC)'.format(hour))
            ax[i,j].set_ylabel('Height (km AGL)')
            ax[i,j].grid(which='major', axis='both')

        # Save image
        date = num2date(radar.time['data'][0], radar.time['units']).date()
        image = '{}.{:02d}0000.png'.format(date.strftime('%Y%m%d'), hour)
        fig.savefig(os.path.join(outdir, image), format='png', dpi=dpi,
                    bbox_inches='tight')
        plt.close(fig)

    return
Exemplo n.º 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)