예제 #1
0
def load_data(work_dir='./', tmin=0.0, tmax=np.inf):

    data_list, times = utilities.select_data_by_time(dir=work_dir,
                                                     tmin=tmin,
                                                     tmax=tmax)

    # pre-load all the data
    _all_data = {}
    _all_meta_data = {}
    for i, k in enumerate(data_list):
        try:
            _all_data[k] = dd.io.load(k, '/observables')
            _all_meta_data[k] = dd.io.load(k, '/meta_data')
        except:
            print('skipping data entry ', i, k)

    # gather all data so it can be readily plotted
    all_data = {}
    all_meta_data = {}
    for k in _all_data[_all_data.keys()[0]].keys():
        all_data[k] = utilities.extract_nested_dict_asarray(
            _all_data, [k], self_contained=True)

    for k in _all_meta_data[_all_meta_data.keys()[0]].keys():
        all_meta_data[k] = utilities.extract_nested_dict_asarray(
            _all_meta_data, [k], self_contained=True)

    return all_data, all_meta_data, times
예제 #2
0
def plot_metal_retention(workdir = './', outdir = './'):

    labels     = {'Halo' : 'CGM' , 'Disk' : 'Disk', 'Outside Halo' : 'Outside Halo'} 
    lstyle     = {'Halo' : '-', 'Disk' : '--', 'Outside Halo' : ':'}

    gather_keys = {'Disk' : ['gas_meta_data', 'masses', 'Disk', 'Total Tracked Metals'],
                   'Halo' : ['gas_meta_data', 'masses', 'Halo', 'Total Tracked Metals'],
                   'FB'   : ['gas_meta_data', 'masses', 'FullBox', 'Total Tracked Metals'],
                   'Outside Box' : ['gas_meta_data', 'masses', 'OutsideBox', 'Total Tracked Metals']}

    all_data = {}

    data_list, times = utilities.select_data_by_time(dir = workdir,
                                                     tmin=0.0,tmax= 650.0)
    all_data['times'] = times
    for k in gather_keys.keys():
        all_data[k] = utilities.extract_nested_dict_asarray(None, gather_keys[k], data_list, False)

    fig, ax = plt.subplots()
    fig.set_size_inches(8,8)

    total = all_data['FB'] + all_data['Outside Box']
    disk_frac = all_data['Disk'] / total
    halo_frac = all_data['Halo'] / total
    outside_halo_frac = (all_data['FB'] - all_data['Halo'] - all_data['Disk'] + all_data['Outside Box']) / total

    t = all_data['times'] - all_data['times'][0]

    ax.plot(t, halo_frac, lw = line_width, ls = lstyle['Halo'], color = 'black', label = labels['Halo'])
    ax.plot(t, disk_frac, lw = line_width,  ls = lstyle['Disk'], color = 'black', label = labels['Disk'])
    ax.plot(t, outside_halo_frac, lw = line_width, ls = lstyle['Outside Halo'], color = 'black', label = labels['Outside Halo'])

    ax.set_xlabel(r'Time (Myr)')
    ax.set_ylabel(r'Fraction of Metals')
    ax.set_xlim(0.0, TMAX)
    ax.set_ylim(0.0, 1.0)
    ax.legend(loc = 'best')
    plt.minorticks_on()
    plt.tight_layout()
    fig.savefig(outdir + 'metal_retention.png')
    plt.close()

    return
