text
stringlengths
0
828
repo = Repo()
commitobj = repo.commit(gitref)
blob = commitobj.tree[_delta_dir() + filename]
return blob.data_stream.read()"
3936,"def get(self, key, _else=None):
""""""The method to get an assets value
""""""
with self._lock:
self.expired()
# see if everything expired
try:
value = self._dict[key].get()
return value
except KeyError:
return _else
except ValueError:
return _else"
3937,"def set(self, key, value, expires=None, future=None):
""""""Set a value
""""""
# assert the values above
with self._lock:
try:
self._dict[key].set(value, expires=expires, future=future)
except KeyError:
self._dict[key] = moment(value, expires=expires, future=future, lock=self._lock)
return value"
3938,"def values(self):
""""""Will only return the current values
""""""
self.expired()
values = []
for key in self._dict.keys():
try:
value = self._dict[key].get()
values.append(value)
except:
continue
return values"
3939,"def has_key(self, key):
""""""Does the key exist?
This method will check to see if it has expired too.
""""""
if key in self._dict:
try:
self[key]
return True
except ValueError:
return False
except KeyError:
return False
return False"
3940,"def dicom2db(file_path, file_type, is_copy, step_id, db_conn, sid_by_patient=False, pid_in_vid=False,
visit_in_path=False, rep_in_path=False):
""""""Extract some meta-data from a DICOM file and store in a DB.
Arguments:
:param file_path: File path.
:param file_type: File type (should be 'DICOM').
:param is_copy: Indicate if this file is a copy.
:param step_id: Step ID
:param db_conn: Database connection.
:param sid_by_patient: Rarely, a data set might use study IDs which are unique by patient
(not for the whole study).
E.g.: LREN data. In such a case, you have to enable this flag. This will use PatientID + StudyID as a session ID.
:param pid_in_vid: Rarely, a data set might mix patient IDs and visit IDs. E.g. : LREN data. In such a case, you
to enable this flag. This will try to split PatientID into VisitID and PatientID.
:param visit_in_path: Enable this flag to get the visit ID from the folder hierarchy instead of DICOM meta-data
(e.g. can be useful for PPMI).
:param rep_in_path: Enable this flag to get the repetition ID from the folder hierarchy instead of DICOM meta-data
(e.g. can be useful for PPMI).
:return: A dictionary containing the following IDs : participant_id, visit_id, session_id, sequence_type_id,
sequence_id, repetition_id, file_id.
""""""
global conn
conn = db_conn
tags = dict()
logging.info(""Extracting DICOM headers from '%s'"" % file_path)
try:
dcm = dicom.read_file(file_path)
dataset = db_conn.get_dataset(step_id)
tags['participant_id'] = _extract_participant(dcm, dataset, pid_in_vid)
if visit_in_path:
tags['visit_id'] = _extract_visit_from_path(
dcm, file_path, pid_in_vid, sid_by_patient, dataset, tags['participant_id'])
else:
tags['visit_id'] = _extract_visit(dcm, dataset, tags['participant_id'], sid_by_patient, pid_in_vid)
tags['session_id'] = _extract_session(dcm, tags['visit_id'])
tags['sequence_type_id'] = _extract_sequence_type(dcm)
tags['sequence_id'] = _extract_sequence(tags['session_id'], tags['sequence_type_id'])
if rep_in_path:
tags['repetition_id'] = _extract_repetition_from_path(dcm, file_path, tags['sequence_id'])
else:
tags['repetition_id'] = _extract_repetition(dcm, tags['sequence_id'])
tags['file_id'] = extract_dicom(file_path, file_type, is_copy, tags['repetition_id'], step_id)
except InvalidDicomError: