Skip to content

Provide nice default colormaps for precip data #112

Description

@cchwala

We could add some nice default colormaps for precip. I took one from the MeteoSwiss colorscale from here and tried it out

from matplotlib.colors import ListedColormap
import numpy as np

colors = {
    "precip4_11lev": [[254.0,254.0,254.0],[223.0,255.0,249.0],[154.0,217.0,202.0],[103.0,194.0,163.0],[64.0,173.0,117.0],[50.0,166.0,150.0],[90.0,160.0,205.0],[66.0,146.0,199.0],[76.0,141.0,196.0],[7.0,47.0,107.0],[7.0,30.0,70.0],[76.0,0.0,115.0]],
    "precip_11lev":[[255.0,255.0,255.0],[237.0,250.0,194.0],[205.0,255.0,205.0],[153.0,240.0,178.0],[83.0,189.0,159.0],[50.0,166.0,150.0],[50.0,150.0,180.0],[5.0,112.0,176.0],[5.0,80.0,140.0],[10.0,31.0,150.0],[44.0,2.0,70.0],[106.0,44.0,90.0]],
    "precip_diff_12lev":[[182.0,106.0,40.0],[205.0,133.0,63.0],[225.0,165.0,100.0],[245.0,205.0,132.0],[245.0,224.0,158.0],[255.0,245.0,186.0],[255.0,255.0,255.0],[205.0,255.0,205.0],[153.0,240.0,178.0],[83.0,189.0,159.0],[110.0,170.0,200.0],[5.0,112.0,176.0],[2.0,56.0,88.0]],
}

def cmap(name):
    data = np.array(colors[name])
    data = data / np.max(data)
    cmap = ListedColormap(data, name=name)
    return cmap

plg.plot_map.plot_plg(
    da_grid=ds_rad.R.resample(time='1h').mean().sum(dim="time"),
    da_gauges=ds_gauges_municp.rainfall_amount.sum(dim='time'),
    da_cmls=ds_cmls,
    vmin=0,
    vmax=80,
    cmap=cmap('precip_11lev'),
    kwargs_cmls_plot={"line_color": "k", "line_width": 1},
    kwargs_gauges_plot={"edge_color": 'w'},
)
Image

In this issue we could collect and discuss good options and then implement some in poligrain.

Note that I would not add one of the packages which provide additional matplotlib colormaps because, then again there is a too broad variety of options to chose from. I would prefer to have maybe two options for rainfall intensity (low- strong -heavy, so this could go from light blue to dark blue and then maybe red or violet) and two for rainfall sums (dry - wet - wetter, so this could go from brownish to blueish)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions