pcntoolkit.dataio.fileio#
Attributes#
Functions#
|
Create an incremental backup of a file using the .bak{n} naming scheme. |
|
Create a mask from a data array or a nifti file |
|
Determine the file extension of a file (e.g. .nii.gz) |
|
Determine the file stem of a file (e.g. /path/to/file.nii.gz -> file) |
|
Determine the file type of a file |
|
Load array from a file. |
|
Load an ascii file into a numpy array |
|
Load a cifti file into a numpy array |
|
Load a nifti file into a numpy array |
|
Load a csv file into a pandas dataframe |
|
Save a numpy array to a file |
|
Save a numpy array to an ascii file |
|
Save a cifti file from a numpy array |
|
Write output to nifti |
|
Save a pandas dataframe to a csv file |
|
Vectorise a 3d image |
Module Contents#
- create_incremental_backup(filepath)#
Create an incremental backup of a file using the .bak{n} naming scheme.
- If the file exists, a backup is created in the same directory with the following format:
original_name.bak{n}.original_extension
where {n} is incremented based on existing backups. If the file does not exist, None is returned.
- create_mask(data_array, mask, verbose=False)#
Create a mask from a data array or a nifti file
Basic usage:
create_mask(data_array, mask, verbose)
- Parameters:
data_array – numpy array containing the data to write out
mask – nifti image containing a mask for the image
verbose – verbose output
- file_extension(filename)#
Determine the file extension of a file (e.g. .nii.gz)
Basic usage:
file_extension(filename)
- Parameters:
filename – name of the file to check
- file_stem(filename)#
Determine the file stem of a file (e.g. /path/to/file.nii.gz -> file)
Basic usage:
file_stem(filename)
- Parameters:
filename – name of the file to check
- file_type(filename)#
Determine the file type of a file
Basic usage:
file_type(filename)
- Parameters:
filename – name of the file to check
- Returns:
str: The file type (‘cifti’, ‘nifti’, ‘text’, or ‘binary’)
- Raises:
ValueError if file type is unknown
- load(filename, mask=None, text=False, vol=True)#
Load array from a file.
A beautiful waterfall of errors.
Basic usage:
load(filename, mask, text, vol)
- Parameters:
filename – name of the file to load
mask – nifti image containing a mask for the image
text – whether to write out a text file
vol – whether to load the image as a volume
- load_ascii(filename)#
Load an ascii file into a numpy array
Basic usage:
load_ascii(filename)
- Parameters:
filename – name of the file to load
- load_cifti(filename, vol=False, mask=None, rmtmp=True)#
Load a cifti file into a numpy array
Basic usage:
load_cifti(filename, vol, mask, rmtmp)
- Parameters:
filename – name of the file to load
vol – whether to load the image as a volume
mask – nifti image containing a mask for the image
rmtmp – whether to remove temporary files
- load_nifti(datafile, mask=None, vol=False)#
Load a nifti file into a numpy array
Basic usage:
load_nifti(datafile, mask, vol, verbose)
- Parameters:
datafile – name of the file to load
mask – nifti image containing a mask for the image
vol – whether to load the image as a volume
verbose – verbose output
- load_pd(filename)#
Load a csv file into a pandas dataframe
Basic usage:
load_pd(filename)
- Parameters:
filename – name of the file to load
- save(data, filename, example=None, mask=None, text=False, dtype=None)#
Save a numpy array to a file
Basic usage:
save(data, filename, example, mask, text, dtype)
- Parameters:
data – numpy array containing the data to write out
filename – where to store it
example – example file to copy the geometry from
mask – nifti image containing a mask for the image
text – whether to write out a text file
dtype – data type for the output image (if different from the image)
- save_ascii(data, filename)#
Save a numpy array to an ascii file
Basic usage:
save_ascii(data, filename)
- Parameters:
data – numpy array containing the data to write out
filename – where to store it
- save_cifti(data, filename, example, mask=None, vol=True, volatlas=None)#
Save a cifti file from a numpy array
Basic usage:
save_cifti(data, filename, example, mask, vol, volatlas)
- Parameters:
data – numpy array containing the data to write out
filename – where to store it
example – example file to copy the geometry from
mask – nifti image containing a mask for the image
vol – whether to load the image as a volume
volatlas – atlas to use for the volume
- save_nifti(data, filename, examplenii, mask, dtype=None)#
Write output to nifti
Basic usage:
save_nifti(data, filename mask, dtype)
- Parameters:
data – numpy array containing the data to write out
filename – where to store it
examplenii – nifti to copy the geometry and data type from
dtype – data type for the output image (if different from the image)
- Mask:
nifti image containing a mask for the image
- save_pd(data, filename)#
Save a pandas dataframe to a csv file
Basic usage:
save_pd(data, filename)
- Parameters:
data – pandas dataframe containing the data to write out
filename – where to store it
- vol2vec(dat, mask, verbose=False)#
Vectorise a 3d image
Basic usage:
vol2vec(dat, mask, verbose)
- Parameters:
dat – numpy array containing the data to write out
mask – nifti image containing a mask for the image
verbose – verbose output
- CIFTI_MAPPINGS = ('dconn', 'dtseries', 'pconn', 'ptseries', 'dscalar', 'dlabel', 'pscalar', 'pdconn', 'dpconn',...#
- CIFTI_VOL_ATLAS = 'Atlas_ROIs.2.nii.gz'#
- path = b'.'#
- path#