I have created a map of a particular climate variable, which has been produced by extracting data from netCDF4 files and converting them into mask arrays. The data is the ensemble mean of 9 CMIP6 models.
I would like to plot over the top of this some hatching that shows the regions where all models are within 1 standard deviation of the mean to show where there is the least variation in model outputs.
The shape of all arrays is (33, 180, 360), where 33 is the number of years the array represents, 180 latitude coordinates and 360 the longitude coordiates. I have then average values for the time so a 2d projection on the map can be made. Code used so far is below:
from netCDF4 import Dataset
import matplotlib
matplotlib.use('agg')
import matplotlib.pyplot as plt
import numpy as np
import os
os.environ["PROJ_LIB"] = "C:/Users/username/miniconda3/Library/share;" #fixr
from mpl_toolkits.basemap import Basemap
from pylab import *
import matplotlib as mpl
from matplotlib import cm
from matplotlib.colors import ListedColormap, LinearSegmentedColormap
#wind
#historicala
fig_index=1
fig = plt.figure(num=fig_index, figsize=(12,7), facecolor='w')
fbot_levels = arange(-0.3, 0.5,0.05)
fname_hist_tauu='C:/Users/userbame/Historical data analysis/Historical/Wind/tauu_hist_ensmean_so.nc'
ncfile_tauu_hist = Dataset(fname_hist_tauu, 'r', format='NETCDF4')
TS2_hist=ncfile_tauu_hist.variables['tauu'][:]
TS2_mean_hist = np.mean(TS2_hist, axis=(0))
LON=ncfile_tauu_hist.variables['LON'][:]
LAT=ncfile_tauu_hist.variables['LAT'][:]
ncfile_tauu_hist.close()
lon,lat=np.meshgrid(LON,LAT)
ax1 = plt.axes([0.1, 0.225, 0.5, 0.6])
meridians=[0,1,1,1]
m = Basemap(projection='spstere',lon_0=0,boundinglat=-35)
m.drawcoastlines()
x, y =m(lon,lat)
m.contourf(x,y,TS2_mean_hist , fbot_levels, origin='lower', cmap=cm.RdYlGn)
m.drawparallels(np.arange(-90.,120.,10.),labels=[1,0,0,0]) # draw parallels
m.drawmeridians(np.arange(0.,420.,30.),labels=meridians) # draw meridians
coloraxis = [0.1, 0.1, 0.5, 0.035]
cx = fig.add_axes(coloraxis, label='m', title='Wind Stress/ Pa')
cbar=plt.colorbar(cax=cx,orientation='horizontal',ticks=list(fbot_levels))
plt.savefig('C:/Users/username/Historical data analysis/Historical/Wind/Wind_hist_AP.png')
What I would like some help with is how to extract values for the latitude and longitude coordinates where all model numpy arrays are within one standard deviation of the ensemble mean, as I'm not really sure where to start with this as I still fairly new to python. This is what I have come up with so far to give you an idea of what I mean:
sd_minus_1 = ensemble_mean - stan_dev
sd_plus_1 = ensemble_mean + stan_dev
for mod in model_list:
new_arr = a = numpy.zeros(shape=(180,360))
if sd_minus_1 <= mod <= sd_plus_1:
np.append(neww_arr, mod, axis=None)
I then wish to plot this to create a map that looks something like this:
Any ideas would be greatly appreciated!
Please let me know if you need any more information.