Пример #1
0
def main(iargs=None):
    inps = cmd_line_parse(iargs)
    plt.switch_backend('Agg')  # Backend setting

    # Read data
    k = readfile.read_attribute(inps.file)['FILE_TYPE']
    if k == 'timeseries' and inps.dset and '_' in inps.dset:
        inps.ref_date, inps.dset = inps.dset.split('_')
    else:
        inps.ref_date = None

    data, atr = readfile.read(inps.file, datasetName=inps.dset)
    if k == 'timeseries' and inps.ref_date:
        data -= readfile.read(inps.file, datasetName=inps.ref_date)[0]

    # mask
    mask = pp.read_mask(inps.file,
                        mask_file=inps.mask_file,
                        datasetName=inps.dset,
                        print_msg=True)[0]
    if mask is not None:
        data = np.ma.masked_where(mask == 0., data)
    if inps.zero_mask:
        print('masking pixels with zero value')
        data = np.ma.masked_where(data == 0., data)

    # Data Operation - Display Unit & Rewrapping
    (data, inps.disp_unit, inps.disp_scale,
     inps.wrap) = pp.scale_data4disp_unit_and_rewrap(
         data,
         metadata=atr,
         disp_unit=inps.disp_unit,
         wrap=inps.wrap,
         wrap_range=inps.wrap_range)
    if inps.wrap:
        inps.vlim = inps.wrap_range

    # Output filename
    inps.fig_title = pp.auto_figure_title(inps.file,
                                          datasetNames=inps.dset,
                                          inps_dict=vars(inps))
    if not inps.outfile:
        inps.outfile = '{}.kmz'.format(inps.fig_title)
    inps.outfile = os.path.abspath(inps.outfile)

    # 2. Generate Google Earth KMZ
    write_kmz_file(data, metadata=atr, out_file=inps.outfile, inps=inps)
    return inps.outfile
Пример #2
0
def main(iargs=None):
    inps = cmd_line_parse(iargs)
    plt.switch_backend('Agg')  # Backend setting

    # Read data
    data, atr = readfile.read(inps.file, datasetName=inps.dset)

    # mask
    mask = pp.read_mask(inps.file, mask_file=inps.mask_file, datasetName=inps.dset, print_msg=True)[0]
    if mask is not None:
        data = np.ma.masked_where(mask == 0., data)

    # Data Operation - Display Unit & Rewrapping
    (data,
     inps.disp_unit,
     inps.disp_scale,
     inps.wrap) = pp.scale_data4disp_unit_and_rewrap(data,
                                                     metadata=atr,
                                                     disp_unit=inps.disp_unit,
                                                     wrap=inps.wrap,
                                                     wrap_range=inps.wrap_range)
    if inps.wrap:
        inps.vlim = inps.wrap_range

    # Output filename
    inps.fig_title = pp.auto_figure_title(inps.file,
                                          datasetNames=inps.dset,
                                          inps_dict=vars(inps))
    if not inps.outfile:
        inps.outfile = '{}.kmz'.format(inps.fig_title)
    inps.outfile = os.path.abspath(inps.outfile)

    # 2. Generate Google Earth KMZ
    write_kmz_file(data,
                   metadata=atr,
                   out_file=inps.outfile,
                   inps=inps)
    return inps.outfile
Пример #3
0
def update_data_with_plot_inps(data, metadata, inps):
    # Seed Point
    if inps.ref_yx:  # and inps.ref_yx != [int(metadata['REF_Y']), int(metadata['REF_X'])]:
        try:
            ref_y = inps.ref_yx[0] - inps.pix_box[1]
            ref_x = inps.ref_yx[1] - inps.pix_box[0]
        except:
            pass
        if len(data.shape) == 2:
            data -= data[ref_y, ref_x]
        elif len(data.shape) == 3:
            data -= np.tile(data[:, ref_y, ref_x].reshape(-1, 1, 1),
                            (1, data.shape[1], data.shape[2]))
        vprint('set reference pixel to: {}'.format(inps.ref_yx))
    else:
        inps.ref_yx = None

    # Convert data to display unit and wrap
    (data, inps.disp_unit, inps.disp_scale,
     inps.wrap) = pp.scale_data4disp_unit_and_rewrap(
         data,
         metadata=metadata,
         disp_unit=inps.disp_unit,
         wrap=inps.wrap,
         wrap_range=inps.wrap_range,
         print_msg=inps.print_msg)
    if inps.wrap:
        inps.vlim = inps.wrap_range

    # 1.6 Min / Max - Data/Display
    inps.dlim = [np.nanmin(data), np.nanmax(data)]
    if not inps.vlim:  # and data.ndim < 3:
        inps.vlim = [np.nanmin(data), np.nanmax(data)]
    vprint('data    range: {} {}'.format(inps.dlim, inps.disp_unit))
    vprint('display range: {} {}'.format(inps.vlim, inps.disp_unit))

    return data, inps