예제 #3
0
def plot_metal_retention_resolution(work_dir='./',
                                    output_dir=None,
                                    comparison=None,
                                    new_color=False,
                                    colors=None):

    if output_dir is None:
        output_dir = work_dir

    if comparison is None:
        labels = {'3pcH2': '3.6 pc', '6pcH2': '7.2 pc', 'Fiducial': 'Fiducial'}
        lstyle = {'3pcH2': '--', '6pcH2': '-.', 'Fiducial': '-'}
        dirs = {
            '3pcH2': '../3pc_H2/',
            '6pcH2': '../6pc_H2/',
            'Fiducial': work_dir
        }

        comparison = {}
        for k in labels.keys():
            comparison[k] = (dirs[k], labels[k], lstyle[k])
    else:
        dirs = {}
        labels = {}
        lstyle = {}
        for k in comparison.keys():
            dirs[k] = work_dir + comparison[k][0]
            labels[k] = comparison[k][1]
            lstyle[k] = comparison[k][2]

    gather_keys = {
        'Disk TM': ['gas_meta_data', 'masses', 'Disk', 'Total Tracked Metals'],
        'Halo TM': ['gas_meta_data', 'masses', 'Halo', 'Total Tracked Metals'],
        'FB TM':
        ['gas_meta_data', 'masses', 'FullBox', 'Total Tracked Metals'],
        'Outside Box TM':
        ['gas_meta_data', 'masses', 'OutsideBox', 'Total Tracked Metals']
    }

    all_data = {}

    if colors is None:
        colors = {}
        i = 0
        for k in comparison.keys():
            if not (k in colors.keys()):
                colors[k] = 'C%1i' % (i)
                i = i + 1

    for sim in comparison.keys():
        data_list, times = utilities.select_data_by_time(dir=dirs[sim],
                                                         tmin=0.0,
                                                         tmax=1000.0)
        all_data[sim] = {}
        all_data[sim]['times'] = times
        for k in gather_keys.keys():

            all_data[sim][k] = utilities.extract_nested_dict_asarray(
                None, gather_keys[k], data_list, False)

    fig, ax = plt.subplots()
    fig.set_size_inches(8, 8)

    for sim in all_data.keys():
        total = all_data[sim]['FB TM'] + all_data[sim]['Outside Box TM']

        disk_frac = all_data[sim]['Disk TM'] / total
        halo_frac = all_data[sim]['Halo TM'] / total
        outside_halo_frac = (
            all_data[sim]['FB TM'] - all_data[sim]['Halo TM'] -
            all_data[sim]['Disk TM'] + all_data[sim]['Outside Box TM']) / total

        t = all_data[sim]['times'] - all_data[sim]['times'][0]

        if new_color:
            ax.plot(t, disk_frac, lw=line_width, ls='-', color=colors[sim])
            ax.plot(t,
                    outside_halo_frac,
                    lw=line_width,
                    ls=':',
                    color=colors[sim])
        else:
            ax.plot(t, disk_frac, lw=line_width, ls=lstyle[sim], color='navy')
            ax.plot(t,
                    outside_halo_frac,
                    lw=line_width,
                    ls=lstyle[sim],
                    color='C1')

    # plot this so it shows up on diagram
    if new_color:
        ax.plot([-10, -1], [0, 0],
                lw=line_width,
                ls='-',
                color='black',
                label='Disk')
        ax.plot([-10, -1], [0, 0],
                lw=line_width,
                ls='--',
                color='black',
                label='Outside Halo')
    else:
        ax.plot([-10, -1], [0, 0],
                lw=line_width,
                ls='-',
                color='navy',
                label='Disk')
        ax.plot([-10, -1], [0, 0],
                lw=line_width,
                ls='-',
                color='C1',
                label='Outside Halo')

    ax.set_xlabel(r'Time (Myr)')
    ax.set_ylabel(r'Fraction of Metals')
    ax.set_xlim(0.0, TMAX)
    ax.set_ylim(0.0, 1.0)
    ax.legend(loc='best')
    plt.minorticks_on()
    plt.tight_layout()
    fig.savefig(work_dir + output_dir + 'metal_retention_resolution.png')
    plt.close()

    return
