slideflow.util¶
This module contains a variety of utility functions used throughout the package.
- class slideflow.util.FileFormatter(fmt=None, datefmt=None, style='%')¶
- format(record)¶
Format the specified record as text.
The record’s attribute dictionary is used as the operand to a string formatting operation which yields the returned string. Before formatting the dictionary, a couple of preparatory steps are carried out. The message attribute of the record is computed using LogRecord.getMessage(). If the formatting string uses the time (as determined by a call to usesTime(), formatTime() is called to format the event time. If there is exception information, it is formatted using formatException() and appended to the message.
- class slideflow.util.LogFormatter(fmt=None, datefmt=None, style='%')¶
- format(record)¶
Format the specified record as text.
The record’s attribute dictionary is used as the operand to a string formatting operation which yields the returned string. Before formatting the dictionary, a couple of preparatory steps are carried out. The message attribute of the record is computed using LogRecord.getMessage(). If the formatting string uses the time (as determined by a call to usesTime(), formatTime() is called to format the event time. If there is exception information, it is formatted using formatException() and appended to the message.
- class slideflow.util.ProgressBar(ending_val, starting_val=0, bar_length=20, endtext='', show_eta=False, show_counter=False, counter_text='', leadtext='', mp_counter=None, mp_lock=None)¶
Flexible progress bar with dynamic ETA monitoring and multiprocessing support.
- __init__(ending_val, starting_val=0, bar_length=20, endtext='', show_eta=False, show_counter=False, counter_text='', leadtext='', mp_counter=None, mp_lock=None)¶
- class slideflow.util.TqdmLoggingHandler(*args, **kwargs)¶
Avoid tqdm progress bar interruption by logger’s output to console
- __init__(*args, **kwargs)¶
Initialize the handler.
If stream is not specified, sys.stderr is used.
- emit(record)¶
Emit a record.
If a formatter is specified, it is used to format the record. The record is then written to the stream with a trailing newline. If exception information is present, it is formatted using traceback.print_exception and appended to the stream. If the stream has an ‘encoding’ attribute, it is used to determine how to do the output to the stream.
- slideflow.util.choice_input(prompt, valid_choices, default=None, multi_choice=False, input_type=<class 'str'>)¶
Prompts user for multi-choice input.
- slideflow.util.float_input(prompt, default=None, valid_range=None)¶
Prompts user for float input.
- slideflow.util.get_model_config(model_path)¶
Loads model configuration JSON file.
- slideflow.util.get_relative_tfrecord_paths(root, directory='')¶
Returns relative tfrecord paths with respect to the given directory.
- slideflow.util.get_slide_paths(slides_dir)¶
Get all slide paths from a given directory containing slides.
- slideflow.util.get_slides_from_model_manifest(model_path, dataset=None)¶
Get list of slides from a model manifest.
- slideflow.util.global_path(root, path_string)¶
Returns global path from a local path.
- slideflow.util.int_input(prompt, default=None)¶
Prompts user for int input.
- slideflow.util.load_json(filename)¶
Reads JSON data from file.
- slideflow.util.make_dir(_dir)¶
Makes a directory if one does not already exist, in a manner compatible with multithreading.
- slideflow.util.multi_warn(arr, compare, msg)¶
Logs multiple warnings.
- slideflow.util.path_input(prompt, root, default=None, create_on_invalid=False, filetype=None, verify=True)¶
Prompts user for directory input.
- slideflow.util.path_to_ext(path)¶
Returns extension of a file path string.
- slideflow.util.path_to_name(path)¶
Returns name of a file, without extension, from a given full path string.
- slideflow.util.read_annotations(annotations_file)¶
Read an annotations file.
- slideflow.util.relative_path(path, root)¶
Returns a relative path, from a given root directory.
- slideflow.util.tfrecord_heatmap(tfrecord, slide, tile_px, tile_um, tile_dict, outdir)¶
Creates a tfrecord-based WSI heatmap using a dictionary of tile values for heatmap display.
- Parameters
tfrecord (str) – Path to tfrecord.
slide (str) – Path to whole-slide image.
tile_dict (dict) – Dictionary mapping tfrecord indices to a tile-level value for display in heatmap format.
tile_px (int) – Tile width in pixels.
tile_um (int) – Tile width in microns.
outdir (str) – Path to directory in which to save images.
- Returns
Dictionary mapping slide names to dict of statistics (mean, median, above_0, and above_1)
- slideflow.util.to_onehot(val, max)¶
Converts value to one-hot encoding
- slideflow.util.update_results_log(results_log_path, model_name, results_dict)¶
Dynamically update results_log when recording training metrics.
- slideflow.util.write_json(data, filename)¶
Writes data to JSON file.
- slideflow.util.yes_no_input(prompt, default='no')¶
Prompts user for yes/no input.