Skip to content

bgc_data_processing.core.variables.vars

Variables.

BaseVar(name, unit, var_type, default=np.nan, name_format='%-15s', value_format='%15s')

Bases: ABC

Class to store Meta data on a variable of interest.

Parameters:

Name Type Description Default
name str

'Official' name for the variable : name to use when displaying the variable.

required
unit str

Variable unit (written using the following format: [deg_C] for Celsius degree of [kg] for kilograms).

required
var_type str

Variable type (str, int, datetime...). It will be used to convert the data using df[variable].astype(type)

required
default Any

Default value to set instead of nan., by default np.nan

nan
name_format str

Format to use to save the data name and unit in a csv of txt file. , by default "%-15s"

'%-15s'
value_format str

Format to use to save the data value in a csv of txt file., by default "%15s"

'%15s'

Examples:

>>> var_lat = BaseVar("LATITUDE", "[deg_N]", float, 7, 6, "%-12s", "%12.6f")

Class to store Meta data on a variable of interest.

Parameters:

Name Type Description Default
name str

'Official' name for the variable : name to use when displaying the variable.

required
unit str

Variable unit (written using the following format: [deg_C] for Celsius degree of [kg] for kilograms).

required
var_type str

Variable type (str, int, datetime...). It will be used to convert the data using df[variable].astype(type)

required
default Any

Default value to set instead of nan., by default np.nan

nan
name_format str

Format to use to save the data name and unit in a csv of txt file. , by default "%-15s"

'%-15s'
value_format str

Format to use to save the data value in a csv/txt file., by default "%15s"

'%15s'

Examples:

>>> var_lat = BaseVar("LATITUDE", "[deg_N]", float, 7, 6, "%-12s", "%12.6f")
Source code in src/bgc_data_processing/core/variables/vars.py
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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
def __init__(
    self,
    name: str,
    unit: str,
    var_type: str,
    default: Any = np.nan,
    name_format: str = "%-15s",
    value_format: str = "%15s",
):
    """Class to store Meta data on a variable of interest.

    Parameters
    ----------
    name : str
        'Official' name for the variable : name to use when displaying the variable.
    unit : str
        Variable unit (written using the following format:
        [deg_C] for Celsius degree of [kg] for kilograms).
    var_type : str
        Variable type (str, int, datetime...).
        It will be used to convert the data using df[variable].astype(type)
    default: Any
        Default value to set instead of nan., by default np.nan
    name_format: str
        Format to use to save the data name and unit in a csv of txt file.
        , by default "%-15s"
    value_format: str
        Format to use to save the data value in a csv/txt file., by default "%15s"

    Examples
    --------
    >>> var_lat = BaseVar("LATITUDE", "[deg_N]", float, 7, 6, "%-12s", "%12.6f")
    """
    self.name = name
    self.unit = unit
    self.type = var_type
    self.default = default
    self.name_format = name_format
    self.value_format = value_format

is_feature = False class-attribute instance-attribute

exist_in_dset: bool = None class-attribute instance-attribute

name = name instance-attribute

unit = unit instance-attribute

type = var_type instance-attribute

default = default instance-attribute

name_format = name_format instance-attribute

value_format = value_format instance-attribute

label: str property

Returns the label to use to find the variable data in a dataframe.

Returns:

Type Description
str

label.

__hash__()

Hashing method.

Returns:

Type Description
int

Hashed object.

Source code in src/bgc_data_processing/core/variables/vars.py
84
85
86
87
88
89
90
91
92
def __hash__(self) -> int:
    """Hashing method.

    Returns
    -------
    int
        Hashed object.
    """
    return hash(self.__repr__())

__str__()

Convert the variable to a string.

Returns:

Type Description
str

name - unit (type)

Source code in src/bgc_data_processing/core/variables/vars.py
 94
 95
 96
 97
 98
 99
100
101
102
def __str__(self) -> str:
    """Convert the variable to a string.

    Returns
    -------
    str
        name - unit (type)
    """
    return f"{self.name} - {self.unit} ({self.type})"

__repr__()

Represent the variable as string.

Returns:

Type Description
str

name_unit_type

Source code in src/bgc_data_processing/core/variables/vars.py
104
105
106
107
108
109
110
111
112
def __repr__(self) -> str:
    """Represent the variable as string.

    Returns
    -------
    str
        name_unit_type
    """
    return f"{self.name}_{self.unit}"

__eq__(__o)

Test variable equality.

Parameters:

Name Type Description Default
__o object

Object to test equality with.

required

Returns:

Type Description
bool

True if both are instance of basevar with same representation.

Source code in src/bgc_data_processing/core/variables/vars.py
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
def __eq__(self, __o: object) -> bool:
    """Test variable equality.

    Parameters
    ----------
    __o : object
        Object to test equality with.

    Returns
    -------
    bool
        True if both are instance of basevar with same representation.
    """
    if isinstance(__o, BaseVar):
        return repr(self) == repr(__o)
    return False

TemplateVar

Bases: BaseVar

Class to define default variable as a template to ease variable instantiation.

building_informations()

Self's informations to instanciate object with same informations as self.

Returns:

Type Description
dict

arguments to use when initiating an instance of BaseVar.

Source code in src/bgc_data_processing/core/variables/vars.py
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
def building_informations(self) -> dict:
    """Self's informations to instanciate object with same informations as self.

    Returns
    -------
    dict
        arguments to use when initiating an instance of BaseVar.
    """
    return {
        "name": self.name,
        "unit": self.unit,
        "var_type": self.type,
        "default": self.default,
        "name_format": self.name_format,
        "value_format": self.value_format,
    }

in_file_as(*args)

Return an ExistingVar.

New object has same attributes as self and the property 'aliases' correctly set up using ExistingVar._set_aliases method.

Parameters:

Name Type Description Default
args str | tuple[str, str, list]

Name(s) of the variable in the dataset and the corresponding flags. Aliases are ranked: first will be the only one used if present in dataset. If not second will be checked, and so on.. Aliases are supposed to be formatted as : (alias, flag_alias, flag_values), where alias (str) is the name of the column storing the variable in the dataset, flag_alias (str) is the name of the column storing the variable's flag in the dataset and flag_values (list) is the list of correct values for the flag. If there is no flag columns, flag_alias and flag_values can be set to None, or the argument can be reduced to the variable column name only.

()

Returns:

Type Description
ExistingVar

Variable with correct loading informations.

Examples:

To instantiate a variable specifying a flag column to use:

>>> default_var = TemplateVar("PSAL", "[psu]", float, 10, 9, "%-10s", "%10.3f")
>>> instanciated_var = default_var.in_file_as(("CTDSAL", "CTDSAL_FLAG_W", [2]))

To instantiate a variable without flag columns to use:

>>> default_var = TemplateVar("PSAL", "[psu]", float, 10, 9, "%-10s", "%10.3f")
>>> instanciated_var = default_var.in_file_as(("CTDSAL",None,None))
# or equivalently:
>>> default_var = TemplateVar("PSAL", "[psu]", float, 10, 9, "%-10s", "%10.3f")
>>> instanciated_var = default_var.in_file_as("CTDSAL")

To instantiate a variable with multiple possible aliases and flags:

>>> default_var = TemplateVar("PSAL", "[psu]", float, 10, 9, "%-10s", "%10.3f")
>>> instanciated_var = default_var.in_file_as(
>>>     ("CTDSAL1", "CTDSAL1_FLAG_W", [2]),
>>>     ("CTDSAL2", "CTDSAL2_FLAG_W", [2]),
>>> )

To instantiate a variable with multiple possible aliases and some flags:

