[fix] TestDetermineZPosition in z_localization_test.py#3408
[fix] TestDetermineZPosition in z_localization_test.py#3408tepals merged 1 commit intodelmic:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the z-localization unit test to use an absolute path for test images (so it can run from any working directory) and adjusts the z-stack step size/precision used by the assertions.
Changes:
- Updated
z_stack_step_sizeand derivedPRECISIONforTestDetermineZPosition. - Introduced
IMG_PATHand updated image loads to use that path instead of CWD-relative paths.
Comments suppressed due to low confidence (1)
src/odemis/acq/align/test/z_localization_test.py:114
- This block says it changes the range so “warning 6 is raised”, but the subsequent assertion expects warning
4. Please update the comment to match the behavior being tested (or adjust the assertion if the comment is correct).
# Change the range so warning 6 is raised with an image which is just above focus
calib_data_limited_range = CALIB_DATA.copy()
calib_data_limited_range["z_calibration_range"] = (-1e-10, 1e-10)
image = read_data(IMG_PATH + "super_z_single_beed_aprox_500nm_above_focus.tif")[0]
expected_outcome_image_3 = 420.6e-9 # Value determined using the function determine_z_position
z, warning = determine_z_position(image, calib_data_limited_range)
# Since the range is set to small the detected feature is to big and warning raised should be 4
self.assertEqual(warning, 4)
| image = read_data("images/super_z_no_beed_just_white.tif")[0] | ||
| image = read_data(IMG_PATH + "super_z_no_beed_just_white.tif")[0] | ||
| _, warning = determine_z_position(image, CALIB_DATA) | ||
| self.assertEqual(warning, 6) # Since the entire image is white the warning raised should be 5 |
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 57 minutes and 34 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe test file src/odemis/acq/align/test/z_localization_test.py was updated to add an IMG_PATH constant and rewrite all image reads to use os.path.join(IMG_PATH, ...). The numeric literal z_stack_step_size was clarified from 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/odemis/acq/align/test/z_localization_test.py`:
- Around line 55-56: The test's z resolution is too coarse: update the constants
so z_stack_step_size and PRECISION match the dataset ("step50nm") and production
convergence threshold (50 nm). Change z_stack_step_size from 10e-6 to 50e-9 (50
nm) and set PRECISION to that same 50e-9 (or to a slightly tighter fraction of
z_stack_step_size, e.g., 0.9 * z_stack_step_size) so the test will catch real
localization regressions; update the symbols z_stack_step_size and PRECISION
accordingly.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: ce45ca74-db76-42e7-8e01-d0f7dcb2ef1d
📒 Files selected for processing (1)
src/odemis/acq/align/test/z_localization_test.py
f854ecf to
3078238
Compare
| # Test on an image below focus | ||
| image = read_data("images/super_z_single_beed_aprox_500nm_under_focus.tif")[0] | ||
| expected_outcome_image_1 = -592.5e-9 # Value determined using the function determine_z_position | ||
| image = read_data(IMG_PATH + "super_z_single_beed_aprox_500nm_under_focus.tif")[0] |
There was a problem hiding this comment.
I think it is easier to read if you use os.path.join here as well. So update line 57 to:
IMG_PATH = os.path.join(os.path.dirname(__file__), "images")
and then in the test cases use:
| image = read_data(IMG_PATH + "super_z_single_beed_aprox_500nm_under_focus.tif")[0] | |
| image = read_data(os.path.join(IMG_PATH, "super_z_single_beed_aprox_500nm_under_focus.tif"))[0] |
pieleric
left a comment
There was a problem hiding this comment.
Looks good to me... assuming you implement the suggestions by Thera and copilot.
3078238 to
520bedf
Compare
520bedf to
20daaa0
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/odemis/acq/align/test/z_localization_test.py (1)
55-57: Good fix forz_stack_step_size; remove trailing empty string fromIMG_PATH.The correction from
50*10-9(which incorrectly evaluates to491) to50e-9(50 nm) properly aligns with the dataset context ("step50nm") and restores meaningful test precision.However, the trailing
""inIMG_PATHis unconventional. Whileos.path.joinhandles it, it produces a path with a trailing separator that's unnecessary since all usages already callos.path.join(IMG_PATH, filename).Suggested fix
-IMG_PATH = os.path.join(os.path.dirname(__file__), "images", "") +IMG_PATH = os.path.join(os.path.dirname(__file__), "images")🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/odemis/acq/align/test/z_localization_test.py` around lines 55 - 57, The z_stack_step_size has been corrected to 50e-9 and PRECISION is derived from it (no change needed), but IMG_PATH contains an unnecessary trailing empty string; update IMG_PATH by removing the trailing "" so it is built as os.path.join(os.path.dirname(__file__), "images") (ensure existing usages that call os.path.join(IMG_PATH, filename) still work unchanged).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/odemis/acq/align/test/z_localization_test.py`:
- Around line 55-57: The z_stack_step_size has been corrected to 50e-9 and
PRECISION is derived from it (no change needed), but IMG_PATH contains an
unnecessary trailing empty string; update IMG_PATH by removing the trailing ""
so it is built as os.path.join(os.path.dirname(__file__), "images") (ensure
existing usages that call os.path.join(IMG_PATH, filename) still work
unchanged).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 3ba7e6f9-70fc-4d0c-9261-c19906b67e25
📒 Files selected for processing (1)
src/odemis/acq/align/test/z_localization_test.py
| z_stack_step_size = 50*10-9 # m | ||
| z_stack_step_size = 50e-9 # m | ||
| PRECISION = z_stack_step_size * 0.45 # Precision should be better than the step within a z stack | ||
| IMG_PATH = os.path.join(os.path.dirname(__file__), "images", "") |
There was a problem hiding this comment.
Since you are now using os.path.join everywhere, you do not need the , "" at the end
| IMG_PATH = os.path.join(os.path.dirname(__file__), "images", "") | |
| IMG_PATH = os.path.join(os.path.dirname(__file__), "images") |
Fix the z_stack_step_size value and add a folder path for images such that test cases can be run any path.
20daaa0 to
fc17d32
Compare
Fix the z_stack_step_size value and add a folder path for images such that test cases can be run any path.