Skip to content

bgc_data_processing.features

Transformations to apply to data to create new features.

BaseFeature(var_name, var_unit, var_type, var_default, var_name_format, var_value_format)

Bases: ABC

Base class for added features.

Parameters:

Name Type Description Default
var_name str

Name of the added variable.

required
var_unit str

Unit of the added variable.

required
var_type str

Type of the added variable.

required
var_default Any

Default value for the added variable.

required
var_name_format str

Name format for the added variable.

required
var_value_format str

Value format for the added variable.

required
Source code in src/bgc_data_processing/features.py
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
def __init__(
    self,
    var_name: str,
    var_unit: str,
    var_type: str,
    var_default: Any,
    var_name_format: str,
    var_value_format: str,
) -> None:
    self._output_var = NotExistingVar(
        name=var_name,
        unit=var_unit,
        var_type=var_type,
        default=var_default,
        name_format=var_name_format,
        value_format=var_value_format,
    )

variable: NotExistingVar property

Variable which correspond to the feature.

required_variables: list[ExistingVar | NotExistingVar | ParsedVar] property

Required variables for the feature computation.

transform(*args) abstractmethod

Compute the new variable values using all required series.

Source code in src/bgc_data_processing/features.py
85
86
87
@abstractmethod
def transform(self, *args: pd.Series) -> pd.Series:
    """Compute the new variable values using all required series."""

insert_in_storer(storer)

Insert the new feature in a given storer.

Parameters:

Name Type Description Default
storer Storer

Storer to include data into.

required
Source code in src/bgc_data_processing/features.py
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
def insert_in_storer(self, storer: "Storer") -> None:
    """Insert the new feature in a given storer.

    Parameters
    ----------
    storer : Storer
        Storer to include data into.
    """
    data = self.transform(*self._extract_from_storer(storer=storer))
    data.index = storer.data.index
    storer.add_feature(
        variable=self.variable,
        data=data,
    )

copy_var_infos_from_template(template, **kwargs) classmethod

Create Feature from a variable template.

Parameters:

Name Type Description Default
template TemplateVar

Template to use for the variable definition.

required

Returns:

Type Description
BaseFeature

Feature.

Source code in src/bgc_data_processing/features.py
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
@classmethod
def copy_var_infos_from_template(
    cls,
    template: "TemplateVar",
    **kwargs: ExistingVar | NotExistingVar | ParsedVar,
) -> "BaseFeature":
    """Create Feature from a variable template.

    Parameters
    ----------
    template : TemplateVar
        Template to use for the variable definition.

    Returns
    -------
    BaseFeature
        Feature.
    """
    return cls(
        **kwargs,
        var_name=template.name,
        var_unit=template.unit,
        var_type=template.type,
        var_default=template.default,
        var_name_format=template.name_format,
        var_value_format=template.value_format,
    )

Pressure(depth_variable, latitude_variable, var_name='PRES', var_unit='[dbars]', var_type=float, var_default=np.nan, var_name_format='%-10s', var_value_format='%10.3f')

Bases: BaseFeature

Pressure feature.

Parameters:

Name Type Description Default
depth_variable ExistingVar | NotExistingVar | ParsedVar

Variable for depth.

required
latitude_variable ExistingVar | NotExistingVar | ParsedVar

Variable for latitude.

required
var_name str

Variable Name., by default "PRES"

'PRES'
var_unit str

Variable unit., by default "[dbars]"

'[dbars]'
var_type str

Data type., by default float

float
var_default Any

Default value., by default np.nan

nan
var_name_format str

Name format for the added variable., by default "%-10s"

'%-10s'
var_value_format str

Value format for the added variable., by default "%10.3f"

'%10.3f'
Source code in src/bgc_data_processing/features.py
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
def __init__(
    self,
    depth_variable: ExistingVar | NotExistingVar | ParsedVar,
    latitude_variable: ExistingVar | NotExistingVar | ParsedVar,
    var_name: str = "PRES",
    var_unit: str = "[dbars]",
    var_type: str = float,
    var_default: Any = np.nan,
    var_name_format: str = "%-10s",
    var_value_format: str = "%10.3f",
) -> None:
    super().__init__(
        var_name=var_name,
        var_unit=var_unit,
        var_type=var_type,
        var_default=var_default,
        var_name_format=var_name_format,
        var_value_format=var_value_format,
    )
    self._source_vars = [depth_variable, latitude_variable]

