def main():
    from argparse import ArgumentParser
    description = """
Plot binary files using matplotlib.
    """
    parser = ArgumentParser(description=description)
    parser.add_argument("scene_file", help="the data file to be sampled from")
    parser.add_argument("product_name", help="product in scene to inspect")
    parser.add_argument("lonVal", type=float, help="Specify the longitude to find a the point nearest")
    parser.add_argument("latVal", type=float, help="Specify the latitude  to find a the point nearest")

    args = parser.parse_args()
    
    # check what the user gave us on the command line
    if len(args.data_file) != 1 :
        print("Data file required for point selection. Skipping.")
    elif args.latVal is None or args.lonVal is None:
        print("Longitude and latitude to find must be selected. Skipping.")
    else:
        # if we got to here, we have the minimum we needed to try
        scene = SwathScene.load(args.scene_file)
        data = scene[args.product_name].get_data_array()
        swath_def = scene[args.product_name]["swath_definition"]
        lon_data = swath_def.get_longitude_array()
        lat_data = swath_def.get_longitude_array()

        value, lonPt, latPt = _find_nearest_data_pt(args.lonVal, args.latVal, lon_data, lat_data, data)
        
        print("Found data value %f at longitude %f and latitude %f" % (value, lonPt, latPt))
Beispiel #2
0
def main():
    from polar2grid.core.script_utils import create_basic_parser, create_exc_handler, setup_logging
    from polar2grid.core.containers import SwathScene
    parser = create_basic_parser(description="Remap a SwathScene to the provided grids")
    subgroup_titles = add_remap_argument_groups(parser)
    parser.add_argument("--scene", required=True,
                        help="JSON SwathScene filename to be remapped")
    parser.add_argument('-o', dest="output_filename", default="gridded_scene_{grid_name}.json",
                        help="Output filename for JSON scene (default is to 'gridded_scene_{grid_name}.json')")
    global_keywords = ("keep_intermediate", "overwrite_existing", "exit_on_error")
    args = parser.parse_args(subgroup_titles=subgroup_titles, global_keywords=global_keywords)

    levels = [logging.ERROR, logging.WARN, logging.INFO, logging.DEBUG]
    setup_logging(console_level=levels[min(3, args.verbosity)], log_filename=args.log_fn)
    sys.excepthook = create_exc_handler(LOG.name)
    LOG.debug("Starting script with arguments: %s", " ".join(sys.argv))

    if args.output_filename and args.output_filename != "-" and os.path.isfile(args.output_filename):
            LOG.error("JSON file '%s' already exists, will not overwrite." % (args.output_filename,))
            raise RuntimeError("JSON file '%s' already exists, will not overwrite." % (args.output_filename,))

    scene = SwathScene.load(args.scene)

    remapper = Remapper(**args.subgroup_args["Remapping Initialization"])
    remap_kwargs = args.subgroup_args["Remapping"]
    for grid_name in remap_kwargs.pop("forced_grids", ["wgs84_fit"]):
        gridded_scene = remapper.remap_scene(scene, grid_name, **remap_kwargs)
        if args.output_filename is None or args.output_filename == "-":
            print(gridded_scene.dumps(persist=True))
        else:
            fn = args.output_filename.format(grid_name=grid_name)
            LOG.info("Saving gridded scene to file: %s", fn)
            gridded_scene.save(fn)
Beispiel #3
0
def main():
    from polar2grid.core.script_utils import create_basic_parser, create_exc_handler, setup_logging
    from polar2grid.core.containers import SwathScene
    parser = create_basic_parser(description="Remap a SwathScene to the provided grids")
    subgroup_titles = add_remap_argument_groups(parser)
    parser.add_argument("--scene", required=True,
                        help="JSON SwathScene filename to be remapped")
    parser.add_argument('-o', dest="output_filename", default="gridded_scene_{grid_name}.json",
                        help="Output filename for JSON scene (default is to 'gridded_scene_{grid_name}.json')")
    global_keywords = ("keep_intermediate", "overwrite_existing", "exit_on_error")
    args = parser.parse_args(subgroup_titles=subgroup_titles, global_keywords=global_keywords)

    levels = [logging.ERROR, logging.WARN, logging.INFO, logging.DEBUG]
    setup_logging(console_level=levels[min(3, args.verbosity)], log_filename=args.log_fn)
    sys.excepthook = create_exc_handler(LOG.name)
    LOG.debug("Starting script with arguments: %s", " ".join(sys.argv))

    if args.output_filename and args.output_filename != "-" and os.path.isfile(args.output_filename):
            LOG.error("JSON file '%s' already exists, will not overwrite." % (args.output_filename,))
            raise RuntimeError("JSON file '%s' already exists, will not overwrite." % (args.output_filename,))

    scene = SwathScene.load(args.scene)

    remapper = Remapper(**args.subgroup_args["Remapping Initialization"])
    remap_kwargs = args.subgroup_args["Remapping"]
    for grid_name in remap_kwargs.pop("forced_grids", ["wgs84_fit"]):
        gridded_scene = remapper.remap_scene(scene, grid_name, **remap_kwargs)
        if args.output_filename is None or args.output_filename == "-":
            print(gridded_scene.dumps(persist=True))
        else:
            fn = args.output_filename.format(grid_name=grid_name)
            LOG.info("Saving gridded scene to file: %s", fn)
            gridded_scene.save(fn)
Beispiel #4
0
def main():
    from argparse import ArgumentParser
    description = """
Plot binary files using matplotlib.
    """
    parser = ArgumentParser(description=description)
    parser.add_argument("scene_file", help="the data file to be sampled from")
    parser.add_argument("product_name", help="product in scene to inspect")
    parser.add_argument(
        "lonVal",
        type=float,
        help="Specify the longitude to find a the point nearest")
    parser.add_argument(
        "latVal",
        type=float,
        help="Specify the latitude  to find a the point nearest")

    args = parser.parse_args()

    # check what the user gave us on the command line
    if len(args.data_file) != 1:
        print("Data file required for point selection. Skipping.")
    elif args.latVal is None or args.lonVal is None:
        print("Longitude and latitude to find must be selected. Skipping.")
    else:
        # if we got to here, we have the minimum we needed to try
        scene = SwathScene.load(args.scene_file)
        data = scene[args.product_name].get_data_array()
        swath_def = scene[args.product_name]["swath_definition"]
        lon_data = swath_def.get_longitude_array()
        lat_data = swath_def.get_longitude_array()

        value, lonPt, latPt = _find_nearest_data_pt(args.lonVal, args.latVal,
                                                    lon_data, lat_data, data)

        print("Found data value %f at longitude %f and latitude %f" %
              (value, lonPt, latPt))