Пример #4
0
def main(iargs=None):
    inps = cmd_line_parse(iargs)

    # 1. Read metadata and data
    k = readfile.read_attribute(inps.file)['FILE_TYPE']
    if k == 'timeseries' and inps.dset and '_' in inps.dset:
        inps.ref_date, inps.dset = inps.dset.split('_')
    else:
        inps.ref_date = None
    atr = readfile.read_attribute(inps.file, datasetName=inps.dset)

    # pix_box
    inps.pix_box = subset.subset_input_dict2box(vars(inps), atr)[0]
    inps.pix_box = ut.coordinate(atr).check_box_within_data_coverage(
        inps.pix_box)
    data_box = (0, 0, int(atr['WIDTH']), int(atr['LENGTH']))
    print('data   coverage in y/x: {}'.format(data_box))
    print('subset coverage in y/x: {}'.format(inps.pix_box))
    atr = attr.update_attribute4subset(atr, inps.pix_box)

    # read data
    data = readfile.read(inps.file, datasetName=inps.dset, box=inps.pix_box)[0]
    if k == 'timeseries' and inps.ref_date:
        data -= readfile.read(inps.file,
                              datasetName=inps.ref_date,
                              box=inps.pix_box)[0]

    # mask
    mask = pp.read_mask(inps.file,
                        mask_file=inps.mask_file,
                        datasetName=inps.dset,
                        box=inps.pix_box)[0]
    if mask is not None:
        print('masking out pixels with zero value in file: {}'.format(
            inps.mask_file))
        data[mask == 0] = np.nan
    if inps.zero_mask:
        print('masking out pixels with zero value')
        data[data == 0] = np.nan
    del mask

    # Data Operation - Display Unit & Rewrapping
    (data, inps.disp_unit, inps.disp_scale,
     inps.wrap) = pp.scale_data4disp_unit_and_rewrap(
         data,
         metadata=atr,
         disp_unit=inps.disp_unit,
         wrap=inps.wrap,
         wrap_range=inps.wrap_range)
    if inps.wrap:
        inps.vlim = inps.wrap_range

    # 2. Generate Google Earth KMZ
    # 2.1 Common settings
    # disp min/max and colormap
    cmap_lut = 256
    if not inps.vlim:
        cmap_lut, inps.vlim = pp.auto_adjust_colormap_lut_and_disp_limit(data)
    inps.colormap = pp.auto_colormap_name(atr, inps.colormap)
    inps.colormap = pp.ColormapExt(inps.colormap, cmap_lut).colormap
    inps.norm = colors.Normalize(vmin=inps.vlim[0], vmax=inps.vlim[1])

    # Output filename
    inps.fig_title = pp.auto_figure_title(inps.file,
                                          datasetNames=inps.dset,
                                          inps_dict=vars(inps))
    if not inps.outfile:
        inps.outfile = '{}.kmz'.format(inps.fig_title)
    inps.outfile = os.path.abspath(inps.outfile)

    # 2.2 Write KMZ file
    if 'Y_FIRST' in atr.keys():
        # create ground overlay KML for file in geo-coord
        write_kmz_overlay(
            data,
            meta=atr,
            out_file=inps.outfile,
            inps=inps,
        )

    else:
        # create placemark KML for file in radar-coord
        write_kmz_placemark(
            data,
            meta=atr,
            out_file=inps.outfile,
            geom_file=inps.geom_file,
            inps=inps,
        )

    return inps.outfile