Exemplo n.º 1
0
    def from_dispersion_spectrum(cls,
                                 dispersion_spectrum,
                                 file_type='observed'):
        # type: (BinnedSpectrumWithDispersion, str) -> PHASpectrum

        if dispersion_spectrum.is_poisson:

            rate_errors = None

        else:

            rate_errors = dispersion_spectrum.rate_errors

        pha = PHAII(instrument_name=dispersion_spectrum.instrument,
                    telescope_name=dispersion_spectrum.mission,
                    tstart=dispersion_spectrum.tstart,
                    telapse=dispersion_spectrum.tstop -
                    dispersion_spectrum.tstart,
                    channel=list(range(1,
                                       len(dispersion_spectrum) + 1)),
                    rate=dispersion_spectrum.rates,
                    stat_err=rate_errors,
                    quality=dispersion_spectrum.quality.to_ogip(),
                    grouping=np.ones(len(dispersion_spectrum)),
                    exposure=dispersion_spectrum.exposure,
                    backscale=dispersion_spectrum.scale_factor,
                    respfile=None,
                    ancrfile=None,
                    is_poisson=dispersion_spectrum.is_poisson)

        return cls(pha_file_or_instance=pha,
                   spectrum_number=1,
                   file_type=file_type,
                   rsp_file=dispersion_spectrum.response)
Exemplo n.º 2
0
    def clone(
        self,
        new_counts=None,
        new_count_errors=None,
    ):
        """
        make a new spectrum with new counts and errors and all other
        parameters the same


        :param new_counts: new counts for the spectrum
        :param new_count_errors: new errors from the spectrum
        :return: new pha spectrum
        """

        if new_counts is None:
            new_counts = self.counts
            new_count_errors = self.count_errors

        if new_count_errors is None:
            stat_err = None

        else:

            stat_err = old_div(new_count_errors, self.exposure)

        # create a new PHAII instance

        pha = PHAII(
            instrument_name=self.instrument,
            telescope_name=self.mission,
            tstart=0,
            telapse=self.exposure,
            channel=list(range(1,
                               len(self) + 1)),
            rate=old_div(new_counts, self.exposure),
            stat_err=stat_err,
            quality=self.quality.to_ogip(),
            grouping=self.grouping,
            exposure=self.exposure,
            backscale=self.scale_factor,
            respfile=None,
            ancrfile=None,
            is_poisson=self.is_poisson,
        )

        return pha
Exemplo n.º 3
0
    def from_dispersion_spectrum(cls,
                                 dispersion_spectrum,
                                 file_type="observed",
                                 response=None):
        # type: (BinnedSpectrumWithDispersion, str) -> PHASpectrum

        if dispersion_spectrum.is_poisson:

            rate_errors = None

        else:

            rate_errors = dispersion_spectrum.rate_errors

        if dispersion_spectrum.tstart is None:

            tstart = 0

        else:

            tstart = dispersion_spectrum.tstart

        if dispersion_spectrum.tstop is None:

            telapse = dispersion_spectrum.exposure

        else:

            telapse = dispersion_spectrum.tstop - tstart

        pha = PHAII(
            instrument_name=dispersion_spectrum.instrument,
            telescope_name=dispersion_spectrum.mission,
            tstart=tstart,  # TODO: add this in so that we have proper time!
            telapse=telapse,
            channel=list(range(1,
                               len(dispersion_spectrum) + 1)),
            rate=dispersion_spectrum.rates,
            stat_err=rate_errors,
            quality=dispersion_spectrum.quality.to_ogip(),
            grouping=np.ones(len(dispersion_spectrum)),
            exposure=dispersion_spectrum.exposure,
            backscale=dispersion_spectrum.scale_factor,
            respfile=None,
            ancrfile=None,
            is_poisson=dispersion_spectrum.is_poisson,
        )

        if file_type == "background":

            if response is None:

                log.error(
                    "passed a background file but no response to extract energy spectra."
                )

                raise AssertionError()

        else:

            response = dispersion_spectrum.response

        return cls(pha_file_or_instance=pha,
                   spectrum_number=1,
                   file_type=file_type,
                   rsp_file=response)
Exemplo n.º 4
0
    def clone(self,
              new_counts=None,
              new_count_errors=None,
              new_exposure=None,
              new_scale_factor=None):
        """
        make a new spectrum with new counts and errors and all other
        parameters the same


        :param new_exposure: the new exposure for the clone
        :param new_scale_factor: the new scale factor for the clone

        :param new_counts: new counts for the spectrum
        :param new_count_errors: new errors from the spectrum
        :return: new pha spectrum
        """

        if new_exposure is None:

            new_exposure = self.exposure

        if new_counts is None:
            new_counts = self.counts
            new_count_errors = self.count_errors

        if new_count_errors is None:
            stat_err = None

        else:

            stat_err = new_count_errors / new_exposure

        if self._tstart is None:

            tstart = 0

        else:

            tstart = self._tstart

        if self._tstop is None:

            telapse = new_exposure

        else:

            telapse = self._tstop - tstart

        if new_scale_factor is None:

            new_scale_factor = self.scale_factor

        # create a new PHAII instance

        pha = PHAII(instrument_name=self.instrument,
                    telescope_name=self.mission,
                    tstart=tstart,
                    telapse=telapse,
                    channel=range(1,
                                  len(self) + 1),
                    rate=new_counts / self.exposure,
                    stat_err=stat_err,
                    quality=self.quality.to_ogip(),
                    grouping=self.grouping,
                    exposure=new_exposure,
                    backscale=new_scale_factor,
                    respfile=None,
                    ancrfile=None,
                    is_poisson=self.is_poisson)

        return pha