test.test_count_spectrum

Unit test for the count spectrum facility.

class ximpol.test.test_count_spectrum.TestCountSpectrum(methodName='runTest')[source]

Unit test for xCountSpectrum.

classmethod setUpClass()[source]

Setup—here we essentially create the effective area.

>>> file_path = os.path.join(XIMPOL_IRF,'fits','xipe_baseline.arf')
>>> cls.aeff = xEffectiveArea(file_path)
test_power_law_rvs(num_events=1000000)[source]

Test the generation of event energies from a count power-law spectrum convoluted with the effective area.

This turned out to be more tricky than we anticipated. Since the convolution of the source spectrum with the effective area falls pretty quickly at high energy, there’s typically very few events above a few keV and, as a consequence, the slope of the corresponding ppf is fairly steep close to one.

../_images/test_power_law_rvs_vppf.png

This implies that the ppf in each slice must be properly sampled close to 1 (initial tests showed, e.g., that a uniform grid with 100 points between 0 and 1 was not enough to throw meaningful random numbers for a typical power-law source spectrum). This is particularly true for soft spectral indices—which is why we picked Gamma = 3. for this test.

../_images/test_power_law_rvs_counts.png
test_power_law_stationary()[source]

Test a time-independent power law.

This creates a count spectrum with no time dependence, i.e., with only two (identical) interpolating time points on the auxiliary (time) axis. The power-law parameters (C and gamma) are constant

>>> tmin = 0.
>>> tmax = 100.
>>> C = 1.
>>> Gamma = 2.
>>>
>>> def powerlaw(E, t):
>>>     return C*numpy.power(E, -Gamma)
>>>
>>> _t = numpy.linspace(tmin, tmax, 2)
>>> count_spectrum = xCountSpectrum(powerlaw, self.aeff, _t)

and the underlying xUnivariateAuxGenerator looks like.

../_images/test_power_law_stationary_2d.png

Then a vertical slice (i.e., an interpolated linear spline) is taken in the middle of the auxiliary axis

>>> tref = 0.5*(tmin + tmax)
>>> ref_slice = count_spectrum.slice(tref)

and the y-values of the spline are compared with the direct product of the effective area and the input spectrum:

>>> _x = self.aeff.x
>>> _y = C*numpy.power(_x, -Gamma)*self.aeff.y

(Note that in general the two are technically not the same thing, as going from the count spectrum to the slice we do interpolate in time, although in this particular case the interpolation is trivial). If everything goes well, they should be on top of each other. The figure below is also showing the original power-law spectrum multiplied by the peak effective area.

../_images/test_power_law_stationary_slice.png
test_power_law_variable()[source]

Test a time-dependent power law.

This creates a time-dependent count spectrum, where the two parameters of the underlying power law (C and Gamma) vary linearly with time, in opposite direction, between 1 and 2.

>>> def C(t):
>>>     return 1. + (t - tmin)/(tmax - tmin)
>>>
>>> def Gamma(t):
>>>    return 2. - (t - tmin)/(tmax - tmin)
>>>
>>> def powerlaw(E, t):
>>>    return C(t)*numpy.power(E, -Gamma(t))

(Beware: this does not mean that you can interpolate linearly between the two time extremes, as both parameters vary at the same time and the spectral shape does not evolve linearly with time—we’re sampling the time axis with 100 points). The underlying xUnivariateAuxGenerator looks like.

../_images/test_power_law_variable_2d.png

Then a vertical slice (i.e., an interpolated linear spline) is taken in the middle of the auxiliary axis and the y-values of the spline are compared with the direct product of the effective area and the count spectrum (evaluated at the same time). If everything goes well, they should be on top of each other. The figure below is also showing the orignal power-law spectrum multiplied by the peak effective area.

../_images/test_power_law_variable_slice.png

Finally, we do test the light-curve building by comparing it with the values from a direct intergration of the vertical slices on a fixed-spacing grid. Note that, since the normalization increases with time and the spectral index becomes harder, the light-curve increases more than linearly.

../_images/test_power_law_variable_lc.png