Пример #1
0
def multipanel_V03(inpdir, outdir, stamp, dpi=100, verbose=False):
    """
    """
    files = [os.path.join(inpdir, f) for f in sorted(os.listdir(inpdir))
             if stamp in f]

    if verbose:
        print 'Number of files to plot = %i' % len(files)

    for f in files:

        # Parse input file
        radar = read_radx(f)

        # Check the number of sweeps are consistent with defined VCP
        if radar.nsweeps != VCP_SWEEPS:
            continue

        if verbose:
            print 'Currently plotting file %s' % os.path.basename(f)

        # Create figure instance
        subs = {'xlim': (-MAX_RANGE, MAX_RANGE),
                'ylim': (-MAX_RANGE, MAX_RANGE)}
        figs = {'figsize': (66, 24)}
        fig, ax = plt.subplots(
            nrows=3, ncols=len(SWEEPS), subplot_kw=subs, **figs)

        # Iterate over each sweep
        for j, sweep in enumerate(SWEEPS):

            # (a) Reflectivity
            qma = pcolormesh(
                radar, 'REF', sweep=sweep, cmap=cmap_refl, norm=norm_refl,
                ax=ax[0,j])

            # (b) Doppler velocity
            qmb = pcolormesh(
                radar, 'VEL', sweep=sweep, cmap=cmap_vdop, norm=norm_vdop,
                ax=ax[1,j])

            # (c) Spectrum width
            qmc = pcolormesh(
                radar, 'SW', sweep=sweep, cmap=cmap_sw, norm=norm_sw,
                ax=ax[2,j])

        # Format plot axes
        for i, j in np.ndindex(ax.shape):
            ax[i,j].xaxis.set_major_locator(MultipleLocator(50))
            ax[i,j].xaxis.set_minor_locator(MultipleLocator(10))
            ax[i,j].yaxis.set_major_locator(MultipleLocator(50))
            ax[i,j].yaxis.set_minor_locator(MultipleLocator(10))
            ax[i,j].set_xlabel('Eastward Range from Radar (km)')
            ax[i,j].set_ylabel('Northward Range from Radar (km)')
            ax[i,j].grid(which='major')

        # Color bars
        plt.colorbar(mappable=qma, cax=fig.add_axes([0.91, 0.68, 0.008, 0.2]),
                     ticks=ticks_refl)
        plt.colorbar(mappable=qmb, cax=fig.add_axes([0.91, 0.40, 0.008, 0.2]),
                     ticks=ticks_vdop)
        plt.colorbar(mappable=qmc, cax=fig.add_axes([0.91, 0.12, 0.008, 0.2]),
                     ticks=ticks_sw)

        # Save figure
        date_stamp = num2date(radar.time['data'][:].min(), radar.time['units'])
        filename = '{}.png'.format(date_stamp.strftime('%Y%m%d.%H%M%S'))
        fig.savefig(os.path.join(outdir, filename), format='png', dpi=dpi,
                    bbox_inches='tight')
        plt.close(fig)

    return
Пример #2
0
def process_file(filename, outdir, debug=False, verbose=False):
    """
    """

    # Read radar data
    if USE_RADX:
        radar = read_radx(filename)
    else:
        radar = read(filename, exclude_fields=None)

    # Radar VCP check
    if CHECK_VCP:
        if NSWEEPS is not None and radar.nsweeps != NSWEEPS:
            return

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

    if debug:
        print 'Number of sweeps: {}'.format(radar.nsweeps)

    if USE_RADX:
        # Create file metadata object
        meta = FileMetadata(
            'nexrad_archive', field_names=None, additional_metadata=None,
            file_field_names=False, exclude_fields=None)

        # Remove unnecessary fields
        for field in REMOVE_FIELDS:
            radar.fields.pop(field, None)

        # Rename fields to default Py-ART names
        for field in radar.fields.keys():
            default_field = meta.get_field_name(field)
            radar.fields[default_field] = radar.fields.pop(field, None)

    # Step 1: Determine radar significant detection
    # Since NEXRAD WSR-88D Level II data is already processed to some degree,
    # this amounts to essentially removing salt and pepper noise
    gf = noise._significant_features(
        radar, REFL_FIELD, gatefilter=None, size_bins=SIZE_BINS,
        size_limits=SIZE_LIMITS, structure=STRUCTURE, remove_size_field=False,
        fill_value=None, size_field=None, debug=debug)
    gf = noise.significant_detection(
        radar, gatefilter=gf, remove_small_features=False, size_bins=SIZE_BINS,
        size_limits=SIZE_LIMITS, fill_holes=FILL_HOLES, dilate=DILATE,
        structure=STRUCTURE, iterations=1, rays_wrap_around=False,
        min_ncp=None, detect_field=None, debug=debug, verbose=verbose)

    # Step 2: Doppler velocity correction
    if DEALIAS == 'phase':
        vdop_corr = dealias_unwrap_phase(
            radar, gatefilter=gf, unwrap_unit='sweep', nyquist_vel=None,
            rays_wrap_around=True, keep_original=False, vel_field=None,
            corr_vel_field=VDOP_CORR_FIELD)
    elif DEALIAS == 'region':
        vdop_corr = dealias_region_based(
            radar, gatefilter=gf, interval_splits=INTERVAL_SPLITS,
            interval_limits=None, skip_between_rays=2, skip_along_ray=2,
            centered=True, nyquist_vel=None, rays_wrap_around=True,
            keep_original=False, vel_field=None,
            corr_vel_field=VDOP_CORR_FIELD)
    else:
        raise ValueError('Unsupported velocity correction routine')

    radar.add_field(VDOP_CORR_FIELD, vdop_corr, replace_existing=True)

    # Step 3: Reflectivity correction
    # Currently no correction procedures are applied to the reflectivity field
    # due to minimal attenuation at S-band
    refl_corr = radar.fields[REFL_FIELD].copy()
    radar.add_field(REFL_CORR_FIELD, refl_corr, replace_existing=True)

    # Step 4: Interpolate missing gates
    basic_fixes.interpolate_missing(
        radar, fields=FILL_FIELDS, interp_window=FILL_WINDOW,
        interp_sample=FILL_SAMPLE, kind='mean', rays_wrap_around=False,
        fill_value=None, debug=debug, verbose=verbose)

    # Add metadata
    _add_metadata(radar, filename)

    # ARM file name protocols
    date_stamp = datetimes_from_radar(radar).min().strftime('%Y%m%d.%H%M%S')
    fname = 'nexradwsr88d{}cmac{}.{}.{}.cdf'.format(QF, FN, DL, date_stamp)

    # Write CMAC NetCDF file
    write_cfradial(os.path.join(outdir, fname), radar, format=FORMAT,
                   arm_time_variables=True)

    return