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()
import matplotlib.pylab as plt import sys import yt from yt.units.yt_array import YTQuantity import numpy as np import yt_functions as ytf import ion_plot_definitions as ipd import romulus_analysis_helper as rom_help #output = int(sys.argv[1]) output = 3035 ds = ytf.load_romulusC(output) cen = rom_help.get_romulus_yt_center('romulusC', output, ds) ad = ds.sphere(cen, (3300, 'kpc')) #sp = ad.cut_region(["(obj[('gas', 'metal_cooling_time')]>0) & (obj[('gas', 'metal_primordial_cooling_time_ratio')] > 0) & (obj[('gas', 'temperature')] >= 1e4) & (obj[('gas', 'temperature')] <= 1e6) & (obj[('gas', 'particle_H_nuclei_density')] > 1e-6) & (obj[('gas', 'particle_H_nuclei_density')] < 1e-2)"]) sp = ad.cut_region(["(obj[('gas', 'temperature')] >= 1e4) & (obj[('gas', 'temperature')] <= 1e6) & (obj[('gas', 'particle_H_nuclei_density')] > 1e-6) & (obj[('gas', 'particle_H_nuclei_density')] < 1e-2)"]) #sp = ad xfield = ('gas', 'spherical_position_radius') yfield = ('Gas', 'Mass') #mass enclosed needs to have all mass, not just CGM mass pm = yt.ProfilePlot(ad, xfield, yfield, weight_field = None, accumulation = True, n_bins = 128) pm.set_unit(xfield, 'cm') pm.set_unit(yfield, 'g') pm.set_log(xfield, False) profile = pm.profiles[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')
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()
def generate_column_data(sim, output, ion_list, width, res=800, cluster_center=True, ionization_table='hm2012'): field_list = ion_help.generate_ion_field_list(ion_list, 'number_density') ds = yt.load('/nobackupp2/ibutsky/simulations/%s/%s.%06d' % (sim, sim, output)) trident.add_ion_fields(ds, ions=ion_list) # "regular" column density measured as impact parameter from cluster center if cluster_center: fn = '/nobackupp2/ibutsky/data/%s/%s.%06d_column_data.h5' % (sim, sim, output) if ionization_table == 'fg2009': fn = '/nobackupp2/ibutsky/data/%s/%s.%06d_fg2009_column_data.h5' % ( sim, sim, output) cdens_file = h5.File(fn) print(list(cdens_file.keys())) center = rom_help.get_romulus_yt_center(sim, output, ds) axis_list = ['x', 'y', 'z'] print('using cluster center') else: cdens_file = h5.File( '/nobackupp2/ibutsky/data/%s/%s.%06d_column_data_special_regions.h5' % (sim, sim, output), 'a') id_list, center_x, center_y, width_list = \ np.loadtxt('/nobackup/ibutsky/data/YalePaper/%s.%06d_gas_rich_y_coordinate_list.dat', skiprows=2) axis_list = ['y'] width = yt.YTQuantity(width, 'kpc') px, py = np.mgrid[-width / 2:width / 2:res * 1j, -width / 2:width / 2:res * 1j] radius = (px**2.0 + py**2.0)**0.5 if "px" not in cdens_file.keys(): cdens_file.create_dataset("px", data=px.ravel()) if "py" not in cdens_file.keys(): cdens_file.create_dataset("py", data=py.ravel()) if "radius" not in cdens_file.keys(): cdens_file.create_dataset("radius", data=radius.ravel()) for axis in axis_list: # frb = ion_help.make_projection(ds, axis, field_list, center, width, res = res) for i, ion in enumerate(ion_list): dset = "%s_%s" % (ion.replace(" ", ""), axis) if dset not in cdens_file.keys(): print(dset) sys.stdout.flush() frb = ion_help.make_projection(ds, axis, field_list[i], center, width, res=res) cdens_file.create_dataset(dset, data=frb[field_list[i]].ravel()) cdens_file.flush()