예제 #4
0
def plot_basic_outflow_and_loading(work_dir='./',
                                   t_min=0.0,
                                   t_max=1000.0,
                                   phase=None,
                                   outdir='./'):

    data_list, times = utilities.select_data_by_time(dir=work_dir,
                                                     tmin=t_min,
                                                     tmax=t_max)

    xpos = dd.io.load(data_list[0], '/gas_profiles/outflow/sphere')
    xpos = xpos['centers_rvir']
    temp = dd.io.load(data_list[0], '/gas_meta_data/masses/CNM')
    elements = utilities.sort_by_anum([
        x for x in temp.keys()
        if len(x) <= 2 and (not (x in ['H', 'He', 'H2', 'HI', 'HII', 'HeI']))
    ])

    #
    # Mass Outflow Plot
    #
    fig, ax = plt.subplots()
    fig.set_size_inches(8, 8)

    all_data = obtain_outflow_rates(data_list,
                                    'cell_mass',
                                    elements,
                                    phase=phase)
    metal_data = obtain_outflow_rates(data_list,
                                      'Total Tracked Metals',
                                      elements,
                                      phase=phase)
    metal_mass = obtain_metal_mass(data_list)
    stellar_mass = obtain_stellar_mass(
        data_list)  # total mass in stars produced at a time, NOT M_* of galaxy
    sfr = obtain_sfr(data_list, times)

    binned_y = 1.0 * all_data  # np.array( [all_data[k] for k in all_data.keys()] )
    binned_metal_mass = 1.0 * metal_data
    for i, loc in enumerate([0.1, 0.25, 0.5, 1.0]):
        loc_bin = np.argmin(np.abs(xpos - loc))  # get the right position bin
        y = binned_y[:, loc_bin]
        print(i, loc, loc_bin)
        bin_edges = utilities.bin_edges(np.round(times))
        # rebin with 10 Myr bins, rather than previous 1 Myr bins
        newx, rebiny = utilities.simple_rebin(
            1.0 * bin_edges, 1.0 * y,
            np.arange(np.min(bin_edges),
                      np.max(bin_edges) + 2, 10), 'average')

        plot_histogram(ax,
                       newx - newx[0],
                       rebiny,
                       lw=line_width,
                       color=plasma(i / 4.0),
                       label=r"%0.1f R$_{\rm vir}$" % (loc))

    ax.set_xlabel(r'Time (Myr)')
    ax.set_ylabel(r'Outflow Rate (M$_{\odot}$ yr$^{-1}$)')
    ax.semilogy()
    ax.set_xlim(0.0, np.min([TMAX, np.max(newx - newx[0])]))
    ax.set_ylim(1.0E-5, 0.03)

    plt.tight_layout()
    ax.legend(loc='best')
    plt.minorticks_on()

    outname = outdir + 'total_mass_outflow'
    if not (phase is None):
        outname += '_' + phase
    fig.savefig(outname + '.png')
    plt.close()

    #
    # Mass Loading plot
    #
    fig, ax = plt.subplots()
    fig.set_size_inches(8, 8)

    #    binned_y = np.array( [all_data[k] for k in all_data.keys()] )
    for i, loc in enumerate([0.1, 0.25, 0.5, 1.0]):
        loc_bin = np.argmin(np.abs(xpos - loc))  # get the right position bin
        y = binned_y[:, loc_bin] / sfr

        bin_edges = utilities.bin_edges(np.round(times))
        # rebin with 10 Myr bins, rather than previous 1 Myr bins
        newx, rebiny = utilities.simple_rebin(
            1.0 * bin_edges, 1.0 * y,
            np.arange(np.min(bin_edges),
                      np.max(bin_edges) + 2, 10), 'average')

        plot_histogram(ax,
                       newx - newx[0],
                       rebiny,
                       lw=line_width,
                       color=plasma(i / 4.0),
                       label=r"%0.1f R$_{\rm vir}$" % (loc))

    ax.set_xlabel(r'Time (Myr)')
    ax.set_ylabel(r'Mass Loading Factor')
    ax.semilogy()
    ax.set_xlim(0.0, np.min([TMAX, np.max(newx - newx[0])]))
    ax.set_ylim(0.1, 300)

    plt.tight_layout()
    #ax.legend(loc='best')
    plt.minorticks_on()
    outname = outdir + 'total_mass_loading'
    if not (phase is None):
        outname += '_' + phase
    fig.savefig(outname + '.png')
    plt.close()

    #
    # Metal Mass Loading
    #
    fig, ax = plt.subplots()
    fig.set_size_inches(8, 8)

    for i, loc in enumerate([0.1, 0.25, 0.5, 1.0]):
        loc_bin = np.argmin(np.abs(xpos - loc))  # get the right position bin
        print(np.shape(binned_y), np.shape(binned_metal_mass), np.size(sfr),
              np.size(metal_mass), np.size(stellar_mass))
        y = binned_metal_mass[:, loc_bin] / (sfr * (metal_mass / stellar_mass)
                                             )  # metal mass loading factor
        print(loc, np.min(y), np.max(y), np.average(y))
        print(np.min(metal_mass), np.max(metal_mass), np.min(stellar_mass),
              np.max(stellar_mass))

        bin_edges = utilities.bin_edges(np.round(times))
        # rebin with 10 Myr bins, rather than previous 1 Myr bins
        newx, rebiny = utilities.simple_rebin(
            1.0 * bin_edges, 1.0 * y,
            np.arange(np.min(bin_edges),
                      np.max(bin_edges) + 2, 10), 'average')

        plot_histogram(ax,
                       newx - newx[0],
                       rebiny,
                       lw=line_width,
                       color=plasma(i / 4.0),
                       label=r"%0.1f R$_{\rm vir}$" % (loc))

    ax.set_xlabel(r'Time (Myr)')
    ax.set_ylabel(r'Metal Mass Loading Factor')
    ax.semilogy()
    ax.set_xlim(0.0, np.min([TMAX, np.max(newx - newx[0])]))
    ax.set_ylim(0.04, 20)

    plt.tight_layout()
    ax.legend(loc='upper right')
    plt.minorticks_on()
    outname = outdir + 'metal_mass_loading'
    if not (phase is None):
        outname += '_' + phase
    fig.savefig(outname + '.png')
    plt.close()

    #
    # Metal Mass Loading
    #
    fig, ax = plt.subplots()
    fig.set_size_inches(8, 8)

    for i, loc in enumerate([0.1, 0.25, 0.5, 1.0]):
        loc_bin = np.argmin(np.abs(xpos - loc))  # get the right position bin
        print(np.shape(binned_y), np.shape(binned_metal_mass), np.size(sfr),
              np.size(metal_mass), np.size(stellar_mass))
        y = binned_metal_mass[:, loc_bin] / (sfr)  # metal mass loading factor
        print(loc, np.min(y), np.max(y), np.average(y))
        print(np.min(metal_mass), np.max(metal_mass), np.min(stellar_mass),
              np.max(stellar_mass))

        bin_edges = utilities.bin_edges(np.round(times))
        # rebin with 10 Myr bins, rather than previous 1 Myr bins
        newx, rebiny = utilities.simple_rebin(
            1.0 * bin_edges, 1.0 * y,
            np.arange(np.min(bin_edges),
                      np.max(bin_edges) + 2, 10), 'average')

        print(np.sum(rebiny) / (1.0 * np.size(rebiny)), '-------------')
        plot_histogram(ax,
                       newx - newx[0],
                       rebiny,
                       lw=line_width,
                       color=plasma(i / 4.0),
                       label=r"%0.1f R$_{\rm vir}$" % (loc))

    ax.set_xlabel(r'Time (Myr)')
    ax.set_ylabel(r'Metal Mass Loading Factor')
    ax.semilogy()
    ax.set_xlim(0.0, np.min([TMAX, np.max(newx - newx[0])]))
    ax.set_ylim(1.0E-6, 1.0)

    plt.tight_layout()
    ax.legend(loc='best')
    plt.minorticks_on()
    outname = outdir + 'metal_mass_loading_sfr'
    if not (phase is None):
        outname += '_' + phase
    fig.savefig(outname + '.png')
    plt.close()

    return
