bgc_data_processing.comparison.matching
¶
Data selectors objects.
SelectiveABFileLoader(provider_name, category, exclude, variables, grid_basename)
¶
Bases: ABFileLoader
Load ABFile only on given points.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
provider_name |
str
|
Data provider name. |
required |
category |
str
|
Category provider belongs to. |
required |
exclude |
list[str]
|
Filenames to exclude from loading. |
required |
variables |
LoadingVariablesSet
|
Storer object containing all variables to consider for this data, both the one in the data file but and the one not represented in the file. |
required |
grid_basename |
str
|
Basename of the ab grid grid file for the loader. => files are considered to be loaded over the same grid. |
required |
Source code in src/bgc_data_processing/comparison/matching.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
|
load(filepath, constraints, mask)
¶
Load a abfiles from basename.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filepath |
Path | str
|
Path to the basename of the file to load. |
required |
constraints |
Constraints
|
Constraints slicer. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
DataFrame corresponding to the file. |
Source code in src/bgc_data_processing/comparison/matching.py
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 |
|
from_abloader(loader)
classmethod
¶
Create a Selective loader based on an existing loader.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
loader |
ABFileLoader
|
Loader to use as reference. |
required |
Returns:
Type | Description |
---|---|
SelectiveABFileLoader
|
Selective Loader. |
Source code in src/bgc_data_processing/comparison/matching.py
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 |
|
NearestNeighborStrategy(**model_kwargs)
¶
Implement a closest point search using NearestNeighbor algorithm.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**model_kwargs |
Additional arguments to pass to sklearn.neighbors.NearestNeighbors. The value of 'n_neighbors' while be overridden by 1. |
{}
|
Source code in src/bgc_data_processing/comparison/matching.py
309 310 311 |
|
model_kwargs = model_kwargs
instance-attribute
¶
name: str
property
¶
Strategy name.
get_closest_indexes(simulations_lat_lon, observations_lat_lon)
¶
Find closest simulation point for each observation point.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
simulations_lat_lon |
DataFrame
|
DataFrame with longitude and latitude for each simulations point. |
required |
observations_lat_lon |
DataFrame
|
DataFrame with longitude and latitude for each observation point. |
required |
Returns:
Type | Description |
---|---|
Series
|
Index of closest point for every observation point. |
Source code in src/bgc_data_processing/comparison/matching.py
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 |
|
Mask(mask_2d, index_2d)
¶
Mask to apply to ABFiles to filter data while loading.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mask_2d |
ndarray
|
2D array to mask layers when loading them. |
required |
index_2d |
ndarray
|
2D array of indexes to use to reindex the filtered array. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If the mask and the index have a different shape. |
Source code in src/bgc_data_processing/comparison/matching.py
369 370 371 |
|
mask: np.ndarray
property
writable
¶
2D boolean mask.
index: pd.Index
property
¶
Index for masked data reindexing.
Returns:
Type | Description |
---|---|
Index
|
Data Index. |
__call__(data_2d, **kwargs)
¶
Apply mask to 2D data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_2d |
ndarray
|
Data to apply the mask to. |
required |
**kwargs |
Additional parameters to pass to pd.Series. The value of 'index' while be overridden by self._index. |
{}
|
Returns:
Type | Description |
---|---|
Series
|
Masked data as a pd.Series with self._index as index. |
Source code in src/bgc_data_processing/comparison/matching.py
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 |
|
intersect(mask_array)
¶
Intersect the mask with another (same-shaped) boolean array.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mask_array |
ndarray
|
Array to intersect with. |
required |
Returns:
Type | Description |
---|---|
Mask
|
New mask whith self._mask & mask_array as mask array. |
Raises:
Type | Description |
---|---|
IncompatibleMaskShapeError
|
If mask_array has the wrong shape. |
Source code in src/bgc_data_processing/comparison/matching.py
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 |
|
make_empty(grid)
classmethod
¶
Create a Mask with all values True with grid size.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
grid |
ABFileGrid
|
ABFileGrid to use to have the grid size. |
required |
Returns:
Type | Description |
---|---|
Mask
|
Mask with only True values. |
Source code in src/bgc_data_processing/comparison/matching.py
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 |
|
Match(obs_closests_indexes)
¶
Match between observation indexes and simulations indexes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obs_closests_indexes |
Series
|
Closest simulated point index Series. The index is supposed to correspond to observations' index. |
required |
Source code in src/bgc_data_processing/comparison/matching.py
474 475 476 477 478 |
|
index_simulated: str = 'sim_index'
class-attribute
instance-attribute
¶
index_observed: str = 'obs_index'
class-attribute
instance-attribute
¶
index_loaded: str = 'load_index'
class-attribute
instance-attribute
¶
index_link = index_link
instance-attribute
¶
match(loaded_df)
¶
Transform the DataFrame index to link it to observations' index.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
loaded_df |
DataFrame
|
DataFrame to change the index of. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
Copy of loaded_df with a modified index, which correspond to observations' index values. |
Source code in src/bgc_data_processing/comparison/matching.py
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 |
|
SelectiveDataSource(reference, strategy, provider_name, data_format, dirin, data_category, excluded_files, files_pattern, variable_ensemble, **kwargs)
¶
Bases: DataSource
Selective Data Source.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
reference |
DataFrame
|
Reference Dataframe (observations). |
required |
strategy |
NearestNeighborStrategy
|
Closer point finding strategy. |
required |
provider_name |
str
|
Name of the data provider. |
required |
data_format |
str
|
Data format. |
required |
dirin |
Path | str
|
Input data directory. |
required |
data_category |
str
|
Category of the data. |
required |
excluded_files |
list[str]
|
Files not to load. |
required |
files_pattern |
FileNamePattern
|
Pattern to match to load files. |
required |
variable_ensemble |
SourceVariableSet
|
Ensembles of variables to consider. |
required |
Source code in src/bgc_data_processing/comparison/matching.py
539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 |
|
reference = reference.data
instance-attribute
¶
strategy = strategy
instance-attribute
¶
grid = self.loader.grid_file
instance-attribute
¶
get_coord(var_name)
¶
Get a coordinate field from loader.grid_file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
var_name |
str
|
Name of the variable to retrieve. |
required |
Returns:
Type | Description |
---|---|
Series
|
Loaded variable as pd.Series. |
Raises:
Type | Description |
---|---|
ABFileLoadingError
|
If the variable dosn't exist in the grid file. |
Source code in src/bgc_data_processing/comparison/matching.py
601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 |
|
get_x_y_indexes()
¶
Get x and y indexes.
Returns:
Type | Description |
---|---|
tuple[Series, Series]
|
X indexes series, Y indexes series. |
Source code in src/bgc_data_processing/comparison/matching.py
635 636 637 638 639 640 641 642 643 644 645 646 647 |
|
select(data_slice)
¶
Select closest points in an abfile using self.strategy.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_slice |
DataFrame
|
Sice of data to select from. |
required |
Returns:
Type | Description |
---|---|
tuple[Mask, Match]
|
Mask to use for loader, Match to link observations to simulations. |
Source code in src/bgc_data_processing/comparison/matching.py
649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 |
|
parse_date_from_filepath(filepath)
staticmethod
¶
Parse date from abfile basename.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filepath |
Path | str
|
File path. |
required |
Returns:
Type | Description |
---|---|
date
|
Corresponding date. |
Source code in src/bgc_data_processing/comparison/matching.py
682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 |
|
get_basenames(constraints)
¶
Return basenames of files matching constraints.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
constraints |
Constraints
|
Data constraints, only year constraint is used. |
required |
Returns:
Type | Description |
---|---|
list[Path]
|
List of basenames matching constraints. |
Source code in src/bgc_data_processing/comparison/matching.py
702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 |
|
load_all(constraints)
¶
Load all files for the loader.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
constraints |
Constraints
|
Constraints slicer., by default Constraints() |
required |
Returns:
Type | Description |
---|---|
Storer
|
Storer for the loaded data. |
Source code in src/bgc_data_processing/comparison/matching.py
748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 |
|
load_and_save(saving_directory, dateranges_gen, constraints)
¶
Save all the data before saving it all in the saving directory.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
saving_directory |
Path | str
|
Path to the directory to save in. |
required |
dateranges_gen |
DateRangeGenerator
|
Generator to use to retrieve dateranges. |
required |
constraints |
Constraints
|
Contraints ot apply on data. |
required |
Source code in src/bgc_data_processing/comparison/matching.py
790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 |
|
from_data_source(reference, strategy, dsource)
classmethod
¶
Create the sleective data source from an existing data source.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
reference |
Storer
|
Reference Dataframe (observations). |
required |
strategy |
NearestNeighborStrategy
|
Closer point finding strategy. |
required |
dsource |
DataSource
|
Template DataSource |
required |
Returns:
Type | Description |
---|---|
SelectiveDataSource
|
Selective datasource from Template. |
Source code in src/bgc_data_processing/comparison/matching.py
814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 |
|