def find_energy(self, aeff, emin=None, emax=None): """Find energy for a given effective area. In case the solution is not unique, provide the `emin` or `emax` arguments to limit the solution to the given range. By default the peak energy of the effective area is chosen as `emax`. Parameters ---------- aeff : `~astropy.units.Quantity` Effective area value emin : `~astropy.units.Quantity` Lower bracket value in case solution is not unique. emax : `~astropy.units.Quantity` Upper bracket value in case solution is not unique. Returns ------- energy : `~astropy.units.Quantity` Energy corresponding to the given aeff. """ from gammapy.modeling.models import TemplateSpectralModel energy = self.energy.center if emin is None: emin = energy[0] if emax is None: # use the peak effective area as a default for the energy maximum emax = energy[np.argmax(self.data.data)] aeff_spectrum = TemplateSpectralModel(energy, self.data.data) return aeff_spectrum.inverse(aeff, emin=emin, emax=emax)
def get_bias_energy(self, bias, energy_min=None, energy_max=None): """Find energy corresponding to a given bias. In case the solution is not unique, provide the ``energy_min`` or ``energy_max`` arguments to limit the solution to the given range. By default the peak energy of the bias is chosen as ``energy_min``. Parameters ---------- bias : float Bias value. energy_min : `~astropy.units.Quantity` Lower bracket value in case solution is not unique. energy_max : `~astropy.units.Quantity` Upper bracket value in case solution is not unique. Returns ------- bias_energy : `~astropy.units.Quantity` Reconstructed energy corresponding to the given bias. """ from gammapy.modeling.models import TemplateSpectralModel energy_true = self.axes["energy_true"].center values = self.get_bias(energy_true) if energy_min is None: # use the peak bias energy as default minimum energy_min = energy_true[np.nanargmax(values)] if energy_max is None: energy_max = energy_true[-1] bias_spectrum = TemplateSpectralModel(energy=energy_true, values=values) energy_true_bias = bias_spectrum.inverse(Quantity(bias), energy_min=energy_min, energy_max=energy_max) if np.isnan(energy_true_bias[0]): energy_true_bias[0] = energy_min # return reconstructed energy return energy_true_bias * (1 + bias)