Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Reading netCDF4 with xarray

import xarray as xr
import matplotlib.pyplot as plt

ds = xr.open_dataset("smi.20260210.t12z.6000m.d-mssm.global.v0201.nc")

# Apply scale factor (xarray does this automatically if CF conventions are followed)
sm = ds["d_mssm"]

# Mask using the advisory flag
sm_masked = sm.where(ds["aflag"] == 0)

# Plot
sm_masked.plot(figsize=(12, 6), cmap="YlGnBu")
plt.title("D-MSSM — 2026-02-10")
plt.show()

Interpreting quality flags

qflag_value = 42  # Example value

# D-MSSM flag definitions (7 bits)
mssm_flags = [
    "Complex topography",
    "Urban area",
    "Water body",
    "Precipitation",
    "Snow and ice",
    "Freeze/thaw",
    "Dense vegetation",
]

for bit, name in enumerate(mssm_flags):
    is_set = bool(qflag_value & (1 << bit))
    print(f"  Bit {bit} ({name}): {'SET' if is_set else 'clear'}")

Reading CSV with pandas

import pandas as pd

df = pd.read_csv("smi.20260210.t12z.6000m.d-mssm.lon_100.5_lat_14.0.v0201.csv")

# Filter for recommended quality
df_clean = df[df["aflag"] == 0]

# Plot time series
df_clean.plot(x="ref_local_time", y="d_mssm", figsize=(10, 4))

Reading GeoTIFF with rasterio

import rasterio
import numpy as np

with rasterio.open("smi.20260210.t12z.6000m.d-mssm.global.v0201.tif") as src:
    data = src.read(1)
    # Apply scale factor
    sm = np.where(data == 255, np.nan, data * 0.005)