ASLtk base classes and functions
ASLData class API
ASLData
Source code in asltk/asldata.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 | |
__call__(spec)
Object caller to expose the image data.
Examples:
>>> data = ASLData(pcasl='./tests/files/t1-mri.nrrd')
>>> type(data('pcasl'))
<class 'asltk.utils.io.ImageIO'>
>>> type(data('pcasl').get_as_numpy())
<class 'numpy.ndarray'>
>>> np.min(data('pcasl').get_as_numpy())
0
Returns:
| Type | Description |
|---|---|
ndarray
|
The data placed in the ASLData object |
Source code in asltk/asldata.py
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 | |
__init__(**kwargs)
ASLData constructor
The basic data needed to represent ASL data are: - The full path to load the image file - The Labeling Duration (LD) array - The Post-labeling Delay (PLD) array
If none of these are provided, a null ASLData object is created, which can be further populated using the get/set methods.
The constructor supports classic ASL data, multi-TE, and Diffusion-Weighted (DW) ASL protocols.
There are specific get/set methods for TE/DW data. If TE/DW is not provided, those properties are set to None.
To provide TE or DW values, use the te_values or dw_values keyword arguments.
Examples:
By default, the LD and PLD arrays are empty lists.
>>> data = ASLData()
>>> data.get_ld()
[]
>>> data.get_pld()
[]
>>> data = ASLData(te_values=[13.0, 20.2, 50.5, 90.5, 125.2])
>>> data.get_te()
[13.0, 20.2, 50.5, 90.5, 125.2]
>>> data = ASLData(dw_values=[13.0, 20.2, 50.5, 90.5, 125.2])
>>> data.get_dw()
[13.0, 20.2, 50.5, 90.5, 125.2]
Other Parameters:
| Name | Type | Description |
|---|---|---|
pcasl |
str
|
The ASL data full path with filename. Defaults to ''. |
m0 |
str
|
The M0 data full path with filename. Defaults to ''. |
ld_values |
list
|
The LD values. Defaults to []. |
pld_values |
list
|
The PLD values. Defaults to []. |
te_values |
list
|
The TE values. Defaults to None. |
dw_values |
list
|
The DW values. Defaults to None. |
average_m0 |
bool
|
If True, average the M0 image across the first dimension. This may be helpful for MRI acquisitions that collect an subset sample of M0 volumes and take the average of it. Defaults to False. |
Source code in asltk/asldata.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | |
__len__()
Return the number of volumes in the ASL data.
This method returns the number of volumes in the ASL data based on the pCASL image format.
Returns:
| Name | Type | Description |
|---|---|---|
int |
The number of volumes in the ASL data considering the |
Source code in asltk/asldata.py
319 320 321 322 323 324 325 326 327 328 329 330 331 | |
copy()
Make a copy of the ASLData object. This method creates a deep copy of the ASLData object, including all its attributes and data. It is useful when you want to preserve the original object while working with a modified version.
Note
This method uses copy.deepcopy to ensure that all nested objects
are also copied, preventing any unintended side effects from
modifying the original object.
Examples:
>>> data = ASLData(pcasl='./tests/files/t1-mri.nrrd')
>>> data_copy = data.copy()
>>> type(data_copy)
<class 'asltk.asldata.ASLData'>
Returns:
| Name | Type | Description |
|---|---|---|
ASLData |
A new instance of ASLData that is a deep copy of the original object. |
Source code in asltk/asldata.py
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 | |
get_dw()
Obtain the Diffusion b values array
Source code in asltk/asldata.py
257 258 259 | |
get_ld()
Obtain the LD array values
Source code in asltk/asldata.py
202 203 204 | |
get_pld()
Obtain the PLD array values
Source code in asltk/asldata.py
221 222 223 | |
get_te()
Obtain the TE array values
Source code in asltk/asldata.py
240 241 242 | |
set_dw(dw_values)
Set the Diffusion b values.
The proper way to inform the values here is using a list of int or float data. The total quantity of values depends on the image acquisition protocol.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dw_values
|
list
|
The values to be adjusted for DW array |
required |
Source code in asltk/asldata.py
261 262 263 264 265 266 267 268 269 270 271 272 | |
set_image(image, spec, **kwargs)
Insert an image necessary to define the ASL data processing.
The spec parameters specifies what is the type of image to be used in
ASL processing step. Choose one of the options: m0 for the M0 volume,
pcasl for the pCASL data.
Note
The image can be a full path to the image file or a numpy array.
In case the image parameter is a path, then the method will load
the image file directly and associate it with the spec parameter.
However, if the image is a numpy array, then the method will
pass it to the ASLData object image data regarding the spec
parameter as well.
Examples:
>>> data = ASLData()
>>> path_m0 = './tests/files/m0.nii.gz' # M0 file with shape (5,35,35)
>>> data.set_image(path_m0, spec='m0')
>>> data('m0').get_as_numpy().shape
(5, 35, 35)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
str
|
The image to be used. |
required |
spec
|
str
|
The type of image being used in the ASL processing. |
required |
Source code in asltk/asldata.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | |
set_ld(ld_values)
Set the LD values.
The proper way to inform the values here is using a list of int or float data. The total quantity of values depends on the image acquisition protocol.
The list length for LD must be equal to PLD list length.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ld_values
|
list
|
The values to be adjusted for LD array |
required |
Source code in asltk/asldata.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 | |
set_pld(pld_values)
Set the PLD values.
The proper way to inform the values here is using a list of int or float data. The total quantity of values depends on the image acquisition protocol.
The list length for PLD must be equal to LD list length.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pld_values
|
list
|
The values to be adjusted for PLD array |
required |
Source code in asltk/asldata.py
225 226 227 228 229 230 231 232 233 234 235 236 237 238 | |
set_te(te_values)
Set the TE values.
The proper way to inform the values here is using a list of int or float data. The total quantity of values depends on the image acquisition protocol.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
te_values
|
list
|
The values to be adjusted for TE array |
required |
Source code in asltk/asldata.py
244 245 246 247 248 249 250 251 252 253 254 255 | |
Auxiliary Methods API
Logging Configuration
MRI Parameters Class API
The MRI parameters are defined here.
The paper references is listed below, which can be used to get more information about some measures:
[1] Leonie Petitclerc, et al. "Ultra-long-TE arterial spin labeling reveals rapid and brain-wide blood-to-CSF water transport in humans", Neuroimage (2021). DOI: 10.1016/j.neuroimage.2021.118755
[2] R B Buxton, et al. "A general kinetic model for quantitative perfusion imaging with arterial spin labeling". Magn Reson Med (1998). PMID: 9727941 DOI: 10.1002/mrm.1910400308
MRIParameters
Source code in asltk/mri_parameters.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | |
__init__()
Creates the basic MRIParameters object to define the main MRI constants and values for ASL processing
To see all the parameters listed in the class, one can call print the
values using the default print() function
Source code in asltk/mri_parameters.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | |
get_constant(param)
Collect a parameter value from a defined type
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
param
|
str
|
The specific parameter that should return the storage |
required |
Raises:
| Type | Description |
|---|---|
AttributeError
|
The parameter type must be already defined in the |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
The parameter value storage in the object instance |
Source code in asltk/mri_parameters.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | |
set_constant(value, param)
Set a different value for a parameter defined in the MRIParameter class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float
|
The value to be assumed in the parameter |
required |
param
|
str
|
The parameter that will receive the new value |
required |
Raises:
| Type | Description |
|---|---|
AttributeError
|
The parameter type must be already defined in the |
Source code in asltk/mri_parameters.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | |