AllenInstitute / ophys_nway_matching

Other
4 stars 0 forks source link

adds meaningful exception for mismatched image sizes #63

Closed djkapner closed 3 years ago

djkapner commented 3 years ago

nway cell matching expects that the average projection images in the container are all the same size. The current failure mode relies on opencv.phaseCorrelate failing with the error message:

cv2.error: OpenCV(4.4.0) /tmp/pip-req-build-99ib2vsi/opencv/modules/imgproc/src/phasecorr.cpp:524: error: (-215:Assertion failed) src1.size == src2.size in function 'phaseCorrelate'

This PR adds an early check, a test for the check, and a more informative message:

__main__.NwayException: not all experiments have the same size average projection images, which nway matching currently expects. sizes and image paths are
(449, 512): /allen/programs/braintv/production/visualbehavior/prod0/specimen_789992909/ophys_session_815485890/ophys_experiment_815652334/processed/ophys_cell_segmentation_run_1080895240/avgInt_a1X.png
(449, 512): /allen/programs/braintv/production/visualbehavior/prod0/specimen_789992909/ophys_session_817101568/ophys_experiment_817267785/processed/ophys_cell_segmentation_run_1080850339/avgInt_a1X.png
(447, 512): /allen/programs/braintv/production/visualbehavior/prod0/specimen_789992909/ophys_session_819949602/ophys_experiment_820307518/processed/ophys_cell_segmentation_run_1080863409/avgInt_a1X.png
(447, 512): /allen/programs/braintv/production/visualbehavior/prod0/specimen_789992909/ophys_session_820871900/ophys_experiment_821011078/processed/ophys_cell_segmentation_run_1080861432/avgInt_a1X.png
(447, 512): /allen/programs/braintv/production/visualbehavior/prod0/specimen_789992909/ophys_session_822388759/ophys_experiment_822647135/processed/ophys_cell_segmentation_run_1080895280/avgInt_a1X.png
(447, 512): /allen/programs/braintv/production/visualbehavior/prod0/specimen_789992909/ophys_session_824745199/ophys_experiment_825130141/processed/ophys_cell_segmentation_run_1080861930/avgInt_a1X.png
codecov-io commented 3 years ago

Codecov Report

Merging #63 (5383ffd) into main (30ce5fe) will increase coverage by 0.02%. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #63      +/-   ##
==========================================
+ Coverage   97.59%   97.62%   +0.02%     
==========================================
  Files           9        9              
  Lines        1041     1052      +11     
==========================================
+ Hits         1016     1027      +11     
  Misses         25       25              
Impacted Files Coverage Δ
nway/nway_matching.py 97.07% <100.00%> (+0.16%) :arrow_up: