import time
import sys
import os
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

import flare
import flare.filters
import synthobs
from synthobs.sed import models

import synthobs.morph.images
import synthobs.morph.PSF



cosmo = flare.default_cosmo()
z = 8.


test = synthobs.test_data() # --- read in some test data

# --- calculate V-band (550nm) optical depth for each star particle
A = 5.2
test.tauVs = (10**A) * test.MetSurfaceDensities



model = models.define_model('BPASSv2.2.1.binary/ModSalpeter_300') # DEFINE SED GRID -
model.dust = {'slope': -1.0} # define dust curve

Ejemplo n.º 2
0
def m_to_lum(m, z, cosmo=flare.default_cosmo()):

    return flux_to_L(m_to_flux(m), cosmo, z)
Ejemplo n.º 3
0
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm

import sys
import os
sys.path.insert(0,
                os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

import flare
import flare.LF
from flare.LF import evo, lf_parameters, LF_plots, completeness
from flare.photom import m_to_flux

cosmo = flare.default_cosmo()  # WMAP9

f_limit_deep = flare.photom.m_to_flux(26.)

area = 60. * 60. * 40.

print('area of Euclid deep: {0} arcmin2'.format(area))

# load in lf parameters
m = getattr(lf_parameters, 'FLARES')()

evo_model = evo.linear(
    m)  # initialises the linear evolution model with the FLARES parameters

bin_edges, bin_centres, N = evo_model.N(cosmo=cosmo,
                                        redshift_limits=[8., 15.],
                                        log10L_limits=[27., 30.],
Ejemplo n.º 4
0
def m_to_M(m, z, cosmo=flare.default_cosmo()):
    return m - DM(z, cosmo=cosmo)
Ejemplo n.º 5
0
def M_to_m(M, z, cosmo=flare.default_cosmo()):
    return M + DM(z, cosmo=cosmo)
Ejemplo n.º 6
0
def DM(z, cosmo=flare.default_cosmo()):
    luminosity_distance = cosmo.luminosity_distance(z).to('pc').value
    return 5 * np.log10(luminosity_distance / (np.sqrt(1. + z) * 10.))
Ejemplo n.º 7
0
def flux(sim,
         kappa,
         tag,
         BC_fac,
         inp='FLARES',
         IMF='Chabrier_300',
         filters=flare.filters.NIRCam_W,
         Type='Total',
         log10t_BC=7.,
         extinction='default',
         data_folder='data',
         aperture='30'):

    S_mass, S_Z, S_age, S_los, S_len, begin, end, S_ap, DTM = get_data(
        sim, tag, inp, data_folder, aperture)

    if np.isscalar(filters):
        Fnus = np.zeros(len(begin), dtype=np.float64)
    else:
        Fnus = np.zeros((len(begin), len(filters)), dtype=np.float64)

    model = models.define_model(
        F'BPASSv2.2.1.binary/{IMF}')  # DEFINE SED GRID -
    if extinction == 'default':
        model.dust_ISM = ('simple', {'slope': -1.})  #Define dust curve for ISM
        model.dust_BC = ('simple', {
            'slope': -1.
        })  #Define dust curve for birth cloud component
    elif extinction == 'Calzetti':
        model.dust_ISM = ('Starburst_Calzetti2000', {''})
        model.dust_BC = ('Starburst_Calzetti2000', {''})
    elif extinction == 'SMC':
        model.dust_ISM = ('SMC_Pei92', {''})
        model.dust_BC = ('SMC_Pei92', {''})
    elif extinction == 'MW':
        model.dust_ISM = ('MW_Pei92', {''})
        model.dust_BC = ('MW_Pei92', {''})
    elif extinction == 'N18':
        model.dust_ISM = ('MW_N18', {''})
        model.dust_BC = ('MW_N18', {''})
    else:
        ValueError("Extinction type not recognised")

    z = float(tag[5:].replace('p', '.'))
    F = flare.filters.add_filters(filters, new_lam=model.lam * (1. + z))

    cosmo = flare.default_cosmo()

    model.create_Fnu_grid(
        F, z, cosmo
    )  # --- create new Fnu grid for each filter. In units of nJy/M_sol

    for jj in range(len(begin)):

        Masses = S_mass[begin[jj]:end[jj]][S_ap[begin[jj]:end[jj]]]
        Ages = S_age[begin[jj]:end[jj]][S_ap[begin[jj]:end[jj]]]
        Metallicities = S_Z[begin[jj]:end[jj]][S_ap[begin[jj]:end[jj]]]
        MetSurfaceDensities = S_los[begin[jj]:end[jj]][S_ap[begin[jj]:end[jj]]]

        MetSurfaceDensities = DTM[jj] * MetSurfaceDensities

        if Type == 'Total':
            tauVs_ISM = kappa * MetSurfaceDensities  # --- calculate V-band (550nm) optical depth for each star particle
            tauVs_BC = BC_fac * (Metallicities / 0.01)
            fesc = 0.0

        elif Type == 'Pure-stellar':
            tauVs_ISM = np.zeros(len(Masses))
            tauVs_BC = np.zeros(len(Masses))
            fesc = 1.0

        elif Type == 'Intrinsic':
            tauVs_ISM = np.zeros(len(Masses))
            tauVs_BC = np.zeros(len(Masses))
            fesc = 0.0

        elif Type == 'Only-BC':
            tauVs_ISM = np.zeros(len(Masses))
            tauVs_BC = BC_fac * (Metallicities / 0.01)
            fesc = 0.0

        else:
            ValueError(F"Undefined Type {Type}")

        Fnu = models.generate_Fnu(
            model=model,
            F=F,
            Masses=Masses,
            Ages=Ages,
            Metallicities=Metallicities,
            tauVs_ISM=tauVs_ISM,
            tauVs_BC=tauVs_BC,
            fesc=fesc,
            log10t_BC=log10t_BC
        )  # --- calculate rest-frame flux of each object in nJy

        Fnus[jj] = list(Fnu.values())

    return Fnus
Ejemplo n.º 8
0
def flux(sim, kappa, tag, BC_fac, inp='FLARES', IMF='Chabrier_300',
         filters=flare.filters.NIRCam_W, Type='Total', log10t_BC=7.,
         extinction='default', orientation="sim"):
    kinp = np.load('/cosma/home/dp004/dc-rope1/cosma7/FLARES/'
                   'flares/los_extinction/kernel_sph-anarchy.npz',
                   allow_pickle=True)
    lkernel = kinp['kernel']
    header = kinp['header']
    kbins = header.item()['bins']

    S_mass, S_Z, S_age, S_los, G_Z, S_len, \
    G_len, G_sml, S_sml, G_mass, S_coords, G_coords, \
    S_vels, G_vels, cops, \
    begin, end, gbegin, gend = get_data(sim, tag, inp)

    Fnus = {f: np.zeros(len(S_mass), dtype=np.float64) for f in filters}

    model = models.define_model(
        F'BPASSv2.2.1.binary/{IMF}')  # DEFINE SED GRID -
    if extinction == 'default':
        model.dust_ISM = (
            'simple', {'slope': -1.})  # Define dust curve for ISM
        model.dust_BC = ('simple', {
            'slope': -1.})  # Define dust curve for birth cloud component
    elif extinction == 'Calzetti':
        model.dust_ISM = ('Starburst_Calzetti2000', {''})
        model.dust_BC = ('Starburst_Calzetti2000', {''})
    elif extinction == 'SMC':
        model.dust_ISM = ('SMC_Pei92', {''})
        model.dust_BC = ('SMC_Pei92', {''})
    elif extinction == 'MW':
        model.dust_ISM = ('MW_Pei92', {''})
        model.dust_BC = ('MW_Pei92', {''})
    elif extinction == 'N18':
        model.dust_ISM = ('MW_N18', {''})
        model.dust_BC = ('MW_N18', {''})
    else:
        ValueError("Extinction type not recognised")

    z = float(tag[5:].replace('p', '.'))
    F = flare.filters.add_filters(filters, new_lam=model.lam * (1. + z))

    cosmo = flare.default_cosmo()

    # --- create new Fnu grid for each filter. In units of nJy/M_sol
    model.create_Fnu_grid(F, z, cosmo)

    for jj in range(len(begin)):

        # Extract values for this galaxy
        Masses = S_mass[begin[jj]: end[jj]]
        Ages = S_age[begin[jj]: end[jj]]
        Metallicities = S_Z[begin[jj]: end[jj]]
        gasMetallicities = G_Z[begin[jj]: end[jj]]
        gasSML = G_sml[begin[jj]: end[jj]]
        gasMasses = G_mass[begin[jj]: end[jj]]

        if orientation == "sim":

            starCoords = S_coords[:, begin[jj]: end[jj]].T - cops[:, jj]
            S_coords[:, begin[jj]: end[jj]] = starCoords.T

            MetSurfaceDensities = S_los[begin[jj]:end[jj]]

        elif orientation == "face-on":

            starCoords = S_coords[:, begin[jj]: end[jj]].T - cops[:, jj]
            gasCoords = G_coords[:, begin[jj]: end[jj]].T - cops[:, jj]
            gasVels = G_vels[:, begin[jj]: end[jj]].T

            # Get angular momentum vector
            ang_vec = util.ang_mom_vector(gasMasses, gasCoords, gasVels)

            # Rotate positions
            starCoords = util.get_rotated_coords(ang_vec, starCoords)
            gasCoords = util.get_rotated_coords(ang_vec, gasCoords)
            S_coords[:, begin[jj]: end[jj]] = starCoords.T

            MetSurfaceDensities = util.get_Z_LOS(starCoords, gasCoords,
                                                 gasMasses, gasMetallicities,
                                                 gasSML, (0, 1, 2),
                                                 lkernel, kbins)
        elif orientation == "side-on":

            starCoords = S_coords[:, begin[jj]: end[jj]].T - cops[:, jj]
            gasCoords = G_coords[:, begin[jj]: end[jj]].T - cops[:, jj]
            gasVels = G_vels[:, begin[jj]: end[jj]].T

            # Get angular momentum vector
            ang_vec = util.ang_mom_vector(gasMasses, gasCoords, gasVels)

            # Rotate positions
            starCoords = util.get_rotated_coords(ang_vec, starCoords)
            gasCoords = util.get_rotated_coords(ang_vec, gasCoords)
            S_coords[:, begin[jj]: end[jj]] = starCoords.T

            MetSurfaceDensities = util.get_Z_LOS(starCoords, gasCoords,
                                                 gasMasses, gasMetallicities,
                                                 gasSML, (2, 0, 1),
                                                 lkernel, kbins)
        else:
            MetSurfaceDensities = None
            print(orientation,
                  "is not an recognised orientation. "
                  "Accepted types are 'sim', 'face-on', or 'side-on'")

        Mage = np.nansum(Masses * Ages) / np.nansum(Masses)
        Z = np.nanmean(gasMetallicities)

        MetSurfaceDensities = DTM_fit(Z, Mage) * MetSurfaceDensities

        if Type == 'Total':
            # --- calculate V-band (550nm) optical depth for each star particle
            tauVs_ISM = kappa * MetSurfaceDensities
            tauVs_BC = BC_fac * (Metallicities / 0.01)
            fesc = 0.0

        elif Type == 'Pure-stellar':
            tauVs_ISM = np.zeros(len(Masses))
            tauVs_BC = np.zeros(len(Masses))
            fesc = 1.0

        elif Type == 'Intrinsic':
            tauVs_ISM = np.zeros(len(Masses))
            tauVs_BC = np.zeros(len(Masses))
            fesc = 0.0

        elif Type == 'Only-BC':
            tauVs_ISM = np.zeros(len(Masses))
            tauVs_BC = BC_fac * (Metallicities / 0.01)
            fesc = 0.0

        else:
            tauVs_ISM = None
            tauVs_BC = None
            fesc = None
            ValueError(F"Undefined Type {Type}")

        # --- calculate rest-frame Luminosity. In units of erg/s/Hz
        for f in filters:
            # --- calculate rest-frame flux of each object in nJy
            Fnu = models.generate_Fnu_array(model, Masses, Ages, Metallicities,
                                            tauVs_ISM, tauVs_BC, F, f,
                                            fesc=fesc, log10t_BC=log10t_BC)

            Fnus[f][begin[jj]: end[jj]] = Fnu

    Fnus["coords"] = S_coords
    Fnus["smls"] = S_sml
    Fnus["begin"] = begin
    Fnus["end"] = end

    return Fnus