예제 #5
0
def plot_species_outflow_panel(work_dir='./',
                               t_min=0.0,
                               t_max=1000.0,
                               phase=None,
                               method='fraction',
                               outdir='./'):
    """
    Default to plotting the following:
        For each species, x, plots   (dM_x/dt / M_x_prod) / SFR
        or the fractional mass outflow rate per unit SFR.
    """

    data_list, times = utilities.select_data_by_time(dir=work_dir,
                                                     tmin=0.0,
                                                     tmax=1000)

    xpos = dd.io.load(data_list[0], '/gas_profiles/outflow/sphere')
    xpos = xpos['centers_rvir']
    temp = dd.io.load(data_list[0], '/gas_meta_data/masses/CNM')
    elements = utilities.sort_by_anum([
        x for x in temp.keys()
        if len(x) <= 2 and (not (x in ['H', 'He', 'H2', 'HI', 'HII', 'HeI']))
    ])

    fig, ax = plt.subplots(4, 4, sharex=True, sharey=True)
    fig.set_size_inches(16, 16)
    fig.subplots_adjust(hspace=0.0, wspace=0.0)

    SFR = obtain_sfr(data_list, times)

    axi, axj = 0, 0

    for e in elements:
        index = (axi, axj)

        field_name = e + '_Mass'
        all_data = obtain_outflow_rates(data_list,
                                        field_name,
                                        elements,
                                        phase=phase)
        M_prod = obtain_mprod(data_list, e)

        binned_y = 1.0 * all_data  # np.array( [all_data[k] for k in all_data.keys()] )
        for i, loc in enumerate([0.1, 0.25, 0.5, 1.0]):
            loc_bin = np.argmin(np.abs(xpos -
                                       loc))  # get the right position bin
            y = binned_y[:, loc_bin]

            bin_edges = utilities.bin_edges(np.round(times))
            # rebin with 10 Myr bins, rather than previous 1 Myr bins

            # convert y from outflow rate to outflow rate / mass produced / sfr
            if method == 'fraction':
                y = (y / M_prod) * 1.0E6  # convert to 1/Myr
            else:
                y = (y / M_prod) / SFR

            newx, rebiny = utilities.simple_rebin(
                1.0 * bin_edges, 1.0 * y,
                np.arange(np.min(bin_edges),
                          np.max(bin_edges) + 2, 5.0), 'average')

            plot_histogram(ax[index],
                           newx - newx[0],
                           rebiny,
                           lw=line_width,
                           color=plasma(i / 4.0),
                           label=r"%0.1f R$_{\rm vir}$" % (loc))

            if i == 0:
                xy = (np.max(newx - newx[0]) * 0.8, np.max(rebiny) * 10.0)

        ax[index].annotate(e, xy=xy, xytext=xy)

        axj = axj + 1
        if axj >= 4:
            axj = 0
            axi = axi + 1

    for i in np.arange(4):
        ax[(3, i)].set_xlabel(r'Time (Myr)')
        #        ax[(i,0)].set_ylabel(r'log(X Fractional Outflow per SFR [M$_\odot$ yr$^{-1}$]$^{-1}$)')
        ax[(i, 0)].set_xlim(newx[0] - newx[0],
                            np.min([TMAX, newx[-1] - newx[0]]))

        if method == 'fraction':
            ax[(0, i)].set_ylim(1.0E-5, 1.0E-1)
        else:
            ax[(0, i)].set_ylim(1.0E-7, 1.0E-3)

        ax[(0, i)].semilogy()

    if method == 'fraction':
        ax[(2, 0)].set_ylabel(r'log(X Fractional Outflow Rate [Myr$^{-1}$])')
    else:
        ax[(2, 0)].set_ylabel(
            r'log(X Fractional Outflow per SFR [M$_\odot$ yr$^{-1}$]$^{-1}$)')

    plt.minorticks_on()
    if method == 'fraction':
        fig.savefig(outdir + 'X_Fractional_Outflow_panel.png')
    else:
        fig.savefig(outdir + 'X_Fractional_Outflow_loading_panel.png')
    plt.close()

    return
