Documentation for Helper Modules
Documentation for the terrakit.general_utils helper modules.
terrakit.general_utils.labels_downloader
rapid_mapping_event_lookup(event_id) -> dict
Event look up for a given event from Copernicus Rapid Mapping Service.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event_id
|
str
|
event id is a three digit code unique to each event. Provide either as "EMSR000" or "000". |
required |
Returns:
| Type | Description |
|---|---|
dict
|
dict[str: any]: json response containing full details available for a given event. |
Source code in terrakit/general_utils/labels_downloader.py
rapid_mapping_acquisition_time_lookup(event_id, monitoring_number) -> str
Look up acquisition time for a given event ID from Copernicus Rapid Mapping Service.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event_id
|
str
|
event id is a three digit code unique to each event. Provide either as "EMSR000" or "000". |
required |
monitoring_number
|
str
|
monitoring number given by a two digit number. Provide either as "MONIT00" or "monit00" or "00". |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
acquisition time with format '%Y-%m-%dT%H:%M:%S' |
Source code in terrakit/general_utils/labels_downloader.py
rapid_mapping_event_date_time_lookup(event_id) -> str
Look up event date and time for a given event ID from Copernicus Rapid Mapping Service.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event_id
|
str
|
event id is a three digit code unique to each event. Provide either as "EMSR000" or "000". |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
event time with format '%Y-%m-%dT%H:%M:%S' |
Source code in terrakit/general_utils/labels_downloader.py
rapid_mapping_geojson_downloader(event_id, aoi, monitoring_number, version, dest) -> str
Download GeoJSON labels from Copernicus Rapid Mapping Service.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event_id
|
str
|
event id is a three digit code unique to each event. Provide either as "EMSR000" or "emsr000" or "000". |
required |
aoi
|
str
|
The area of interest is a two digit code for the aoi of the given event. Provide either as "AOI00" or "aoi00" or "00". |
required |
monitoring_number
|
str
|
The monitoring number for the event. Provide either as "MONIT00" or "monit00" or "00". |
required |
version
|
str
|
The event version number. Provide either as "V1" or "v1" or "1". |
required |
dest
|
str
|
The destination directory to save the downloaded GeoJSON files. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
downloaded GeoJSON path name |
Example
Source code in terrakit/general_utils/labels_downloader.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | |
hugging_face_file_downloader(repo_id: str, filename: str, revision: str = 'main', subfolder: str | None = None, dest: str = '.')
Downloads a label file from Hugging Face Hub.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_id
|
str
|
The Hugging Face Hub repository ID. |
required |
filename
|
str
|
The name of the file to download. |
required |
revision
|
str
|
The revision or commit to download. Defaults to "main". |
'main'
|
subfolder
|
str
|
The subfolder within the repository to download from. Defaults to None. |
None
|
dest
|
str
|
The destination directory to save the downloaded file. Defaults to the current directory (.). |
'.'
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
The path to the downloaded file. |
Example
Source code in terrakit/general_utils/labels_downloader.py
terrakit.general_utils.statistics
compute_stats(dataset)
Compute descriptive statistics for a given dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
ndarray
|
The dataset for which to compute statistics. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
A tuple containing mean, median, minimum, maximum, standard deviation, and count of the dataset. |
Source code in terrakit/general_utils/statistics.py
compute_stats_for_masked_pixels(image, mask)
Compute descriptive statistics for masked pixels in the given image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
ndarray
|
The image data. |
required |
mask
|
ndarray
|
The mask to filter the image data. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
A tuple containing mean, median, minimum, maximum, standard deviation, and count of the masked pixels. |
Source code in terrakit/general_utils/statistics.py
load_verified_stats()
Load precomputed statistics for verified data calculated from target_tif = "sentinel_aws_sentinel-2-l2a_2024-08-30_imputed_20" generated using EMSR748
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
A tuple containing verified label statistics, verified data statistics, and verified masked statistics. |
Source code in terrakit/general_utils/statistics.py
terrakit.general_utils.defaults
get_default_class_args_and_values(cls_name: type) -> dict
Return a dictionary of class arguments and default values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cls_name
|
type)
|
The class for which to retrieve default arguments. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
A dictionary containing class arguments and their default values. |
Source code in terrakit/general_utils/defaults.py
get_pipeline_defaults() -> dict
Return a dictionary of arguments and default values for all pipeline steps.
Returns dict: A dictionary containing class arguments and their default values for pipeline steps.
Example
Source code in terrakit/general_utils/defaults.py
update_pipeline_args(pipeline_options: dict) -> dict
Update default values for any pipeline steps specified in pipelines_options.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pipeline_options
|
dict
|
Dictionary of all pipeline options. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
Dictionary of class arguments and either default values or 'pipeline_options' values. |
Example
Source code in terrakit/general_utils/defaults.py
terrakit.general_utils.exceptions
TerrakitBaseException
Bases: Exception
Base exception for all custom exceptions in the project.
Source code in terrakit/general_utils/exceptions.py
TerrakitValidationError
Bases: TerrakitBaseException
Raised when there is an validation error.
Source code in terrakit/general_utils/exceptions.py
TerrakitValueError
Bases: TerrakitBaseException
Raised when there is invalid input.