コード例 #1
0
def save_to_hdf5(num, tag, dset, name, desc, dtype = None, unit = '', group = 'Galaxy', inp='FLARES', data_folder = 'data/', verbose = False, overwrite=False):

    if dtype is None:
        dtype = dset.dtype

    if inp == 'FLARES':
        filename = './{}/FLARES_{}_sp_info.hdf5'.format(data_folder, num)
        sim_type = 'FLARES'


    elif inp == 'REF' or inp == 'AGNdT9':
        filename = F"./{data_folder}/EAGLE_{inp}_sp_info.hdf5"
        sim_type = 'PERIODIC'


    else:
        ValueError("Type of input simulation not recognized")


    if verbose: print("Writing out required properties to hdf5")

    fl = flares.flares(fname = filename,sim_type = sim_type)
    fl.create_group(tag)

    if verbose: print("Creating necessary groups")
    groups = group.split(os.sep)
    ogrp = ''
    for grp in groups:
        ogrp += os.sep + grp
        fl.create_group(f'{tag}/{ogrp}')

    if unit is None:
        fl.create_dataset(dset, name, f'{tag}/{group}', dtype = dtype, desc = desc, overwrite=overwrite)
    else:
        fl.create_dataset(dset, name, f'{tag}/{group}', dtype = dtype, desc = desc, unit = unit, overwrite=overwrite)
コード例 #2
0
def lum_write_out(num, tag, kappa, BC_fac, filters = flare.filters.TH[:-1], inp = 'FLARES', log10t_BC = 7., extinction = 'default', data_folder = 'data', aperture='30'):


    if inp == 'FLARES':
        num = str(num)
        if len(num) == 1:
            num =  '0'+num

        filename = F"./{data_folder}/FLARES_{num}_sp_info.hdf5"
        sim_type = inp

    elif (inp == 'REF') or (inp == 'AGNdT9'):
        filename = F"./{data_folder}/EAGLE_{inp}_sp_info.hdf5"
        sim_type = 'PERIODIC'
        num = '00'

    else:
        ValueError(F"No input option of {inp}")


    lumintr = get_lum(num, 0, tag, BC_fac, filters = filters, LF = False, inp = inp, Type = 'Intrinsic', extinction = extinction, data_folder = data_folder, aperture = aperture)
    lumstell = get_lum(num, 0, tag, BC_fac, filters = filters, LF = False, inp = inp, Type = 'Pure-stellar', extinction = extinction, data_folder = data_folder, aperture = aperture)
    lumBC = get_lum(num, 0, tag, BC_fac, filters = filters, LF = False, inp = inp, Type = 'Only-BC', extinction = extinction, data_folder = data_folder, aperture = aperture)
    lumatt = get_lum(num, kappa, tag, BC_fac, filters = filters, LF = False, inp = inp, Type = 'Total', log10t_BC =  log10t_BC, extinction = extinction, data_folder = data_folder, aperture = aperture)

    # print("Output array dimensions:",lumintr.shape, lumstell.shape, lumBC.shape, lumatt.shape)

    # print(lumintr)

    fl = flares.flares(fname = filename, sim_type = sim_type)

    fl.create_group(F"{tag}/Galaxy/BPASS_2.2.1/Chabrier300/Luminosity/Intrinsic")
    fl.create_group(F"{tag}/Galaxy/BPASS_2.2.1/Chabrier300/Luminosity/Pure_Stellar")
    fl.create_group(F"{tag}/Galaxy/BPASS_2.2.1/Chabrier300/Luminosity/No_ISM")
    fl.create_group(F"{tag}/Galaxy/BPASS_2.2.1/Chabrier300/Luminosity/DustModelI")

    for ii, jj in enumerate(filters):

        _filter = jj[8:]

        fl.create_dataset(values = lumintr[:,ii], name = F"{_filter}",
                          group = F"{tag}/Galaxy/BPASS_2.2.1/Chabrier300/Luminosity/Intrinsic",
                          desc = F'Intrinsic (stellar + nebular) luminosity of the galaxy in the {_filter} band', unit = "ergs/s/Hz", overwrite=True)

        fl.create_dataset(values = lumstell[:,ii], name = F"{_filter}",
                          group = F"{tag}/Galaxy/BPASS_2.2.1/Chabrier300/Luminosity/Pure_Stellar",
                          desc = F'Stellar luminosity of the galaxy in the {_filter} band', unit = "ergs/s/Hz", overwrite=True)

        fl.create_dataset(values = lumBC[:,ii], name = F"{_filter}",
                          group = F"{tag}/Galaxy/BPASS_2.2.1/Chabrier300/Luminosity/No_ISM",
                          desc = F'Intrinsic (stellar + nebular) luminosity of the galaxy with BC attenuation in the {_filter} band with a birth cloud factor of {BC_fac} following {extinction} curve',
                          unit = "ergs/s/Hz", overwrite=True)

        fl.create_dataset(values = lumatt[:,ii], name = F"{_filter}",
                          group = F"{tag}/Galaxy/BPASS_2.2.1/Chabrier300/Luminosity/DustModelI",
                          desc = F"Dust corrected luminosity (using ModelI) of the galaxy in the {_filter} band with a birth cloud factor of {BC_fac} following {extinction} curve",
                          unit = "ergs/s/Hz", overwrite=True)
コード例 #3
0
def sed_write_out(num, tag, kappa, BC_fac, inp = 'FLARES', IMF = 'Chabrier_300', log10t_BC = 7., extinction = 'default', data_folder = 'data', aperture='30'):

    if inp == 'FLARES':
        num = str(num)
        if len(num) == 1:
            num =  '0'+num

        filename = F"./{data_folder}/FLARES_{num}_sp_info.hdf5"
        sim_type = inp

    elif (inp == 'REF') or (inp == 'AGNdT9'):
        filename = F"./{data_folder}/EAGLE_{inp}_sp_info.hdf5"
        sim_type = 'PERIODIC'
        num='00'

    else:
        ValueError(F"No input option of {inp}")

    try:
        dat     = get_SED(num, kappa, tag, BC_fac, inp=inp, log10t_BC=log10t_BC, extinction=extinction, data_folder=data_folder, aperture=aperture)
        lam     = dat[0][0]
        stell   = dat[1]
        intr    = dat[2]
        noISM   = dat[3]
        dust    = dat[4]
    except:
        lam     = np.array([])
        stell   = np.array([])
        intr    = np.array([])
        noISM   = np.array([])
        dust    = np.array([])

    fl = flares.flares(fname = filename, sim_type = sim_type)
    fl.create_group(F"{tag}/Galaxy/BPASS_2.2.1/Chabrier300/SED")


    fl.create_dataset(values = lam, name = F"Wavelength",
    group = F"{tag}/Galaxy/BPASS_2.2.1/Chabrier300/SED",
    desc = F"Wavelength array for the SED", unit = "Angstrom", overwrite=True)

    fl.create_dataset(values = stell, name = F"Pure_Stellar",
    group = F"{tag}/Galaxy/BPASS_2.2.1/Chabrier300/SED",
    desc = F"Pure stellar SED", unit = "ergs/s/Hz", overwrite=True)

    fl.create_dataset(values = intr, name = F"Intrinsic",
    group = F"{tag}/Galaxy/BPASS_2.2.1/Chabrier300/SED",
    desc = F"Intrinisc SED", unit = "ergs/s/Hz", overwrite=True)

    fl.create_dataset(values = noISM, name = F"No_ISM",
    group = F"{tag}/Galaxy/BPASS_2.2.1/Chabrier300/SED",
    desc = F"SED from attenuation only from the birth cloud component with kappa_BC={BC_fac} and {extinction} curve", unit = "ergs/s/Hz", overwrite=True)

    fl.create_dataset(values = dust, name = F"DustModelI",
    group = F"{tag}/Galaxy/BPASS_2.2.1/Chabrier300/SED",
    desc = F"SED from DustModelI with kappa_BC={BC_fac} and {extinction} curve", unit = "ergs/s/Hz", overwrite=True)
コード例 #4
0
def flux_write_out(num, tag, kappa, BC_fac, filters = flare.filters.ACS, inp = 'FLARES', extinction = 'default', data_folder = 'data', aperture='30'):

    if inp == 'FLARES':
        num = str(num)
        if len(num) == 1:
            num =  '0'+num

        filename = F"./{data_folder}/FLARES_{num}_sp_info.hdf5"
        sim_type = inp

    elif (inp == 'REF') or (inp == 'AGNdT9'):
        filename = F"./{data_folder}/EAGLE_{inp}_sp_info.hdf5"
        sim_type = 'PERIODIC'

    else:
        ValueError(F"No input option of {inp}")

    fluxintr = get_flux(num, 0, tag, BC_fac, filters = filters, inp = inp, Type = 'Intrinsic', extinction = extinction, data_folder = data_folder, aperture = aperture)
    fluxstell = get_flux(num, 0, tag, BC_fac, filters = filters, inp = inp, Type = 'Pure-stellar', extinction = extinction, data_folder = data_folder, aperture = aperture)
    fluxBC = get_flux(num, 0, tag, BC_fac, filters = filters, inp = inp, Type = 'Only-BC', extinction = extinction, data_folder = data_folder, aperture = aperture)
    fluxatt = get_flux(num, kappa, tag, BC_fac, filters = filters, inp = inp, Type = 'Total', extinction = extinction, data_folder = data_folder, aperture = aperture)

    fl = flares.flares(fname = filename, sim_type = sim_type)
    fl.create_group(F"{tag}/Galaxy/BPASS_2.2.1/Chabrier300/Flux/Intrinsic")
    fl.create_group(F"{tag}/Galaxy/BPASS_2.2.1/Chabrier300/Flux/Pure_Stellar")
    fl.create_group(F"{tag}/Galaxy/BPASS_2.2.1/Chabrier300/Flux/No_ISM")
    fl.create_group(F"{tag}/Galaxy/BPASS_2.2.1/Chabrier300/Flux/DustModelI")

    for ii, jj in enumerate(filters):

        _filter = re.findall('\w+', jj) #index `0` is the telescope, `1` is the name
        #of the instrument and `2` is the name of the filter

        fl.create_dataset(values = fluxintr[:,ii], name = F"{_filter[0]}/{_filter[1]}/{_filter[2]}",
        group = F"{tag}/Galaxy/BPASS_2.2.1/Chabrier300/Flux/Intrinsic",
        desc = F"Intrinsic (stellar + nebular) flux of the galaxy in the {_filter}", unit = "nJy", overwrite=True)

        fl.create_dataset(values = fluxstell[:,ii], name = F"{_filter[0]}/{_filter[1]}/{_filter[2]}",
        group = F"{tag}/Galaxy/BPASS_2.2.1/Chabrier300/Flux/Pure_Stellar",
        desc = F"Stellar flux of the galaxy in the {_filter}", unit = "nJy", overwrite=True)

        fl.create_dataset(values = fluxBC[:,ii], name = F"{_filter[0]}/{_filter[1]}/{_filter[2]}",
        group = F"{tag}/Galaxy/BPASS_2.2.1/Chabrier300/Flux/No_ISM",
        desc = F"Intrinsic (stellar + nebular) flux of the galaxy with BC attenuation in the {_filter} with a birth cloud factor of {BC_fac} following {extinction} curve", unit = "nJy", overwrite=True)

        fl.create_dataset(values = fluxatt[:,ii], name = F"{_filter[0]}/{_filter[1]}/{_filter[2]}",
        group = F"{tag}/Galaxy/BPASS_2.2.1/Chabrier300/Flux/DustModelI",
        desc = F"Dust corrected flux (using ModelI) of the galaxy in the {_filter} with a birth cloud factor of {BC_fac} following {extinction} curve", unit = "nJy", overwrite=True)
コード例 #5
0
def extract_info(num, tag, inp='FLARES'):

    """
    Returns set of pre-defined properties of galaxies from a
    region in FLARES `num` for `tag`. Selects only galaxies
    with more than 100 star+gas particles inside 30pkpc
    ----------
    Args:
        num : str
            the FLARES/G-EAGLE id of the sim; eg: '00', '01', ...
        tag : str
            the file tag; eg: '000_z015p00', '001_z014p000',...., '011_z004p770'

    """

    ## MPI parameters
    comm = MPI.COMM_WORLD
    rank = comm.Get_rank()
    size = comm.Get_size()

    print (F"Extracing information from {inp} {num} {tag} (rank: {rank}, size: {size})")

    if inp == 'FLARES':
        sim_type = 'FLARES'
        fl = flares.flares(fname = './data/',sim_type=sim_type)
        _dir = fl.directory
        sim = F"{_dir}GEAGLE_{num}/data/"

    elif inp == 'REF':
        sim_type = 'PERIODIC'
        fl = flares.flares(fname = './data/',sim_type=sim_type)
        sim = fl.ref_directory

    elif inp == 'AGNdT9':
        sim_type = 'PERIODIC'
        fl = flares.flares(fname = './data/',sim_type=sim_type)
        sim = fl.agn_directory

    else:
        ValueError("Type of input simulation not recognized")

    if rank == 0:
        print (F"Sim location: {sim}, tag: {tag}")

    #Simulation redshift
    z = E.read_header('SUBFIND', sim, tag, 'Redshift')
    a = E.read_header('SUBFIND', sim, tag, 'ExpansionFactor')
    boxl = E.read_header('SUBFIND', sim, tag, 'BoxSize')/E.read_header('SUBFIND', sim, tag, 'HubbleParam')

    ####### Galaxy global properties  #######
    # SubhaloMass = E.read_array('SUBFIND', sim, tag, '/Subhalo/Mass', numThreads=4, noH=True, physicalUnits=True)
    Maperture = E.read_array('SUBFIND', sim, tag, '/Subhalo/ApertureMeasurements/Mass/030kpc', numThreads=4, noH=True, physicalUnits=True)
    mstar = Maperture[:,4]
    sgrpno = E.read_array('SUBFIND', sim, tag, '/Subhalo/SubGroupNumber', numThreads=4)
    grpno = E.read_array('SUBFIND', sim, tag, '/Subhalo/GroupNumber', numThreads=4)


    if inp == 'FLARES':
        ## Selecting the subhalos within our region
        cop = E.read_array('SUBFIND', sim, tag, '/Subhalo/CentreOfPotential', noH=False, physicalUnits=False, numThreads=4) #units of cMpc/h
        cen, r, min_dist = fl.spherical_region(sim, tag)  #units of cMpc/h
        indices = np.where((mstar*1e10 >= 10**7.) & (norm(cop-cen, axis=1)<=fl.radius))[0]

    else:
        indices = np.where(mstar*1e10 >= 10**7.)[0]

    cop = E.read_array('SUBFIND', sim, tag, '/Subhalo/CentreOfPotential', noH=True, physicalUnits=True, numThreads=4)
    # sfr_inst =  E.read_array('SUBFIND', sim, tag, '/Subhalo/ApertureMeasurements/SFR/030kpc', numThreads=4, noH=True, physicalUnits=True)


    ####### Particle properties #######

    #dm particle
    dm_cood = E.read_array('PARTDATA', sim, tag, '/PartType1/Coordinates', noH=True, physicalUnits=True, numThreads=4)
    dm_sgrpn = E.read_array('PARTDATA', sim, tag, '/PartType1/SubGroupNumber', numThreads=4)
    dm_grpn = E.read_array('PARTDATA', sim, tag, '/PartType1/GroupNumber', numThreads=4)

    #Gas particle
    gp_cood = E.read_array('PARTDATA', sim, tag, '/PartType0/Coordinates', noH=True, physicalUnits=True, numThreads=4)
    gp_sgrpn = E.read_array('PARTDATA', sim, tag, '/PartType0/SubGroupNumber', numThreads=4)
    gp_grpn = E.read_array('PARTDATA', sim, tag, '/PartType0/GroupNumber', numThreads=4)
    gp_sfr = E.read_array('PARTDATA', sim, tag, '/PartType0/StarFormationRate', noH=True, physicalUnits=True, numThreads=4)

    #Star particle
    try:
        sp_cood = E.read_array('PARTDATA', sim, tag, '/PartType4/Coordinates', noH=True, physicalUnits=True, numThreads=4)
        sp_sgrpn = E.read_array('PARTDATA', sim, tag, '/PartType4/SubGroupNumber', numThreads=4)
        sp_grpn = E.read_array('PARTDATA', sim, tag, '/PartType4/GroupNumber', numThreads=4)
        SP = True
    except:
        SP = False
        print("No star particles found")


    #Black hole particle
    """
    Subgrid properties are the ones required.
    Only at high masses are the subhalo and particle properties trace each other
    """
    try:
        bh_sgrpn = E.read_array('PARTDATA', sim, tag, '/PartType5/SubGroupNumber', numThreads=4)
        bh_grpn = E.read_array('PARTDATA', sim, tag, '/PartType5/GroupNumber', numThreads=4)
        bh_mass = E.read_array('PARTDATA', sim, tag, '/PartType5/BH_Mass', noH=True, physicalUnits=True, numThreads=4)
        bh_cood = E.read_array('PARTDATA', sim, tag, '/PartType5/Coordinates', numThreads=4, noH=True, physicalUnits=True)
        BH = True
    except:
        BH = False
        print("No Black hole particles found")




    ###########################  For identifying spurious galaxies and remerging them to the parent  ###########################

    #First method: just using the EAGLE method of merging them
    #to the nearby subhalo
    #Second method: use Will's criterion in MEGA to merge only
    #particles of those group that are identified as single
    #entities ----- not done for now

    #Identifying the index of the spurious array within the
    #array `indices`

    spurious_indices = np.where((Maperture[:,0][indices] == 0) | (Maperture[:,1][indices] == 0) | (Maperture[:,4][indices] == 0))[0]
    if len(spurious_indices)>0:
        #Calculating the distance of the spurious to the other subhalos
        dist_to_others = cdist(cop[indices[spurious_indices]], cop[indices])

        #To take into account the fact that the spurious subhalos
        #themselves as well as others are present within
        #`indices` at the moment
        dist_to_others[:, spurious_indices] = np.nan

        #Parent is classified as the nearest subhalo to the spurious
        parent = indices[np.nanargmin(dist_to_others, axis=1)]

        #returns the index of the parent and its associated spurious
        #as an array of arrays. `spurious_of_parent` is linked to
        #the `spurious` which is defined below so you can get the
        #original index back wrt to the whole dataset
        parent, spurious_of_parent = ndix_unique(parent)

        #remove the spurious from indices so they aren't counted twice
        #in the subhalo/particle property collection, but retain
        #information (`spurious` array) on where they are within the
        #whole dataset for later use
        spurious = indices[spurious_indices]
        indices = np.delete(indices, spurious_indices)

        del spurious_indices, dist_to_others
        sp_ok = True

    else:
        sp_ok = False

    gc.collect()


    comm.Barrier()

    part = int(len(indices)/size)
    num_subhalos = int(len(sgrpno))

    if rank == 0:
        if inp != 'FLARES': num = ''
        print("Extracting required properties for {} subhalos from {} region {} at z = {} of boxsize = {}".format(len(indices), inp, num, z, boxl))

    #For getting black hole subgrid masses
    tbhindex = np.zeros(num_subhalos, dtype = np.int32)
    tbh_cood = np.zeros((num_subhalos, 3), dtype = np.float64)
    tbh_mass = np.zeros(num_subhalos, dtype = np.float32)

    tsindex = np.zeros(num_subhalos, dtype = np.int32)


    if inp == 'FLARES':
        if rank!=size-1:
            thisok = indices[rank*part:(rank+1)*part]
        else:
            thisok = indices[rank*part:]

    else:
        #Size needs to be a perfect cube to work
        l = boxl / (size)**(1/3)
        sz = (size)**(1/3)
        dl = 10.
        xyz = np.zeros((size,8,3))
        count=0
        for xx in range(int(sz)):
            for yy in range(int(sz)):
                for zz in range(int(sz)):
                    xyz[count] = np.array([[xx, yy, zz], [xx+1, yy, zz], [xx, yy+1, zz], [xx, yy, zz+1], [xx+1, yy+1, zz], [xx+1, yy, zz+1], [xx, yy+1, zz+1], [xx+1, yy+1, zz+1]])
                    count+=1


        this_xyz = xyz[rank]*l
        max_xyz = np.max(this_xyz, axis=0)
        min_xyz = np.min(this_xyz, axis=0)


        thisok = np.ones(len(indices), dtype=bool)
        for xx in range(3):
            thisok*=np.logical_and(cop[indices][:,xx]/a>=min_xyz[xx], cop[indices][:,xx]/a<=max_xyz[xx])
        thisok = indices[thisok]
        # print (thisok, rank, max_xyz, min_xyz)
        # print (cop[thisok])

        #Dividing the gas particles into a cell for current task
        dd = np.ones(len(dm_cood), dtype=bool)
        for xx in range(3):
            dd*=np.logical_or((min_xyz[xx]-dl<=dm_cood[:,xx]/a)*(dm_cood[:,xx]/a<=max_xyz[xx]+dl), np.logical_or((min_xyz[xx]-dl<=dm_cood[:,xx]/a+boxl)*(dm_cood[:,xx]/a+boxl<=max_xyz[xx]+dl), (min_xyz[xx]-dl<=dm_cood[:,xx]/a-boxl)*(dm_cood[:,xx]/a-dl<=max_xyz[xx]+dl)))
        dd = np.where(dd)[0]

        dm_cood = dm_cood[dd]
        dm_sgrpn = dm_sgrpn[dd]
        dm_grpn = dm_grpn[dd]

        gg = np.ones(len(gp_cood), dtype=bool)
        for xx in range(3):
            gg*=np.logical_or((min_xyz[xx]-dl<=gp_cood[:,xx]/a)*(gp_cood[:,xx]/a<=max_xyz[xx]+dl), np.logical_or((min_xyz[xx]-dl<=gp_cood[:,xx]/a+boxl)*(gp_cood[:,xx]/a+boxl<=max_xyz[xx]+dl), (min_xyz[xx]-dl<=gp_cood[:,xx]/a-boxl)*(gp_cood[:,xx]/a-dl<=max_xyz[xx]+dl)))
        gg = np.where(gg)[0]

        gp_cood = gp_cood[gg]
        gp_sgrpn = gp_sgrpn[gg]
        gp_grpn = gp_grpn[gg]
        gp_sfr = gp_sfr[gg]

        #Dividing the star particles into a cell for current task
        if SP:
            ss = np.ones(len(sp_cood), dtype=bool)
            for xx in range(3):
                ss*=np.logical_or((min_xyz[xx]-dl<=sp_cood[:,xx]/a)*(sp_cood[:,xx]/a<=max_xyz[xx]+dl), np.logical_or((min_xyz[xx]/a-dl<=sp_cood[:,xx]/a+boxl)*(sp_cood[:,xx]/a+boxl<=max_xyz[xx]+dl), (min_xyz[xx]-dl<=sp_cood[:,xx]/a-boxl)*(sp_cood[:,xx]/a-boxl<=max_xyz[xx]+dl)))
            ss = np.where(ss)[0]

            sp_cood = sp_cood[ss]
            sp_sgrpn = sp_sgrpn[ss]
            sp_grpn = sp_grpn[ss]

        #Dividing the black hole particles into a cell for current task
        if BH:
            bb = np.ones(len(bh_cood), dtype=bool)
            for xx in range(3):
                bb*=np.logical_or((min_xyz[xx]-dl<=bh_cood[:,xx]/a)*(bh_cood[:,xx]/a<=max_xyz[xx]+dl), np.logical_or((min_xyz[xx]-dl<=bh_cood[:,xx]/a+boxl)*(bh_cood[:,xx]/a+boxl<=max_xyz[xx]+dl), (min_xyz[xx]-dl<=bh_cood[:,xx]/a-boxl)*(bh_cood[:,xx]/a-boxl<=max_xyz[xx]+dl)))
            bb = np.where(bb)[0]

            bh_sgrpn = bh_sgrpn[bb]
            bh_grpn = bh_grpn[bb]
            bh_mass = bh_mass[bb]
            bh_cood = bh_cood[bb]

    gc.collect()

    tdnum = np.zeros(len(thisok)+1, dtype = np.int32)
    tsnum = np.zeros(len(thisok)+1, dtype = np.int32)
    tgnum = np.zeros(len(thisok)+1, dtype = np.int32)
    ind = np.array([])

    tdindex = np.zeros(len(dm_grpn), dtype = np.int32)
    tgindex = np.zeros(len(gp_grpn), dtype = np.int32)

    if SP:
        tsindex = np.zeros(len(sp_grpn), dtype = np.int32)

    gc.collect()

    kk = 0
    # dist = 0.1 #in pMpc for 100 pkpc Aperture, writes out particle properties within this aperture
    sel_dist = 0.03 #in pMpc for 30 pkpc Aperture, only galaxies with more than 100 star + gas particles within this aperture is written out to the master file. Only spurious galaxies within 30 pkpc are selected
    bounds = np.array([boxl, boxl, boxl])   #https://stackoverflow.com/a/11109244
    for ii, jj in enumerate(thisok):

        #start = timeit.default_timer()

        d_ok = np.where((dm_sgrpn-sgrpno[jj]==0) & (dm_grpn-grpno[jj]==0))[0]

        g_ok = np.where((gp_sgrpn-sgrpno[jj]==0) & (gp_grpn-grpno[jj]==0))[0]
        tmp = gp_cood[g_ok]-cop[jj]
        if inp!='FLARES': tmp = np.min(np.dstack(((tmp) % bounds, (-tmp) % bounds)), axis = 2)
        g_ok_sel = g_ok[norm(tmp,axis=1)<=sel_dist]

        if SP:
            s_ok = np.where((sp_sgrpn-sgrpno[jj]==0) & (sp_grpn-grpno[jj]==0))[0]
            tmp = sp_cood[s_ok]-cop[jj]
            if inp!='FLARES': tmp = np.min(np.dstack(((tmp) % bounds, (-tmp) % bounds)), axis = 2)
            s_ok_sel = s_ok[norm(tmp,axis=1)<=sel_dist]
        else:
            s_ok = np.array([])
            s_ok_sel = np.array([])

        if BH:
            bh_ok = np.where((bh_sgrpn-sgrpno[jj]==0) & (bh_grpn-grpno[jj]==0))[0]

        if sp_ok:
            if jj in parent:
                this_spurious = np.where(parent == jj)[0]

                for _jj in spurious[spurious_of_parent[this_spurious[0]]]:

                    #To apply Will's recombine method, it should
                    #be applied here, instead of the next block

                    spurious_d_ok = np.where((dm_sgrpn-sgrpno[_jj]==0) & (dm_grpn-grpno[_jj]==0))[0]
                    tmp = dm_cood[spurious_d_ok]-cop[jj]
                    if inp!='FLARES': tmp = np.min(np.dstack(((tmp) % bounds, (-tmp) % bounds)), axis = 2)
                    d_ok = np.append(d_ok, spurious_d_ok[norm(tmp,axis=1)<=sel_dist])

                    spurious_g_ok = np.where((gp_sgrpn-sgrpno[_jj]==0) & (gp_grpn-grpno[_jj]==0))[0]
                    tmp = gp_cood[spurious_g_ok]-cop[jj]
                    if inp!='FLARES': tmp = np.min(np.dstack(((tmp) % bounds, (-tmp) % bounds)), axis = 2)
                    g_ok = np.append(g_ok, spurious_g_ok[norm(tmp,axis=1)<=sel_dist])
                    g_ok_sel = np.append(g_ok_sel, spurious_g_ok[norm(tmp,axis=1)<=sel_dist])

                    if SP:
                        spurious_s_ok = np.where((sp_sgrpn-sgrpno[_jj]==0) & (sp_grpn-grpno[_jj]==0))[0]
                        tmp = sp_cood[spurious_s_ok]-cop[jj]
                        if inp!='FLARES': tmp = np.min(np.dstack(((tmp) % bounds, (-tmp) % bounds)), axis = 2)
                        s_ok = np.append(s_ok, spurious_s_ok[norm(tmp,axis=1)<=sel_dist])
                        s_ok_sel = np.append(s_ok_sel, spurious_s_ok[norm(tmp,axis=1)<=sel_dist])

                    if BH:
                        spurious_bh_ok = np.where((bh_sgrpn-sgrpno[_jj]==0) & (bh_grpn-grpno[_jj]==0))[0]
                        tmp = bh_cood[spurious_bh_ok]-cop[jj]
                        if inp!='FLARES': tmp = np.min(np.dstack(((tmp) % bounds, (-tmp) % bounds)), axis = 2)
                        bh_ok = np.append(bh_ok, spurious_bh_ok[norm(tmp,axis=1)<=sel_dist])

                #Add in here the subhalo properties that needed
                #to be added due to spurious
                # tsfr_inst_spurious[jj] = np.sum(gp_sfr[g_ok])
                # tmstar_spurious[jj] = np.sum(mstar[spurious[spurious_of_parent[this_spurious[0]]]])
                # tSubhaloMass_spurious[jj] = np.sum(SubhaloMass[spurious[spurious_of_parent[this_spurious[0]]]])


        #stop = timeit.default_timer()

        if len(s_ok_sel) + len(g_ok_sel) >= 100:

            #print ("Calculating indices took {}s".format(np.round(stop - start,6)))
            # start = timeit.default_timer()

            #Extracting subgrid black hole properties
            if BH:
                if len(bh_ok>0):

                    tbh_max_index = np.argmax(bh_mass[bh_ok])
                    tbh_mass[jj] = bh_mass[bh_ok[tbh_max_index]]

                    if inp=='FLARES':
                        tbhindex[jj] = bh_ok[tbh_max_index]
                    else:
                        tbhindex[jj] = bb[bh_ok[tbh_max_index]]

            if SP:
                tsnum[kk+1] = len(s_ok)
                scum = np.cumsum(tsnum)
                sbeg = scum[kk]
                send = scum[kk+1]
                if inp=='FLARES':
                    tsindex[sbeg:send] = s_ok
                else:
                    tsindex[sbeg:send] = ss[s_ok]


            tdnum[kk+1] = len(d_ok)
            tgnum[kk+1] = len(g_ok)
            dcum = np.cumsum(tdnum)
            gcum = np.cumsum(tgnum)
            dbeg = dcum[kk]
            dend = dcum[kk+1]
            gbeg = gcum[kk]
            gend = gcum[kk+1]

            if inp=='FLARES':
                tdindex[dbeg:dend] = d_ok
                tgindex[gbeg:gend] = g_ok
            else:
                tdindex[dbeg:dend] = dd[d_ok]
                tgindex[gbeg:gend] = gg[g_ok]

            # stop = timeit.default_timer()
            # print ("Assigning arrays took {}s".format(np.round(stop - start,6)))
            gc.collect()

            kk+=1

        else:

            ind = np.append(ind, ii)

    ##End of loop ii, jj##

    del dm_sgrpn, dm_grpn, dm_cood, gp_sgrpn, gp_grpn, gp_cood, gp_sfr
    if SP: del sp_sgrpn, sp_grpn, sp_cood,
    if BH: del bh_sgrpn, bh_grpn, bh_mass

    gc.collect()


    thisok = np.delete(thisok, ind.astype(int))
    tbhindex = tbhindex[thisok]
    tbh_mass = tbh_mass[thisok]

    tdtot = np.sum(tdnum)
    tstot = np.sum(tsnum)
    tgtot = np.sum(tgnum)

    tdnum = tdnum[1:len(thisok)+1]
    tsnum = tsnum[1:len(thisok)+1]
    tgnum = tgnum[1:len(thisok)+1]

    tdindex = tdindex[:tdtot]
    tsindex = tsindex[:tstot]
    tgindex = tgindex[:tgtot]

    comm.Barrier()

    gc.collect()


    if rank == 0:
        print ("Gathering data from different processes")

    indices = comm.gather(thisok, root=0)


    bhindex = comm.gather(tbhindex, root=0)
    bh_mass = comm.gather(tbh_mass, root=0)

    del thisok, tbhindex, tbh_mass
    gc.collect()

    dnum = comm.gather(tdnum, root=0)
    del tdnum
    snum = comm.gather(tsnum, root=0)
    del tsnum
    gnum = comm.gather(tgnum, root=0)
    del tgnum

    dindex = comm.gather(tdindex, root=0)
    del tdindex
    sindex = comm.gather(tsindex, root=0)
    del tsindex
    gindex = comm.gather(tgindex, root=0)
    del tgindex

    gc.collect()

    ok_centrals = 0.

    if rank == 0:

        print ("Gathering completed")

        indices = np.concatenate(np.array(indices))
        dindex = np.concatenate(np.array(dindex))
        sindex = np.concatenate(np.array(sindex))
        gindex = np.concatenate(np.array(gindex))
        bhindex = np.concatenate(np.array(bhindex))

        bh_mass = np.concatenate(np.array(bh_mass))

        dnum = np.concatenate(np.array(dnum))
        snum = np.concatenate(np.array(snum))
        gnum = np.concatenate(np.array(gnum))

        ok_centrals = grpno[indices] - 1

        cop = cop[indices]/a
        sgrpno = sgrpno[indices]
        grpno = grpno[indices]


    return ok_centrals, indices, sgrpno, grpno, cop, dnum, snum, gnum, dindex, sindex, gindex, bhindex, bh_mass
