Example #1
0
def generate_projection_data(output, field_list, weight_list, width):
    sim = 'romulusC'
    rvir = rom.get_romulus_rvir(sim, output)
    #    z = get_redshift(output)
    #    width = width / (1. + z)
    #    plot_data = h5.File('/nobackup/ibutsky/data/YalePaper/white_paper_plot_data', 'a')
    plot_data = h5.File(
        '/nobackup/ibutsky/data/YalePaper/multipanel_romulusC_%i_plot_data' %
        (output), 'a')
    ds = yt.load('/nobackup/ibutsky/simulations/romulusC/romulusC.%06d' %
                 (output))
    z = ds.current_redshift
    width = width / (1. + z)
    trident.add_ion_fields(ds, ions=['H I'])
    cen = rom.get_romulus_yt_center(sim, output, ds)

    # set up projection plots for fields that are weighted and unweighted
    for field, weight in zip(field_list, weight_list):
        dset = field[1]
        if dset not in plot_data.keys():
            proj = yt.ProjectionPlot(ds,
                                     'y',
                                     field,
                                     weight_field=weight,
                                     center=cen)
            proj_frb = proj.data_source.to_frb((width, 'Mpc'), 1600)

            plot_data.create_dataset(dset, data=np.array(proj_frb[field]))
            plot_data.flush()
                                         xlim = xlim, ylim = ylim, zlim = zlim, nbins = nbins[i],\
                                   cbar_label = cbar_label, xscale = xscale, cmap = cmap, data_cut = data_cut)
    if row == 0:
        ax.set_xlabel('')
        ax.xaxis.set_ticks_position('none')
    if col == 0:
#        cbar = fig.colorbar(im, ax = ax)
        cbar.set_label('')
        cbar.set_ticklabels('')
        cbar.set_ticks(None)
        cbar.update_ticks()
    elif col == 1:
        ax.set_ylabel('')
        ax.yaxis.set_ticks_position('none')
    ax.annotate(title_list[i], xy = (300, 1.5e-3), fontsize = 14)
    rvir = rom.get_romulus_rvir('romulusC', output)
    ipd.add_cluster_metallicity_observations(ax, color = 'white', rvir = rvir)


ffig, aax, im, cbar = ipd.plot_phase(xfield, yfield, 'xray_emissivity', fig = fig, ax = axes[0][0], \
                                         profile = profile, profile_linestyle = 'dotted', \
                                         profile_label = 'X-ray weighted', \
                                         profile_color = profile_color, do_pcolormesh = False,\
                                         output = output, xlabel = xlabel, ylabel = ylabel, \
                                         xlim = xlim, ylim = ylim, zlim = zlim, nbins = nbins[i],\
                                     cbar_label = cbar_label, xscale = xscale, cmap = cmap, data_cut = 'hot_icm2')


axes[0][0].legend()
fig.tight_layout()
plt.savefig('multipanel_metallicity_%06d.png'%(output), dpi = 300)
matplotlib.use('Agg')
import matplotlib.pylab as plt
import h5py as h5
import sys

import numpy as np
import romulus_analysis_helper as rom_help
import ion_plot_definitions as ipd
import seaborn as sns

sns.set_style("ticks", {'axes.grid': True, 'grid.linestyle': '--'})

output = int(sys.argv[1])
plot_type = sys.argv[2]

rvir = rom_help.get_romulus_rvir('romulusC', output)
#rvir = rom_help.get_romulusC_r200(output)
#rvir = 1.0
xmax = 3000
xmax /= rvir
xmax = 3.
dset_list = [
    'rbins_cold', 'rbins_warm', 'rbins_hot', 'mass_cold', 'mass_warm',
    'mass_hot'
]
if plot_type == 'gas':
    plot_data = h5.File(
        '/nobackup/ibutsky/data/YalePaper/romulusC_%i_gas_temperature_profile_data_icm'
        % (output), 'r')