transform(depth, latitude)

Compute pressure from depth and latitude.

Parameters:

Name Type Description Default
depth Series

Depth (in meters).

required
latitude Series

Latitude (in degree).

required

Returns:

Type Description
Series

Pressure (in dbars).

Source code in src/bgc_data_processing/features.py
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
def transform(self, depth: pd.Series, latitude: pd.Series) -> pd.Series:
    """Compute pressure from depth and latitude.

    Parameters
    ----------
    depth : pd.Series
        Depth (in meters).
    latitude : pd.Series
        Latitude (in degree).

    Returns
    -------
    pd.Series
        Pressure (in dbars).
    """
    pressure = pd.Series(eos80.pres(np.abs(depth), latitude))
    pressure.name = self.variable.label
    return pressure

PotentialTemperature(salinity_variable, temperature_variable, pressure_variable, var_name='PTEMP', var_unit='[deg_C]', var_type=float, var_default=np.nan, var_name_format='%-10s', var_value_format='%10.3f')

Bases: BaseFeature

Potential Temperature feature..

Parameters:

Name Type Description Default
salinity_variable ExistingVar | NotExistingVar | ParsedVar

Variable for salinity.

required
temperature_variable ExistingVar | NotExistingVar | ParsedVar

Variable for temperature.

required
pressure_variable ExistingVar | NotExistingVar | ParsedVar

Variable for pressure.

required
var_name str

Variable name., by default "PTEMP"

'PTEMP'
var_unit str

Variable unit., by default "[deg_C]"

'[deg_C]'
var_type str

Data type., by default float

float
var_default Any

Default value, by default np.nan

nan
var_name_format str

Name format for the added variable., by default "%-10s"

'%-10s'
var_value_format str

Value format for the added variable., by default "%10.3f"

'%10.3f'
Source code in src/bgc_data_processing/features.py
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
def __init__(
    self,
    salinity_variable: ExistingVar | NotExistingVar | ParsedVar,
    temperature_variable: ExistingVar | NotExistingVar | ParsedVar,
    pressure_variable: ExistingVar | NotExistingVar | ParsedVar,
    var_name: str = "PTEMP",
    var_unit: str = "[deg_C]",
    var_type: str = float,
    var_default: Any = np.nan,
    var_name_format: str = "%-10s",
    var_value_format: str = "%10.3f",
) -> None:
    super().__init__(
        var_name=var_name,
        var_unit=var_unit,
        var_type=var_type,
        var_default=var_default,
        var_name_format=var_name_format,
        var_value_format=var_value_format,
    )
    self._source_vars = [salinity_variable, temperature_variable, pressure_variable]

transform(salinity, temperature, pressure)

Compute potential temperature from salinity, temperature and pressure.

Parameters:

Name Type Description Default
salinity Series

Salinity (in psu).

required
temperature Series

Temperature (in Celsius degree).

required
pressure Series

Pressure (in dbars).

required

Returns:

Type Description
Series

Potential Temperature (in Celsisus degree).

Source code in src/bgc_data_processing/features.py
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
def transform(
    self,
    salinity: pd.Series,
    temperature: pd.Series,
    pressure: pd.Series,
) -> pd.Series:
    """Compute potential temperature from salinity, temperature and pressure.

    Parameters
    ----------
    salinity : pd.Series
        Salinity (in psu).
    temperature : pd.Series
        Temperature (in Celsius degree).
    pressure : pd.Series
        Pressure (in dbars).

    Returns
    -------
    pd.Series
        Potential Temperature (in Celsisus degree).
    """
    potential_temperature = pd.Series(eos80.ptmp(salinity, temperature, pressure))
    potential_temperature.name = self.variable.label
    return potential_temperature

SigmaT(salinity_variable, temperature_variable, var_name='SIGT', var_unit='[kg/m3]', var_type=float, var_default=np.nan, var_name_format='%-10s', var_value_format='%10.3f')

Bases: BaseFeature

Sigma T feature.

Parameters:

Name Type Description Default
salinity_variable ExistingVar | NotExistingVar | ParsedVar

Variable for slainity.

required
temperature_variable ExistingVar | NotExistingVar | ParsedVar

Variable for temperature.

required
var_name str

Variable name., by default "SIGT"

'SIGT'
var_unit str

Variable unit., by default "[kg/m3]"

'[kg/m3]'
var_type str

Data type., by default float

float
var_default Any

