deid.utils package

Submodules

deid.utils.actions module

deid.utils.actions.get_func(function_name)[source]

Get_func will return a function that is defined from a string.

the function is assumed to be in this file

Parameters:a function from globals based on a name string (return) –
deid.utils.actions.get_timestamp(item_date, item_time=None, jitter_days=None, format=None)[source]

Get_timestamp will return (default) a UTC timestamp.

This will have some date and (optional) time. A different format can be provided to change default behavior. eg: “%Y%m%d”

deid.utils.actions.parse_keyvalue_pairs(pairs)[source]

Given a listing of extra arguments, parse into lookup dict.

deid.utils.actions.parse_value(dicom, value, item=None, field=None, funcs=None)[source]

Parse_value will parse the value field of an action.

This function returns either: 1. the string (string or from function) 2. a variable looked up (var:FieldName)

deid.utils.fileio module

deid.utils.fileio.get_installdir()[source]

Get installation directory of the application

deid.utils.fileio.get_temporary_name(prefix=None, ext=None)[source]

Get a temporary name.

Get a temporary name, can be used for a directory or file. This does so without creating the file, and adds an optional prefix

Parameters:
  • prefix (if defined, add the prefix after deid) –
  • ext (if defined, return the file extension appended. Do not specify ".") –
deid.utils.fileio.is_number(value)[source]

Determine if the value for a field is numeric

deid.utils.fileio.read_file(filename, mode='r')[source]

Read a file.

Parameters:
  • filename (the name of the file to write to) –
  • mode (the mode to open the file, defaults to read (r)) –
deid.utils.fileio.read_json(filename, mode='r', ordered_dict=False)[source]

Open a file, “filename” and read the string as json

Parameters:
  • filename (the name of the file to write to) –
  • mode (the mode to open the file, defaults to read (r)) –
  • ordered_dict (If true, return an OrderedDict (default is False)) –
deid.utils.fileio.recursive_find(base, pattern=None)[source]

Recursively find files that match a pattern.

recursive find will yield dicom files in all directory levels below a base path. It uses get_dcm_files to find the files in the bases.

Parameters:
  • base (the base directory to search) –
  • pattern (a pattern to match. If None, defaults to "*") –
deid.utils.fileio.to_int(value)[source]

Convert a value (value) to int, if found to be otherwise

deid.utils.fileio.write_file(filename, content, mode='w')[source]

Write to file.

write_file will open a file, “filename” and write content, “content” and properly close the file

Parameters:
  • filename (the name of the file to write to) –
  • content (the content to write to file) –
  • mode (the mode to open the file, defaults to write (w)) –
deid.utils.fileio.write_json(json_obj, filename, mode='w', print_pretty=True)[source]

Write a json object to file

Parameters:
  • json_obj (the dict to print to json) –
  • filename (the output file to write to) –
  • pretty_print (if True, will use nicer formatting) –

Module contents