Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI error that sometimes shows up (Python 2.7) #1747

Closed
arokem opened this issue Feb 28, 2019 · 1 comment

Comments

@arokem
Copy link
Member

commented Feb 28, 2019

Seems to be intermittent, but thought I would record it here, so we can keep track of this:

___________________________ test_image_registration ____________________________
    def test_image_registration():
        with TemporaryDirectory() as temp_out_dir:
    
            static, moving, static_g2w, moving_g2w, smask, mmask, M\
                = setup_random_transform(transform=regtransforms[('AFFINE', 3)],
                                         rfactor=0.1)
    
            save_nifti(pjoin(temp_out_dir, 'b0.nii.gz'), data=static,
                       affine=static_g2w)
            save_nifti(pjoin(temp_out_dir, 't1.nii.gz'), data=moving,
                       affine=moving_g2w)
    
            static_image_file = pjoin(temp_out_dir, 'b0.nii.gz')
            moving_image_file = pjoin(temp_out_dir, 't1.nii.gz')
    
            image_registeration_flow = ImageRegistrationFlow()
    
            def read_distance(qual_fname):
                temp_val = 0
                with open(pjoin(temp_out_dir, qual_fname), 'r') as f:
                    temp_val = f.readlines()[-1]
                return float(temp_val)
    
            def test_com():
    
                out_moved = pjoin(temp_out_dir, "com_moved.nii.gz")
                out_affine = pjoin(temp_out_dir, "com_affine.txt")
    
                image_registeration_flow._force_overwrite = True
                image_registeration_flow.run(static_image_file,
                                             moving_image_file,
                                             transform='com',
                                             out_dir=temp_out_dir,
                                             out_moved=out_moved,
                                             out_affine=out_affine)
                check_existence(out_moved, out_affine)
    
            def test_translation():
    
                out_moved = pjoin(temp_out_dir, "trans_moved.nii.gz")
                out_affine = pjoin(temp_out_dir, "trans_affine.txt")
    
                image_registeration_flow._force_overwrite = True
                image_registeration_flow.run(static_image_file,
                                             moving_image_file,
                                             transform='trans',
                                             out_dir=temp_out_dir,
                                             out_moved=out_moved,
                                             out_affine=out_affine,
                                             save_metric=True,
                                             level_iters=[100, 10, 1],
                                             out_quality='trans_q.txt')
    
                dist = read_distance('trans_q.txt')
                npt.assert_almost_equal(float(dist), -0.3953547764454917, 1)
                check_existence(out_moved, out_affine)
    
            def test_rigid():
    
                out_moved = pjoin(temp_out_dir, "rigid_moved.nii.gz")
                out_affine = pjoin(temp_out_dir, "rigid_affine.txt")
    
                image_registeration_flow._force_overwrite = True
                image_registeration_flow.run(static_image_file,
                                             moving_image_file,
                                             transform='rigid',
                                             out_dir=temp_out_dir,
                                             out_moved=out_moved,
                                             out_affine=out_affine,
                                             save_metric=True,
                                             level_iters=[100, 10, 1],
                                             out_quality='rigid_q.txt')
    
                dist = read_distance('rigid_q.txt')
                npt.assert_almost_equal(dist, -0.6900534794005155, 1)
                check_existence(out_moved, out_affine)
    
            def test_affine():
    
                out_moved = pjoin(temp_out_dir, "affine_moved.nii.gz")
                out_affine = pjoin(temp_out_dir, "affine_affine.txt")
    
                image_registeration_flow._force_overwrite = True
                image_registeration_flow.run(static_image_file,
                                             moving_image_file,
                                             transform='affine',
                                             out_dir=temp_out_dir,
                                             out_moved=out_moved,
                                             out_affine=out_affine,
                                             save_metric=True,
                                             level_iters=[100, 10, 1],
                                             out_quality='affine_q.txt')
    
                dist = read_distance('affine_q.txt')
                npt.assert_almost_equal(dist, -0.7670650775914811, 1)
                check_existence(out_moved, out_affine)
    
            # Creating the erroneous behavior
            def test_err():
                image_registeration_flow._force_overwrite = True
                npt.assert_raises(ValueError, image_registeration_flow.run,
                                  static_image_file,
                                  moving_image_file,
                                  transform='notransform')
    
                image_registeration_flow._force_overwrite = True
                npt.assert_raises(ValueError, image_registeration_flow.run,
                                  static_image_file,
                                  moving_image_file,
                                  metric='wrong_metric')
    
            def check_existence(movedfile, affine_mat_file):
                assert os.path.exists(movedfile)
                assert os.path.exists(affine_mat_file)
                return True
    
            test_com()
            test_translation()
            test_rigid()
