def create_cog(image_locations, scene, same_path=False): """ Args: image_locations (List[(uri, filename)]): Used to fetch source imagery for the scene for processing scene (Scene): Scene to create COG from same_path (boolean): Output to the same path that it was downloaded from Returns: Scene: The mutated scene. Must call update() on it to be reflected on the API Raises: Exception: Any exceptions here are unrecoverable. """ with get_tempdir() as local_dir: dsts = [os.path.join(local_dir, fname) for _, fname in image_locations] cog.fetch_imagery(image_locations, local_dir) warped_paths = cog.warp_tifs(dsts, local_dir) merged_tif = cog.merge_tifs(warped_paths, local_dir) cog.add_overviews(merged_tif) cog_path = cog.convert_to_cog(merged_tif, local_dir) if same_path: updated_scene = upload_tif( cog_path, scene, os.path.join('user-uploads', scene.owner, '{}_COG.tif'.format(scene.id)), os.path.join('user-uploads', urllib.quote_plus(scene.owner), '{}_COG.tif'.format(scene.id)) ) else: updated_scene = upload_tif(cog_path, scene) os.remove(cog_path) return updated_scene
def create_cog(image_locations, scene): with get_tempdir() as local_dir: dsts = [os.path.join(local_dir, fname) for _, fname in image_locations] cog.fetch_imagery(image_locations, local_dir) warped_paths = cog.warp_tifs(dsts, local_dir) merged_tif = cog.merge_tifs(warped_paths, local_dir) cog.add_overviews(merged_tif) cog_path = cog.convert_to_cog(merged_tif, local_dir) updated_scene = upload_tif(cog_path, scene) updated_scene.update()
def process_to_cog(prefix, gcs_prefix, landsat_id, config): logger.info('Fetching all bands') for band in config.bands.keys(): fetch_band(prefix, gcs_prefix, band, landsat_id) cog_fname = '{}_COG.tif'.format(landsat_id) stacked_fname = '{}_STACKED.tif'.format(landsat_id) filenames = { 'COG': os.path.join(prefix, cog_fname), 'STACKED': os.path.join(prefix, stacked_fname) } local_paths = sorted(glob.glob('/{}/{}*.TIF'.format(prefix, landsat_id))) warped_paths = cog.warp_tifs(local_paths, prefix) merged = cog.merge_tifs(warped_paths, prefix) cog.add_overviews(merged) cog_path = cog.convert_to_cog(merged, prefix) shutil.move(cog_path, filenames['COG']) return (filenames['COG'], cog_fname)
def process_to_cog(prefix, gcs_prefix, landsat_id, config): logger.info('Fetching all bands') for band in config.bands.keys(): fetch_band(prefix, gcs_prefix, band, landsat_id) cog_fname = '{}_COG.tif'.format(landsat_id) stacked_fname = '{}_STACKED.tif'.format(landsat_id) filenames = { 'COG': os.path.join(prefix, cog_fname), 'STACKED': os.path.join(prefix, stacked_fname) } local_paths = sorted(glob.glob('{}/{}*.TIF'.format(prefix, landsat_id))) warped_paths = cog.warp_tifs(local_paths, prefix) merged = cog.merge_tifs(warped_paths, prefix) cog.add_overviews(merged) cog_path = cog.convert_to_cog(merged, prefix) shutil.move(cog_path, filenames['COG']) return (filenames['COG'], cog_fname)
def create_cog(image_locations, scene, same_path=False): with get_tempdir() as local_dir: dsts = [os.path.join(local_dir, fname) for _, fname in image_locations] cog.fetch_imagery(image_locations, local_dir) warped_paths = cog.warp_tifs(dsts, local_dir) merged_tif = cog.merge_tifs(warped_paths, local_dir) cog.add_overviews(merged_tif) cog_path = cog.convert_to_cog(merged_tif, local_dir) if same_path: updated_scene = upload_tif( cog_path, scene, os.path.join('user-uploads', scene.owner, '{}_COG.tif'.format(scene.id)), os.path.join('user-uploads', urllib.quote_plus(scene.owner), '{}_COG.tif'.format(scene.id)) ) else: updated_scene = upload_tif(cog_path, scene) updated_scene.update() os.remove(cog_path)
def create_cog(image_locations, scene, same_path=False): with get_tempdir() as local_dir: dsts = [os.path.join(local_dir, fname) for _, fname in image_locations] cog.fetch_imagery(image_locations, local_dir) warped_paths = cog.warp_tifs(dsts, local_dir) merged_tif = cog.merge_tifs(warped_paths, local_dir) cog.add_overviews(merged_tif) cog_path = cog.convert_to_cog(merged_tif, local_dir) if same_path: updated_scene = upload_tif( cog_path, scene, os.path.join('user-uploads', scene.owner, '{}_COG.tif'.format(scene.id)), os.path.join('user-uploads', urllib.quote_plus(scene.owner), '{}_COG.tif'.format(scene.id))) else: updated_scene = upload_tif(cog_path, scene) updated_scene.update() os.remove(cog_path)
def create_geotiffs(modis_path, local_dir): """Create geotiffs from MODIS HDF 1. Create separate tifs for each band 2. Combine tifs into a single tif 3. Warp tif to web mercator (for quicker access) 4. Generate COG Args: modis_path (str): path to modis HDF file local_dir (str): directory to output tiffs to """ logger.info('Preparing to create geotiffs') post_web_mercator_path = os.path.join(local_dir, 'warp2.tif') tifs = sorted(hdf_to_geotiffs(modis_path, local_dir)) logger.info('Tifs: %s', '\n'.join(tifs)) warped_paths = cog.warp_tifs(tifs, local_dir) merged_tif = cog.merge_tifs(warped_paths, local_dir) warp_tif(merged_tif, post_web_mercator_path) cog.add_overviews(post_web_mercator_path) cog_path = cog.convert_to_cog(post_web_mercator_path, local_dir) return [cog_path]
def create_geotiffs(modis_path, local_dir): """Create geotiffs from MODIS HDF 1. Create separate tifs for each band 2. Combine tifs into a single tif 3. Warp tif to web mercator (for quicker access) 4. Generate COG Args: modis_path (str): path to modis HDF file local_dir (str): directory to output tiffs to """ logger.info('Preparing to create geotiffs') post_web_mercator_path = os.path.join(local_dir, 'warp2.tif') tifs = sorted(hdf_to_geotiffs(modis_path, local_dir)) logger.info('Tifs: %s', '\n'.join(tifs)) warped_paths = cog.warp_tifs(tifs, local_dir) merged_tif = cog.merge_tifs(warped_paths, local_dir) warp_tif(merged_tif, post_web_mercator_path) cog.add_overviews(post_web_mercator_path) cog_path = cog.convert_to_cog(post_web_mercator_path, local_dir) return [cog_path]