Download Utils Documentation
Documentation for the terrakit.download.geodata_utils module.
terrakit.download.geodata_utils
list_data_connectors(as_json: bool = False) -> Union[list, Dict[str, Any], Any]
List available data connectors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
as_json
|
bool
|
If True, return data connectors as a JSON object, otherwise return a list of connector names. |
False
|
Returns:
| Type | Description |
|---|---|
Union[list, Dict[str, Any], Any]
|
Union[list, Dict[str, Any], Any]: List of connector names or JSON object containing all connector specifications. |
Source code in terrakit/download/geodata_utils.py
load_and_list_collections(as_json: bool = False, connector_type: Union[str, None] = None) -> Union[list, Dict[str, Any]]
Load and list collections for a given data connector type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
as_json
|
bool
|
If True, return collection details as a JSON object, otherwise return a list of collection names. |
False
|
connector_type
|
str
|
The type of data connector to filter collections by. |
None
|
Returns:
| Type | Description |
|---|---|
Union[list, Dict[str, Any]]
|
Union[list, Dict[str, Any]]: List of collection names or JSON object containing collection specifications. |
Source code in terrakit/download/geodata_utils.py
check_bands(connector_type: str, collection_name: str, bands: list)
Check if the specified bands are available for a given collection and connector type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connector_type
|
str
|
The type of data connector. |
required |
collection_name
|
str
|
The name of the collection. |
required |
bands
|
list
|
List of band names to check. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
list |
Modified list of bands with any unavailable bands replaced by their alternative names if possible. |
Source code in terrakit/download/geodata_utils.py
polygon_to_bbox(polygon, buffer_size)
Convert a Shapely Polygon to a bounding box with a buffer zone.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
polygon
|
Polygon
|
The input polygon. |
required |
buffer_size
|
float
|
The size of the buffer zone in the same units as the polygon's CRS. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
list |
float
|
Bounding box [min_lon, min_lat, max_lon, max_lat] with buffer zone. |
Source code in terrakit/download/geodata_utils.py
calculate_resolution(meter_resolution, lat)
Calculate the spatial resolution in latitude and longitude for a given meter resolution at a specific latitude.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
meter_resolution
|
float
|
The desired resolution in meters. |
required |
lat
|
float
|
The latitude for which to calculate the resolution. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
(float, float)
|
Resolution in latitude and longitude. |
Source code in terrakit/download/geodata_utils.py
verify_input_image(image, standard_dimensions=224) -> typing.Tuple[int, str]
Verify input dimensions for supplied image
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
bytes
|
image |
required |
standard_dimensions
|
int
|
expected size of image |
224
|
Return
tuple[int, str]: [verification_status_code, verification_msg]
Source code in terrakit/download/geodata_utils.py
check_projection(file)
Check the projection is correct, if not reproject to EPSG:4326
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file
|
str
|
The path to the input file. |
required |
Returns:
| Type | Description |
|---|---|
|
None |
Source code in terrakit/download/geodata_utils.py
pad_bbox(padding_degrees, bbox)
Add padding to bounding box to help with edge artifacts. Args: padding_degrees (float): number of degrees to add as border to bbox bbox (list(float)): original bounding box [min_lon, min_lat, max_lon, max_lat] Return: padded_bbox (list(float)): bouning box with border of padding [min_lon, min_lat, max_lon, max_lat]
Source code in terrakit/download/geodata_utils.py
tile_bbox(aoi_size, bbox, resolution, tile_size_x=2200.0, tile_size_y=2200.0)
Tile a bounding box if it exceeds 2400 pixels in any dimension.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
aoi_size
|
tuple(float
|
The size of the area of interest [width, height]. |
required |
bbox
|
list(float
|
The original bounding box [min_lon, min_lat, max_lon, max_lat]. |
required |
resolution
|
float
|
The spatial resolution. |
required |
tile_size_x
|
float
|
The desired width of each tile. |
2200.0
|
tile_size_y
|
float
|
The desired height of each tile. |
2200.0
|
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
A tuple containing lists of tiled bounding boxes and their respective sizes. |
Source code in terrakit/download/geodata_utils.py
check_and_crop_bbox(bbox, resolution)
Check and crop a bounding box to ensure it fits within Sentinel Hub's processing limits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bbox
|
list(float
|
The original bounding box [min_lon, min_lat, max_lon, max_lat]. |
required |
resolution
|
float
|
The spatial resolution. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
A tuple containing the cropped bounding box and its size. |
Source code in terrakit/download/geodata_utils.py
save_data_array_to_file(da, save_file, imputed=False) -> None
Save an xarray DataArray to a GeoTIFF file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
da
|
DataArray
|
The input DataArray. |
required |
save_file
|
str
|
The path to save the DataArray. |
required |
imputed
|
bool
|
Whether the DataArray has been imputed. |
False
|
Source code in terrakit/download/geodata_utils.py
save_cog(ds, filename='cogeo.tif') -> None
Save an xarray Dataset as a Cloud Optimized GeoTIFF.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds
|
Dataset
|
The input Dataset. |
required |
filename
|
str
|
The path and filename for the output GeoTIFF. |
'cogeo.tif'
|
Source code in terrakit/download/geodata_utils.py
save_data_array_as_netcdf(da: xr.DataArray, save_file: str | bool, **kwargs) -> None
Save an xarray DataArray as a NetCDF file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
da
|
DataArray
|
The input DataArray. |
required |
save_file
|
str
|
The path to save the DataArray. |
required |
**kwargs
|
Additional keyword arguments for the to_netcdf method. |
{}
|
Source code in terrakit/download/geodata_utils.py
validate_input_params(bbox: tuple | None, date_start: str | None, date_end: str | None) -> None
Validate input parameters for bounding box and date range.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bbox
|
tuple | None
|
The bounding box as a tuple (min_lon, min_lat, max_lon, max_lat). |
required |
date_start
|
str | None
|
The start date in 'YYYY-MM-DD' format. |
required |
date_end
|
str | None
|
The end date in 'YYYY-MM-DD' format. |
required |