helpers
collection of useful functions used across workflows
bbox_to_utm(bbox, *, epsg_src, epsg_dst)
Convert bounding box coordinates to UTM.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bbox
|
tuple
|
Tuple containing the lon/lat bounding box coordinates (left, bottom, right, top) in degrees |
required |
epsg_src
|
int
|
EPSG code identifying input bbox coordinate system |
required |
epsg_dst
|
int
|
EPSG code identifying output coordinate system |
required |
Returns:
| Type | Description |
|---|---|
tuple
|
Tuple containing the bounding box coordinates in UTM (meters) (left, bottom, right, top) |
Source code in src/compass/utils/helpers.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |
burst_bbox_from_db(burst_id, burst_db_file=None, burst_db_conn=None)
Find the bounding box of a burst in the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
burst_id
|
str
|
JPL burst ID |
required |
burst_db_file
|
str
|
Location of burst database sqlite file, by default None |
None
|
burst_db_conn
|
Connection
|
Connection object to burst database (If already connected) Alternative to providing burst_db_file, will be faster for multiply queries. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
epsg |
int
|
EPSG code(s) of burst bounding box(es) |
bbox |
tuple[float]
|
Bounding box of burst in EPSG coordinates. Bounding box given as tuple(xmin, ymin, xmax, ymax) |
Raises:
| Type | Description |
|---|---|
ValueError
|
If burst_id is not found in burst database |
Source code in src/compass/utils/helpers.py
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 | |
burst_bboxes_from_db(burst_ids, burst_db_file=None, burst_db_conn=None)
Find the bounding box of bursts in the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
burst_id
|
list[str]
|
list of JPL burst IDs. |
required |
burst_db_file
|
str
|
Location of burst database sqlite file, by default None |
None
|
burst_db_conn
|
Connection
|
Connection object to burst database (If already connected) Alternative to providing burst_db_file, will be faster for multiply queries. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
bboxes |
dict
|
Burst bounding boxes as a dict with burst IDs as key and tuples of EPSG and bounding boxes (tuple[float]) as values. Bounding box given as tuple(xmin, ymin, xmax, ymax) |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no burst_ids are found in burst database |
Source code in src/compass/utils/helpers.py
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 | |
bursts_grouping_generator(bursts)
Dict to group bursts with the same burst ID but different polarizations key: burst ID, value: list[S1BurstSlc]
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bursts
|
List of bursts to grouped |
required |
Yields:
| Name | Type | Description |
|---|---|---|
k |
S1BurstId
|
Burst ID of grouped list of bursts |
v |
list[Sentinel1BurstSlc]
|
List of bursts with the same burst ID |
Source code in src/compass/utils/helpers.py
425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 | |
check_dem(dem_path)
Check if given path is a GDAL-compatible file; else raise error
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dem_path
|
str
|
File path to DEM for which to check GDAL-compatibility |
required |
Source code in src/compass/utils/helpers.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | |
check_directory(file_path)
Check if directory in file_path exists else raise an error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str
|
Path to directory to be checked |
required |
Source code in src/compass/utils/helpers.py
43 44 45 46 47 48 49 50 51 52 53 54 55 | |
check_file_path(file_path)
Check if file_path exist else raise an error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str
|
Path to file to be checked |
required |
Source code in src/compass/utils/helpers.py
28 29 30 31 32 33 34 35 36 37 38 39 40 | |
check_url(url)
Check if a resource exists at the given URL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
URL to the object |
required |
Returns:
| Name | Type | Description |
|---|---|---|
_ |
Bool
|
|
Source code in src/compass/utils/helpers.py
465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 | |
check_write_dir(dst_path)
Check if given directory is writeable; else raise error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dst_path
|
str
|
File path to directory for which to check writing permission |
required |
Source code in src/compass/utils/helpers.py
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 | |
deep_update(original, update)
Update default runconfig dict with user-supplied dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
original
|
dict
|
Dict with default options to be updated |
required |
update
|
Dict with user-defined options used to update original/default |
required |
Returns:
| Name | Type | Description |
|---|---|---|
original |
dict
|
Default dictionary updated with user-defined options |
References
https://stackoverflow.com/questions/3232943/update-value-of-a-nested-dictionary-of-varying-depth
Source code in src/compass/utils/helpers.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |
download_url(url, out_file_path)
Download a file from a given URL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
URL to the object |
required |
out_file_path
|
str
|
Path to the file where the object is to be downloaded |
required |
Returns:
| Name | Type | Description |
|---|---|---|
_ |
Bool
|
|
Source code in src/compass/utils/helpers.py
498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 | |
get_file_polarization_mode(file_path)
Check polarization mode from file name
Taking PP from SAFE file name with following format: MMM_BB_TTTR_LFPP_YYYYMMDDTHHMMSS_YYYYMMDDTHHMMSS_OOOOOO_DDDDDD_CCCC.SAFE
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str
|
SAFE file name to parse |
required |
Returns:
| Name | Type | Description |
|---|---|---|
original |
dict
|
Default dictionary updated with user-defined options |
References
https://sentinel.esa.int/web/sentinel/user-guides/sentinel-1-sar/naming-conventions
Source code in src/compass/utils/helpers.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
get_time_delta_str(t_prev)
Helper function that computes difference between current time and a given time object and returns it as a str
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t_prev
|
time
|
Date and time where a difference is to be computed from |
required |
_
|
Difference from current time and t_prev represented as a string |
required |
Source code in src/compass/utils/helpers.py
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 | |
open_raster(filename, band=1)
Return band as numpy array from gdal-friendly raster
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
Path where is stored GDAL raster to open |
required | |
band
|
Band number to open |
1
|
Returns:
| Name | Type | Description |
|---|---|---|
raster |
ndarray
|
Numpy array containing the raster band to open |
Source code in src/compass/utils/helpers.py
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 | |
polygon_to_utm(poly, *, epsg_src, epsg_dst)
Convert a shapely.Polygon's coordinates to UTM.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
poly
|
Polygon object |
required | |
epsg
|
int
|
EPSG code identifying output projection system |
required |
Returns:
| Type | Description |
|---|---|
tuple
|
Tuple containing the bounding box coordinates in UTM (meters) (left, bottom, right, top) |
Source code in src/compass/utils/helpers.py
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | |
write_raster(filename, data_list, descriptions, data_type=gdal.GDT_Float32, data_format='GTiff')
Write a multiband GDAL-friendly raster to disk. Each dataset allocated in the output file contains a description of the dataset allocated for that band
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
File path where to store output dataset |
required | |
data_list
|
List of numpy.ndarray to allocate for each raster band. All datasets within the list are assumed to have the same shape |
required | |
descriptions
|
List of strings containing a description for the bands to allocate |
required | |
data_type
|
GDAL dataset type |
GDT_Float32
|
|
format
|
Format for GDAL output file |
required |
Source code in src/compass/utils/helpers.py
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 | |