Esempio n. 1
0
import sys
import os

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

import FLARE
from FLARE.SED import models
from FLARE.SED import SFZH
import FLARE.filters

SPS = models.SPS('BPASSv2.2.1.binary/ModSalpeter_300')

sfzh, sfr = SFZH.constant(SPS, {
    'log10_duration': 8.,
    'log10Z': -2.,
    'log10M*': 8.
})

print('star formation rate: {0}'.format(sfr))

# plt.imshow(sfzh.T)
# plt.show()

SED = SPS.get_Lnu(sfzh)

plt.plot(np.log10(SED.stellar.lam), np.log10(SED.stellar.lnu))
plt.plot(np.log10(SED.total.lam), np.log10(SED.total.lnu))

plt.xlim([2.7, 4.])
Esempio n. 2
0
    def create_SED(self, p):

        derived = {}

        if 'beta' in p:

            rest_lam = np.arange(0., 5000., 1.)

            self.F = FLARE.filters.add_filters(self.Filters,
                                               new_lam=rest_lam *
                                               (1. + p['z']))

            sed = FLARE.SED.models.beta(rest_lam,
                                        p['beta'],
                                        10**p['log10L1500'],
                                        normalisation_wavelength=1500.)

        else:

            # --- get SFH for a given choice of

            sfzh, sfr = SFZH.constant(
                self.SPS.grid['log10age'], self.SPS.grid['log10Z'], {
                    'log10_duration': p['log10_duration'],
                    'log10Z': p['log10Z'],
                    'log10M*': p['log10M*']
                })

            # --- generate SED for a given choice of parameters

            SED = self.SPS.get_Lnu(sfzh, {
                'fesc': p['fesc'],
                'log10tau_V': p['log10tau_V']
            },
                                   dust_model='very_simple')

            sed = SED.total

            self.F = FLARE.filters.add_filters(self.Filters,
                                               new_lam=sed.lam * (1. + p['z']))

            restF = FLARE.filters.add_filters(self.Filters,
                                              new_lam=sed.lam * (1. + p['z']))

            derived['log10L1500'] = np.log10(
                sed.return_Lnu(
                    FLARE.filters.add_filters(['FAKE.TH.FUV'],
                                              new_lam=sed.lam))['FAKE.TH.FUV'])
            derived['log10SFR'] = np.log10(sfr)

            if self.verbose:
                print(rf'log10(L1500/erg/s/Hz)={derived["log10L1500"]:2f}')
                print(rf'log10(SFR/M/yr)={derived["log10SFR"]:2f}')

        sed.get_fnu(
            self.cosmo, p['z']
        )  # --- generate observed frame spectrum (necessary to get broad band photometry)
        sed.get_Fnu(self.F)  # --- generate broadband photometry
        Fnu = {f: [sed.Fnu[f]] for f in self.Filters}

        # --- print out fluxes

        if self.verbose:
            print('-' * 5, 'SED')
            for f in self.Filters:
                print('{0}: {1:.2f}/nJy'.format(f, Fnu[f][0]))

        return Fnu, derived
