AusClimateService / plotting_maps

Standardising hazard maps for ACS
4 stars 1 forks source link

Map options for station based data #3

Closed xenct closed 1 month ago

xenct commented 1 month ago

Currently, the ACS plotting function is designed for gridded data. However, some of our hazard teams have station-based data. It would be good to enable station-based data to be plotted consistently with other hazard data. Examples of data may include coastal tidal gauges or land weather stations.

The enhancement woulbe be able to take a dataframe of station_ids, lats, lons, values and plot it on the map. Size and colour parameters can be used for two different parameters simultaneously eg frequency and magnitude.

plt.scatter might be useful. Can use size (s) and colour (c) for data on lat lon projection (https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.scatter.html)

plotly express might be useful (https://plotly.com/python/scatter-plots-on-maps/)

The following snippet might be helpful:

norm = BoundaryNorm(levels, len(levels)-1)
projection = ccrs.PlateCarree()
fig = plt.figure()
ax = fig.add_subplot(1,1,1, projection=projection)
ax.set_extent([135,155,-45,-30]) 
ax.scatter(lons, lats, transform = projection, c = colors, marker = 'o', cmap = cmap, norm = norm, edgecolors = 'k')
bhague commented 1 month ago

the code is here: https://github.com/AusClimateService/hazards-coastal/blob/main/NCRA_flood-days.py. The data files on NCI (/g/data/ia39/ncra/coastal/flood_days) should already have the lat/lons with them (otherwise you can download them here: https://thredds.nci.org.au/thredds/fileServer/fx31/publications/ANCHORS/pdfs/ANCHORS_latlon.csv The code I used to plot them (also at /g/data/ia39/ncra/coastal/flood_days) starts at Line 167 in the github script.

xenct commented 1 month ago

Thanks for pointing me to your data, Ben @bhague.

I have updated the plotting script only in this branch for now: https://github.com/AusClimateService/plotting_maps/blob/plotting_scatter_3/acs_plotting_maps.py

Check this out!

from acs_plotting_maps import plot_acs_hazard, regions_dict, cmap_dict, tick_dict
import xarray as xr
import pandas as pd
import matplotlib.cm as cm
import matplotlib.pyplot as plt
import numpy as np

df = pd.read_csv("/g/data/ia39/ncra/coastal/flood_days/annmax_exceeds_means.csv")
var = "0.06m 90th percentile"

plot_acs_hazard(station_df=df[["lat", "lon", var]],
                regions = regions_dict['ncra_regions'],
                facecolor="lightgrey",
                cmap=cm.viridis_r,
                ticks=np.arange(0,18,3),
                cbar_extend="max",
                title = "Annual exceedances of minor impact level",
                date_range = "0.06m",
                cbar_label = "annual exceedances [days]",
                dataset_name = "BARPA-R ACCESS-CM2",
                outfile = "figures/out.png");

out (1)

example in this branch https://github.com/AusClimateService/plotting_maps/blob/plotting_scatter_3/minimal_plotting_example_station.ipynb

I'll do further testing and documenting before merging it with main.