def _parallel_loop(dsname):

    groupname = dsname.rsplit('/')[1]
    print("starting computation on ", groupname)
    gal = Galaxy(groupname)

    M = gal.df['birth_mass']
    L = gal.df[('io', 'particle_model_L_1_3eV')].value
    L_LW = gal.df[('io', 'particle_model_L_LW')].value
    pt = gal.df['particle_type']

    L_low = np.sum(L[(M < 8.0) * (pt == 11)])
    L_high = np.sum(L[(M > 8.0) * (pt == 11)])

    L_LW_low = np.sum(L_LW[(M < 8.0) * (pt == 11)])
    L_LW_high = np.sum(L_LW[(M > 8.0) * (pt == 11)])

    dict = {}
    dict[groupname] = [L_low, L_high, L_LW_low, L_LW_high]

    del (gal)

    return dict
Ejemplo n.º 2
0
from galaxy_analysis.utilities import utilities
import numpy as np
from matplotlib.ticker import NullFormatter
from galaxy_analysis.particle_analysis.abundances import single_MDF
#
from galaxy_analysis.analysis import Galaxy

from mpl_toolkits.axes_grid1 import make_axes_locatable
import h5py

# grab the most recent file
workdir = '/mnt/ceph/users/emerick/enzo_runs/pleiades/starIC/run11_30km/final_sndriving/'
#workdir = '/home/emerick/work/enzo_runs/pleiades/starIC/run11_30km/final_sndriving/'
data_files = np.sort(glob.glob(workdir + 'DD????'))
name = data_files[-1].split('final_sndriving/')[1]
gal = Galaxy(name, wdir = workdir)

#
#
#
def plot_alpha_vs_fe():
    fig,ax = plt.subplots()
    fig.set_size_inches(8,7)

    ptype     = gal.df['particle_type']
    fe_over_h = gal.df[('io','particle_Fe_over_H')]
    alpha     = gal.df[('io','particle_alpha_over_Fe')]
    age       = (gal.ds.current_time - gal.df[('io','creation_time')]).convert_to_units('Myr')

    age = age - np.min(age)
Ejemplo n.º 3
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
def plot_field(dsname, mass_field, paperstyle=False, show_colorbar=True):

    fontsize = 'large'

    field_to_plot = mass_field + "_disk_fraction"
    field_parameter = "total_field_mass"

    gal = Galaxy(dsname)

    dims = [700, 700, 56]
    pix = np.array(dims) / 2.0
    dist = pix * np.min(gal.df['dx'].to('pc'))

    LE = gal.ds.domain_center - dist

    cg = gal.ds.smoothed_covering_grid(level=int(np.max(gal.df['grid_level'])),
                                       left_edge=LE,
                                       dims=dims)

    disk_mass = np.sum((gal.disk[mass_field].to('Msun').value))
    cg.set_field_parameter(field_parameter, disk_mass * yt.units.Msun)

    def _disk_mass_fraction(field, data):
        if data.has_field_parameter(field_parameter):
            mtot = data.get_field_parameter(field_parameter)
            if hasattr(mtot, 'convert_to_units'):
                mtot = mtot.convert_to_units('Msun')
            else:
                mtot = mtot * yt.units.Msun
        else:
            raise ValueError
        mfield = mass_field
        return data[mfield].convert_to_units('Msun') / mtot

    gal.ds.add_field(field_to_plot,
                     function=_disk_mass_fraction,
                     units="",
                     take_log=False,
                     force_override=True,
                     validators=[ValidateParameter(field_parameter)])

    # sum the data over 2nd axes
    axis = 2
    #print np.shape(cg[field_to_plot])
    proj_data = np.sum(cg[field_to_plot], axis=axis)
    n_proj_data = np.max(cg['number_density'].value, axis=axis)
    #print np.shape(proj_data)

    #print np.min(proj_data), np.max(proj_data)

    if axis == 2:
        extent = [-dist[0], dist[0], -dist[1], dist[1]]
        fsize = (8, 8)
    elif axis == 0 or axis == 1:
        extent = [-dist[1], dist[1], -dist[2], dist[2]]
        proj_data = proj_data.T
        fsize = (12.5, 1)
        n_proj_data = n_proj_data.T

    pp = plt.imshow(proj_data, norm=LogNorm(), extent=extent)
    pp.set_clim(1.0E-10, 1.0E-1)
    pp.set_cmap("magma")
    #plt.tight_layout()
    #pp.axes.set_xticks([-600,-400,-200,0,200,400,600])
    pp.axes.yaxis.set_visible(False)
    pp.axes.xaxis.set_visible(False)
    pp.axes.set_frame_on(False)
    pp.figure.set_size_inches(fsize)
    pp.figure.patch.set_facecolor('black')
    # annotate the size
    anncoord = (0.9, 0.1)
    dim = np.shape(proj_data)
    x = 0.5
    di = 250.0 / (1.8)
    pp.axes.plot([dim[0] * x, dim[0] * x + di], [-dim[1] * 0.825] * 2,
                 lw=3,
                 color="white")

    pp.axes.annotate(
        '250 pc',
        xy=anncoord,
        xycoords='axes fraction',
        xytext=anncoord,
        textcoords='axes fraction',
        color="white",
        # arrowprops=dict(facecolor='black', shrink=0.05),
        horizontalalignment='right',
        verticalalignment='top',
        fontsize=fontsize)

    start = 220.0
    anncoord2 = (0.225, 0.96)
    if not paperstyle:
        pp.axes.annotate(
            "%.1f Myr" % (gal.ds.current_time.to('Myr').value - start),
            xy=anncoord2,
            xycoords='axes fraction',
            xytext=anncoord2,
            textcoords='axes fraction',
            color="white",
            # arrowprops=dict(facecolor='black', shrink=0.05),
            horizontalalignment='right',
            verticalalignment='top',
            fontsize=fontsize)


#    pp.figure.savefig("./mixing_plots/" + dsname + "_" + mass_field + "_disk_fraction.png")
    outname = "./mixing_plots/" + dsname + "_" + mass_field + "_disk_fraction.png"
    if show_colorbar:
        cax = plt.colorbar(orientation="horizontal")
        cticks = [1.0E-8, 1.0E-6, 1.0E-4, 1.0E-2, 1.0]
        cticks = [1.0E-9, 1.0E-7, 1.0E-5, 1.0E-3, 1.0E-1]
        cax.set_ticks(cticks)
        cax.set_ticklabels([r"10$^{%2i}$" % (np.log10(x)) for x in cticks])
        cax.set_label("Tracer Fraction (Arbitrary Units)")

    plt.savefig(outname, bbox_inches="tight", pad_inches=0.0)
    plt.close()

    ############
    pp = plt.imshow(n_proj_data, norm=LogNorm(), extent=extent)
    pp.set_clim(1.0E-4, 1.0E3)
    #plt.tight_layout()
    #pp.axes.set_xticks([-600,-400,-200,0,200,400,600])
    pp.axes.yaxis.set_visible(False)
    pp.axes.xaxis.set_visible(False)
    pp.axes.set_frame_on(False)
    pp.figure.set_size_inches(fsize)
    pp.figure.patch.set_facecolor('black')
    # annotate the size
    anncoord = (0.9, 0.1)
    dim = np.shape(n_proj_data)
    x = 0.5
    di = 250.0 / (1.8)
    pp.axes.plot([dim[0] * x, dim[0] * x + di], [-dim[1] * 0.825] * 2,
                 lw=3,
                 color="white")

    pp.axes.annotate(
        '250 pc',
        xy=anncoord,
        xycoords='axes fraction',
        xytext=anncoord,
        textcoords='axes fraction',
        color="white",
        # arrowprops=dict(facecolor='black', shrink=0.05),
        horizontalalignment='right',
        verticalalignment='top',
        fontsize=fontsize)

    start = 220.0
    anncoord2 = (0.225, 0.96)
    pp.axes.annotate(
        "%.1f Myr" % (gal.ds.current_time.to('Myr').value - start),
        xy=anncoord2,
        xycoords='axes fraction',
        xytext=anncoord2,
        textcoords='axes fraction',
        color="white",
        # arrowprops=dict(facecolor='black', shrink=0.05),
        horizontalalignment='right',
        verticalalignment='top',
        fontsize=fontsize)

    #    pp.figure.savefig("./mixing_plots/" + dsname + "_" + mass_field + "_disk_fraction.png")
    outname = "./mixing_plots/" + dsname + "_" + "ndens.png"
    if show_colorbar:
        cax = plt.colorbar(orientation="horizontal")
        cticks = [1.0E-4, 1.0E-2, 1.0, 100.0]
        cax.set_ticks(cticks)
        cax.set_ticklabels([r"10$^{%2i}$" % (np.log10(x)) for x in cticks])
        cax.set_label(r"n (cm$^{-3}$)")

    plt.savefig(outname, bbox_inches="tight", pad_inches=0.0)

    return
