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:
      """
  
  [... 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:
      """
  
  [... 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
  """Cube models (axes: lon, lat, energy)."""
  import copy
  from pathlib import Path
  import numpy as np
  import astropy.units as u
  from gammapy.maps import Map, MapAxis, RegionGeom, WcsGeom
  from gammapy.modeling import Covariance, Parameter, Parameters
  from gammapy.modeling.parameter import _get_parameters_str
  from gammapy.utils.scripts import make_name, make_path
  from gammapy.utils.fits import LazyFitsData, HDULocation
  from .core import Model, Models
  from .spatial import SpatialModel
  from .spectral import SpectralModel, PowerLawNormSpectralModel
  from .temporal import TemporalModel
  
  
  class SkyModelBase(Model):
      """Sky model base class"""
  
      def __add__(self, other
  
  [... the rest is omitted ...]
files.new_path: gammapy/modeling/models/cube.py
files.old_contents: # Licensed under a 3-clause BSD style license - see LICENSE.rst
  """Cube models (axes: lon, lat, energy)."""
  import copy
  from pathlib import Path
  import numpy as np
  import astropy.units as u
  from gammapy.maps import Map, MapAxis, RegionGeom, WcsGeom
  from gammapy.modeling import Covariance, Parameter, Parameters
  from gammapy.modeling.parameter import _get_parameters_str
  from gammapy.utils.scripts import make_name, make_path
  from gammapy.utils.fits import LazyFitsData, HDULocation
  from .core import Model, Models
  from .spatial import SpatialModel
  from .spectral import SpectralModel, PowerLawNormSpectralModel
  from .temporal import TemporalModel
  
  
  class SkyModelBase(Model):
      """Sky model base class"""
  
      def __add__(self, other
  
  [... the rest is omitted ...]
files.old_path: gammapy/modeling/models/cube.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.utils import lazyproperty
  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
  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
  
  [... 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.utils import lazyproperty
  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
  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
  
  [... 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 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
  
  [... 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 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
  
  [... 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
  """Time-dependent models."""
  import numpy as np
  import scipy.interpolate
  from astropy import units as u
  from astropy.table import Table
  from astropy.time import Time
  from astropy.utils import lazyproperty
  from gammapy.modeling import Parameter
  from gammapy.utils.random import InverseCDFSampler, get_random_state
  from gammapy.utils.scripts import make_path
  from gammapy.utils.time import time_ref_from_dict
  from .core import Model
  
  
  # TODO: make this a small ABC to define a uniform interface.
  class TemporalModel(Model):
      """Temporal model base class.
      evaluates on  astropy.time.Time objects"""
  
      _type = "temporal"
  
      def __call__(self, time):
          """Evaluate model
  
          Parameters
          ----------
          time : `~astropy.time.Time`
             
  
  [... the rest is omitted ...]
files.new_path: gammapy/modeling/models/temporal.py
files.old_contents: # Licensed under a 3-clause BSD style license - see LICENSE.rst
  """Time-dependent models."""
  import numpy as np
  import scipy.interpolate
  from astropy import units as u
  from astropy.table import Table
  from astropy.time import Time
  from astropy.utils import lazyproperty
  from gammapy.modeling import Parameter
  from gammapy.utils.random import InverseCDFSampler, get_random_state
  from gammapy.utils.scripts import make_path
  from gammapy.utils.time import time_ref_from_dict
  from .core import Model
  
  
  # TODO: make this a small ABC to define a uniform interface.
  class TemporalModel(Model):
      """Temporal model base class.
      evaluates on  astropy.time.Time objects"""
      _type = "temporal"
  
      def __call__(self, time):
          """Evaluate model
  
          Parameters
          ----------
          time : `~astropy.time.Time`
             
  
  [... the rest is omitted ...]
files.old_path: gammapy/modeling/models/temporal.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.
  
  [... 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.
  
  [... 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.time import Time
  from gammapy.data.gti import GTI
  from gammapy.datasets.map import MapEvaluator
  from gammapy.irf import EDispKernel, PSFKernel
  from gammapy.maps import Map, MapAxis, WcsGeom
  from gammapy.modeling.models import (
      BackgroundModel,
      ConstantSpectralModel,
      ConstantTemporalModel,
      GaussianSpatialModel,
      Models,
      PointSpatialModel,
      PowerLawSpectralModel,
      PowerLawNormSpectralModel,
      TemplateSpatialModel,
      CompoundSpectralModel,
      SkyModel,
      create_fermi_isotropic_diffuse_model,
  )
  from
  
  [... the rest is omitted ...]
files.new_path: gammapy/modeling/models/tests/test_cube.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.time import Time
  from gammapy.data.gti import GTI
  from gammapy.datasets.map import MapEvaluator
  from gammapy.irf import EDispKernel, PSFKernel
  from gammapy.maps import Map, MapAxis, WcsGeom
  from gammapy.modeling.models import (
      BackgroundModel,
      ConstantSpectralModel,
      ConstantTemporalModel,
      GaussianSpatialModel,
      Models,
      PointSpatialModel,
      PowerLawSpectralModel,
      PowerLawNormSpectralModel,
      TemplateSpatialModel,
      CompoundSpectralModel,
      SkyModel,
      create_fermi_isotropic_diffuse_model,
  )
  from
  
  [... the rest is omitted ...]
files.old_path: gammapy/modeling/models/tests/test_cube.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,
      PowerLawSpectralModel,
      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) ==
  
  [... 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 =
  
  [... 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
  import pytest
  import numpy as np
  import operator
  from numpy.testing import assert_allclose
  import astropy.units as u
  from gammapy.maps import MapAxis
  from gammapy.modeling.models import (
      SPECTRAL_MODEL_REGISTRY,
      AbsorbedSpectralModel,
      Absorption,
      ConstantSpectralModel,
      CompoundSpectralModel,
      ExpCutoffPowerLaw3FGLSpectralModel,
      ExpCutoffPowerLawSpectralModel,
      ExpCutoffPowerLawNormSpectralModel,
      GaussianSpectralModel,
      LogParabolaSpectralModel,
      LogParabolaNormSpectralModel,
      NaimaSpectralModel,
      PowerLaw2SpectralModel,
      PowerLawSpectralModel,
      PowerLawNormSpectralModel,
      BrokenPowerLawSpectralModel,
      SmoothBroken
  
  [... the rest is omitted ...]
files.new_path: gammapy/modeling/models/tests/test_spectral.py
files.old_contents: # Licensed under a 3-clause BSD style license - see LICENSE.rst
  import pytest
  import numpy as np
  import operator
  from numpy.testing import assert_allclose
  import astropy.units as u
  from gammapy.maps import MapAxis
  from gammapy.modeling.models import (
      SPECTRAL_MODEL_REGISTRY,
      AbsorbedSpectralModel,
      Absorption,
      ConstantSpectralModel,
      CompoundSpectralModel,
      ExpCutoffPowerLaw3FGLSpectralModel,
      ExpCutoffPowerLawSpectralModel,
      ExpCutoffPowerLawNormSpectralModel,
      GaussianSpectralModel,
      LogParabolaSpectralModel,
      LogParabolaNormSpectralModel,
      NaimaSpectralModel,
      PowerLaw2SpectralModel,
      PowerLawSpectralModel,
      PowerLawNormSpectralModel,
      BrokenPowerLawSpectralModel,
      SmoothBroken
  
  [... the rest is omitted ...]
files.old_path: gammapy/modeling/models/tests/test_spectral.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.table import Table
  from astropy.time import Time
  from gammapy.data.gti import GTI
  from gammapy.modeling.models import (
      ConstantTemporalModel,
      ExpDecayTemporalModel,
      GaussianTemporalModel,
      LightCurveTemplateTemporalModel,
      PowerLawSpectralModel,
      SkyModel,
  )
  from gammapy.utils.scripts import make_path
  from gammapy.utils.testing import requires_data, requires_dependency, mpl_plot_check
  
  
  # TODO: add light-curve test case from scratch
  # only use the FITS one for I/O (or not at all)
  @pytest.fixture(scope="session")
  def light_curve():
      path = "$
  
  [... the rest is omitted ...]
files.new_path: gammapy/modeling/models/tests/test_temporal.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.table import Table
  from astropy.time import Time
  from gammapy.data.gti import GTI
  from gammapy.modeling.models import (
      ConstantTemporalModel,
      ExpDecayTemporalModel,
      GaussianTemporalModel,
      LightCurveTemplateTemporalModel,
      PowerLawSpectralModel,
      SkyModel,
  )
  from gammapy.utils.scripts import make_path
  from gammapy.utils.testing import requires_data, requires_dependency, mpl_plot_check
  
  
  # TODO: add light-curve test case from scratch
  # only use the FITS one for I/O (or not at all)
  @pytest.fixture(scope="session")
  def light_curve():
      path = "$
  
  [... the rest is omitted ...]
files.old_path: gammapy/modeling/models/tests/test_temporal.py