dbdicom.Series.shape#
- Series.shape(dims=('InstanceNumber',), mesh=True, slice={}, coords={}, exclude=False, **filters) tuple [source]#
Return the shape of the series along given dimensions.
- Parameters:
dims (tuple, optional) – Dimensions along which the shape is to be determined. If dims is not provided, the shape of the flattened series is returned. Defaults to None.
- Returns:
one value for each element of dims.
- Return type:
- Raises:
ValueError – if the shape in the specified dimensions is ambiguous (because the number of slices is not unique at each location)
ValueError – if the shape in the specified dimensions is not well defined (because there is no slice at one or more locations).
See also
Example
Create a zero-filled series with 3 dimensions.
>>> coords = { >>> 'SliceLocation': np.arange(4), >>> 'FlipAngle': [2, 15, 30], >>> 'RepetitionTime': [2.5, 5.0] } >>> series = db.zeros((128,128,4,3,2), coords)
Check the shape of a flattened series: >>> series.shape() (24,)
Check the shape along all 3 dimensions:
>>> dims = tuple(coords) >>> series.shape(dims) (4, 3, 2)
Swap the first two dimensions:
>>> series.shape((dims[1], dims[0], dims[2])) (3, 4, 2)
Determine the shape along another DICOM attribute:
>>> series.shape(('FlipAngle', 'InstanceNumber')) (3, 8)
The shape of an empty series is zero along any dimension:
>>> series.new_sibling().shape(dims) (0, 0, 0)
If one or more of the dimensions is not defined in the header, this raises an error:
>>> series.shape(('FlipAngle', 'Gobbledigook')) ValueError: series shape is not well defined in dimensions (FlipAngle, Gobbledigook, ) --> Some of the dimensions are not defined in the header. --> Hint: use Series.value() to find the undefined values.
An error is also raised if the values are defined, but are not unique. In this case, all acquisition times are the same so this raises an error:
>>> series.shape(('FlipAngle', 'AcquisitionTime')) ValueError: series shape is ambiguous in dimensions (FlipAngle, AcquisitionTime, ) --> Multiple slices exist at some or all locations. --> Hint: use Series.unique() to list the values at all locations.