def from_general_dispersion_spectrum(cls, dispersion_like): # type: (DispersionSpectrumLike) -> OGIPLike """ Build on OGIPLike from a dispersion like. This makes it easy to write a dispersion like to a pha file :param dispersion_like: :return: """ pha_files = dispersion_like.get_pha_files() observed = pha_files["pha"] background = pha_files["bak"] observed_pha = PHASpectrum.from_dispersion_spectrum( observed, file_type="observed") if background is None: background_pha = None else: background_pha = PHASpectrum.from_dispersion_spectrum( background, file_type="background") return cls( dispersion_like.name, observation=observed_pha, background=background_pha, verbose=False, )
def test_loading_bad_keywords_file(): with within_directory(__example_dir): pha_fn = "example_integral_spi.pha" rsp_fn = "example_integral_spi.rsp" pha_spectrum = PHASpectrum(pha_fn, rsp_file=rsp_fn) assert type(pha_spectrum.is_poisson) == bool ogip = OGIPLike("test_ogip", observation=pha_fn, response=rsp_fn) ogip.__repr__()
def from_general_dispersion_spectrum(cls, dispersion_like): # type: (DispersionSpectrumLike) -> OGIPLike """ Build on OGIPLike from a dispersion like. This makes it easy to write a dispersion like to a pha file :param dispersion_like: :return: """ pha_files = dispersion_like.get_pha_files() observed = pha_files['pha'] background = pha_files['bak'] observed_pha = PHASpectrum.from_dispersion_spectrum(observed, file_type='observed') if background is None: background_pha = None else: background_pha = PHASpectrum.from_dispersion_spectrum(background, file_type='background') return cls(dispersion_like.name, observation=observed_pha, background=background_pha, verbose=False)
def __init__( self, name, observation, background=None, response=None, arf_file=None, spectrum_number=None, verbose=True, ): assert is_valid_variable_name(name), ( "Name %s is not a valid name for a plugin. You must use a name which is " "a valid python identifier: no spaces, no operators (+,-,/,*), " "it cannot start with a number, no special characters" % name) # Read the pha file (or the PHAContainer instance) assert (isinstance(observation, str) or isinstance(observation, PHASpectrum) or isinstance(observation, PHAII) ), "observation must be a FITS file name or PHASpectrum" assert ( isinstance(background, str) or isinstance(background, PHASpectrum) or (background is None) or isinstance(background, PHAII) or isinstance(background, SpectrumLike) or isinstance(background, XYLike) ), "background must be a FITS file name, PHASpectrum, a Plugin or None" if isinstance(observation, str) or isinstance(observation, PHAII): pha = PHASpectrum( observation, spectrum_number=spectrum_number, file_type="observed", rsp_file=response, arf_file=arf_file, ) else: pha = observation # Get the required background file, response and (if present) arf_file either from the # calling sequence or the file. # NOTE: if one of the file is specified in the calling sequence, it will be used whether or not there is an # equivalent specification in the header. This allows the user to override the content of the header of the # PHA file, if needed if background is None: background = pha.background_file # assert background is not None, "No background file provided, and the PHA file does not specify one." # Get a PHA instance with the background, we pass the response to get the energy bounds in the # histogram constructor. It is not saved to the background class if background is None: # in the case there is no background file bak = None elif isinstance(background, str) or isinstance(observation, PHAII): bak = PHASpectrum( background, spectrum_number=spectrum_number, file_type="background", rsp_file=pha.response, ) else: bak = background # we do not need to pass the response as it is contained in the observation (pha) spectrum # already. super(OGIPLike, self).__init__(name=name, observation=pha, background=bak, verbose=verbose)