コード例 #6
0
import pandas as pd
import h5py
import flares

df = pd.read_csv('weight_files/weights_grid.txt')
df.drop(columns=['Unnamed: 0'], inplace=True)

fl = flares.flares('./data/flares.hdf5', sim_type='FLARES')

in_dir = './data/'

with h5py.File('./data/flares.hdf5', 'a') as outfile:

    for ii, halo in enumerate(fl.halos):
        print(halo)

        fl.create_group(halo)

        hdr = df.iloc[ii:ii + 1].to_dict('list')
        for key, value in hdr.items():
            outfile[halo].attrs[key] = value[0]

        infile = h5py.File('%s/FLARES_%s_sp_info.hdf5' % (in_dir, halo), 'r')

        for tag in fl.tags:
            infile.copy(tag, outfile[halo])

        infile.close()
コード例 #7
0
def Lagn_T_grid_erg():
    '''Plots T_BB against L_AGN (erg/s units) at all redshifts into a single figure, no inputs required, prcoess is the same as in above function'''
    import numpy as np
    import pandas as pd
    import matplotlib as mpl
    import matplotlib.cm as cm
    mpl.use('Agg')
    import matplotlib.pyplot as plt
    import flares
    import astropy.constants as constants
    import astropy.units as units

    flares_dir = '../../../../../../../research/astro/flare'
    
    zed_tags = (-1,-2,-3,-4,-5,-6)
    
    fl = flares.flares(f'{flares_dir}/simulations/FLARES/data/flares.hdf5', sim_type='FLARES')
    halo = fl.halos
    cmap = mpl.cm.plasma
    
    Mstar = fl.load_dataset('Mstar_30', arr_type='Galaxy') # stellar mass of galaxy
    MBHdot_ = fl.load_dataset('BH_Mdot', arr_type='Galaxy') # Black accretion rate
    MBH_ = fl.load_dataset('BH_Mass', arr_type='Galaxy') # Black hole mass of galaxy

    X = Mstar
    fig = plt.figure(figsize=(14,6))
    plot_no = 1
    temp_max = []
    temp_min = []
    
    for zed_tag in zed_tags:
        tag = fl.tags[zed_tag]
        z = fl.zeds[zed_tag]
        df = pd.read_csv(f'{flares_dir}/modules/flares/weight_files/weights_grid.txt')
        weights = np.array(df['weights'])
        ws, x, MBH, MBHdot = np.array([]), np.array([]), np.array([]), np.array([])
        for ii in range(len(halo)):
            ws = np.append(ws, np.ones(np.shape(MBH_[halo[ii]][tag]))*weights[ii])
            x = np.append(x, np.log10(X[halo[ii]][tag]))
            MBH = np.append(MBH, np.log10(MBH_[halo[ii]][tag]))
            MBHdot = np.append(MBHdot, np.log10(MBHdot_[halo[ii]][tag]))
        MBH += 10. # convert to M_sol
        h = 0.6777 # Hubble parameter
        MBHacc = MBHdot + np.log10(h*6.445909132449984E23) # g/s
        MBHacc -= np.log10(constants.M_sun.to('g').value) # convert to M_sol/s
        MBHacc += np.log10(units.yr.to('s')) # convert to M_sol/yr

        x += 10 # units are 1E10 M_sol
        #cutting below mstar = 10**8
        y = MBH
        y_dot = MBHacc
        #cutting below mstar = 10**8
        xcut, ycut, y_dotcut = np.array([]), np.array([]), np.array([])
        for i in range(len(y)):
            if x[i] > 8:
                xcut = np.append(xcut, x[i])
                ycut = np.append(ycut, y[i])
                y_dotcut = np.append(y_dotcut, y_dot[i])
            else:
                continue
        
        x = xcut
        y = ycut
        y_dot = y_dotcut
        
        #only diffference from above function, luminosities calculated in units of erg/s
        lums = np.array([])
        for l in range(len(x)):
            lum = L_AGN_erg(y_dot[l])
            lums = np.append(lums, lum)
            
        temps = np.array([])
        for t in range(len(x)):
            temp = ((2.24e9)*((10**y_dot[t])**(0.25))*((10**y[t])**(-0.5)))    # Using blue numbers from bluetides 
            temps = np.append(temps, temp)

        figloc = '23'+str(plot_no)
        ax = fig.add_subplot(figloc)

        ax.scatter(lums, temps/(10**6), alpha=0.25)
        ax.set_title('z = '+str(z))
        ax.set_xlabel(r'AGN Luminosity ($\rm log_{10}(L_{AGN}/ergs^{-1}))$')
        ax.set_ylabel(r'Temperature (T$_{AGN}$/$10^6$ K)')
        ax.set_ylim(0, 1.5)
        ax.set_xlim(32.5, 48)
        ax.grid()
        #ax.ticklabel_format(axis = 'y', style = 'sci', scilimits=(6,6))
        plot_no+=1

    plt.tight_layout(pad=0.5, w_pad=1.25, h_pad=0.5)
    fig.subplots_adjust(right=0.85)
    fig.savefig(f'figures/LAGN_T/LAGN_T_grid_erg.png')
    plt.clf()
    fig.clf()