>>> default_var = TemplateVar("PSAL", "[psu]", float, 10, 9, "%-10s", "%10.3f")
>>> instanciated_var = default_var.in_file_as(
>>>     ("CTDSAL1", "CTDSAL1_FLAG_W", [2]),
>>>     ("CTDSAL2", None, None),
>>> )
# or equivalently:
To instantiate a variable with multiple possible aliases and some flags:
>>> default_var = TemplateVar("PSAL", "[psu]", float, 10, 9, "%-10s", "%10.3f")
>>> instanciated_var = default_var.in_file_as(
>>>     ("CTDSAL1", "CTDSAL1_FLAG_W", [2]),
>>>     "CTDSAL2",
>>> )
Source code in src/bgc_data_processing/core/variables/vars.py
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
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
def in_file_as(self, *args: str | tuple[str, str, list]) -> "ExistingVar":
    """Return an ExistingVar.

    New object has same attributes as self and \
    the property 'aliases' correctly set up using ExistingVar._set_aliases method.

    Parameters
    ----------
    args : str | tuple[str, str, list]
        Name(s) of the variable in the dataset and the corresponding flags.
        Aliases are ranked: first will be the only one used if present in dataset.
        If not second will be checked, and so on..
        Aliases are supposed to be formatted as : (alias, flag_alias, flag_values),
        where alias (str) is the name of the column storing the variable
        in the dataset, flag_alias (str) is the name of the column storing
        the variable's flag in the dataset and flag_values (list) is
        the list of correct values for the flag.
        If there is no flag columns, flag_alias and flag_values can be set to None,
        or the argument can be reduced to the variable column name only.

    Returns
    -------
    ExistingVar
        Variable with correct loading informations.

    Examples
    --------
    To instantiate a variable specifying a flag column to use:
    >>> default_var = TemplateVar("PSAL", "[psu]", float, 10, 9, "%-10s", "%10.3f")
    >>> instanciated_var = default_var.in_file_as(("CTDSAL", "CTDSAL_FLAG_W", [2]))

    To instantiate a variable without flag columns to use:
    >>> default_var = TemplateVar("PSAL", "[psu]", float, 10, 9, "%-10s", "%10.3f")
    >>> instanciated_var = default_var.in_file_as(("CTDSAL",None,None))
    # or equivalently:
    >>> default_var = TemplateVar("PSAL", "[psu]", float, 10, 9, "%-10s", "%10.3f")
    >>> instanciated_var = default_var.in_file_as("CTDSAL")

    To instantiate a variable with multiple possible aliases and flags:
    >>> default_var = TemplateVar("PSAL", "[psu]", float, 10, 9, "%-10s", "%10.3f")
    >>> instanciated_var = default_var.in_file_as(
    >>>     ("CTDSAL1", "CTDSAL1_FLAG_W", [2]),
    >>>     ("CTDSAL2", "CTDSAL2_FLAG_W", [2]),
    >>> )

    To instantiate a variable with multiple possible aliases and some flags:
    >>> default_var = TemplateVar("PSAL", "[psu]", float, 10, 9, "%-10s", "%10.3f")
    >>> instanciated_var = default_var.in_file_as(
    >>>     ("CTDSAL1", "CTDSAL1_FLAG_W", [2]),
    >>>     ("CTDSAL2", None, None),
    >>> )
    # or equivalently:
    To instantiate a variable with multiple possible aliases and some flags:
    >>> default_var = TemplateVar("PSAL", "[psu]", float, 10, 9, "%-10s", "%10.3f")
    >>> instanciated_var = default_var.in_file_as(
    >>>     ("CTDSAL1", "CTDSAL1_FLAG_W", [2]),
    >>>     "CTDSAL2",
    >>> )
    """
    return ExistingVar.from_template(self).set_aliases(*args)

not_in_file()

Return a NotExistingVar object with same attributes as self.

Returns:

Type Description
NotExistingVar

Instanciated variable.

Source code in src/bgc_data_processing/core/variables/vars.py
224
225
226
227
228
229
230
231
232
def not_in_file(self) -> "NotExistingVar":
    """Return a NotExistingVar object with same attributes as self.

    Returns
    -------
    NotExistingVar
        Instanciated variable.
    """
    return NotExistingVar.from_template(self)

NotExistingVar(name, unit, var_type, default=np.nan, name_format='%-15s', value_format='%15s')

Bases: BaseVar

Class to represent variables which don't exist in the dataset.

Parameters:

Name Type Description Default
name str

'Official' name for the variable : name to use when displaying the variable.

required
unit str

Variable unit (written using the following format: [deg_C] for Celsius degree of [kg] for kilograms).

required
var_type str

Variable type (str, int, datetime...). It will be used to convert the data using df[variable].astype(type)

required
default Any

Default value to set instead of nan., by default np.nan

nan
name_format str

Format to use to save the data name and unit in a csv of txt file. , by default "%-15s"

'%-15s'
value_format str

Format to use to save the data value in a csv of txt file., by default "%15s"

'%15s'

Class to represent variables which don't exist in the dataset.

Parameters:

Name Type Description Default
name str

'Official' name for the variable : name to use when displaying the variable.

required
unit str

Variable unit (written using the following format: [deg_C] for Celsius degree of [kg] for kilograms).

required
var_type str

Variable type (str, int, datetime...). It will be used to convert the data using df[variable].astype(type)

required
default Any

Default value to set instead of nan., by default np.nan

nan
name_format str

Format to use to save the data name and unit in a csv of txt file. , by default "%-15s"

'%-15s'
value_format str

Format to use to save the data value in a csv/txt file., by default "%15s"

