Staging
Common workflows for general usage
PrefectCommonConfig
Common configuration for Prefect tasks and flows. Base class for configuration used in Prefect task and flow used in staging the files from different stations (cadip, adgs...)
Attributes:
Name | Type | Description |
---|---|---|
rs_client |
AuxipClient | CadipClient
|
The client for accessing the Auxip or Cadip service. |
mission |
str
|
The mission identifier. |
tmp_download_path |
str
|
The local path where temporary files will be downloaded. |
s3_path |
str
|
The S3 bucket path where the files will be stored. |
Source code in docs/rs-client-libraries/rs_workflows/staging.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
|
PrefectFlowConfig
Bases: PrefectCommonConfig
Configuration class for Prefect flow.
This class inherits the PrefectCommonConfig and represents the configuration for a Prefect flow
see :py:class:`PrefectCommonConfig`
Name | Type | Description |
---|---|---|
max_workers |
int
|
The maximum number of workers for the Prefect flow. |
start_datetime |
datetime
|
The start datetime of the files that the station should return |
stop_datetime |
datetime
|
The stop datetime of the files that the station should return |
limit |
The limit for the number of the files in the list retrieved from the ADGS/CADIP station (optional). |
Source code in docs/rs-client-libraries/rs_workflows/staging.py
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 |
|
__init__(rs_client, mission, tmp_download_path, s3_path, max_workers, start_datetime, stop_datetime, limit=None)
Initialize the PrefectFlowConfig object with provided parameters.
Source code in docs/rs-client-libraries/rs_workflows/staging.py
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 |
|
PrefectTaskConfig
Bases: PrefectCommonConfig
Configuration class for Prefect tasks.
This class extends the PrefectCommonConfig
class with additional attributes
specific to Prefect tasks. It includes the configuration for the task, such as the
files to be processed by the task and the maximum number of retries allowed.
see :py:class:`PrefectCommonConfig`
Name | Type | Description |
---|---|---|
task_files_stac |
List[Dict]
|
A list of dictionaries containing information about the files to be processed by the task. This info is in STAC format |
max_retries |
int
|
The maximum number of retries allowed for the task. |
Source code in docs/rs-client-libraries/rs_workflows/staging.py
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 |
|
__init__(rs_client, mission, tmp_download_path, s3_path, task_files_stac, max_retries=3)
Initialize the PrefectTaskConfig object with provided parameters.
Source code in docs/rs-client-libraries/rs_workflows/staging.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
|
create_collection_name(mission, station)
Create the name of a catalog collection
This function constructs and returns a specific name for the catalog collection. For ADGS station type should be "mission_name"_aux For CADIP stations types should be "mission_name"_chunk
For other values, a RuntimeError is raised.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mission |
str
|
The name of the mission. |
required |
station |
str
|
The type of station . Supported values are "AUX" and "CADIP", "INS", "MPS", "MTI", "NSG", "SGS". |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The name of the collection |
Raises:
Type | Description |
---|---|
RuntimeError
|
If the provided station type is not supported. |
Source code in docs/rs-client-libraries/rs_workflows/staging.py
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 |
|
filter_unpublished_files(stac_client, collection_name, files_stac)
Checks for unpublished files in the STAC catalog.
This function takes a list of files and checks if they are already published in a specified STAC (SpatioTemporal Asset Catalog) collection. It returns a list of files that are not yet published.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stac_client |
StacClient
|
An instance of |
required |
collection_name |
str
|
The name of the collection in which the search is performed. |
required |
files_stac |
list of dict
|
A list of files to be checked for publication. Each file is represented as a dictionary with at least an "id" key. |
required |
Returns:
Type | Description |
---|---|
list
|
list of dict: A list of files that are not yet published in the catalog. Each file is represented as a |
list
|
dictionary. |
Examples:
>>> rs_client = StacClient(...)
>>> collection_name = "example_collection"
>>> files_stac = [{"id": "file1.raw"}, {"id": "file2.raw"}]
>>> unpublished_files = filter_unpublished_files(rs_client, collection_name, files_stac)
>>> print(unpublished_files)
[{"id": "file1.raw"}]
Source code in docs/rs-client-libraries/rs_workflows/staging.py
269 270 271 272 273 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 327 328 |
|
get_prefect_logger(general_logger_name)
It returns the Prefect logger. If this can't be taken due to the missing Prefect context (i.e. the flow/task is executed as a single function, from Pytest for example), the general logger is returned
Parameters:
Name | Type | Description | Default |
---|---|---|---|
general_logger_name |
str
|
The name of the general logger if Prefect logger can't be returned. |
required |
Returns:
Name | Type | Description |
---|---|---|
logger |
logger
|
A Prefect logger instance or a general logger instance. |
Source code in docs/rs-client-libraries/rs_workflows/staging.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
|
staging(config)
Prefect task function to stage (=download/ingest) files from a specified station.
This task function stages files for processing by calling the appropriate rs-server endpoint for each requested file. It monitors the status of the file until it is completely staged before initiating the next stage request.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
PrefectTaskConfig
|
The configuration object containing the necessary parameters for staging the files. |
required |
Returns:
Name | Type | Description |
---|---|---|
List |
[dict]
|
A list containing information about files that FAILED to be staged. The files within this list don't appear in the catalog as published |
Source code in docs/rs-client-libraries/rs_workflows/staging.py
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 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 |
|
staging_flow(config)
Prefect flow for staging (downloading/ingesting) files from a station.
This flow orchestrates the download process by obtaining the list of files from the search endpoint (provided station), splitting the list into tasks based on the number of workers, and submitting tasks for ingestion.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
PrefectFlowConfig
|
Configuration object containing details about the download flow, such as start and stop datetime, limit, rs_client, mission, temporary download path, S3 path, and max_workers. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the flow execution is successful, False otherwise. |
Raises:
Type | Description |
---|---|
None
|
This function does not raise any exceptions. |
Source code in docs/rs-client-libraries/rs_workflows/staging.py
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 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 |
|
update_stac_catalog(stac_client, collection_name, stac_file_info, obs)
Update the STAC catalog with file information.
This task updates the STAC catalog with the information of a file that has been processed and saved to a specific location. It adds the mandatory fields such as geometry, collection name and object storage href. It sends a POST request to add the newly composed item into the STAC catalog.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stac_client |
StacClient
|
The client for accessing the STAC catalog. |
required |
collection_name |
str
|
The name of the collection in the STAC catalog. |
required |
stac_file_info |
dict
|
Information about the STAC file to be updated. |
required |
obs |
str
|
The bucket location where the file has been saved. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the STAC catalog is successfully updated, False otherwise. |
Source code in docs/rs-client-libraries/rs_workflows/staging.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
|