Ejemplo n.º 5
0
def plot_panel(ds_list=default_list,
               fields_list=default_fields,
               axis='x',
               width=(1.55, 'kpc'),
               fsize=4,
               outdir='./'):

    ncol = len(fields_list)
    nrow = len(ds_list)

    fig = plt.figure(figsize=(fsize * nrow, fsize * ncol))

    # See http://matplotlib.org/mpl_toolkits/axes_grid/api/axes_grid_api.html
    # These choices of keyword arguments produce a four panel plot with a single
    # shared narrow colorbar on the right hand side of the multipanel plot. Axes
    # labels are drawn for all plots since we're slicing along different directions
    # for each plot.
    grid = AxesGrid(fig, (0.075, 0.075, 0.875, 0.875),
                    nrows_ncols=(nrow, ncol),
                    axes_pad=0.1,
                    label_mode="L",
                    share_all=True,
                    cbar_location="right",
                    cbar_mode="edge",
                    cbar_size="8%",
                    cbar_pad="0%")

    for i, fn in enumerate(ds_list):
        for j, field in enumerate(fields_list):
            index = i + j * ncol

            # Load the data and create a single plot
            gal = Galaxy(fn.split('/')[0])
            region = gal.ds.disk([0.5, 0.5, 0.5], [0, 0, 1],
                                 2.0 * yt.units.kpc, 2.0 * yt.units.kpc)

            if field == 'number_density':
                p = yt.ProjectionPlot(gal.ds,
                                      axis,
                                      field,
                                      weight_field='number_density',
                                      width=width,
                                      data_source=region)
                #            p.set_zlim(field, 1.0E-3, 1.0E3)
                p.set_zlim(field, 0.9E-3, 0.9E3)
                p.set_cmap(field, 'viridis')
                p.set_colorbar_label(field, r'n (cm$^{-3}$)')

                if gal.ds.parameters['NumberOfParticles'] > 0:
                    p.annotate_particles((1.0, 'kpc'),
                                         p_size=0.5,
                                         ptype='main_sequence_stars',
                                         col='white')

            elif field == 'temperature':
                p = yt.SlicePlot(gal.ds,
                                 axis,
                                 field,
                                 width=width,
                                 data_source=region)
                #            p.set_zlim(field, 1.0E2, 1.0E7)
                p.set_zlim(field, 1.1E2, 0.9E7)
                p.set_cmap(field, 'RdYlBu_r')
                p.set_colorbar_label(field, r'T (K)')
            elif field == 'H_p0_number_density':
                p = yt.ProjectionPlot(gal.ds,
                                      axis,
                                      field,
                                      width=width,
                                      data_source=region,
                                      weight_field=None)
                #            p.set_zlim(field, 1.0E16, 1.0E22)
                p.set_zlim(field, 1.1E16, 0.9E22)
                p.set_cmap(field, 'Greys')
                p.set_colorbar_label(field, r'N$_{\rm HI}$ (cm$^{-2}$)')
            elif field == 'H2_p0_number_density':
                p = yt.ProjectionPlot(gal.ds,
                                      axis,
                                      field,
                                      width=width,
                                      data_source=region,
                                      weight_field=None)
                #            p.set_zlim(field, 6.0E18, 1.0E21)
                #p.set_zlim(field, 6.1E18, 0.9E21)
                p.set_zlim(field, 1.0E16, 4.0E20)
                p.set_cmap(field, 'plasma')
                p.set_colorbar_label(field, r'N$_{\rm H_2}$ (cm$^{-2}$)')
            elif field == 'O_Number_Density':
                p = yt.ProjectionPlot(gal.ds,
                                      axis,
                                      field,
                                      width=width,
                                      data_source=region,
                                      weight_field=None)
                #            p.set_zlim(field, 1.0E12, 1.0E17)
                p.set_zlim(field, 1.1E12, 0.9E17)
                p.set_cmap(field, 'magma')
                p.set_colorbar_label(field, r'N$_{\rm O}$ (cm$^{-2}$)')

            p.set_axes_unit('kpc')
            p.set_buff_size(1600)

            # This forces the ProjectionPlot to redraw itself on the AxesGrid axes.
            plot = p.plots[field]
            plot.figure = fig
            plot.axes = grid[index].axes

            if ((index + 1) % (nrow)):
                plot.cax = grid.cbar_axes[index / nrow]

        # Finally, this actually redraws the plot.
            p._setup_plots()

    #for cax in grid.cbar_axes:
    #    cax.toggle_label(True)
    #    cax.axis[cax.orientation].set_label('label')
    fig.set_size_inches(fsize * nrow, fsize * ncol)
    plt.savefig(outdir + 'multiplot_4x4_' + axis + '_w%.2f.png' % (width[0]))

    del (fig)
    return
