Пример #1
0
    def iter_alpha(i, surveys=surveys, parallel=None):
        alpha = ALPHAS[i]
        pop = CosmicPopulation.complex(SIZE)
        pop.set_dist(model='vol_co', z_max=1.0, alpha=alpha)
        pop.set_lum(model='powerlaw', low=1e40, high=1e45, power=-1)
        pop.generate()

        for li in LIS:
            pop.set_lum(model='powerlaw', low=1e40, high=1e45, power=li)
            pop.gen_lum()

            for si in SIS:
                pop.set_si(model='constant', value=si)
                pop.gen_si()

                pop.name = f'complex_alpha_{alpha}_lum_{li}_si_{si}'

                for survey in surveys:
                    surv_pop = SurveyPopulation(pop, survey)
                    print(surv_pop.name)
                    surv_pop.save()

                    sr = surv_pop.source_rate
                    rate = sr.det / sr.days
                    mask = (df.alpha == alpha) & (df.li == li) & (df.si == si)

                    if parallel is not None:
                        i = df[mask].index
                        j = SURVEY_NAMES.index(survey.name)
                        parallel[i, j] = rate
                    else:
                        df.loc[mask, survey.name] = rate
Пример #2
0
        def iter_alpha(i):
            alpha = alphas[i]
            pop = CosmicPopulation.complex(self.pop_size)

            pop.set_dist(model='vol_co', z_max=1.0, alpha=alpha)
            pop.set_lum(model='constant', value=1)

            if not np.isnan(w_mean):
                pop.set_w(model='lognormal', mean=w_mean, std=w_std)
            if not np.isnan(dm_igm_slope):
                pop.set_dm_igm(model='ioka', slope=dm_igm_slope)
                pop.set_dm_host(model='constant', value=dm_host)

            pop.generate()

            for si in sis:
                pop.set_si(model='constant', value=si)
                pop.gen_si()

                for li in lis:
                    pop.set_lum(model='powerlaw',
                                low=1e40,
                                high=1e45,
                                power=li)

                    if not np.isnan(lum_min):
                        pop.set_lum(model='powerlaw',
                                    low=lum_min,
                                    high=lum_max,
                                    index=li)

                    pop.gen_lum()

                    for survey in self.surveys:
                        surv_pop = SurveyPopulation(pop, survey)

                        # Get unique identifier
                        mask = (self.so.df.par_set == 1)
                        mask &= (self.so.df.run == run)
                        mask &= (self.so.df.alpha == alpha)
                        mask &= (self.so.df.si == si)
                        mask &= (self.so.df.li == li)
                        mask &= (self.so.df.survey == survey.name)
                        uuid = self.so.df[mask].uuid.iloc[0]
                        surv_pop.name = f'mc/run_{run}/{uuid}'
                        surv_pop.save()
Пример #3
0
        def adapt_pop(e):
            w_mean, w_std = e
            t_pop = deepcopy(pop)
            t_pop.set_w(model='lognormal', mean=w_mean, std=w_std)
            t_pop.gen_w()

            for survey in self.surveys:
                surv_pop = SurveyPopulation(t_pop, survey)

                # Get unique identifier
                mask = (self.so.df.par_set == 3)
                mask &= (self.so.df.run == run)
                mask &= (self.so.df.run == run)
                mask &= (self.so.df.w_mean == w_mean)
                mask &= (self.so.df.w_std == w_std)
                mask &= (self.so.df.survey == survey.name)
                uuid = self.so.df[mask].uuid.iloc[0]
                surv_pop.name = f'mc/run_{run}/{uuid}'
                surv_pop.save()
Пример #4
0
def get_survey_pop(pop, survey, overwrite=False):
    """Quickly get survey populations.

    Args:
        pop (CosmicPopulation): Population to survey
        survey (Survey): Survey to use
        overwrite (bool): Check whether a population has already
            been run. If overwrite is true, it will always make a new
            instance.

    Returns:
        pop: Desired population.

    """
    observe = True

    # Check where a possible population would be located
    path = ''
    if isinstance(pop, str):
        name = f'{pop}_{survey.name}'
        path = paths.populations() + name + '.p'

    # Check if the file exists
    if not overwrite:
        if os.path.isfile(path):
            observe = False
            return unpickle(path)

    # If all else fails observe again
    if observe:

        if isinstance(pop, str):
            m = f'No survey population at {path}, yet no surveying requested'
            raise ValueError(m)

        surv_pop = SurveyPopulation(pop, survey)
        surv_pop.name = f'{pop.name}_{survey.name}'
        surv_pop.save()
        return surv_pop
Пример #5
0
        def adapt_pop(e):
            dm_igm_slope, dm_host = e
            t_pop = deepcopy(pop)
            t_pop.set_dm_igm(model='ioka', slope=dm_igm_slope)
            t_pop.gen_dm_igm()
            t_pop.set_dm_host(model='constant', value=dm_host)
            t_pop.gen_dm_host()
            t_pop.frbs.dm = t_pop.frbs.dm_mw + t_pop.frbs.dm_igm
            t_pop.frbs.dm += t_pop.frbs.dm_host

            for survey in self.surveys:
                surv_pop = SurveyPopulation(t_pop, survey)

                # Get unique identifier
                mask = (self.so.df.par_set == 4)
                mask &= (self.so.df.run == run)
                mask &= (self.so.df.dm_igm_slope == dm_igm_slope)
                mask &= (self.so.df.dm_host == dm_host)
                mask &= (self.so.df.survey == survey.name)
                uuid = self.so.df[mask].uuid.iloc[0]
                surv_pop.name = f'mc/run_{run}/{uuid}'
                surv_pop.save()
Пример #6
0
        def adapt_pop(e):
            li, lum_min, lum_max = e
            if lum_max < lum_min:
                return
            t_pop = deepcopy(pop)
            t_pop.set_lum(model='powerlaw',
                          low=lum_min,
                          high=lum_max,
                          power=li)
            t_pop.gen_lum()

            for survey in self.surveys:
                surv_pop = SurveyPopulation(t_pop, survey)

                # Get unique identifier
                mask = (self.so.df.par_set == 2)
                mask &= (self.so.df.run == run)
                mask &= (self.so.df.li == li)
                mask &= (self.so.df.lum_min == lum_min)
                mask &= (self.so.df.lum_max == lum_max)
                mask &= (self.so.df.survey == survey.name)
                uuid = self.so.df[mask].uuid.iloc[0]
                surv_pop.name = f'mc/run_{run}/{uuid}'
                surv_pop.save()
Пример #7
0
import numpy as np
import matplotlib.pyplot as plt

from frbpoppy import CosmicPopulation, Survey, SurveyPopulation
from frbpoppy.population import unpickle

from tests.convenience import plot_aa_style, rel_path

MAKE = True

if MAKE:
    population = CosmicPopulation.simple(1e5, generate=True)
    survey = Survey('perfect')
    surv_pop = SurveyPopulation(population, survey)
    surv_pop.name = 'lognlogflocal'
    surv_pop.save()
else:
    surv_pop = unpickle('lognlogflocal')

# Get parameter
parms = surv_pop.frbs.fluence
min_p = min(parms)
max_p = max(parms)

# Bin up
min_f = np.log10(min(parms))
max_f = np.log10(max(parms))
log_bins = np.logspace(min_f, max_f, 50)
hist, edges = np.histogram(parms, bins=log_bins)
n_gt_s = np.cumsum(hist[::-1])[::-1]