Skip to content

bgc_data_processing.core.loaders.netcdf_loaders

NetCDF Loaders.

NetCDFLoader(provider_name, category, exclude, variables)

Bases: BaseLoader

Loader class to use with NetCDF files.

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 SourceVariableSet

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
Source code in src/bgc_data_processing/core/loaders/netcdf_loaders.py
47
48
49
50
51
52
53
54
55
56
57
58
59
def __init__(
    self,
    provider_name: str,
    category: str,
    exclude: list[str],
    variables: "SourceVariableSet",
) -> None:
    super().__init__(
        provider_name=provider_name,
        category=category,
        exclude=exclude,
        variables=variables,
    )

load(filepath, constraints=None)

Load a netCDF file from filepath.

Parameters:

Name Type Description Default
filepath Path | str

Path to the file to load.

required
constraints Constraints | None

Constraints slicer., by default None

None

Returns:

Type Description
DataFrame

DataFrame corresponding to the file.

Source code in src/bgc_data_processing/core/loaders/netcdf_loaders.py
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
def load(
    self,
    filepath: Path | str,
    constraints: Constraints | None = None,
) -> pd.DataFrame:
    """Load a netCDF file from filepath.

    Parameters
    ----------
    filepath: Path | str
        Path to the file to load.
    constraints : Constraints | None, optional
        Constraints slicer., by default None

    Returns
    -------
    pd.DataFrame
        DataFrame corresponding to the file.
    """
    if constraints is None:
        constraints = Constraints()
    file_id = self._get_id(Path(filepath).name)
    nc_data = self._read(filepath=Path(filepath))
    df_format = self._format(nc_data)
    df_dates = self._set_dates(df_format)
    df_dates_sliced = constraints.apply_specific_constraint(
        field_label=self._variables.get(self._variables.date_var_name).label,
        df=df_dates,
    )
    df_prov = self._set_provider(df_dates_sliced)
    df_expo = self._set_expocode(df_prov, file_id)
    df_ecols = self._add_empty_cols(df_expo)
    df_types = self._convert_type(df_ecols)
    df_corr = self._correct(df_types)
    df_sliced = constraints.apply_constraints_to_dataframe(df_corr)
    return self.remove_nan_rows(df_sliced)

SatelliteNetCDFLoader(provider_name, category, exclude, variables)

Bases: NetCDFLoader

Loader class to use with NetCDF files related to Satellite data.

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 SourceVariableSet

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
Source code in src/bgc_data_processing/core/loaders/netcdf_loaders.py
474
475
476
477
478
479
480
481
482
483
484
485
486
def __init__(
    self,
    provider_name: str,
    category: str,
    exclude: list[str],
    variables: "SourceVariableSet",
) -> None:
    super().__init__(
        provider_name=provider_name,
        category=category,
        exclude=exclude,
        variables=variables,
    )