dbdicom.Series.set_coords#
- Series.set_coords(new_coords: dict, dims=(), slice={}, coords={}, **filters)[source]#
Set a dictionary of coordinates.
- Parameters:
- Raises:
ValueError – if the coordinates provided are not properly formatted or have the wrong shape.
See also
Example
Create an empty series:
>>> coords = { ... 'SliceLocation': np.array([0,1,2,0,1,2]), ... 'FlipAngle': np.array([2,2,2,10,10,10]), ... 'RepetitionTime': np.array([1,5,15,1,5,15]), ... } >>> series = db.empty_series(coords)
Change the flip angle of 15 to 12:
>>> coords = series.coords(tuple(coords)) >>> fa = coords['FlipAngle'] >>> fa[np.where(fa==2)] = 5 >>> series.set_coords(coords)
Check the new coordinates:
>>> new_coords = series.coords(dims) >>> new_coords['FlipAngle'] [5,10,5,10,5,10]
Create a new set of coordinates along slice location and acquisition time:
>>> new_coords = { ... 'SliceLocation': np.array([0,0,1,1,2,2]), ... 'AcquisitionTime': np.array([0,60,0,60,0,60]), ... } >>> series.set_coords(new_coords, ('SliceLocation', 'FlipAngle'))
# Inspect the new coordinates - each slice now has two acquisition times corresponding to the flip angles:
>>> coords['SliceLocation'] [0,0,1,1,2,2] >>> coords['AcquisitionTime'] [0,60,0,60,0,60] >>> coords['FlipAngle'] [5,10,5,10,5,10]
# Check that an error is raised if coordinate values have different sizes: >>> new_coords = { … ‘SliceLocation’: np.zeros(24), … ‘AcquisitionTime’: np.ones(25), … } >>> series.set_coords(new_coords, dims) ValueError: Coordinate values must all have the same size
# An error is also raised if they have all the same size but the values are not unique:
>>> new_coords = { ... 'SliceLocation': np.zeros(24), ... 'AcquisitionTime': np.ones(24), ... } >>> series.set_coords(new_coords, dims) ValueError: Coordinate values must all have the same size
# .. or when the number does not match up with the size of the series:
>>> new_coords = { ... 'SliceLocation': np.arange(25), ... 'AcquisitionTime': np.arange(25), ... } >>> series.set_coords(new_coords, dims) ValueError: Shape of coordinates does not match up with the size of the series.