예제 #1
0
파일: temp.py 프로젝트: AlexAudette/WE2015
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
예제 #2
0
def main(lowres=True,
         usesaved=False,
         savedata=True,
         filename='Fb_sensitivity'):
    """"""
    if usesaved:
        Fb, xi_summer, xi_mean, xi_winter = f.OpenSensitivityData(filename)
    else:
        Fb = np.linspace(0.5, 9.5, 10)
        xi_summer = np.zeros(len(Fb))
        xi_winter = np.zeros(len(Fb))
        xi_mean = np.zeros(len(Fb))

        for i in xrange(len(Fb)):
            params.Fb = Fb[i]
            print "Calculating with F_b = %.2f W/m^2..." % params.Fb
            t, x, E, T = WE.Integration(lowres=lowres)
            xi_of_t = WE.xi_seasonal(E, x)
            xi_summer[i] = np.max(xi_of_t)
            xi_winter[i] = np.min(xi_of_t)
            xi_mean[i] = np.mean(xi_of_t)
        print ""

        if savedata:
            f.SaveSensitivityData(Fb, xi_summer, xi_mean, xi_winter, filename)

    fig, ax = pl.PlotSensitivity(Fb,
                                 xi_summer,
                                 xi_mean,
                                 xi_winter,
                                 type='Fb',
                                 xlim=[0, 10])
    fig.show()
예제 #3
0
def main(lowres=True, usesaved=False, savedata=True, filename='Hml_sensitivity.txt'):
    """"""
    if usesaved:
        Hml, xi_summer, xi_mean, xi_winter = f.OpenSensitivityData(filename)
    else:
        Hml = np.array([30, 40, 50, 60, 70, 80, 90, 100])
        xi_summer = np.zeros(len(Hml))
        xi_winter = np.zeros(len(Hml))
        xi_mean = np.zeros(len(Hml))
        
        for i in xrange(len(Hml)):
            params.cw = (9.8/75.0)*Hml[i]
            print "Calculating with Hml = %.2f m..." % (params.cw*75.0/9.8)
            t, x, E, T = WE.Integration(lowres=lowres)
            xi_of_t = WE.xi_seasonal(E, x)
            xi_summer[i] = np.max(xi_of_t)
            xi_winter[i] = np.min(xi_of_t)
            xi_mean[i] = np.mean(xi_of_t)
        print ""
        
        if savedata:
            f.SaveSensitivityData(Hml, xi_summer, xi_mean, xi_winter, filename)
    
    fig, ax = pl.PlotSensitivity(Hml, xi_summer, xi_mean, xi_winter)
    fig.show()
예제 #4
0
파일: temp.py 프로젝트: AlexAudette/WE2015
def main():
    """Plot the interactive form of the ocean basal heat-flux."""
    x = np.arange(0.0, 1.0001, 0.001)
    E = np.cos(np.pi * x + 0.2)

    xi = WE.xi_seasonal(np.array([[i] for i in E]), x)
    print xi

    y = JA.BasalFluxInteractive(x, xi[0])

    fig, ax = plt.subplots()
    ax.plot(np.degrees(np.arcsin(x)),
            y,
            color='k',
            linewidth=1.5,
            label=r'$F_\mathrm{b}(\phi)$')
    ax.set_xlabel(r'$\phi$ ($^\circ$)', fontsize=18)
    ax.set_ylabel(r'Ocean upward heat flux, $F_\mathrm{b}$ (W m$^{-2}$)',
                  fontsize=18)
    ax.axvline(np.degrees(np.arcsin(xi[0])),
               linestyle='--',
               color='k',
               label=r'$\phi=\phi_\mathrm{i}$')
    ax.set_xlim([0, 90])
    ax.set_ylim([0, 16])
    ax.legend(loc=0)
    fig, ax = pl.FormatAxis(fig, ax)
    fig.show()
    pass
