Пример #1
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()
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()
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()
Пример #4
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()
Пример #5
0
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()