<commit_before>from threeML.plugins.OGIPLike import OGIPLike

__instrument_name = "Swift XRT"


# At the moment this is just another name for the GenericOGIPLike spectrum
class SwiftXRTLike(OGIPLike):

    def _get_diff_flux_and_integral(self):

        # In the XRT response matrix there are many many channels, so we can
        # use a very crude formula for the integral. This is why we override this

        nPointSources = self.likelihoodModel.get_number_of_point_sources()

        def diffFlux(energies):
            fluxes = self.likelihoodModel.get_point_source_fluxes(0, energies)

            # If we have only one point source, this will never be executed
            for i in range(1, nPointSources):
                fluxes += self.likelihoodModel.get_point_source_fluxes(i, energies)

            return fluxes

        # The following integrates the diffFlux function using Simpson's rule
        # This assume that the intervals e1,e2 are all small, which is guaranteed
        # for any reasonable response matrix, given that e1 and e2 are Monte-Carlo
        # energies. It also assumes that the function is smooth in the interval
        # e1 - e2 and twice-differentiable, again reasonable on small intervals for
        # decent models. It might fail for models with too sharp features, smaller
        # than the size of the monte carlo interval.

        def integral(e1, e2):

            avg = (e2 + e1) / 2.0

            return diffFlux(avg) * (e2 - e1)

        return diffFlux, integral<commit_msg>Corrected the integral computation to reflect the new class design<commit_after>from threeML.plugins.OGIPLike import OGIPLike

__instrument_name = "Swift XRT"


# At the moment this is just another name for the GenericOGIPLike spectrum
class SwiftXRTLike(OGIPLike):

    def _get_diff_flux_and_integral(self):

        # In the XRT response matrix there are many many channels, so we can
        # use a very crude formula for the integral. This is why we override this

        n_point_sources = self._like_model.get_number_of_point_sources()

        # Make a function which will stack all point sources (OGIP do not support spatial dimension)

        def differential_flux(energies):

            fluxes = self._like_model.get_point_source_fluxes(0, energies)

            # If we have only one point source, this will never be executed
            for i in range(1, n_point_sources):
                fluxes += self._like_model.get_point_source_fluxes(i, energies)

            return fluxes

        # The following integrates the diffFlux function using Simpson's rule
        # This assume that the intervals e1,e2 are all small, which is guaranteed
        # for any reasonable response matrix, given that e1 and e2 are Monte-Carlo
        # energies. It also assumes that the function is smooth in the interval
        # e1 - e2 and twice-differentiable, again reasonable on small intervals for
        # decent models. It might fail for models with too sharp features, smaller
        # than the size of the monte carlo interval.

        def integral(e1, e2):

            avg = (e2 + e1) / 2.0

            return differential_flux(avg) * (e2 - e1)

        return differential_flux, integral
{'fraction_non_alphanumeric': 0.051654809774203524, 'fraction_numerical': 0.009897927621404269, 'mean_word_length': 2.725806451612903, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4603363', 'n_tokens_mistral': 904, 'n_tokens_neox': 843, 'n_words': 359}