Skip to content

mplnet

MPLNET Reader

MPLNETReader

Bases: GriddedReader

Reader for MPLNET (NASA Micro-Pulse Lidar Network) V3 NetCDF data.

Source code in monetio/readers/mplnet.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("mplnet")
class MPLNETReader(GriddedReader):
    """
    Reader for MPLNET (NASA Micro-Pulse Lidar Network) V3 NetCDF data.
    """

    def open_dataset(self, files: str | list[str], **kwargs) -> xr.Dataset:
        """
        Retrieve and load MPLNET 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 MPLNET 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=mplnet_preprocess, **kwargs)

        return ds

open_dataset(files, **kwargs)

Retrieve and load MPLNET 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 MPLNET data.

Source code in monetio/readers/mplnet.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 MPLNET 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 MPLNET 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=mplnet_preprocess, **kwargs)

    return ds

mplnet_preprocess(ds)

Preprocess MPLNET dataset: standardize coordinates and dimensions.

Parameters:

Name Type Description Default
ds Dataset

Input MPLNET dataset.

required

Returns:

Type Description
Dataset

Preprocessed dataset.

Source code in monetio/readers/mplnet.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
84
def mplnet_preprocess(ds: xr.Dataset) -> xr.Dataset:
    """
    Preprocess MPLNET dataset: standardize coordinates and dimensions.

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

    Returns
    -------
    xr.Dataset
        Preprocessed dataset.
    """
    # 1. Standardize Time
    # MPLNET often has 'time' as double (days since start of year or similar)
    # but modern V3 should be CF compliant and xarray should handle it.
    # If not, we might need custom logic.

    # 2. Rename Dimensions/Coordinates
    rename_vars = {}
    if "surface_altitude" in ds.variables:
        rename_vars["surface_altitude"] = "elevation"

    if rename_vars:
        ds = ds.rename_vars(rename_vars)

    # 3. Unit Conversions
    # elevation (surface_altitude) is in km in MPLNET V3
    if "elevation" in ds.coords or "elevation" in ds.data_vars:
        if ds["elevation"].attrs.get("units") == "km":
            ds["elevation"] = ds["elevation"] * 1000.0
            ds["elevation"].attrs["units"] = "m"

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

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

    return ds