def main4(): """Animate the form of F_b with (crude) seasonal cycle.""" ### Import data for ice-edge latitude: tdef, xdef, Edef = filing.OpenData('DAT_constFb=4.0_constHML=75.0_HR')[0:3] xideg_def = np.degrees(np.arcsin(WE.xi_seasonal(Edef, xdef))) t, x_coords, E = filing.OpenData('DAT_t_DEPENDENCE')[0:3] x = WE.xi_seasonal(E, x_coords) xdeg = np.degrees(np.arcsin(x)) FB = np.zeros((len(t), len(x_coords))) for i in xrange(len(t)): FB[i] = JA.BasalFluxTimeDependent(x_coords, t[i], x[i]) fig, (ax1, ax2) = plt.subplots(1, 2) ### Fixed plot elements: ax1.set_xlabel(r'$\phi$ ($^\circ$)') ax1.set_ylabel(r'$F_\mathrm{b}(x,t)$ (W m$^{-2}$)') ax1.set_xlim([0, 90]) ax1.set_ylim([0, 10]) fig, ax1 = pl.FormatAxis(fig, ax1) ax2.plot(tdef, xideg_def, color='grey', linewidth=1.5) ax2.plot(t, xdeg, color='k', linewidth=1.5) ax2.set_xlabel(r'Time, $t$ (yr)') ax2.set_ylabel(r'Ice-edge latitude, $\phi_\mathrm{i}$ ($^\circ$)') ax2.set_title(r'Seasonal ice-edge latitude') ax2.set_xlim([0, 1]) ax2.set_ylim([0, 90]) ### Initial frame plot: ax1.set_title(r'$t = %.2f$' % t[0]) line, = ax1.plot(np.degrees(np.arcsin(x_coords)), FB[0], color='k', linewidth=1.5, label=r'$t=%.2f$ yr' % t[0]) time, = ax2.plot(np.array([t[0], t[0]]), np.array([0, 90]), color='k', linestyle='--') fig, ax1 = pl.FormatAxis(fig, ax1) fig, ax2 = pl.FormatAxis(fig, ax2) def animate(i): line.set_ydata(FB[i]) time.set_xdata(np.array([t[i], t[i]])) ax1.set_title(r'$t=%.2f$ yr' % t[i]) return line ani = animation.FuncAnimation(fig, animate, np.arange(1, len(t)), interval=100, blit=False) fig.show() return FB
def main(lowres=False, usesaved=False, savefigs=True, custom=False): """For the standard model implementation by Wagner and Eisenman (WE2015), test whether it is conserving energy by calculating the integral over the hemisphere of their equation (2). By integrating, the D*laplacian(T) term drops out. """ if usesaved: if custom: t, x, E, T = filing.OpenData(params.custom_filename + ('LR' if lowres else 'HR')) else: t, x, E, T = filing.OpenData('WE2015_DEFAULT_DATA_' + ('LR' if lowres else 'HR')) else: t, x, E, T = WE.Integration(lowres, varyHML=False, varyFB=False) filing.SaveData( t, x, E, T, 'DAT_constFb=%.1f_constHML=%.1f_' % (params.Fb, params.HML_OCEAN) + ('LR' if lowres else 'HR')) # We now have an equilibrated seasonal cycle surface enthalpy E(x,t) and # temperature profile T specified at certain times within the season. dx = x[1] - x[0] dt = t[1] - t[0] dE = np.zeros(len(t) - 2) for i in xrange(1, len(t) - 1): dE[i - 1] = EnergyDiagnostic(np.array([enth[i - 1] for enth in E]), np.array([enth[i] for enth in E]), np.array([enth[i + 1] for enth in E]), np.array([temp[i] for temp in T]), x, t[i], dt=dt) # Return also the integral of this curve (if zero, net energy loss within # one seasonal cycle is zero so maybe okay...): int_dE = np.sum(dE) * dt print "The integral of dE over time = %.4f W yr m^-2" % int_dE # Now use the second diagnostic: E_stored = np.zeros(len(t)) F_leave = np.zeros(len(t)) for i in xrange(len(t)): E_stored[i], F_leave[i] = EnergyDiagnostic2( x, t[i], np.array([enth[i] for enth in E]), np.array([temp[i] for temp in T])) fig1, ax1 = pl.PlotEnergyDiagnostic1(t[1:len(t) - 1], dE) fig1.canvas.set_window_title('cons_test_diag1_dx=%.2E_dt=%.2E' % (dx, dt)) fig2, ax2a, ax2b = pl.PlotEnergyDiagnostic2(t, E_stored, F_leave) fig2.canvas.set_window_title('cons_test_diag2_dx=%.2E_dt=%.2E' % (dx, dt)) if savefigs: filing.SaveFigures([fig1, fig2], 'conservation_tests') filing.SaveFigures([fig1, fig2], 'conservation_tests', '.svg') fig1.show() fig2.show() pass
def main(lowres=False, usesaved=False, times=[22, 73], savefigs=False, interactive=[False, False]): """Bla bla bla... --Args-- lowres: boolean; if True, uses low resolution numerical parameters. usesaved: boolean; if True, attempts to load relevant saved data rather than calculating from scratch. times: len-2 array; time *indexes* for winter and summer plots, respectively. savefigs: boolean; if True, saves figures (*.pdf) to the plots sub- directory (will check before over-writing). interactive: len-2 array of booleans; whether to use interactive form of Fb(x, xi) [0] and Hml(x, xi) [1]. """ if usesaved: t, x, E, T = filing.OpenData( 'DAT_%.1f_Fb_%.1f_%.1f_Hml_%.1f' % (params.FB_ICE, params.FB_ICE + params.DELTA_FB, params.HML_ICE, params.HML_OCEAN) + ('_LR' if lowres else '_HR') + ('_interactiveFb' if interactive[0] else '') + ('_interactiveHml' if interactive[1] else '')) else: t, x, E, T = WE.Integration(lowres, varyHML=True, varyFB=True, interactiveFB=interactive[0], interactiveHML=interactive[1]) filing.SaveData( t, x, E, T, 'DAT_%.1f_Fb_%.1f_%.1f_Hml_%.1f' % (params.FB_ICE, params.FB_ICE + params.DELTA_FB, params.HML_ICE, params.HML_OCEAN) + ('_LR' if lowres else '_HR') + ('_interactiveFb' if interactive[0] else '') + ('_interactiveHml' if interactive[1] else '')) tdef, xdef, Edef, Tdef = filing.OpenData( 'DAT_constFb=4.0_constHML=75.0_HR') xi_deg = np.degrees(np.arcsin(WE.xi_seasonal(E, x))) xidef_deg = np.degrees(np.arcsin(WE.xi_seasonal(Edef, xdef))) # Plot the ice-edge seasonal cycle: details = r'(variable $H_\mathrm{ml}$, variable $F_\mathrm{b}$)' f1, a1 = pl.PlotIceEdge(t, xi_deg, details=details) a1.plot(tdef, xidef_deg, color='grey', linewidth=1.5) a1.axvline(t[times[0]], color='k') a1.axvline(t[times[1]], color='k', linestyle='--') f1.tight_layout() # Plot E(x, t) contour map: f2, a2 = pl.PlotContour(t, np.degrees(np.arcsin(x)), E) # Plot T(x, t) contour map: f3, a3 = pl.PlotContour(t, np.degrees(np.arcsin(x)), T, type='T') # Plot E(x) for winter and summer: title = r'$%.1f< H_\mathrm{ml}(x,t)$ /m $<%.1f$, $%.1f<F_\mathrm{b}(x,t) /$Wm$^{-2} <%.1f$' % ( params.HML_ICE, params.HML_OCEAN, params.FB_ICE, params.FB_ICE + params.DELTA_FB) f4, a4 = pl.PlotContourWS(t, np.degrees(np.arcsin(x)), E, times, 'E', title) # Plot T(x) for winter and summer: f5, a5 = pl.PlotContourWS(t, np.degrees(np.arcsin(x)), T, times, 'T', title) # Plot h(x) for winter and summer: f6, a6 = pl.PlotIceThickness(t, np.degrees(np.arcsin(x)), E, times, title) #### Add plot for constant Fb and constant Hml model manually: h_def_win = Edef[:, times[0]] / -params.Lf h_def_sum = Edef[:, times[1]] / -params.Lf h_def_win = [h if h >= 0 else 0 for h in h_def_win] h_def_sum = [h if h >= 0 else 0 for h in h_def_sum] a6.plot(np.degrees(np.arcsin(xdef)), h_def_win, color='grey', linewidth=1.5) a6.plot(np.degrees(np.arcsin(xdef)), h_def_sum, color='grey', linewidth=1.5, linestyle='--') # Plot the heat transport D(del^2)T(x,t) for winter and summer: f7, a7 = pl.PlotHeatTransport(t, x, T, times, title=title) figures = [f1, f2, f3, f4, f5, f6, f7] if savefigs: dirname = '%.1f_Fb_%.1f_%.1f_Hml_%.1f' % ( params.FB_ICE, params.FB_ICE + params.DELTA_FB, params.HML_ICE, params.HML_OCEAN) + ('_interactiveFb' if interactive[0] else '') + ('_interactiveHml' if interactive[1] else '') filing.SaveFigures(figures, dirname) for fig in figures: fig.show() pass
def main(lowres=False, usesaved=False, custom=False, times=[22, 73], savefigs=False): """Run the model and generate all plots for the standard model as described by Wagner and Eisenman (2015), i.e. with constant ocean mixed-layer depth and constant ocean basal heat-flux (selects the parameter values in params.py) --Args-- lowres: boolean; if True, uses low resolution numerical parameters. usesaved: boolean; if True, attempts to load relevant saved data rather than calculating from scratch. times: len-2 array; time *indexes* for winter and summer plots, respectively. savefigs: boolean; if True, saves figures (*.pdf) to the plots sub- directory (will check before over-writing). """ if usesaved: if custom: t, x, E, T = filing.OpenData(params.custom_filename + ('LR' if lowres else 'HR')) else: t, x, E, T = filing.OpenData('DAT_constFb=%.1f_constHml=%.1f_' % (params.Fb, params.HML_OCEAN) + ('LR' if lowres else 'HR')) else: t, x, E, T = WE.Integration(lowres, varyHML=False, varyFB=False) if custom: filing.SaveData( t, x, E, T, params.custom_filename + ('LR' if lowres else 'HR')) else: filing.SaveData( t, x, E, T, 'DAT_constFb=%.1f_constHML=%.1f_' % (params.Fb, params.HML_OCEAN) + ('LR' if lowres else 'HR')) xi_deg = np.degrees(np.arcsin(WE.xi_seasonal(E, x))) # Plot the ice-edge seasonal cycle: details = r'(constant $F_\mathrm{b}=%.1f$ Wm$^{-2}$, constant' % params.Fb details += r' $H_\mathrm{ml}=%.1f$ m)' % params.HML_OCEAN f1, a1 = pl.PlotIceEdge(t, xi_deg, label='Default model', details=details) a1.axvline(t[times[0]], color='k') a1.axvline(t[times[1]], color='k', linestyle='--') f1.tight_layout() # Plot E(x, t) contour map: if lowres: f2, a2 = pl.PlotContour(t, np.degrees(np.arcsin(x)), E) else: f2, a2 = pl.PlotContour(t, np.degrees(np.arcsin(x)), E) # Plot T(x, t) contour map: f3, a3 = pl.PlotContour(t, np.degrees(np.arcsin(x)), T, type='T') f3.tight_layout() # Plot E(x) for winter and summer: title = r'$F_\mathrm{b}(x,t)=%.1f$ Wm$^{-2}$, $H_\mathrm{ml}(x,t)=%.1f$ m' % ( params.Fb, params.HML_OCEAN) f4, a4 = pl.PlotContourWS(t, np.degrees(np.arcsin(x)), E, times, 'E', title) # Plot T(x) for winter and summer: f5, a5 = pl.PlotContourWS(t, np.degrees(np.arcsin(x)), T, times, 'T', title) # Plot h(x) for winter and summer: f6, a6 = pl.PlotIceThickness(t, np.degrees(np.arcsin(x)), E, times, title) # Plot the heat transport D(del^2)T(x,t) for winter and summer: f7, a7 = pl.PlotHeatTransport(t, x, T, times, title=title) figures = [f1, f2, f3, f4, f5, f6, f7] if savefigs: filing.SaveFigures( figures, 'constantFb=%.1f_constantHml=%.1f' % (params.Fb, params.HML_OCEAN)) for fig in figures: fig.show() pass