-
Notifications
You must be signed in to change notification settings - Fork 20
improvment of the cellvizio reader: reading meta informations from hexcode directly #150
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request improves the CellVizio MKT file reader by extracting metadata information directly from the file content rather than using hardcoded values. The changes enable reading image dimensions, frame rate, field of view, and patient ID from embedded metadata, and expose this information through properties for display in the UI.
Changes:
- Replaced hardcoded width/height/fps values with dynamic metadata extraction from MKT file content
- Added
getMetaInfo()andgetMostRelevantMetaInfo()methods to parse metadata from file - Added
meta_dataandmeta_data_dictproperties to expose metadata for UI display
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| self.mpp_x = self.fovx/self.fi.width # approximate number for gastroflex, 250 ym field of view, 576 px | ||
| self.mpp_y = self.fovy/self.fi.height |
Copilot
AI
Feb 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential division by zero if width or height metadata is missing or zero. The mpp_x and mpp_y calculations will fail if self.fi.width or self.fi.height is 0 (which would happen if the metadata keys are not found, since the default is 0). Add validation to ensure width and height are non-zero before performing these calculations, or provide sensible fallback values.
exact/util/cellvizio.py
Outdated
| metaStart = fileContent.rfind(b'allowed_egain_eoffset_pairs=') | ||
| metaEnd = fileContent.find(b'<CEND', metaStart) | ||
| metaInfo = fileContent[metaStart:metaEnd].decode('utf-8') |
Copilot
AI
Feb 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the '<CEND' marker is not found, find() will return -1, resulting in an incorrect slice that includes content from the start position to near the beginning of the file. Add validation to check if metaEnd is -1 and handle this case appropriately.
| metaStart = fileContent.rfind(b'allowed_egain_eoffset_pairs=') | |
| metaEnd = fileContent.find(b'<CEND', metaStart) | |
| metaInfo = fileContent[metaStart:metaEnd].decode('utf-8') | |
| metaStart = fileContent.rfind(b'allowed_egain_eoffset_pairs=') | |
| if metaStart == -1: | |
| # expected metadata start marker not found | |
| self.fileHandle.close() | |
| print("Meta information start marker 'allowed_egain_eoffset_pairs=' not found.") | |
| return "" | |
| metaEnd = fileContent.find(b'<CEND', metaStart) | |
| if metaEnd == -1: | |
| # expected metadata end marker not found | |
| self.fileHandle.close() | |
| print("Meta information end marker '<CEND' not found.") | |
| return "" | |
| metaInfo = fileContent[metaStart:metaEnd].decode('utf-8') | |
| self.fileHandle.close() |
|
|
||
| self.fovx = float(meta.get('fovx', 250)) | ||
| self.fovy = float(meta.get('fovy', 250)) | ||
| print(f"fovx: {self.fovx}, fovy: {self.fovy}") |
Copilot
AI
Feb 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This print statement should be removed or replaced with proper logging. Use logger.debug() instead for debug output in production code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, let's do this with the next commit.
exact/util/cellvizio.py
Outdated
| # find start position with fileContent.find(b'allowed_egain_eoffset_pairs=') that searches for the byte sequence | ||
| metaStart = fileContent.rfind(b'allowed_egain_eoffset_pairs=') | ||
| metaEnd = fileContent.find(b'<CEND', metaStart) | ||
| metaInfo = fileContent[metaStart:metaEnd].decode('utf-8') |
Copilot
AI
Feb 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The decode operation assumes UTF-8 encoding but provides no error handling if the metadata contains invalid UTF-8 sequences. Consider adding error handling with errors='ignore' or errors='replace' parameter, or catching UnicodeDecodeError to handle corrupted metadata gracefully.
| metaInfo = fileContent[metaStart:metaEnd].decode('utf-8') | |
| metaInfo = fileContent[metaStart:metaEnd].decode('utf-8', errors='replace') |
| key, value = line.split('=') | ||
| if key == 'framerate': | ||
| relevantInfo['framerate'] = value | ||
| relevantInfo['duration_seconds'] = self.fi.nImages / float(relevantInfo['framerate']) | ||
| elif key == 'width': | ||
| relevantInfo['width'] = value | ||
| elif key == 'height': | ||
| relevantInfo['height'] = value | ||
| elif key == 'fovx': | ||
| relevantInfo['fovx'] = value | ||
| elif key == 'fovy': | ||
| relevantInfo['fovy'] = value | ||
| elif key == 'patient_id': | ||
| relevantInfo['patient_id'] = value |
Copilot
AI
Feb 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The key from the split operation is not stripped of whitespace, which could cause comparison failures if there's any leading or trailing whitespace in the metadata. Consider using key.strip() when comparing against expected key names to make the parsing more robust.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally not a problem in MKT File format.
|
With this code, we now have a better functionality of different MKT image sizes, because we now have access to the correct image width and height of the MKT file, instead of hard coding the size. |
See copilot comment, it's sensible to close the filehandle after using it. Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Removed print statement Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Maybe not essential, but also doesn't hurt. Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Added caching for meta_data Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
remove old code Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
Nice feature :-) |
directly reading meta informations from hex code.
Also added more informations of the MKT file to the UI info panel.