Skip to content

CubeList.combine and .median seems broken on osx

Running the combine tests on osx gives garbage values:

=================================== FAILURES ===================================
__________________________ TestCubeList.test_combine ___________________________
self = <mpdaf.obj.tests.test_cubelist.TestCubeList testMethod=test_combine>
    @pytest.mark.skipif(not HAS_CFITSIO, reason="requires cfitsio")
    def test_combine(self):
        clist = CubeList(self.cubenames)
        combined_cube = np.full(self.shape, 2, dtype=float)
    
        cube, expmap, stat_pix = clist.combine(header={'FOO': 'BAR'})
        cube2, expmap2, stat_pix2 = clist.combine(header={'FOO': 'BAR'},
                                                  mad=True)
>       assert_array_equal(cube.data, cube2.data)
../venv/lib/python3.6/site-packages/mpdaf/obj/tests/test_cubelist.py:141: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
x = masked_array(data =
 [[[2.3 2.3 2.3]
  [2.3 2.3 2.3]
  [2.3 2.3 2.3]
  [2.3 2.3 2.3]]
 [[2.3 2.3 2.3]
  [2.3 2.3 2.3]...
 [[False False False]
  [False False False]
  [False False False]
  [False False False]]],
       fill_value = 1e+20)
y = masked_array(data =
 [[[1075000115.0 1075000115.0 1075000115.0]
  [1075000115.0 1075000115.0 1075000115.0]
  [10750001...
 [[False False False]
  [False False False]
  [False False False]
  [False False False]]],
       fill_value = 1e+20)
err_msg = '', verbose = True
    def assert_array_equal(x, y, err_msg='', verbose=True):
        """
        Raises an AssertionError if two array_like objects are not equal.
    
        Given two array_like objects, check that the shape is equal and all
        elements of these objects are equal. An exception is raised at
        shape mismatch or conflicting values. In contrast to the standard usage
        in numpy, NaNs are compared like numbers, no assertion is raised if
        both objects have NaNs in the same positions.
    
        The usual caution for verifying equality with floating point numbers is
        advised.
    
        Parameters
        ----------
        x : array_like
            The actual object to check.
        y : array_like
            The desired, expected object.
        err_msg : str, optional
            The error message to be printed in case of failure.
        verbose : bool, optional
            If True, the conflicting values are appended to the error message.
    
        Raises
        ------
        AssertionError
            If actual and desired objects are not equal.
    
        See Also
        --------
        assert_allclose: Compare two array_like objects for equality with desired
                         relative and/or absolute precision.
        assert_array_almost_equal_nulp, assert_array_max_ulp, assert_equal
    
        Examples
        --------
        The first assert does not raise an exception:
    
        >>> np.testing.assert_array_equal([1.0,2.33333,np.nan],
        ...                               [np.exp(0),2.33333, np.nan])
    
        Assert fails with numerical inprecision with floats:
    
        >>> np.testing.assert_array_equal([1.0,np.pi,np.nan],
        ...                               [1, np.sqrt(np.pi)**2, np.nan])
        ...
        <type 'exceptions.ValueError'>:
        AssertionError:
        Arrays are not equal
        <BLANKLINE>
        (mismatch 50.0%)
         x: array([ 1.        ,  3.14159265,         NaN])
         y: array([ 1.        ,  3.14159265,         NaN])
    
        Use `assert_allclose` or one of the nulp (number of floating point values)
        functions for these cases instead:
    
        >>> np.testing.assert_allclose([1.0,np.pi,np.nan],
        ...                            [1, np.sqrt(np.pi)**2, np.nan],
        ...                            rtol=1e-10, atol=0)
    
        """
        assert_array_compare(operator.__eq__, x, y, err_msg=err_msg,
>                            verbose=verbose, header='Arrays are not equal')
E       AssertionError: 
E       Arrays are not equal
E       
E       (mismatch 100.0%)
E        x: MaskedArray([[[ 2.3,  2.3,  2.3],
E               [ 2.3,  2.3,  2.3],
E               [ 2.3,  2.3,  2.3],...
E        y: MaskedArray([[[  1.075000e+09,   1.075000e+09,   1.075000e+09],
E               [  1.075000e+09,   1.075000e+09,   1.075000e+09],
E               [  1.075000e+09,   1.075000e+09,   1.075000e+09],...
../venv/lib/python3.6/site-packages/numpy/testing/utils.py:813: AssertionError
----------------------------- Captured stdout call -----------------------------
merging cube using mean with sigma clipping
nmax = 2
nclip_low = 5.000000
nclip_high = 5.000000
nstop = 2
  1: /var/folders/bb/n7t3rs157850byt_jfdcq9k80000gn/T/tmp3vjm0p96/cube-0.fits
  2: /var/folders/bb/n7t3rs157850byt_jfdcq9k80000gn/T/tmp3vjm0p96/cube-1.fits
  3: /var/folders/bb/n7t3rs157850byt_jfdcq9k80000gn/T/tmp3vjm0p96/cube-5.fits
nfiles: 3
num_nthreads: 76
Using 1 threads
Read fits files
naxes 3 4 5
 100%
merging cube using mean with sigma clipping
nmax = 2
nclip_low = 5.000000
nclip_high = 5.000000
nstop = 2
  1: /var/folders/bb/n7t3rs157850byt_jfdcq9k80000gn/T/tmp3vjm0p96/cube-0.fits
  2: /var/folders/bb/n7t3rs157850byt_jfdcq9k80000gn/T/tmp3vjm0p96/cube-1.fits
  3: /var/folders/bb/n7t3rs157850byt_jfdcq9k80000gn/T/tmp3vjm0p96/cube-5.fits
nfiles: 3
num_nthreads: 76
Using 1 threads
Read fits files
naxes 3 4 5
 100%
----------------------------- Captured stderr call -----------------------------
[INFO] % of rejected pixels per files: nan% nan% nan%
[INFO] % of rejected pixels per files: nan% nan% nan%
------------------------------ Captured log call -------------------------------
cubelist.py                505 INFO     % of rejected pixels per files: nan% nan% nan%
cubelist.py                505 INFO     % of rejected pixels per files: nan% nan% nan%
_______________________ TestCubeList.test_combine_scale ________________________
self = <mpdaf.obj.tests.test_cubelist.TestCubeList testMethod=test_combine_scale>
    @pytest.mark.skipif(not HAS_CFITSIO, reason="requires cfitsio")
    def test_combine_scale(self):
        clist = CubeList(self.cubenames, scalelist=[2.] * self.ncubes)
        combined_cube = np.full(self.shape, 2 * 2, dtype=float)
        cube, expmap, stat_pix = clist.combine(header={'FOO': 'BAR'})
>       assert_array_equal(cube.data, combined_cube)
../venv/lib/python3.6/site-packages/mpdaf/obj/tests/test_cubelist.py:174: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
x = masked_array(data =
 [[[2.123318448e-314 2.123318448e-314 2.123318448e-314]
  [2.123318448e-314 2.123318448e-314 2.123...
 [[False False False]
  [False False False]
  [False False False]
  [False False False]]],
       fill_value = 1e+20)
y = array([[[ 4.,  4.,  4.],
        [ 4.,  4.,  4.],
        [ 4.,  4.,  4.],
        [ 4.,  4.,  4.]],
       [[ 4.,  4... 4.,  4.,  4.]],
       [[ 4.,  4.,  4.],
        [ 4.,  4.,  4.],
        [ 4.,  4.,  4.],
        [ 4.,  4.,  4.]]])
err_msg = '', verbose = True
    def assert_array_equal(x, y, err_msg='', verbose=True):
        """
        Raises an AssertionError if two array_like objects are not equal.
    
        Given two array_like objects, check that the shape is equal and all
        elements of these objects are equal. An exception is raised at
        shape mismatch or conflicting values. In contrast to the standard usage
        in numpy, NaNs are compared like numbers, no assertion is raised if
        both objects have NaNs in the same positions.
    
        The usual caution for verifying equality with floating point numbers is
        advised.
    
        Parameters
        ----------
        x : array_like
            The actual object to check.
        y : array_like
            The desired, expected object.
        err_msg : str, optional
            The error message to be printed in case of failure.
        verbose : bool, optional
            If True, the conflicting values are appended to the error message.
    
        Raises
        ------
        AssertionError
            If actual and desired objects are not equal.
    
        See Also
        --------
        assert_allclose: Compare two array_like objects for equality with desired
                         relative and/or absolute precision.
        assert_array_almost_equal_nulp, assert_array_max_ulp, assert_equal
    
        Examples
        --------
        The first assert does not raise an exception:
    
        >>> np.testing.assert_array_equal([1.0,2.33333,np.nan],
        ...                               [np.exp(0),2.33333, np.nan])
    
        Assert fails with numerical inprecision with floats:
    
        >>> np.testing.assert_array_equal([1.0,np.pi,np.nan],
        ...                               [1, np.sqrt(np.pi)**2, np.nan])
        ...
        <type 'exceptions.ValueError'>:
        AssertionError:
        Arrays are not equal
        <BLANKLINE>
        (mismatch 50.0%)
         x: array([ 1.        ,  3.14159265,         NaN])
         y: array([ 1.        ,  3.14159265,         NaN])
    
        Use `assert_allclose` or one of the nulp (number of floating point values)
        functions for these cases instead:
    
        >>> np.testing.assert_allclose([1.0,np.pi,np.nan],
        ...                            [1, np.sqrt(np.pi)**2, np.nan],
        ...                            rtol=1e-10, atol=0)
    
        """
        assert_array_compare(operator.__eq__, x, y, err_msg=err_msg,
>                            verbose=verbose, header='Arrays are not equal')
E       AssertionError: 
E       Arrays are not equal
E       
E       (mismatch 100.0%)
E        x: MaskedArray([[[  2.123318e-314,   2.123318e-314,   2.123318e-314],
E               [  2.123318e-314,   2.123318e-314,   2.123318e-314],
E               [  2.123318e-314,   2.123318e-314,   2.123318e-314],...
E        y: array([[[ 4.,  4.,  4.],
E               [ 4.,  4.,  4.],
E               [ 4.,  4.,  4.],...
../venv/lib/python3.6/site-packages/numpy/testing/utils.py:813: AssertionError
----------------------------- Captured stdout call -----------------------------
merging cube using mean with sigma clipping
nmax = 2
nclip_low = 5.000000
nclip_high = 5.000000
nstop = 2
  1: /var/folders/bb/n7t3rs157850byt_jfdcq9k80000gn/T/tmp3vjm0p96/cube-0.fits
  2: /var/folders/bb/n7t3rs157850byt_jfdcq9k80000gn/T/tmp3vjm0p96/cube-1.fits
  3: /var/folders/bb/n7t3rs157850byt_jfdcq9k80000gn/T/tmp3vjm0p96/cube-5.fits
nfiles: 3
num_nthreads: 76
Using 1 threads
Read fits files
naxes 3 4 5
 T� 100%
----------------------------- Captured stderr call -----------------------------
[INFO] % of rejected pixels per files: nan% nan% nan%
------------------------------ Captured log call -------------------------------
cubelist.py                505 INFO     % of rejected pixels per files: nan% nan% nan%
___________________________ TestCubeList.test_median ___________________________
self = <mpdaf.obj.tests.test_cubelist.TestCubeList testMethod=test_median>
    @pytest.mark.skipif(not HAS_CFITSIO, reason="requires cfitsio")
    def test_median(self):
        clist = CubeList(self.cubenames)
        combined_cube = np.ones(self.shape)
        cube, expmap, stat_pix = clist.median(header={'FOO': 'BAR'})
>       self.assert_header(cube)
../venv/lib/python3.6/site-packages/mpdaf/obj/tests/test_cubelist.py:120: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
self = <mpdaf.obj.tests.test_cubelist.TestCubeList testMethod=test_median>
cube = <Cube(shape=(5, 4, 3), unit='ct', dtype='float64')>
    def assert_header(self, cube):
        assert cube.primary_header['FOO'] == 'BAR'
        assert 'CUBEIDX' not in cube.primary_header
        assert cube.primary_header['OBJECT'] == 'OBJECT 0'
        assert cube.data_header['OBJECT'] == 'OBJECT 0'
>       assert cube.primary_header['EXPTIME'] == 100 * self.ncubes
E       AssertionError: assert 107500011500.0 == (100 * 3)
E        +  where 3 = <mpdaf.obj.tests.test_cubelist.TestCubeList testMethod=test_median>.ncubes
../venv/lib/python3.6/site-packages/mpdaf/obj/tests/test_cubelist.py:92: AssertionError
----------------------------- Captured stdout call -----------------------------
  1: /var/folders/bb/n7t3rs157850byt_jfdcq9k80000gn/T/tmp3vjm0p96/cube-0.fits
  2: /var/folders/bb/n7t3rs157850byt_jfdcq9k80000gn/T/tmp3vjm0p96/cube-1.fits
  3: /var/folders/bb/n7t3rs157850byt_jfdcq9k80000gn/T/tmp3vjm0p96/cube-5.fits
nfiles: 3
num_nthreads: 76
Using 1 threads
Read fits files
naxes 3 4 5

Maybe some type issue?