elif plot_type == 'metal':
    plot_data = h5.File(
Example #4
0
import yt
import trident
import h5py as h5
import numpy as np
import sys
import romulus_analysis_helper as rom

sim = 'romulusC'
output = 3035
field = ('gas', 'H_p0_number_density')

plot_data = h5.File('/nobackup/ibutsky/data/YalePaper/white_paper_plot_data',
                    'a')
ds = yt.load('/nobackup/ibutsky/simulations/romulusC/romulusC.%06d' % (output))
cen = rom.get_romulus_yt_center(sim, output, ds)
rvir = rom.get_romulus_rvir(sim, output)
trident.add_ion_fields(ds, ions=['H I', 'O VI'])

p = yt.ProjectionPlot(ds,
                      'y',
                      field,
                      weight_field=None,
                      center=cen,
                      width=(5, 'Mpc'))
p.set_cmap(field, 'purple_mm')
p.set_zlim(field, 3e12, 1e17)
p.set_colorbar_label(field, '$\mathrm{H\ I\ Column\ Density\ (cm}^{-2})$')
p.set_font_size(26)
p.save('HI_fg2009.png')

field = ('gas', 'O_p5_number_density')
Example #5
0
def generate_phase_plot_data(output, xfield, yfield, zfield, icm_cut = None, weight_field = ('Gas', 'Mass'), \
                             xbins = 128, ybins = 128, fractional = False, xlim = None, ylim = None, xunit = None, \
                             yunit = None, zunit = None, xlog = None, ylog = None, zlog = None, radius = None):
    sim = 'romulusC'
    ds = ytf.load_romulusC(output, ions=['H I', 'C IV', 'O VI'])

    redshift = ds.current_redshift
    if output == 4096:
        redshift = 0.01
    #xray_fields = yt.add_xray_emissivity_field(ds, 0.5, 7.0, redshift=redshift, \
    #               cosmology=ds.cosmology, metallicity=("Gas", "metallicity2"), table_type='cloudy')

# ds.add_field(('gas', 'xray_luminosity'), function = _xray_luminosity2, particle_type = True)
# ds.add_field(('gas', 'xray_intensity'), function = _xray_intensity2, units = 'erg/(arcsec**2*cm**3*s)', particle_type = True)

    cen = rom.get_romulus_yt_center(sim, output, ds)
    rvir = rom.get_romulus_rvir(sim, output)

    icm_mask = None

    if radius:
        sp = ds.sphere(cen, (radius, 'kpc'))
    else:
        sp = ds.sphere(cen, (3. * rvir, 'kpc'))

    bv = sp.quantities.bulk_velocity().in_units('km/s')
    print(bv)

    if icm_cut == 'xray':
        icm_mask = "(obj[('gas', 'xray_intensity')] > 1e-44)"
    elif icm_cut == 'uv':
        icm_mask = "(obj[('gas', 'particle_H_nuclei_density')] > 1e-6) & (obj[('gas', 'particle_H_nuclei_density')] < 1e-2)"
        icm_mask = "& (obj[('gas', 'temperature')] > 1e4) & (obj[('gas', 'temperature')] < 1e6)"

    elif icm_cut == 'cold':
        icm_mask = "(obj[('gas', 'temperature')] < 1e4)"
    elif icm_cut == 'cool':
        icm_mask = " (obj[('gas', 'temperature')]  >= 1e4) & (obj[('gas', 'temperature')] < 1e5)"
    elif icm_cut == 'coolwarm':
        icm_mask = "(obj[('gas', 'temperature')]  >= 1e4) & (obj[('gas', 'temperature')] <= 1e6)"
    elif icm_cut == 'warm':
        icm_mask = "(obj[('gas', 'temperature')]  >= 1e5) & (obj[('gas', 'temperature')] < 1e6)"
    elif icm_cut == 'hot':
        icm_mask = "(obj[('gas', 'temperature')] >= 1e6)"

    elif icm_cut == 'hot_icm':
        icm_mask = "(obj[('gas', 'particle_H_nuclei_density')] < 0.1) & (obj[('gas', 'temperature')] >= 1e6)"
    elif icm_cut == 'warm_icm':
        icm_mask = "(obj[('gas', 'particle_H_nuclei_density')] < 0.1) & (obj[('gas', 'temperature')]  >= 1e5) & (obj[('gas', 'temperature')] < 1e6)"
    elif icm_cut == 'cool_icm':
        icm_mask = "(obj[('gas', 'particle_H_nuclei_density')] < 0.1) & (obj[('gas', 'temperature')]  >= 1e4) & (obj[('gas', 'temperature')] < 1e5)"
    elif icm_cut == 'cold_icm':
        icm_mask = "(obj[('gas', 'particle_H_nuclei_density')] < 0.1) & (obj[('gas', 'temperature')] <= 1e4)"
    elif icm_cut == 'hot_icm2':
        icm_mask = "(obj[('gas', 'particle_H_nuclei_density')] < 0.01) & (obj[('gas', 'temperature')] >= 1e6)"

    if yfield[1] == 'metallicity':
        if icm_mask:
            icm_mask += "& (obj[('gas', 'metallicity')] > 0)"
        else:
            icm_mask = "(obj[('gas', 'metallicity')] > 0)"

    if icm_mask == None:
        icm = sp
    else:
        icm = sp.cut_region(icm_mask)

    ph = yt.PhasePlot(icm, xfield, yfield, zfield, weight_field = weight_field, \
                      fractional = fractional, x_bins = xbins, y_bins = ybins)

    ytf.setup_phase_axes(ph, [xfield, yfield, zfield],
                         unit_list=[xunit, yunit, zunit],
                         log_list=[xlog, ylog, zlog])

    if ylim:
        ph.set_ylim(ylim[0], ylim[1])
    if xlim:
        ph.set_xlim(xlim[0], xlim[1])
    profile = ph.profile
    ph.save()

    outfile_name = '/nobackup/ibutsky/data/YalePaper/romulusC.%06d_phase_data_%s_%s_%s'\
                   %(output, xfield[1], yfield[1], zfield[1])
    if weight_field:
        outfile_name += '_%s' % (weight_field[1])
    if icm_cut:
        outfile_name += '_%s' % (icm_cut)
    outfile = h5.File(outfile_name + '.h5', 'w')

    outfile.create_dataset(xfield[1], data=profile.x)
    outfile.create_dataset(yfield[1], data=profile.y)
    outfile.create_dataset(zfield[1], data=profile[zfield])
    outfile.create_dataset('weight_field', data=str(weight_field))
    outfile.flush()