dbdicom.merge#
- dbdicom.merge(records: list, into: Record | None = None, inplace=False) Record [source]#
Merge a list of records into a single new record.
- Parameters:
records (list) – list of Records of the same type
into (Record, optional) – location for the merged series. If None is provided, the merged series is created in the parent of the first record in the list. Defaults to None.
inplace (bool, optional) – If set to True, the original series will be removed and only the merged series retain. If set to False the original series will contine to exist. Default is False.
- Returns:
the merged record.
- Return type:
new_record (Record)
Example
The first patient in the hollywood demo database currently has two studies
>>> database = db.dro.database_hollywood() >>> jb = database.patients(PatientName = 'James Bond')[0] >>> len(jb.studies()) 2
If we merge them together, the patient now has three studies, the original MRI and Xray studies, and the new merged study:
>>> new_study = db.merge(jb.studies()) >>> len(jb.studies()) 3 >>> jb.StudyDescription ['MRI', 'New Study', 'Xray']
Since the original MRI and Xray studies had two series each, the new study now has 2+2=4 series:
>>> len(new_study.series()) 4
We have used here the default setting of
inplace=False
, so the original series are preserved. To see what happens withinplace=True
, lets merge all 3 studies of the patient:>>> single_jb_study = db.merge(jb.studies(), inplace=True)
Since we have merged in place, the original 3 studies have been removed and there is now only one study left.
>>> len(jb.studies()) 1
The new study now groups the 8 series that were in the original 3 studies:
>>> len(single_jb_study.series()) 8