Skip to content

earlinet

EARLINET Reader

EARLINETReader

Bases: GriddedReader

Reader for EARLINET (European Aerosol Research Lidar Network) NetCDF data.

Source code in monetio/readers/earlinet.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
@register_reader("earlinet")
class EARLINETReader(GriddedReader):
    """
    Reader for EARLINET (European Aerosol Research Lidar Network) NetCDF data.
    """

    def open_dataset(self, files: str | list[str], **kwargs) -> xr.Dataset:
        """
        Retrieve and load EARLINET data.

        Parameters
        ----------
        files : Union[str, List[str]]
            File path, list of paths, or glob pattern.
        **kwargs : dict
            Additional arguments passed to xarray.open_mfdataset.

        Returns
        -------
        xr.Dataset
            The loaded EARLINET data.
        """
        # Default to combined dimensions if not specified
        kwargs.setdefault("combine", "by_coords")

        # Use XarrayDriver (via GriddedReader) to open
        ds = super().open_dataset(files, preprocess=earlinet_preprocess, **kwargs)

        return ds

open_dataset(files, **kwargs)

Retrieve and load EARLINET data.

Parameters:

Name Type Description Default
files Union[str, List[str]]

File path, list of paths, or glob pattern.

required
**kwargs dict

Additional arguments passed to xarray.open_mfdataset.

{}

Returns:

Type Description
Dataset

The loaded EARLINET data.

Source code in monetio/readers/earlinet.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
def open_dataset(self, files: str | list[str], **kwargs) -> xr.Dataset:
    """
    Retrieve and load EARLINET data.

    Parameters
    ----------
    files : Union[str, List[str]]
        File path, list of paths, or glob pattern.
    **kwargs : dict
        Additional arguments passed to xarray.open_mfdataset.

    Returns
    -------
    xr.Dataset
        The loaded EARLINET data.
    """
    # Default to combined dimensions if not specified
    kwargs.setdefault("combine", "by_coords")

    # Use XarrayDriver (via GriddedReader) to open
    ds = super().open_dataset(files, preprocess=earlinet_preprocess, **kwargs)

    return ds

earlinet_preprocess(ds)

Preprocess EARLINET dataset: standardize coordinates and dimensions.

Parameters:

Name Type Description Default
ds Dataset

Input EARLINET dataset.

required

Returns:

Type Description
Dataset

Preprocessed dataset.

Source code in monetio/readers/earlinet.py
40
41
42
43
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
83
def earlinet_preprocess(ds: xr.Dataset) -> xr.Dataset:
    """
    Preprocess EARLINET dataset: standardize coordinates and dimensions.

    Parameters
    ----------
    ds : xr.Dataset
        Input EARLINET dataset.

    Returns
    -------
    xr.Dataset
        Preprocessed dataset.
    """
    # 1. Standardize Time
    # EARLINET NetCDF files are usually CF compliant and xarray handles them.

    # 2. Rename Dimensions/Coordinates
    # altitude is usually a coordinate/dimension already named 'altitude' or 'height'.
    # If it's something else, we can rename it.
    if "height" in ds.dims and "altitude" not in ds.dims:
        ds = ds.rename({"height": "altitude"})

    # 3. Coordinate handling
    # Ensure latitude and longitude are coordinates
    coord_vars = ["latitude", "longitude", "altitude", "time", "wavelength"]
    actual_coords = [v for v in coord_vars if v in ds.variables]
    if actual_coords:
        ds = ds.set_coords(actual_coords)

    # 4. Standard attributes
    if "altitude" in ds.coords:
        ds["altitude"].attrs.update({"units": "m", "standard_name": "altitude", "positive": "up"})

    if "latitude" in ds.coords:
        ds["latitude"].attrs.update({"units": "degrees_north", "standard_name": "latitude"})

    if "longitude" in ds.coords:
        ds["longitude"].attrs.update({"units": "degrees_east", "standard_name": "longitude"})

    # Update history
    ds = update_history(ds, "Preprocessed EARLINET data.")

    return ds