Default value., by default np.nan

nan
var_name_format str

Name format for the added variable., by default "%-10s"

'%-10s'
var_value_format str

Value format for the added variable., by default "%10.3f"

'%10.3f'
Source code in src/bgc_data_processing/features.py
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
def __init__(
    self,
    salinity_variable: ExistingVar | NotExistingVar | ParsedVar,
    temperature_variable: ExistingVar | NotExistingVar | ParsedVar,
    var_name: str = "SIGT",
    var_unit: str = "[kg/m3]",
    var_type: str = float,
    var_default: Any = np.nan,
    var_name_format: str = "%-10s",
    var_value_format: str = "%10.3f",
) -> None:
    super().__init__(
        var_name=var_name,
        var_unit=var_unit,
        var_type=var_type,
        var_default=var_default,
        var_name_format=var_name_format,
        var_value_format=var_value_format,
    )
    self._source_vars = [salinity_variable, temperature_variable]

transform(salinity, temperature)

Compute sigma t from salinity and temperature.

Parameters:

Name Type Description Default
salinity Series

Salinity (in psu).

required
temperature Series

Temperature (in Celsius degree).

required

Returns:

Type Description
Series

Sigma T (in kg/m3).

Source code in src/bgc_data_processing/features.py
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
def transform(
    self,
    salinity: pd.Series,
    temperature: pd.Series,
) -> pd.Series:
    """Compute sigma t from salinity and temperature.

    Parameters
    ----------
    salinity : pd.Series
        Salinity (in psu).
    temperature : pd.Series
        Temperature (in Celsius degree).

    Returns
    -------
    pd.Series
        Sigma T (in kg/m3).
    """
    sigma_t = pd.Series(eos80.dens0(salinity, temperature) - 1000)
    sigma_t.name = self.variable.label
    return sigma_t

ChlorophyllFromDiatomFlagellate(diatom_variable, flagellate_variable, var_name='CPHL', var_unit='[mg/m3]', var_type=float, var_default=np.nan, var_name_format='%-10s', var_value_format='%10.3f')

Bases: BaseFeature

Chlorophyll-a feature.

Parameters:

Name Type Description Default
diatom_variable ExistingVar | NotExistingVar | ParsedVar

Variable for diatom.

required
flagellate_variable ExistingVar | NotExistingVar | ParsedVar

Variable for flagellate.

required
var_name str

Variable name., by default "CPHL"

'CPHL'
var_unit str

Variable unit., by default "[mg/m3]"

'[mg/m3]'
var_type str

Data type., by default float

float
var_default Any

Default value., by default np.nan

nan
var_name_format str

Name format for the added variable., by default "%-10s"

'%-10s'
var_value_format str

Value format for the added variable., by default "%10.3f"

'%10.3f'
Source code in src/bgc_data_processing/features.py
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
def __init__(
    self,
    diatom_variable: ExistingVar | NotExistingVar | ParsedVar,
    flagellate_variable: ExistingVar | NotExistingVar | ParsedVar,
    var_name: str = "CPHL",
    var_unit: str = "[mg/m3]",
    var_type: str = float,
    var_default: Any = np.nan,
    var_name_format: str = "%-10s",
    var_value_format: str = "%10.3f",
) -> None:
    super().__init__(
        var_name=var_name,
        var_unit=var_unit,
        var_type=var_type,
        var_default=var_default,
        var_name_format=var_name_format,
        var_value_format=var_value_format,
    )
    self._source_vars = [diatom_variable, flagellate_variable]

transform(diatom, flagellate)

Compute chlorophyll-a from diatom and flagellate.

Parameters:

Name Type Description Default
diatom Series

Diatoms (in mg/m3).

required
flagellate Series

Flagellates (in mg/m3).

required

Returns:

Type Description
Series

Chlorophyll-a (in kg/m3).

Source code in src/bgc_data_processing/features.py
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
def transform(
    self,
    diatom: pd.Series,
    flagellate: pd.Series,
) -> pd.Series:
    """Compute chlorophyll-a from diatom and flagellate.

    Parameters
    ----------
    diatom : pd.Series
        Diatoms (in mg/m3).
    flagellate : pd.Series
        Flagellates (in mg/m3).

    Returns
    -------
    pd.Series
        Chlorophyll-a (in kg/m3).
    """
    sigma_t = diatom + flagellate
    sigma_t.name = self.variable.label
    return sigma_t