From 239de68ec4838ef9f883e44be177ed57141bbf6a Mon Sep 17 00:00:00 2001 From: William T Clarke Date: Thu, 18 Apr 2024 14:28:13 +0100 Subject: [PATCH] ENH: twix mixed headers (#135) * Catch an odd case where there were XA like headers in VX scan. * Update changelog --- CHANGELOG.md | 1 + spec2nii/Siemens/twixfunctions.py | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c9993f6..d50924c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ This document contains the Spec2nii release history in reverse chronological ord --------------------------------- - Refinements and improvements to the GE SVS pipeline from Mark Mikkelsen. - Add support for older jMRUI text formats which have a slightly different syntax. With thanks to Donnie Cameron. +- Handle odd case of XA like .twix headers in a VX baseline scan 0.7.3 (Tuesday 12th March 2024) ------------------------------- diff --git a/spec2nii/Siemens/twixfunctions.py b/spec2nii/Siemens/twixfunctions.py index f5c0198..e5c3b0c 100644 --- a/spec2nii/Siemens/twixfunctions.py +++ b/spec2nii/Siemens/twixfunctions.py @@ -880,7 +880,17 @@ def examineTwix(twixObj, fileName, mraid): def extractTwixMetadata(mapVBVDHdr, original_file): """Pass to appropriate extractTwixMetadata function for software version.""" if xa_or_vx(mapVBVDHdr) == 'vx': - return extractTwixMetadata_vx(mapVBVDHdr, original_file) + try: + return extractTwixMetadata_vx(mapVBVDHdr, original_file) + except KeyError as original_err: + try: + print(f'VX-line scanner headers caused KeyError {original_err}.') + print('Trying XA interpreter. ') + return extractTwixMetadata_xa(mapVBVDHdr, original_file) + except Exception as backup_err: + print(f'XA interpreter failed with reason {backup_err}. Raising original error.') + raise original_err + elif xa_or_vx(mapVBVDHdr) == 'xa': return extractTwixMetadata_xa(mapVBVDHdr, original_file)