Esempio n. 3
0
import os
sys.path.insert(0,
                os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

import FLARE
from FLARE.SED import models
from FLARE.SED import SFZH

SPS = models.SPS('BPASSv2.2.1.binary/ModSalpeter_300')

N = 100

for i, log10age in enumerate(np.linspace(6.0, 8.0, N)):

    print(i)

    sfzh = SFZH.simple(SPS, {'log10age': log10age, 'log10Z': -2.})

    SED = SPS.get_Lnu(sfzh)

    plt.plot(np.log10(SED.stellar.lam),
             np.log10(SED.stellar.lnu),
             c=cm.viridis(i / N),
             lw=1,
             alpha=0.5)

mx = np.max(np.log10(SED.stellar.lnu))  # only last one
plt.xlim([2.7, 4.])
plt.ylim([mx - 4., mx + 3.0])
plt.show()
Esempio n. 4
0
    def create_SED(self, p):

        derived = {}

        if self.SimType == 'beta':

            rest_lam = np.arange(0., 5000., 1.)

            self.F = FLARE.filters.add_filters(self.Filters,
                                               new_lam=rest_lam *
                                               (1. + p['z']))

            sed = FLARE.SED.models.beta(rest_lam,
                                        p['beta'],
                                        1.0,
                                        normalisation_wavelength=1500.)

        elif self.SimType == 'const':

            # --- get SFH for a given choice of

            # -- this was the old behaviour where we later rescaled by SNR
            if 'SNR' in p:
                sfzh, sfr = SFZH.constant(
                    self.SPS.grid['log10age'], self.SPS.grid['log10Z'], {
                        'log10_duration': p['log10_duration'],
                        'log10Z': p['log10Z'],
                        'log10M*': 8.0
                    })
            if 'log10M*' in p:
                sfzh, sfr = SFZH.constant(
                    self.SPS.grid['log10age'], self.SPS.grid['log10Z'], {
                        'log10_duration': p['log10_duration'],
                        'log10Z': p['log10Z'],
                        'log10M*': p['log10M*']
                    })

            # --- generate SED for a given choice of parameters

            SED = self.SPS.get_Lnu(sfzh, {
                'fesc': p['fesc'],
                'log10tau_V': p['log10tau_V']
            },
                                   dust=('simple', {
                                       'slope': -1.0
                                   }))

            sed = SED.total
            self.F = FLARE.filters.add_filters(self.Filters,
                                               new_lam=sed.lam * (1. + p['z']))

        elif self.SimType == 'instantaneous':  # instantaneous burst as close to age of the Universe as possible

            # --- get SFH for a given choice of

            sfzh, sfr = SFZH.instantaneous(
                self.SPS.grid['log10age'], self.SPS.grid['log10Z'], {
                    'log10age': p['log10age'],
                    'log10Z': p['log10Z'],
                    'log10M*': p['log10M*']
                })

            # --- generate SED for a given choice of parameters

            SED = self.SPS.get_Lnu(sfzh, {
                'fesc': 0.0,
                'log10tau_V': p['log10tau_V']
            },
                                   dust=('simple', {
                                       'slope': -1.0
                                   }))

            sed = SED.total
            self.F = FLARE.filters.add_filters(self.Filters,
                                               new_lam=sed.lam * (1. + p['z']))

        else:

            print('WARNING! Incorrect simulation type set')

        sed.get_fnu(
            self.cosmo, p['z']
        )  # --- generate observed frame spectrum (necessary to get broad band photometry)
        sed.get_Fnu(self.F)  # --- generate broadband photometry

        Fnu = {f: sed.Fnu[f] for f in self.Filters}

        return Fnu
Esempio n. 5
0
    def create_SED(self, p):

        derived = {}

        if 'beta' in p:

            rest_lam = np.arange(0., 5000., 1.)

            self.F = FLARE.filters.add_filters(self.Filters,
                                               new_lam=rest_lam *
                                               (1. + p['z']))

            sed = FLARE.SED.models.beta(rest_lam,
                                        p['beta'],
                                        10**p['log10L1500'],
                                        normalisation_wavelength=1500.)

        else:

            # --- get SFH for a given choice of

            sfzh, sfr = SFZH.constant(
                self.SPS.grid['log10age'], self.SPS.grid['log10Z'], {
                    'log10_duration': p['log10_duration'],
                    'log10Z': p['log10Z'],
                    'log10M*': 8.0
                })

            # --- generate SED for a given choice of parameters

            SED = self.SPS.get_Lnu(sfzh, {
                'fesc': p['fesc'],
                'log10tau_V': p['log10tau_V']
            },
                                   dust_model='very_simple')

            sed = SED.total

            self.F = FLARE.filters.add_filters(self.Filters,
                                               new_lam=sed.lam * (1. + p['z']))

            restF = FLARE.filters.add_filters(self.Filters,
                                              new_lam=sed.lam * (1. + p['z']))

        sed.get_fnu(
            self.cosmo, p['z']
        )  # --- generate observed frame spectrum (necessary to get broad band photometry)
        sed.get_Fnu(self.F)  # --- generate broadband photometry

        Fnu = {
            f: sed.Fnu[f] / sed.Fnu[self.ReferenceFilter]
            for f in self.Filters
        }

        # --- add in noise

        ref_noise = Fnu[self.ReferenceFilter] / p['SNR']

        ref_depth = FLARE.photom.m_to_flux(self.depths[self.ReferenceFilter])

        noise_scaling = {
            f: FLARE.photom.m_to_flux(self.depths[f]) / ref_depth
            for f in self.Filters
        }

        obs = SimpleNamespace()

        obs.error = {f: ref_noise * noise_scaling[f] for f in self.Filters}

        obs.flux = {
            f: Fnu[f] + obs.error[f] * np.random.randn()
            for f in self.Filters
        }

        obs.flux = {
            f: obs.flux[f] / obs.flux[self.ReferenceFilter]
            for f in self.Filters
        }

        # --- print out fluxes

        if self.verbose:
            print('-' * 5, 'SED')
            for f in self.Filters:
                print(
                    f'{f}: {Fnu[f]:.2f} | {obs.flux[f]:.2f} {obs.error[f]:.2f} {obs.flux[f]/obs.error[f]:.2f}'
                )

        return Fnu, obs
Esempio n. 6
0
    def create_SED(self, p):

        derived = {}

        if 'beta' in p:

            rest_lam = np.arange(0., 5000., 1.)

            self.F = FLARE.filters.add_filters(self.Filters,
                                               new_lam=rest_lam *
                                               (1. + p['z']))

            sed = FLARE.SED.models.beta(rest_lam,
                                        p['beta'],
                                        10**p['log10L1500'],
                                        normalisation_wavelength=1500.)

        elif 'log10M*' in p:

            print('WARNING: not yet implemented')

        elif 'log10L1500' in p:

            if 'duration' in p.keys():
                p['log10_duration'] = np.log10(p['duration']) + 6.

            sfzh, sfr = SFZH.constant(
                self.SPS.grid['log10age'], self.SPS.grid['log10Z'], {
                    'log10_duration': p['log10_duration'],
                    'log10Z': p['log10Z'],
                    'log10M*': 0.0
                })

            # --- generate SED for a given choice of parameters

            SED = self.SPS.get_Lnu(sfzh, {
                'fesc': p['fesc'],
                'log10tau_V': p['log10tau_V']
            },
                                   dust_model='very_simple')

            sed = SED.total

            log10L1500 = np.log10(
                sed.return_Lnu(
                    FLARE.filters.add_filters(['FAKE.TH.FUV'],
                                              new_lam=sed.lam))['FAKE.TH.FUV'])

            derived['log10M*'] = p['log10L1500'] - log10L1500
            derived['log10SFR'] = np.log10(sfr) + derived['log10M*']

            sed.lnu *= 10**derived['log10M*']

            self.F = FLARE.filters.add_filters(self.Filters,
                                               new_lam=sed.lam * (1. + p['z']))

        sed.get_fnu(
            self.cosmo, p['z']
        )  # --- generate observed frame spectrum (necessary to get broad band photometry)
        sed.get_Fnu(self.F)  # --- generate broadband photometry
        Fnu = {f: [sed.Fnu[f]] for f in self.Filters}

        # --- print out fluxes

        if self.verbose:
            print('-' * 5, 'Derived Quantities')
            for k, v in derived.items():
                print(f'{k} {v:.2f}')
            print('-' * 5, 'SED')
            for f in self.Filters:
                print('{0}: {1:.2f}/nJy'.format(f, Fnu[f][0]))

        return Fnu, derived
Esempio n. 7
0
sed.get_fnu(
    cosmo, z
)  # --- generate observed frame SED (necessary to get broad band photometry)
Fnu = sed.return_Fnu(F)  # --- generate observed frame broadband photometry

FLARE.obs.misc.measure_beta(z, Fnu, F, verbose=True)

# --- using SPS model

SPS = FLARE.SED.models.SPS('BPASSv2.2.1.binary/Chabrier_300')

F = FLARE.filters.add_filters(filters, new_lam=SPS.lam * (1. + z))

sfzh, sfr = SFZH.constant(SPS.grid['log10age'], SPS.grid['log10Z'], {
    'log10_duration': 8.,
    'log10Z': -8.0,
    'log10M*': 8.0
})

for log10tau_V in np.arange(-2., 2.0, 0.5):

    SED = SPS.get_Lnu(sfzh, {
        'fesc': 0.0,
        'log10tau_V': log10tau_V
    },
                      dust_model='very_simple')

    sed = SED.total

    sed.get_fnu(
        cosmo, z