I am trying to build an application that requires quick and easy parsing of MRI protocol data. I want to extract parameters such as, TE time, TR time, number of averages and so on, from EXAR1 files. However, I am struggling with the formatting of EXAR1 file. I have found no documentation on EXAR1 files and have found a thread from a while ago and tried all of the code within said threat: .
For example, here is a link to a freely available EXAR1 file:
So far, I have figured out that EAXR1 files are SQL databases. I have tried using the sqlite3 library in Python to query the database:
# Import python SQL library
import sqlite3
# Connecting to the EXAR1 file
connection = sqlite3.connect('path_to_exar1_file')
cursor = connection.cursor()
# Query for table names
cursor.execute("SELECT name FROM sqlite_master WHERE type='table';")
tables = cursor.fetchall()
# Close the connection
connection.close()
# Display the table names
print(tables)
This returned a list of tables:
[('ElementToInstanceMap',), ('InstanceChangeSet',), ('Instance',), ('Content',), ('Element',), ('ChangeSet',), ('Branch',)]
I then suspect that the parameters are within 'Content.' Looking inside 'Content' I though the data was zlibcompressed so I tried decompressing the data:
import zlib
try:
decompressed_data = zlib.decompress(raw_data).decode("utf-8") # Decompress and convert to text
print("First 500 characters of decompressed data:", decompressed_data[:500]) # Preview first 500 chars
except Exception as e:
print("Decompression failed:", e)
This displays the following error:
Decompression failed: Error -3 while decompressing data: incorrect header check
I am not sure where to go from here. Any help is appreciated.
I am trying to build an application that requires quick and easy parsing of MRI protocol data. I want to extract parameters such as, TE time, TR time, number of averages and so on, from EXAR1 files. However, I am struggling with the formatting of EXAR1 file. I have found no documentation on EXAR1 files and have found a thread from a while ago and tried all of the code within said threat: https://neurostars./t/parsing-exar-files/20237.
For example, here is a link to a freely available EXAR1 file: https://www.magnetomworld.siemens-healthineers/clinical-corner/protocols/musculoskeletal-mri/shoulder-protocol-with-flex-4-coil
So far, I have figured out that EAXR1 files are SQL databases. I have tried using the sqlite3 library in Python to query the database:
# Import python SQL library
import sqlite3
# Connecting to the EXAR1 file
connection = sqlite3.connect('path_to_exar1_file')
cursor = connection.cursor()
# Query for table names
cursor.execute("SELECT name FROM sqlite_master WHERE type='table';")
tables = cursor.fetchall()
# Close the connection
connection.close()
# Display the table names
print(tables)
This returned a list of tables:
[('ElementToInstanceMap',), ('InstanceChangeSet',), ('Instance',), ('Content',), ('Element',), ('ChangeSet',), ('Branch',)]
I then suspect that the parameters are within 'Content.' Looking inside 'Content' I though the data was zlibcompressed so I tried decompressing the data:
import zlib
try:
decompressed_data = zlib.decompress(raw_data).decode("utf-8") # Decompress and convert to text
print("First 500 characters of decompressed data:", decompressed_data[:500]) # Preview first 500 chars
except Exception as e:
print("Decompression failed:", e)
This displays the following error:
Decompression failed: Error -3 while decompressing data: incorrect header check
I am not sure where to go from here. Any help is appreciated.
Share Improve this question asked Feb 4 at 19:23 QuantumQuantum 14 bronze badges1 Answer
Reset to default 0Your decompress was missing a parameter listed on the thread you linked (noted in code below).
The Content table had some rows that looked like "MRI parameters". Hopefully the code below will help:
import sqlite3
import zlib
import json
with sqlite3.connect('Downloads/shoulder_4ch_flex.exar1') as connection:
cursor = connection.cursor()
cursor.execute("SELECT * FROM Content")
rows = cursor.fetchall()
for hash, data, fmt in rows:
decompressed_data = zlib.decompress(data, -zlib.MAX_WBITS).decode()
# missing this ---------------------------^^^^^^^^^^^^^^^
# Validate data
if hash != hashlib.sha1(decompressed_data).hexdigest():
raise RuntimeError('bad hash')
# The JSON data has a header string ending in a semicolon.
decoded_data = decompressed_data.decode()
header, sdata = decoded_data.split(';', 1)
# This content type has a 'Data' key that may be the parameters you are looking for.
if header == 'EDF V1: ContentType=syngo.MR.ExamDataFoundation.Data.EdfProtocolContent':
jdata = json.loads(sdata)
print(jdata['Data'])
break # Just print the first one...there other EdfProtocolContent rows.
Output:
<XProtocol>
{
<Name> "MultiStep Controller"
<ID> 1000001
<Userversion> 666.0
<EVAStringTable>
{
60
400 "Multistep Protocol"
401 "Step"
402 "Inline Composing"
403 "Composing Group"
404 "Last Step"
405 "Composing Function"
406 "Inline Combine"
407 "Enables you to set up a Multistep Protocol."
408 "Indicates the number of the current Step of the Multistep Protocol.\nPress the + button to add a Step at the end of the list.\nPress the - button to delete the current Step."
409 "Invokes Inline Composing."
410 "Identifies all Steps that will be composed."
411 "Defines the last measurement step of a composing function."
412 "Save all measurements of the Multistep Protocol into one series."
413 "Defines the composing algorithm to be used."
414 "Prio recon"
415 "Enables Prio Recon measurement"
416 "Auto Align Spine"
417 "Enables the Auto Align Spine mode in GSP when protocol is open"
422 "Coil Select Mode"
423 "If set to ""Default"",\nglobal settings from the queue menu will be used.\nIf set to ""All Off"",\nboth ""Auto Coil Select"" and ""Coil Memory"" are deactivated."
424 "Auto Coil Select On"
425 "Auto Coil Select Off"
426 "Default"
429 "Wait for user to start"
430 "Load images to graphic segments"
431 "Before measurement"
432 "After measurement"
433 "1st segment"
434 "2nd segment"
435 "3rd segment"
436 "All segments"
445 "Angio"
446 "Spine"
447 "Adaptive"
525 "SD???"
526 "SD"
538 "Normalize"
539 "Homogenize composed data to avoid unwanted local enhancements."
540 "Off"
541 "Weak"
542 "Medium"
543 "Strong"
545 "Diffusion"
546 "Coil Memory On"
547 "Coil Memory Off"
548 "All Off"
616 "Disable auto transfer to RIS"
617 "Single measurement"
618 "Repeated measurement"
620 "Auto open inline display"
621 "Auto close inline display"
622 "Load images to viewer"
623 "Auto store images"
624 "Generate inline position display"
625 "All orientations"
626 "Load images to stamp segments"
627 "Inline movie"
628 "Sag"
629 "Cor"
630 "Tra"
}
... lots more ...