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

add scan_line_rate, grid_spacing and origin_coords from scanimage metadata #328

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@

* Add InscopixImagingExtractor: [#276](https://github.com/catalystneuro/roiextractors/pull/276)
* Updated testing workflows to include python 3.12, m1/intel macos, and dev tests to check neuroconv: [PR #317](https://github.com/catalystneuro/roiextractors/pull/317)
* Updated `parse_metadata()` from `scaimagetiff_utils` to include `scan_line_rate`, `grid_spacing`, `grid_spacing_unit`,`origin_coords`, `origin_coords_unit`

### Fixes

Original file line number Diff line number Diff line change
@@ -95,6 +95,12 @@ def parse_metadata(metadata: dict) -> dict:
- frames_per_slice
- channel_names
- num_channels
- scan_line_rate,
- grid_spacing,
- grid_spacing_unit,
- origin_coords,
- origin_coords_unit,
- roi_metadata,

Parameters
----------
@@ -119,18 +125,34 @@ def parse_metadata(metadata: dict) -> dict:
active_channels = parse_matlab_vector(metadata["SI.hChannels.channelsActive"])
channel_indices = np.array(active_channels) - 1 # Account for MATLAB indexing
channel_names = np.array(metadata["SI.hChannels.channelName"].split("'")[1::2])
scan_line_rate = 1 / float(metadata["SI.hRoiManager.linePeriod"])
channel_names = channel_names[channel_indices].tolist()
num_channels = len(channel_names)
if "RoiGroups" in metadata.keys():
roi_metadata = metadata["RoiGroups"]
pauladkisson marked this conversation as resolved.
Show resolved Hide resolved
else:
roi_metadata = None
roi_metadata = metadata["RoiGroups"]
grid_spacing = None
grid_spacing_unit = "n.a"
origin_coords = None
origin_coords_unit = "n.a"
if roi_metadata["imagingRoiGroup"]["rois"].__contains__("scanfields"):
scanfields = roi_metadata["imagingRoiGroup"]["rois"]["scanfields"]
fov_size_in_um = np.array(scanfields["sizeXY"])
frame_dimension = np.array(scanfields["pixelResolutionXY"])
grid_spacing = fov_size_in_um / frame_dimension
grid_spacing_unit = "micrometers"
origin_coords = scanfields["centerXY"]
origin_coords_unit = "micrometers"

metadata_parsed = dict(
sampling_frequency=sampling_frequency,
num_channels=num_channels,
num_planes=num_planes,
frames_per_slice=frames_per_slice,
channel_names=channel_names,
scan_line_rate=scan_line_rate,
grid_spacing=grid_spacing,
grid_spacing_unit=grid_spacing_unit,
origin_coords=origin_coords,
origin_coords_unit=origin_coords_unit,
roi_metadata=roi_metadata,
)
return metadata_parsed
10 changes: 10 additions & 0 deletions tests/test_scanimage_utils.py
Original file line number Diff line number Diff line change
@@ -70,6 +70,11 @@ def test_parse_matlab_vector_invalid():
"num_planes": 20,
"frames_per_slice": 24,
"channel_names": ["Channel 1"],
"scan_line_rate": 15847.40847329236,
"grid_spacing": [0.01757812, 0.01757812],
"grid_spacing_unit": "micrometers",
"origin_coords": [0, 0],
"origin_coords_unit": "micrometers",
"roi_metadata": {
"imagingRoiGroup": {
"ver": 1,
@@ -147,6 +152,11 @@ def test_parse_matlab_vector_invalid():
"num_planes": 2,
"frames_per_slice": 2,
"channel_names": ["Channel 1", "Channel 4"],
"scan_line_rate": 15843.868185354244,
"grid_spacing": None,
"grid_spacing_unit": "n.a",
"origin_coords": None,
"origin_coords_unit": "n.a",
"roi_metadata": {
"imagingRoiGroup": {
"ver": 1,
Loading