import numpy as np
import pandas as pd
import rasterio
from rasterio.transform import from_origin


for year in range(1950, 2023):
    """Go Main Go."""
    img = np.ma.array(np.load(f"{year}.npy"))
    img.mask = np.ma.where(img == 0)
    transform = from_origin(-126, 50, 0.1, 0.1)

    with rasterio.open(
        f"{year}_era5land_maxphour_mm.tif",
        "w",
        driver="GTiff",
        height=img.shape[0],
        width=img.shape[1],
        count=1,
        dtype=str(img.dtype),
        crs="+proj=longlat +datum=WGS84 +no_defs ",
        transform=transform,
    ) as rst:
        rst.write(np.flipud(img), 1)
        rst.write_mask(True)

