Ejemplo n.º 1
0
def main():
    # setup logging
    logging.basicConfig(filename='bulk_clipper.log',
                        filemode='w',
                        level=logging.INFO)
    start_date = datetime.utcnow()
    logging.info(
        f'start process at {start_date} from command {" ".join(sys.argv[:])}')
    args = parse_args(sys.argv[1:])
    # get the input path and data file list
    input_path = Path(args.input_path)
    data_files = get_file_list(input_dir=input_path,
                               files=args.data_files,
                               glob_pattern=args.glob_pattern)
    # If tif out specified, look for a reference tif
    if args.write_tifs and not args.ref_file:
        if 'tif' not in args.mask_file.lower():
            input_tifs = locate_tifs(data_files)
            if len(input_tifs) < 1:
                raise Exception(
                    'Must include at least one geotif input or a ref_file when tif_outs is selected'
                )
    if args.mask_file:
        mask_clip(args.mask_file, data_files, args.out_dir, args.write_pfbs,
                  args.write_tifs)
    elif args.bbox_file:
        box_clip(file_io_tools.read_bbox(args.bbox_file), data_files,
                 args.out_dir, args.write_pfbs, args.write_tifs)
    elif args.bbox_def:
        box_clip(args.bbox_def, data_files, args.out_dir, args.write_pfbs,
                 args.write_tifs)
    end_date = datetime.utcnow()
    logging.info(
        f'completed process at {end_date} for a runtime of {end_date-start_date}'
    )
Ejemplo n.º 2
0
 def test_conus1_raster_defaults(self):
     rasterize_shape.rasterize_shape(input_path=self.good_shape_file_path, shapefile=self.good_shape_file_name,
                                     ref_file=test_files.conus1_mask)
     ref_mask = read_file(test_files.huc10190004.get('conus1_mask'))
     ref_bbox = test_files.huc10190004.get('conus1_bbox')
     self.assertSequenceEqual(ref_bbox, read_bbox('bbox.txt'))
     self.assertIsNone(np.testing.assert_array_equal(ref_mask, read_file('WBDHU8.tif')))
     self.assertIsNone(os.remove('bbox.txt'))
     self.assertIsNone(os.remove('WBDHU8.tif'))
Ejemplo n.º 3
0
    def test_subset_tif_conus2(self):
        data_array = file_io_tools.read_file(test_files.conus2_dem.as_posix())
        my_mask = SubsetMask(
            test_files.huc10190004.get('conus2_mask').as_posix())
        clipper = MaskClipper(subset_mask=my_mask, no_data_threshold=-1)
        return_arr, new_geom, new_mask, bbox = clipper.subset(data_array)
        file_io_tools.write_array_to_geotiff("conus_2_clip_dem_test.tif",
                                             return_arr, new_geom,
                                             my_mask.mask_tif.GetProjection())
        self.assertIsNone(
            np.testing.assert_array_equal(
                file_io_tools.read_file(
                    test_files.huc10190004.get('conus2_dem').as_posix()),
                file_io_tools.read_file('conus_2_clip_dem_test.tif')),
            'Clipping DEM matches reference')
        os.remove('conus_2_clip_dem_test.tif')

        file_io_tools.write_bbox(bbox, 'bbox_conus2_full.txt')
        self.assertSequenceEqual(
            file_io_tools.read_bbox('bbox_conus2_full.txt'),
            test_files.huc10190004.get('conus2_bbox'),
            'Subset writes correct bounding box file')
        os.remove('bbox_conus2_full.txt')
Ejemplo n.º 4
0
 def test_write_read_bbox(self):
     bbox = [10, 15, 20, 25]
     file_io_tools.write_bbox(bbox, 'bbox_test.txt')
     self.assertSequenceEqual(bbox, file_io_tools.read_bbox('bbox_test.txt'),
                              'writing and reading a bbox does not change values')
     os.remove('bbox_test.txt')