Skip to content

Commit 4524624

Browse files
Merge branch 'main' into fix_extra_requirement_logic
2 parents 8ff4f8a + e7d4904 commit 4524624

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
* Added direct imports for all base classes from the outer level; you may now call `from neuroconv import BaseDataInterface, BaseTemporalAlignmentInterface, BaseExtractorInterface`. [PR #442](https://github.com/catalystneuro/neuroconv/pull/442)
4848
* Added basic temporal alignment methods to the AudioInterface. `align_starting_time` is split into `align_starting_times` (list of times, one per audio file) and `align_global_starting_time` (shift all by a scalar amount). `align_by_interpolation` and other timestamp-based approaches is not yet implemented for this interface. [PR #402](https://github.com/catalystneuro/neuroconv/pull/402)
4949
* Changed the order of recording properties extraction in `NeuroscopeRecordingInterface` and `NeuroScopeLFPInterface` to make them consistent with each other [PR #466](https://github.com/catalystneuro/neuroconv/pull/466)
50+
* The `ScanImageImagingInterface` has been updated to read metadata from more recent versions of ScanImage [PR #457](https://github.com/catalystneuro/neuroconv/pull/457)
5051

5152
### Testing
5253
* The tests for `automatic_dandi_upload` now follow up-to-date DANDI validation rules for file name conventions. [PR #310](https://github.com/catalystneuro/neuroconv/pull/310)

src/neuroconv/datainterfaces/ophys/scanimage/scanimageimaginginterface.py

+20-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import datetime
12
import json
23
from typing import Optional
34

@@ -12,10 +13,15 @@ def extract_extra_metadata(file_path) -> dict:
1213
ScanImageTiffReader = get_package(
1314
package_name="ScanImageTiffReader", installation_instructions="pip install scanimage-tiff-reader"
1415
)
15-
16-
description = ScanImageTiffReader.ScanImageTiffReader(str(file_path)).description(iframe=0)
17-
extra_metadata = {x.split("=")[0]: x.split("=")[1] for x in description.split("\r") if "=" in x}
18-
16+
src_file = ScanImageTiffReader.ScanImageTiffReader(str(file_path))
17+
extra_metadata = {}
18+
for metadata_string in (src_file.description(iframe=0), src_file.metadata()):
19+
metadata_dict = {
20+
x.split("=")[0].strip(): x.split("=")[1].strip()
21+
for x in metadata_string.replace("\n", "\r").split("\r")
22+
if "=" in x
23+
}
24+
extra_metadata = dict(**extra_metadata, **metadata_dict)
1925
return extra_metadata
2026

2127

@@ -50,6 +56,8 @@ def __init__(
5056

5157
if "state.acq.frameRate" in self.image_metadata:
5258
sampling_frequency = float(self.image_metadata["state.acq.frameRate"])
59+
elif "SI.hRoiManager.scanFrameRate" in self.image_metadata:
60+
sampling_frequency = float(self.image_metadata["SI.hRoiManager.scanFrameRate"])
5361
else:
5462
assert_msg = (
5563
"sampling frequency not found in image metadata, "
@@ -68,6 +76,14 @@ def get_metadata(self) -> dict:
6876
if "state.internal.triggerTimeString" in self.image_metadata:
6977
extracted_session_start_time = dateparse(self.image_metadata["state.internal.triggerTimeString"])
7078
metadata["NWBFile"].update(session_start_time=extracted_session_start_time)
79+
elif "epoch" in self.image_metadata:
80+
# Versions of ScanImage at least as recent as 2020, and possibly earlier, store the start time under keyword
81+
# `epoch`, as a string encoding of a Matlab array, example `'[2022 8 8 16 56 7.329]'`
82+
# dateparse can't cope with this representation, so using strptime directly
83+
extracted_session_start_time = datetime.datetime.strptime(
84+
self.image_metadata["epoch"], "[%Y %m %d %H %M %S.%f]"
85+
)
86+
metadata["NWBFile"].update(session_start_time=extracted_session_start_time)
7187

7288
# Extract many scan image properties and attach them as dic in the description
7389
ophys_metadata = metadata["Ophys"]

0 commit comments

Comments
 (0)