Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (gammapy-dev) hfm-1804a:gammapy deil$ pytest --lf
- ========================================================================== test session starts ===========================================================================
- platform darwin -- Python 3.7.0, pytest-5.0.1, py-1.8.0, pluggy-0.12.0
- rootdir: /Users/deil/work/code/gammapy, inifile: setup.cfg
- plugins: xdist-1.29.0, arraydiff-0.3, forked-1.0.2, asdf-2.4.0.dev63+gb67cb02, openfiles-0.4.0, doctestplus-0.3.0, remotedata-0.3.1, cov-2.7.1
- collecting ...
- Gammapy test data availability:
- gammapy-data ... yes
- Gammapy environment variables:
- GAMMAPY_DATA = /Users/deil/work/gammapy-tutorials/datasets
- Setting matplotlib backend to "agg" for the tests.
- collected 4 items / 3 deselected / 1 selected
- run-last-failure: rerun previous 1 failure (skipped 5752 files)
- gammapy/modeling/tests/test_serialize_yaml.py F [100%]
- ================================================================================ FAILURES ================================================================================
- __________________________________________________________________________ test_datasets_to_io ___________________________________________________________________________
- self = <gammapy.cube.fit.MapEvaluator object at 0x117dc0b70>
- exposure = WcsNDMap
- geom : WcsGeom
- axes : ['lon', 'lat', 'energy']
- shape : (10, 10, 3)
- ndim : 3
- unit : m2 s
- dtype : >f4
- psf = <gammapy.cube.psf_kernel.PSFKernel object at 0x117efdd30>, edisp = <gammapy.irf.energy_dispersion.EnergyDispersion object at 0x117f0c9b0>
- geom = WcsGeom
- axes : ['lon', 'lat', 'energy']
- shape : (10, 10, 3)
- ndim : 3
- coordsys : GAL
- projection : CAR
- center : 0.0 deg, 0.0 deg
- width : 1.0 deg x 1.0 deg
- def update(self, exposure, psf, edisp, geom):
- """Update MapEvaluator, based on the current position of the model component.
- Parameters
- ----------
- exposure : `~gammapy.maps.Map`
- Exposure map.
- psf : `gammapy.cube.PSFMap`
- PSF map.
- edisp : `gammapy.cube.EDispMap`
- Edisp map.
- geom : `gammapy.maps.MapGeom`
- Reference geometry of the data.
- """
- log.debug("Updating model evaluator")
- # cache current position of the model component
- # TODO: lookup correct Edisp for this component
- self.edisp = edisp
- # TODO: lookup correct PSF for this component
- self.psf = psf
- if self.evaluation_mode == "local" and self.model.evaluation_radius is not None:
- self._init_position = self.model.position
- if psf is not None:
- psf_width = np.max(psf.psf_kernel_map.geom.width)
- else:
- psf_width = 0 * u.deg
- width = psf_width + 2 * (self.model.evaluation_radius + CUTOUT_MARGIN)
- try:
- self.exposure = exposure.cutout(
- > position=self.model.position, width=width
- )
- gammapy/cube/fit.py:773:
- _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
- self = WcsNDMap
- geom : WcsGeom
- axes : ['lon', 'lat', 'energy']
- shape : (10, 10, 3)
- ndim : 3
- unit : m2 s
- dtype : >f4
- position = <SkyCoord (ICRS): (ra, dec) in deg
- (0., 0.)>, width = (0.7, 0.7), mode = 'trim'
- def cutout(self, position, width, mode="trim"):
- """
- Create a cutout around a given position.
- Parameters
- ----------
- position : `~astropy.coordinates.SkyCoord`
- Center position of the cutout region.
- width : tuple of `~astropy.coordinates.Angle`
- Angular sizes of the region in (lon, lat) in that specific order.
- If only one value is passed, a square region is extracted.
- mode : {'trim', 'partial', 'strict'}
- Mode option for Cutout2D, for details see `~astropy.nddata.utils.Cutout2D`.
- Returns
- -------
- cutout : `~gammapy.maps.WcsNDMap`
- Cutout map
- """
- width = _check_width(width)
- idx = (0,) * len(self.geom.axes)
- c2d = Cutout2D(
- data=self.data[idx],
- wcs=self.geom.wcs,
- position=position,
- # Cutout2D takes size with order (lat, lon)
- size=width[::-1] * u.deg,
- > mode=mode,
- )
- gammapy/maps/wcsnd.py:704:
- _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
- self = <astropy.nddata.utils.Cutout2D object at 0x1173511d0>
- data = array([[1.2810383e+09, 1.2990996e+09, 1.3108037e+09, 1.3119762e+09,
- 1.3125650e+09, 1.3125650e+09, 1.3119759e+0... 1.3728622e+09, 1.3728622e+09, 1.3721943e+09, 1.3708570e+09,
- 1.3645513e+09, 1.3570106e+09]], dtype=float32)
- position = (array(-958.8728337), array(-597.38551947)), size = <Quantity [0.7, 0.7] deg>
- wcs = WCS Keywords
- Number of WCS axes: 2
- CTYPE : 'GLON-CAR' 'GLAT-CAR'
- CRVAL : 0.0 0.0
- CRPIX : 5.5 5.5
- PC1_1 PC1_2 : 1.0 0.0
- PC2_1 PC2_2 : 0.0 1.0
- CDELT : -0.1 0.1
- NAXIS : 10 10 3
- mode = 'trim', fill_value = nan, copy = False
- def __init__(self, data, position, size, wcs=None, mode='trim',
- fill_value=np.nan, copy=False):
- if isinstance(position, SkyCoord):
- if wcs is None:
- raise ValueError('wcs must be input if position is a '
- 'SkyCoord')
- position = skycoord_to_pixel(position, wcs, mode='all') # (x, y)
- if np.isscalar(size):
- size = np.repeat(size, 2)
- # special handling for a scalar Quantity
- if isinstance(size, u.Quantity):
- size = np.atleast_1d(size)
- if len(size) == 1:
- size = np.repeat(size, 2)
- if len(size) > 2:
- raise ValueError('size must have at most two elements')
- shape = np.zeros(2).astype(int)
- pixel_scales = None
- # ``size`` can have a mixture of int and Quantity (and even units),
- # so evaluate each axis separately
- for axis, side in enumerate(size):
- if not isinstance(side, u.Quantity):
- shape[axis] = int(np.round(size[axis])) # pixels
- else:
- if side.unit == u.pixel:
- shape[axis] = int(np.round(side.value))
- elif side.unit.physical_type == 'angle':
- if wcs is None:
- raise ValueError('wcs must be input if any element '
- 'of size has angular units')
- if pixel_scales is None:
- pixel_scales = u.Quantity(
- proj_plane_pixel_scales(wcs), wcs.wcs.cunit[axis])
- shape[axis] = int(np.round(
- (side / pixel_scales[axis]).decompose()))
- else:
- raise ValueError('shape can contain Quantities with only '
- 'pixel or angular units')
- data = np.asanyarray(data)
- # reverse position because extract_array and overlap_slices
- # use (y, x), but keep the input position
- pos_yx = position[::-1]
- cutout_data, input_position_cutout = extract_array(
- data, tuple(shape), pos_yx, mode=mode, fill_value=fill_value,
- > return_position=True)
- ../../../software/anaconda3/envs/gammapy-dev/lib/python3.7/site-packages/astropy/nddata/utils.py:686:
- _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
- array_large = array([[1.2810383e+09, 1.2990996e+09, 1.3108037e+09, 1.3119762e+09,
- 1.3125650e+09, 1.3125650e+09, 1.3119759e+0... 1.3728622e+09, 1.3728622e+09, 1.3721943e+09, 1.3708570e+09,
- 1.3645513e+09, 1.3570106e+09]], dtype=float32)
- shape = (7, 7), position = (array(-597.38551947), array(-958.8728337)), mode = 'trim', fill_value = nan, return_position = True
- def extract_array(array_large, shape, position, mode='partial',
- fill_value=np.nan, return_position=False):
- """
- Extract a smaller array of the given shape and position from a
- larger array.
- Parameters
- ----------
- array_large : `~numpy.ndarray`
- The array from which to extract the small array.
- shape : tuple or int
- The shape of the extracted array (for 1D arrays, this can be an
- `int`). See the ``mode`` keyword for additional details.
- position : tuple of numbers or number
- The position of the small array's center with respect to the
- large array. The pixel coordinates should be in the same order
- as the array shape. Integer positions are at the pixel centers
- (for 1D arrays, this can be a number).
- mode : {'partial', 'trim', 'strict'}, optional
- The mode used for extracting the small array. For the
- ``'partial'`` and ``'trim'`` modes, a partial overlap of the
- small array and the large array is sufficient. For the
- ``'strict'`` mode, the small array has to be fully contained
- within the large array, otherwise an
- `~astropy.nddata.utils.PartialOverlapError` is raised. In all
- modes, non-overlapping arrays will raise a
- `~astropy.nddata.utils.NoOverlapError`. In ``'partial'`` mode,
- positions in the small array that do not overlap with the large
- array will be filled with ``fill_value``. In ``'trim'`` mode
- only the overlapping elements are returned, thus the resulting
- small array may be smaller than the requested ``shape``.
- fill_value : number, optional
- If ``mode='partial'``, the value to fill pixels in the extracted
- small array that do not overlap with the input ``array_large``.
- ``fill_value`` must have the same ``dtype`` as the
- ``array_large`` array.
- return_position : boolean, optional
- If `True`, return the coordinates of ``position`` in the
- coordinate system of the returned array.
- Returns
- -------
- array_small : `~numpy.ndarray`
- The extracted array.
- new_position : tuple
- If ``return_position`` is true, this tuple will contain the
- coordinates of the input ``position`` in the coordinate system
- of ``array_small``. Note that for partially overlapping arrays,
- ``new_position`` might actually be outside of the
- ``array_small``; ``array_small[new_position]`` might give wrong
- results if any element in ``new_position`` is negative.
- Examples
- --------
- We consider a large array with the shape 11x10, from which we extract
- a small array of shape 3x5:
- >>> import numpy as np
- >>> from astropy.nddata.utils import extract_array
- >>> large_array = np.arange(110).reshape((11, 10))
- >>> extract_array(large_array, (3, 5), (7, 7))
- array([[65, 66, 67, 68, 69],
- [75, 76, 77, 78, 79],
- [85, 86, 87, 88, 89]])
- """
- if np.isscalar(shape):
- shape = (shape, )
- if np.isscalar(position):
- position = (position, )
- if mode not in ['partial', 'trim', 'strict']:
- raise ValueError("Valid modes are 'partial', 'trim', and 'strict'.")
- large_slices, small_slices = overlap_slices(array_large.shape,
- > shape, position, mode=mode)
- ../../../software/anaconda3/envs/gammapy-dev/lib/python3.7/site-packages/astropy/nddata/utils.py:211:
- _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
- large_array_shape = (10, 10), small_array_shape = (7, 7), position = (array(-597.38551947), array(-958.8728337)), mode = 'trim'
- def overlap_slices(large_array_shape, small_array_shape, position,
- mode='partial'):
- """
- Get slices for the overlapping part of a small and a large array.
- Given a certain position of the center of the small array, with
- respect to the large array, tuples of slices are returned which can be
- used to extract, add or subtract the small array at the given
- position. This function takes care of the correct behavior at the
- boundaries, where the small array is cut of appropriately.
- Integer positions are at the pixel centers.
- Parameters
- ----------
- large_array_shape : tuple of int or int
- The shape of the large array (for 1D arrays, this can be an
- `int`).
- small_array_shape : tuple of int or int
- The shape of the small array (for 1D arrays, this can be an
- `int`). See the ``mode`` keyword for additional details.
- position : tuple of numbers or number
- The position of the small array's center with respect to the
- large array. The pixel coordinates should be in the same order
- as the array shape. Integer positions are at the pixel centers.
- For any axis where ``small_array_shape`` is even, the position
- is rounded up, e.g. extracting two elements with a center of
- ``1`` will define the extracted region as ``[0, 1]``.
- mode : {'partial', 'trim', 'strict'}, optional
- In ``'partial'`` mode, a partial overlap of the small and the
- large array is sufficient. The ``'trim'`` mode is similar to
- the ``'partial'`` mode, but ``slices_small`` will be adjusted to
- return only the overlapping elements. In the ``'strict'`` mode,
- the small array has to be fully contained in the large array,
- otherwise an `~astropy.nddata.utils.PartialOverlapError` is
- raised. In all modes, non-overlapping arrays will raise a
- `~astropy.nddata.utils.NoOverlapError`.
- Returns
- -------
- slices_large : tuple of slices
- A tuple of slice objects for each axis of the large array, such
- that ``large_array[slices_large]`` extracts the region of the
- large array that overlaps with the small array.
- slices_small : tuple of slices
- A tuple of slice objects for each axis of the small array, such
- that ``small_array[slices_small]`` extracts the region that is
- inside the large array.
- """
- if mode not in ['partial', 'trim', 'strict']:
- raise ValueError('Mode can be only "partial", "trim", or "strict".')
- if np.isscalar(small_array_shape):
- small_array_shape = (small_array_shape, )
- if np.isscalar(large_array_shape):
- large_array_shape = (large_array_shape, )
- if np.isscalar(position):
- position = (position, )
- if len(small_array_shape) != len(large_array_shape):
- raise ValueError('"large_array_shape" and "small_array_shape" must '
- 'have the same number of dimensions.')
- if len(small_array_shape) != len(position):
- raise ValueError('"position" must have the same number of dimensions '
- 'as "small_array_shape".')
- # define the min/max pixel indices
- indices_min = [int(np.ceil(pos - (small_shape / 2.)))
- for (pos, small_shape) in zip(position, small_array_shape)]
- indices_max = [int(np.ceil(pos + (small_shape / 2.)))
- for (pos, small_shape) in zip(position, small_array_shape)]
- for e_max in indices_max:
- if e_max <= 0:
- > raise NoOverlapError('Arrays do not overlap.')
- E astropy.nddata.utils.NoOverlapError: Arrays do not overlap.
- ../../../software/anaconda3/envs/gammapy-dev/lib/python3.7/site-packages/astropy/nddata/utils.py:106: NoOverlapError
- During handling of the above exception, another exception occurred:
- tmpdir = local('/private/var/folders/t_/_mywtcj146lbk2c99bnxw7z40000gp/T/pytest-of-deil/pytest-68/test_datasets_to_io0')
- @requires_data()
- def test_datasets_to_io(tmpdir):
- filedata = "$GAMMAPY_DATA/tests/models/gc_example_datasets.yaml"
- filemodel = "$GAMMAPY_DATA/tests/models/gc_example_models.yaml"
- > datasets = Datasets.from_yaml(filedata, filemodel)
- gammapy/modeling/tests/test_serialize_yaml.py:106:
- _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
- gammapy/modeling/datasets.py:171: in from_yaml
- constructor = dict_to_datasets(data_list, components)
- gammapy/modeling/serialize.py:148: in __init__
- self.update_dataset(dataset, components, bkg_name, model_names)
- gammapy/modeling/serialize.py:161: in update_dataset
- dataset.model = SkyModels(models)
- gammapy/cube/fit.py:227: in model
- evaluator.update(self.exposure, self.psf, self.edisp, self._geom)
- _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
- self = <gammapy.cube.fit.MapEvaluator object at 0x117dc0b70>
- exposure = WcsNDMap
- geom : WcsGeom
- axes : ['lon', 'lat', 'energy']
- shape : (10, 10, 3)
- ndim : 3
- unit : m2 s
- dtype : >f4
- psf = <gammapy.cube.psf_kernel.PSFKernel object at 0x117efdd30>, edisp = <gammapy.irf.energy_dispersion.EnergyDispersion object at 0x117f0c9b0>
- geom = WcsGeom
- axes : ['lon', 'lat', 'energy']
- shape : (10, 10, 3)
- ndim : 3
- coordsys : GAL
- projection : CAR
- center : 0.0 deg, 0.0 deg
- width : 1.0 deg x 1.0 deg
- def update(self, exposure, psf, edisp, geom):
- """Update MapEvaluator, based on the current position of the model component.
- Parameters
- ----------
- exposure : `~gammapy.maps.Map`
- Exposure map.
- psf : `gammapy.cube.PSFMap`
- PSF map.
- edisp : `gammapy.cube.EDispMap`
- Edisp map.
- geom : `gammapy.maps.MapGeom`
- Reference geometry of the data.
- """
- log.debug("Updating model evaluator")
- # cache current position of the model component
- # TODO: lookup correct Edisp for this component
- self.edisp = edisp
- # TODO: lookup correct PSF for this component
- self.psf = psf
- if self.evaluation_mode == "local" and self.model.evaluation_radius is not None:
- self._init_position = self.model.position
- if psf is not None:
- psf_width = np.max(psf.psf_kernel_map.geom.width)
- else:
- psf_width = 0 * u.deg
- width = psf_width + 2 * (self.model.evaluation_radius + CUTOUT_MARGIN)
- try:
- self.exposure = exposure.cutout(
- position=self.model.position, width=width
- )
- except NoOverlapError:
- raise ValueError(
- > f"Position {self.model.position!r} of model component is outside the image boundaries."
- " Please check the starting values or position parameter boundaries of the model."
- )
- E ValueError: Position <SkyCoord (ICRS): (ra, dec) in deg
- E (0., 0.)> of model component is outside the image boundaries. Please check the starting values or position parameter boundaries of the model.
- gammapy/cube/fit.py:777: ValueError
- ================================================================= 1 failed, 3 deselected in 3.49 seconds =================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement