Improve EchoNet-LVH conversion script#435
Conversation
…onversion-cleanup
…onversion-cleanup
…onversion-cleanup
…onversion-cleanup
|
(still ironing out some bugs that I encountered while running on the full set) |
…onversion-cleanup
…onversion-cleanup
There was a problem hiding this comment.
Actionable comments posted: 5
🧹 Nitpick comments (1)
tests/test_display.py (1)
121-172: ⚡ Quick winUnused
angleparameter in test function.The
angleparameter is still defined in the parametrization (line 128) and function signature (line 132), but it's no longer used in the test body after the refactor to use a fixed symmetrictheta_range. This creates dead code and could confuse future maintainers.♻️ Proposed fix to remove unused parameter
`@pytest.mark.parametrize`( - "size, pattern_creator, allowed_error, angle", + "size, pattern_creator, allowed_error", [ - ((200, 200), "create_radial_pattern", 0.001, None), - ((100, 333), "create_radial_pattern", 0.001, None), - ((200, 200), "create_concentric_rings", 0.1, None), - ((100, 333), "create_concentric_rings", 0.1, None), - ((200, 200), "create_radial_pattern", 0.001, np.deg2rad(30)), + ((200, 200), "create_radial_pattern", 0.001), + ((100, 333), "create_radial_pattern", 0.001), + ((200, 200), "create_concentric_rings", 0.1), + ((100, 333), "create_concentric_rings", 0.1), ], ) `@backend_equality_check`(decimal=2) -def test_scan_conversion_and_inverse(size, pattern_creator, allowed_error, angle): +def test_scan_conversion_and_inverse(size, pattern_creator, allowed_error):🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/test_display.py` around lines 121 - 172, The test_scan_conversion_and_inverse function has an unused angle parameter in both the pytest.mark.parametrize decorator and the function signature. Remove the angle parameter from the parametrize list (which appears in all test case tuples) and remove it from the function signature, since the test uses a fixed theta_range value instead of utilizing the angle parameter.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/source/environment.rst`:
- Around line 42-45: The documentation table in docs/source/environment.rst
contains a duplicate entry for ZEA_DOWNLOAD_TIMEOUT and the documented default
value of 60 seconds is incorrect. Remove the duplicate ZEA_DOWNLOAD_TIMEOUT row
shown in lines 42-45, and update the default value in the remaining
ZEA_DOWNLOAD_TIMEOUT entry to 600 to match the actual runtime default used in
zea/data/convert/utils.py line 149. This ensures the documentation accurately
reflects the actual configuration and eliminates the conflicting guidance from
having two entries for the same environment variable.
In `@zea/data/convert/camus.py`:
- Around line 448-456: The function currently returns `src / "database_nifti"`
when found, but when CAMUS_public is extracted as a directory structure, the
patient folders are located under `src / "CAMUS_public" / "database_nifti"`.
Update the logic to check for and return the correct nested path: after finding
`database_nifti` exists at line 448-456 area, verify if it actually contains
patient folders; if not but `CAMUS_public / database_nifti` exists with patient
folders, return that nested path instead. Apply the same fix at line 510 where
patient folder paths are resolved to ensure consistent path handling across both
locations.
In `@zea/data/convert/echonet.py`:
- Around line 455-466: The _resolve_path function returns the wrong value when
unzipping is needed. On line 465, instead of returning the direct result of
unzip(src / zip_name, src), it should return unzip_dir (which is src /
folder_name / "Videos") to match the behavior when the folder already exists on
line 463. This ensures convert_echonet scans the correct Videos directory for
avi files after unzipping.
In `@zea/data/convert/picmus.py`:
- Around line 318-328: The _resolve_path function currently returns the raw src
directory instead of the stable archive_to_download subdirectory after
unzipping, which causes inconsistent output paths for zip-based runs.
Additionally, it only checks for picmus.zip but should also handle
archive_to_download.zip for manual downloads. Modify the function to return
unzip_dir (src/archive_to_download) after calling unzip, and update the zip file
resolution logic to check for both picmus.zip and archive_to_download.zip files
to support both standard and manual download formats.
In `@zea/data/convert/utils.py`:
- Around line 115-117: The zip extraction in the code is vulnerable to path
traversal attacks where a malicious archive could contain member paths with
traversal sequences like `../` to write files outside the destination directory.
Validate each member path before extraction to ensure the resolved absolute path
remains within the destination directory. For each member in zip_ref.namelist(),
normalize and resolve the full path that would result from extraction, then
verify it starts with the destination directory's absolute path. Only extract
members whose resolved paths are safe. Consider using os.path.normpath and
os.path.abspath for path validation, or alternatively manually extract and write
files by reading from the zip archive and writing to validated target paths.
---
Nitpick comments:
In `@tests/test_display.py`:
- Around line 121-172: The test_scan_conversion_and_inverse function has an
unused angle parameter in both the pytest.mark.parametrize decorator and the
function signature. Remove the angle parameter from the parametrize list (which
appears in all test case tuples) and remove it from the function signature,
since the test uses a fixed theta_range value instead of utilizing the angle
parameter.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 30b8bd34-0d52-4ba9-b081-b7b79c32d193
⛔ Files ignored due to path filters (1)
uv.lockis excluded by!**/*.lock
📒 Files selected for processing (19)
docs/source/environment.rstpyproject.tomltests/data/test_conversion_scripts.pytests/data/test_data_format.pytests/test_display.pyzea/data/convert/__main__.pyzea/data/convert/camus.pyzea/data/convert/echonet.pyzea/data/convert/echonetlvh/README.mdzea/data/convert/echonetlvh/__init__.pyzea/data/convert/echonetlvh/precompute_crop.pyzea/data/convert/picmus.pyzea/data/convert/utils.pyzea/data/file.pyzea/data/file_operations.pyzea/data/spec.pyzea/display.pyzea/scan.pyzea/tools/fit_scan_cone.py
💤 Files with no reviewable changes (3)
- zea/data/convert/echonetlvh/README.md
- zea/data/convert/echonetlvh/precompute_crop.py
- zea/data/file_operations.py
| reversed order (matching cartesian_to_polar_matrix's rot90 column ordering, which is what | ||
| polar_geometry_from_coords_for_interp returns). | ||
| """ | ||
| from keras import ops |
There was a problem hiding this comment.
either remove this inline imports or add backend_equality_check (if that runs that is preferred).
anglefromcone_paramswas actually used in the cartesian -> polar conversion. Now thetip,theta_angleandr_maxare used.LVHProcessor.scan_convertfor exact reconstruction. There is a test for this.huggingface_hub >=1.2for non uv installFile.create, never save an incomplete file.Example of bug, but I've seen more extreme examples that I cannot quickly find now:
Note that the round-trip error is scaled for visualization.
Some useful preprocessing could be to crop the black top from the polar image.
Code for testing
Summary by CodeRabbit
Release Notes
Documentation
Dependencies
New Features
Bug Fixes
Tests