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

debug: pass failing unit test - Value errors from shape / num pixels mismatch #12

Merged
merged 11 commits into from
Nov 6, 2021

Conversation

geoffwoollard
Copy link
Contributor

Can't reproduce failing unit test yet. Python 8 issue?

https://github.com/compSPI/simSPI/runs/4031149125?check_suite_focus=true

Run $CONDA/bin/pytest --cov-report term --cov-report xml:coverage.xml --cov=simSPI tests
  $CONDA/bin/pytest --cov-report term --cov-report xml:coverage.xml --cov=simSPI tests
  shell: /bin/bash -e {0}
  env:
    pythonLocation: /opt/hostedtoolcache/Python/3.8.12/x64
    LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.8.12/x64/lib
============================= test session starts ==============================
platform linux -- Python 3.9.5, pytest-6.2.5, py-1.10.0, pluggy-1.0.0
rootdir: /home/runner/work/simSPI/simSPI, configfile: pytest.ini, testpaths: tests
plugins: cov-3.0.0
collected 8 items

tests/test_multislice.py ...F.                                           [ 62%]
tests/test_transfer.py ...                                               [100%]

=================================== FAILURES ===================================
________________________________ test_apply_dqe ________________________________

    def test_apply_dqe():
        """Test apply_dqe."""
        N_random = np.random.uniform(low=50, high=100)
        N = int(2 * (N_random // 2))
        ones = np.ones((N, N))
        freq_A_2d = transfer.ctf_freqs(N, dim=2)[0]
        mtf_const = 1.5
        mtf2 = (np.sinc(freq_A_2d * mtf_const)) ** 2
        ntf2 = np.sinc(freq_A_2d) ** 2
        dqe = mtf2 / ntf2
>       i0_dqe = multislice.apply_dqe(ones, dqe)

tests/test_multislice.py:85: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

i0_f = array([[1., 1., 1., ..., 1., 1., 1.],
       [1., 1., 1., ..., 1., 1., 1.],
       [1., 1., 1., ..., 1., 1., 1.],
       ...,
       [1., 1., 1., ..., 1., 1., 1.],
       [1., 1., 1., ..., 1., 1., 1.],
       [1., 1., 1., ..., 1., 1., 1.]])
dqe = array([[0.02518659, 0.01654163, 0.00994395, ..., 0.00994395, 0.01654163,
        0.02518659],
       [0.01654163, 0.00...16,
        0.01654163],
       [0.02518659, 0.01654163, 0.00994395, ..., 0.00994395, 0.01654163,
        0.02518659]])

    def apply_dqe(i0_f, dqe):
        """Convolution with detector's DQE.
    
        Convolution of (ctf applied) exit wave
        with sqrt of the detective quantum efficiency.
    
        Parameters
        ----------
        i0_f : numpy.ndarray, shape (N,N)
            Image with ctf applied.
        dqe : numpy.ndarray, shape (N,N)
            Detective quantum efficiency (in 2D).
    
        Returns
        -------
        i0_dqe : numpy.ndarray, shape (N,N)
            Exit wave with dqe applied (in real space).
        """
>       i0_dqe = fourier.do_ifft(i0_f * np.sqrt(dqe), dim=2)
E       ValueError: operands could not be broadcast together with shapes (98,98) (99,99)

simSPI/multislice.py:47: ValueError
=============================== warnings summary ===============================
../../../../../usr/share/miniconda/lib/python3.9/site-packages/raster_geometry/raster.py:2447
  /usr/share/miniconda/lib/python3.9/site-packages/raster_geometry/raster.py:2447: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.
  Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
    dtype=np.float):

-- Docs: https://docs.pytest.org/en/stable/warnings.html

----------- coverage: platform linux, python 3.9.5-final-0 -----------
Name                   Stmts   Miss  Cover   Missing
----------------------------------------------------
simSPI/__init__.py         1      0   100%
simSPI/multislice.py      21      0   100%
simSPI/transfer.py        50      3    94%   90, 97, 167
----------------------------------------------------
TOTAL                     72      3    96%
Coverage XML written to file coverage.xml

Required test coverage of 90.0% reached. Total coverage: 95.83%
=========================== short test summary info ============================
FAILED tests/test_multislice.py::test_apply_dqe - ValueError: operands could ...
=================== 1 failed, 7 passed, 1 warning in 10.13s ====================
Error: Process completed with exit code 1.

@codecov
Copy link

codecov bot commented Nov 6, 2021

Codecov Report

Merging #12 (ecca33d) into master (9f392bd) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #12   +/-   ##
=======================================
  Coverage   95.84%   95.84%           
=======================================
  Files           3        3           
  Lines          72       72           
=======================================
  Hits           69       69           
  Misses          3        3           
Impacted Files Coverage Δ
simSPI/transfer.py 94.00% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9f392bd...ecca33d. Read the comment docs.

@geoffwoollard
Copy link
Contributor Author

Passing all tests consistently.

@geoffwoollard geoffwoollard changed the title debug: pass failing unit test - shape mismatch debug: pass failing unit test - Value errors from shape / num pixels mismatch Nov 6, 2021
@geoffwoollard geoffwoollard merged commit e368ba2 into compSPI:master Nov 6, 2021
@geoffwoollard geoffwoollard mentioned this pull request Nov 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant