Exemple #1
0
def calc_cddf(**kwargs):
    ion = kwargs.get("ion", "H I 1216")
    # load the simulation
    forced_ds = yt.load(
        "/Users/molly/foggie/halo_008508/nref11n/nref11n_nref10f_refine200kpc_z4to2/RD0020/RD0020"
    )
    track_name = "/Users/molly/foggie/halo_008508/nref11n/nref11n_nref10f_refine200kpc_z4to2/halo_track"
    output_dir = "/Users/molly/Dropbox/foggie-collab/plots_halo_008508/nref11n/comparisons/"
    natural_ds = yt.load(
        "/Users/molly/foggie/halo_008508/nref11n/natural/RD0020/RD0020")
    ## output_dir = "/Users/molly/Dropbox/foggie-collab/plots/halo_008508/natural/nref11/spectra/"
    os.chdir(output_dir)
    track = Table.read(track_name, format='ascii')
    track.sort('col1')
    zsnap = forced_ds.get_parameter('CosmologyCurrentRedshift')

    proper_box_size = get_proper_box_size(forced_ds)
    forced_box, forced_c, width = get_refine_box(forced_ds, zsnap, track)
    natural_box, natural_c, width = get_refine_box(natural_ds, zsnap, track)
    width = width * proper_box_size

    # forced_box = forced_ds.box([xmin, ymin, zmin], [xmax, ymax, zmax])
    # forced_c = forced_ds.arr(halo_center,'code_length')
    # natural_box = natural_ds.box([xmin, ymin, zmin], [xmax, ymax, zmax])
    # natural_c = natural_ds.arr(halo_center,'code_length')
    # width = (197./forced_ds.hubble_constant)/(1+forced_ds.current_redshift)
    print "width = ", width, "kpc"

    axis = 'z'
    res = [1000, 1000]

    trident.add_ion_fields(forced_ds, ions=['O VI'])
    trident.add_ion_fields(natural_ds, ions=['O VI'])
    # trident.add_ion_fields(forced_ds, ions=['C II'])
    # trident.add_ion_fields(natural_ds, ions=['C II'])

    ## start with HI

    ion = 'O_p5_number_density'

    dph_forced = yt.ProjectionPlot(forced_ds,axis,('gas',ion), center=forced_c, \
                            width=(width,"kpc"), data_source=forced_box)
    frb = dph_forced.frb['gas', ion]
    hi_forced = np.array(np.log10(frb))

    dph_natural = yt.ProjectionPlot(natural_ds,axis,('gas',ion), center=natural_c, \
                            width=(width,"kpc"), data_source=natural_box)
    frb = dph_natural.frb['gas', ion]
    hi_natural = np.array(np.log10(frb))

    # plot
    fig, ax = plt.subplots(figsize=(6, 6))
    ax.hist(hi_forced.ravel(), cumulative=True, normed=True, bins=500, \
                    histtype='step', range=[12,19], lw=2, label="forced")
    ax.hist(hi_natural.ravel(), cumulative=True, normed=True, bins=500, \
                    histtype='step', range=[12,19],lw=2, label="natural")
    plt.legend()
    plt.xlabel('log OVI')
    plt.ylabel('cumulative fraction')
    plt.savefig('ovi_cddf_compare.png')
Exemple #2
0
def make_frbs(filename,center,fields,ions,fdbk=False):
    ds = yt.load(filename)
    args = filename.split('/')

    trident.add_ion_fields(ds,ions=ions)

    if fdbk== True:
        print 'in fdbk'
        halo_center, halo_velocity = get_halo_center(ds,center)

        refine_box = fdbk_refine_box(ds,halo_center)

        width = [(160,'kpc'),(80.,'kpc')]
        resolution = (320,160)
        for field in fields:
            fileout = args[-3]+'_'+args[-2]+'_x_'+field+'.cpkl'
            obj = ds.proj(field,'x',data_source=refine_box)
            frb = obj.to_frb(width,resolution,center=box_center)
            cPickle.dump(frb[field],open(fileout,'wb'),protocol=-1)

    else:
        print 'in else'
        halo_center, halo_velocity = get_halo_center(ds,center)
        refine_box = sym_refine_box(ds,halo_center)
        width = [(40,'kpc'),(100.,'kpc')]
        resolution = (80,200)

        for field in fields:
            fileout = args[-3]+'_'+args[-2]+'_x_'+field+'.cpkl'
            obj = ds.proj(field,'x',data_source=refine_box)
            frb = obj.to_frb(width,resolution,center=halo_center)
            cPickle.dump(frb[field],open(fileout,'wb'),protocol=-1)
    return
Exemple #3
0
def multiplot(): 

    field = 'density'  
    view = 'projection' 
    field = 'O_p5_number_density'

    track = Table.read('complete_track', format='ascii') 
    track.sort('col1') 

    outs = [x+55 for x in range(400)]

    for n in outs: 

        fig = plt.figure() 
        grid = AxesGrid(fig, (0.5,0.5,1.5,1.5),
                nrows_ncols = (1, 5),
                axes_pad = 0.1,
                label_mode = "1",
                share_all = True,
                cbar_location="right",
                cbar_mode="edge",
                cbar_size="5%",
                cbar_pad="0%")

        strset = 'DD00'+str(n) 
        if (n > 99): strset = 'DD0'+str(n) 
        fields = [field, field, field, field, field] 
        snaps = ['nref10_track_2/'+strset+'/'+strset, 'nref10_track_lowfdbk_1/'+strset+'/'+strset, 
             'nref10_track_lowfdbk_2/'+strset+'/'+strset, 'nref10_track_lowfdbk_3/'+strset+'/'+strset,
             'nref10_track_lowfdbk_4/'+strset+'/'+strset]

        for i, (field, snap) in enumerate(zip(fields, snaps)):
    
            ds = yt.load(snap) 
            zsnap = ds.get_parameter('CosmologyCurrentRedshift')
            trident.add_ion_fields(ds, ions=['C IV', 'O VI','H I','Si III'])

            centerx = np.interp(zsnap, track['col1'], 0.5*(track['col2']+track['col5']) ) 
            centery = np.interp(zsnap, track['col1'], track['col3']+30./143886.) 
            centerz = np.interp(zsnap, track['col1'], 0.5*(track['col4']+track['col7']) ) 
            center = [centerx, centery, centerz] 
    
            box = ds.r[ center[0]-200./143886:center[0]+200./143886, center[1]-250./143886.:center[1]+250./143886., center[2]-40./143886.:center[2]+40./143886.]
    
            # projection 
            p = yt.ProjectionPlot(ds, 'z', field, center=center, width=((120,'kpc'),(240,'kpc')), data_source=box)
            if (field == 'density'): 
                p.set_unit('density', 'Msun / pc**2')
                p.set_zlim('density', 0.01, 1000) 
            if ('O_p5' in field): 
                p.set_zlim("O_p5_number_density",1e11,1e15)
            if (i < 1): p.annotate_timestamp(corner='upper_left', redshift=True, draw_inset_box=True, text_args={'color':'white', 'size':'small'} )
    
            # This forces the ProjectionPlot to redraw itself on the AxesGrid axes.
            plot = p.plots[field]
            plot.figure = fig
            plot.axes = grid[i].axes
            p._setup_plots()   # Finally, redraw the plot.
    
        plt.savefig(strset+'_multiplot_'+field+'_projection.png', bbox_inches='tight')
