bgc_data_processing.core.variables.sets
¶
Variable Ensembles.
AllVariablesTypes: TypeAlias = ExistingVar | NotExistingVar | ParsedVar | FeatureVar
module-attribute
¶
NotParsedvar: TypeAlias = ExistingVar | NotExistingVar | FeatureVar
module-attribute
¶
FromFileVariables: TypeAlias = ExistingVar | NotExistingVar
module-attribute
¶
VariableSet(*args, **kwargs)
¶
Variable ensemble behavior implementation.
This class represents the set of both variables present in the file and variables to take in consideration (therefore to add even if empty) when loading the data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args |
FromFileVariables
|
Var objects to represent the variables stored by the object. It is better if these Var object have been instanciated using .not_here or .here_as methods. |
()
|
*kwargs |
FromFileVariables
|
Var objects to represent the variables stored by the object. It is better if these Var object have been instanciated using .not_here or .here_as methods. The parameter name has no importance. |
{}
|
Raises:
Type | Description |
---|---|
ValueError:
|
If multiple var object have the same name. |
Source code in src/bgc_data_processing/core/variables/sets.py
51 52 53 54 55 56 57 58 59 60 61 62 |
|
elements: list[AllVariablesTypes]
property
¶
All variables in the ensemble.
labels: dict[str, str]
property
¶
Returns a dicitonnary mapping variable names to variables labels.
Returns:
Type | Description |
---|---|
dict[str, str]
|
name : label |
mapper_by_name: dict[str, FromFileVariables]
property
¶
Mapper between variables names and variables Var objects (for getitem).
Returns:
Type | Description |
---|---|
dict[str, Var]
|
Mapping between names (str) and variables (Var) |
__getitem__(__k)
¶
Get variable by its name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
__k |
str
|
Variable name |
required |
Returns:
Type | Description |
---|---|
FromFileVariables
|
Corresponding variable with name __k |
Source code in src/bgc_data_processing/core/variables/sets.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
|
__iter__()
¶
Get an iterator of all variables.
Yields:
Type | Description |
---|---|
Iterator[FromFileVariables]
|
Ietrator of all element in the storer. |
Source code in src/bgc_data_processing/core/variables/sets.py
92 93 94 95 96 97 98 99 100 |
|
__str__()
¶
Convert the object to string.
Returns:
Type | Description |
---|---|
str
|
All variable as strings. |
Source code in src/bgc_data_processing/core/variables/sets.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
|
__len__()
¶
Return the number of elements.
Returns:
Type | Description |
---|---|
int
|
Number of elements. |
Source code in src/bgc_data_processing/core/variables/sets.py
121 122 123 124 125 126 127 128 129 |
|
__eq__(__o)
¶
Compare to object for equality.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
__o |
object
|
Object to compare with. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if the objects have same types and all equal variables. |
Source code in src/bgc_data_processing/core/variables/sets.py
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 |
|
get(var_name)
¶
Return the variable which name corresponds to var_name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
var_name |
str
|
Name of the variable to get. |
required |
Returns:
Type | Description |
---|---|
FromFileVariables
|
Variable with corresponding name in self._elements. |
Raises:
Type | Description |
---|---|
IncorrectVariableNameError
|
If var_name doesn't correspond to any name. |
Source code in src/bgc_data_processing/core/variables/sets.py
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 |
|
add_var(var)
¶
Add a new variable to self._elements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
var |
Var
|
Variable to add |
required |
Raises:
Type | Description |
---|---|
DuplicatedVariableNameError
|
If the variable name is already in the set. |
Source code in src/bgc_data_processing/core/variables/sets.py
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
|
pop(var_name)
¶
Remove and return the variable with the given name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
var_name |
str
|
Name of the variable to remove from the ensemble. |
required |
Returns:
Type | Description |
---|---|
AllVariablesTypes
|
Removed variable. |
Source code in src/bgc_data_processing/core/variables/sets.py
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
|
has_name(var_name)
¶
Check if a variable name is the nam eof one of the variables.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
var_name |
str
|
Name to test. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if the name is in self.keys(), False otherwise. |
Source code in src/bgc_data_processing/core/variables/sets.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
|
keys()
¶
Keys to use when calling self[key].
Returns:
Type | Description |
---|---|
dict_keys
|
View of self.mapper_by_name keys. |
Source code in src/bgc_data_processing/core/variables/sets.py
236 237 238 239 240 241 242 243 244 |
|
FeatureVariablesSet(*args, **kwargs)
¶
Bases: VariableSet
Ensemble of features.
This class represents the set of both variables present in the file and variables to take in consideration (therefore to add even if empty) when loading the data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args |
FeatureVar
|
Var objects to represent the variables stored by the object. It is better if these Var object have been instanciated using .not_here or .here_as methods. |
()
|
*kwargs |
FeatureVar
|
Var objects to represent the variables stored by the object. It is better if these Var object have been instanciated using .not_here or .here_as methods. The parameter name has no importance. |
{}
|
Raises:
Type | Description |
---|---|
ValueError:
|
If multiple var object have the same name. |
Source code in src/bgc_data_processing/core/variables/sets.py
331 332 |
|
iter_constructables_features(available_vars)
¶
Create an iterator returning constructables features.
The Iterator considers that all constructed features are available to construct the following ones.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
available_vars |
list[AllVariablesTypes]
|
Variable available to build the features. |
required |
Yields:
Type | Description |
---|---|
Iterator[FeatureVar]
|
Iterator. |
Raises:
Type | Description |
---|---|
FeatureConstructionError
|
If all features can not be constructed. |
Source code in src/bgc_data_processing/core/variables/sets.py
355 356 357 358 359 360 361 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 |
|
BaseRequiredVarsSet(expocode, date, year, month, day, latitude, longitude, depth, hour=None, provider=None, *args, **kwargs)
¶
Bases: VariableSet
Storer for Variable objects with some required variables.
This class represents the set of both variables present in the file and variables to take in consideration (therefore to add even if empty) when loading the data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expocode |
FromFileVariables
|
Expocode related variable. |
required |
date |
FromFileVariables
|
Date related variable. |
required |
year |
FromFileVariables
|
Year related variable. |
required |
month |
FromFileVariables
|
Month related variable. |
required |
day |
FromFileVariables
|
Day related variable. |
required |
latitude |
FromFileVariables
|
Latitude related variable. |
required |
longitude |
FromFileVariables
|
Longitude related variable. |
required |
depth |
FromFileVariables
|
Depth related variable. |
required |
provider |
FromFileVariables
|
Provider related variable. Can be set to None to be ignored., by default None |
None
|
hour |
FromFileVariables
|
Hour related variable. Can be set to None to be ignored., by default None |
None
|
*args |
FromFileVariables
|
Var objects to represent the variables stored by the object. It is better if these Var object have been instanciated using .not_here or .here_as methods. |
()
|
*kwargs |
FromFileVariables
|
Var objects to represent the variables stored by the object. It is better if these Var object have been instanciated using .not_here or .here_as methods. The parameter name has no importance. |
{}
|
Raises:
Type | Description |
---|---|
ValueError:
|
If multiple var object have the same name. |
Source code in src/bgc_data_processing/core/variables/sets.py
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 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 |
|
has_provider = False
instance-attribute
¶
provider_var_name = None
instance-attribute
¶
expocode_var_name = expocode.name
instance-attribute
¶
date_var_name = date.name
instance-attribute
¶
year_var_name = year.name
instance-attribute
¶
month_var_name = month.name
instance-attribute
¶
day_var_name = day.name
instance-attribute
¶
has_hour = False
instance-attribute
¶
hour_var_name = None
instance-attribute
¶
latitude_var_name = latitude.name
instance-attribute
¶
longitude_var_name = longitude.name
instance-attribute
¶
depth_var_name = depth.name
instance-attribute
¶
pop(var_name)
¶
Remove and return the variable with the given name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
var_name |
str
|
Name of the variable to remove from the ensemble. |
required |
Returns:
Type | Description |
---|---|
AllVariablesTypes
|
Removed variable. |
Raises:
Type | Description |
---|---|
KeyError
|
If the variable is mandatory. |
Source code in src/bgc_data_processing/core/variables/sets.py
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 529 530 531 532 533 534 535 |
|
LoadingVariablesSet(expocode, date, year, month, day, latitude, longitude, depth, hour=None, provider=None, *args, **kwargs)
¶
Bases: BaseRequiredVarsSet
Storer for Var object which are going to be loaded.
This class represents the set of both variables present in the file and variables to take in consideration (therefore to add even if empty) when loading the data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expocode |
FromFileVariables
|
Expocode related variable. |
required |
date |
FromFileVariables
|
Date related variable. |
required |
year |
FromFileVariables
|
Year related variable. |
required |
month |
FromFileVariables
|
Month related variable. |
required |
day |
FromFileVariables
|
Day related variable. |
required |
latitude |
FromFileVariables
|
Latitude related variable. |
required |
longitude |
FromFileVariables
|
Longitude related variable. |
required |
depth |
FromFileVariables
|
Depth related variable. |
required |
provider |
FromFileVariables
|
Provider related variable. Can be set to None to be ignored., by default None |
None
|
hour |
FromFileVariables
|
Hour related variable. Can be set to None to be ignored., by default None |
None
|
*args |
FromFileVariables
|
Var objects to represent the variables stored by the object. It is better if these Var object have been instanciated using .not_here or .here_as methods. |
()
|
*kwargs |
FromFileVariables
|
Var objects to represent the variables stored by the object. It is better if these Var object have been instanciated using .not_here or .here_as methods. The parameter name has no importance. |
{}
|
Raises:
Type | Description |
---|---|
ValueError:
|
If multiple var object have the same name. |
Source code in src/bgc_data_processing/core/variables/sets.py
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 |
|
in_dset: list[ExistingVar]
property
¶
List of Var object supposedly present in the dataset.
Returns:
Type | Description |
---|---|
list[Var]
|
Var objects in the dataset. |
corrections: dict[str, Callable]
property
¶
Mapping between variables keys and correcting functions.
Returns:
Type | Description |
---|---|
dict[str, Callable]
|
Mapping. |
to_remove_if_all_nan: list[str]
property
¶
Return the list of keys to inspect when removing rows.
This is suited when seeking for rows to delete when many given variables are NaN.
Returns:
Type | Description |
---|---|
list[str]
|
List of keys to use. |
to_remove_if_any_nan: list[str]
property
¶
Return the list of keys to inspect when removing rows.
This is suited when seeking for rows to delete when at least one given variable is NaN.
Returns:
Type | Description |
---|---|
list[str]
|
List of keys to use. |
StoringVariablesSet(expocode, date, year, month, day, latitude, longitude, depth, hour=None, provider=None, *args, **kwargs)
¶
Bases: BaseRequiredVarsSet
Storer for Var object which are going to be stored.
This class represents the set of both variables present in the file and variables to take in consideration (therefore to add even if empty) when loading the data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expocode |
FromFileVariables
|
Expocode related variable. |
required |
date |
FromFileVariables
|
Date related variable. |
required |
year |
FromFileVariables
|
Year related variable. |
required |
month |
FromFileVariables
|
Month related variable. |
required |
day |
FromFileVariables
|
Day related variable. |
required |
latitude |
FromFileVariables
|
Latitude related variable. |
required |
longitude |
FromFileVariables
|
Longitude related variable. |
required |
depth |
FromFileVariables
|
Depth related variable. |
required |
provider |
FromFileVariables
|
Provider related variable. Can be set to None to be ignored., by default None |
None
|
hour |
FromFileVariables
|
Hour related variable. Can be set to None to be ignored., by default None |
None
|
*args |
FromFileVariables
|
Var objects to represent the variables stored by the object. It is better if these Var object have been instanciated using .not_here or .here_as methods. |
()
|
*kwargs |
FromFileVariables
|
Var objects to represent the variables stored by the object. It is better if these Var object have been instanciated using .not_here or .here_as methods. The parameter name has no importance. |
{}
|
Raises:
Type | Description |
---|---|
ValueError:
|
If multiple var object have the same name. |
Source code in src/bgc_data_processing/core/variables/sets.py
732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 |
|
saving_variables: SavingVariablesSet
property
¶
Order of the variables to save.
set_saving_order(var_names=None)
¶
Set the saving order for the variables.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
var_names |
list[str] | None
|
List of variable names => saving variables sorted., by default None |
None
|
Raises:
Type | Description |
---|---|
ValueError
|
If a variable name is not one of the variables'. |
Source code in src/bgc_data_processing/core/variables/sets.py
763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 |
|
SavingVariablesSet(expocode, date, year, month, day, latitude, longitude, depth, hour=None, provider=None, save_order=None, *args, **kwargs)
¶
Bases: BaseRequiredVarsSet
Storer for Var object which are going to be saved.
This class represents the set of both variables present in the file and variables to take in consideration (therefore to add even if empty) when loading the data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expocode |
FromFileVariables
|
Expocode related variable. |
required |
date |
FromFileVariables
|
Date related variable. |
required |
year |
FromFileVariables
|
Year related variable. |
required |
month |
FromFileVariables
|
Month related variable. |
required |
day |
FromFileVariables
|
Day related variable. |
required |
latitude |
FromFileVariables
|
Latitude related variable. |
required |
longitude |
FromFileVariables
|
Longitude related variable. |
required |
depth |
FromFileVariables
|
Depth related variable. |
required |
hour |
FromFileVariables
|
Hour related variable. Can be set to None to be ignored., by default None |
None
|
provider |
FromFileVariables
|
Provider related variable. Can be set to None to be ignored., by default None |
None
|
save_order |
list[AllVariablesTypes] | None
|
Default saving order. Order of the variables if None., by default None |
None
|
*args |
FromFileVariables
|
Var objects to represent the variables stored by the object. It is better if these Var object have been instanciated using .not_here or .here_as methods. |
()
|
*kwargs |
FromFileVariables
|
Var objects to represent the variables stored by the object. It is better if these Var object have been instanciated using .not_here or .here_as methods. The parameter name has no importance. |
{}
|
Raises:
Type | Description |
---|---|
ValueError:
|
If multiple var object have the same name. |
Source code in src/bgc_data_processing/core/variables/sets.py
834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 |
|
save_labels: list[str | tuple[str]]
property
¶
Sorting order to use when saving data.
Returns:
Type | Description |
---|---|
list[str | tuple[str]]
|
List of columns keys to pass as df[self.save_sort] to sort data. |
save_names: list[str | tuple[str]]
property
¶
Sorted names of variables to use for saving.
Returns:
Type | Description |
---|---|
list[str | tuple[str]]
|
List of columns keys to pass as df[self.save_sort] to sort data. |
name_save_format: str
property
¶
String line to use as formatting for name and unit rows.
Returns:
Type | Description |
---|---|
str
|
Format string |
value_save_format: str
property
¶
String line to use as formatting for value rows.
Returns:
Type | Description |
---|---|
str
|
Format string" |
set_saving_order(var_names=None)
¶
Set the saving order for the variables.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
var_names |
list[str] | None
|
List of variable names => saving variables sorted., by default None |
None
|
Raises:
Type | Description |
---|---|
ValueError
|
If a variable name is not one of the variables'. |
Source code in src/bgc_data_processing/core/variables/sets.py
869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 |
|
SourceVariableSet(expocode, date, year, month, day, latitude, longitude, depth, hour=None, provider=None, *args, **kwargs)
¶
Bases: BaseRequiredVarsSet
Ensemble of variables.
This class represents the set of both variables present in the file and variables to take in consideration (therefore to add even if empty) when loading the data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expocode |
FromFileVariables
|
Expocode related variable. |
required |
date |
FromFileVariables
|
Date related variable. |
required |
year |
FromFileVariables
|
Year related variable. |
required |
month |
FromFileVariables
|
Month related variable. |
required |
day |
FromFileVariables
|
Day related variable. |
required |
latitude |
FromFileVariables
|
Latitude related variable. |
required |
longitude |
FromFileVariables
|
Longitude related variable. |
required |
depth |
FromFileVariables
|
Depth related variable. |
required |
provider |
FromFileVariables
|
Provider related variable. Can be set to None to be ignored., by default None |
None
|
hour |
FromFileVariables
|
Hour related variable. Can be set to None to be ignored., by default None |
None
|
*args |
FromFileVariables
|
Var objects to represent the variables stored by the object. It is better if these Var object have been instanciated using .not_here or .here_as methods. |
()
|
*kwargs |
FromFileVariables
|
Var objects to represent the variables stored by the object. It is better if these Var object have been instanciated using .not_here or .here_as methods. The parameter name has no importance. |
{}
|
Raises:
Type | Description |
---|---|
ValueError:
|
If multiple var object have the same name. |
Source code in src/bgc_data_processing/core/variables/sets.py
975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 |
|