def mdp_table(self, column_density, index, exposure_time, eflux):
        """Return the MDP table for a point source with a power-law
        spectral shape with a given set of parameters and for a given
        observation time.

        There's a slight complication, here, due to the fact that the
        sensitivity calculator is rescaling the absorbed fluxes so that the
        input energy flux (in the web form) is that at the observer instead of
        that at the source. Therefore we need to do the same here.
        """
        tsamples = numpy.linspace(0.0, exposure_time, 2)
        norm = int_eflux2pl_norm(eflux, self.emin, self.emax, index, erg=True)
        energy_spectrum = power_law(norm, index)
        ism_trans = self.ism_model.transmission_factor(column_density)
        _x = numpy.linspace(self.emin, self.emax, 1000)
        _y = _x * energy_spectrum(_x, 0.0) * ism_trans(_x)
        absorbed_energy_spectrum = xInterpolatedUnivariateSplineLinear(_x, _y)
        absorbed_eflux = keV2erg(absorbed_energy_spectrum.norm())
        scale = eflux / absorbed_eflux
        count_spectrum = xCountSpectrum(energy_spectrum, self.aeff, tsamples, column_density, scale_factor=scale)
        mdp_table = count_spectrum.build_mdp_table(self.ebinning, self.modf)
        return mdp_table
Example #2
0
def process_grb(grb_name, tstart=21600., duration=30000., prompt_duration=600):
    """
    """
    file_path = download_swift_grb_lc_file(grb_name)
    if file_path is None:
        return None
    pl_index = get_grb_spec_index(file_path)
    ra, dec = get_grb_position(file_path)
    light_curve = parse_light_curve(file_path, num_min_data=5.)
    if light_curve is None:
        return None
    t = light_curve.x
    grb_start, prompt_tstart = t[0], t[0]
    grb_stop = t[-1]
    prompt_tstop = t[0] + prompt_duration
    prompt_flux = light_curve.integral(prompt_tstart, prompt_tstop)
    logger.info('Integral energy flux in %.3f--%.3f s: %.3e erg cm^{-2}' %\
                (prompt_tstart, prompt_tstop, prompt_flux))
    tstart = max(tstart, t[0])
    tstop = min(tstart + duration, t[-1])
    logger.info('Effective time interval for the MDP: %.3f--%.3f s' %\
                (tstart, tstop))
    t = t[(t >= tstart)*(t <= tstop)]
    if len(t) < 2:
        return None
    scale_factor = int_eflux2pl_norm(1., 0.3, 10., pl_index, erg=True)
    pl_norm = light_curve.scale(scale_factor)# Fix the label.
    def energy_spectrum(E, t):
        return pl_norm(t)*numpy.power(E, -pl_index)
    count_spectrum = xCountSpectrum(energy_spectrum, aeff, t)
    mdp_table = count_spectrum.build_mdp_table(ENERGY_BINNING, modf)
    logger.info(mdp_table)
    mdp = mdp_table.mdp_values()[0]
    eff_mu = [row.mu_effective for row in mdp_table.rows]
    counts = [row.num_signal for row in mdp_table.rows]
    grb_values = [ra, dec, pl_index, tstart, tstop, prompt_flux, prompt_tstart,\
                  prompt_tstop, grb_start, grb_stop, eff_mu[0], counts[0], mdp]
    return grb_values
Example #3
0
        p_opt_max = float(p_opt_max)
        p_opt_min = float(p_opt_min)
        if p_opt_min < 0.5:
            p_opt_min = 0.5
        if p_opt_max > 0.5:
            src = {
                "name": name,
                "flux_min": flux_min,
                "flux_max": flux_max,
                "p_opt_max": p_opt_max,
                "p_opt_min": p_opt_min,
            }
            src_list.append(src)


pl_norm_ref = int_eflux2pl_norm(FLUX_REF, E_MIN, E_MAX, PL_INDEX)
logger.info("PL normalization @ %.3e erg cm^-2 s^-1: %.3e keV^-1 cm^-2 s^-1" % (FLUX_REF, pl_norm_ref))
aeff = load_arf(DEFAULT_IRF_NAME)
modf = load_mrf(DEFAULT_IRF_NAME)
tsamples = numpy.array([0, OBS_TIME_REF])
ebinning = numpy.array([E_MIN, E_MAX])
energy_spectrum = power_law(pl_norm_ref, PL_INDEX)
count_spectrum = xCountSpectrum(energy_spectrum, aeff, tsamples)
mdp_table = count_spectrum.build_mdp_table(ebinning, modf)
mdp_ref = mdp_table.mdp_values()[-1]
logger.info("Reference MDP for %s s: %.3f" % (OBS_TIME_REF, mdp_ref))

blazar_list = parse_blazar_list(PRIORITY_ONLY)
mirror_list = [1, 3, 9, 17, 18]

numpy.random.seed(10)
Example #4
0
    spline = xInterpolatedUnivariateSplineLinear(tave, fave)
    tave = numpy.linspace(tave[0], tave[-1], num_bins)
    fave = spline(tave)
    tave = numpy.power(10., tave)
    fave = numpy.power(10., fave)
    fmt = dict(xname='Time', xunits='s',
               yname='Energy integral flux 0.3-10 keV',
               yunits='erg cm$^{-2}$ s$^{-1}$')
    return xInterpolatedUnivariateSplineLinear(tave, fave, **fmt)


ROI_MODEL = xROIModel(GRB_RA, GRB_DEC)

lc_file_path = os.path.join(XIMPOL_CONFIG, 'ascii/GRB130427_Swift.dat')
integral_flux_spline = parse_light_curve(lc_file_path)
scale_factor = int_eflux2pl_norm(1, MIN_ENERGY, MAX_ENERGY, PL_INDEX)
fmt = dict(yname='PL normalization', yunits='cm$^{-2}$ s$^{-1}$ keV$^{-1}$')
pl_normalization_spline = integral_flux_spline.scale(scale_factor, **fmt)

"""For the polarization degree we are literally making up something
that decreases with time.
"""
_t = integral_flux_spline.x
_p = 0.6*(1. - (_t/integral_flux_spline.xmax())**0.1)
fmt = dict(xname='Time', xunits='s', yname='Polarization degree')
pol_degree_spline = xInterpolatedUnivariateSplineLinear(_t, _p, **fmt)

def energy_spectrum(E, t):
    return pl_normalization_spline(t)*numpy.power(E, -PL_INDEX)

def polarization_degree(E, t, ra, dec):