def calcIntVel(directory, runName, runNumber, ions, velocityBin, frameVel):
    #load and add ions to the dataset
    velocityBin = velocityBin * 1.0e5  #convert to cm/s
    frameVel = frameVel * 1.0e5  #convert to cm/s
    data = yt.load(directory + runName + '/KH_hdf5_chk_' + runNumber)
    data.add_field(('gas', 'metallicity'),
                   function=_metallicity,
                   display_name="Metallicity",
                   units='Zsun')

    #add ion fields to the dataset
    IntVels = []
    for ion in ions:
        tri.add_ion_fields(data, ions=[ion['ion']])

        #make cylinder
        reg = data.disk([0.0, 0.2 * kpc, 0.0], [0, 1, 0], (0.25, 'kpc'),
                        (1.6, 'kpc'))
        #reg = data.all_data()

        #meanVel + frameVel will be the final mean velocity
        meanVel = reg.quantities.weighted_average_quantity(
            "velocity_y", weight_field=ion['fieldname'])
        finalmeanVel = meanVel + frameVel

        IntVels.append(finalmeanVel)

    return IntVels
Exemple #5
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()
def generate_sim_column_densities(sim, ion_list, res = 800):
    cdens_file = h5.File('../../data/simulated_ion_column_densities_%s.h5'%(sim), 'a')

    if sim == 'ad' or sim == 'stream':
        ds = yt.load('/Users/irynabutsky/Work/galaxy/g160_torB_%s/DD2600'%(sim))
    elif sim == 'P0':
        ds = yt.load('/Users/irynabutsky/Work/galaxy/P0/P0.003195')
        
    trident.add_ion_fields(ds, ion_list)
    if sim == 'P0':
#        center = YTArray([-1.693207e4, -1.201068e4, 5.303337e3], 'kpc')
        center = [-0.42323229, -0.30021773,  0.13256167]
    else:
        v, center = ds.h.find_max(("gas", "density")) 
    print(center)
    
    field_list = ipd.generate_ion_field_list(ion_list, 'number_density', model = 'P0')

    width = yt.YTQuantity(1000, '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 "radius" not in cdens_file.keys():
        cdens_file.create_dataset("radius", data = radius.ravel())

    # note: something weird going on in x-axis with P0
    for axis in ['y', 'z']:
        frb = ipd.make_projection(ds, axis, field_list, center, width)
        
        for i, ion in enumerate(ion_list):
            dset = "%s_%s" % (ion.replace(" ", ""), axis)
            if dset not in cdens_file.keys():
                cdens_file.create_dataset(dset, data=frb[field_list[i]].ravel())
                cdens_file.flush()
Exemple #7
0
def generate_sim_column_densities(sim, ion_list, res=800):
    #cdens_file = h5.File('../../data/simulated_ion_column_densities_%s.h5'%(sim), 'w')
    cdens_file = h5.File('test.h5', 'w')

    ds, center, bv = spg.load_simulation_properties(sim)
    print(center)
    center = ds.arr(center, 'kpc')

    trident.add_ion_fields(ds, ion_list)

    field_list = ipd.generate_ion_field_list(ion_list,
                                             'number_density',
                                             model='P0')

    width = yt.YTQuantity(110, '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 "radius" not in cdens_file.keys():
        cdens_file.create_dataset("radius", data=radius.ravel())

    # note: something weird going on in x-axis with P0
    for axis in ['x', 'y', 'z']:
        frb = ipd.make_projection(ds, axis, field_list, center, width)

        for i, ion in enumerate(ion_list):
            dset = "%s_%s" % (ion.replace(" ", ""), axis)
            if dset not in cdens_file.keys():
                cdens_file.create_dataset(dset,
                                          data=frb[field_list[i]].ravel())
                cdens_file.flush()
Exemple #8
0
def create_coldens_frbs():
    dx = np.unique(rb['dx'])[1]
    #dx = ds.arr(0.1829591205,'kpc').in_units('code_length')
    dxs_list = [0.5,1,5,10]
    dxs_list = [ds.quan(q,'kpc').in_units('code_lenght') for q in dxs_list]
    res_list = np.append(dx,dxs_list)
    res_list = ds.arr(res_list,'code_length')

    trident.add_ion_fields(ds, ions=['Si II', 'Si III', 'Si IV',
                                     'C II', 'C III', 'C IV', 'O VI', 'Mg II'])
    lines = ['H_p0_number_density','Si_p1_number_density','Si_p2_number_density',
             'Si_p3_number_density','C_p1_number_density','C_p2_number_density',
             'C_p3_number_density','O_p5_number_density','Mg_p1_number_density']

    for line in lines:
        field = line
        print line
        for index in 'xyz':
            print index
            for res in res_list:
                reskpc = round(res.in_units('kpc'),2)
                print res,' kpc'
                num_cells = np.ceil(rb_width/res)

                if res == res_list[0]:
                    fileout = 'frb'+index+'_'+args[-3]+'_'+args[-2]+'_'+field+'_forcedres.cpkl'
                else:
                    fileout = 'frb'+index+'_'+args[-3]+'_'+args[-2]+'_'+field+'_'+str(reskpc)+'kpc.cpkl'

                obj = ds.proj(('gas',field),index,data_source=rb)
                frb = obj.to_frb((rb_width,'code_length'),(num_cells,num_cells),center=rb_center)
                cPickle.dump(frb[('gas',field)],open(fileout,'wb'),protocol=-1)
    return
Exemple #9
0
def generate_spectrum_plot_data(index_start, index_end, output):
    ds = yt.load('/nobackupp2/ibutsky/simulations/romulusC/romulusC.%06d'%(output))
    ion_list = ['H I', 'C II', 'C III', 'C IV', 'Si II', 'Si III', 'Si IV', 'O VI']
    trident.add_ion_fields(ds, ions=ion_list)
    ds.add_field(("gas", "particle_H_nuclei_density"), function = ytf._H_nuc, \
             particle_type = True, force_override = True, units = "cm**(-3)")

    y_start = ds.domain_left_edge[2]
    y_end = ds.domain_right_edge[2]

    center = rom.get_romulusC_center(output)
    center_x = center[0]
    center_y = center[1]
    center_z = center[2]
    print(center_x, center_y, center_z)

    ray_id, x_list, z_list = np.loadtxt('/nobackupp2/ibutsky/data/YalePaper/spectra/coordinate_list.dat',\
                                skiprows = 1, unpack=True)

    for i in range(index_start, index_end):
        h5file = h5.File('/nobackup/ibutsky/data/YalePaper/romulusC.%06d_sightline_%i_plot_data.h5'%(output, i), 'w')
        # note: the plus is important. x_list, z_list counted from center                              
        x = ((x_list[i] + center_x) / ds.length_unit).d   
        z = ((z_list[i] + center_z) / ds.length_unit).d
        print(x_list[i], z_list[i], ds.length_unit)
        ycen = (center_y / ds.length_unit).d

        # y from -2.5 mpc of center to 2.5 mpc from center
        ylen = (2500. / ds.length_unit).d
        ray_start = [x, ycen-ylen , z]
        ray_end = [x, ycen+ylen, z]

        ad = ds.r[ray_start:ray_end]
        ray = trident.make_simple_ray(ds,
                                      start_position = ray_start,
                                      end_position = ray_end,
                                      lines=ion_list)
        ad_ray = ray.all_data()

        field_list = ['y', 'temperature', 'density', 'metallicity', 'dl']
        source_list = [ad, ad, ad, ad, ad_ray]
        unit_list = ['kpc', 'K', 'g/cm**3', 'Zsun', 'cm']
        yt_ion_list = ipd.generate_ion_field_list(ion_list, 'number_density', full_name = False)
        yt_ion_list[0] = 'H_number_density'
        field_list = np.append(field_list, yt_ion_list)
        for j in range(len(yt_ion_list)):
            unit_list.append('cm**-3')
            source_list.append(ad_ray)

        for field,source,unit in zip(field_list, source_list, unit_list):
            if field not in h5file.keys():
                h5file.create_dataset(field, data = source[('gas', field)].in_units(unit))
                h5file.flush()
        h5file.create_dataset('y_lr', data = ad_ray['y'].in_units('kpc'))
        h5file.flush()
        print("saved sightline data %i\n"%(i))
def load_simulation_properties(model,
                               output=3195,
                               ion_list=[
                                   'H I', 'O VI', 'Si II', 'Si III', 'Si IV',
                                   'Mg II', 'N V', 'C IV'
                               ]):
    # note AHF finds this value for P0:  78.13         -239.42          -65.99
    if model == 'P0':
        ds = yt.load(
            '/Users/irynabutsky/simulations/patient0/pioneer50h243.1536gst1bwK1BH.%06d'
            % output)
        gcenter = YTArray([-16933.77317667, -12009.28144633, 5305.25448309],
                          'kpc')  # generated with shrink sphere
        bulk_velocity = YTArray([73.05701672, -239.32976334, -68.07892736],
                                'km/s')
        ds.add_field(('gas', 'pressure'),
                     function=_Pressure,
                     sampling_type='particle',
                     units=ds.unit_system["pressure"])
    elif model == 'P0_agncr':
        print('adding cosmic ray')
        ds = yt.load(
            '/Users/irynabutsky/simulations/patient0_agncr/pioneer.%06d' %
            output)
        gcenter = YTArray([-16933.48544591, -12006.24067239, 5307.33807425],
                          'kpc')  # generated with shrink sphere
        bulk_velocity = YTArray([74.98331176, -240.71723683, -67.77556155],
                                'km/s')
        ds.add_field(('gas', 'cr_pressure'),
                     function=_CRPressure,
                     sampling_type='particle',
                     units=ds.unit_system["pressure"])
        ds.add_field(('gas', 'pressure'),
                     function=_Pressure,
                     sampling_type='particle',
                     units=ds.unit_system["pressure"])
        ds.add_field(('gas', 'cr_eta'),
                     display_name=('$P_{\\rm c} / P_{\\rm g}$'),
                     function=_CRBeta,
                     sampling_type='particle',
                     units='')

    ds.add_field(('gas', 'O_mass'),
                 function=_omass,
                 sampling_type='particle',
                 units=ds.unit_system['mass'])
    ds.add_field(('gas', 'Fe_mass'),
                 function=_femass,
                 sampling_type='particle',
                 units=ds.unit_system['mass'])
    trident.add_ion_fields(ds, ions=ion_list)

    return ds, gcenter, bulk_velocity
Exemple #11
0
def load_romulusC(output, ions=[]):
    ds = yt.load('/nobackup/ibutsky/simulations/romulusC/romulusC.%06d' %
                 output)
    ad = ds.all_data()
    cen = YTArray(rom.get_romulus_center('romulusC', output), 'kpc')
    bv = rom.get_romulusC_bulk_velocity(output)
    ad.set_field_parameter('center', cen)
    ad.set_field_parameter('bulk_velocity', bv)
    add_thermal_fields(ds)
    if len(ions) > 0:
        trident.add_ion_fields(ds, ions=ions)
    return ds
def generate_column_data(output, ion_list, res=800, axis='y'):
    sim = 'romulusC'
    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)

    cdens_file = h5.File(
        '/nobackupp2/ibutsky/data/%s/%s.%06d_column_data.h5' %
        (sim, sim, output), 'a')
    rom_center = rom_help.get_romulus_center(sim, output)

    id_list, center_x_list, center_z_list, width_list = \
                np.loadtxt('data/temp_coordinate_list.dat'%(sim, output, axis), skiprows=3, unpack = True)

    for region_id, center_x, center_z, width in zip(id_list, center_x_list,
                                                    center_z_list, width_list):
        cdens_file = h5.File(
            '/nobackupp2/ibutsky/data/%s/%s.%06d_column_data_region_%i.h5' %
            (sim, sim, output, region_id), 'a')
        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())

        center = [
            rom_center[0] + center_x, rom_center[1], rom_center[2] + center_z
        ]
        center = (center / ds.length_unit).d

        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():
                cdens_file.create_dataset(dset,
                                          data=frb[field_list[i]].ravel())
                cdens_file.flush()