Ejemplo n.º 6
0
def check_all_masses(ds, data, ds0=None, time_cut=-1.0):

    pt = data['particle_type']

    # cut out DM
    select = pt >= 11

    pt = pt[select]

    bm = data['birth_mass'][select].value
    pm = data['particle_mass'][select].convert_to_units('Msun').value
    z = data['metallicity_fraction'][select].value

    elements = util.species_from_fields(ds.field_list)

    all_stars = generate_model_stars(
        bm,
        z,
        abund=elements,
        include_popIII=ds.parameters['IndividualStarPopIIIFormation'])

    lifetime = data['dynamical_time'][select].convert_to_units('Myr')
    birth = data['creation_time'][select].convert_to_units('Myr')
    age = ds.current_time.convert_to_units('Myr') - birth

    model_wind_ejecta = {}  # total_wind_ejecta
    for k in all_stars[0].wind_ejecta_masses().keys():
        model_wind_ejecta[k] = np.array(
            [x.wind_ejecta_masses()[k] for x in all_stars])

    model_sn_ejecta = {}
    for k in all_stars[0].sn_ejecta_masses.keys():
        model_sn_ejecta[k] = np.array(
            [x.sn_ejecta_masses[k] for x in all_stars])

    # correct for AGB stars that haven't died
    AGB = (bm < 8.0) * (pt == 11)
    select = (bm > 8.0) * (pt == 11)
    factor = age / lifetime
    factor[factor > 1.0] = 1.0

    time_select = birth > time_cut

    #
    # Apply correction and zero out SN abundances for stars that have not gone SNe
    #
    for k in list(model_wind_ejecta.keys()):
        model_wind_ejecta[k][AGB] = 0.0
        model_sn_ejecta[k][(pt == 11)] = 0.0  # regular stars
        model_sn_ejecta[k][(pt == 14)] = 0.0  # popIII stars
        model_wind_ejecta[k][
            select] = model_wind_ejecta[k][select] * factor[select]

    total_model_ejecta = {}
    for k in list(model_wind_ejecta.keys()):
        total_model_ejecta[k] = np.sum(
            model_sn_ejecta[k][time_select]) + np.sum(
                model_wind_ejecta[k][time_select])

    #print("xxxxxx", np.sum(model_sn_ejecta['O']), np.sum(model_sn_ejecta['O'][bm>8.0]), np.sum(model_sn_ejecta['O'][bm<8.0]))
    # construct the indivdual mode dictionary
    separate_mode_ejecta = {
        'AGB': {},
        'SWind': {},
        'SNII': {},
        'SNIa': {},
        'PopIII': {},
        'Total': {}
    }
    for k in list(model_wind_ejecta.keys()):
        separate_mode_ejecta['PopIII'][k] = np.sum(
            model_sn_ejecta[k][(pt == 13) * (z < 2.2E-6)])
        separate_mode_ejecta['SNII'][k] = np.sum(
            model_sn_ejecta[k][(bm > 8.0) * (z > 2.2E-6)])
        separate_mode_ejecta['SNIa'][k] = np.sum(
            model_sn_ejecta[k][(bm < 8.0) * (z > 2.2E-6)])
        separate_mode_ejecta['SWind'][k] = np.sum(
            model_wind_ejecta[k][bm > 8.0])
        separate_mode_ejecta['AGB'][k] = np.sum(model_wind_ejecta[k][bm < 8.0])
        separate_mode_ejecta['Total'][k] = np.sum([
            separate_mode_ejecta[x][k]
            for x in ['AGB', 'SWind', 'SNII', 'SNIa', 'PopIII']
        ])
    for k in list(separate_mode_ejecta.keys()):
        separate_mode_ejecta[k]['Total Tracked Metals'] = np.sum([
            separate_mode_ejecta[k][x]
            for x in list(separate_mode_ejecta[k].keys())
            if (not x in ['m_tot', 'm_metal', 'H', 'He'])
        ])

    if os.path.exists(str(ds) + '_galaxy_data.h5'):
        dd_data = dd.io.load(str(ds) + '_galaxy_data.h5')
        dd_data['gas_meta_data']['masses']['Type'] = separate_mode_ejecta
        dd.io.save(str(ds) + '_galaxy_data.h5', dd_data)

    # now do this for the individual abundances on grid:
    grid_masses = {}
    for k in list(model_wind_ejecta.keys()):
        if k is 'm_tot' or k is 'm_metal':
            continue

        grid_masses[k] = np.sum(data[k + '_Density'] * ds.mass_unit / ds.length_unit**3 *\
                                   data['cell_volume']).convert_to_units('Msun').value

        if not (ds0 is None):
            grid_masses[k] = grid_masses[k] - np.sum(ds0[k + '_Density'] * ds0.mass_unit / ds0.length_unit**3 *\
                                       ds0['cell_volume']).convert_to_units('Msun').value


