def p_cent_rate(data, days=False): """ Inputs: data - xarray dataset climatology including precipitation as either precipitation or as convection_rain and condensation_rain days - instructs if data is in daily or pentad means Returns: dpcentdt - rate of movement of the precipitation centroid dpcentdt2 - rate of acceleration of the precipitation centroid """ # Get total precip try: data['precipitation'] = data.condensation_rain + data.convection_rain except: data['precipitation'] = data.precipitation data['precipitation'] = make_sym(data.precipitation) # Locate precipitation centroid precip_centroid(data) # If units in are days rather than pentads (e.g. for shorter years) convert to pentads if days: dpcentdt = gr.ddt(data.p_cent, secperunit=86400.) * 86400. else: dpcentdt = gr.ddt(data.p_cent) * 86400. dpcentdt2 = gr.ddt(dpcentdt, secperunit=86400.) * 86400. return dpcentdt, dpcentdt2
def rate_at_eq(runs, do_make_sym=True, days=None): dpdt_eq = [] if days == None: days = [False] * len(runs) j = 0 for run in runs: data = xr.open_dataset('/disca/share/rg419/Data_moist/climatologies/' + run + '.nc') if do_make_sym: # If symmetric data is wanted, average over both hemispheres (NB currently only set up for a climatology 2/05/18) data['precipitation'] = make_sym(data.precipitation) # Locate precipitation centroid precip_centroid(data) # Get rate of movement of precip centroid if days[j]: dpcentdt = gr.ddt(data.p_cent, secperunit=86400.) * 86400. else: dpcentdt = gr.ddt(data.p_cent) * 86400. #dpcentdt_max = dpcentdt_pmask.where(dpcentdt_pmask==dpcentdt_pmask.max('xofyear'),drop=True) # Find the maximum rate p_cent = np.abs(data.p_cent.where(dpcentdt >= 0.)) dpdt_eq_j = dpcentdt.where(p_cent == p_cent.min('xofyear'), drop=True) dpdt_eq.append(dpdt_eq_j.values[0]) j = j + 1 return np.asarray(dpdt_eq)
def abs_vort_dt_at_pcent(run, rot_fac=1., lev=150.,lat_bound=45., res=0.01, interp=True): '''Calculate the (normalised) vorticity tendency at the precipitation centroid''' data = xr.open_dataset('/disca/share/rg419/Data_moist/climatologies/' + run + '.nc') # Interpolate in time if wanted if interp: times_new = np.arange(1., 72.2, 0.2) precip_new = time_interp(data.precipitation, times_new) u_new = time_interp(data.ucomp.sel(pfull=lev), times_new) v_new = time_interp(data.vcomp.sel(pfull=lev), times_new) else: precip_new = data.precipitation u_new = data.ucomp.sel(pfull=lev) v_new = data.vcomp.sel(pfull=lev) # Find precipitation centroid precip_new = make_sym(precip_new) data = xr.Dataset({'precipitation': precip_new}, coords=precip_new.coords) precip_centroid(data, lat_bound=lat_bound, res=res) # Calculate vorticity v_dx = gr.ddx(v_new) # dvdx u_dy = gr.ddy(u_new) # dudy omega = 7.2921150e-5 * rot_fac f = 2 * omega * np.sin(data.lat *np.pi/180) vor = (v_dx - u_dy + f)*86400. div = gr.ddx(u_new) + gr.ddy(v_new) stretching_mean = (-86400. * vor * div).mean('lon') vor = make_sym(vor, asym=True) stretching_mean = make_sym(stretching_mean, asym=True) # Take time derivative of absolute vorticity if interp: dvordt = gr.ddt(vor.mean('lon'))*86400.*5. else: dvordt = gr.ddt(vor.mean('lon'))*86400. # Also normalise this by the value of vorticity dvordtvor = dvordt/vor.mean('lon') #dvordtvor = stretching_mean/vor.mean('lon') # Interpolate vorticity in latitude to match precipitation centroid lats lats = [data.lat[i] for i in range(len(data.lat)) if data.lat[i] >= -lat_bound and data.lat[i] <= lat_bound] lats_new = np.arange(-lat_bound, lat_bound+res, res) stretching_mean = lat_interp(stretching_mean.sel(lat=lats), lats_new) dvordt = lat_interp(dvordt.sel(lat=lats), lats_new) dvordtvor = lat_interp(dvordtvor.sel(lat=lats), lats_new) # Get and return dvordt and dvordtvor at the precipitation centroid, as well as the precipitation centroid itself st_pcent = [float(stretching_mean[i,:].sel(lat=data.p_cent.values[i]).values) for i in range(len(data.xofyear))] st_pcent = xr.DataArray(np.asarray(st_pcent), coords=[stretching_mean.xofyear.values], dims=['xofyear']) dvordt_pcent = [float(dvordt[i,:].sel(lat=data.p_cent.values[i]).values) for i in range(len(data.xofyear))] dvordt_pcent = xr.DataArray(np.asarray(dvordt_pcent), coords=[dvordt.xofyear.values], dims=['xofyear']) dvordtvor_pcent = [float(dvordtvor[i,:].sel(lat=data.p_cent.values[i]).values) for i in range(len(data.xofyear))] dvordtvor_pcent = xr.DataArray(np.asarray(dvordtvor_pcent), coords=[dvordtvor.xofyear.values], dims=['xofyear']) return dvordt_pcent, dvordtvor_pcent, data.p_cent, st_pcent
def abs_vort_at_pcent_plot(runs, rot_facs, colors, ax=None, lev=150., filename='abs_vort_dtvor_pcent', interp=True, dvordt=False, period_facs=None): plot_dir = '/scratch/rg419/plots/paper_2_figs/' mkdir = sh.mkdir.bake('-p') mkdir(plot_dir) rcParams['figure.figsize'] = 6.5, 4 rcParams['font.size'] = 14 if ax==None: fig = plt.figure() ax1 = fig.add_subplot(111) ax=ax1 if period_facs==None: period_facs = [1.]*len(runs) for i in range(len(runs)): dvordt_pcent, dvordtvor_pcent, pcent, st_pcent = abs_vort_dt_at_pcent(runs[i], rot_facs[i], interp=interp) if interp: dpcentdt = gr.ddt(pcent)*86400.*5.*period_facs[i] else: dpcentdt = gr.ddt(pcent)*86400.*period_facs[i] times = [dvordt_pcent.xofyear[j] for j in range(len(dvordt_pcent.xofyear)) if dvordt_pcent.xofyear[j] >= 40*period_facs[i] and dvordt_pcent.xofyear[j] <= 55*period_facs[i]] #times = [dvordt_pcent.xofyear[i] for i in range(len(dvordt_pcent.xofyear)) if dvordt_pcent.xofyear[i] >= 0 and dvordt_pcent.xofyear[i] <= 10000] dvordtvor_pcent = dvordtvor_pcent.where(((dvordtvor_pcent < 0.02) & (dvordtvor_pcent > -0.04))) if dvordt: #ax.plot(dpcentdt.sel(xofyear=times), dvordt_pcent.sel(xofyear=times), color=colors[i], linewidth=2) ax.plot(pcent.sel(xofyear=times), dvordt_pcent.sel(xofyear=times), color=colors[i], linewidth=2) ax.set_ylabel('d$\zeta$/dt at precip. centroid') else: ax.plot(dpcentdt.sel(xofyear=times), dvordtvor_pcent.sel(xofyear=times), color=colors[i], linewidth=2) #ax.plot(pcent.sel(xofyear=times), dvordtvor_pcent.sel(xofyear=times), color=colors[i], linewidth=2) ax.set_ylim([-0.04,0.02]) #ax.set_ylim([-0.1,0.1]) ax.set_ylabel('$1/(f+\zeta)$*d$\zeta$/dt at ITCZ') ax.set_xlabel('ITCZ migration rate') ax.set_xlim([0.,0.6]) ax.grid(True,linestyle=':') box = ax.get_position() ax.set_position([box.x0, box.y0, box.width * 0.85, box.height]) legend = ax.legend(rot_facs, bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0., title='$\Omega$/$\Omega_{E}$', fontsize=10) legend.get_title().set_fontsize(10) if ax==None: plt.subplots_adjust(left=0.18, right=0.8, top=0.95, bottom=0.15) plt.savefig(plot_dir+filename+'.pdf', format='pdf') plt.close()
def p_cent_rate(data, days=False): # Locate precipitation centroid precip_centroid(data) # If units in are days rather than pentads (e.g. for shorter years) convert to pentads if days: data['xofyear'] = data['xofyear'] / 5. # Get rate of movement of precip centroid dpcentdt = gr.ddt(data.p_cent) * 86400. dpcentdt2 = gr.ddt(dpcentdt, secperunit=86400.) * 86400. return dpcentdt, dpcentdt2
def p_cent_rate_max(runs, days=None): # Get the maximum rate of change of the precipitation centroid latitude, and the latitude at which this occurs. max_rate = [] max_rate_lat = [] if days==None: days=[False]*len(runs) j=0 for run in runs: # Open dataset data = xr.open_dataset('/scratch/rg419/Data_moist/climatologies/' + run + '.nc') # Get total precip try: data['precipitation'] = data.condensation_rain + data.convection_rain except: data['precipitation'] = data.precipitation data['precipitation'] = make_sym(data.precipitation) # Locate precipitation centroid precip_centroid(data) # Get rate of movement of precip centroid if days[j]: dpcentdt = gr.ddt(data.p_cent, secperunit = 86400.) * 86400. else: dpcentdt = gr.ddt(data.p_cent) * 86400. dpcentdt_ppos = dpcentdt.where(data.p_cent>=0.) # Find precip centroid rate where precip centroid is in the northern hemisphere dpcentdt_max = dpcentdt_ppos.where(dpcentdt_ppos==dpcentdt_ppos.max(),drop=True) # Find the maximum of the above if len(dpcentdt_max) > 1: dpcentdt_max = dpcentdt_max[0] pcent_dtmax = data.p_cent.sel(xofyear=dpcentdt_max.xofyear) # Find the location of the preciptiation when the rate is maximum print(dpcentdt_max.values, pcent_dtmax.values) # Print both max_rate.append(dpcentdt_max) max_rate_lat.append(pcent_dtmax) j=j+1 max_rate = np.asarray(max_rate) max_rate_lat = np.asarray(max_rate_lat) return max_rate, max_rate_lat
def get_pcent_ellipse(data, check=True): # Input: climatology of Isca run precipitation # Output: parameters for an ellipse describing the relation between the precipitation centroid and its rate of movement. precip_centroid(data) dpcentdt = gr.ddt(data.p_cent) * 86400. lsqe = el.LSqEllipse() lsqe.fit([data.p_cent.values, dpcentdt.values]) center, width, height, phi = lsqe.parameters() if check: plt.close('all') fig = plt.figure(figsize=(6,6)) ax = fig.add_subplot(111) ax.plot(data.p_cent, dpcentdt, 'ro', label='test data', zorder=1) ellipse = Ellipse(xy=center, width=2*width, height=2*height, angle=np.rad2deg(phi), edgecolor='b', fc='None', lw=2, label='Fit', zorder = 2) ax.add_patch(ellipse) plt.legend() plt.show() return center, width, height, phi
def fig_9(run, ax, pentad=40, lev=850.): data = xr.open_dataset('/disca/share/rg419/Data_moist/climatologies/' + run + '.nc') heating = (data.dt_tg_condensation + data.dt_tg_convection + data.dt_tg_diffusion + data.tdt_rad).mean('lon') * 86400. rho = data.pfull * 100. / mc.rdgas / data.temp dtdy = gr.ddy(data.temp.mean('lon'), vector=False) dtdp = gr.ddp(data.temp.mean('lon')) dtdt = gr.ddt(data.temp.mean('lon')) * 86400. vt_eddy = data.vcomp_temp.mean( 'lon') - data.vcomp.mean('lon') * data.temp.mean('lon') wt_eddy = data.omega_temp.mean( 'lon') - data.omega.mean('lon') * data.temp.mean('lon') vdtdy_mean = -1. * data.vcomp.mean('lon') * dtdy * 86400. wdtdp_mean = -1. * data.omega.mean('lon') * dtdp * 86400. expansion_term = (data.omega / rho / mc.cp_air).mean('lon') * 86400. div_vt_eddy = -1. * gr.ddy(vt_eddy, vector=True) * 86400. div_wt_eddy = -1. * gr.ddp(wt_eddy) * 86400. lats = [ data.lat[i] for i in range(len(data.lat)) if data.lat[i] >= -40. and data.lat[i] <= 40. ] heating.sel(pfull=lev, xofyear=pentad, lat=lats).plot(ax=ax, color='k') dtdt.sel(pfull=lev, xofyear=pentad, lat=lats).plot(ax=ax, color='k', linestyle=':') #vdtdy_mean.sel(pfull=lev, xofyear=pentad, lat=lats).plot(ax=ax, color='C1') #(wdtdp_mean + heating).sel(pfull=lev, xofyear=pentad, lat=lats).plot(ax=ax, color='C2') expansion_term.sel(pfull=lev, xofyear=pentad, lat=lats).plot(ax=ax, color='C1') (vdtdy_mean + wdtdp_mean + expansion_term).sel(pfull=lev, xofyear=pentad, lat=lats).plot( ax=ax, color='k', linestyle='--') #vdtdy_mean.sel(pfull=lev, xofyear=pentad, lat=lats).plot(ax=ax, color='C2', linestyle='--') #wdtdp_mean.sel(pfull=lev, xofyear=pentad, lat=lats).plot(ax=ax, color='C3', linestyle='--') #(vdtdy_mean + wdtdp_mean + expansion_term).sel(pfull=lev, xofyear=pentad, lat=lats).plot(ax=ax, color='k', linestyle='--') #(-dthetadt + vdthetady_mean + wdthetadp_mean + heating_theta + div_vt_eddy + div_wt_eddy).sel(pfull=lev, xofyear=pentad, lat=lats).plot(ax=ax, color='k', linestyle=':') (div_vt_eddy + div_wt_eddy).sel(pfull=lev, xofyear=pentad, lat=lats).plot(ax=ax, color='k', linestyle='-.') ax.set_title('') ax.set_xlabel('') #ax.set_ylim(-0.25,0.25) ax.set_ylim(-5., 5.) ax.set_xlim(-30., 30.) ax.grid(True, linestyle=':') ax.set_ylabel('Heating rate, K/day')
def bootstrap_method(data, days=False): max_rate = [] max_rate_lat = [] max_lat = [] eq_rate = [] for boot in range(1000): print(boot) sample = bootstrap_sample(data.year_no.size) precip_sample = data.sel(year_no=sample).mean('year_no') precip_centroid(precip_sample) # Next step is to unpick pcent_rate_max function so that you can just hand it the data for the sample mean # Get the numbers for 1000 or so samples, find 5 and 95 percentile if days: dpcentdt = gr.ddt(precip_sample.p_cent, secperunit=86400.) * 86400. else: dpcentdt = gr.ddt(precip_sample.p_cent) * 86400. dpcentdt_ppos = dpcentdt.where( precip_sample.p_cent >= 0. ) # Find precip centroid rate where precip centroid is in the northern hemisphere dpcentdt_max = dpcentdt_ppos.where( dpcentdt_ppos == dpcentdt_ppos.max('xofyear'), drop=True) dpcentdt_max = dpcentdt_max[0] pcent_max = precip_sample.p_cent.max('xofyear') pcent_dtmax = precip_sample.p_cent.sel( xofyear=dpcentdt_max.xofyear ) # Find the location of the preciptiation when the rate is maximum p_cent_abs = np.abs(precip_sample.p_cent.where(dpcentdt >= 0.)) dpdt_eq = (dpcentdt.where(p_cent_abs == p_cent_abs.min('xofyear'), drop=True)).values[0] #dpdt_eq = dpcentdt.where(precip_sample.p_cent == precip_sample.p_cent.min('xofyear'), drop=True).max() max_rate.append(float(dpcentdt_max.values)) max_rate_lat.append(float(pcent_dtmax.values)) max_lat.append(float(pcent_max.values)) eq_rate.append(float(dpdt_eq)) return max_rate, max_rate_lat, max_lat, eq_rate
def get_budget_terms(energy, uenergy, venergy, wenergy, diab): u_e_eddy = uenergy - energy * data.ucomp v_e_eddy = venergy - energy * data.vcomp w_e_eddy = wenergy - energy * data.omega eddy_conv = -1.*(gr.ddx(u_e_eddy) + gr.ddy(v_e_eddy) + gr.ddp(w_e_eddy)) horiz_adv = -1.*(data.ucomp * gr.ddx(energy) + data.vcomp * gr.ddy(energy, vector=False)) denergydt = gr.ddt(energy)*20. total = (diab + horiz_adv + vert_adv + eddy_conv)*10. return diab, horiz_adv, vert_adv, eddy_conv, denergydt, total
def fig_8(run, ax, pentad=45, rotfac=1., dayfac=1.): data = xr.open_dataset('/disca/share/rg419/Data_moist/climatologies/' + run + '.nc') heating = data.dt_tg_condensation + data.dt_tg_convection + data.dt_tg_diffusion + data.tdt_rad convTtotheta=(1000./data.pfull)**mc.kappa theta = data.temp*convTtotheta heating_theta = heating*convTtotheta dthetady = gr.ddy(theta.mean('lon'), vector=False) dthetadp = gr.ddp(theta.mean('lon')) dthetadt = gr.ddt(theta.mean('lon')) vdthetady_mean = data.vcomp.mean('lon') * dthetady wdthetadp_mean = data.omega.mean('lon') * dthetadp adv_heating = -1. *(vdthetady_mean + wdthetadp_mean) sinphi = np.sin(data.lat * np.pi/180.) cosphi = np.cos(data.lat * np.pi/180.) w_850 = data.omega.sel(pfull=850.).mean('lon') w_max, w_max_lat = get_latmax(-1.*w_850) theta_850 = theta.sel(pfull=850.).mean('lon') theta_max, theta_max_lat = get_latmax(theta_850) sinphimax = np.sin(theta_max_lat * np.pi/180.) theta_m = theta_max - 300.*(mc.omega * rotfac)**2.*mc.a**2./(2.*mc.grav*14000.) * (sinphi**2.-sinphimax**2.)**2./cosphi**2. def adj_theta(theta_in, adj_by, dayfac=dayfac): if 'lon' in adj_by.coords: return theta_in + adj_by.sel(pfull=850.).mean('lon') * 86400. * dayfac else: return theta_in + adj_by.sel(pfull=850.) * 86400. * dayfac theta_rc = adj_theta(theta_850, heating_theta) theta_adv = adj_theta(theta_850, adv_heating) theta_net = adj_theta(theta_850, dthetadt, dayfac=20.) lats = [data.lat[i] for i in range(len(data.lat)) if data.lat[i] >= -60. and data.lat[i] <= 60.] theta_m.sel(xofyear=pentad, lat=lats).plot(ax=ax, color='0.7') theta_rc.sel(xofyear=pentad, lat=lats).plot(ax=ax, color='k', linestyle='--') theta_adv.sel(xofyear=pentad, lat=lats).plot(ax=ax, color='k', linestyle='-.') theta_850.sel(xofyear=pentad, lat=lats).plot(ax=ax, color='C0') theta_net.sel(xofyear=pentad, lat=lats).plot(ax=ax, color='C2') ax.plot([w_max_lat.sel(xofyear=pentad),w_max_lat.sel(xofyear=pentad)], [295,315], color='0.7', linestyle=':') ax.set_title('') ax.set_xlabel('') ax.set_ylim(295.,315.) ax.set_xlim(-35.,35.) ax.grid(True,linestyle=':') ax.set_ylabel('$\Theta$, K')
def fig_9(run, ax, pentad=40): data = xr.open_dataset('/disca/share/rg419/Data_moist/climatologies/' + run + '.nc') convTtotheta=(1000./data.pfull)**mc.kappa heating = data.dt_tg_condensation + data.dt_tg_convection + data.dt_tg_diffusion + data.tdt_rad rho = data.pfull*100./mc.rdgas/data.temp heating_theta = (heating*convTtotheta).mean('lon') theta = data.temp*convTtotheta dthetady = gr.ddy(theta.mean('lon'), vector=False) dthetadp = gr.ddp(theta.mean('lon')) dthetadt = gr.ddt(theta.mean('lon')) vcomp_theta = data.vcomp_temp*convTtotheta vcomp_theta_eddy = vcomp_theta.mean('lon') - data.vcomp.mean('lon')*theta.mean('lon') vdthetady_mean = data.vcomp.mean('lon') * dthetady wdthetadp_mean = data.omega.mean('lon') * dthetadp def column_int(var_in): var_int = mc.cp_air * var_in.sum('pfull')*5000./mc.grav return var_int vdtdy_mean_int = -1. * column_int(vdthetady_mean) wdtdp_mean_int = -1. * column_int(wdthetadp_mean) vt_eddy_int = -1. * column_int(vcomp_theta_eddy) div_vt_eddy_int = gr.ddy(vt_eddy_int, vector=True) w_850 = data.omega.sel(pfull=850.).mean('lon') w_max, w_max_lat = get_latmax(-1.*w_850) heating_theta_int = column_int(heating_theta) dthetadt_int = column_int(dthetadt) lats = [data.lat[i] for i in range(len(data.lat)) if data.lat[i] >= -40. and data.lat[i] <= 40.] dthetadt_int.sel(xofyear=pentad, lat=lats).plot(ax=ax, color='C2') heating_theta_int.sel(xofyear=pentad, lat=lats).plot(ax=ax, color='k', linestyle='--') #wdtdp_mean_int.sel(xofyear=pentad, lat=lats).plot(ax=ax, color='C1') #vdtdy_mean_int.sel(xofyear=pentad, lat=lats).plot(ax=ax, color='k', linestyle='--') (vdtdy_mean_int + wdtdp_mean_int).sel(xofyear=pentad, lat=lats).plot(ax=ax, color='k', linestyle='-.') #(-dthetadt_int + vdtdy_mean_int + wdtdp_mean_int + heating_theta_int + div_vt_eddy_int).sel(xofyear=pentad, lat=lats).plot(ax=ax, color='k', linestyle=':') #(vdtdy_mean_int + wdtdp_mean_int + heating_theta_int + div_vt_eddy_int).sel(xofyear=pentad, lat=lats).plot(ax=ax, color='k', linestyle=':') div_vt_eddy_int.sel(xofyear=pentad, lat=lats).plot(ax=ax, color='k', linestyle=':') ax.plot([w_max_lat.sel(xofyear=pentad),w_max_lat.sel(xofyear=pentad)], [-500.,500.], color='0.7', linestyle=':') ax.set_title('') ax.set_xlabel('') ax.set_ylim(-500.,500.) ax.set_xlim(-35.,35.) ax.grid(True,linestyle=':') ax.set_ylabel('Heating rate, W/m$^2$')
def p_cent_rate(data, days=False): """ Inputs: data - xarray dataset climatology including precipitation as either precipitation or as convection_rain and condensation_rain days - instructs if data is in daily or pentad means Returns: dpcentdt - rate of movement of the precipitation centroid dpcentdt2 - rate of acceleration of the precipitation centroid """ # Get total precip try: data['precipitation'] = data.condensation_rain + data.convection_rain except: data['precipitation'] = data.precipitation precip_temp = np.zeros(data.precipitation.values.shape) n = len(data.xofyear.values) // 2 for i in range(0, n): precip_temp[i, :, :] = (data.precipitation[i, :, :].values + data.precipitation[i + n, ::-1, :].values) / 2. precip_temp[i + n, :, :] = precip_temp[i, ::-1, :] precip_temp = xr.DataArray( precip_temp, coords=[data.xofyear.values, data.lat, data.lon], dims=['xofyear', 'lat', 'lon']) data['precipitation'] = precip_temp # Locate precipitation centroid precip_centroid(data) # If units in are days rather than pentads (e.g. for shorter years) convert to pentads if days: dpcentdt = gr.ddt(data.p_cent, secperunit=86400.) * 86400. else: dpcentdt = gr.ddt(data.p_cent) * 86400. dpcentdt2 = gr.ddt(dpcentdt, secperunit=86400.) * 86400. return dpcentdt, dpcentdt2
def abs_vort_dt_at_pcent(run, rot_fac=1., lev=150., lat_bound=45.): data = xr.open_dataset('/scratch/rg419/Data_moist/climatologies/' + run + '.nc') data['precipitation'] = make_sym(data.precipitation) precip_centroid(data, lat_bound=lat_bound) v_dx = gr.ddx(data.vcomp) # dvdx u_dy = gr.ddy(data.ucomp) # dudy omega = 7.2921150e-5 * rot_fac f = 2 * omega * np.sin(data.lat * np.pi / 180) vor = (v_dx - u_dy + f).sel(pfull=lev) * 86400. vor = make_sym(vor, asym=True) # Take time derivative of absolute vorticity dvordt = gr.ddt(vor.mean('lon')) * 86400. # Select latitudes over which to evaluate precip centroid lats = [ data.lat[i] for i in range(len(data.lat)) if data.lat[i] >= -lat_bound and data.lat[i] <= lat_bound ] dvordt_lats = dvordt.sel(lat=lats).values #f_lats = f.sel(lat=lats).values # Interpolate vorticity tendency and f in latitude lats_new = np.arange(-lat_bound, lat_bound + 0.1, 0.1) fun = spint.interp1d(lats, dvordt_lats, axis=-1, fill_value='extrapolate', kind='quadratic') dvordt_new = fun(lats_new) dvordt = xr.DataArray(dvordt_new, coords=[data.xofyear.values, lats_new], dims=['xofyear', 'lat']) #fun = spint.interp1d(lats, f_lats, axis=-1, fill_value='extrapolate', kind='quadratic') #f_new = fun(lats_new) #f = xr.DataArray(f_new, coords=[lats_new], dims=['lat']) dvordt_pcent = [ float(dvordt[i, :].sel(lat=data.p_cent.values[i]).values) for i in range(len(data.xofyear)) ] #f_pcent = [float(f.sel(lat=data.p_cent.values[i]).values*86400.) for i in range(len(data.xofyear))] dvordt_pcent = xr.DataArray(np.asarray(dvordt_pcent), coords=[data.xofyear.values], dims=['xofyear']) return dvordt_pcent
def plot_bs_fig_9_moist(run, pentads=[35, 40, 45, 50], rotfac=1.): plot_dir = '/scratch/rg419/plots/paper_2_figs/revisions/heatbudg_moist/' mkdir = sh.mkdir.bake('-p') mkdir(plot_dir) rcParams['figure.figsize'] = 5.5, 7. rcParams['font.size'] = 14 data = xr.open_dataset('/disca/share/rg419/Data_moist/climatologies/' + run + '.nc') data['precipitation'] = make_sym(data.precipitation) precip_centroid(data) # Locate precipitation centroid dpcentdt = gr.ddt(data.p_cent) * 86400. p_cent_pos = np.abs(data.p_cent.where(dpcentdt >= 0.)) eq_time = p_cent_pos.xofyear[p_cent_pos.argmin('xofyear').values] peak_rate_time = dpcentdt.xofyear[dpcentdt.argmax('xofyear').values] max_lat_time = data.p_cent.xofyear[data.p_cent.argmax('xofyear').values] edge_loc, psi_max, psi_max_loc = get_edge_psi(data, lev=850., thresh=0., intdown=True) fig, (ax1, ax2, ax3, ax4) = plt.subplots(4, sharex=True) axes = [ax1, ax2, ax3, ax4] pentads = [ eq_time.values, peak_rate_time.values, np.floor((peak_rate_time.values + max_lat_time.values) / 2.), max_lat_time.values ] for i in range(4): fig_9_moist(run, ax=axes[i], pentad=pentads[i]) edge = edge_loc.sel(xofyear=pentads[i]) axes[i].plot([edge, edge], [-250., 250.], 'k:') axes[i].text(20, 240., 'Pentad ' + str(int(pentads[i]))) ax4.set_xlabel('Latitude') #ax1.text(-55, 315., 'a)') #ax2.text(-55, 315., 'b)') #ax3.text(-55, 315., 'c)') #ax4.text(-55, 315., 'd)') plt.subplots_adjust(left=0.15, right=0.95, top=0.97, bottom=0.1) plt.savefig(plot_dir + 'sb08_fig9_moist_' + run + '.pdf', format='pdf') plt.close()
def abs_vort_dt_plot(run, rot_fac=1., lev=150.): data = xr.open_dataset('/scratch/rg419/Data_moist/climatologies/' + run + '.nc') psi = mass_streamfunction(data, a=6376.0e3, dp_in=50.) psi /= 1.e9 data['precipitation'] = make_sym(data.precipitation) precip_centroid(data) v_dx = gr.ddx(data.vcomp) # dvdx u_dy = gr.ddy(data.ucomp) # dudy omega = 7.2921150e-5 * rot_fac f = 2 * omega * np.sin(data.lat * np.pi / 180) vor = (v_dx - u_dy + f).sel(pfull=lev) * 86400. vor = make_sym(vor, asym=True) psi = make_sym(psi, asym=True) # Take time derivative of absolute vorticity dvordt = gr.ddt(vor.mean('lon')) * 86400. plot_dir = '/scratch/rg419/plots/paper_2_figs/abs_vort_dt/' mkdir = sh.mkdir.bake('-p') mkdir(plot_dir) rcParams['figure.figsize'] = 5.5, 4.3 rcParams['font.size'] = 16 fig = plt.figure() ax1 = fig.add_subplot(111) f1 = dvordt.plot.contourf(ax=ax1, x='xofyear', y='lat', levels=np.arange(-0.06, 0.07, 0.01), add_colorbar=False, add_labels=False) psi.sel(pfull=500).plot.contour(ax=ax1, x='xofyear', y='lat', levels=np.arange(-500., 0., 100.), add_labels=False, colors='0.7', linewidths=2, linestyles='--') psi.sel(pfull=500).plot.contour(ax=ax1, x='xofyear', y='lat', levels=np.arange(0., 510., 100.), add_labels=False, colors='0.7', linewidths=2) psi.sel(pfull=500).plot.contour(ax=ax1, x='xofyear', y='lat', levels=np.arange(-1000., 1010., 1000.), add_labels=False, colors='0.5', linewidths=2) data.p_cent.plot.line(color='k', linewidth=2) ax1.set_ylim([-60, 60]) ax1.set_ylabel('Latitude') ax1.set_xticks([12, 24, 36, 48, 60, 72]) ax1.set_yticks([-60, -30, 0, 30, 60]) ax1.set_xlabel('Pentad') ax1.grid(True, linestyle=':') plt.subplots_adjust(left=0.15, right=0.95, top=0.95, bottom=0.05) cb1 = fig.colorbar(f1, ax=ax1, use_gridspec=True, orientation='horizontal', fraction=0.15, pad=0.2, aspect=40) cb1.set_label('Absolute vorticity tendency, day$^{-2}$') plt.savefig(plot_dir + 'abs_vort_dt_' + run + '.pdf', format='pdf') plt.close()
plot_dir = '/scratch/rg419/plots/paper_2_figs/divergence/' mkdir = sh.mkdir.bake('-p') mkdir(plot_dir) # Set figure parameters rcParams['figure.figsize'] = 5.5, 7. rcParams['font.size'] = 14 # Start figure with 4 subplots fig, (ax1, ax2) = plt.subplots(2, 1) div_plot(run, ax=ax1) psi_mean = psi_mean_clim(run) div_pcent, p_cent = div_at_pcent(run, interp=False, rot_fac=rots[i]) dpcentdt = gr.ddt(p_cent) * 86400. #dpcentdt.plot(ax=ax2, color='k', linewidth=2) p_cent.plot(ax=ax2, color='k', linewidth=2) print(run, div_pcent.max('xofyear').values) #a = div_pcent.where(p_cent==np.min(np.abs(p_cent)), drop=True).values #print(run, a) max_div.append(div_pcent.max('xofyear').values) #max_div.append(a) #dpsi_meandt = gr.ddt(psi_mean)*86400./5. #psi_mean.plot(ax=ax2, color='g', linewidth=2) ax2_twin = ax2.twinx() #st_pcent.plot(ax=ax2_twin, color='b', linewidth=2) div_pcent.plot(ax=ax2_twin, color='b', linewidth=2) box = ax2.get_position() ax2.set_position([box.x0, box.y0, box.width * 0.85, box.height])
def abs_vort_dt_plot(run, ax, rot_fac=1., lev=150., dvordt_flag=False): '''Plot dvordt or 1/vor * dvordt''' #Load data data = xr.open_dataset('/disca/share/rg419/Data_moist/climatologies/' + run + '.nc') #Calculate psi to overplot psi = mass_streamfunction(data, a=6376.0e3, dp_in=50.) psi /= 1.e9 psi = make_sym(psi, asym=True) # Make precip symmetric and find the precip centroid data['precipitation'] = make_sym(data.precipitation) precip_centroid(data) # Calculate vorticity v_dx = gr.ddx(data.vcomp) # dvdx u_dy = gr.ddy(data.ucomp) # dudy omega = 7.2921150e-5 * rot_fac f = 2 * omega * np.sin(data.lat *np.pi/180) vor = (v_dx - u_dy + f).sel(pfull=lev)*86400. vor = make_sym(vor, asym=True) # Take time derivative of absolute vorticity dvordt = gr.ddt(vor.mean('lon'))*86400. # Also normalise this by the value of vorticity dvordtvor = dvordt/vor.mean('lon') # Plot! plot_dir = '/scratch/rg419/plots/paper_2_figs/abs_vort_dt/' mkdir = sh.mkdir.bake('-p') mkdir(plot_dir) rcParams['figure.figsize'] = 5.5, 4.3 rcParams['font.size'] = 14 #fig = plt.figure() #ax1 = fig.add_subplot(111) if dvordt_flag: f1 = dvordt.plot.contourf(ax=ax, x='xofyear', y='lat', levels=np.arange(-0.06,0.07,0.01), add_colorbar=False, add_labels=False) else: f1 = dvordtvor.plot.contourf(ax=ax, x='xofyear', y='lat', levels=np.arange(-0.05,0.055,0.005), add_colorbar=False, add_labels=False) #psi.sel(pfull=500).plot.contour(ax=ax, x='xofyear', y='lat', levels=np.arange(-500.,0.,100.), add_labels=False, colors='0.7', linewidths=2, linestyles='--') #psi.sel(pfull=500).plot.contour(ax=ax, x='xofyear', y='lat', levels=np.arange(0.,510.,100.), add_labels=False, colors='0.7', linewidths=2) #psi.sel(pfull=500).plot.contour(ax=ax, x='xofyear', y='lat', levels=np.arange(-1000.,1010.,1000.), add_labels=False, colors='0.5', linewidths=2) data.p_cent.plot.line(ax=ax, color='k', linewidth=2) ax.set_ylim([-60,60]) ax.set_ylabel('Latitude') ax.set_xticks([12,24,36,48,60,72]) ax.set_yticks([-60,-30,0,30,60]) ax.set_xlabel('Pentad') ax.grid(True,linestyle=':') #originalSize = get(gca, 'Position') #set(f1, 'Position', originalSize) #plt.subplots_adjust(left=0.15, right=0.95, top=0.95, bottom=0.05) box = ax.get_position() #ax.set_position([box.x0*1.05, box.y0, box.width, box.height]) axColor = plt.axes([box.x0 + box.width*0.92, box.y0+box.y0*0.12, 0.015, box.height]) #cb1=fig.colorbar(f1, ax=ax, use_gridspec=True, orientation = 'horizontal',fraction=0.15, pad=0.2, aspect=40) #cb1=plt.colorbar(f1, ax=axColor, use_gridspec=True, orientation = 'vertical',fraction=0.15, pad=0.05, aspect=30) cb1=fig.colorbar(f1, cax=axColor, orientation = 'vertical')
def surface_plot(run, lonin=[-1., 361.], diff_run=None, scale_fac=1., do_make_sym=True): rcParams['figure.figsize'] = 12, 10 rcParams['font.size'] = 16 plot_dir = '/scratch/rg419/plots/surface_fluxes/' mkdir = sh.mkdir.bake('-p') mkdir(plot_dir) data = xr.open_dataset('/scratch/rg419/Data_moist/climatologies/' + run + '.nc') data['flux_lw_up'] = data.t_surf**4. * mc.stefan data['dTdt'] = gr.ddt(data.t_surf) * 86400. * scale_fac if do_make_sym: for field in [ 't_surf', 'dTdt', 'flux_sw', 'flux_lw', 'flux_lw_up', 'flux_t', 'flux_lhe' ]: data[field] = make_sym(data[field]) lons = pick_lons(data, lonin) if not diff_run == None: diff_data = xr.open_dataset( '/scratch/rg419/Data_moist/climatologies/' + diff_run + '.nc') data = (data - diff_data).sel(lon=lons).mean('lon') levels_t = np.arange(-10., 11., 1.) levels_dt = np.arange(-0.5, 0.51, 0.05) levels_flux = np.arange(-80., 81., 5.) else: data = data.sel(lon=lons).mean('lon') levels_t = np.arange(250., 311., 1.) levels_dt = np.arange(-0.5, 0.51, 0.01) levels_flux = np.arange(-300., 305., 10.) f, ((ax1, ax2), (ax3, ax4), (ax5, ax6)) = plt.subplots(3, 2, sharex='col', sharey='row') left_column = [ax1, ax3, ax5] bottom_row = [ax5, ax6] all_plots = [ax1, ax2, ax3, ax4, ax5, ax6] #check = data.flux_sw + (data.flux_lw - flux_lw_up) - data.flux_t - data.flux_lhe #check = data.flux_sw - data.flux_lhe data.t_surf.plot.contourf(x='xofyear', y='lat', levels=levels_t, ax=ax1, extend='both', add_labels=False) ax1.set_title('SST') data.dTdt.plot.contourf(x='xofyear', y='lat', ax=ax2, levels=levels_dt, extend='both', add_labels=False, cmap='RdBu_r') ax2.set_title('d(SST)/dt') data.flux_sw.plot.contourf(x='xofyear', y='lat', levels=levels_flux, ax=ax3, extend='both', add_labels=False, cmap='RdBu_r') ax3.set_title('Net downward SW flux') (data.flux_lw - data.flux_lw_up).plot.contourf(x='xofyear', y='lat', levels=levels_flux, ax=ax4, extend='both', add_labels=False, cmap='RdBu_r') ax4.set_title('Net downward LW flux') (-1. * data.flux_t).plot.contourf(x='xofyear', y='lat', levels=levels_flux, ax=ax5, extend='both', add_labels=False, cmap='RdBu_r') #check.plot.contourf(x='xofyear', y='lat', levels=np.arange(-300.,305.,20.), ax=ax5, extend = 'both', add_labels=False, cmap='RdBu_r') ax5.set_title('Downward sensible heat flux') (-1. * data.flux_lhe).plot.contourf(x='xofyear', y='lat', levels=levels_flux, ax=ax6, extend='both', add_labels=False, cmap='RdBu_r') ax6.set_title('Downward latent heat flux') for ax in left_column: ax.set_ylabel('Latitude') for ax in bottom_row: ax.set_xlabel('Pentad') for ax in all_plots: ax.grid(True, linestyle=':') ax.set_xticks([12, 24, 36, 48, 60, 72]) ax.set_ylim([-60, 60]) if not diff_run == None: plt.savefig(plot_dir + 'surface_fluxes_' + run + '_' + diff_run + '.pdf', format='pdf') else: plt.savefig(plot_dir + 'surface_fluxes_' + run + '.pdf', format='pdf') plt.close()
def fig_8(run, ax, pentad=45, lev=200., dayfac=3., rotfac=1.): data = xr.open_dataset('/disca/share/rg419/Data_moist/climatologies/' + run + '.nc') sinphi = np.sin(data.lat * np.pi/180.) cosphi = np.cos(data.lat * np.pi/180.) zeta = 2.* rotfac * mc.omega*sinphi -1.* gr.ddy(data.ucomp.mean('lon')) #* 86400. nu = gr.ddp(data.ucomp.mean('lon')) #* 86400. dzetady = gr.ddy(zeta, vector=False) dzetadp = gr.ddp(zeta) dwdy = gr.ddy(data.omega, vector=False) dvdy = gr.ddy(data.vcomp) dwdp = gr.ddp(data.omega) dzetadt = gr.ddt(zeta) vdzetady_mean = data.vcomp.mean('lon') * dzetady wdzetadp_mean = data.omega.mean('lon') * dzetadp adv_tend = -1. *(vdzetady_mean + wdzetadp_mean) vert_adv = -1.*wdzetadp_mean horiz_adv = -1.*vdzetady_mean stretching = -1.* zeta * dvdy tilting = nu * dwdy eddy_tend = dzetadt - adv_tend - stretching - tilting w_850 = data.omega.sel(pfull=850.).mean('lon') w_max = w_850.min('lat') w_max_lat = data.lat.values[w_850.argmin('lat').values] w_max_lat = xr.DataArray(w_max_lat, coords=[data.xofyear], dims=['xofyear']) cosphimax = np.cos(w_max_lat * np.pi/180.) u_m = rotfac * mc.omega * mc.a * (cosphimax**2. - cosphi**2.)/cosphi zeta_m = 2.*mc.omega*sinphi -1.* gr.ddy(u_m) def adj_zeta(zeta_in, adj_by, dayfac=dayfac): if 'lon' in adj_by.coords: return zeta_in + adj_by.sel(pfull=lev).mean('lon') * 86400.**2. * dayfac else: return zeta_in + adj_by.sel(pfull=lev) * 86400.**2. * dayfac zeta_150 = zeta.sel(pfull=150.)*86400. zeta_adv = adj_zeta(zeta_150, adv_tend); zeta_vadv = adj_zeta(zeta_150, horiz_adv); zeta_hadv = adj_zeta(zeta_150, vert_adv) zeta_stretching = adj_zeta(zeta_150, stretching) zeta_tilting = adj_zeta(zeta_150, tilting) zeta_eddy = adj_zeta(zeta_150, eddy_tend); zeta_net = adj_zeta(zeta_150, dzetadt, dayfac=10.*dayfac) lats = [data.lat[i] for i in range(len(data.lat)) if data.lat[i] >= -60. and data.lat[i] <= 60.] zeta_m.sel(xofyear=pentad, lat=lats).plot(ax=ax, color='0.7', linestyle='-') zeta_stretching.sel(xofyear=pentad, lat=lats).plot(ax=ax, color='k', linestyle='--') zeta_tilting.sel(xofyear=pentad, lat=lats).plot(ax=ax, color='0.7', linestyle='--') zeta_adv.sel(xofyear=pentad, lat=lats).plot(ax=ax, color='k', linestyle='-.') #u_hadv.sel(xofyear=pentad, lat=lats).plot(ax=ax, color='C1', linestyle='-.') #u_vadv.sel(xofyear=pentad, lat=lats).plot(ax=ax, color='C2', linestyle='-.') zeta_eddy.sel(xofyear=pentad, lat=lats).plot(ax=ax, color='k', linestyle=':') zeta_150.sel(xofyear=pentad, lat=lats).plot(ax=ax, color='C0') zeta_net.sel(xofyear=pentad, lat=lats).plot(ax=ax, color='C2') ax.plot([w_max_lat.sel(xofyear=pentad),w_max_lat.sel(xofyear=pentad)], [-7.5,7.5], color='0.7', linestyle=':') ax.set_title('') ax.set_xlabel('') ax.set_xlim(-35.,35.) ax.set_ylim(-7.5,7.5) ax.grid(True,linestyle=':') ax.set_ylabel('zeta, /s')
def bs_mombudg(run, ax, pentad=45, lev=150., dayfac=3., rotfac=1.): data = xr.open_dataset('/disca/share/rg419/Data_moist/climatologies/' + run + '.nc') damping = data.dt_ug_diffusion # + data.tdt_diss_rdamp dudy = gr.ddy(data.ucomp.mean('lon')) duvdy = gr.ddy(data.ucomp_vcomp.mean('lon'), uv=True) dudp = gr.ddp(data.ucomp.mean('lon')) duwdp = gr.ddp(data.ucomp_omega.mean('lon')) dudt = gr.ddt(data.ucomp.mean('lon')) vdudy_mean = data.vcomp.mean('lon') * dudy wdudp_mean = data.omega.mean('lon') * dudp adv_tend = -1. * (vdudy_mean + wdudp_mean) vert_adv = -1. * wdudp_mean horiz_adv = -1. * vdudy_mean eddy_tend = -1. * duvdy - 1. * duwdp - adv_tend vert_eddy = -1. * duwdp - vert_adv horiz_eddy = -1. * duvdy - horiz_adv sinphi = np.sin(data.lat * np.pi / 180.) cosphi = np.cos(data.lat * np.pi / 180.) coriolis = 2. * rotfac * mc.omega * sinphi * data.vcomp def get_latmax(data_in): data_max = data_in.max('lat') data_max_lat = data_in.lat.values[data_in.argmax('lat').values] data_max_lat = xr.DataArray(data_max_lat, coords=[data_in.xofyear], dims=['xofyear']) return data_max, data_max_lat w_850 = data.omega.sel(pfull=850.).mean('lon') w_max, w_max_lat = get_latmax(-1. * w_850) convTtotheta = (1000. / data.pfull)**mc.kappa theta_equiv_850 = ((data.temp + mc.L / mc.cp_air * data.sphum / (1 - data.sphum)) * convTtotheta).sel(pfull=850.).mean('lon') theta_max, theta_max_lat = get_latmax(theta_equiv_850) cosphimax = np.cos(theta_max_lat * np.pi / 180.) u_150 = data.ucomp.sel(pfull=lev).mean('lon') u_m = rotfac * mc.omega * mc.a * (cosphimax**2. - cosphi**2.) / cosphi def adj_u(u_in, adj_by, dayfac=dayfac): if 'lon' in adj_by.coords: return u_in + adj_by.sel(pfull=lev).mean('lon') * 86400. * dayfac else: return u_in + adj_by.sel(pfull=lev) * 86400. * dayfac u_damp = adj_u(u_150, damping) u_cor = adj_u(u_150, coriolis) u_adv = adj_u(u_150, adv_tend) u_vadv = adj_u(u_150, horiz_adv) u_hadv = adj_u(u_150, vert_adv) u_eddy = adj_u(u_150, eddy_tend) u_veddy = adj_u(u_150, horiz_eddy) u_heddy = adj_u(u_150, vert_eddy) resid = coriolis + damping + adv_tend + eddy_tend u_resid = adj_u(u_150, resid, dayfac=10. * dayfac) u_net = adj_u(u_150, dudt, dayfac=10. * dayfac) lats = [ data.lat[i] for i in range(len(data.lat)) if data.lat[i] >= -60. and data.lat[i] <= 60. ] u_m.sel(xofyear=pentad, lat=lats).plot(ax=ax, color='0.7') u_cor.sel(xofyear=pentad, lat=lats).plot(ax=ax, color='k', linestyle='--') u_adv.sel(xofyear=pentad, lat=lats).plot(ax=ax, color='k', linestyle='-.') u_eddy.sel(xofyear=pentad, lat=lats).plot(ax=ax, color='k', linestyle=':') u_150.sel(xofyear=pentad, lat=lats).plot(ax=ax, color='C0') u_net.sel(xofyear=pentad, lat=lats).plot(ax=ax, color='C2') ax.plot([w_max_lat.sel(xofyear=pentad), w_max_lat.sel(xofyear=pentad)], [-75., 75.], color='0.7', linestyle=':') ax.set_title('') ax.set_xlabel('') ax.set_xlim(-35., 35.) ax.set_ylim(-75., 75.) ax.grid(True, linestyle=':') ax.set_ylabel('u, m/s')
def fixed_sst_imbalance(run, lonin=[-1., 361.], mld=10.): # Plot the imbalance between actual rate of change of temperature and that the fluxes should cause for fixed SST expts rcParams['figure.figsize'] = 6, 10 rcParams['font.size'] = 16 plot_dir = '/scratch/rg419/plots/surface_fluxes/' mkdir = sh.mkdir.bake('-p') mkdir(plot_dir) data = xr.open_dataset('/disca/share/rg419/Data_moist/climatologies/' + run + '.nc') lons = pick_lons(data, lonin) data = data.sel(lon=lons).mean('lon') flux_lw_up = data.t_surf**4. * mc.stefan dTdt = gr.ddt(data.t_surf) * 86400. f, (ax1, ax2, ax3) = plt.subplots(3, sharex=True) sum_of_all = (data.flux_sw + (data.flux_lw - flux_lw_up) - data.flux_t - data.flux_lhe) / rho_cp / mld * 86400. dTdt = gr.ddt(data.t_surf) * 86400. f1 = sum_of_all.plot.contourf(x='xofyear', y='lat', levels=np.arange(-1., 1., 0.1), ax=ax1, extend='both', add_labels=False, add_colorbar=False) ax1.set_title('Sum of all fluxes') dTdt.plot.contourf(x='xofyear', y='lat', levels=np.arange(-1., 1., 0.1), ax=ax2, extend='both', add_labels=False, cmap='RdBu_r', add_colorbar=False) ax2.set_title('dTs/dt') (sum_of_all - dTdt).plot.contourf(x='xofyear', y='lat', levels=np.arange(-1., 1., 0.1), ax=ax3, extend='both', add_labels=False, cmap='RdBu_r', add_colorbar=False) ax3.set_title('Fluxes-dTsdt') ax3.set_xlabel('Pentad') for ax in [ax1, ax2, ax3]: ax.set_ylabel('Latitude') ax.grid(True, linestyle=':') plt.subplots_adjust(left=0.2, right=0.95, top=0.95, bottom=0., hspace=0.2) #Colorbar cb1 = f.colorbar(f1, ax=(ax1, ax2, ax3), use_gridspec=True, orientation='horizontal', fraction=0.15, pad=0.07, aspect=30) cb1.set_label('dT/dt, K/day') plt.savefig(plot_dir + 'fixed_sst_imbalance_' + run + '.pdf', format='pdf') plt.close()
def int_flux_plot(run, lonin=[-1., 361.], mld=10.): rcParams['figure.figsize'] = 6, 13.3 rcParams['font.size'] = 16 plot_dir = '/scratch/rg419/plots/surface_fluxes/' mkdir = sh.mkdir.bake('-p') mkdir(plot_dir) data = xr.open_dataset('/disca/share/rg419/Data_moist/climatologies/' + run + '.nc') lons = pick_lons(data, lonin) data = data.sel(lon=lons).mean('lon') flux_lw_up = data.t_surf**4. * mc.stefan dTdt = gr.ddt(data.t_surf) * 86400. def int_flux_fwd(flux): #cp dTdt = SW + LW + LH + SH n = data.t_surf.shape[0] t_out = np.zeros([n, 64]) t_out[0, :] = data.t_surf[0, :] for i in range(n - 1): t_out[i + 1, :] = t_out[i, :] + flux[i, :] / rho_cp / mld * 86400. * 5. t_out = xr.DataArray(t_out, coords=[data.xofyear.values, data.lat.values], dims=['xofyear', 'lat']) return t_out t_all = int_flux_fwd(data.flux_sw - data.flux_lhe + data.flux_lw - flux_lw_up - data.flux_t) t_sw = int_flux_fwd(data.flux_sw + (-data.flux_lhe + data.flux_lw - flux_lw_up - data.flux_t).mean('xofyear')) t_lw = int_flux_fwd(data.flux_sw + data.flux_lw - flux_lw_up - data.flux_lhe.mean('xofyear')) t_lh = int_flux_fwd(data.flux_sw - data.flux_lhe + (data.flux_lw - flux_lw_up).mean('xofyear')) f, (ax1, ax2, ax3, ax4) = plt.subplots(4, sharex=True) f1 = t_all.plot.contourf(x='xofyear', y='lat', levels=np.arange(250., 311., 5.), ax=ax1, extend='both', add_labels=False, add_colorbar=False) ax1.set_title('Sum of all fluxes') f1 = t_sw.plot.contourf(x='xofyear', y='lat', levels=np.arange(250., 311., 5.), ax=ax2, extend='both', add_labels=False, add_colorbar=False) ax2.set_title('SW') t_lw.plot.contourf(x='xofyear', y='lat', levels=np.arange(250., 311., 5.), ax=ax3, extend='both', add_labels=False, add_colorbar=False) ax3.set_title('SW + LHE') t_lh.plot.contourf(x='xofyear', y='lat', levels=np.arange(250., 311., 5.), ax=ax4, extend='both', add_labels=False, add_colorbar=False) ax4.set_title('SW + LW') ax4.set_xlabel('Pentad') for ax in [ax1, ax2, ax3, ax4]: ax.set_ylabel('Latitude') ax.grid(True, linestyle=':') plt.subplots_adjust(left=0.2, right=0.95, top=0.95, bottom=0., hspace=0.2) #Colorbar cb1 = f.colorbar(f1, ax=(ax1, ax2, ax3, ax4), use_gridspec=True, orientation='horizontal', fraction=0.15, pad=0.07, aspect=30) cb1.set_label('Temperature, K') plt.savefig(plot_dir + 'int_flux_plot_' + run + '.pdf', format='pdf') plt.close()
def surf_cooling_plot(run, lonin=[-1., 361.], mld=10.): rcParams['figure.figsize'] = 6, 10 rcParams['font.size'] = 16 plot_dir = '/scratch/rg419/plots/surface_fluxes/' mkdir = sh.mkdir.bake('-p') mkdir(plot_dir) data = xr.open_dataset('/disca/share/rg419/Data_moist/climatologies/' + run + '.nc') lons = pick_lons(data, lonin) data = data.sel(lon=lons).mean('lon') flux_lw_up = data.t_surf**4. * mc.stefan dTdt = gr.ddt(data.t_surf) * 86400. f, (ax1, ax2, ax3) = plt.subplots(3, sharex=True) sum_of_all = (data.flux_sw + (data.flux_lw - flux_lw_up) - data.flux_t - data.flux_lhe) / rho_cp / mld * 86400. sw_and_lhe = (data.flux_sw - data.flux_lhe + (data.flux_lw - flux_lw_up - data.flux_t).mean('xofyear')) / rho_cp / mld * 86400. sw_and_lw = ( data.flux_sw + (data.flux_lw - flux_lw_up) - (data.flux_lhe + data.flux_t).mean('xofyear')) / rho_cp / mld * 86400. f1 = sum_of_all.plot.contourf(x='xofyear', y='lat', levels=np.arange(-1., 1.05, 0.1), ax=ax1, extend='both', add_labels=False, add_colorbar=False) ax1.set_title('Sum of all fluxes') sw_and_lhe.plot.contourf(x='xofyear', y='lat', levels=np.arange(-1., 1.05, 0.1), ax=ax2, extend='both', add_labels=False, cmap='RdBu_r', add_colorbar=False) ax2.set_title('SW + LHE') sw_and_lw.plot.contourf(x='xofyear', y='lat', levels=np.arange(-1., 1.05, 0.1), ax=ax3, extend='both', add_labels=False, cmap='RdBu_r', add_colorbar=False) ax3.set_title('SW + LW') ax3.set_xlabel('Pentad') for ax in [ax1, ax2, ax3]: ax.set_ylabel('Latitude') ax.grid(True, linestyle=':') plt.subplots_adjust(left=0.2, right=0.95, top=0.95, bottom=0., hspace=0.2) #Colorbar cb1 = f.colorbar(f1, ax=(ax1, ax2, ax3), use_gridspec=True, orientation='horizontal', fraction=0.15, pad=0.07, aspect=30) cb1.set_label('Downward flux, W/m^2') plt.savefig(plot_dir + 'surf_cooling_plot_' + run + '.pdf', format='pdf') plt.close()
if __name__ == "__main__": # Set plotting directory plot_dir = '/scratch/rg419/plots/paper_2_figs/' mkdir = sh.mkdir.bake('-p') mkdir(plot_dir) # Set figure parameters rcParams['figure.figsize'] = 10, 9 rcParams['font.size'] = 12 subsolar_point = -23.439 * np.cos(np.arange(0., 361., 1.) * np.pi / 180.) subsolar_point = xr.DataArray(subsolar_point, coords=[np.arange(0., 361., 1.)], dims=['xofyear']) subsolar_rate = gr.ddt(subsolar_point, secperunit=86400.) * 86400. # Start figure with 4 subplots #fig, ((ax1, ax2, ax3), (ax4, ax5, ax6), (ax7, ax8, ax9)) = plt.subplots(3, 3) fig, ((ax1, ax2), (ax3, ax4), (ax5, ax6)) = plt.subplots(3, 2) # Switch on errorbars errorbars = True # Set colors for lines #colors=['b','g','r','c','m','y'] colors = ['C0', 'C1', 'C2', 'C3', 'C4', 'C5'] '''Seasons''' runs_sn = [ 'sn_0.250', 'sn_0.500', 'sn_1.000', 'sn_2.000', 'sn_3.000', 'sn_4.000' ]
def local_pcent_plots(run, regions=[[350, 10], [80, 100], [170, 190], [260, 280]], do_make_sym=True): data = xr.open_dataset('/disca/share/rg419/Data_moist/climatologies/' + run + '.nc') if do_make_sym: data['precipitation'] = make_sym(data.precipitation) data = precip_centroid_ll(data, lat_bound=30.) def get_lons(lonin, data): if lonin[1] > lonin[0]: lons = [ data.lon[i] for i in range(len(data.lon)) if data.lon[i] >= lonin[0] and data.lon[i] < lonin[1] ] else: lons = [ data.lon[i] for i in range(len(data.lon)) if data.lon[i] >= lonin[0] or data.lon[i] < lonin[1] ] return lons lons_1 = get_lons(regions[0], data) lons_2 = get_lons(regions[1], data) lons_3 = get_lons(regions[2], data) lons_4 = get_lons(regions[3], data) dpcentdt_1 = gr.ddt(data.p_cent.sel(lon=lons_1).mean('lon')) * 86400. dpcentdt_2 = gr.ddt(data.p_cent.sel(lon=lons_2).mean('lon')) * 86400. dpcentdt_3 = gr.ddt(data.p_cent.sel(lon=lons_3).mean('lon')) * 86400. dpcentdt_4 = gr.ddt(data.p_cent.sel(lon=lons_4).mean('lon')) * 86400. # Set figure parameters rcParams['figure.figsize'] = 10, 7 rcParams['font.size'] = 14 # Start figure with 4 subplots fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2) ax1.plot(data.p_cent.sel(lon=lons_1).mean('lon'), dpcentdt_1, 'kx', mew=2, ms=10, alpha=0.5) ax1.plot(data.p_cent.sel(lon=lons_1).mean('lon'), dpcentdt_1, alpha=0.3, color='k', linewidth=2) ax1.set_title('West coast') ax2.plot(data.p_cent.sel(lon=lons_2).mean('lon'), dpcentdt_2, 'kx', mew=2, ms=10, alpha=0.5) ax2.plot(data.p_cent.sel(lon=lons_2).mean('lon'), dpcentdt_2, alpha=0.3, color='k', linewidth=2) ax2.set_title('Land') ax3.plot(data.p_cent.sel(lon=lons_3).mean('lon'), dpcentdt_3, 'kx', mew=2, ms=10, alpha=0.5) ax3.plot(data.p_cent.sel(lon=lons_3).mean('lon'), dpcentdt_3, alpha=0.3, color='k', linewidth=2) ax3.set_title('East coast') ax4.plot(data.p_cent.sel(lon=lons_4).mean('lon'), dpcentdt_4, 'kx', mew=2, ms=10, alpha=0.5) ax4.plot(data.p_cent.sel(lon=lons_4).mean('lon'), dpcentdt_4, alpha=0.3, color='k', linewidth=2) ax4.set_title('Ocean') ax3.set_xlabel('ITCZ latitude') ax4.set_xlabel('ITCZ latitude') ax1.set_ylabel('ITCZ migration rate') ax3.set_ylabel('ITCZ migration rate') for ax in [ax1, ax2, ax3, ax4]: ax.grid(True, linestyle=':') ax.set_xlim(-25, 25) ax.set_ylim(-1.0, 1.0) plt.subplots_adjust(left=0.1, right=0.97, top=0.95, bottom=0.1, hspace=0.3, wspace=0.3) # Save as a pdf plt.savefig(plot_dir + 'bowties_' + run + '.pdf', format='pdf') plt.close() # Start figure with 4 subplots fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2) precip_mse_plot(data, ax1, lonin=regions[0], lat_bound=30.) precip_mse_plot(data, ax2, lonin=regions[1], lat_bound=30.) precip_mse_plot(data, ax3, lonin=regions[2], lat_bound=30.) precip_mse_plot(data, ax4, lonin=regions[3], lat_bound=30.) ax1.set_title('West coast') ax2.set_title('Land') ax3.set_title('East coast') ax4.set_title('Ocean') ax3.set_xlabel('Pentad') ax4.set_xlabel('Pentad') ax1.set_ylabel('Latitude') ax3.set_ylabel('Latitude') for ax in [ax1, ax2, ax3, ax4]: ax.grid(True, linestyle=':') plt.subplots_adjust(left=0.1, right=0.97, top=0.95, bottom=0.1, hspace=0.3, wspace=0.3) # Save as a pdf plt.savefig(plot_dir + 'precip_' + run + '.pdf', format='pdf') plt.close() data.close()
def fig_9_moist(run, ax, pentad=40): data = xr.open_dataset('/disca/share/rg419/Data_moist/climatologies/' + run + '.nc') convTtotheta = (1000. / data.pfull)**mc.kappa heating = data.dt_tg_condensation + data.dt_tg_convection + data.dt_tg_diffusion + data.tdt_rad hum_tend = data.dt_qg_condensation + data.dt_qg_convection + data.dt_qg_diffusion heating_theta_equiv = ((heating + mc.L / mc.cp_air * hum_tend / (1 - data.sphum)**2.) * convTtotheta).mean('lon') theta_equiv = (data.temp + mc.L / mc.cp_air * data.sphum / (1 - data.sphum)) * convTtotheta dthetady_equiv = gr.ddy(theta_equiv.mean('lon'), vector=False) dthetadp_equiv = gr.ddp(theta_equiv.mean('lon')) dthetadt_equiv = gr.ddt(theta_equiv.mean('lon')) vcomp_theta_equiv = (data.vcomp_temp + mc.L / mc.cp_air * data.sphum_v) * convTtotheta vcomp_theta_eddy_equiv = vcomp_theta_equiv.mean( 'lon') - data.vcomp.mean('lon') * theta_equiv.mean('lon') vdthetady_mean_equiv = data.vcomp.mean('lon') * dthetady_equiv wdthetadp_mean_equiv = data.omega.mean('lon') * dthetadp_equiv def column_int(var_in): var_int = mc.cp_air * var_in.sum('pfull') * 5000. / mc.grav return var_int vdtdy_mean_int_equiv = -1. * column_int(vdthetady_mean_equiv) wdtdp_mean_int_equiv = -1. * column_int(wdthetadp_mean_equiv) vt_eddy_int_equiv = -1. * column_int(vcomp_theta_eddy_equiv) div_vt_eddy_int_equiv = gr.ddy(vt_eddy_int_equiv, vector=True) heating_theta_int_equiv = column_int(heating_theta_equiv) dthetadt_int_equiv = column_int(dthetadt_equiv) lats = [ data.lat[i] for i in range(len(data.lat)) if data.lat[i] >= -60. and data.lat[i] <= 60. ] w_850 = data.omega.sel(pfull=850.).mean('lon') w_max, w_max_lat = get_latmax(-1. * w_850) dthetadt_int_equiv.sel(xofyear=pentad, lat=lats).plot(ax=ax, color='C2') heating_theta_int_equiv.sel(xofyear=pentad, lat=lats).plot(ax=ax, color='k', linestyle='--') (vdtdy_mean_int_equiv + wdtdp_mean_int_equiv).sel( xofyear=pentad, lat=lats).plot(ax=ax, color='k', linestyle='-.') #(vdtdy_mean_int_equiv + wdtdp_mean_int_equiv + heating_theta_int_equiv + div_vt_eddy_int_equiv).sel(xofyear=pentad, lat=lats).plot(ax=ax, color='k', linestyle=':') div_vt_eddy_int_equiv.sel(xofyear=pentad, lat=lats).plot(ax=ax, color='k', linestyle=':') ax.plot([w_max_lat.sel(xofyear=pentad), w_max_lat.sel(xofyear=pentad)], [-250., 250.], color='0.7', linestyle=':') ax.set_title('') ax.set_xlabel('') ax.set_ylim(-250., 250.) ax.set_xlim(-35., 35.) ax.grid(True, linestyle=':') ax.set_ylabel('Heating rate, W/m$^2$')
def heat_budg_hm_fluxform(run, lev=850, filename='plev_pentad', timeav='pentad', period_fac=1.,lonin=[-1.,361.], plot_precip=True, do_theta=False): rcParams['figure.figsize'] = 12, 8 rcParams['font.size'] = 18 rcParams['text.usetex'] = True plot_dir = '/scratch/rg419/plots/heat_budg/' mkdir = sh.mkdir.bake('-p') mkdir(plot_dir) data = xr.open_dataset('/disca/share/rg419/Data_moist/climatologies/'+run+'.nc') uT_dx = -86400. * gr.ddx(data.ucomp_temp.sel(pfull=lev)).mean('lon') vT_dy = -86400. * gr.ddy(data.vcomp_temp.sel(pfull=lev)).mean('lon') wT_dp = -86400. * gr.ddp(data.omega_temp).sel(pfull=lev).mean('lon') uT_eddy = data.ucomp_temp - data.ucomp * data.temp vT_eddy = data.vcomp_temp - data.vcomp * data.temp wT_eddy = data.omega_temp - data.omega * data.temp #uT_dx = -86400. * (data.ucomp * gr.ddx(data.temp)).sel(pfull=lev).mean('lon') #vT_dy = -86400. * (data.vcomp * gr.ddy(data.temp, vector=False)).sel(pfull=lev).mean('lon') #wT_dp = -86400. * (data.omega * gr.ddp(data.temp)).sel(pfull=lev).mean('lon') uT_dx_eddy = -86400. * gr.ddx(uT_eddy.sel(pfull=lev)).mean('lon') vT_dy_eddy = -86400. * gr.ddy(vT_eddy.sel(pfull=lev)).mean('lon') wT_dp_eddy = -86400. * gr.ddp(wT_eddy).sel(pfull=lev).mean('lon') tdt_rad = data.tdt_rad.sel(pfull=lev).mean('lon')*86400. tdt_conv = data.dt_tg_convection.sel(pfull=lev).mean('lon')*86400. tdt_cond = data.dt_tg_condensation.sel(pfull=lev).mean('lon')*86400. tdt_diff = data.dt_tg_diffusion.sel(pfull=lev).mean('lon')*86400. diabatic = tdt_rad + tdt_conv + tdt_cond + tdt_diff eddies = uT_dx_eddy + vT_dy_eddy + wT_dp_eddy rho = data.pfull*100./data.temp/mc.rdgas asc_cool = (data.omega /(mc.cp_air * rho)).sel(pfull=lev).mean('lon') *86400. heat_sum = uT_dx + vT_dy + wT_dp + diabatic + asc_cool #+ eddies Tdt = gr.ddt(data.temp.sel(pfull=lev)).mean('lon') *86400. horiz_adv = uT_dx + vT_dy vertical_term = wT_dp + asc_cool levels = np.arange(-100,101.1,10.) #levels = np.arange(-20,21.,2.) #levels = np.arange(-3,3.1,0.2) #levels = np.arange(-1,1.1,0.1) # Nine subplots fig, ((ax1, ax2, ax3), (ax4, ax5, ax6)) = plt.subplots(2, 3, sharex='col', sharey='row') plt.set_cmap('RdBu_r') plot_vars = [horiz_adv, vertical_term, diabatic, heat_sum, Tdt, eddies] axes = [ax1,ax2,ax3,ax4,ax5,ax6] labels = ['a)','b)','c)','d)','e)','f)'] for i in range(6): f1=plot_vars[i].plot.contourf(ax=axes[i], x='xofyear', y='lat', extend='both', add_labels=False, cmap='RdBu_r', levels = levels, add_colorbar=False) axes[i].set_ylim(-60,60) axes[i].grid(True,linestyle=':') axes[i].set_yticks(np.arange(-60.,61.,30.)) for i in [0,3]: axes[i].set_ylabel('Latitude') axes[i].text(-15, 60, labels[i]) for i in [1,2,4,5]: axes[i].text(-5, 60, labels[i]) #for i in [3,4,5]: # axes[i].set_xticklabels(ticklabels,rotation=25) # set titles ax1.set_title('Horizontal advection', fontsize=17) ax2.set_title('Vertical advection and expansion', fontsize=17) ax3.set_title('Diabatic', fontsize=17) ax4.set_title('Residual', fontsize=17) ax5.set_title('Temperature tendency', fontsize=17) ax6.set_title('Eddy convergence', fontsize=17) plt.subplots_adjust(right=0.97, left=0.1, top=0.95, bottom=0., hspace=0.25, wspace=0.12) #Colorbar cb1=fig.colorbar(f1, ax=axes, use_gridspec=True, orientation = 'horizontal',fraction=0.15, pad=0.15, aspect=30, shrink=0.5) figname = 'heat_budg_fluxform_' +run+ '.pdf' plt.savefig(plot_dir + figname, format='pdf') plt.close()
def surface_plot(run, lonin=[-1., 361.], diff_run=None, scale_fac=1., do_make_sym=True): print('what?') rcParams['figure.figsize'] = 15, 10 rcParams['font.size'] = 14 plot_dir = '/scratch/rg419/plots/surface_fluxes/' mkdir = sh.mkdir.bake('-p') mkdir(plot_dir) data = xr.open_dataset('/disca/share/rg419/Data_moist/climatologies/' + run + '.nc') #Calculate psi to overplot psi = mass_streamfunction(data, a=6376.0e3, dp_in=50.) psi /= 1.e9 psi = make_sym(psi, asym=True) # Make precip symmetric and find the precip centroid data['precipitation'] = make_sym(data.precipitation) precip_centroid(data) data['flux_lw_up'] = data.t_surf**4. * mc.stefan data['dTdt'] = gr.ddt(data.t_surf) * 86400. * scale_fac if do_make_sym: for field in [ 't_surf', 'dTdt', 'flux_sw', 'flux_lw', 'flux_lw_up', 'flux_t', 'flux_lhe' ]: data[field] = make_sym(data[field]) lons = pick_lons(data, lonin) if not diff_run == None: diff_data = xr.open_dataset( '/disca/share/rg419/Data_moist/climatologies/' + diff_run + '.nc') data = (data - diff_data).sel(lon=lons).mean('lon') levels_t = np.arange(-10., 11., 1.) levels_dt = np.arange(-0.5, 0.51, 0.05) levels_flux = np.arange(-80., 81., 5.) else: data = data.sel(lon=lons).mean('lon') levels_t = np.arange(270., 306., 2.5) levels_dt = np.arange(-0.3, 0.31, 0.05) levels_flux = np.arange(-300., 305., 20.) f, ((ax1, ax2), (ax3, ax4), (ax5, ax6)) = plt.subplots(3, 2, sharex='col', sharey='row') left_column = [ax1, ax3, ax5] bottom_row = [ax5, ax6] all_plots = [ax1, ax2, ax3, ax4, ax5, ax6] #check = data.flux_sw + (data.flux_lw - flux_lw_up) - data.flux_t - data.flux_lhe #check = data.flux_sw - data.flux_lhe data.t_surf.plot.contourf(x='xofyear', y='lat', levels=levels_t, ax=ax1, extend='both', add_labels=False) ax1.set_title('SST') data.dTdt.plot.contourf(x='xofyear', y='lat', ax=ax2, levels=levels_dt, extend='both', add_labels=False, cmap='RdBu_r') ax2.set_title('d(SST)/dt') data.flux_sw.plot.contourf(x='xofyear', y='lat', levels=levels_flux, ax=ax3, extend='both', add_labels=False, cmap='RdBu_r') ax3.set_title('Net downward SW flux') (data.flux_lw - data.flux_lw_up).plot.contourf(x='xofyear', y='lat', levels=levels_flux, ax=ax4, extend='both', add_labels=False, cmap='RdBu_r') ax4.set_title('Net downward LW flux') (-1. * data.flux_t).plot.contourf(x='xofyear', y='lat', levels=levels_flux, ax=ax5, extend='both', add_labels=False, cmap='RdBu_r') #check.plot.contourf(x='xofyear', y='lat', levels=np.arange(-300.,305.,20.), ax=ax5, extend = 'both', add_labels=False, cmap='RdBu_r') ax5.set_title('Downward sensible heat flux') (-1. * data.flux_lhe).plot.contourf(x='xofyear', y='lat', levels=levels_flux, ax=ax6, extend='both', add_labels=False, cmap='RdBu_r') ax6.set_title('Downward latent heat flux') i = 0 labels = ['a)', 'b)', 'c)', 'd)', 'e)', 'f)'] for ax in all_plots: ax.grid(True, linestyle=':') ax.set_xticks([12, 24, 36, 48, 60, 72]) ax.set_ylim([-60, 60]) ax.set_yticks([-60, -30, 0, 30, 60]) ax.text(-8, 60., labels[i]) psi.sel(pfull=500).plot.contour(ax=ax, x='xofyear', y='lat', levels=np.arange(-500., 0., 100.), add_labels=False, colors='0.7', linewidths=2, linestyles='--') psi.sel(pfull=500).plot.contour(ax=ax, x='xofyear', y='lat', levels=np.arange(0., 510., 100.), add_labels=False, colors='0.7', linewidths=2) psi.sel(pfull=500).plot.contour(ax=ax, x='xofyear', y='lat', levels=np.arange(-1000., 1010., 1000.), add_labels=False, colors='0.5', linewidths=2) data.p_cent.plot.line(ax=ax, color='k', linewidth=2) ax.set_ylabel('') ax.set_xlabel('') i = i + 1 for ax in left_column: ax.set_ylabel('Latitude') for ax in bottom_row: ax.set_xlabel('Pentad') plt.subplots_adjust(left=0.07, right=0.97, top=0.97, bottom=0.05, hspace=0.2, wspace=0.1) if lonin == [-1., 361.]: if not diff_run == None: plt.savefig(plot_dir + 'surface_fluxes_' + run + '_' + diff_run + '.pdf', format='pdf') else: plt.savefig(plot_dir + 'surface_fluxes_' + run + '.pdf', format='pdf') else: figname = plot_dir + 'surface_fluxes_' + run + '_' + str(int( lonin[0])) + '_' + str(int(lonin[1])) + '.pdf' plt.savefig(figname, format='pdf') plt.close()
def fig_8_moist(run, ax, pentad=45, rotfac=1., dayfac=5.): data = xr.open_dataset('/disca/share/rg419/Data_moist/climatologies/' + run + '.nc') heating = data.dt_tg_condensation + data.dt_tg_convection + data.dt_tg_diffusion + data.tdt_rad hum_tend = data.dt_qg_condensation + data.dt_qg_convection + data.dt_qg_diffusion convTtotheta = (1000. / data.pfull)**mc.kappa theta = data.temp * convTtotheta heating_theta = heating * convTtotheta heating_equiv_theta = heating_theta + mc.L / mc.cp_air * hum_tend / ( 1 - data.sphum)**2. * convTtotheta sinphi = np.sin(data.lat * np.pi / 180.) cosphi = np.cos(data.lat * np.pi / 180.) theta_850 = theta.sel(pfull=850.).mean('lon') theta_equiv = (data.temp + mc.L / mc.cp_air * data.sphum / (1 - data.sphum)) * convTtotheta theta_equiv_850 = theta_equiv.sel(pfull=850.).mean('lon') lats = [ data.lat[i] for i in range(len(data.lat)) if data.lat[i] >= -10. and data.lat[i] <= 10. ] Tt = (data.temp.sel(pfull=150.).mean(('lon')) * cosphi).sel(lat=lats).sum('lat') / cosphi.sel(lat=lats).sum('lat') Ts = (data.t_surf.mean(('lon')) * cosphi).sel(lat=lats).sum('lat') / cosphi.sel(lat=lats).sum('lat') dthetady_equiv = gr.ddy(theta_equiv.mean('lon'), vector=False) dthetadp_equiv = gr.ddp(theta_equiv.mean('lon')) dthetadt_equiv = gr.ddt(theta_equiv.mean('lon')) vdthetady_mean = data.vcomp.mean('lon') * dthetady_equiv wdthetadp_mean = data.omega.mean('lon') * dthetadp_equiv adv_heating_equiv = -1. * (vdthetady_mean + wdthetadp_mean) w_850 = data.omega.sel(pfull=850.).mean('lon') w_max, w_max_lat = get_latmax(-1. * w_850) theta_max, theta_max_lat = get_latmax(theta_equiv_850) cosphimax = np.cos(theta_max_lat * np.pi / 180.) chi = (rotfac * mc.omega)**2 * mc.a**2. / mc.cp_air / (Ts - Tt) theta_m_equiv = theta_max * np.exp( -1. * chi * (cosphimax**2. - cosphi**2.)**2. / cosphi**2.) def adj_theta(theta_in, adj_by, dayfac=dayfac): if 'lon' in adj_by.coords: return theta_in + adj_by.sel( pfull=850.).mean('lon') * 86400. * dayfac else: return theta_in + adj_by.sel(pfull=850.) * 86400. * dayfac theta_equiv_rc = adj_theta(theta_equiv_850, heating_equiv_theta, dayfac=dayfac) theta_equiv_adv = adj_theta(theta_equiv_850, adv_heating_equiv, dayfac=dayfac) theta_equiv_net = adj_theta(theta_equiv_850, dthetadt_equiv, dayfac=dayfac * 3.) lats = [ data.lat[i] for i in range(len(data.lat)) if data.lat[i] >= -60. and data.lat[i] <= 60. ] theta_m_equiv.sel(xofyear=pentad, lat=lats).plot(ax=ax, color='0.7') theta_equiv_rc.sel(xofyear=pentad, lat=lats).plot(ax=ax, color='k', linestyle='--') theta_equiv_adv.sel(xofyear=pentad, lat=lats).plot(ax=ax, color='k', linestyle='-.') theta_equiv_850.sel(xofyear=pentad, lat=lats).plot(ax=ax, color='C0') theta_equiv_net.sel(xofyear=pentad, lat=lats).plot(ax=ax, color='C2') ax.plot([w_max_lat.sel(xofyear=pentad), w_max_lat.sel(xofyear=pentad)], [300., 380.], color='0.7', linestyle=':') ax.set_title('') ax.set_xlabel('') ax.set_ylim(300., 380.) ax.set_xlim(-35., 35.) ax.grid(True, linestyle=':') ax.set_ylabel('$\Theta$, K')