Exemple #13
0
def generate_column_data(sim, ion_list, width=400, res=800):

    field_list = ion_help.generate_ion_field_list(ion_list, 'number_density')
    ds, center = rom.load_charlotte_sim(sim)
    trident.add_ion_fields(ds, ions=ion_list)

    fn = '/nobackupp2/ibutsky/data/charlotte/%s_column_data.h5' % (sim)
    cdens_file = h5.File(fn)
    axis_list = ['x', 'y', 'z']

    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)
                p = yt.ProjectionPlot(ds,
                                      axis,
                                      field_list[i],
                                      width=width,
                                      weight_field=None,
                                      center=center)
                p.set_zlim(field_list[i], 1e13, 1e15)
                p.save()
                frb = p.data_source.to_frb(width, res)
                print(frb)
                print(frb.keys())
                print(frb[field_list[i]])
                cdens_file.create_dataset(dset,
                                          data=frb[field_list[i]].d.ravel())
                cdens_file.flush()
Exemple #14
0
def get_spec(ds, halo_center, rho_ray):

    proper_box_size = get_proper_box_size(ds)
    line_list = ['H', 'O', 'C', 'N', 'Si']

    # big rectangle box
    ray_start = [
        halo_center[0] - 250. / proper_box_size,
        halo_center[1] + 71. / proper_box_size,
        halo_center[2] - 71. / proper_box_size
    ]
    ray_end = [
        halo_center[0] + 250. / proper_box_size,
        halo_center[1] + 71. / proper_box_size,
        halo_center[2] - 71. / proper_box_size
    ]

    ray = trident.make_simple_ray(ds,
                                  start_position=ray_start,
                                  end_position=ray_end,
                                  data_filename="ray.h5",
                                  lines=line_list,
                                  ftype='gas')

    sg = trident.SpectrumGenerator(lambda_min=1020,
                                   lambda_max=1045,
                                   dlambda=0.002)
    trident.add_ion_fields(ds, ions=['C IV', 'O VI', 'H I', 'Si III'])

    sg.make_spectrum(ray, lines=line_list)
    sg.plot_spectrum('spec_final.png')
    sg.save_spectrum('spec_final.txt')

    # this makes for convenient field extraction from the ray
    ad = ray.all_data()
    dl = ad["dl"]  # line element length

    out_dict = {
        'nhi': np.sum(ad['H_number_density'] * dl),
        'no6': np.sum(ad['O_p5_number_density'] * dl),
        'nsi3': np.sum(ad['Si_p2_number_density'] * dl)
    }
    print np.sum(ad['H_number_density'] * dl)
    print np.sum(ad['O_p5_number_density'] * dl)
    print np.sum(ad['Si_p2_number_density'] * dl)

    return ray, out_dict
def makeProjections(directory, runName, f_list, savefolder, ion, fieldname):
    for i in f_list:
        data = yt.load(directory+runName+'/KH_hdf5_chk_'+i)
        data.add_field(('gas', 'metallicity'), function=_metallicity, display_name="Metallicity", units='Zsun')
        #add an ion field to the dataset
        tri.add_ion_fields(data, ions=[ion])

        #add new fields for projection plots
        #data.add_field(('gas', 'vel_squared'), function=_vel_squared, display_name = 'vel squared', units = 'cm**2/s**2')
        #data.add_field(('gas', 'b_param'), function=_b_param, display_name = 'b parameter', units = 'cm/s')

        #plot the the column density
        plot1 = yt.ProjectionPlot(data, 'z', fieldname, origin = 'native')
        plot1.set_zlim(fieldname, 1e8, 1e18)
        plot1.set_cmap(fieldname,"gist_rainbow")
        plot1.save(savefolder)

        #plot the average y-velocity
        #plot2 = yt.ProjectionPlot(data, 'y', 'velocity_y', origin = 'native', weight_field = fieldname)
        #plot2.set_log('velocity_y', False)
        #plot2.set_zlim(fieldname, 1e-16, 5e-6)
        #plot2.set_cmap(fieldname,"gist_rainbow")
        #plot2.save(savefolder)

        #reg = data.all_data()
        #vel_Proj = reg.mean('velocity_y', 'y', weight = fieldname)
        #vel2_proj = reg.mean('vel_squared', 'y', weight = fieldname)

        #bparam = np.sqrt(vel2_proj['vel_squared']- vel_Proj['velocity_y']**2)

        #plt.scatter(vel_Proj['z'], vel_Proj['x'], c=bparam, marker = 'o')
        #plt.contour(vel_Proj['z'], vel_Proj['x'], bparam)
        #plt.colorbar()
        #fig = plt.gcf()
        #fig.savefig('test.png')

        #plot3 = yt.ProjectionPlot(vel_Proj, 'y', 'test', origin = 'native')
        #plot3.set_log('b_param', False)
        #plot3.set_zlim(fieldname, 1e-16, 5e-6)
        #plot3.set_cmap(fieldname,"gist_rainbow")
        #plot3.save(savefolder)


        print('Saved plots as '+savefolder+'KH_......')

    print("Finished with run "+runName)