'%15s'
Source code in src/bgc_data_processing/core/variables/vars.py
261
262
263
264
265
266
267
268
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
def __init__(
    self,
    name: str,
    unit: str,
    var_type: str,
    default: Any = np.nan,
    name_format: str = "%-15s",
    value_format: str = "%15s",
):
    """Class to represent variables which don't exist in the dataset.

    Parameters
    ----------
    name : str
        'Official' name for the variable : name to use when displaying the variable.
    unit : str
        Variable unit (written using the following format:
        [deg_C] for Celsius degree of [kg] for kilograms).
    var_type : str
        Variable type (str, int, datetime...).
        It will be used to convert the data using df[variable].astype(type)
    default: Any
        Default value to set instead of nan., by default np.nan
    name_format: str
        Format to use to save the data name and unit in a csv of txt file.
        , by default "%-15s"
    value_format: str
        Format to use to save the data value in a csv/txt file., by default "%15s"
    """
    super().__init__(name, unit, var_type, default, name_format, value_format)
    self.exist_in_dset = self.__default_exist_in_dset
    self._remove_if_nan = self.__default_remove_if_nan
    self._remove_if_all_nan = self.__default_remove_if_all_nan

__default_exist_in_dset: bool = False class-attribute instance-attribute

__default_remove_if_nan: bool = False class-attribute instance-attribute

__default_remove_if_all_nan: bool = False class-attribute instance-attribute

exist_in_dset = self.__default_exist_in_dset instance-attribute

remove_if_nan: bool property

True if the variable must be removed if NaN.

Returns:

Type Description
bool

True if the variable must be removed if NaN.

remove_if_all_nan: bool property

Whether the variable must be removed if all same are NaN.

If True, then the variable must be removed when this variable and other 'remove if all nan' variables are NaN.

Returns:

Type Description
bool

True if the variable must be removed when this variable and other 'remove if all nan' variables are NaN.

from_template(template) classmethod

Instantiate a NotExistingVar from a TemplateVar.

Parameters:

Name Type Description Default
template TemplateVar

Template variable to build from.

required

Returns:

Type Description
NotExistingVar

NotExistingVar from template.

Source code in src/bgc_data_processing/core/variables/vars.py
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
@classmethod
def from_template(cls, template: "TemplateVar") -> "NotExistingVar":
    """Instantiate a NotExistingVar from a TemplateVar.

    Parameters
    ----------
    template : TemplateVar
        Template variable to build from.

    Returns
    -------
    NotExistingVar
        NotExistingVar from template.
    """
    return cls(**template.building_informations())

set_default(default)

Set the default value for the variable column.

Parameters:

Name Type Description Default
default Any

Value to use as default

required

Returns:

Type Description
NotExistingVar

Self.

Source code in src/bgc_data_processing/core/variables/vars.py
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
def set_default(self, default: Any) -> "NotExistingVar":
    """Set the default value for the variable column.

    Parameters
    ----------
    default : Any
        Value to use as default

    Returns
    -------
    NotExistingVar
        Self.
    """
    self.default = default
    return self

remove_when_all_nan()

Set self._remove_if_all_nan to True.

Returns:

Type Description
NotExistingVar

self

Source code in src/bgc_data_processing/core/variables/vars.py
353
354
355
356
357
358
359
360
361
362
def remove_when_all_nan(self) -> "NotExistingVar":
    """Set self._remove_if_all_nan to True.

    Returns
    -------
    NotExistingVar
        self
    """
    self._remove_if_all_nan = True
    return self

remove_when_nan()

Set self._remove_if_nan to True.

Returns:

Type Description
NotExistingVar

self

Source code in src/bgc_data_processing/core/variables/vars.py
364
365
366
367
368
369
370
371
372
373
def remove_when_nan(self) -> "NotExistingVar":
    """Set self._remove_if_nan to True.

    Returns
    -------
    NotExistingVar
        self
    """
    self._remove_if_nan = True
    return self

ExistingVar(name, unit, var_type, default=np.nan, name_format='%-15s', value_format='%15s')

Bases: NotExistingVar

Class to represent variables existing in the dataset.

This class allows to specify flag columns, correction functions...

Parameters:

Name Type Description Default
name str

'Official' name for the variable : name to use when displaying the variable.

required
unit str

Variable unit (written using the following format: [deg_C] for Celsius degree of [kg] for kilograms).

required
var_type str

Variable type (str, int, datetime...). It will be used to convert the data using df[variable].astype(type)

required
default Any

Default value to set instead of nan., by default np.nan

nan
name_format str

Format to use to save the data name and unit in a csv of txt file. , by default "%-15s"

'%-15s'
value_format str

Format to use to save the data value in a csv of txt file., by default "%15s"

'%15s'

Class to represent variables existing in the dataset.

This class allows to specify flag columns, correction functions...

Parameters:

Name Type Description Default
name str

'Official' name for the variable : name to use when displaying the variable.

required
unit str

Variable unit (written using the following format: [deg_C] for Celsius degree of [kg] for kilograms).

required
var_type str

Variable type (str, int, datetime...). It will be used to convert the data using df[variable].astype(type)

required
default Any

Default value to set instead of nan., by default np.nan

nan
name_format str

Format to use to save the data name and unit in a csv of txt file. , by default "%-15s"

'%-15s'
value_format str

Format to use to save the data value in a csv/txt file., by default "%15s"

'%15s'
Source code in src/bgc_data_processing/core/variables/vars.py
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
def __init__(
    self,
    name: str,
    unit: str,
    var_type: str,
    default: Any = np.nan,
    name_format: str = "%-15s",
    value_format: str = "%15s",
):
    """Class to represent variables existing in the dataset.

    This class allows to specify flag columns, correction functions...

    Parameters
    ----------
    name : str
        'Official' name for the variable : name to use when displaying the variable.
    unit : str
        Variable unit (written using the following format:
        [deg_C] for Celsius degree of [kg] for kilograms).
    var_type : str
        Variable type (str, int, datetime...).
        It will be used to convert the data using df[variable].astype(type)
    default: Any
        Default value to set instead of nan., by default np.nan
    name_format: str
        Format to use to save the data name and unit in a csv of txt file.
        , by default "%-15s"
    value_format: str
        Format to use to save the data value in a csv/txt file., by default "%15s"
    """
    super().__init__(name, unit, var_type, default, name_format, value_format)
    self.exist_in_dset = self.__default_exist_in_dset
    self.correction = self.__default_correction
    self._aliases = self.__default_aliases.copy()

__default_exist_in_dset: bool = True class-attribute instance-attribute

__default_correction: callable = None class-attribute instance-attribute

__default_aliases: list[tuple[str, str, list]] = [] class-attribute

exist_in_dset = self.__default_exist_in_dset instance-attribute

correction = self.__default_correction instance-attribute

aliases: list[tuple[str, str, list]] property

Getter for aliases.

Returns:

Type Description
list[tuple[str, str, list]]

alias, flag column alias (None if not), values to keep from flag column (None if not)

remove_if_all_nan: bool property

Whether or not to suppress the row when this an other variables are NaN.

Returns:

Type Description
bool

True if this variable must be included when removing where some variables are all nan.

remove_if_nan: bool property

Whether or not to suppress the row when the variable is np.nan.

Returns:

Type Description
bool

True if rows must be removed when this variable is nan.

from_template(template) classmethod

Instantiate a ExistingVar from a TemplateVar.

Parameters:

Name Type Description Default
template TemplateVar

Template variable to build from.

required

Returns:

Type Description
ExistingVar

ExistingVar from template.

Source code in src/bgc_data_processing/core/variables/vars.py
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
@classmethod
def from_template(cls, template: "TemplateVar") -> "ExistingVar":
    """Instantiate a ExistingVar from a TemplateVar.

    Parameters
    ----------
    template : TemplateVar
        Template variable to build from.

    Returns
    -------
    ExistingVar
        ExistingVar from template.
    """
    return super().from_template(template)

set_aliases(*args)

Set aliases for the variable.

Parameters:

Name Type Description Default
args str | tuple[str, str, list]

Name(s) of the variable in the dataset and the corresponding flags. Aliases are ranked: first alias will be the only one considered if present in dataset. If not second will be checked, and so on.. Aliases are supposed to be formatted as : (alias, flag_alias, flag_values), where alias (str) is the name of the column storing the variable in the dataset, flag_alias (str) is the name of the column storing the variable's flag in the dataset and flag_values (list) is the list of correct values for the flag. If there is no flag columns, flag_alias and flag_values can be set to None, or the argument can be reduced to the variable column name only.

()

Returns:

Type Description
ExistingVar

Updated version of self

Raises:

Type Description
VariableInstantiationError

If one of the arguments length is different than 1 and 3.

ValueError

If one of the arguments is not an instance of string or Iterable.