コード例 #8
0
def Lagn_T_individual(wanted_zed_tag):
    '''Plots T_BB against L_AGN individually, takes single input, must be string:
    'all' gives Lagn vs T for all possible redshifts
    '-1' gives redshift 5
    '-2' gives redshift 6
    '-3' gives redshift 7
    '-4' gives redshift 8
    '-5' gives redshift 9
    '-6' gives redshift 10
        '''
    import numpy as np
    import pandas as pd
    import matplotlib as mpl
    import matplotlib.cm as cm
    mpl.use('Agg')
    import matplotlib.pyplot as plt
    import flares
    import astropy.constants as constants
    import astropy.units as units
    
    #sorting which zed tags are needed
    if wanted_zed_tag == 'all':
        zed_tags = (-1,-2,-3,-4,-5,-6)
    else:
        zed_tags = [int(wanted_zed_tag)]
        
    flares_dir = '../../../../../../../research/astro/flare' #location of flares
    
    #importing flares data
    fl = flares.flares(f'{flares_dir}/simulations/FLARES/data/flares.hdf5', sim_type='FLARES')
    halo = fl.halos

    #defining colormap
    cmap = mpl.cm.plasma
    
    #loading required datasets
    Mstar = fl.load_dataset('Mstar_30', arr_type='Galaxy') # stellar mass of galaxy
    MBHdot_ = fl.load_dataset('BH_Mdot', arr_type='Galaxy') # Black accretion rate
    MBH_ = fl.load_dataset('BH_Mass', arr_type='Galaxy') # Black hole mass of galaxy

    X = Mstar
    fig = plt.figure(figsize=(14,6))
    plot_no = 1
    temp_max = []
    temp_min = []
    
    for zed_tag in zed_tags:
        tag = fl.tags[zed_tag]
        z = fl.zeds[zed_tag] # converting zedtag to redshift number

        #loading in weights
        df = pd.read_csv(f'{flares_dir}/modules/flares/weight_files/weights_grid.txt')
        weights = np.array(df['weights'])

        # creating data arrays for plotting
        ws, x, MBH, MBHdot = np.array([]), np.array([]), np.array([]), np.array([])
        for ii in range(len(halo)):
            ws = np.append(ws, np.ones(np.shape(MBH_[halo[ii]][tag]))*weights[ii])
            x = np.append(x, np.log10(X[halo[ii]][tag]))
            MBH = np.append(MBH, np.log10(MBH_[halo[ii]][tag]))
            MBHdot = np.append(MBHdot, np.log10(MBHdot_[halo[ii]][tag]))
        MBH += 10. # converting MBH units to M_sol
        h = 0.6777 # Hubble parameter

        #converting MBHacc units to M_sol/yr
        MBHacc = MBHdot + np.log10(h*6.445909132449984E23) # g/s
        MBHacc -= np.log10(constants.M_sun.to('g').value) # convert to M_sol/s
        MBHacc += np.log10(units.yr.to('s')) # convert to M_sol/yr

        x += 10 # changing units of Mstar to M_sol
        
        #cutting out galaxies below mstar = 10**8
        y = MBH
        y_dot = MBHacc
        xcut, ycut, y_dotcut = np.array([]), np.array([]), np.array([])
        for i in range(len(y)):
            if x[i] > 8:
                xcut = np.append(xcut, x[i])
                ycut = np.append(ycut, y[i])
                y_dotcut = np.append(y_dotcut, y_dot[i])
            else:
                continue
        
        x = xcut
        y = ycut
        y_dot = y_dotcut
        
        #calculating luminosities
        lums = np.array([])
        for l in range(len(x)):
            lum = L_AGN(y_dot[l])
            lums = np.append(lums, lum)
        #calculating big bump temperatures    
        temps = np.array([])
        for t in range(len(x)):
            temp = ((2.24e9)*((10**y_dot[t])**(0.25))*((10**y[t])**(-0.5))) 
            temps = np.append(temps, temp)
        
        #plotting data individually at each redshift
        plt.scatter(lums, temps/10**6, alpha = 0.25)#,s=3,c=temps, cmap = cmap,alpha=0.25)
        plt.title('z = ' + str(z))
        plt.xlabel(r'AGN Luminosity ($\rm log_{10}(L_{AGN}/L_{\odot}yr))$')
        plt.ylabel(r'Temperature (T$_{AGN}$/$10^6$ K)')
        plt.ylim(0)
        plt.xlim(0)
        plt.grid()
        #plt.ticklabel_format(axis = 'y', style = 'sci', scilimits=(6,6))

        fig.savefig(f'figures/LAGN_T/LAGN_T_'+str(int(z))+'.png')
        plt.clf()
        fig.clf()
コード例 #9
0
import matplotlib as mpl
import matplotlib.cm as cm
mpl.use('Agg')
import matplotlib.pyplot as plt

import flares

import FLARE.photom as photom
import FLARE.plt as fplt

# Selection
bhm_cut = 0  # minimum considered black-hole mass selection in log10(M_BH)

flares_dir = '../../../data/simulations'

fl = flares.flares(f'{flares_dir}/flares.hdf5', sim_type='FLARES')
halo = fl.halos
print(fl.tags)  # print list of available snapshots
tags = fl.tags

# --- define redshift colour scale

cmap = mpl.cm.plasma
norm = mpl.colors.Normalize(vmin=5., vmax=10.)

Mstar = fl.load_dataset('Mstar_30',
                        arr_type='Galaxy')  # stellar mass of galaxy
MBH = fl.load_dataset('BH_Mass',
                      arr_type='Galaxy')  # Black hole mass of galaxy
# Mdot = fl.load_dataset('BH_Mass', arr_type='Galaxy') # Black hole acretion rate
コード例 #10
0
ファイル: MstarMdot.py プロジェクト: Ross-D/flares_agn
def Mstar_Mdot_grid_MBH():
    '''plots Mstar against Mdot at all redshifts in a single figure'''
    import numpy as np
    import pandas as pd
    import matplotlib as mpl
    import matplotlib.cm as cm
    mpl.use('Agg')
    import matplotlib.pyplot as plt
    import flares
    import astropy.units as units
    import astropy.constants as constants

    flares_dir = '../../../../../../../research/astro/flare'  #location of flares

    zed_tags = (-1, -2, -3, -4, -5, -6
                )  # tags used to specify redshift in flares

    # importing flares data
    fl = flares.flares(f'{flares_dir}/simulations/FLARES/data/flares.hdf5',
                       sim_type='FLARES')
    halo = fl.halos

    #specifying and normalising colormap
    cmap = mpl.cm.cividis_r
    norm = mpl.colors.Normalize(vmin=5, vmax=9.5)

    #importing datasets from flares
    Mstar_ = fl.load_dataset('Mstar_30',
                             arr_type='Galaxy')  # stellar mass of galaxy
    MBH_ = fl.load_dataset('BH_Mass',
                           arr_type='Galaxy')  # Black hole mass of galaxy
    MBHdot_ = fl.load_dataset('BH_Mdot', arr_type='Galaxy')

    fig = plt.figure(figsize=(14, 6))
    plot_no = 1

    for zed_tag in zed_tags:
        tag = fl.tags[zed_tag]
        z = fl.zeds[zed_tag]  # converting zed tag to redshift number
        #loading in weights
        df = pd.read_csv(
            f'{flares_dir}/modules/flares/weight_files/weights_grid.txt')
        weights = np.array(df['weights'])
        #creating data arrays
        ws, x, y, MBHdot = np.array([]), np.array([]), np.array([]), np.array(
            [])
        for ii in range(len(halo)):
            ws = np.append(
                ws,
                np.ones(np.shape(MBH_[halo[ii]][tag])) * weights[ii])
            x = np.append(x, np.log10(Mstar_[halo[ii]][tag]))
            y = np.append(y, np.log10(MBH_[halo[ii]][tag]))
            MBHdot = np.append(MBHdot, np.log10(MBHdot_[halo[ii]][tag]))

        x += 10  # converting units of Mstar to M_sol
        y += 10  # converting units of MBH to M_sol

        h = 0.6777  # Hubble parameter

        #converting units of MBHacc to M_sol/yr
        MBHacc = MBHdot + np.log10(h * 6.445909132449984E23)  # g/s
        MBHacc -= np.log10(constants.M_sun.to('g').value)  # convert to M_sol/s
        MBHacc += np.log10(units.yr.to('s'))  # convert to M_sol/yr
        y_dot = MBHacc

        # cutting out galaxies below 10^8 Msol
        xcut, ycut, y_dotcut = np.array([]), np.array([]), np.array([])
        for i in range(len(y)):
            if x[i] > 8:
                xcut = np.append(xcut, x[i])
                ycut = np.append(ycut, y[i])
                y_dotcut = np.append(y_dotcut, y_dot[i])
            else:
                continue

        x = xcut
        y = ycut
        y_dot = y_dotcut
        # removing unseeded galaxies
        xcut, ycut, y_dotcut = np.array([]), np.array([]), np.array([])
        for ii in range(len(y)):
            if y[ii] == -np.inf:
                continue
            else:
                xcut = np.append(xcut, x[ii])
                ycut = np.append(ycut, y[ii])
                y_dotcut = np.append(y_dotcut, y_dot[ii])
        x = xcut
        y = ycut
        y_dot = y_dotcut

        #plotting MBHacc against Mstar, colouring by MBH
        figloc = '23' + str(plot_no)
        ax = fig.add_subplot(figloc)
        ax.scatter(x, y_dot, s=3, c=y, cmap=cmap, norm=norm, alpha=0.5)
        ax.set_title('z = ' + str(z))
        ax.set_xlabel(r'Stellar Mass ($\rm log_{10}(M_{\star}/M_{\odot}))$')
        ax.set_ylabel(
            r'Accretion Rate, $log_{10}(\dot{M}_{BH}/M_\odot yr^{-1})$')
        ax.set_xlim(8, 11.5)
        ax.set_ylim(-18, 1)
        ax.grid()
        plot_no += 1

    plt.tight_layout(pad=0.5, w_pad=1, h_pad=0.5)
    fig.subplots_adjust(right=0.85)
    # adding colourbar
    cbar_ax = fig.add_axes([0.875, 0.1, 0.01, 0.8])
    cbar = fig.colorbar(cm.ScalarMappable(cmap=cmap, norm=norm), cax=cbar_ax)
    cbar.set_label(r'SMBH Mass ($\rm log_{10}(M_{BH}/M_{\odot}))$',
                   rotation=270,
                   fontsize=7,
                   labelpad=8)
    cbar.ax.tick_params(labelsize=7)

    fig.savefig(f'figures/MstarMdot/MstarMdot_grid_MBH.png')
    plt.clf()
    fig.clf()
コード例 #11
0
import eagle_IO.eagle_IO as E
import numpy as np
import json

import matplotlib.pyplot as plt
from matplotlib.ticker import FuncFormatter

import flares
fl = flares.flares(fname='../../flares/data/flares.hdf5')

nthr = 8
tag = '008_z007p000'
z = float(tag[5:].replace('p', '.'))
scale_factor = 1. / (1 + z)

N = 10

mstar = fl.load_dataset('Mstar_30', arr_type='Galaxy')
m200 = fl.load_dataset('M200', arr_type='Galaxy')

coods = fl.load_dataset('COP', arr_type='Galaxy')
grp = fl.load_dataset('GroupNumber', arr_type='Galaxy')
sgrp = fl.load_dataset('SubGroupNumber', arr_type='Galaxy')

ind = [
    np.argpartition(m200[halo][tag][sgrp[halo][tag] == 0], -N)[-N:]
    for halo in fl.halos
]