예제 #6
0
def plot_time_average_PD(wdir,
                         t_min,
                         t_max,
                         nbin=100,
                         plots=['nT', 'G_o', 'Q_o'],
                         outdir=None):

    x = utilities.select_data_by_time(wdir, tmin=0.0, tmax=np.inf)
    sim_files = {'files': x[0], 'Time': x[1]}
    #                    'DD_files' : np.sort(glob.glob(wdir + '/DD????/DD????'))}
    #iremove = len(sim_files['files'])
    #sim_files['DD_files'] = sim_files['DD_files'][-iremove:]
    # --- get data sets associated with output files (this is gross - I am sorry)
    sim_files['DD_files'] = np.array([
        x.split('_galaxy_data')[0] + '/' + x.split('_galaxy_data')[0][-6:]
        for x in sim_files['files']
    ])
    # --- make sure they exist
    sim_files['Time'] = np.array([
        sim_files['Time'][i] for i in np.arange(np.size(sim_files['Time']))
        if os.path.isfile(sim_files['DD_files'][i])
    ])
    sim_files['DD_files'] = np.array(
        [x for x in sim_files['DD_files'] if os.path.isfile(x)])
    # --- select the ones in the time range we want
    sim_files['phase_files'] = sim_files['DD_files'][ (sim_files['Time'] >= t_min) *\
                                                      (sim_files['Time'] <= t_max)]

    gal = Galaxy(sim_files['DD_files'][0].split('/')[-1])

    if 'G_o' in plots:
        pd = tapd.time_average_phase_diagram(
            t_min,
            t_max,
            ds_list=sim_files['phase_files'],
            wdir=wdir,
            x_bins=np.linspace(0.0, 600.0, nbin) * yt.units.pc,
            xlog=False,
            xfield='cylindrical_radius',
            ylabel=r'G$_{\rm o}$',
            y_bins=np.logspace(np.log10(0.00324), 3, nbin) * yt.units.pc /
            yt.units.pc,
            yfield='G_o',
            region_type='Disk',
            region_kwargs={
                'normal': np.array([0.0, 0.0, 1.0]),
                'radius': 600 * yt.units.pc,
                'height': (1.5 * yt.units.pc * 20),
                'center': np.array([0.5, 0.5, 0.5])
            },
            zlog=True,
            zlabel=r'Mass (M$_{\odot}$)',
            #                                         region_type = 'FullBox', zlog = True,
            ylog=True,
            zlim=[5.0E-2, 1.0E5],
            zunit='Msun',
            cmap='cubehelix',
            #                                         outname = 'G_o_r_cell_mass_2D_phase.png',
            outdir=outdir)

    if ('Q_o' in plots) or ('Q0' in plots) or ('Q_0' in plots):
        pd = tapd.time_average_phase_diagram(
            t_min,
            t_max,
            ds_list=sim_files['phase_files'],
            wdir=wdir,
            x_bins=np.linspace(0.0, 600.0, nbin) * yt.units.pc,
            xlog=False,
            xfield='cylindrical_radius',
            ylabel=r'HI Ionizing Flux (erg s$^{-1}$ cm$^{-2}$)',
            y_bins=np.logspace(-8, 1, nbin) * yt.units.erg / yt.units.s /
            yt.units.cm**2,
            yfield='Q0_flux',
            region_type='Disk',
            region_kwargs={
                'normal': np.array([0.0, 0.0, 1.0]),
                'radius': 600 * yt.units.pc,
                'height': (1.5 * yt.units.pc) * 20,
                'center': np.array([0.5, 0.5, 0.5])
            },
            zlog=True,
            zlabel=r'Mass (M$_{\odot}$)',
            #                                         region_type = 'FullBox', zlog = True,
            ylog=True,
            zlim=[5.0E-2, 1.0E5],
            zunit='Msun',
            cmap='cubehelix',
            #                                     outname = 'Q_o_r_cell_mass_2D_phase.png',
            outdir=outdir)

    if 'nT' in plots:
        pd = tapd.time_average_phase_diagram(
            t_min,
            t_max,
            ds_list=sim_files['phase_files'],
            wdir=wdir,
            x_bins=np.logspace(-6, 3, 512) * yt.units.cm**(-3),
            xlog=True,
            xfield='number_density',
            y_bins=np.logspace(0, 7.5, 512) * yt.units.K,
            yfield='Temperature',
            region_type='sphere',
            region_kwargs={
                'radius': 3.6 * yt.units.kpc,
                'center': np.array([0.5, 0.5, 0.5])
            },
            zlog=True,
            #                                      region_type = 'FullBox', zlog = True,
            ylog=True,
            zlim=[1.0E-2, 6.0E4],
            zunit='Msun',
            cmap='cubehelix',
            #                                     outname = 'T_n_cell_mass_2D_phase.png',
            outdir=outdir)

    if 'nT_special' in plots:
        pd = tapd.time_average_phase_diagram(
            t_min,
            t_max,
            ds_list=sim_files['phase_files'],
            wdir=wdir,
            x_bins=np.logspace(-6, 3, 512) * yt.units.cm**(-3),
            xlog=True,
            xfield='number_density',
            y_bins=np.logspace(0, 7.5, 512) * yt.units.K,
            yfield='Temperature',
            region_type='sphere_exclude_disk',
            region_kwargs={
                'sphere_radius': 3.6 * yt.units.kpc,
                'disk_radius': 600 * yt.units.pc,
                'disk_height': 200 * yt.units.pc,
                'center': np.array([0.5, 0.5, 0.5])
            },
            zlog=True,
            #                                      region_type = 'FullBox', zlog = True,
            ylog=True,
            zlim=[1.0E-2, 6.0E4],
            zunit='Msun',
            cmap='cubehelix',
            outname='nT_outside_disk.png',
            outdir=outdir)

        pd = tapd.time_average_phase_diagram(
            t_min,
            t_max,
            ds_list=sim_files['phase_files'],
            wdir=wdir,
            x_bins=np.logspace(-6, 3, 512) * yt.units.cm**(-3),
            xlog=True,
            xfield='number_density',
            y_bins=np.logspace(0, 7.5, 512) * yt.units.K,
            yfield='Temperature',
            region_type='disk',
            region_kwargs={
                'radius': 600 * yt.units.pc,
                'height': 200 * yt.units.pc,
                'center': np.array([0.5, 0.5, 0.5])
            },
            zlog=True,
            #                                      region_type = 'FullBox', zlog = True,
            ylog=True,
            zlim=[1.0E-2, 6.0E4],
            zunit='Msun',
            cmap='cubehelix',
            outname='nT_disk.png',
            outdir=outdir)

    return