Source code in src/bgc_data_processing/core/variables/vars.py
491
492
493
494
495
496
497
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
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
def set_aliases(self, *args: str | tuple[str, str, list]) -> "ExistingVar":
    """Set aliases for the variable.

    Parameters
    ----------
    args : str | tuple[str, str, list]
        Name(s) of the variable in the dataset and the corresponding flags.
        Aliases are ranked: first alias will be the only one considered if present
        in dataset. If not second will be checked, and so on..
        Aliases are supposed to be formatted as : (alias, flag_alias, flag_values),
        where alias (str) is the name of the column storing the variable
        in the dataset, flag_alias (str) is the name of the column storing
        the variable's flag in the dataset and flag_values (list) is the list
        of correct values for the flag.
        If there is no flag columns, flag_alias and flag_values can be set to None,
        or the argument can be reduced to the variable column name only.

    Returns
    -------
    "ExistingVar"
        Updated version of self

    Raises
    ------
    VariableInstantiationError
        If one of the arguments length is different than 1 and 3.
    ValueError
        If one of the arguments is not an instance of string or Iterable.
    """
    aliases = []
    for arg in args:
        if isinstance(arg, str):
            alias = arg
            flag_alias = None
            flag_value = None
        elif isinstance(arg, Iterable):
            if len(arg) == 1:
                alias = arg[0]
                flag_alias = None
                flag_value = None
            elif len(arg) == 3:
                alias = arg[0]
                flag_alias = arg[1]
                flag_value = arg[2]
            else:
                msg = f"{arg} can't be of length {len(arg)}"
                raise VariableInstantiationError(msg)
        else:
            msg = f"{arg} must be str or Iterable"
            raise TypeError(msg)
        aliases.append((alias, flag_alias, flag_value))
    self._aliases = aliases
    return self

correct_with(function)

Correction function definition.

Parameters:

Name Type Description Default
function Callable

Function to apply to the dataframe row storing this variable's values.

required

Returns:

Type Description
ExistingVar

self.

Raises:

Type Description
VariableInstantiationError

If the given object is not callable.

Source code in src/bgc_data_processing/core/variables/vars.py
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
def correct_with(self, function: Callable) -> "ExistingVar":
    """Correction function definition.

    Parameters
    ----------
    function : Callable
        Function to apply to the dataframe row storing this variable's values.

    Returns
    -------
    ExistingVar
        self.

    Raises
    ------
    VariableInstantiationError
        If the given object is not callable.
    """
    if not isinstance(function, Callable):
        msg = "Correcting function must be callable."
        raise VariableInstantiationError(msg)
    self.correction = function
    self._has_correction = True
    return self

ParsedVar

Bases: BaseVar

Variables parsed from a csv file.

__repr__()

Represent the parsed variable as a string.

Returns:

Type Description
str

name_unit

Source code in src/bgc_data_processing/core/variables/vars.py
574
575
576
577
578
579
580
581
582
def __repr__(self) -> str:
    """Represent the parsed variable as a string.

    Returns
    -------
    str
        name_unit
    """
    return f"{self.name}_{self.unit}"

FeatureVar(feature)

Bases: BaseVar

Variable resulting of an operation between variables.

Parameters:

Name Type Description Default
feature BaseFeature

Feature the variable comes from.

required
Source code in src/bgc_data_processing/core/variables/vars.py
597
598
599
600
601
602
603
604
605
606
607
def __init__(self, feature: "BaseFeature"):
    super().__init__(
        feature.variable.name,
        feature.variable.unit,
        feature.variable.type,
        feature.variable.default,
        feature.variable.name_format,
        feature.variable.value_format,
    )
    self._feature = feature
    self.required_vars = feature.required_variables

is_feature = True class-attribute instance-attribute

exist_in_dset: bool = False class-attribute instance-attribute

required_vars = feature.required_variables instance-attribute

feature: BaseFeature property

Feature for the variable.

is_loadable(loaded_list)

Find if the variable can be made using given some loaded variables.

Parameters:

Name Type Description Default
loaded_list list[ExistingVar | NotExistingVar]

List of available variables.

required

Returns:

Type Description
bool

True if the variable is loadable.

Source code in src/bgc_data_processing/core/variables/vars.py
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
def is_loadable(self, loaded_list: list[ExistingVar | NotExistingVar]) -> bool:
    """Find if the variable can be made using given some loaded variables.

    Parameters
    ----------
    loaded_list : list[ExistingVar  |  NotExistingVar]
        List of available variables.

    Returns
    -------
    bool
        True if the variable is loadable.
    """
    for var in self.required_vars:
        if not any(x.name == var.name for x in loaded_list):
            return False
    return True