index
Objects
TileMetadata
@dataclass
class TileMetadata()
Tile Metadata necessary for DynamoDB record
Arguments:
tilestr | gdal.Dataset - input tile.
Attributes:
affineAffine | List[Decimal] - an Affine transformation matrix.boundsList[float] | List[Decimal] - outer bounds of thetile.crsint - input EPSG code.epsgint - tile EPSG code.origin_xDecimal | float - origin value on the x-axis.origin_yDecimal | float - origin value on the y-axis.resolutionDecimal | float - resolution valuetile_sizeDecimal | float - loaded from source.
generate_decimals
def generate_decimals(attr: str)
Convert floats into Decimals for DynamoDB
Arguments:
attrstr - name of this class' attribute.
set_all_decimals
def set_all_decimals()
Loops through all possible attributes to convert to Decimal.
BaseInput
@dataclass
class BaseInput()
Input for running the main lambda handler.
Attributes:
crsint | str - input EPSG code.job_idstr - Job ID.schemastr | gdal.Dataset - input grid from the tile bounds lambda.block_idint, optional - specific ID of a polygon. Used to make output unique.clipbool - Crop tiles based on input inpolygon. Defaults to falseoutput_keystr, optional - object path to output directory.output_formatstr - output image format. Defaults to "GTiff".polygonstr, optional - input polygon to clip on withclip:True. Withoutclipit will just perform an intersect.prefixstr, optional - prefix object path to raster data.resolutionfloat | str, optional - "source" fixes resolution on source data resolution. Any number will overwrite the resolution in meters.target_bucketstr, optional - overwrite the output bucket whereoutput_keywill be written.
SimpleInput
@dataclass
class SimpleInput()
Input for running the simplified lambda handler.
Attributes:
job_idstr - Job ID.tilestr | gdal.Dataset - input tile.bucketstr, optional - bucket to search for source data. Defaults to SOURCE_BUCKET.forcebool - switch to negate uniqueness created byjob_id. This can be used to force tile creation regardless. Defaults to False.output_formatstr - output image format. Defaults to "GTiff".output_keystr, optional - object path to output directory.resolutionfloat | str, optional - "source" fixes resolution on source data resolution. Any number will overwrite the resolution in meters.target_bucketstr, optional - overwrite the output bucket whereoutput_keywill be written. Defaults to TARGET_BUCKET.tile_outputstr, optional - override the output tile name.uploadbool - use this switch to have the lambda write thetile_outputto thetarget_bucketandoutput_key. Set this toFalseto just generate tile records in DynamoDB. Defaults to True.
Raises:
NotImplementedError- raised when the input resolution is unexpected.
get_source_file
def get_source_file() -> str
Wrapper around GDAL API to get original filename back.
Returns:
str- the filename of thegdal.Dataset
Functions
get_tiff_affine
def get_tiff_affine(file_src: gdal.Dataset | str) -> Affine
Generate Affine matrix from GDAL object
Arguments:
file_srcgdal.Dataset | str - source raster data
Returns:
Affine- Affine matrix
create_tile_item
def create_tile_item(job_id: str, image_id: str, source_key: str,
output_key: str, metadata: TileMetadata)
Create a reference in DynamoDB. Basically a wrapper for create_item().
Arguments:
job_idstr - input job IDimage_idstr - input image_id/namesource_keystr - file path to source dataoutput_keystr - file path to output datametadataTileMetadata - metadata of raster data
lambda_handler
@tracer.capture_lambda_handler
@logger.inject_lambda_context()
def lambda_handler(event: dict, context: dict) -> None
Function used to crop RGB data on polygons for Inference data preperation.
Arguments:
eventdict - should fit the BaseInput.contextdict - lambda context object.
Examples:
{
"schema": "path/to/the/tilescheme.geojson",
"crs": 3118,
"output_key": "path/to/some/output/directory/",
"output_format": "GTiff",
"polygon": "POLYGON((1008415.8843999999 1148875.7007999998,1008419.7657000003 1148879.1108,1008416.2456 1148875.8717,1008415.8843999999 1148875.7007999998))",
"prefix": "path/to/the/raster/data/",
"resolution": "source",
"target_bucket": "some-bucket"
}
simple_handler
def simple_handler(event: dict, context: dict) -> None
Function handles a simple tile preparation for inference
Arguments:
eventdict - should fit the SimpleInput.contextdict - lambda context object
Raises:
ReferenceError- raised whenjob_idisn't available.NotImplementedError- add aresolutionin the allowed pathways.
Examples:
{
"job_id": "28934hf934-1337-9823hd234gf8334f34qf",
"tile": "some-tile-0-0.tiff",
"bucket": "some-bucket",
"force": false,
"output_format": "GTiff",
"output_key": "some/output/object/path/",
"resolution": 0.4,
"target_bucket": "some-bucket-too",
"tile_output": "some-output-0-0.tiff",
"upload": true
}