def plot_colat_slice(self, component, colat, valmin, valmax, iteration=0, verbose=True):
#- Some initialisations. ------------------------------------------------------------------
colat = np.pi * colat / 180.0
n_procs = self.setup["procs"]["px"] * self.setup["procs"]["py"] * self.setup["procs"]["pz"]
vmax = float("-inf")
vmin = float("inf")
fig, ax = plt.subplots()
#- Loop over processor boxes and check if colat falls within the volume. ------------------
for p in range(n_procs):
if (colat >= self.theta[p,:].min()) & (colat <= self.theta[p,:].max()):
#- Read this field and make lats & lons. ------------------------------------------
field = self.read_single_box(component,p,iteration)
r, lon = np.meshgrid(self.z[p,:], self.phi[p,:])
x = r * np.cos(lon)
y = r * np.sin(lon)
#- Find the colat index and plot for this one box. --------------------------------
idx=min(np.where(min(np.abs(self.theta[p,:]-colat))==np.abs(self.theta[p,:]-colat))[0])
colat_effective = self.theta[p,idx]*180.0/np.pi
#- Find min and max values. -------------------------------------------------------
vmax = max(vmax, field[idx,:,:].max())
vmin = min(vmin, field[idx,:,:].min())
#- Make a nice colourmap and plot. ------------------------------------------------
my_colormap=cm.make_colormap({0.0:[0.1,0.0,0.0], 0.2:[0.8,0.0,0.0], 0.3:[1.0,0.7,0.0],0.48:[0.92,0.92,0.92], 0.5:[0.92,0.92,0.92], 0.52:[0.92,0.92,0.92], 0.7:[0.0,0.6,0.7], 0.8:[0.0,0.0,0.8], 1.0:[0.0,0.0,0.1]})
cax = ax.pcolor(x, y, field[idx,:,:], cmap=my_colormap, vmin=valmin,vmax=valmax)
#- Add colobar and title. ------------------------------------------------------------------
cbar = fig.colorbar(cax)
if component in UNIT_DICT:
cb.set_label(UNIT_DICT[component], fontsize="x-large", rotation=0)
plt.suptitle("Vertical slice of %s at %i degree colatitude" % (component, colat_effective), size="large")
plt.axis('equal')
plt.show()
#==============================================================================================
#- Plot depth slice.
#==============================================================================================
评论列表
文章目录