selection = np.argsort(np.hstack([m200[halo][tag][sgrp[halo][tag] == 0][_idx]\
                       [np.argsort(metric[halo][tag][sgrp[halo][tag] == 0][_idx])][::-1] \
コード例 #12
0
ファイル: MBH_massfunc.py プロジェクト: Ross-D/flares_agn
def Mdot_func():
    '''Creates figure containing six sublots of SMBH accretion rate function at each redshift'''
    # importing modules
    import numpy as np
    import pandas as pd
    import matplotlib as mpl
    import matplotlib.cm as cm
    mpl.use('Agg')
    import matplotlib.pyplot as plt
    import flares
    import FLARE.plt as fplt
    import astropy.constants as constants
    import astropy.units as units

    flares_dir = '/research/astro/flare/' # location of flares
    
    # loading in flares
    fl = flares.flares(f'{flares_dir}/simulations/FLARES/data/flares.hdf5', sim_type='FLARES')
    halo = fl.halos
    
    # setting colour map
    cmap = mpl.cm.viridis
    norm = mpl.colors.Normalize(vmin=5., vmax=10.)
    
    # creating figure
    fig = plt.figure(figsize=(14,6))
    
    # Loading in data
    MBH_ = fl.load_dataset('BH_Mass', arr_type='Galaxy') # Black accretion rate
    MBHdot_ = fl.load_dataset('BH_Mdot', arr_type='Galaxy') # Black accretion rate

    for i in (-1, -2, -3, -4, -5, -6):
        # redshift tags
        tag = fl.tags[i]
        z = fl.zeds[i]
        
        # reading in weights
        df = pd.read_csv(f'{flares_dir}/modules/flares/weight_files/weights_grid.txt')
        weights = np.array(df['weights'])
        
        # reading in data for redshift
        ws, MBH, MBHdot = np.array([]), np.array([]), np.array([])
        for ii in range(len(halo)):
            ws = np.append(ws, np.ones(np.shape(MBH_[halo[ii]][tag]))*weights[ii])
            MBHdot = np.append(MBHdot, np.log10(MBHdot_[halo[ii]][tag]))
        
        h = 0.6777 # Hubble parameter
        
        # transforming accretion units
        MBHacc = MBHdot + np.log10(h*6.445909132449984E23) # g/s
        MBHacc -= np.log10(constants.M_sun.to('g').value) # convert to M_sol/s
        MBHacc += np.log10(units.yr.to('s')) # convert to M_sol/yr
        x = MBHacc
        
        # setting up data bins
        binw = 0.5
        bins = np.arange(-17.75,1.25,binw)
        b_c = bins[:-1]+binw/2
        
        # Binning data
        N_weighted, edges = np.histogram(x, bins = bins, weights = ws)

        #Finding Mass function
        vol = h = 0.6777
        vol = (4/3)*np.pi*(14/h)**3
        phi = N_weighted/(binw*vol)
        
        
        bins = np.append(bins, max(bins)+0.5)
        x = np.array([-18])
        x = np.append(x, bins)
        phi = np.append(phi, 1e-100)
        y = np.zeros(1)
        y = np.append(y, phi)
        phi = y
        bins = x
        for i in range(len(phi)):
            if phi[i]==0:
                phi[i] = 1e-100
        
        # Plotting
        plt.plot(bins[:-1]+binw/2, np.log10(phi), c=cmap(norm(z)), label = 'z = '+str(z))

    # Formatting plot
    plt.title('Accretion Rate "Mass" Function')
    plt.grid()
    plt.ylim(-8, -2)
    plt.xlim(-18, 1)
    plt.ylabel(r'Mass function $\rm log_{10}(\phi/Mpc^{-3}\, dex^{-1})$')
    plt.xlabel(r'Accretion Rate $\rm log_{10}(\dot{M}_{BH}/M_{\odot}yr^{-1})$')
    plt.legend()
    fig.subplots_adjust(right=0.85)
    fig.savefig(f'figures/MBH_massfunc/Mdot_single.png')
    plt.clf()
    fig.clf()
コード例 #13
0
def Lagn_MBH_grid():
    '''No inputs, creates a figure of 6 plots of Lagn vs MBH at each redshift'''
    import numpy as np
    import pandas as pd
    import matplotlib as mpl
    import matplotlib.cm as cm
    mpl.use('Agg')
    import matplotlib.pyplot as plt
    import flares
    import astropy.constants as constants
    import astropy.units as units

    flares_dir = '../../../../../../../research/astro/flare'  #location of flares directory (apollo2 location specified)

    zed_tags = (-1, -2, -3, -4, -5, -6
                )  #labels used to specify redshifts in flares

    #importing flares data
    fl = flares.flares(f'{flares_dir}/simulations/FLARES/data/flares.hdf5',
                       sim_type='FLARES')
    halo = fl.halos

    #specifying colormap
    cmap = mpl.cm.plasma

    #loading FLARES data
    Mstar = fl.load_dataset('Mstar_30',
                            arr_type='Galaxy')  # stellar mass of galaxy
    MBHdot_ = fl.load_dataset('BH_Mdot',
                              arr_type='Galaxy')  # Black accretion rate
    MBH_ = fl.load_dataset('BH_Mass',
                           arr_type='Galaxy')  # Black hole mass of galaxy

    fig = plt.figure(figsize=(14, 6))
    plot_no = 1
    temp_max = []
    temp_min = []

    for zed_tag in zed_tags:
        tag = fl.tags[zed_tag]
        z = fl.zeds[zed_tag]  #converts zed tag to redshift

        #getting weights from flares
        df = pd.read_csv(
            f'{flares_dir}/modules/flares/weight_files/weights_grid.txt')
        weights = np.array(df['weights'])

        #creating data arrarys
        ws, x, MBH, MBHdot = np.array([]), np.array([]), np.array(
            []), np.array([])
        for ii in range(len(halo)):
            ws = np.append(
                ws,
                np.ones(np.shape(MBH_[halo[ii]][tag])) * weights[ii])
            x = np.append(x, np.log10(Mstar[halo[ii]][tag]))
            MBH = np.append(MBH, np.log10(MBH_[halo[ii]][tag]))
            MBHdot = np.append(MBHdot, np.log10(MBHdot_[halo[ii]][tag]))

        MBH += 10.  # convert MBH units to M_sol
        h = 0.6777  # Hubble parameter

        #converting MBHacc units to M_sol/yr
        MBHacc = MBHdot + np.log10(h * 6.445909132449984E23)  # g/s
        MBHacc -= np.log10(constants.M_sun.to('g').value)  # convert to M_sol/s
        MBHacc += np.log10(units.yr.to('s'))  # convert to M_sol/yr

        x += 10  # convert Mstar units to M_sol

        #cutting out galaxies below Mstar = 10**8
        y = MBH
        y_dot = MBHacc

        xcut, ycut, y_dotcut = np.array([]), np.array([]), np.array([])
        for i in range(len(y)):
            if x[i] > 8:
                xcut = np.append(xcut, x[i])
                ycut = np.append(ycut, y[i])
                y_dotcut = np.append(y_dotcut, y_dot[i])
            else:
                continue

        x = xcut
        y = ycut
        y_dot = y_dotcut

        #computing luminosities with function
        lums = np.array([])
        for l in range(len(x)):
            lum = L_AGN(y_dot[l])
            lums = np.append(lums, lum)

        #Creating plot for this redshift
        figloc = '23' + str(plot_no)
        ax = fig.add_subplot(figloc)
        MBHrange = np.linspace(5.5, 10, 100)
        ax.scatter(lums, y, alpha=0.25)
        ax.plot(np.log10(L_edd(MBHrange)), MBHrange, c='k', linestyle='dashed')
        ax.set_title('z = ' + str(z))
        ax.set_xlabel(r'AGN Luminosity ($\rm log_{10}(L_{AGN}/erg s^{-1}))$')
        ax.set_ylabel(r'SMBH Mass ($\rm log_{10}(M_{BH}/M_{\odot}))$')
        ax.set_xlim(35, 48)
        ax.set_ylim(5.5, 10)
        ax.grid()
        plot_no += 1

    plt.tight_layout(pad=0.5, w_pad=1, h_pad=0.5)
    fig.subplots_adjust(right=0.85)
    fig.savefig(f'figures/LAGN_MBH/LAGN_MBH_grid_erg.png')
    plt.clf()
    fig.clf()
コード例 #14
0
def Lagn_Mstar_individual(wanted_zed_tag):
    '''takes single input, must be string:
    'all' gives Lagn vs M* for all possible redshifts
    '-1' gives redshift 5
    '-2' gives redshift 6
    '-3' gives redshift 7
    '-4' gives redshift 8
    '-5' gives redshift 9
    '-6' gives redshift 10
        '''
    import numpy as np
    import pandas as pd
    import matplotlib as mpl
    import matplotlib.cm as cm
    mpl.use('Agg')
    import matplotlib.pyplot as plt
    import flares
    import astropy.constants as constants
    import astropy.units as units
    
    #sorting which z tag is wanted
    if wanted_zed_tag == 'all':
        zed_tags = (-1,-2,-3,-4,-5,-6)
    else:
        zed_tags = [int(wanted_zed_tag)]
        
    flares_dir = '../../../../../../../research/astro/flare' #location of flares
    
    # importing flars data
    fl = flares.flares(f'{flares_dir}/simulations/FLARES/data/flares.hdf5', sim_type='FLARES')
    halo = fl.halos

    #specifying colormap
    cmap = mpl.cm.plasma
    
    #loading dataset
    Mstar = fl.load_dataset('Mstar_30', arr_type='Galaxy') # stellar mass of galaxy
    MBHdot_ = fl.load_dataset('BH_Mdot', arr_type='Galaxy') # Black accretion rate
    MBH_ = fl.load_dataset('BH_Mass', arr_type='Galaxy') # Black hole mass of galaxy

    X = Mstar
    fig = plt.figure(figsize=(14,6))
    plot_no = 1
    temp_max = []
    temp_min = []
    
    for zed_tag in zed_tags:
        tag = fl.tags[zed_tag]
        z = fl.zeds[zed_tag] #getting redshift from zed tag

        #loading weights
        df = pd.read_csv(f'{flares_dir}/modules/flares/weight_files/weights_grid.txt')
        weights = np.array(df['weights'])
        
        #creating data 
        ws, x, MBH, MBHdot = np.array([]), np.array([]), np.array([]), np.array([])
        for ii in range(len(halo)):
            ws = np.append(ws, np.ones(np.shape(MBH_[halo[ii]][tag]))*weights[ii])
            x = np.append(x, np.log10(X[halo[ii]][tag]))
            MBH = np.append(MBH, np.log10(MBH_[halo[ii]][tag]))
            MBHdot = np.append(MBHdot, np.log10(MBHdot_[halo[ii]][tag]))
        MBH += 10. # converting MBH units to M_sol
        
        h = 0.6777 # Hubble parameter

        #converting MBHacc units to M_sol/yr
        MBHacc = MBHdot + np.log10(h*6.445909132449984E23) # g/s
        MBHacc -= np.log10(constants.M_sun.to('g').value) # convert to M_sol/s
        MBHacc += np.log10(units.yr.to('s')) # convert to M_sol/yr

        x += 10 # converting units of Mstar to M_sol

        #cutting out galaxies below mstar = 10**8
        y = MBH
        y_dot = MBHacc
        xcut, ycut, y_dotcut = np.array([]), np.array([]), np.array([])
        for i in range(len(y)):
            if x[i] > 8:
                xcut = np.append(xcut, x[i])
                ycut = np.append(ycut, y[i])
                y_dotcut = np.append(y_dotcut, y_dot[i])
            else:
                continue
        
        x = xcut
        y = ycut
        y_dot = y_dotcut
        
        #calculating luminosities with defined function
        lums = np.array([])
        for l in range(len(x)):
            lum = L_AGN(y_dot[l])
            lums = np.append(lums, lum)
        
        #plotting Lagn vs Mstar at redshift in loop
        plt.scatter(x,lums, alpha = 0.25)#,s=3,c=temps, cmap = cmap,alpha=0.25)
        plt.title('z = ' + str(z))
        plt.ylabel(r'AGN Luminosity ($\rm log_{10}(L_{AGN}/L_{\odot}yr))$')
        plt.xlabel(r'Stellar Mass ($\rm log_{10}(M*/M_{\odot}))$')
        plt.xlim(8)#,11.5)
        #plt.ylim(-5,15)
        plt.grid()
        fig.savefig(f'figures/LAGN_Mstar/LAGN_Mstar_'+str(int(z))+'.png')
        plt.clf()
        fig.clf()
コード例 #15
0
def line_write_out(num, lines, tag, kappa, BC_fac, label, inp = 'FLARES', LF = False, log10t_BC = 7., Type = 'Total', extinction = 'default', data_folder = 'data', aperture='30'):

    if inp == 'FLARES':
        num = str(num)
        if len(num) == 1:
            num =  '0'+num

        filename = F"./{data_folder}/FLARES_{num}_sp_info.hdf5"
        sim_type = inp

    elif (inp == 'REF') or (inp == 'AGNdT9'):
        filename = F"./{data_folder}/EAGLE_{inp}_sp_info.hdf5"
        sim_type = 'PERIODIC'
        num='00'

    else:
        ValueError(F"No input option of {inp}")

    calc = partial(get_lines, sim=num, kappa = kappa, tag = tag, BC_fac = BC_fac, inp = inp, IMF = 'Chabrier_300', LF = False, log10t_BC = log10t_BC, Type = Type, extinction = extinction, data_folder = data_folder, aperture = aperture)

    pool = schwimmbad.MultiPool(processes=8)
    dat = np.array(list(pool.map(calc, lines)))
    pool.close()

    for ii, line in enumerate(lines):
        out_lum = dat[:,0][ii]
        out_EW = dat[:,1][ii]


        if Type == 'Total':
            fl = flares.flares(fname = filename, sim_type = sim_type)
            fl.create_group(F"{tag}/Galaxy/BPASS_2.2.1/Chabrier300/Lines/DustModelI", verbose=True)
            print (F'{line} is being written to disk')
            fl.create_dataset(values = out_lum, name = F"{line}/Luminosity",
            group = F"{tag}/Galaxy/BPASS_2.2.1/Chabrier300/Lines/DustModelI",
            desc = F"Dust corrected luminosity (using ModelI) of the galaxy with a birth cloud factor of {BC_fac} following {extinction} curve", unit = "ergs/s", overwrite=True)

            fl.create_dataset(values = out_EW, name = F"{line}/EW",
            group = F"{tag}/Galaxy/BPASS_2.2.1/Chabrier300/Lines/DustModelI",
            desc = F"EW (using ModelI) of the galaxy with a birth cloud factor of {BC_fac} following {extinction} curve", unit = "Angstrom", overwrite=True)

        elif Type=='Intrinsic':
            fl = flares.flares(fname = filename, sim_type = sim_type)
            fl.create_group(F"{tag}/Galaxy/BPASS_2.2.1/Chabrier300/Lines/{label}", verbose=True)
            print (F'{line} is being written to disk')
            fl.create_dataset(values = out_lum, name = F"{line}/Luminosity",
            group = F"{tag}/Galaxy/BPASS_2.2.1/Chabrier300/Lines/{label}",
            desc = F"Intrinsic line luminosity", unit = "ergs/s", overwrite=True)

            fl.create_dataset(values = out_EW, name = F"{line}/EW",
            group = F"{tag}/Galaxy/BPASS_2.2.1/Chabrier300/Lines/{label}",
            desc = F"Intrinsic EW", unit = "Angstrom", overwrite=True)

        elif Type=='Only-BC':
            fl = flares.flares(fname = filename, sim_type = sim_type)
            fl.create_group(F"{tag}/Galaxy/BPASS_2.2.1/Chabrier300/Lines/{label}", verbose=True)
            print (F'{line} is being written to disk')
            fl.create_dataset(values = out_lum, name = F"{line}/Luminosity",
            group = F"{tag}/Galaxy/BPASS_2.2.1/Chabrier300/Lines/{label}",
            desc = F"Intrinsic line luminosity with birth cloud factor {BC_fac} following {extinction} curve", unit = "ergs/s", overwrite=True)

            fl.create_dataset(values = out_EW, name = F"{line}/EW",
            group = F"{tag}/Galaxy/BPASS_2.2.1/Chabrier300/Lines/{label}",
            desc = F"Intrinsic EW with birth cloud factor {BC_fac} following {extinction} curve", unit = "Angstrom", overwrite=True)
コード例 #16
0
    # extinction = ['SMC', 'N18']
    # kappas = [0.0691, 0.22]

    ii, tag, inp, prop, data_folder = sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4], sys.argv[5]
    num = str(ii)
    tag = str(tag)
    data_folder = str(data_folder)

    #Parameters used
    BC_fac = 1.
    kappa = 0.0795
    aperture = '30'


    sim_type = get_simtype(inp)
    fl = flares.flares(fname = 'tmp', sim_type = sim_type)
    tags = fl.tags
    print (num, tag, inp, data_folder)

    if prop == 'Luminosity':
        print ("Calculating luminosities")
        lum_write_out(num=num, tag = tag, kappa = kappa, BC_fac = BC_fac, inp = inp, data_folder = data_folder, filters=flare.filters.TH[:-1], aperture=aperture)

    elif prop == 'Flux':
        print ("Calculating fluxes")
        flux_write_out(num=num, tag = tag, kappa = kappa, BC_fac = BC_fac,
                       filters = flare.filters.ACS + flare.filters.WFC3NIR_W + flare.filters.IRAC + flare.filters.Euclid + flare.filters.Subaru + flare.filters.NIRCam + flare.filters.MIRI,
                       inp = inp, data_folder = data_folder, aperture=aperture)

    elif prop == 'Lines':
        print ("Calculating line luminosities and EW")
コード例 #17
0
def plotBH_frac_single():
    '''Plots the fraction of galaxies that contain a SMBH binned into masses at each redshift onto a single plot'''
    #importing modules
    import numpy as np
    import pandas as pd
    import numpy as np
    import matplotlib as mpl
    import matplotlib.cm as cm
    mpl.use('Agg')
    import matplotlib.pyplot as plt
    import flares
    
    flares_dir = '../../../../../../../research/astro/flare' # location of FLARES directory
    zed_tags = (-1,-2,-3,-4,-5,-6) # need all redshifts
    
    # loading in flares
    fl = flares.flares(f'{flares_dir}/simulations/FLARES/data/flares.hdf5', sim_type='FLARES')
    halo = fl.halos
    
    # setting up colourmap
    cmap = mpl.cm.viridis
    norm = mpl.colors.Normalize(vmin=5., vmax=10.)
    
    # loading data from flares
    Mstar = fl.load_dataset('Mstar_30', arr_type='Galaxy') # stellar mass of galaxy
    MBH = fl.load_dataset('BH_Mass', arr_type='Galaxy') # Black hole mass of galaxy
    
    X = Mstar
    Y = MBH
    
    # creating figure
    fig = plt.figure(figsize=(14,6))
    
    # plotting for each redshift
    for zed_tag in zed_tags:
        
        # getting redshift tag
        tag = fl.tags[zed_tag]
        z = fl.zeds[zed_tag]
        
        # importing data
        x, y = np.array([]), np.array([])
        for ii in range(len(halo)):
            y = np.append(y, np.log10(Y[halo[ii]][tag]))
            x = np.append(x, np.log10(X[halo[ii]][tag]))
            
        x += 10 # units are 1E10 M_sol
        y += 10 # units are 1E10 M_sol
        
        # creating set of just galaxies with AGN
        x_with = []
        for i in range(len(y)):
            if y[i] == -np.inf:
                continue
            else:
                x_with.append(x[i])
        
        # binning data
        bins = 18 # int((max(x)-min(x))*4)+1
        gals = np.histogram(x, bins = bins)
        gals_with = np.histogram(x_with, bins = bins)
        
        # fraction of galaxies with SMBH in each bin
        fracs = gals_with[0]/gals[0]
        
        # plotting data for this redshift
        linewidth = 0.8*(gals[1][1]-gals[1][0])
        bincen = []
        for i in range(len(fracs)):
            cen = (gals[1][i]+gals[1][i+1])/2
            bincen.append(cen)
        plt.plot(bincen, fracs, c=cmap(norm(z)), label = 'z = '+str(int(z)))
    
    # formatting plots
    plt.legend()
    plt.ylabel(r'Fraction with SMBH')
    plt.xlabel(r'Stellar Mass ($\rm log_{10}(M_{\star}/M_{\odot})$)')
    plt.xlim(7.2, 11.5)
    #plt.ylim(0.8, 1.01)
    plt.grid()
    plt.savefig(f'figures/BH_Frac/single.png')
    plt.clf()
コード例 #18
0
def recalculate_derived_subhalo_properties(inp, num, tag, S_len, G_len, D_len, \
                                   S_index, G_index, D_index, data_folder = 'data/'):
    """
    Recalculate subhalo properties, such as the stellar/total mass and SFR,
    after inclusion of spurious galaxies.
    """

    if inp == 'FLARES':
        sim_type = 'FLARES'
        fl = flares.flares(fname = F'./{data_folder}/',sim_type=sim_type)
        _dir = fl.directory
        sim = F"{_dir}GEAGLE_{num}/data/"

    elif inp == 'REF':
        sim_type = 'PERIODIC'
        fl = flares.flares(fname = F'./{data_folder}/',sim_type=sim_type)
        sim = fl.ref_directory

    elif inp == 'AGNdT9':
        sim_type = 'PERIODIC'
        fl = flares.flares(fname = F'./{data_folder}/',sim_type=sim_type)
        sim = fl.agn_directory

    else:
        ValueError("Type of input simulation not recognized")


    # gp_sfr = E.read_array('PARTDATA', sim, tag, '/PartType0/StarFormationRate', noH=True, physicalUnits=True, numThreads=1)
    try:
        gp_mass = E.read_array('PARTDATA', sim, tag, '/PartType0/Mass',
                               noH=True, physicalUnits=True, numThreads=1)
    except:
        gp_mass = np.array([])

    try:
        sp_mass = E.read_array('PARTDATA', sim, tag, '/PartType4/Mass',
                               noH=True, physicalUnits=True, numThreads=1)
    except:
        sp_mass = np.array([])

    try:
        dm_pmass = E.read_header('PARTDATA',sim,tag,'MassTable')[1] /\
                   E.read_header('PARTDATA',sim,tag,'HubbleParam')
    except:
        dm_pmasss = np.array([])

    sbegin = np.zeros(len(S_len), dtype = np.int64)
    send = np.zeros(len(S_len), dtype = np.int64)
    sbegin[1:] = np.cumsum(S_len)[:-1]
    send = np.cumsum(S_len)

    gbegin = np.zeros(len(G_len), dtype = np.int64)
    gend = np.zeros(len(G_len), dtype = np.int64)
    gbegin[1:] = np.cumsum(G_len)[:-1]
    gend = np.cumsum(G_len)

    SMass = np.zeros(len(S_len))
    GMass = np.zeros(len(G_len))
    # total_SFR = np.zeros(len(S_len))

    for jj in range(len(sbegin)):
        SMass[jj] = np.sum(sp_mass[S_index[sbegin[jj]:send[jj]]])
        GMass[jj] = np.sum(gp_mass[G_index[gbegin[jj]:gend[jj]]])
        # total_SFR[jj] = np.sum(gp_sfr[G_index[gbegin[jj]:gend[jj]]])

    DMass = D_len * dm_pmass

    return SMass, GMass, DMass # , total_SFR
コード例 #19
0
def MBH_Mdot_grid_Mstar():
    '''No inputs, creates grid of Mdot vs MBH at each redshift'''
    import numpy as np
    import pandas as pd
    import matplotlib as mpl
    import matplotlib.cm as cm
    mpl.use('Agg')
    import matplotlib.pyplot as plt
    import flares
    import astropy.units as units
    import astropy.constants as constants

    flares_dir = '../../../../../../../research/astro/flare' #location of flares directory
    
    zed_tags = (-1,-2,-3,-4,-5,-6) #tags used to specify redshift
    
    #importing data from flars
    fl = flares.flares(f'{flares_dir}/simulations/FLARES/data/flares.hdf5', sim_type='FLARES')
    halo = fl.halos
    # defining and normalising colour map
    cmap = mpl.cm.jet
    norm = mpl.colors.Normalize(vmin=8, vmax=11.3)
    
    #loading data sets
    Mstar_ = fl.load_dataset('Mstar_30', arr_type='Galaxy') # stellar mass of galaxy
    MBH_ = fl.load_dataset('BH_Mass', arr_type='Galaxy') # Black hole mass of galaxy
    MBHdot_ = fl.load_dataset('BH_Mdot', arr_type='Galaxy')

    fig = plt.figure(figsize=(14,6))
    plot_no = 1
    
    for zed_tag in zed_tags:
        tag = fl.tags[zed_tag]
        z = fl.zeds[zed_tag] # getting redshift number from zed tag

        #loading in weights
        df = pd.read_csv(f'{flares_dir}/modules/flares/weight_files/weights_grid.txt')
        weights = np.array(df['weights'])

        #creating data arrays
        ws, x, y, MBHdot = np.array([]), np.array([]), np.array([]), np.array([])
        for ii in range(len(halo)):
            ws = np.append(ws, np.ones(np.shape(MBH_[halo[ii]][tag]))*weights[ii])
            x = np.append(x, np.log10(Mstar_[halo[ii]][tag]))
            y = np.append(y, np.log10(MBH_[halo[ii]][tag]))
            MBHdot = np.append(MBHdot, np.log10(MBHdot_[halo[ii]][tag]))
        
        #converting MBH and Mstar units to M_sol
        x += 10
        y += 10
        
        h = 0.6777 # Hubble parameter
        
        #converting MBHacc units to M_sol/yr
        MBHacc = MBHdot + np.log10(h*6.445909132449984E23) # g/s
        MBHacc -= np.log10(constants.M_sun.to('g').value) # convert to M_sol/s
        MBHacc += np.log10(units.yr.to('s')) # convert to M_sol/yr
        y_dot = MBHacc
        
        #cutting out galaxies below Mstar = 10^8
        xcut, ycut, y_dotcut = np.array([]), np.array([]), np.array([])
        for i in range(len(y)):
            if x[i] > 8:
                xcut = np.append(xcut, x[i])
                ycut = np.append(ycut, y[i])
                y_dotcut = np.append(y_dotcut, y_dot[i])
            else:
                continue
        
        x = xcut
        y = ycut
        y_dot = y_dotcut
        
        #cutting the unseeded galaxies
        xcut, ycut, y_dotcut = np.array([]), np.array([]), np.array([])
        for ii in range(len(y)):
            if y[ii] == -np.inf:
                continue
            else:
                xcut = np.append(xcut, x[ii])
                ycut = np.append(ycut, y[ii])
                y_dotcut = np.append(y_dotcut, y_dot[ii])
        x = xcut
        y = ycut
        y_dot = y_dotcut
        
        figloc = '23'+str(plot_no)
        ax = fig.add_subplot(figloc)

        # creating subplots
        ax.scatter(y,y_dot,s=3,c=x, cmap = cmap, norm = norm, alpha = 0.5)
        ax.set_title('z = '+str(z))
        ax.set_ylabel(r'Accretion Rate ($\rm log_{10}(\dot{M}/M_{\odot}yr))$')
        ax.set_xlabel(r'SMBH Mass ($\rm log_{10}(M_{BH}/M_{\odot}))$')
        ax.set_xlim(5.16,9.5)
        ax.set_ylim(-10,2)
        ax.grid()
        plot_no+=1
        
    plt.tight_layout(pad=0.5, w_pad=2, h_pad=0.5)
    fig.subplots_adjust(right=0.85)
    #adding colour bar
    cbar_ax = fig.add_axes([0.875, 0.1, 0.01, 0.8])
    cbar = fig.colorbar(cm.ScalarMappable(cmap = cmap, norm = norm), cax = cbar_ax)
    cbar.set_ticks([8.0, 8.5, 9.0, 9.5, 10.0, 10.5, 11.0, 11.3])
    cbar.set_label(r'Stellar Mass ($log_{10}(M_\star/M_\odot$))', rotation=270, fontsize = 7, labelpad = 8.5)
    cbar.ax.tick_params(labelsize=7)
    fig.savefig(f'figures/MBHMdot/MBHMdot_grid_Mstar.png')
    plt.clf()
    fig.clf()
コード例 #20
0
def Lagn_Mstar_grid():
    '''No inputs, creates grid of Lagn vs Mstar at each redshift'''
    import numpy as np
    import pandas as pd
    import matplotlib as mpl
    import matplotlib.cm as cm
    mpl.use('Agg')
    import matplotlib.pyplot as plt
    import flares
    import astropy.constants as constants
    import astropy.units as units
 
    flares_dir = '../../../../../../../research/astro/flare' #location of flares
    
    zed_tags = (-1,-2,-3,-4,-5,-6) #tags used to identify redshift in FLARES
    
    #process for loading data and creating arrays is the same as above
    fl = flares.flares(f'{flares_dir}/simulations/FLARES/data/flares.hdf5', sim_type='FLARES')
    halo = fl.halos
    cmap = mpl.cm.plasma
    
    Mstar = fl.load_dataset('Mstar_30', arr_type='Galaxy') # stellar mass of galaxy
    MBHdot_ = fl.load_dataset('BH_Mdot', arr_type='Galaxy') # Black accretion rate
    MBH_ = fl.load_dataset('BH_Mass', arr_type='Galaxy') # Black hole mass of galaxy

    X = Mstar
    fig = plt.figure(figsize=(14,6))
    plot_no = 1
    temp_max = []
    temp_min = []
    
    for zed_tag in zed_tags:
        tag = fl.tags[zed_tag]
        z = fl.zeds[zed_tag]
        df = pd.read_csv(f'{flares_dir}/modules/flares/weight_files/weights_grid.txt')
        weights = np.array(df['weights'])
        ws, x, MBH, MBHdot = np.array([]), np.array([]), np.array([]), np.array([])
        for ii in range(len(halo)):
            ws = np.append(ws, np.ones(np.shape(MBH_[halo[ii]][tag]))*weights[ii])
            x = np.append(x, np.log10(X[halo[ii]][tag]))
            MBH = np.append(MBH, np.log10(MBH_[halo[ii]][tag]))
            MBHdot = np.append(MBHdot, np.log10(MBHdot_[halo[ii]][tag]))
        MBH += 10. # convert to M_sol
        h = 0.6777 # Hubble parameter
        MBHacc = MBHdot + np.log10(h*6.445909132449984E23) # g/s
        MBHacc -= np.log10(constants.M_sun.to('g').value) # convert to M_sol/s
        MBHacc += np.log10(units.yr.to('s')) # convert to M_sol/yr

        x += 10 # units are 1E10 M_sol
        #cutting below mstar = 10**8
        y = MBH
        y_dot = MBHacc
        #cutting below mstar = 10**8
        xcut, ycut, y_dotcut = np.array([]), np.array([]), np.array([])
        for i in range(len(y)):
            if x[i] > 8:
                xcut = np.append(xcut, x[i])
                ycut = np.append(ycut, y[i])
                y_dotcut = np.append(y_dotcut, y_dot[i])
            else:
                continue
        
        x = xcut
        y = ycut
        y_dot = y_dotcut
        
        lums = np.array([])
        for l in range(len(x)):
            lum = L_AGN(y_dot[l])
            lums = np.append(lums, lum)
         
        #function is different after this point
        # each redshift plotted into the same figure
        figloc = '23'+str(plot_no)
        ax = fig.add_subplot(figloc)

        ax.scatter(x, lums, alpha=0.25)
        ax.set_title('z = '+str(z))
        ax.set_ylabel(r'AGN Luminosity ($\rm log_{10}(L_{AGN}/L_{\odot}))$')
        ax.set_xlabel(r'Stellar Mass ($\rm log_{10}(M*/M_{\odot}))$')
        ax.set_xlim(8,11.5)
        ax.set_ylim(-5,15)
        ax.grid()
        plot_no+=1

    plt.tight_layout(pad=0.5, w_pad=1, h_pad=0.5)
    fig.subplots_adjust(right=0.85)
    fig.savefig(f'figures/LAGN_Mstar/LAGN_Mstar_grid.png')
    plt.clf()
    fig.clf()
コード例 #21
0
ファイル: MBH_massfunc.py プロジェクト: Ross-D/flares_agn
def MBH_func():
    '''Creates figure containing six sublots of SMBH massfunction at each redshift'''
    #Importing modules
    import numpy as np
    import pandas as pd
    import matplotlib as mpl
    import matplotlib.cm as cm
    mpl.use('Agg')
    import matplotlib.pyplot as plt
    import flares
    import FLARE.plt as fplt
    
    flares_dir = '/research/astro/flare/' # location of flares files
    
    # loading flares
    fl = flares.flares(f'{flares_dir}/simulations/FLARES/data/flares.hdf5', sim_type='FLARES')
    halo = fl.halos
    
    # setting colour map
    cmap = mpl.cm.viridis
    norm = mpl.colors.Normalize(vmin=5., vmax=10.)
    
    # creating figure
    fig = plt.figure(figsize=(14,6))
    
    # loading SMBH Mass data
    MBH = fl.load_dataset('BH_Mass', arr_type='Galaxy') # stellar mass of galaxy
    X = MBH

    for i in (-1, -2, -3, -4, -5, -6):
        # geting redshift tag
        tag = fl.tags[i]
        z = fl.zeds[i]
        
        # creating array of data
        df = pd.read_csv(f'{flares_dir}/modules/flares/weight_files/weights_grid.txt')
        weights = np.array(df['weights'])
        ws, x = np.array([]), np.array([])
        for ii in range(len(halo)):
            ws = np.append(ws, np.ones(np.shape(X[halo[ii]][tag]))*weights[ii])
            x = np.append(x, np.log10(X[halo[ii]][tag]))


        x += 10 # units are 1E10 M_sol
        
        # seting up bins for data
        binw = 0.3
        bins = np.arange(5.35, 9.45, binw)
        b_c = bins[:-1]+binw/2
        
        # binning data (weighted)
        N_weighted, edges = np.histogram(x, bins = bins, weights = ws)

        # calculating mass function
        vol = h = 0.6777
        vol = (4/3)*np.pi*(14/h)**3
        phi = N_weighted/(binw*vol)
        
        bins = np.append(bins, max(bins)+0.5)
        phi = np.append(phi, 1e-100)
        for i in range(len(phi)):
            if phi[i]==0:
                phi[i] = 1e-100
        # plotting at redshift
        plt.plot(bins[:-1]+binw/2, np.log10(phi), c=cmap(norm(z)), label = 'z = '+str(z))

    # Formatting plot
    plt.title('SMBH Mass Function')
    plt.grid()
    plt.ylabel(r'Mass function $\rm log_{10}(\phi/Mpc^{-3}\, dex^{-1})$')
    plt.xlabel(r'SMBH mass $\rm log_{10}(M_{BH}/M_{\odot})$')
    plt.legend()
    plt.ylim(-8, -3)
    plt.xlim(5.5)
    fig.subplots_adjust(right=0.85)
    fig.savefig(f'figures/MBH_massfunc/MBH_single.png')
    plt.clf()
    fig.clf()
コード例 #22
0
ファイル: MBH_hist.py プロジェクト: Ross-D/flares_agn
def MBH_hist_single_line():
    '''Plots histogram of SMBH masses at all redshifts onto a single plot'''
    #importing modules
    import numpy as np
    import pandas as pd
    import numpy as np
    import matplotlib as mpl
    import matplotlib.cm as cm
    mpl.use('Agg')
    import matplotlib.pyplot as plt
    import flares

    flares_dir = '../../../../../../../research/astro/flare'  #location of flares directory
    zed_tags = (-1, -2, -3, -4, -5, -6
                )  #tags used to specify redshifts in flares

    #importing flares data set
    fl = flares.flares(f'{flares_dir}/simulations/FLARES/data/flares.hdf5',
                       sim_type='FLARES')
    halo = fl.halos
    #creating and normalising colour map
    cmap = mpl.cm.viridis
    norm = mpl.colors.Normalize(vmin=5., vmax=10.)

    #extracting stellar mass and black hole mass for the required sim and redshift
    Mstar = fl.load_dataset('Mstar_30',
                            arr_type='Galaxy')  # stellar mass of galaxy
    MBH = fl.load_dataset('BH_Mass',
                          arr_type='Galaxy')  # Black hole mass of galaxy

    X = Mstar
    Y = MBH

    fig = plt.figure(figsize=(14, 6))
    #plot_no = 1

    for zed_tag in zed_tags:
        tag = fl.tags[zed_tag]
        z = fl.zeds[zed_tag]
        #creating data arrays
        x, y = np.array([]), np.array([])
        for ii in range(len(halo)):
            y = np.append(y, np.log10(Y[halo[ii]][tag]))
            x = np.append(x, np.log10(X[halo[ii]][tag]))
        #converting MBH and Mstar to units of M_sol
        x += 10
        y += 10
        #cuttting out unseeded galaxies
        y2 = []
        for i in range(len(y)):
            if y[i] == -np.inf:
                continue
            else:
                y2.append(y[i])

        #binning SMBHs into mass bins
        bins = np.arange(5, 10.15, 0.3)
        y_binned = np.histogram(y2, bins=bins)
        bincen = []
        for i in range(len(y_binned[1]) - 1):
            cen = y_binned[1][i] + (y_binned[1][i + 1] - y_binned[1][i]) / 2
            bincen.append(cen)
        #plotting histogram
        plt.plot(bincen,
                 y_binned[0],
                 c=cmap(norm(z)),
                 label='z = ' + str(int(z)))  #[0], y_binned[1])

    plt.ylabel('Frequency')
    plt.yscale('log')
    plt.xlabel(r'$\rm log_{10}(M_{BH}/M_{\odot})$')
    plt.legend()
    plt.xlim(5.5, 9.5)
    plt.grid()
    plt.title('Total Simulated SMBH by Mass')
    fig.savefig(f'figures/MBH_hist/hist_single_line.png')
    plt.clf()
    fig.clf()
コード例 #23
0
ファイル: ImportFunc.py プロジェクト: Ross-D/flares_agn
def retrieve_data():
    import numpy as np
    import pandas as pd
    import matplotlib as mpl
    import matplotlib.cm as cm
    mpl.use('Agg')
    import matplotlib.pyplot as plt
    import flares
    import astropy.constants as constants
    import astropy.units as units

    zed_tags = (-1, -2, -3, -4, -5, -6)
    #zed_tags = [-1]

    flares_dir = '../../../../../../../research/astro/flare'

    fl = flares.flares(f'{flares_dir}/simulations/FLARES/data/flares.hdf5',
                       sim_type='FLARES')
    halo = fl.halos
    cmap = mpl.cm.plasma

    Mstar_ = fl.load_dataset('Mstar_30',
                             arr_type='Galaxy')  # stellar mass of galaxy
    MBHdot_ = fl.load_dataset('BH_Mdot',
                              arr_type='Galaxy')  # Black accretion rate
    MBH_ = fl.load_dataset('BH_Mass',
                           arr_type='Galaxy')  # Black hole mass of galaxy
    Lum_Gal = fl.load_dataset(
        "BPASS_2.2.1/Chabrier300/Luminosity/Intrinsic/FUV",
        arr_type='Galaxy')  # Black hole mass of galaxy
    Data = {}
    for zed_tag in zed_tags:
        tag = fl.tags[zed_tag]
        z = fl.zeds[zed_tag]
        df = pd.read_csv(
            f'{flares_dir}/modules/flares/weight_files/weights_grid.txt')
        weights = np.array(df['weights'])
        ws, Mstar, MBH, MBHdot, Gal_FUV = np.array([]), np.array([]), np.array(
            []), np.array([]), np.array([])
        for ii in range(len(halo)):
            ws = np.append(
                ws,
                np.ones(np.shape(MBH_[halo[ii]][tag])) * weights[ii])
            Mstar = np.append(Mstar, np.log10(Mstar_[halo[ii]][tag]))
            MBH = np.append(MBH, np.log10(MBH_[halo[ii]][tag]))
            MBHdot = np.append(MBHdot, np.log10(MBHdot_[halo[ii]][tag]))
            Gal_FUV = np.append(Gal_FUV, np.log10(Lum_Gal[halo[ii]][tag]))
        Mstar += 10.  # convert to M_sol
        MBH += 10.  # convert to M_sol
        h = 0.6777  # Hubble parameter

        MBHacc = MBHdot + np.log10(h * 6.445909132449984E23)  # g/s
        MBHacc -= np.log10(constants.M_sun.to('g').value)  # convert to M_sol/s
        MBHacc += np.log10(units.yr.to('s'))  # convert to M_sol/yr
        MBH_cut, MBHacc_cut, Gal_FUV_cut, Mstar_cut, ws_cut = [], [], [], [], []
        for i in range(len(MBH)):
            if MBH[i] == -np.inf:
                continue
            elif MBHacc[i] == -np.inf:
                continue
            else:
                MBH_cut.append(MBH[i])
                MBHacc_cut.append(MBHacc[i])
                Gal_FUV_cut.append(Gal_FUV[i])
                Mstar_cut.append(Mstar[i])
                ws_cut.append(ws[i])

        MBH = np.asarray(MBH_cut)
        MBHacc = np.asarray(MBHacc_cut)
        Gal_FUV = np.asarray(Gal_FUV_cut)
        Mstar = np.asarray(Mstar_cut)
        ws = np.asarray(ws_cut)

        AGN_Lbol, AGN_FUV, AGN_T = np.zeros(len(MBHacc)), np.zeros(
            len(MBHacc)), np.zeros(len(MBHacc))
        for iii in range(len(MBHacc)):
            L_agn = L_AGN(MBHacc[iii])
            T_agn = Temp(MBH[iii], MBHacc[iii])
            L_agn_FUV = L_FUV_fit(L_agn, T_agn)
            AGN_Lbol[iii] = L_agn + 18.27875360095283
            AGN_FUV[iii] = L_agn_FUV + 18.27875360095283
            AGN_T[iii] = T_agn

        data_at_z = {}
        data_at_z.update({"AGN_Lbol": AGN_Lbol})
        data_at_z.update({"AGN_FUV": AGN_FUV})
        data_at_z.update({"AGN_T": AGN_T})
        data_at_z.update({"Gal_FUV": Gal_FUV})
        data_at_z.update({"MBH": MBH})
        data_at_z.update({"MBHacc": MBHacc})
        data_at_z.update({"Mstar": Mstar})
        data_at_z.update({"Weights": ws})
        Data.update({str(z): data_at_z})
    return Data
コード例 #24
0
ファイル: MBH_DF.py プロジェクト: stephenmwilkins/flares_agn
import numpy as np
import pandas as pd

import matplotlib as mpl
import matplotlib.cm as cm
mpl.use('Agg')
import matplotlib.pyplot as plt

import flares

flares_dir = '/research/astro/flare/'

fl = flares.flares(f'{flares_dir}/simulations/FLARES/data/flares.hdf5',
                   sim_type='FLARES')
halo = fl.halos
print(fl.tags)  # print list of available snapshots
tag = fl.tags[-1]  #This would be z=5

z = fl.zeds[-1]  # get redshift

MBH = fl.load_dataset('BH_Mass',
                      arr_type='Galaxy')  # Black hole mass of galaxy

X = MBH

# --- FLARES is composed of 40 individual simulations. Each simulation has a statistical weight (basically the likelhood a similar region would appear in a volume of the real Universe). To get true distribution functions we need to weight each galaxy by the weight of the simulation.

# --- This bit of codes reads in the properties for all of the galaxies in every simulation and also produces a corresponding weight array. These can be combined later to get a true relationship.

df = pd.read_csv(f'{flares_dir}/modules/flares/weight_files/weights_grid.txt')
weights = np.array(df['weights'])
コード例 #25
0
import fitDF.fitDF as fitDF
import fitDF.models as models
import fitDF.analyse as analyse

import flares
from modules import get_lum_all, Schechter, DPL, fit_function
# import fit_bootstrap
from mpi4py import MPI
import seaborn as sns

sns.set_context("paper")

model = str(sys.argv[1])
zs = [5., 6., 7., 8., 9., 10.]
fl = flares.flares('./data/flares.hdf5')
h = 0.6777
vol = (4 / 3) * np.pi * (14 / h)**3
refvol = 100**3
AGNdT9vol = 50**3
filters = 'FUV'

if model == 'Schechter':
    folder = 'fit_Sch'
elif model == 'DPL':
    folder = 'fit_DPL'

tags = fl.tags[::-1]


def fitdf(ii, tag, N_up, N, V, bins, model):
コード例 #26
0
def MBH_Mdot_individual_Mstar(wanted_zed_tag):
    '''Creates individual plot of Mdot vs MBH at each redshift,
      takes single input, must be string:
    'all' gives histograms for all possible redshifts
    '-1' gives redshift 5
    '-2' gives redshift 6
    '-3' gives redshift 7
    '-4' gives redshift 8
    '-5' gives redshift 9
    '-6' gives redshift 10
        '''
    import numpy as np
    import pandas as pd
    import matplotlib as mpl
    import matplotlib.cm as cm
    mpl.use('Agg')
    import matplotlib.pyplot as plt
    import flares
    import astropy.units as units
    import astropy.constants as constants

    flares_dir = '../../../../../../../research/astro/flare' #location of flares directory
    
    # sorting needed zed tags    
    if wanted_zed_tag == 'all':
        zed_tags = (-1,-2,-3,-4,-5,-6)
    else:
        zed_tags = [int(wanted_zed_tag)]
    
    #importing flares data
    fl = flares.flares(f'{flares_dir}/simulations/FLARES/data/flares.hdf5', sim_type='FLARES')
    halo = fl.halos
    #creating nd normalising colour map
    cmap = mpl.cm.jet
    norm = mpl.colors.Normalize(vmin=8, vmax=11.3)
    #loading datasets
    Mstar_ = fl.load_dataset('Mstar_30', arr_type='Galaxy') # stellar mass of galaxy
    MBH_ = fl.load_dataset('BH_Mass', arr_type='Galaxy') # Black hole mass of galaxy
    MBHdot_ = fl.load_dataset('BH_Mdot', arr_type='Galaxy')

    fig = plt.figure(figsize=(14,6))
    plot_no = 1
    
    for zed_tag in zed_tags:
        tag = fl.tags[zed_tag]
        z = fl.zeds[zed_tag] #getting redshift number from zed tag

        #importing weights
        df = pd.read_csv(f'{flares_dir}/modules/flares/weight_files/weights_grid.txt')
        weights = np.array(df['weights'])
        #creating data arrays        
        ws, x, y, MBHdot = np.array([]), np.array([]), np.array([]), np.array([])
        for ii in range(len(halo)):
            ws = np.append(ws, np.ones(np.shape(MBH_[halo[ii]][tag]))*weights[ii])
            x = np.append(x, np.log10(Mstar_[halo[ii]][tag]))
            y = np.append(y, np.log10(MBH_[halo[ii]][tag]))
            MBHdot = np.append(MBHdot, np.log10(MBHdot_[halo[ii]][tag]))

        #converting MBH and Mstar units to M_sol
        x += 10
        y += 10
        
        h = 0.6777 # Hubble parameter
        
        #converting MBHacc units to M_sol/yr
        MBHacc = MBHdot + np.log10(h*6.445909132449984E23) # g/s
        MBHacc -= np.log10(constants.M_sun.to('g').value) # convert to M_sol/s
        MBHacc += np.log10(units.yr.to('s')) # convert to M_sol/yr
        y_dot = MBHacc
        
        #cutting out galaxies below Mstar = 10^8
        xcut, ycut, y_dotcut = np.array([]), np.array([]), np.array([])
        for i in range(len(y)):
            if x[i] > 8:
                xcut = np.append(xcut, x[i])
                ycut = np.append(ycut, y[i])
                y_dotcut = np.append(y_dotcut, y_dot[i])
            else:
                continue
        
        x = xcut
        y = ycut
        y_dot = y_dotcut
        
        #cutting the unseeded galaxies
        xcut, ycut, y_dotcut = np.array([]), np.array([]), np.array([])
        for ii in range(len(y)):
            if y[ii] == -np.inf:
                continue
            else:
                xcut = np.append(xcut, x[ii])
                ycut = np.append(ycut, y[ii])
                y_dotcut = np.append(y_dotcut, y_dot[ii])
        x = xcut
        y = ycut
        y_dot = y_dotcut
        
        #plotting
        plt.scatter(y,y_dot,s=3,c=x, cmap = cmap, norm = norm, alpha=0.5)
        plt.title('z = ' + str(z))
        plt.ylabel(r'Accretion Rate ($\rm log_{10}(\dot{M}/M_{\odot}yr))$')
        plt.xlabel(r'SMBH Mass ($\rm log_{10}(M_{BH}/M_{\odot}))$')
        plt.grid()
        plt.xlim(5.16)
        plt.tight_layout(pad=0.5, w_pad=1, h_pad=0.5)
        fig.subplots_adjust(right=0.85)
        cbar = fig.colorbar(cm.ScalarMappable(cmap = cmap, norm = norm))
        cbar.set_ticks([8.0, 8.5, 9.0, 9.5, 10.0, 10.5, 11.0, 11.3])
        cbar.set_label(r'Stellar Mass ($log_{10}(M_\star/M_\odot$))', rotation=270, fontsize = 7, labelpad = 8.5)
        cbar.ax.tick_params(labelsize=7)
        fig.savefig(f'figures/MBHMdot/MBHMdot_'+str(int(z))+'_Mstar.png')
        plt.clf()
        fig.clf()
コード例 #27
0
import numpy as np
import matplotlib.cm as cm

import flares
import flares_analysis
import flare.plt as fplt

# ----------------------------------------------------------------------
# --- open data

fl = flares.flares(
    '/cosma7/data/dp004/dc-payy1/my_files/flares_pipeline/data/flares.hdf5',
    sim_type='FLARES')
halo = fl.halos

# ----------------------------------------------------------------------
# --- define parameters and tag
tag = fl.tags[-3]  # --- select tag -3 = z=7
log10Mstar_limit = 9.

# ----------------------------------------------------------------------
# --- define quantities to read in [not those for the corner plot, that's done later]

quantities = []
quantities.append({
    'path': 'Galaxy',
    'dataset': 'SFR_inst_30',
    'name': None,
    'log10': True
})
quantities.append({
コード例 #28
0
    angles = np.vstack([hp_theta, hp_phi]).T

    #For galaxies in region `num`
    num = str(ii)
    if len(num) == 1:
        num = '0'+num
    cop, mstar, S_coords, G_coords, S_mass, S_Z, S_age, G_mass, G_sml, G_Z, begin, end, gbegin, gend = get_data(num, tag, inp = 'FLARES')
    z = float(tag[5:].replace('p','.'))
    cop = cop/(1+z)
    S_coords/=(1+z)
    G_coords/=(1+z)

    req_ind = np.where(mstar>10**9.5)[0]
    print ("Number of selected galaxies = ", len(req_ind))
    filename = F'data/Zlos_inclination_{num}.hdf5'
    fl = flares.flares(fname = filename, sim_type = sim_type)
    fl.create_group(F'{tag}')

    for kk, jj in enumerate(req_ind):

        #Coordinates and attributes for the jj galaxy in ii region
        scoords = S_coords[:, begin[jj]:end[jj]].T - cop[:,jj]
        gcoords = G_coords[:, gbegin[jj]:gend[jj]].T - cop[:,jj]

        this_smass = S_mass[begin[jj]:end[jj]]
        this_gmass = G_mass[gbegin[jj]:gend[jj]]

        this_sZ = S_Z[begin[jj]:end[jj]]
        this_gZ = G_Z[gbegin[jj]:gend[jj]]

        this_age = S_age[begin[jj]:end[jj]]
コード例 #29
0
ファイル: T_Mstar.py プロジェクト: Ross-D/flares_agn
def Temp_Mstar_grid():
    '''plots T_BB against Mstar, all plots will be saved as a single figure'''
    import numpy as np
    import pandas as pd
    import matplotlib as mpl
    import matplotlib.cm as cm
    mpl.use('Agg')
    import matplotlib.pyplot as plt
    import flares
    import astropy.constants as constants
    import astropy.units as units

    flares_dir = '../../../../../../../research/astro/flare'  #location of flares

    zed_tags = (-1, -2, -3, -4, -5, -6
                )  # tags used to denote redshift in flares

    #loading flares data
    fl = flares.flares(f'{flares_dir}/simulations/FLARES/data/flares.hdf5',
                       sim_type='FLARES')
    halo = fl.halos

    #defining colormap
    cmap = mpl.cm.plasma

    #loading datasets from flares
    Mstar = fl.load_dataset('Mstar_30',
                            arr_type='Galaxy')  # stellar mass of galaxy
    MBHdot_ = fl.load_dataset('BH_Mdot',
                              arr_type='Galaxy')  # Black accretion rate
    MBH_ = fl.load_dataset('BH_Mass',
                           arr_type='Galaxy')  # Black hole mass of galaxy

    X = Mstar
    fig = plt.figure(figsize=(14, 6))
    plot_no = 1
    temp_max = []
    temp_min = []

    for zed_tag in zed_tags:
        tag = fl.tags[zed_tag]
        z = fl.zeds[zed_tag]  #converting zed tag to redshift number

        #loading in weights
        df = pd.read_csv(
            f'{flares_dir}/modules/flares/weight_files/weights_grid.txt')
        weights = np.array(df['weights'])

        #creating data arrays for plotting
        ws, x, MBH, MBHdot = np.array([]), np.array([]), np.array(
            []), np.array([])
        for ii in range(len(halo)):
            ws = np.append(
                ws,
                np.ones(np.shape(MBH_[halo[ii]][tag])) * weights[ii])
            x = np.append(x, np.log10(X[halo[ii]][tag]))
            MBH = np.append(MBH, np.log10(MBH_[halo[ii]][tag]))
            MBHdot = np.append(MBHdot, np.log10(MBHdot_[halo[ii]][tag]))
        MBH += 10.  # converting MBH units to M_sol
        h = 0.6777  # Hubble parameter
        # converting MBHacc units to M_sol/yr
        MBHacc = MBHdot + np.log10(h * 6.445909132449984E23)  # g/s
        MBHacc -= np.log10(constants.M_sun.to('g').value)  # convert to M_sol/s
        MBHacc += np.log10(units.yr.to('s'))  # convert to M_sol/yr

        x += 10  # # converting Mstar units to M_sol
        #cutting out galaxies below mstar = 10**8
        y = MBH
        y_dot = MBHacc
        xcut, ycut, y_dotcut = np.array([]), np.array([]), np.array([])
        for i in range(len(y)):
            if x[i] > 8:
                xcut = np.append(xcut, x[i])
                ycut = np.append(ycut, y[i])
                y_dotcut = np.append(y_dotcut, y_dot[i])
            else:
                continue

        x = xcut
        y = ycut
        y_dot = y_dotcut

        #calculating temperatures
        temps = np.array([])
        for t in range(len(x)):
            temp = ((2.24e9) * ((10**y_dot[t])**(0.25)) * ((10**y[t])**(-0.5))
                    )  # Using blue numbers from bluetides
            temps = np.append(temps, temp)

        #plotting into single figure
        figloc = '23' + str(plot_no)
        ax = fig.add_subplot(figloc)

        ax.scatter(x, temps / 10**6, alpha=0.25)
        ax.set_title('z = ' + str(z))
        ax.set_ylabel(r'Temperature (T$_{AGN}$/$10^6$ K)')
        ax.set_xlabel(r'Stellar Mass ($\rm log_{10}(M_{*}/M_{\odot}))$')
        ax.set_ylim(0, 1.5)
        ax.set_xlim(8, 11.5)
        ax.grid()
        #ax.ticklabel_format(axis = 'y', style = 'sci', scilimits=(6,6))

        temp_max.append(max(temps))
        temp_min.append(min(temps))
        plot_no += 1

    plt.tight_layout(pad=0.5, w_pad=1, h_pad=0.5)
    fig.savefig(f'figures/T_Mstar/T_Mstar_grid_temp.png')
    plt.clf()
    fig.clf()