dbdicom.Series.unique#

Series.unique(*tags, sortby=(), slice={}, coords={}, exclude=False, return_locs=False, **filters) ndarray[source]#

Return the unique values of an attribute, sorted by any number of variables.

Parameters:
  • tag – either a keyword string or a (group, element) tag of a DICOM data element.

  • sortby (tuple, optional) – Dimensions of the resulting array. If sortby is not provided, then an array of unique values is returned.

Returns:

a sorted array of unique values of the attribute, with dimensions as specified by dims. If dims is provided, the result has the dimensions of dims and each element of the array is an array unique values.

Return type:

np.ndarray

See also

value unique_affines coords gridcoords

Example

Create a zero-filled series with 3 slice dimensions:

>>> loc = np.arange(4)
>>> fa = [2, 15, 30]
>>> tr = [2.5, 5.0]
>>> coords = {
...     'SliceLocation': np.arange(4),
...     'FlipAngle': [2, 15, 30],
...     'RepetitionTime': [2.5, 5.0] }
>>> series = db.zeros((128,128,8,3,2), coords)

Recover the unique values of any coordinate, such as the flip angle:

>>> series.value('FlipAngle')
[ 2. 15. 30.]

List the flip angles for each slice location separately:

>>> fa = series.unique('FlipAngle', sortby=('SliceLocation', ))
>>> fa[0]
[ 2. 15. 30.]
>>> fa[3]
[ 2. 15. 30.]

List the flip angles for each slice location and repetition time:

>>> fa = series.unique('FlipAngle', sortby=('SliceLocation', 'RepetitionTime'))
>>> fa.shape
(4, 2)
>>> fa[1,1]
[ 2. 15. 30.]

Getting the values for a non-existing attribute produces an empty array:

>>> gbbl = series.unique('Gobbledigook')
>>> gbbl.size
0
>>> gbbl.shape
(0,)

Getting a non-existing attribute for each slice location produces an array of the expected shape, where each element is an empty array:

>>> gbbl = series.unique('Gobbledigook', sortby=('SliceLocation',))
>>> gbbl.shape
(4,)
>>> gbbl.size
4
>>> gbbl[-1].size
0