#        else:
#            grid_masses[k] = grid_masses[k] - 1.0E-10 * np.sum(data['cell_mass'].to('Msun')).value

    gal = Galaxy(str(ds))
    outflow_masses = gal.boundary_mass_flux

    #print total_model_ejecta
    #print grid_masses
    #print outflow_masses

    for k in separate_mode_ejecta.keys():
        print(k, separate_mode_ejecta[k]['O'], separate_mode_ejecta[k]['N'])

    print(list(grid_masses.keys()))
    print(
        "Element Total_on_Grid Total_Outflow Sum_Injected Total_model_mass Percent_error"
    )
    for k in list(grid_masses.keys()):
        okey = k + '_Density'
        error = 100 * (outflow_masses[okey] + grid_masses[k] -
                       total_model_ejecta[k]) / total_model_ejecta[k]
        print("%2s     %8.8E %8.8E %8.8E %8.8E %4.4f" %
              (k, grid_masses[k], outflow_masses[okey], grid_masses[k] +
               outflow_masses[okey], total_model_ejecta[k], error))

    return all_stars, model_sn_ejecta, model_wind_ejecta, total_model_ejecta
Ejemplo n.º 7
0
import numpy as np
from galaxy_analysis.analysis import gas_abundance as GA
from galaxy_analysis.analysis import Galaxy

from galaxy_analysis.static_data import ISM  # some pre-defined masks

#
# Test code to load a data set and then compute the gas
# phase mass fraction / abundance distribution for an arbitrarily
# defined mask
#
gal = Galaxy('DD0401')  # load galaxy

# mask is just a boolean mask over the cells. This hould
# be easy to make arbitrarily complex things
data_source = gal.disk
#mask        = np.ones(np.shape(gal.disk['x']))

abundances = {}
for n in [50, 100, 150]:
    mask = (data_source['number_density'] > n)
    abundances[n] = GA.compute_abundance_stats(
        gal.ds,
        data_source,
        mask=mask,
        fraction_fields=['O_Fraction', 'N_Fraction'])