Skip to main content

index

Objects

TileMetadata

@dataclass
class TileMetadata()

Tile Metadata necessary for DynamoDB record

Arguments:

  • tile str | gdal.Dataset - input tile.

Attributes:

  • affine Affine | List[Decimal] - an Affine transformation matrix.
  • bounds List[float] | List[Decimal] - outer bounds of the tile.
  • crs int - input EPSG code.
  • epsg int - tile EPSG code.
  • origin_x Decimal | float - origin value on the x-axis.
  • origin_y Decimal | float - origin value on the y-axis.
  • resolution Decimal | float - resolution value
  • tile_size Decimal | float - loaded from source.

generate_decimals

def generate_decimals(attr: str)

Convert floats into Decimals for DynamoDB

Arguments:

  • attr str - 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:

  • crs int | str - input EPSG code.
  • job_id str - Job ID.
  • schema str | gdal.Dataset - input grid from the tile bounds lambda.
  • block_id int, optional - specific ID of a polygon. Used to make output unique.
  • clip bool - Crop tiles based on input in polygon. Defaults to false
  • output_key str, optional - object path to output directory.
  • output_format str - output image format. Defaults to "GTiff".
  • polygon str, optional - input polygon to clip on with clip: True. Without clip it will just perform an intersect.
  • prefix str, optional - prefix object path to raster data.
  • resolution float | str, optional - "source" fixes resolution on source data resolution. Any number will overwrite the resolution in meters.
  • target_bucket str, optional - overwrite the output bucket where output_key will be written.

SimpleInput

@dataclass
class SimpleInput()

Input for running the simplified lambda handler.

Attributes:

  • job_id str - Job ID.
  • tile str | gdal.Dataset - input tile.
  • bucket str, optional - bucket to search for source data. Defaults to SOURCE_BUCKET.
  • force bool - switch to negate uniqueness created by job_id. This can be used to force tile creation regardless. Defaults to False.
  • output_format str - output image format. Defaults to "GTiff".
  • output_key str, optional - object path to output directory.
  • resolution float | str, optional - "source" fixes resolution on source data resolution. Any number will overwrite the resolution in meters.
  • target_bucket str, optional - overwrite the output bucket where output_key will be written. Defaults to TARGET_BUCKET.
  • tile_output str, optional - override the output tile name.
  • upload bool - use this switch to have the lambda write the tile_output to the target_bucket and output_key. Set this to False to 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 the gdal.Dataset

Functions

get_tiff_affine

def get_tiff_affine(file_src: gdal.Dataset | str) -> Affine

Generate Affine matrix from GDAL object

Arguments:

  • file_src gdal.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_id str - input job ID
  • image_id str - input image_id/name
  • source_key str - file path to source data
  • output_key str - file path to output data
  • metadata TileMetadata - 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:

  • event dict - should fit the BaseInput.
  • context dict - 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:

  • event dict - should fit the SimpleInput.
  • context dict - lambda context object

Raises:

  • ReferenceError - raised when job_id isn't available.
  • NotImplementedError - add a resolution in 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
}