Exemplo n.º 1
0
 def from_mrfile(cls, mrfile):
     uid = nimsutil.pack_dicom_uid(mrfile.series_uid)
     epoch = cls.query.filter_by(uid=uid).filter_by(acq=mrfile.acq_no).first()
     if not epoch:
         session = Session.from_mrfile(mrfile)
         if session.timestamp is None or (mrfile.timestamp is not None and session.timestamp > mrfile.timestamp):
             session.timestamp = mrfile.timestamp
         epoch = cls(
                 session = session,
                 timestamp = mrfile.timestamp,
                 duration = datetime.timedelta(0, mrfile.duration or 0),
                 prescribed_duration = datetime.timedelta(0, mrfile.prescribed_duration or 0),
                 uid = uid,
                 series = mrfile.series_no,
                 acq = mrfile.acq_no,
                 description = nimsutil.clean_string(mrfile.series_desc),
                 psd = unicode(mrfile.psd_name),
                 physio_recorded = True,
                 tr = mrfile.tr,
                 te = mrfile.te,
                 ti = mrfile.ti,
                 flip_angle = mrfile.flip_angle,
                 pixel_bandwidth = mrfile.pixel_bandwidth,
                 num_slices = mrfile.num_slices,
                 num_timepoints = mrfile.num_timepoints or 1,
                 num_averages = mrfile.num_averages,
                 num_echos = mrfile.num_echos,
                 receive_coil_name = unicode(mrfile.receive_coil_name),
                 num_receivers = mrfile.num_receivers,
                 protocol_name = unicode(mrfile.protocol_name),
                 scanner_name = unicode(mrfile.scanner_name),
                 size_x = mrfile.size[0],
                 size_y = mrfile.size[1],
                 fov = unicode(str(mrfile.fov)),
                 mm_per_vox = unicode(str(mrfile.mm_per_vox)),
                 scan_type = unicode(mrfile.scan_type),
                 num_bands = mrfile.num_bands,
                 effective_echo_spacing = mrfile.effective_echo_spacing,
                 phase_encode_undersample = mrfile.phase_encode_undersample,
                 slice_encode_undersample = mrfile.slice_encode_undersample,
                 acquisition_matrix = unicode(str(mrfile.acquisition_matrix)),
                 num_mux_cal_cycle = mrfile.num_mux_cal_cycle if mrfile.filetype == u'pfile' else None,    # hack for pfile
                 qa_status = u'pending',
                 # to unpack fov, mm_per_vox, and acquisition_matrix: np.fromstring(str(mm)[1:-1],sep=',')
                 )
     return epoch
Exemplo n.º 2
0
 def get_metadata(filename):
     try:
         pf = nimsutil.pfile.PFile(filename)
     except nimsutil.pfile.PFileError:
         md = None
     else:
         md = Metadata()
         md.datatype = u"GE PFile"
         md.exam_no = pf.exam_no
         md.series_no = pf.series_no
         md.acq_no = pf.acq_no
         md.exam_uid = nimsutil.pack_dicom_uid(pf.exam_uid)
         md.series_uid = nimsutil.pack_dicom_uid(pf.series_uid)
         md.psd_name = unicode(pf.psd_name)
         md.physio_flag = pf.physio_flag
         md.series_desc = nimsutil.clean_string(pf.series_desc)
         md.timestamp = pf.timestamp
         md.duration = pf.duration
         all_groups = [rg.id for rg in ResearchGroup.query.all()]
         md.subj_code, md.subj_fn, md.subj_ln, md.subj_dob = nimsutil.parse_subject(pf.patient_name, pf.patient_dob)
         md.group_name, md.exp_name = nimsutil.parse_patient_id(pf.patient_id, ResearchGroup.get_all_ids())
     return md
Exemplo n.º 3
0
 def get_metadata(filename):
     try:
         dcm = nimsutil.dicomutil.DicomFile(filename)
     except nimsutil.dicomutil.DicomError:
         md = None
     else:
         md = Metadata()
         md.datatype = u"Dicom Files"
         md.exam_no = dcm.exam_no
         md.series_no = dcm.series_no
         md.acq_no = dcm.acq_no
         md.exam_uid = nimsutil.pack_dicom_uid(dcm.exam_uid)
         md.series_uid = nimsutil.pack_dicom_uid(dcm.series_uid)
         md.psd_name = unicode(dcm.psd_name)
         md.physio_flag = dcm.physio_flag
         md.series_desc = nimsutil.clean_string(dcm.series_desc)
         md.timestamp = dcm.timestamp
         md.duration = dcm.duration
         md.subj_code, md.subj_fn, md.subj_ln, md.subj_dob = nimsutil.parse_subject(
             dcm.patient_name, dcm.patient_dob
         )
         md.group_name, md.exp_name = nimsutil.parse_patient_id(dcm.patient_id, ResearchGroup.get_all_ids())
     return md
Exemplo n.º 4
0
 def name(self):
     return nimsutil.clean_string(self.label)
Exemplo n.º 5
0
 def name(self):
     return nimsutil.clean_string(self.datatype)