예제 #7
0
from galaxy_analysis.plot.plot_styles import *
from galaxy_analysis.analysis.compute_time_average import compute_time_average
from galaxy_analysis.utilities import utilities
import deepdish as dd
import numpy as np
import matplotlib.pyplot as plt
import glob

TMAX = 500.0

# filepath = '/mnt/ceph/users/emerick/enzo_runs/pleiades/starIC/run11_30km/final_sndriving'
work_dir = '/mnt/ceph/users/emerick/enzo_runs/pleiades/starIC/run11_30km/final_sndriving/'
#work_dir      = '/mnt/ceph/users/emerick/enzo_runs/pleiades/starIC/run11/corrected_sndriving/'

data_list, times = utilities.select_data_by_time(dir=work_dir,
                                                 tmin=0.0,
                                                 tmax=1000)
print(data_list[0], times[0])
print(data_list[-1], times[-1])
print(times[-1] - times[0])
all_data = {}

# gather metallicities for:
#   1) ISM
#   2) Halo
#   3) Outflowing gas (at all radii)
#   4) Inflowing gas  (at all radii)
#data_list = data_list[:60]
#times     = times[:60]

for k in ['ISM', 'Halo', 'outflow', 'inflow']:
예제 #8
0
def plot_mass_resolution(work_dir='./',
                         output_dir=None,
                         comparison=None,
                         new_color=False,
                         colors=None):

    if output_dir is None:
        output_dir = work_dir

    if comparison is None:
        labels = {'3pcH2': '3.6 pc', '6pcH2': '7.2 pc', 'Fiducial': 'Fiducial'}
        lstyle = {'3pcH2': '--', '6pcH2': '-.', 'Fiducial': '-'}
        dirs = {
            '3pcH2': '../3pc_H2/',
            '6pcH2': '../6pc_H2/',
            'Fiducial': work_dir
        }

        comparison = {}
        for k in labels.keys():
            comparison[k] = (dirs[k], labels[k], lstyle[k])

    else:
        dirs = {}
        labels = {}
        lstyle = {}
        for k in comparison.keys():
            dirs[k] = work_dir + comparison[k][0]
            labels[k] = comparison[k][1]
            lstyle[k] = comparison[k][2]


