files.new_contents: # Licensed under a 3-clause BSD style license - see LICENSE.rst
  """Fermi catalog and source classes."""
  import abc
  import warnings
  import numpy as np
  import astropy.units as u
  from astropy.table import Column, Table
  from astropy.time import Time
  from astropy.wcs import FITSFixedWarning
  from gammapy.estimators import FluxPoints, LightCurve
  from gammapy.modeling.models import (
      DiskSpatialModel,
      GaussianSpatialModel,
      Model,
      PointSpatialModel,
      SkyModel,
      TemplateSpatialModel,
  )
  from gammapy.utils.gauss import Gauss2DPDF
  from gammapy.utils.scripts import make_path
  from gammapy.utils.table import table_standardise_units_inplace
  from .core import SourceCatalog, SourceCatalogObject
  
  __all__ = [
      "SourceCatalogObject4FGL",
      "SourceCatalogObject3FGL",
      "SourceCatalogObject2FHL",
      "SourceCatalogObject3FHL",
      "SourceCatalog4FGL",
      "SourceCatalog3FGL",
      "SourceCatalog
  
  [... the rest is omitted ...]
files.new_path: gammapy/catalog/fermi.py
files.old_contents: # Licensed under a 3-clause BSD style license - see LICENSE.rst
  """Fermi catalog and source classes."""
  import abc
  import warnings
  import numpy as np
  import astropy.units as u
  from astropy.table import Column, Table
  from astropy.time import Time
  from astropy.wcs import FITSFixedWarning
  from gammapy.estimators import FluxPoints, LightCurve
  from gammapy.modeling.models import (
      DiskSpatialModel,
      GaussianSpatialModel,
      Model,
      PointSpatialModel,
      SkyModel,
      TemplateSpatialModel,
  )
  from gammapy.utils.gauss import Gauss2DPDF
  from gammapy.utils.scripts import make_path
  from gammapy.utils.table import table_standardise_units_inplace
  from .core import SourceCatalog, SourceCatalogObject
  
  __all__ = [
      "SourceCatalogObject4FGL",
      "SourceCatalogObject3FGL",
      "SourceCatalogObject2FHL",
      "SourceCatalogObject3FHL",
      "SourceCatalog4FGL",
      "SourceCatalog3FGL",
      "SourceCatalog
  
  [... the rest is omitted ...]
files.old_path: gammapy/catalog/fermi.py
files.new_contents: # Licensed under a 3-clause BSD style license - see LICENSE.rst
  import pytest
  import numpy as np
  from numpy.testing import assert_allclose
  from astropy import units as u
  from astropy.time import Time
  from astropy.utils.data import get_pkg_data_filename
  from gammapy.catalog import (
      SourceCatalog2FHL,
      SourceCatalog3FGL,
      SourceCatalog3FHL,
      SourceCatalog4FGL,
  )
  from gammapy.modeling.models import (
      ExpCutoffPowerLaw3FGLSpectralModel,
      LogParabolaSpectralModel,
      PowerLaw2SpectralModel,
      PowerLawSpectralModel,
      SuperExpCutoffPowerLaw3FGLSpectralModel,
      SuperExpCutoffPowerLaw4FGLSpectralModel,
  )
  from gammapy.utils.gauss import Gauss2DPDF
  from gammapy.utils.testing import (
      assert_quantity_allclose,
      assert_time_allclose,
      requires_data,
  )
  
  SOURCES_4FGL = [
      dict(
          idx=0,
          name="4FGL J0000.3-7355",
          str_ref
  
  [... the rest is omitted ...]
files.new_path: gammapy/catalog/tests/test_fermi.py
files.old_contents: # Licensed under a 3-clause BSD style license - see LICENSE.rst
  import pytest
  import numpy as np
  from numpy.testing import assert_allclose
  from astropy import units as u
  from astropy.time import Time
  from astropy.utils.data import get_pkg_data_filename
  from gammapy.catalog import (
      SourceCatalog2FHL,
      SourceCatalog3FGL,
      SourceCatalog3FHL,
      SourceCatalog4FGL,
  )
  from gammapy.modeling.models import (
      ExpCutoffPowerLaw3FGLSpectralModel,
      LogParabolaSpectralModel,
      PowerLaw2SpectralModel,
      PowerLawSpectralModel,
      SuperExpCutoffPowerLaw3FGLSpectralModel,
      SuperExpCutoffPowerLaw4FGLSpectralModel,
  )
  from gammapy.utils.gauss import Gauss2DPDF
  from gammapy.utils.testing import (
      assert_quantity_allclose,
      assert_time_allclose,
      requires_data,
  )
  
  SOURCES_4FGL = [
      dict(
          idx=0,
          name="4FGL J0000.3-7355",
          str_ref
  
  [... the rest is omitted ...]
files.old_path: gammapy/catalog/tests/test_fermi.py
files.new_contents: # Licensed under a 3-clause BSD style license - see LICENSE.rst
  import collections.abc
  import copy
  from os.path import split
  import numpy as np
  import astropy.units as u
  from astropy.table import Table
  import yaml
  from gammapy.modeling import Covariance, Parameter, Parameters
  from gammapy.utils.scripts import make_name, make_path
  
  
  def _set_link(shared_register, model):
      for param in model.parameters:
          name = param.name
          link_label = param._link_label_io
          if link_label is not None:
              if link_label in shared_register:
                  new_param = shared_register[link_label]
                  setattr(model, name, new_param)
              else:
                  shared_register[link_label] = param
      return shared_register
  
  
  __all__ = ["Model", "Models", "ProperModels"]
  
  
  class Model:
      """Model base class."""
  
      def __init__(self, **kwargs):
          # Copy default parameters from the class to the instance
          default_parameters = self.default_parameters.copy()
  
          for par in default_parameters:
              value = kwargs
  
  [... the rest is omitted ...]
files.new_path: gammapy/modeling/models/core.py
files.old_contents: # Licensed under a 3-clause BSD style license - see LICENSE.rst
  import collections.abc
  import copy
  from os.path import split
  import numpy as np
  import astropy.units as u
  from astropy.table import Table
  import yaml
  from gammapy.modeling import Covariance, Parameter, Parameters
  from gammapy.utils.scripts import make_name, make_path
  
  
  def _set_link(shared_register, model):
      for param in model.parameters:
          name = param.name
          link_label = param._link_label_io
          if link_label is not None:
              if link_label in shared_register:
                  new_param = shared_register[link_label]
                  setattr(model, name, new_param)
              else:
                  shared_register[link_label] = param
      return shared_register
  
  
  __all__ = ["Model", "Models", "ProperModels"]
  
  
  class Model:
      """Model base class."""
  
      def __init__(self, **kwargs):
          # Copy default parameters from the class to the instance
          default_parameters = self.default_parameters.copy()
  
          for par in default_parameters:
              value = kwargs
  
  [... the rest is omitted ...]
files.old_path: gammapy/modeling/models/core.py
files.new_contents: # Licensed under a 3-clause BSD style license - see LICENSE.rst
  """Spatial models."""
  import logging
  import numpy as np
  import scipy.integrate
  import scipy.special
  import astropy.units as u
  from astropy.coordinates import Angle, SkyCoord
  from astropy.coordinates.angle_utilities import angular_separation, position_angle
  from regions import (
      CircleAnnulusSkyRegion,
      EllipseSkyRegion,
      PointSkyRegion,
      PolygonSkyRegion,
  )
  from gammapy.maps import Map, WcsGeom
  from gammapy.modeling import Parameter, Parameters
  from gammapy.utils.gauss import Gauss2DPDF
  from gammapy.utils.scripts import make_path
  from .core import Model
  
  log = logging.getLogger(__name__)
  
  
  def compute_sigma_eff(lon_0, lat_0, lon, lat, phi, major_axis, e):
      """Effective radius, used for the evaluation of elongated models"""
      phi_0 = position_angle(lon_0, lat_0, lon, lat)
      d_phi = phi - phi_0
  
  
  [... the rest is omitted ...]
files.new_path: gammapy/modeling/models/spatial.py
files.old_contents: # Licensed under a 3-clause BSD style license - see LICENSE.rst
  """Spatial models."""
  import logging
  import numpy as np
  import scipy.integrate
  import scipy.special
  import astropy.units as u
  from astropy.coordinates import Angle, SkyCoord
  from astropy.coordinates.angle_utilities import angular_separation, position_angle
  from regions import (
      CircleAnnulusSkyRegion,
      EllipseSkyRegion,
      PointSkyRegion,
      PolygonSkyRegion,
  )
  from gammapy.maps import Map, WcsGeom
  from gammapy.modeling import Parameter, Parameters
  from gammapy.utils.gauss import Gauss2DPDF
  from gammapy.utils.scripts import make_path
  from .core import Model
  
  log = logging.getLogger(__name__)
  
  
  def compute_sigma_eff(lon_0, lat_0, lon, lat, phi, major_axis, e):
      """Effective radius, used for the evaluation of elongated models"""
      phi_0 = position_angle(lon_0, lat_0, lon, lat)
      d_phi = phi - phi_0
  
  
  [... the rest is omitted ...]
files.old_path: gammapy/modeling/models/spatial.py
files.new_contents: # Licensed under a 3-clause BSD style license - see LICENSE.rst
  """Spectral models for Gammapy."""
  import operator
  import numpy as np
  import scipy.optimize
  import scipy.special
  import astropy.units as u
  from astropy import constants as const
  from astropy.table import Table
  from gammapy.maps import MapAxis
  from gammapy.maps.utils import edges_from_lo_hi
  from gammapy.modeling import Covariance, Parameter, Parameters
  from gammapy.utils.integrate import evaluate_integral_pwl, trapz_loglog
  from gammapy.utils.interpolation import ScaledRegularGridInterpolator
  from gammapy.utils.scripts import make_path
  from .core import Model
  
  
  def integrate_spectrum(func, emin, emax, ndecade=100, intervals=False):
      """Integrate 1d function using the log-log trapezoidal rule.
  
      If scalar values for xmin and xmax are passed an oversampled grid is generated using the
      ``ndecade`` keyword argument. If xmin and xmax arrays are passed,
  
  [... the rest is omitted ...]
files.new_path: gammapy/modeling/models/spectral.py
files.old_contents: # Licensed under a 3-clause BSD style license - see LICENSE.rst
  """Spectral models for Gammapy."""
  import operator
  import numpy as np
  import scipy.optimize
  import scipy.special
  import astropy.units as u
  from astropy import constants as const
  from astropy.table import Table
  from gammapy.maps import MapAxis
  from gammapy.maps.utils import edges_from_lo_hi
  from gammapy.modeling import Covariance, Parameter, Parameters
  from gammapy.utils.integrate import evaluate_integral_pwl, trapz_loglog
  from gammapy.utils.interpolation import ScaledRegularGridInterpolator
  from gammapy.utils.scripts import make_path
  from .core import Model
  
  
  def integrate_spectrum(func, emin, emax, ndecade=100, intervals=False):
      """Integrate 1d function using the log-log trapezoidal rule.
  
      If scalar values for xmin and xmax are passed an oversampled grid is generated using the
      ``ndecade`` keyword argument. If xmin and xmax arrays are passed,
  
  [... the rest is omitted ...]
files.old_path: gammapy/modeling/models/spectral.py
files.new_contents: # Licensed under a 3-clause BSD style license - see LICENSE.rst
  import pytest
  from numpy.testing import assert_allclose
  import astropy.units as u
  from gammapy.modeling.models import Model, Parameter, Parameters
  from gammapy.datasets import Datasets
  from gammapy.utils.testing import requires_data
  
  
  class MyModel(Model):
      """Simple model example"""
  
      x = Parameter("x", 1, "cm")
      y = Parameter("y", 2)
  
  
  class CoModel(Model):
      """Compound model example"""
  
      norm = Parameter("norm", 42, "cm")
  
      def __init__(self, m1, m2, norm=norm.quantity):
          self.m1 = m1
          self.m2 = m2
          super().__init__(norm=norm)
  
      @property
      def parameters(self):
          return Parameters([self.norm]) + self.m1.parameters + self.m2.parameters
  
  
  class WrapperModel(Model):
      """Wrapper compound model.
  
      Dynamically generated parameters in `__init__`,
      and a parameter name conflict with the wrapped
      model, both have a parameter called "
  
  [... the rest is omitted ...]
files.new_path: gammapy/modeling/models/tests/test_core.py
files.old_contents: # Licensed under a 3-clause BSD style license - see LICENSE.rst
  import pytest
  from numpy.testing import assert_allclose
  import astropy.units as u
  from gammapy.modeling.models import Model, Parameter, Parameters
  from gammapy.datasets import Datasets
  from gammapy.utils.testing import requires_data
  
  
  class MyModel(Model):
      """Simple model example"""
  
      x = Parameter("x", 1, "cm")
      y = Parameter("y", 2)
  
  
  class CoModel(Model):
      """Compound model example"""
  
      norm = Parameter("norm", 42, "cm")
  
      def __init__(self, m1, m2, norm=norm.quantity):
          self.m1 = m1
          self.m2 = m2
          super().__init__(norm=norm)
  
      @property
      def parameters(self):
          return Parameters([self.norm]) + self.m1.parameters + self.m2.parameters
  
  
  class WrapperModel(Model):
      """Wrapper compound model.
  
      Dynamically generated parameters in `__init__`,
      and a parameter name conflict with the wrapped
      model, both have a parameter called "
  
  [... the rest is omitted ...]
files.old_path: gammapy/modeling/models/tests/test_core.py
files.new_contents: # Licensed under a 3-clause BSD style license - see LICENSE.rst
  import pytest
  import numpy as np
  from numpy.testing import assert_allclose
  import astropy.units as u
  from astropy.table import Table
  from astropy.utils.data import get_pkg_data_filename
  from gammapy.maps import Map, MapAxis
  from gammapy.modeling.models import (
      MODEL_REGISTRY,
      AbsorbedSpectralModel,
      Absorption,
      BackgroundModel,
      Model,
      Models,
  )
  from gammapy.utils.scripts import read_yaml, write_yaml
  from gammapy.utils.testing import requires_data
  
  
  @requires_data()
  def test_dict_to_skymodels():
      filename = get_pkg_data_filename("data/examples.yaml")
      models_data = read_yaml(filename)
      models = Models.from_dict(models_data)
  
      assert len(models) == 5
  
      model0 = models[0]
      assert isinstance(model0, BackgroundModel)
      assert model0.name == "background_irf"
  
      model0 = models[1]
      assert "ExpCutoffPowerLawSpectralModel" in model0.spect
  
  [... the rest is omitted ...]
files.new_path: gammapy/modeling/models/tests/test_io.py
files.old_contents: # Licensed under a 3-clause BSD style license - see LICENSE.rst
  import pytest
  import numpy as np
  from numpy.testing import assert_allclose
  import astropy.units as u
  from astropy.table import Table
  from astropy.utils.data import get_pkg_data_filename
  from gammapy.maps import Map, MapAxis
  from gammapy.modeling.models import (
      MODEL_REGISTRY,
      AbsorbedSpectralModel,
      Absorption,
      BackgroundModel,
      Model,
      Models,
  )
  from gammapy.utils.scripts import read_yaml, write_yaml
  from gammapy.utils.testing import requires_data
  
  
  @requires_data()
  def test_dict_to_skymodels():
      filename = get_pkg_data_filename("data/examples.yaml")
      models_data = read_yaml(filename)
      models = Models.from_dict(models_data)
  
      assert len(models) == 5
  
      model0 = models[0]
      assert isinstance(model0, BackgroundModel)
      assert model0.name == "background_irf"
  
      model0 = models[1]
      assert model0.spectral_model.tag == "ExpCutoffPowerLawS
  
  [... the rest is omitted ...]
files.old_path: gammapy/modeling/models/tests/test_io.py
files.new_contents: # Licensed under a 3-clause BSD style license - see LICENSE.rst
  __all__ = ["Registry"]
  
  
  class Registry(list):
      """Registry class."""
  
      def get_cls(self, tag):
          for cls in self:
              if hasattr(cls, "tag") and tag in cls.tag:
                  return cls
          raise KeyError(f"No model found with tag: {tag!r}")
  
      def __str__(self):
          info = "Registry\n"
          info += "--------\n\n"
          tags = [_.tag[0] if isinstance(_.tag, list) else _.tag for _ in self]
          len_max = max([len(tag) for tag in tags])
  
          for item in self:
              info += f"\t{item.tag:{len_max}s}: {item.__name__}\n"
  
          return info.expandtabs(tabsize=2)
  
  
  [... the rest is omitted ...]
files.new_path: gammapy/utils/registry.py
files.old_contents: # Licensed under a 3-clause BSD style license - see LICENSE.rst
  
  __all__ = ["Registry"]
  
  
  class Registry(list):
      """Registry class."""
  
      def get_cls(self, tag):
          for cls in self:
              if hasattr(cls, "tag") and cls.tag == tag:
                  return cls
          raise KeyError(f"No model found with tag: {tag!r}")
  
      def __str__(self):
          info = "Registry\n"
          info += "--------\n\n"
  
          len_max = max([len(_.tag) for _ in self])
  
          for item in self:
              info += f"\t{item.tag:{len_max}s}: {item.__name__}\n"
  
          return info.expandtabs(tabsize=2)
  
  
  [... the rest is omitted ...]
files.old_path: gammapy/utils/registry.py