>           test_affine()
../venv/lib/python2.7/site-packages/dipy/workflows/tests/test_align.py:185: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
../venv/lib/python2.7/site-packages/dipy/workflows/tests/test_align.py:160: in test_affine
    npt.assert_almost_equal(dist, -0.7670650775914811, 1)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
actual = -0.989901665092, desired = -0.7670650775914811, decimal = 1
err_msg = '', verbose = True
    def assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=True):
        """
        Raise an assertion if two items are not equal up to desired precision.
    
        .. note:: It is recommended to use one of `assert_allclose`,
                  `assert_array_almost_equal_nulp` or `assert_array_max_ulp`
                  instead of this function for more consistent floating point
                  comparisons.
    
        The test is equivalent to ``abs(desired-actual) < 0.5 * 10**(-decimal)``.
    
        Given two objects (numbers or ndarrays), check that all elements of these
        objects are almost equal. An exception is raised at conflicting values.
        For ndarrays this delegates to assert_array_almost_equal
    
        Parameters
        ----------
        actual : array_like
            The object to check.
        desired : array_like
            The expected object.
        decimal : int, optional
            Desired precision, default is 7.
        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 are not equal up to specified precision.
    
        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
        --------
        >>> import numpy.testing as npt
        >>> npt.assert_almost_equal(2.3333333333333, 2.33333334)
        >>> npt.assert_almost_equal(2.3333333333333, 2.33333334, decimal=10)
        ...
        <type 'exceptions.AssertionError'>:
        Items are not equal:
         ACTUAL: 2.3333333333333002
         DESIRED: 2.3333333399999998
    
        >>> npt.assert_almost_equal(np.array([1.0,2.3333333333333]),
        ...                         np.array([1.0,2.33333334]), decimal=9)
        ...
        <type 'exceptions.AssertionError'>:
        Arrays are not almost equal
        <BLANKLINE>
        (mismatch 50.0%)
         x: array([ 1.        ,  2.33333333])
         y: array([ 1.        ,  2.33333334])
    
        """
        from numpy.core import ndarray
        from numpy.lib import iscomplexobj, real, imag
    
        # Handle complex numbers: separate into real/imag to handle
        # nan/inf/negative zero correctly
        # XXX: catch ValueError for subclasses of ndarray where iscomplex fail
        try:
            usecomplex = iscomplexobj(actual) or iscomplexobj(desired)
        except ValueError:
            usecomplex = False
    
        msg = build_err_msg([actual, desired], err_msg, verbose=verbose,
                 header=('Arrays are not almost equal to %d decimals' % decimal))
    
        if usecomplex:
            if iscomplexobj(actual):
                actualr = real(actual)
                actuali = imag(actual)
            else:
                actualr = actual
                actuali = 0
            if iscomplexobj(desired):
                desiredr = real(desired)
                desiredi = imag(desired)
            else:
                desiredr = desired
                desiredi = 0
            try:
                assert_almost_equal(actualr, desiredr, decimal=decimal)
                assert_almost_equal(actuali, desiredi, decimal=decimal)
            except AssertionError:
                raise AssertionError(msg)
    
        if isinstance(actual, (ndarray, tuple, list)) \
                or isinstance(desired, (ndarray, tuple, list)):
            return assert_array_almost_equal(actual, desired, decimal, err_msg)
        try:
            # If one of desired/actual is not finite, handle it specially here:
            # check that both are nan if any is a nan, and test for equality
            # otherwise
            if not (gisfinite(desired) and gisfinite(actual)):
                if gisnan(desired) or gisnan(actual):
                    if not (gisnan(desired) and gisnan(actual)):
                        raise AssertionError(msg)
                else:
                    if not desired == actual:
                        raise AssertionError(msg)
                return
        except (NotImplementedError, TypeError):
            pass
        if round(abs(desired - actual),decimal) != 0 :
>           raise AssertionError(msg)
E           AssertionError: 
E           Arrays are not almost equal to 1 decimals
E            ACTUAL: -0.989901665092
E            DESIRED: -0.7670650775914811

@skoudoro

This comment has been minimized.

Copy link
Member

commented Jul 20, 2019

specific to python 2.7, and it is a long time we did not see this error. closing

@skoudoro skoudoro closed this Jul 20, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.