#    labels = {'3pc_hsn' : '3.6 pc - SNx2', '3pc' : '3.6 pc', 'final_sndriving' : 'Fiducial', '6pc_hsn' : '7.2 pc'}
#    lstyle     = {'3pc_hsn' : '--', '3pc' : ':', 'final_sndriving' : '-', '6pc_hsn' : '-.'}

    all_data = {}
    for k in comparison.keys():
        all_data[k] = {}

        #        if k == 'final_sndriving':
        #            all_data[k]['times'] = times
        #            all_data[k]['M_HI'] = M_HI
        #            all_data[k]['M_star'] = M_star
        #            all_data[k]['M_total'] = M_total
        #            all_data[k]['M_H2I']    = M_H2
        #
        if True:
            dl, t = utilities.select_data_by_time(dir=dirs[k],
                                                  tmin=0.0,
                                                  tmax=1000.0)

            all_data[k]['times'] = t
            all_data[k]['M_HI'] = np.zeros(np.size(dl))
            all_data[k]['M_star'] = np.zeros(np.size(dl))
            all_data[k]['M_total'] = np.zeros(np.size(dl))
            all_data[k]['M_H2I'] = np.zeros(np.size(dl))

            for i, d in enumerate(dl):
                all_data[k]['M_HI'][i] = dd.io.load(d, '/meta_data/M_HI')
                all_data[k]['M_star'][i] = dd.io.load(d, '/meta_data/M_star')
                all_data[k]['M_total'][i] = dd.io.load(
                    d, '/meta_data/M_H_total') + dd.io.load(
                        d, '/meta_data/M_He_total')
                all_data[k]['M_H2I'][i] = dd.io.load(d, '/meta_data/M_H2I')

    # done collecting data rom all data sets

    fig, ax = plt.subplots()
    fig.set_size_inches(8, 8)

    if colors is None:
        colors = {}
        i = 0
        for k in comparison.keys():
            if not (k in colors.keys()):
                colors[k] = 'C%1i' % (i)
                i = i + 1

    lstyle['M_total'] = '-'
    lstyle['M_HI'] = '--'
    lstyle['M_H2I'] = '-.'
    lstyle['M_star'] = ':'

    for k in comparison.keys():

        for field, color in [('M_total', 'black'), ('M_HI', 'C0'),
                             ('M_H2I', 'C1'), ('M_star', 'C3')]:
            #        for field, ls in [('M_total','-'), ('M_HI', '--'), ('M_H2I', ':')]:  # , ('M_star' , '-.')]:

            if field == 'M_total':
                label = labels[k]
            else:
                label = None
            # print k, field, np.size(all_data[k]['times']), np.size(all_data[k][field])
            if new_color:
                ax.plot(all_data[k]['times'] - all_data[k]['times'][0],
                        all_data[k][field],
                        ls=lstyle[field],
                        lw=line_width,
                        color=colors[k])
            else:

                plot_histogram(ax,
                               all_data[k]['times'] - all_data[k]['times'][0],
                               all_data[k][field],
                               ls=lstyle[k],
                               lw=line_width,
                               color=color)

    if new_color:
        ax.plot((-1, -1), (-2, -2),
                ls='-',
                lw=3,
                color='black',
                label=r'M$_{\rm total}$')
        ax.plot((-1, -1), (-2, -2),
                ls='--',
                lw=3,
                color='black',
                label=r'M$_{\rm HI}$')
        ax.plot((-1, -1), (-2, -2),
                ls='-.',
                lw=3,
                color='black',
                label=r'M$_{\rm H_2}$')
        ax.plot((-1, -1), (-2, -2),
                ls=':',
                lw=3,
                color='black',
                label=r'M$_{\rm *}$')
    else:
        ax.plot((-1, -1), (-2, -2),
                ls='-',
                lw=3,
                color='black',
                label=r'M$_{\rm total}$')
        ax.plot((-1, -1), (-2, -2),
                ls='-',
                lw=3,
                color='C0',
                label=r'M$_{\rm HI}$')
        ax.plot((-1, -1), (-2, -2),
                ls='-',
                lw=3,
                color='C1',
                label=r'M$_{\rm H_2}$')
        ax.plot((-1, -1), (-2, -2),
                ls='-',
                lw=3,
                color='C3',
                label=r'M$_{\rm *}$')

    ax.set_xlabel(r'Time (Myr)')
    ax.set_ylabel(r'Mass in Disk (M$_{\odot}$)')
    ax.semilogy()

    ax.set_xlim(0.0, 500.0)
    ax.legend(loc='lower right')
    #    ax.set_ylim(6E4, 3E6)
    plt.tight_layout()
    plt.minorticks_on()

    fig.savefig(work_dir + output_dir + 'mass_evolution_resolution.png')
    plt.close()
    return
예제 #9
0
def plot_mass_evolution(work_dir,
                        t_f=None,
                        image_num=0,
                        outdir='./',
                        TMAX=500.0):

    data_list, times = utilities.select_data_by_time(dir=work_dir,
                                                     tmin=0.0,
                                                     tmax=650.0)
    M_HI = np.ones(np.size(data_list))
    M_star = np.ones(np.size(data_list))
    M_total = np.ones(np.size(data_list))
    M_H2 = np.ones(np.size(data_list))
    for i, k in enumerate(data_list):
        M_HI[i] = dd.io.load(k, '/meta_data/M_HI')
        M_star[i] = dd.io.load(k, '/meta_data/M_star')
        M_total[i] = dd.io.load(k, '/meta_data/M_H_total') + dd.io.load(
            k, '/meta_data/M_He_total')
        M_H2[i] = dd.io.load(k, '/meta_data/M_H2I')

    selection = (times == times)  # all vals
    plot_times = times
    if not (t_f is None):
        selection = times <= t_f
        plot_times = times[selection]

    plot_times = plot_times - plot_times[0]

    fig, ax = plt.subplots()
    fig.set_size_inches(8, 8)

    plot_histogram(ax,
                   plot_times,
                   M_total[selection],
                   lw=line_width,
                   color='black',
                   label=r'M$_{\rm total}$')
    plot_histogram(ax,
                   plot_times,
                   M_HI[selection],
                   lw=line_width,
                   color='C0',
                   label=r'M$_{\rm HI}$')
    plot_histogram(ax,
                   plot_times,
                   M_H2[selection],
                   lw=line_width,
                   color='C1',
                   label=r'M$_{\rm H_2 }$')
    plot_histogram(ax,
                   plot_times,
                   M_star[selection],
                   lw=line_width,
                   color='C3',
                   label=r'M$_*$')

    ax.set_xlabel(r'Time (Myr)')
    ax.set_ylabel(r'Mass in Disk (M$_{\odot}$)')
    ax.semilogy()
    ax.set_xlim(np.min(times - times[0]),
                np.min([TMAX, np.max(times - times[0])]))
    ax.legend(loc='lower right')
    plt.tight_layout()
    plt.minorticks_on()

    if t_f is None:
        fig.savefig(outdir + 'mass_evolution.png')
    else:
        fig.savefig('./mass_evolution_movie/mass_evolution_%0004i.png' %
                    (image_num))

    plt.close()

    return