예제 #5
0
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
예제 #6
0
def Vary_Constant_Fb(quickly=False,
                     lowres=True,
                     times=[22, 73],
                     savedata=True,
                     usesaved=False,
                     do_plot=True):
    """"""
    if quickly:
        fb = np.array([0.0, 4.0, 10.0])
    else:
        fb = np.arange(0.0, 10.001, 1.0)

    if usesaved:
        datadir = os.path.join(os.path.dirname(__file__), '..', 'data_out')
        filename = 'default_vary_const_fb' + ('_lowres' if lowres else '') + (
            '_quickly' if quickly else '')
        array = np.genfromtxt(os.path.join(datadir, filename + '.txt'))
        fb = array[0]
        phi_i_summer = array[1]
        phi_i_mean = array[2]
        phi_i_winter = array[3]

    else:
        phi_i_winter = np.zeros(len(fb))
        phi_i_summer = np.zeros(len(fb))
        phi_i_mean = np.zeros(len(fb))
        for i in xrange(len(fb)):
            print "Calculating %i of %i..." % (i + 1, len(fb))
            params.Fb = fb[i]
            t, x, E, T = WE.Integration(lowres, varyHML=False, varyFB=False)
            phi_i_t = np.degrees(np.arcsin(WE.xi_seasonal(E, x)))
            phi_i_winter[i] = phi_i_t[times[0]]
            phi_i_summer[i] = phi_i_t[times[1]]
            phi_i_mean[i] = np.mean(phi_i_t)

        if savedata:
            array_to_save = np.array(
                [fb, phi_i_summer, phi_i_mean, phi_i_winter])
            datadir = os.path.join(os.path.dirname(__file__), '..', 'data_out')
            filename = 'default_vary_const_fb' + (
                '_lowres' if lowres else '') + ('_quickly' if quickly else '')
            np.savetxt(os.path.join(datadir, filename + '.txt'), array_to_save)

    if do_plot:
        fig, ax = plt.subplots()
        ax.fill_between(fb, phi_i_summer, phi_i_winter, color=[.9, .9, .9])
        ax.plot(fb, phi_i_summer, color='r', linewidth=1.5, label='Summer')
        ax.plot(fb,
                phi_i_mean,
                color=[.5, .5, .5],
                linestyle=':',
                linewidth=1.5,
                label='Annual mean')
        ax.plot(fb, phi_i_winter, color='b', linewidth=1.5, label='Winter')
        ax.axvline(4.0, linestyle='--', linewidth=1.5, color='k')
        ax.set_xlabel(r'Ocean upward heat flux, $F_\mathrm{b}$ (W m$^{-2}$)')
        ax.set_ylabel(r'Ice-edge latitude, $\phi_\mathrm{i}$ ($^\circ$)')
        ax.legend(loc='upper left', fontsize=14)
        fig, ax = pl.FormatAxis(fig, ax, minorgrid=False)
        fig.show()

    pass
예제 #7
0
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
예제 #8
0
def Vary_Constant_Hml(quickly=False,
                      lowres=True,
                      times=[22, 73],
                      savedata=True,
                      usesaved=False,
                      do_plot=True):
    """"""
    if quickly:
        Hml = np.array([20.0, 50.0, 100.0])
    else:
        Hml = np.arange(30.0, 100.001, 5.0)

    if usesaved:
        datadir = os.path.join(os.path.dirname(__file__), '..', 'data_out')
        filename = 'default_vary_const_Hml' + ('_lowres' if lowres else '') + (
            '_quickly' if quickly else '')
        array = np.genfromtxt(os.path.join(datadir, filename + '.txt'))
        Hml = array[0]
        phi_i_summer = array[1]
        phi_i_mean = array[2]
        phi_i_winter = array[3]

    else:
        phi_i_winter = np.zeros(len(Hml))
        phi_i_summer = np.zeros(len(Hml))
        phi_i_mean = np.zeros(len(Hml))
        for i in xrange(len(Hml)):
            print "Calculating %i of %i..." % (i + 1, len(Hml))
            params.cw = Hml[i] * params.CwRho
            t, x, E, T = WE.Integration(lowres, varyHML=False, varyFB=False)
            phi_i_t = np.degrees(np.arcsin(WE.xi_seasonal(E, x)))
            phi_i_winter[i] = phi_i_t[times[0]]
            phi_i_summer[i] = phi_i_t[times[1]]
            phi_i_mean[i] = np.mean(phi_i_t)

        if savedata:
            array_to_save = np.array(
                [Hml, phi_i_summer, phi_i_mean, phi_i_winter])
            datadir = os.path.join(os.path.dirname(__file__), '..', 'data_out')
            filename = 'default_vary_const_Hml' + (
                '_lowres' if lowres else '') + ('_quickly' if quickly else '')
            np.savetxt(os.path.join(datadir, filename + '.txt'), array_to_save)

    if do_plot:
        fig, ax = plt.subplots()
        ax.fill_between(Hml, phi_i_summer, phi_i_winter, color=[.9, .9, .9])
        ax.plot(Hml, phi_i_summer, color='r', linewidth=1.5, label='Summer')
        ax.plot(Hml,
                phi_i_mean,
                color=[.5, .5, .5],
                linestyle=':',
                linewidth=1.5,
                label='Annual mean')
        ax.plot(Hml, phi_i_winter, color='b', linewidth=1.5, label='Winter')
        ax.axvline(75.0, linestyle='--', linewidth=1.5, color='k')
        ax.set_xlabel(r'Mixed layer depth, $H_\mathrm{ml}$ (m)')
        ax.set_ylabel(r'Ice-edge latitude, $\phi_\mathrm{i}$ ($^\circ$)')
        ax.set_ylim([45, 90])
        ax.legend(loc='upper right', fontsize=14)
        fig, ax = pl.FormatAxis(fig, ax, minorgrid=False)

        fig.show()

    pass