Example #1
0
File: mrf.py Project: pabell/ximpol
 def __init__(self):
     """Constructor.
     """
     _visibility = numpy.linspace(0., 1., 100)
     _phi = numpy.linspace(0., 2*numpy.pi, 100)
     fmt = dict(auxname='$\\xi$', rvname='$\\phi$', rvunits='rad')
     xUnivariateAuxGenerator.__init__(self, _visibility, _phi, self.pdf,
                                      **fmt)
Example #2
0
 def __init__(self):
     """Constructor.
     """
     _visibility = numpy.linspace(0., 1., 100)
     _phi = numpy.linspace(0., 2*numpy.pi, 100)
     fmt = dict(auxname='$\\xi$', rvname='$\\phi$', rvunits='rad')
     xUnivariateAuxGenerator.__init__(self, _visibility, _phi, self.pdf,
                                      **fmt)
Example #3
0
    def __init__(self, source_spectrum, aeff, t):
        """Constructor.
        """
        fmt = dict(auxname='Time', auxunits='s', rvname='Energy',
                   rvunits='keV',  pdfname='dN/dE $\\times$ aeff',
                   pdfunits='s$^{-1}$ keV$^{-1}$')

        def _pdf(E, t):
            """Return the convolution between the effective area and
            the input photon spectrum.
            """
            return source_spectrum(E, t)*numpy.tile(aeff(E[0]), (t.shape[0], 1))

        xUnivariateAuxGenerator.__init__(self, t, aeff.x, _pdf, **fmt)
        self.light_curve = self.build_light_curve()
Example #4
0
File: rmf.py Project: pabell/ximpol
 def __init__(self, hdu, num_aux_points=200):
     """Constructor.
     """
     # First build a bivariate spline with the full data grid.
     _matrix = hdu.data
     _x = 0.5*(_matrix['ENERG_LO'] + _matrix['ENERG_HI'])
     _y = numpy.arange(0, len(_matrix['MATRIX'][0]), 1) - 0.5
     _z = _matrix['MATRIX']
     _pdf = xInterpolatedBivariateSplineLinear(_y, _x, _z.transpose())
     # Then initialize the actual xUnivariateAuxGenerator object
     # with a down-sampled aux axis.
     _aux = numpy.linspace(_pdf.ymin(), _pdf.ymax(), num_aux_points)
     _rv = _y
     fmt = dict(auxname='Energy', auxunits='keV', rvname='Channel',
                pdfname='Probability density')
     xUnivariateAuxGenerator.__init__(self, _aux, _rv, _pdf, **fmt)
Example #5
0
File: rmf.py Project: pabell/ximpol
 def __init__(self, hdu, num_aux_points=200):
     """Constructor.
     """
     # First build a bivariate spline with the full data grid.
     _matrix = hdu.data
     _x = 0.5 * (_matrix['ENERG_LO'] + _matrix['ENERG_HI'])
     _y = numpy.arange(0, len(_matrix['MATRIX'][0]), 1) - 0.5
     _z = _matrix['MATRIX']
     _pdf = xInterpolatedBivariateSplineLinear(_y, _x, _z.transpose())
     # Then initialize the actual xUnivariateAuxGenerator object
     # with a down-sampled aux axis.
     _aux = numpy.linspace(_pdf.ymin(), _pdf.ymax(), num_aux_points)
     _rv = _y
     fmt = dict(auxname='Energy',
                auxunits='keV',
                rvname='Channel',
                pdfname='Probability density')
     xUnivariateAuxGenerator.__init__(self, _aux, _rv, _pdf, **fmt)
Example #6
0
    def __init__(self, source_spectrum, aeff, t, scale=1.):
        """Constructor.

        Warning
        -------
        Do we really want the option to pass a scale here?
        This was a workaround for running the MDP script on a pulsar,
        where we sample in phase and then have to multiply by the
        number of periods.
        """
        fmt = dict(auxname='Time', auxunits='s', rvname='Energy',
                   rvunits='keV',  pdfname='dN/dE $\\times$ aeff',
                   pdfunits='s$^{-1}$ keV$^{-1}$')

        def _pdf(E, t):
            """Return the convolution between the effective area and
            the input photon spectrum.
            """
            return scale*source_spectrum(E, t)*numpy.tile(aeff(E[0]), (t.shape[0], 1))

        xUnivariateAuxGenerator.__init__(self, t, aeff.x, _pdf, **fmt)
        self.light_curve = self.build_light_curve()
Example #7
0
    def __init__(self, source_spectrum, aeff, t, column_density=0.,
                 redshift=0., scale_factor=1.):
        """Constructor.

        Arguments
        ---------
        source_spectrum : a Python function
            The source spectrum, i.e., a Python function that can be called
            with two numpy arrays E and t and returns the differential energy
            spectrum of the source at the appropriate enenrgy and time value(s).

        aeff : ximpol.irf.xEffectiveArea instance
            The instrument effective area.
        
        t : array
            The array of time values where we're sampling the light curve of the
            source.

        column_density : float, defaults to 0.
            The H column density to calculate the insterstellar absorption.

        redshift : float, defaults to 0.
            The source redshift.

        scale_factor : float, defaults to 1.
            An optional scale factor for the output count spectrum (see the
            warning below).

        Warning
        -------
        This was a workaround for running the MDP script on a pulsar,
        where we sample in phase and then have to multiply by the
        observation time.
        """

        def _pdf(E, t):
            """Return the convolution between the effective area and
            the input photon spectrum.

            Note that, due the way this callable is used within the constructor
            of xUnivariateAuxGenerator at this point E and t are two numpy
            arrays whose shape is `(num_time_samples, num_energy_samples)`.
            Particularly, `E[0]` is the array of energy values that we use for
            sampling the spectrum (nominally the same sampling that we use
            for the effective area).

            We start from all the stuff that is energy-independent, e.g., the
            effective area and the interstellar absorption and do the proper
            convolutions in energy space. Then we tile the values horizontally
            for as many times as the length of the array sampling the time,
            and at the end we multiply the resulting bidimensional array by
            an equal-size array containing the value of the differential
            energy spectrum on the time-energy grid.
            """
            # Grab the one-dimensional array used to sample the energy.
            _energy = E[0]
            # Calculate the effective area on the array.
            _vals = aeff(_energy)
            # Multiply by the scale factor.
            _vals *= scale_factor
            # If needed, fold in the transmission factor for the interstellar
            # absorption.
            if column_density > 0.:
                logger.info('Applying interstellar absorption (nH = %.3e)' %\
                            column_density)
                ism_model = xpeInterstellarAbsorptionModel()
                ism_trans = ism_model.transmission_factor(column_density)
                _vals *= ism_trans(_energy)
            # Tile the one dimensional vector horizontally.
            _vals = numpy.tile(_vals, (t.shape[0], 1))
            # And multiply by the source spectrum---we're done.
            _vals *= source_spectrum(E*(1 + redshift), t)
            return _vals

        self.scale_factor = scale_factor
        fmt = dict(auxname='Time', auxunits='s', rvname='Energy',
                   rvunits='keV',  pdfname='dN/dE $\\times$ aeff',
                   pdfunits='s$^{-1}$ keV$^{-1}$')
        xUnivariateAuxGenerator.__init__(self, t, aeff.x, _pdf, **fmt)
        self.light_curve = self.build_light_curve()