def create_geotiff_image(tif_path, sourceuri, filename=None, visibility=Visibility.PRIVATE, imageMetadata={}, scene=None, owner=None, band_create_function=create_geotiff_bands): """Create an Image object from a GeoTIFF. Args: tif_path (str): Local path to tif file sourceuri (str): remote source of image visibility (str): accessibility level for object imageMetadata (dict): Optional dict of metadata about the image scene (Scene): Optional Scene object holding this image owner (str): Optional owner of an image band_create_function (function): function to aid in creating bands for a geotiff """ filename = filename if filename else os.path.basename(tif_path) return Image( get_geotiff_size_bytes(tif_path), visibility, filename, sourceuri, band_create_function(tif_path), imageMetadata, # TIFFs can have a different resolution in the X and Y directions, that is, pixels can be # rectangular with respect to the ground. The RF API doesn't currently support this, so just # select the X resolution. get_geotiff_resolution(tif_path)[0], [], scene=scene, owner=owner)
def make_tif_image_copy(image): """Translate an images jp2 file to tif and return a copy Args: image (Image): image to copy data from Return: Image: the image copy """ copied = Image.from_dict(image.to_dict()) copied.sourceUri = process_jp2000(image.scene, image.sourceUri) return copied
def create_images(scene_id, landsat_id, resolution, bands): """Creates images based on scene_id. Created image is a python representation of the Image.Create case class in the scala datamodel Args: scene_id (str) id of the scene (e.g. LC81351172016273LGN00) Returns: List[Image] """ s3_dir_path = get_landsat_url(landsat_id) def usgs_band_no(band): """Helper to get USGS's band number from a band object""" return band.name.split(' - ')[1] tif_paths_with_bands = [ ('{scene}_B{band}.TIF'.format(scene=landsat_id, band=usgs_band_no(band)), band) for band in bands ] def size_from_path(tif_path, landsat_id=landsat_id): """Get the size of a tif in s3""" logger.info("Getting object size for path: %s", get_landsat_path(landsat_id) + tif_path) s3_obj = s3.Object(bucket.name, get_landsat_path(landsat_id) + tif_path) return s3_obj.content_length return [ Image(organization, size_from_path(tif_path), Visibility.PUBLIC, tif_path, ''.join([s3_dir_path, tif_path]), [band], {}, resolution, [], scene_id) for tif_path, band in tif_paths_with_bands ]
def image_from_key(key): """Return Image based on s3 key Args: key (s3.Object): s3 object representation of an image Returns: Image """ filename = key.key.split("/")[-1] image_band = filename.split('.')[0] return Image( organization, key.content_length, Visibility.PUBLIC, filename, base_http_path.format(key_path=key.key), create_bands(image_band), {}, resolution, [], scene_id )