SHARE
TWEET

Untitled

a guest Oct 13th, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (gammapy-dev) hfm-1804a:gammapy deil$ pytest --lf
  2. ========================================================================== test session starts ===========================================================================
  3. platform darwin -- Python 3.7.0, pytest-5.0.1, py-1.8.0, pluggy-0.12.0
  4. rootdir: /Users/deil/work/code/gammapy, inifile: setup.cfg
  5. 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
  6. collecting ...
  7. Gammapy test data availability:
  8. gammapy-data ... yes
  9. Gammapy environment variables:
  10. GAMMAPY_DATA = /Users/deil/work/gammapy-tutorials/datasets
  11. Setting matplotlib backend to "agg" for the tests.
  12. collected 4 items / 3 deselected / 1 selected                                                                                                                            
  13. run-last-failure: rerun previous 1 failure (skipped 5752 files)
  14.  
  15. gammapy/modeling/tests/test_serialize_yaml.py F                                                                                                                    [100%]
  16.  
  17. ================================================================================ FAILURES ================================================================================
  18. __________________________________________________________________________ test_datasets_to_io ___________________________________________________________________________
  19.  
  20. self = <gammapy.cube.fit.MapEvaluator object at 0x117dc0b70>
  21. exposure = WcsNDMap
  22.  
  23.     geom  : WcsGeom
  24.     axes  : ['lon', 'lat', 'energy']
  25.     shape : (10, 10, 3)
  26.     ndim  : 3
  27.     unit  : m2 s
  28.     dtype : >f4
  29.  
  30. psf = <gammapy.cube.psf_kernel.PSFKernel object at 0x117efdd30>, edisp = <gammapy.irf.energy_dispersion.EnergyDispersion object at 0x117f0c9b0>
  31. geom = WcsGeom
  32.  
  33.     axes       : ['lon', 'lat', 'energy']
  34.     shape      : (10, 10, 3)
  35.     ndim       : 3
  36.     coordsys   : GAL
  37.     projection : CAR
  38.     center     : 0.0 deg, 0.0 deg
  39.     width      : 1.0 deg x 1.0 deg
  40.  
  41.  
  42.     def update(self, exposure, psf, edisp, geom):
  43.         """Update MapEvaluator, based on the current position of the model component.
  44.    
  45.         Parameters
  46.         ----------
  47.         exposure : `~gammapy.maps.Map`
  48.             Exposure map.
  49.         psf : `gammapy.cube.PSFMap`
  50.             PSF map.
  51.         edisp : `gammapy.cube.EDispMap`
  52.             Edisp map.
  53.         geom : `gammapy.maps.MapGeom`
  54.             Reference geometry of the data.
  55.         """
  56.         log.debug("Updating model evaluator")
  57.         # cache current position of the model component
  58.    
  59.         # TODO: lookup correct Edisp for this component
  60.         self.edisp = edisp
  61.    
  62.         # TODO: lookup correct PSF for this component
  63.         self.psf = psf
  64.    
  65.         if self.evaluation_mode == "local" and self.model.evaluation_radius is not None:
  66.             self._init_position = self.model.position
  67.             if psf is not None:
  68.                 psf_width = np.max(psf.psf_kernel_map.geom.width)
  69.             else:
  70.                 psf_width = 0 * u.deg
  71.    
  72.             width = psf_width + 2 * (self.model.evaluation_radius + CUTOUT_MARGIN)
  73.             try:
  74.                 self.exposure = exposure.cutout(
  75. >                   position=self.model.position, width=width
  76.                 )
  77.  
  78. gammapy/cube/fit.py:773:
  79. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  80.  
  81. self = WcsNDMap
  82.  
  83.     geom  : WcsGeom
  84.     axes  : ['lon', 'lat', 'energy']
  85.     shape : (10, 10, 3)
  86.     ndim  : 3
  87.     unit  : m2 s
  88.     dtype : >f4
  89.  
  90. position = <SkyCoord (ICRS): (ra, dec) in deg
  91.     (0., 0.)>, width = (0.7, 0.7), mode = 'trim'
  92.  
  93.     def cutout(self, position, width, mode="trim"):
  94.         """
  95.         Create a cutout around a given position.
  96.    
  97.         Parameters
  98.         ----------
  99.         position : `~astropy.coordinates.SkyCoord`
  100.             Center position of the cutout region.
  101.         width : tuple of `~astropy.coordinates.Angle`
  102.             Angular sizes of the region in (lon, lat) in that specific order.
  103.             If only one value is passed, a square region is extracted.
  104.         mode : {'trim', 'partial', 'strict'}
  105.             Mode option for Cutout2D, for details see `~astropy.nddata.utils.Cutout2D`.
  106.    
  107.         Returns
  108.         -------
  109.         cutout : `~gammapy.maps.WcsNDMap`
  110.             Cutout map
  111.         """
  112.         width = _check_width(width)
  113.         idx = (0,) * len(self.geom.axes)
  114.         c2d = Cutout2D(
  115.             data=self.data[idx],
  116.             wcs=self.geom.wcs,
  117.             position=position,
  118.             # Cutout2D takes size with order (lat, lon)
  119.             size=width[::-1] * u.deg,
  120. >           mode=mode,
  121.         )
  122.  
  123. gammapy/maps/wcsnd.py:704:
  124. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  125.  
  126. self = <astropy.nddata.utils.Cutout2D object at 0x1173511d0>
  127. data = array([[1.2810383e+09, 1.2990996e+09, 1.3108037e+09, 1.3119762e+09,
  128.         1.3125650e+09, 1.3125650e+09, 1.3119759e+0...     1.3728622e+09, 1.3728622e+09, 1.3721943e+09, 1.3708570e+09,
  129.         1.3645513e+09, 1.3570106e+09]], dtype=float32)
  130. position = (array(-958.8728337), array(-597.38551947)), size = <Quantity [0.7, 0.7] deg>
  131. wcs = WCS Keywords
  132.  
  133. Number of WCS axes: 2
  134. CTYPE : 'GLON-CAR'  'GLAT-CAR'  
  135. CRVAL : 0.0  0.0  
  136. CRPIX : 5.5  5.5  
  137. PC1_1 PC1_2  : 1.0  0.0  
  138. PC2_1 PC2_2  : 0.0  1.0  
  139. CDELT : -0.1  0.1  
  140. NAXIS : 10  10  3
  141. mode = 'trim', fill_value = nan, copy = False
  142.  
  143.     def __init__(self, data, position, size, wcs=None, mode='trim',
  144.                  fill_value=np.nan, copy=False):
  145.         if isinstance(position, SkyCoord):
  146.             if wcs is None:
  147.                 raise ValueError('wcs must be input if position is a '
  148.                                  'SkyCoord')
  149.             position = skycoord_to_pixel(position, wcs, mode='all')  # (x, y)
  150.    
  151.         if np.isscalar(size):
  152.             size = np.repeat(size, 2)
  153.    
  154.         # special handling for a scalar Quantity
  155.         if isinstance(size, u.Quantity):
  156.             size = np.atleast_1d(size)
  157.             if len(size) == 1:
  158.                 size = np.repeat(size, 2)
  159.    
  160.         if len(size) > 2:
  161.             raise ValueError('size must have at most two elements')
  162.    
  163.         shape = np.zeros(2).astype(int)
  164.         pixel_scales = None
  165.         # ``size`` can have a mixture of int and Quantity (and even units),
  166.         # so evaluate each axis separately
  167.         for axis, side in enumerate(size):
  168.             if not isinstance(side, u.Quantity):
  169.                 shape[axis] = int(np.round(size[axis]))     # pixels
  170.             else:
  171.                 if side.unit == u.pixel:
  172.                     shape[axis] = int(np.round(side.value))
  173.                 elif side.unit.physical_type == 'angle':
  174.                     if wcs is None:
  175.                         raise ValueError('wcs must be input if any element '
  176.                                          'of size has angular units')
  177.                     if pixel_scales is None:
  178.                         pixel_scales = u.Quantity(
  179.                             proj_plane_pixel_scales(wcs), wcs.wcs.cunit[axis])
  180.                     shape[axis] = int(np.round(
  181.                         (side / pixel_scales[axis]).decompose()))
  182.                 else:
  183.                     raise ValueError('shape can contain Quantities with only '
  184.                                      'pixel or angular units')
  185.    
  186.         data = np.asanyarray(data)
  187.         # reverse position because extract_array and overlap_slices
  188.         # use (y, x), but keep the input position
  189.         pos_yx = position[::-1]
  190.    
  191.         cutout_data, input_position_cutout = extract_array(
  192.             data, tuple(shape), pos_yx, mode=mode, fill_value=fill_value,
  193. >           return_position=True)
  194.  
  195. ../../../software/anaconda3/envs/gammapy-dev/lib/python3.7/site-packages/astropy/nddata/utils.py:686:
  196. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  197.  
  198. array_large = array([[1.2810383e+09, 1.2990996e+09, 1.3108037e+09, 1.3119762e+09,
  199.         1.3125650e+09, 1.3125650e+09, 1.3119759e+0...     1.3728622e+09, 1.3728622e+09, 1.3721943e+09, 1.3708570e+09,
  200.         1.3645513e+09, 1.3570106e+09]], dtype=float32)
  201. shape = (7, 7), position = (array(-597.38551947), array(-958.8728337)), mode = 'trim', fill_value = nan, return_position = True
  202.  
  203.     def extract_array(array_large, shape, position, mode='partial',
  204.                       fill_value=np.nan, return_position=False):
  205.         """
  206.         Extract a smaller array of the given shape and position from a
  207.         larger array.
  208.    
  209.         Parameters
  210.         ----------
  211.         array_large : `~numpy.ndarray`
  212.             The array from which to extract the small array.
  213.         shape : tuple or int
  214.             The shape of the extracted array (for 1D arrays, this can be an
  215.             `int`).  See the ``mode`` keyword for additional details.
  216.         position : tuple of numbers or number
  217.             The position of the small array's center with respect to the
  218.             large array.  The pixel coordinates should be in the same order
  219.             as the array shape.  Integer positions are at the pixel centers
  220.             (for 1D arrays, this can be a number).
  221.         mode : {'partial', 'trim', 'strict'}, optional
  222.             The mode used for extracting the small array.  For the
  223.             ``'partial'`` and ``'trim'`` modes, a partial overlap of the
  224.             small array and the large array is sufficient.  For the
  225.             ``'strict'`` mode, the small array has to be fully contained
  226.             within the large array, otherwise an
  227.             `~astropy.nddata.utils.PartialOverlapError` is raised.   In all
  228.             modes, non-overlapping arrays will raise a
  229.             `~astropy.nddata.utils.NoOverlapError`.  In ``'partial'`` mode,
  230.             positions in the small array that do not overlap with the large
  231.             array will be filled with ``fill_value``.  In ``'trim'`` mode
  232.             only the overlapping elements are returned, thus the resulting
  233.             small array may be smaller than the requested ``shape``.
  234.         fill_value : number, optional
  235.             If ``mode='partial'``, the value to fill pixels in the extracted
  236.             small array that do not overlap with the input ``array_large``.
  237.             ``fill_value`` must have the same ``dtype`` as the
  238.             ``array_large`` array.
  239.         return_position : boolean, optional
  240.             If `True`, return the coordinates of ``position`` in the
  241.             coordinate system of the returned array.
  242.    
  243.         Returns
  244.         -------
  245.         array_small : `~numpy.ndarray`
  246.             The extracted array.
  247.         new_position : tuple
  248.             If ``return_position`` is true, this tuple will contain the
  249.             coordinates of the input ``position`` in the coordinate system
  250.             of ``array_small``. Note that for partially overlapping arrays,
  251.             ``new_position`` might actually be outside of the
  252.             ``array_small``; ``array_small[new_position]`` might give wrong
  253.             results if any element in ``new_position`` is negative.
  254.    
  255.         Examples
  256.         --------
  257.         We consider a large array with the shape 11x10, from which we extract
  258.         a small array of shape 3x5:
  259.    
  260.         >>> import numpy as np
  261.         >>> from astropy.nddata.utils import extract_array
  262.         >>> large_array = np.arange(110).reshape((11, 10))
  263.         >>> extract_array(large_array, (3, 5), (7, 7))
  264.         array([[65, 66, 67, 68, 69],
  265.                [75, 76, 77, 78, 79],
  266.                [85, 86, 87, 88, 89]])
  267.         """
  268.    
  269.         if np.isscalar(shape):
  270.             shape = (shape, )
  271.         if np.isscalar(position):
  272.             position = (position, )
  273.    
  274.         if mode not in ['partial', 'trim', 'strict']:
  275.             raise ValueError("Valid modes are 'partial', 'trim', and 'strict'.")
  276.         large_slices, small_slices = overlap_slices(array_large.shape,
  277. >                                                   shape, position, mode=mode)
  278.  
  279. ../../../software/anaconda3/envs/gammapy-dev/lib/python3.7/site-packages/astropy/nddata/utils.py:211:
  280. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  281.  
  282. large_array_shape = (10, 10), small_array_shape = (7, 7), position = (array(-597.38551947), array(-958.8728337)), mode = 'trim'
  283.  
  284.     def overlap_slices(large_array_shape, small_array_shape, position,
  285.                        mode='partial'):
  286.         """
  287.         Get slices for the overlapping part of a small and a large array.
  288.    
  289.         Given a certain position of the center of the small array, with
  290.         respect to the large array, tuples of slices are returned which can be
  291.         used to extract, add or subtract the small array at the given
  292.         position. This function takes care of the correct behavior at the
  293.         boundaries, where the small array is cut of appropriately.
  294.         Integer positions are at the pixel centers.
  295.    
  296.         Parameters
  297.         ----------
  298.         large_array_shape : tuple of int or int
  299.             The shape of the large array (for 1D arrays, this can be an
  300.             `int`).
  301.         small_array_shape : tuple of int or int
  302.             The shape of the small array (for 1D arrays, this can be an
  303.             `int`).  See the ``mode`` keyword for additional details.
  304.         position : tuple of numbers or number
  305.             The position of the small array's center with respect to the
  306.             large array.  The pixel coordinates should be in the same order
  307.             as the array shape.  Integer positions are at the pixel centers.
  308.             For any axis where ``small_array_shape`` is even, the position
  309.             is rounded up, e.g. extracting two elements with a center of
  310.             ``1`` will define the extracted region as ``[0, 1]``.
  311.         mode : {'partial', 'trim', 'strict'}, optional
  312.             In ``'partial'`` mode, a partial overlap of the small and the
  313.             large array is sufficient.  The ``'trim'`` mode is similar to
  314.             the ``'partial'`` mode, but ``slices_small`` will be adjusted to
  315.             return only the overlapping elements.  In the ``'strict'`` mode,
  316.             the small array has to be fully contained in the large array,
  317.             otherwise an `~astropy.nddata.utils.PartialOverlapError` is
  318.             raised.  In all modes, non-overlapping arrays will raise a
  319.             `~astropy.nddata.utils.NoOverlapError`.
  320.    
  321.         Returns
  322.         -------
  323.         slices_large : tuple of slices
  324.             A tuple of slice objects for each axis of the large array, such
  325.             that ``large_array[slices_large]`` extracts the region of the
  326.             large array that overlaps with the small array.
  327.         slices_small : tuple of slices
  328.             A tuple of slice objects for each axis of the small array, such
  329.             that ``small_array[slices_small]`` extracts the region that is
  330.             inside the large array.
  331.         """
  332.    
  333.         if mode not in ['partial', 'trim', 'strict']:
  334.             raise ValueError('Mode can be only "partial", "trim", or "strict".')
  335.         if np.isscalar(small_array_shape):
  336.             small_array_shape = (small_array_shape, )
  337.         if np.isscalar(large_array_shape):
  338.             large_array_shape = (large_array_shape, )
  339.         if np.isscalar(position):
  340.             position = (position, )
  341.    
  342.         if len(small_array_shape) != len(large_array_shape):
  343.             raise ValueError('"large_array_shape" and "small_array_shape" must '
  344.                              'have the same number of dimensions.')
  345.    
  346.         if len(small_array_shape) != len(position):
  347.             raise ValueError('"position" must have the same number of dimensions '
  348.                              'as "small_array_shape".')
  349.    
  350.         # define the min/max pixel indices
  351.         indices_min = [int(np.ceil(pos - (small_shape / 2.)))
  352.                        for (pos, small_shape) in zip(position, small_array_shape)]
  353.         indices_max = [int(np.ceil(pos + (small_shape / 2.)))
  354.                        for (pos, small_shape) in zip(position, small_array_shape)]
  355.    
  356.         for e_max in indices_max:
  357.             if e_max <= 0:
  358. >               raise NoOverlapError('Arrays do not overlap.')
  359. E               astropy.nddata.utils.NoOverlapError: Arrays do not overlap.
  360.  
  361. ../../../software/anaconda3/envs/gammapy-dev/lib/python3.7/site-packages/astropy/nddata/utils.py:106: NoOverlapError
  362.  
  363. During handling of the above exception, another exception occurred:
  364.  
  365. tmpdir = local('/private/var/folders/t_/_mywtcj146lbk2c99bnxw7z40000gp/T/pytest-of-deil/pytest-68/test_datasets_to_io0')
  366.  
  367.     @requires_data()
  368.     def test_datasets_to_io(tmpdir):
  369.         filedata = "$GAMMAPY_DATA/tests/models/gc_example_datasets.yaml"
  370.         filemodel = "$GAMMAPY_DATA/tests/models/gc_example_models.yaml"
  371.    
  372. >       datasets = Datasets.from_yaml(filedata, filemodel)
  373.  
  374. gammapy/modeling/tests/test_serialize_yaml.py:106:
  375. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  376. gammapy/modeling/datasets.py:171: in from_yaml
  377.     constructor = dict_to_datasets(data_list, components)
  378. gammapy/modeling/serialize.py:148: in __init__
  379.     self.update_dataset(dataset, components, bkg_name, model_names)
  380. gammapy/modeling/serialize.py:161: in update_dataset
  381.     dataset.model = SkyModels(models)
  382. gammapy/cube/fit.py:227: in model
  383.     evaluator.update(self.exposure, self.psf, self.edisp, self._geom)
  384. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  385.  
  386. self = <gammapy.cube.fit.MapEvaluator object at 0x117dc0b70>
  387. exposure = WcsNDMap
  388.  
  389.     geom  : WcsGeom
  390.     axes  : ['lon', 'lat', 'energy']
  391.     shape : (10, 10, 3)
  392.     ndim  : 3
  393.     unit  : m2 s
  394.     dtype : >f4
  395.  
  396. psf = <gammapy.cube.psf_kernel.PSFKernel object at 0x117efdd30>, edisp = <gammapy.irf.energy_dispersion.EnergyDispersion object at 0x117f0c9b0>
  397. geom = WcsGeom
  398.  
  399.     axes       : ['lon', 'lat', 'energy']
  400.     shape      : (10, 10, 3)
  401.     ndim       : 3
  402.     coordsys   : GAL
  403.     projection : CAR
  404.     center     : 0.0 deg, 0.0 deg
  405.     width      : 1.0 deg x 1.0 deg
  406.  
  407.  
  408.     def update(self, exposure, psf, edisp, geom):
  409.         """Update MapEvaluator, based on the current position of the model component.
  410.    
  411.         Parameters
  412.         ----------
  413.         exposure : `~gammapy.maps.Map`
  414.             Exposure map.
  415.         psf : `gammapy.cube.PSFMap`
  416.             PSF map.
  417.         edisp : `gammapy.cube.EDispMap`
  418.             Edisp map.
  419.         geom : `gammapy.maps.MapGeom`
  420.             Reference geometry of the data.
  421.         """
  422.         log.debug("Updating model evaluator")
  423.         # cache current position of the model component
  424.    
  425.         # TODO: lookup correct Edisp for this component
  426.         self.edisp = edisp
  427.    
  428.         # TODO: lookup correct PSF for this component
  429.         self.psf = psf
  430.    
  431.         if self.evaluation_mode == "local" and self.model.evaluation_radius is not None:
  432.             self._init_position = self.model.position
  433.             if psf is not None:
  434.                 psf_width = np.max(psf.psf_kernel_map.geom.width)
  435.             else:
  436.                 psf_width = 0 * u.deg
  437.    
  438.             width = psf_width + 2 * (self.model.evaluation_radius + CUTOUT_MARGIN)
  439.             try:
  440.                 self.exposure = exposure.cutout(
  441.                     position=self.model.position, width=width
  442.                 )
  443.             except NoOverlapError:
  444.                 raise ValueError(
  445. >                   f"Position {self.model.position!r} of model component is outside the image boundaries."
  446.                     " Please check the starting values or position parameter boundaries of the model."
  447.                 )
  448. E               ValueError: Position <SkyCoord (ICRS): (ra, dec) in deg
  449. E                   (0., 0.)> of model component is outside the image boundaries. Please check the starting values or position parameter boundaries of the model.
  450.  
  451. gammapy/cube/fit.py:777: ValueError
  452. ================================================================= 1 failed, 3 deselected in 3.49 seconds =================================================================
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top