Skip to content
This repository has been archived by the owner on Apr 21, 2020. It is now read-only.

Commit

Permalink
populate psgRecordData with signal headers
Browse files Browse the repository at this point in the history
some fields are commented out as their value is not yet clear
  • Loading branch information
jmz-b committed Mar 13, 2020
1 parent c232d4b commit 38dc470
Showing 1 changed file with 33 additions and 13 deletions.
46 changes: 33 additions & 13 deletions resources/catalog/somnonetz-pipeline/bin/extract_edf_header
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,50 @@ if __name__ == "__main__":
parser.add_argument('-host', required=True)
parser.add_argument('-user', required=True)
parser.add_argument('-pwd', required=True)

args = parser.parse_args()
args.host = args.host.strip('/') # remove trailing slash from host as pyxnat fails to connect if it's present

xnat = Interface(args.host, user=args.user, password=args.pwd)
scan = xnat.select(f'/project/{args.project}/subject/{args.subject}/experiment/{args.session}/scan/psg')
remote_edf = scan.resources().files().first()
edf_path = remote_edf.get(f'./{remote_edf.label()}')
header = read_header(edf_path)
edf_header = read_header(edf_path)

scan.insert(**{
'scans': 'snet01:psgScanData',
'snet01:psgScanData/edfversion': header.version,
'snet01:psgScanData/patientid': header.local_patient_identification,
'snet01:psgScanData/localrecordid': header.local_recording_identification,
'snet01:psgScanData/recordingstartdate': header.startdate_of_recording,
'snet01:psgScanData/recordingstarttime': header.starttime_of_recording,
'snet01:psgScanData/numberofheaderbytes': header.number_of_bytes_in_header_record,
'snet01:psgScanData/reservedheaderfield': header.reserved,
'snet01:psgScanData/numberofdatarecords': header.number_of_data_records,
# 'snet01:psgScanData/durationofdatarecordseconds': header.duration_of_a_data_record,
'snet01:psgScanData/numberofsignalsindatarecord': header.number_of_signals,
'snet01:psgScanData/edfversion': edf_header.version,
'snet01:psgScanData/patientid': edf_header.local_patient_identification,
'snet01:psgScanData/localrecordid': edf_header.local_recording_identification,
'snet01:psgScanData/recordingstartdate': edf_header.startdate_of_recording,
'snet01:psgScanData/recordingstarttime': edf_header.starttime_of_recording,
'snet01:psgScanData/numberofheaderbytes': edf_header.number_of_bytes_in_header_record,
'snet01:psgScanData/reservedheaderfield': edf_header.reserved,
'snet01:psgScanData/numberofdatarecords': edf_header.number_of_data_records,
'snet01:psgScanData/durationofdatarecordseconds': edf_header.duration_of_a_data_record,
'snet01:psgScanData/numberofsignalsindatarecord': edf_header.number_of_signals,
# 'snet01:psgScanData/psgdevice': '?',
# 'snet01:psgScanData/durationofrecordhours': header.duration_of_a_data_record,
'snet01:psgScanData/durationofrecordhours': edf_header.duration_of_a_data_record / 3600,
# 'snet01:psgScanData/continuousdataflag': '0',
# 'snet01:psgScanData/comment': '',
})

for i, signal_header in enumerate(edf_header.signals):
scan.insert(**{
'scans': 'snet01:psgScanData',
'snet01:psgScanData/records/record/labeldevice': signal_header.label,
'snet01:psgScanData/records/record/labelstandard': signal_header.label,
'snet01:psgScanData/records/record/channelnumberdevice': i,
'snet01:psgScanData/records/record/channelnumberstandard': i,
# 'snet01:psgScanData/records/record/numberofchunks': ,
'snet01:psgScanData/records/record/samplingrate': signal_header.nr_of_samples_in_each_data_record / edf_header.duration_of_a_data_record,
'snet01:psgScanData/records/record/transducertype': signal_header.transducer_type,
'snet01:psgScanData/records/record/physicaldimension': signal_header.physical_dimension,
'snet01:psgScanData/records/record/physicalminimum': signal_header.physical_minimum,
'snet01:psgScanData/records/record/physicalmaximum': signal_header.physical_maximum,
'snet01:psgScanData/records/record/digitalminimum': signal_header.digital_minimum,
'snet01:psgScanData/records/record/digitalmaximum': signal_header.digital_maximum,
# 'snet01:psgScanData/records/record/prefiltering': ,
'snet01:psgScanData/records/record/samplesinrecord': signal_header.nr_of_samples_in_each_data_record,
'snet01:psgScanData/records/record/reserved': signal_header.reserved,
})

0 comments on commit 38dc470

Please sign in to comment.