Utility

Utility objects and functions

class heudiconv.utils.File(name, executable=False)

Helper for a file entry in the create_tree/@with_tree

It allows to define additional settings for entries

class heudiconv.utils.SeqInfo(total_files_till_now, example_dcm_file, series_id, dcm_dir_name, unspecified2, unspecified3, dim1, dim2, dim3, dim4, TR, TE, protocol_name, is_motion_corrected, is_derived, patient_id, study_description, referring_physician_name, series_description, sequence_name, image_type, accession_number, patient_age, patient_sex, date, series_uid)
TE

Alias for field number 11

TR

Alias for field number 10

accession_number

Alias for field number 21

date

Alias for field number 24

dcm_dir_name

Alias for field number 3

dim1

Alias for field number 6

dim2

Alias for field number 7

dim3

Alias for field number 8

dim4

Alias for field number 9

example_dcm_file

Alias for field number 1

image_type

Alias for field number 20

is_derived

Alias for field number 14

is_motion_corrected

Alias for field number 13

patient_age

Alias for field number 22

patient_id

Alias for field number 15

patient_sex

Alias for field number 23

protocol_name

Alias for field number 12

referring_physician_name

Alias for field number 17

sequence_name

Alias for field number 19

series_description

Alias for field number 18

series_id

Alias for field number 2

series_uid

Alias for field number 25

study_description

Alias for field number 16

total_files_till_now

Alias for field number 0

unspecified2

Alias for field number 4

unspecified3

Alias for field number 5

class heudiconv.utils.StudySessionInfo(locator, session, subject)
locator

Alias for field number 0

session

Alias for field number 1

subject

Alias for field number 2

class heudiconv.utils.TempDirs

A helper to centralize handling and cleanup of dirs

heudiconv.utils.assure_no_file_exists(path)

Check if file or symlink (git-annex?) exists, and if so – remove

heudiconv.utils.clear_temp_dicoms(item_dicoms)

Ensures DICOM temporary directories are safely cleared

heudiconv.utils.create_file_if_missing(filename, content)

Create file if missing, so we do not override any possibly introduced changes

heudiconv.utils.create_tree(path, tree, archives_leading_dir=True)

Given a list of tuples (name, load) or a dict create such a tree

if load is a tuple or a dict itself – that would create either a subtree or an archive with that content and place it into the tree if name ends with .tar.gz

heudiconv.utils.docstring_parameter(*sub)

Borrowed from https://stackoverflow.com/a/10308363/6145776

heudiconv.utils.get_known_heuristic_names()

Return a list of heuristic names present under heudiconv/heuristics

heudiconv.utils.is_readonly(path)

Return True if it is a fully read-only file (dereferences the symlink)

heudiconv.utils.json_dumps_pretty(j, indent=2, sort_keys=True)

Given a json structure, pretty print it by colliding numeric arrays into a line.

If resultant structure differs from original – throws exception

heudiconv.utils.load_heuristic(heuristic)

Load heuristic from the file, return the module

heudiconv.utils.load_json(filename)

Load data from a json file

filename : str
Filename to load data from.

data : dict

heudiconv.utils.safe_copyfile(src, dest, overwrite=False)

Copy file but blow if destination name already exists

heudiconv.utils.save_json(filename, data, indent=4, sort_keys=True, pretty=False)

Save data to a json file

filename : str
Filename to save data in.
data : dict
Dictionary to save in json file.

indent : int, optional sort_keys : bool, optional pretty : bool, optional

heudiconv.utils.set_readonly(path, read_only=True)

Make file read only or writeable while preserving “access levels”

So if file was not readable by others, it should remain not readable by others.

path : str read_only : bool, optional

If True (default) - would make it read-only. If False, would make it writeable for levels where it is readable
heudiconv.utils.slim_down_info(j)

Given an aggregated info structure, removes excessive details

Such as CSA fields, and SourceImageSequence which on Siemens files could be huge and not providing any additional immediately usable information. If needed, could be recovered from stored DICOMs

heudiconv.utils.treat_infofile(filename)

Tune up generated .json file (slim down, pretty-print for humans).