#!/usr/bin/env python3
import numpy as np
import xarray as xr

def main():
    months = np.arange(1, 13, dtype=np.int32)
    precip = (np.random.rand(12).astype(np.float32) * 200.0)

    ds = xr.Dataset(
        data_vars={
            "precip": (("month",), precip, {"units": "mm/month", "long_name": "Monthly precipitation"})
        },
        coords={
            "month": ("month", months, {"long_name": "Month of year"})
        },
        attrs={"title": "Example monthly precipitation", "source": "generated by script"},
    )

    ds.to_zarr("foo.zarr", mode="w")
    print("Wrote foo.zarr")

if __name__ == "__main__":
    main()
