bgc_data_processing.utils.patterns
¶
Filenames Patterns building.
FileNamePattern(str_pattern, year_field='years', month_field='months', day_field='days')
¶
Create the pattern to use to select filenames.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
str_pattern |
str
|
Raw string pattern, with field to infer written in brackets ('{'&'}'). |
required |
year_field |
str
|
Name of the field supposed to contain the year informations. , by default "years" |
'years'
|
month_field |
str
|
Name of the field supposed to contain the month informations. , by default "months" |
'months'
|
day_field |
str
|
Name of the field supposed to contain the day informations. , by default "days" |
'days'
|
Source code in src/bgc_data_processing/utils/patterns.py
30 31 32 33 34 35 36 37 38 39 40 |
|
build_from_constraint(date_constraint)
¶
Build the pattern from date constraints.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
date_constraint |
dict
|
Date constraint. |
required |
Returns:
Type | Description |
---|---|
str
|
Final pattern. |
Source code in src/bgc_data_processing/utils/patterns.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
|
build(date_min, date_max)
¶
Build the pattern from the starting and ending dates.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
date_min |
date | None
|
Starting date. |
required |
date_max |
date | None
|
Ending date. |
required |
Returns:
Type | Description |
---|---|
str
|
Final pattern. |
Source code in src/bgc_data_processing/utils/patterns.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
|
DateIntervalPattern(date_min, date_max, precision='day')
¶
Create the patterns values for a given date interval.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
date_min |
date | None
|
Starting date of the interval. |
required |
date_max |
date | None
|
Ending date of the interval. |
required |
precision |
str
|
Precision of the interval. A "day" precision means that year and month are constant, therefore the required days are contained between the minimum day number and the maximum day number. A "month" precision means that year is constant but months are different but totally included (from first day to last day.) in the interval., therefore the required months are contained between the minimum months number and the maximum months number. A "year" precision means the years to include are different but totally included (from first day to last day.) in the interval, therefore the required years are contained between the minimum year number and the maximum year number., by default "day" |
'day'
|
Source code in src/bgc_data_processing/utils/patterns.py
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 |
|
years: str
property
¶
'year' part of the pattern.
months: str
property
¶
'month' part of the pattern.
days: str
property
¶
'day' part of the pattern.
__repr__()
¶
Object representation string.
Returns:
Type | Description |
---|---|
str
|
Starting date - Ending date ; precision: interval precision. |
Source code in src/bgc_data_processing/utils/patterns.py
409 410 411 412 413 414 415 416 417 |
|
with_day_precision(date_min, date_max)
classmethod
¶
Create a DateIntervalPattern with day precision.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
date_min |
date
|
Starting date. |
required |
date_max |
date
|
Ending date. |
required |
Returns:
Type | Description |
---|---|
DateIntervalPattern
|
Date interval pattern. |
Source code in src/bgc_data_processing/utils/patterns.py
477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 |
|
with_month_precision(date_min, date_max)
classmethod
¶
Create a DateIntervalPattern with month precision.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
date_min |
date
|
Starting date. |
required |
date_max |
date
|
Ending date. |
required |
Returns:
Type | Description |
---|---|
DateIntervalPattern
|
Date interval pattern. |
Source code in src/bgc_data_processing/utils/patterns.py
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 |
|
with_year_precision(date_min, date_max)
classmethod
¶
Create a DateIntervalPattern with year precision.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
date_min |
date
|
Starting date. |
required |
date_max |
date
|
Ending date. |
required |
Returns:
Type | Description |
---|---|
DateIntervalPattern
|
Date interval pattern. |
Source code in src/bgc_data_processing/utils/patterns.py
529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 |
|
PatternMatcher(pattern, validation_function=lambda : True)
¶
Matcher to find files which match agiven pattern.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pattern |
str
|
Pattern to match. |
required |
validation_function |
Callable
|
Function to use to validate that files are to be loaded., by default lambdafilepath |
lambda : True
|
Source code in src/bgc_data_processing/utils/patterns.py
568 569 570 571 572 573 574 |
|
validate: Callable
property
writable
¶
Validation function.
select_matching_filepath(research_directory)
¶
Select the filepaths matching the pattern.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
research_directory |
Path | str
|
Directory to serach for files. |
required |
Returns:
Type | Description |
---|---|
list[Path]
|
List of correct paths. |
Source code in src/bgc_data_processing/utils/patterns.py
588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 |
|