AusClimateService / plotting_maps

Standardising hazard maps for ACS
4 stars 1 forks source link

Add stippling to maps #2

Closed xenct closed 1 month ago

xenct commented 2 months ago

It may be useful to have stippling available for anomaly maps to show how many models agree with the direction of change. This link might be helpful for contour hatching contourf_hatching The required code might look like this:

ax1.contourf(x, y, z, hatches=['..',], cmap='gray', alpha=0.5)

It probably only needs to work on a True/False mask.

xenct commented 1 month ago

I have added this line to acs_plotting_maps.py to apply stippling to the maps. stippling is a True/False mask.

ax.contourf(stippling.lon, stippling.lat, stippling, 
            alpha=0, 
            hatches = ["",".."],
            zorder=4, 
            transform=ccrs.PlateCarree(),
            )

This is an an example of its use.

Note that stippling_mask = ds[var]>42 is a bit of a dummy mask. The intended use is for indicating significance or agreement across models.

import numpy as np
from matplotlib.colors import ListedColormap
from acs_plotting_maps import plot_acs_hazard, regions_dict, cmap_dict, tick_dict
import xarray as xr

filename = "/g/data/ia39/ncra/heat/data/HWAtx/bias-corrected/ensemble/GWL-average/\
HWAtx_AGCD-05i_MME50_ssp370_v1-r1-ACS-QME-AGCD-1960-2022_GWL12.nc"
ds = xr.open_dataset(filename)
var = "HWAtx"
stippling_mask = ds[var]>42

plot_acs_hazard(data = ds[var],
                stippling=stippling_mask,
                regions = regions_dict['ncra_regions'],
                title = "title",
                date_range = "GWL12",
                cmap = cmap_dict["tasmax"],
                ticks = np.arange(18,53,2),
                cbar_label = "degC",
                cbar_extend = "both",                
                dataset_name = "",
                outfile = "figures/out.png",
               watermark_color="k");

stippling