Exemple #16
0
def addTriDens(data, atom, ion):
    #add the atom
    tri.add_ion_fields(data, ions=[atom], ftype='gas')

    def _newDens(field, data):
        fracList = atomFracs_tri[atom]
        ionNum = ionList[ion]
        fieldname = fracList[ionNum][:-7] + 'number_density'
        return data[fieldname]

    data.add_field(('gas', 'dens' + atom + ion + '_tri'),
                   function=_newDens,
                   display_name=atom + ' ' + ion + ' Number Density',
                   units="1/cm**3",
                   sampling_type='cell')
    #trident already adds the number density! so you're all good here
    return data
Exemple #17
0
def addTriFrac(data, atom, ion):
    #add the atom
    tri.add_ion_fields(data, ions=[atom], ftype='gas')

    def _newFrac(field, data):
        fracList = atomFracs_tri[atom]
        botsum = np.sum([data[f] for f in fracList], axis=0)
        ionNum = ionList[ion]
        top = data[fracList[ionNum]]
        frac = top / data.apply_units(botsum, "g/cm**3")
        return frac

    data.add_field(('gas', 'frac' + atom + ion + '_tri'),
                   function=_newFrac,
                   display_name=atom + ' ' + ion + ' Mass Fraction (Tri)',
                   units="",
                   sampling_type='cell')
    return data
Exemple #18
0
def _get_coldens_helper(dsparamsvectorions):
    try:
        ds = dsparamsvectorions[0]
        scanparams = dsparamsvectorions[1]
        vector = dsparamsvectorions[2]
        ions = dsparamsvectorions[3]
        print(str(current_process()))
        ident = str(current_process()).split(",")[0]
        if ident[-2:] == "ss":
            ident = ""
        else:
            ident = ident.split("-")[1]
        start = vector[5:8]
        end = vector[8:11]        
        ray = trident.make_simple_ray(ds,
                    start_position=start,
                    end_position=end,
                    data_filename="ray"+ident+".h5",
                    fields = [('gas',"metallicity")],
                    ftype='gas')
        trident.add_ion_fields(ray,ions)
        field_data = ray.all_data()
        for i in range(len(ions)):
            ion = ions[i]
            cdens = np.sum(field_data[("gas",ion_to_field_name(ion))] * field_data['dl'])
            #outcdens = np.sum((field_data['radial_velocity']>0)*field_data[ion_to_field_name(ion)]*field_data['dl'])
            #incdens = np.sum((field_data['radial_velocity']<0)*field_data[ion_to_field_name(ion)]*field_data['dl'])
            vector[11+i] = cdens
            #vector[12+3*i+1] = outcdens
            #vector[12+3*i+2] = incdens
        Z = np.average(field_data[('gas',"metallicity")],weights=field_data['dl'])
        vector[-1] = Z
        if _platform == 'darwin':
            foldername = "/Users/claytonstrawn/Desktop/astroresearch/code/ready_for_pleiades/quasarlines"
        else:
            foldername = "/u/cstrawn/quasarlines/galaxy_catalogs/"
    except Exception:
        logging.exception("failed")
    try:
        os.remove(foldername+"/"+"ray"+ident+".h5")
    except:
        pass 
    print("vector = "+str(vector))
    return vector
Exemple #19
0
def makeColDist(directory, runName, f_list, savefolder, ion, fieldname):
    for i in f_list:
        data = yt.load(directory + runName + '/KH_hdf5_chk_' + i)
        data.add_field(('gas', 'metallicity'),
                       function=_metallicity,
                       display_name="Metallicity",
                       units='Zsun')

        #add an ion field to the dataset
        tri.add_ion_fields(data, ions=[ion])

        #projection of the number density
        p = data.proj(fieldname, 1)
        #make fixed resolution buffer (same as when a figure is made)
        #to have an array with every value in each pixel
        frb = yt.FixedResolutionBuffer(
            p, (-2.464e21, 2.464e21, -2.464e21, 2.464e21), (800, 800))
        #flatten the frb to a 1d array
        flattened_coldens = frb[fieldname].flatten()

        if min(flattened_coldens) == 0:
            mincol = 8
        else:
            mincol = np.log10(min(flattened_coldens))
        maxcol = np.log10(max(flattened_coldens))

        #make histogram!
        plt.hist(flattened_coldens,
                 bins=np.logspace(mincol - 1, maxcol + 1, 50),
                 fill=False,
                 color='blue',
                 log=True)
        plt.xscale('log')
        #plt.yscale('log')
        plt.ylabel('Number of pixels')
        plt.xlabel(ion + ' Column Density per pixel')
        plt.ylim(1, 1e6)

        fig = plt.gcf()
        fig.savefig(savefolder + '/' + runName + '_' + i + '_' + fieldname +
                    '.png')
        plt.close()
Exemple #20
0
ion_list = ['O VI']
field = ('gas', 'O_p5_number_density')
weight_field = None

# load in simulation data and add ion fields
ray_id_list, x_list, z_list = np.loadtxt('data/temp_coordinate_list.dat',
                                         skiprows=1,
                                         unpack=True)

plot_data = h5.File(
    '/nobackup/ibutsky/data/YalePaper/multipanel_romulusC_%i_sightline_plot_data_fixed2'
    % (output), 'w')
center = rom.get_romulus_center('romulusC', output)

ds = yt.load('/nobackup/ibutsky/simulations/romulusC/romulusC.%06d' % (output))
trident.add_ion_fields(ds, ions=ion_list)

# set up projection plots for fields that are weighted and unweighted
# note: ray_x, ray_z ordering should be consistent with data/coordinate_list.dat

for ray_id, ray_x, ray_z in zip(ray_id_list, x_list, z_list):
    dset = 'ray_%i_%s' % (ray_id, field[1])
    if dset not in plot_data.keys():
        plot_center = [center[0] + ray_x, center[1], center[2] + ray_z]
        print(center, plot_center)
        sys.stdout.flush()
        plot_center = (plot_center / ds.length_unit).d
        proj = yt.ProjectionPlot(ds,
                                 'y',
                                 field,
                                 weight_field=weight_field,
Exemple #21
0
        log("Starting projections for %s" % fn)
        if AMIGA:
            ds = GizmoDataset(fn)
        elif Rockstar:
            ds = yt.load(fn)
            # These vectors are precalculated to be the correct viewing angle for an edge on view
            E1 = ds.arr([0.40607303, 0., -0.91384063], 'code_length')
            L = ds.arr([0.83915456, 0.3959494, 0.37288562], 'code_length') # edge-on disk view at z ~ 0.2
            #vec1 = [L, -E1]
            #vec2 = [E1, L]
            vec1 = []
            vec2 = []
            dir = ['face/', 'edge/']
        else:
            ds = yt.load(fn)
        trident.add_ion_fields(ds, ions=ions, ftype='gas')

        #ions.append('O_nuclei_density')
        #ion_fields.append('O_nuclei_density')
        #full_ion_fields.append(('gas', 'O_nuclei_density'))
        #ions.append('density')
        #ion_fields.append('density')
        #full_ion_fields.append(('gas', 'density'))
        #ions.append('metal_density')
        #ion_fields.append('metal_density')
        #full_ion_fields.append(('gas', 'metal_density'))

        # Figure out centroid and r_vir info
        if AMIGA:
            log("Reading amiga center for halo in %s" % fn)
            c = read_amiga_center(amiga_data, fn, ds)
Exemple #22
0
def calcRankTau(directory, runName, runNumber, ions, velocityBin, frameVel):
    #load and add ions to the dataset
    velocityBin = velocityBin * 1.0e5  #convert to cm/s
    frameVel = frameVel * 1.0e5  #convert to cm/s
    data = yt.load(directory + runName + '/KH_hdf5_chk_' + runNumber)
    data.add_field(('gas', 'metallicity'),
                   function=_metallicity,
                   display_name="Metallicity",
                   units='Zsun')

    absorbFracs = []
    #add ion fields to the dataset
    for ion in ions:
        tri.add_ion_fields(data, ions=[ion['ion']])

        #define the function for b(x) for this particular ion
        ### function definition in a for loop... Ew... ###
        def _soundSpeed(field, data):
            topFrac = 2.0 * kb * data['temperature']
            botFrac = ion['massNum'] * mp
            b = np.sqrt(topFrac / botFrac)
            return b

        #add b_soundSpeed to the dataset
        data.add_field(('gas', 'b_soundSpeed'),
                       function=_soundSpeed,
                       display_name="B Sound Speed",
                       units='cm/s',
                       force_override=True)

        #define the function for dTau for this particular ion/velocity
        ### function definition in a for loop... Ew... ###
        def _dTau(field, data):
            term1 = data[ion['fieldname']] / data['b_soundSpeed']
            #assumes velocity is now cm/s
            #must add the frame velocity to the y velocity!
            expTerm = (((data['velocity_y'] + frameVel *
                         (centimeter / second)) - velocityBin *
                        (centimeter / second)) / data['b_soundSpeed'])**2.0
            dtau = term1 * np.exp(-1.0 * expTerm)
            return dtau

        #add dTau to the dataset
        data.add_field(('gas', 'tau'),
                       function=_dTau,
                       display_name="dTau",
                       units='s/cm**4',
                       force_override=True)

        #make cylinder, project through the y axis
        #reg = data.disk([0.0, 0.2*kpc, 0.0], [0,1,0], (0.25, 'kpc'), (1.6, 'kpc'))

        #select entire region
        reg = data.all_data()

        plot = yt.ProjectionPlot(data, 'y', 'density')
        plot.set_zlim('density', 1e-5, 5e-5)
        plot.save()

        #projection of the number density
        p = data.proj('tau', 1)
        #make fixed resolution buffer (same as when a figure is made)
        #to have an array with every value in each pixel
        frb = yt.FixedResolutionBuffer(
            p, (-2.464e21, 2.464e21, -2.464e21, 2.464e21), (800, 800))
        #flatten the frb to a 1d array
        flattened_tau = frb['tau'].flatten()

        tau_coef = c_speed * ion['sigma'] / np.sqrt(np.pi)
        projectedTau = tau_coef * flattened_tau

        #rank sort the projected taus and then make plot
        sorted_tau = np.sort(projectedTau, kind='quicksort')
        totalpixel = len(sorted_tau)

        pixelNum = np.arange(0.0, totalpixel, 1.0)
        pixelFrac = pixelNum / totalpixel
        print(pixelFrac)

        writeFile = open(
            '../rankTau' + ion['ionfolder'] + 'rankTau' + runName + '_v' +
            str(int(round(velocityBin / 1e5, 0))) + '.txt', 'w')
        for i in range(len(pixelFrac)):
            writeString = str(sorted_tau[i].value) + '\n'
            writeFile.write(writeString)
        writeFile.close()

        #clip = 620800 #0.97
        #plt.plot(pixelFrac[clip:], sorted_tau[clip:])
        #fig = plt.gcf()
        #fig.savefig('rankTau/test_rankTau'+runName+'_v'+str(int(round(velocityBin/1e5, 0)))+'_'+ion['ion']+'.png')
        #fig.clear()

    return absorbFracs
Exemple #23
0
import yt
import trident
import sys
yt.enable_parallelism()

workdir = '/media/azton/bigbook/projects/nextGenIGM'
simname = sys.argv[1]
final = int(sys.argv[2])
d = final
rs = '%s/%s/rockstar_halos/halos_RD%04d.0.bin'%(workdir, simname, final)
rs = yt.load(rs)
ad = rs.all_data()
ds = yt.load('%s%s/RD%04d/RedshiftOutput%04d'%(workdir, simname,d,d))
#print(ds.field_list)
trident.add_ion_fields(ds, ['C', "O", "O IV", "O VI", "C IV"], ftype='gas')

for field in ds.derived_field_list:
    print (field)

pos = ad['particle_position'][ad['particle_mass'] \
            == ad['particle_mass'].max()][0].to('unitary')
r = 4.0*ad['virial_radius'][ad['particle_mass'] \
            == ad['particle_mass'].max()][0].to('unitary')
sp = ds.sphere(pos, r)
fields = ['H_p1_density','O_p4_density','C_p0_density', 'H_density']
labels = ['HI', "OIV", "C", "H"]


## make a ray that intersects this most massive halo ##
ray = trident.make_simple_ray(ds, start_position=[pos[0], pos[1],0], end_position=[pos[0], pos[1], 1],\
                                lines='H')
Exemple #24
0
width = 15.  #kpc
zsnap = dsr.current_redshift
refine_box, refine_box_center, refine_width = get_refine_box(dsr, zsnap, track)

mH = 1.6737236e-24 * u.g
total_forced_HI_mass = sum(mH * refine_box['H_p0_number_density'] *
                           refine_box['cell_volume'].in_units('cm**3'))
print(
    'HI mass: ',
    total_forced_HI_mass.to('Msun'),
)
print('log HI mass: ', np.log10(total_forced_HI_mass.to('Msun').value))

import trident

trident.add_ion_fields(dsr, ions=['C IV', 'O VI', 'Si II', 'Si IV'])

total_forced_SiII_mass = sum(mH * refine_box['Si_p1_number_density'] *
                             refine_box['cell_volume'].in_units('cm**3'))
total_forced_SiII_mass = total_forced_SiII_mass * 28.0855
print(
    'SiII forced: ',
    total_forced_SiII_mass.to('Msun'),
)

total_forced_OVI_mass = sum(mH * refine_box['O_p5_number_density'] *
                            refine_box['cell_volume'].in_units('cm**3'))
total_forced_OVI_mass = total_forced_OVI_mass * 15.999
print('OVI forced: ', total_forced_OVI_mass.to('Msun'))

total_forced_SiIV_mass = sum(mH * refine_box['Si_p3_number_density'] *
Exemple #25
0
comm = MPI.COMM_WORLD

t_start = time.time()

# number of pixels per dimension (for Aitoff projection)
pixels_per_dim = 512

remove_first_N_kpc = 1.0

# Load dataset
fn = "/mnt/scratch/dsilvia/simulations/reu_sims/MW_1638kpcBox_800pcCGM_200pcDisk_lowres/DD1500/DD1500"
ds = yt.load(fn)

# Add H I & O VI ion fields using Trident
trident.add_ion_fields(ds, ions=['O VI', 'H I'], ftype="gas")

# Specify position where the ray starts (position in the volume)
c = ds.arr([0.5, 0.5, 0.5], 'unitary')
c = c.in_units('kpc')

# location in the disk where we're setting our observations
X = YTArray([8., 0., 0.], 'kpc')
ray_start = c - X

# Length of Ray
R = 200.0

# do you want projections of the spheres?  True/False
MakeProjections = True
Exemple #26
0
    return data.apply_units(v, "Zsun")


for i in [6, 9, 12, 13, 14, 18, 21, 24, 27, 35]:
    if i >= 1000:
        data = yt.load('KH_hdf5_chk_' + str(i))
    elif i >= 100:
        data = yt.load('KH_hdf5_chk_0' + str(i))
    elif i >= 10:
        data = yt.load('KH_hdf5_chk_00' + str(i))
    else:
        data = yt.load('KH_hdf5_chk_000' + str(i))

    data.add_field(('gas', 'metallicity'),
                   function=_metallicity,
                   display_name="Metallicity",
                   units='Zsun')

    #try adding an ion field to the dataset
    tri.add_ion_fields(data, ions=['Ne VIII'])
    folder = 'NeVIII'
    #plot the newly added field's number density
    plot = yt.SlicePlot(data, 'z', 'Ne_p7_number_density', origin='native')
    plot.set_zlim('Ne_p7_number_density', 1e-16, 5e-6)
    plot.set_cmap("Ne_p7_number_density", "gist_rainbow")
    plot.save(folder)
    print('Saved plot as ' + folder + 'KH_......')

    #plot = yt.SlicePlot(data, 'z', 'velocity_y', origin='native')
    #plot.save()
Exemple #27
0
def calcRankTau(directory, runName, runNumber, ions, velocityBin, frameVel):
    #load and add ions to the dataset
    frameVel = frameVel*1.0e5*(centimeter/second)  #convert to cm/s
    data = yt.load(directory+runName+'/KH_hdf5_chk_'+runNumber)
    data.add_field(('gas', 'metallicity'), function=_metallicity, display_name="Metallicity", units='Zsun')

    bList = []
    vList = []
    TList = []
    #add ion fields to the dataset
    for ion in ions:
        tri.add_ion_fields(data, ions=[ion['ion']])

        #select entire region
        reg = data.all_data()

        #projection of the number density (= fieldname)
        p = data.proj(ion['fieldname'], 1)
        #make fixed resolution buffer (same as when a figure is made)
        #to have an array with every value in each pixel
        frb = yt.FixedResolutionBuffer(p, (-2.464e21, 2.464e21, -2.464e21, 2.464e21), (800, 800))
        #flatten the frb to a 1d array
        flattened_num = frb[ion['fieldname']].flatten()
        projectedNum = flattened_num

        #rank sort the projected taus and then make plot
        sorted_num = np.sort(projectedNum, kind='quicksort')

        #find the average velocity for the ion
        average_vely = reg.quantities.weighted_average_quantity('vely', ion['fieldname'])+frameVel

        average_temp = reg.quantities.weighted_average_quantity('temperature', ion['fieldname'])


        #write the ranked column densities to a file
        writeFile = open('../rankNum'+ion['ionfolder']+'rankNum'+runName+'_v'+str(velocityBin)+'.txt', 'w')
        for i in range(len(sorted_num)):
            writeString = str(sorted_num[i].value)+'\n'
            writeFile.write(writeString)
        writeFile.close()


        #add b^2 thermal as a field
        def _btherm(field, data):
            topFrac = 2.0*kb*data['temperature']
            botFrac = ion['massNum']*mp
            b = topFrac/botFrac
            return b

        data.add_field(('gas', 'b_therm'), function=_btherm, display_name="B thermal squared", units = 'cm**2/s**2', force_override=True)
        #project b thermal
        btherm = data.proj('b_therm', 1, weight_field=ion['fieldname'])
        frb_therm = yt.FixedResolutionBuffer(btherm, (-2.464e21, 2.464e21, -2.464e21, 2.464e21), (800, 800))
        flattened_btherm = frb_therm['b_therm'].flatten()

        #add b^2 doppler as a field
        def _bdop(field, data):
            b = (data['vely'] - average_vely)**2
            return b  #multiply by number density to weight the b value

        data.add_field(('gas', 'b_doppler'), function=_bdop, display_name="B doppler squared", units = 'cm**2/s**2', force_override=True)
        #project b doppler
        bdop = data.proj('b_doppler', 1, weight_field=ion['fieldname'])
        frb_dop = yt.FixedResolutionBuffer(bdop, (-2.464e21, 2.464e21, -2.464e21, 2.464e21), (800, 800))
        flattened_bdop = frb_dop['b_doppler'].flatten()

        good_btherm = flattened_btherm[~np.isnan(flattened_btherm)]
        good_bdop = flattened_bdop[~np.isnan(flattened_bdop)]

        #add the two b's and sqrt
        b_tot_Sq = good_btherm+good_bdop

        b_tot = np.sqrt(b_tot_Sq)

        #compute the average of the summation of b projections
        b_avg = np.average(b_tot)

        bList.append(b_avg)
        vList.append(average_vely)
        TList.append(average_temp)
        print(b_avg)
        print(average_vely)

    return bList, vList, TList
Exemple #28
0
datafile = sys.argv[1]

start_position = sys.argv[2]

end_position = sys.argv[3]

savename = sys.argv[4]

line_list = ['C','N','O']

ds = yt.load(datafile) # Loading the dataset

if start_position == 'left_edge':
    start_position = ds.domain_left_edge
if end_position == 'right_edge':
    end_position = ds.domain_right_edge


trident.add_ion_fields(ds,ions=line_list) 

actual_ray = trident.make_simple_ray(ds,start_position = np.array([0.,0.,0.]),end_position = np.array([128.,128.,128.]),data_filename="mray.h5",lines=line_list,ftype='gas') 

#lr = trident.LightRay(ds)
#lr.make_light_ray(ds,start_position = start_position,end_position = end_position,data_filename="mray.h5",fields=['temperature','density'])

sg = trident.SpectrumGenerator('COS')
#sg = trident.SpectrumGenerator(lambda_min='auto', lambda_max='auto',dlambda=0.01)
sg.make_spectrum(actual_ray, lines=line_list) 
sg.save_spectrum(savename + '.txt') 
sg.plot_spectrum(savename + '.png') 
    yt.add_particle_filter("youngstars",
                           function=_youngstars,
                           filtered_type='all',
                           requires=["age"])
    yt.add_particle_filter("darkmatter",
                           function=_darkmatter,
                           filtered_type='all',
                           requires=["particle_type"])

    ds.add_particle_filter('stars')
    ds.add_particle_filter('darkmatter')
    ds.add_particle_filter('youngstars')
    print('adding trident fields...')
    trident.add_ion_fields(ds,
                           ions=[
                               'O VI', 'O VII', 'Mg II', 'Si II', 'C II',
                               'C III', 'C IV', 'Si III', 'Si IV', 'Ne VIII'
                           ])

    #Parallel(n_jobs = -1, backend = 'threading')(delayed(measure_mass)(simname = simname, DD = DD, sat_n = sat_n, ds = ds) for sat_n in np.arange(5))
    species_dict = {
        'dark_matter': ("darkmatter", "particle_mass"),
        'gas_tot': ("gas", "cell_mass"),
        'gas_metals': ("gas", "metal_mass"),
        'stars_mass': ("stars", "particle_mass"),
        'stars_youngmass': ("youngstars", "particle_mass"),
        'gas_H': ("gas", 'H_mass'),
        'gas_H0': ("gas", 'H_p0_mass'),
        'gas_H1': ("gas", 'H_p1_mass'),
        'gas_CII': ("gas", 'C_p1_mass'),
        'gas_CIII': ("gas", 'C_p2_mass'),
Exemple #30
0
def generate_halo_column_data(sim,
                              output,
                              ion_list,
                              res=800,
                              start_index=0,
                              end_index=1000):

    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)

    halo_props = h5.File(
        '/nobackupp2/ibutsky/data/%s_halo_data_%i' % (sim, output), 'r')
    halo_ids = halo_props['halo_id'][:]
    mstars = halo_props['mstar'][:]
    centers = halo_props['center'][:]
    contamination = halo_props['contamination'][:]

    mask = (mstars >= 1e9) & (halo_ids > 0) & (contamination < 0.05)

    if start_index > end_index:
        counter = -1
    else:
        counter = 1

    for i in np.arange(start_index, end_index, counter):
        halo_id = halo_ids[mask][i]
        mstar = mstars[mask][i]
        halo_center = centers[mask][i]
        center = (halo_center / ds.length_unit).d

        print(i, halo_id, mstar)
        sys.stdout.flush()

        cdens_file = h5.File(
            '/nobackupp2/ibutsky/data/%s/column_%i_halo%i_600' %
            (sim, output, halo_id), 'a')

        width = yt.YTQuantity(600, '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 "radius" not in cdens_file.keys():
            cdens_file.create_dataset("radius", data=radius.ravel())

        for j, ion in enumerate(ion_list):
            for axis in ['x', 'y', 'z']:
                dset = "%s_%s" % (ion, axis)
                if dset not in cdens_file.keys():
                    frb = ion_help.make_projection(ds,
                                                   axis,
                                                   field_list,
                                                   center,
                                                   width,
                                                   res=res)
                    if dset not in cdens_file.keys():
                        cdens_file.create_dataset(
                            dset, data=frb[field_list[j]].ravel())
                        cdens_file.flush()

        cdens_file.close()