How to use the deid.logger.bot.info function in deid

To help you get started, we’ve selected a few deid examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pydicom / deid / deid / main.py View on Github external
if output_folder is None:
        if args.do_print is False:
            output_folder = tempfile.mkdtemp()

    # If a deid is given, check against format
    if args.deid is not None:
        from deid.config import load_deid
        params = load_deid(args.deid)
        if params['format'] != args.format:
            bot.error("Format in deid (%s) doesn't match choice here (%s) exiting." %(params['format'],
                                                                                      args.format))

    # Get list of dicom files
    base = args.folder
    if base is None:
        bot.info("No input folder specified, will use demo dicom-cookies.")
        base = get_dataset('dicom-cookies')
    basename = os.path.basename(base)
    dicom_files = get_files(base)

    # Does the user want to inspect files?
    if args.action == "inspect":
        from deid.dicom import has_burned_pixels
        has_burned_pixels(dicom_files)
        sys.exit(0) 


    do_get = False
    do_put = False
    ids = None
    if args.action == "all":
        bot.info("GET and PUT identifiers from %s" %(basename))
github pydicom / deid / deid / identifiers / tasks.py View on Github external
def check_item(item):
    '''print item fields and values to screen
    '''
    for key,val in item.items():
        bot.info("%s: %s" %(key,val))
github pydicom / deid / deid / main / inspect.py View on Github external
pass the different levels of criteria
    """

    # If a deid is given, check against format
    deid = args.deid
    if deid is not None:
        params = load_deid(deid)
        if params["format"] != args.format:
            bot.error(
                "Format in deid (%s) doesn't match choice here (%s) exiting."
                % (params["format"], args.format)
            )
    # Get list of dicom files
    base = args.folder
    if base is None:
        bot.info("No input folder specified, will use demo dicom-cookies.")
        base = get_dataset("dicom-cookies")

    dicom_files = list(
        get_files(base, pattern=args.pattern)
    )  # todo : consider using generator functionality
    result = has_burned_pixels(dicom_files, deid=deid)

    print("\nSUMMARY ================================\n")
    if result["clean"]:
        bot.custom(
            prefix="CLEAN", message="%s files" % len(result["clean"]), color="CYAN"
        )

    if result["flagged"]:
        for group, files in result["flagged"].items():
            bot.flag("%s %s files" % (group, len(files)))
github pydicom / deid / deid / dicom / pixels / clean.py View on Github external
take a dicom image and a list of pixel coordinates, and return
        a cleaned file (if output file is specified) or simply plot 
        the cleaned result (if no file is specified)
    
        Parameters
        ==========
            add_padding: add N=margin pixels of padding
            margin: pixels of padding to add, if add_padding True
            fix_interpretation: fix the photometric interpretation if found off
        """

        if not self.results:
            bot.warning("Use %s.detect() to find coordinates first." % self)

        else:
            bot.info("Scrubbing %s." % self.dicom_file)

            # Load in dicom file, and image data
            dicom = read_file(self.dicom_file, force=True)
            pixel_data = getattr(dicom, pixel_data_attribute)

            # Get expected and actual length of the pixel data (bytes, expected does not include trailing null byte)
            expected_length = get_expected_length(dicom)
            actual_length = len(pixel_data)
            padded_expected_length = expected_length + expected_length % 2
            full_length = expected_length / 2 * 3  # upsampled data is a third larger
            full_length += (
                1 if full_length % 2 else 0
            )  # trailing padding byte if even length

            # If we have YBR_FULL_2, must be RGB to obtain pixel data
            if (
github pydicom / deid / deid / identifiers / utils.py View on Github external
def save_identifiers(ids,output_folder=None):
    '''save_identifiers will parse over ids, and ensure that content
    is string (json serializable)
    '''
    if output_folder is None:
        output_folder = tempfile.mkdtemp()
    output_file = "%s/deid-ids.pkl" %output_folder
    bot.info("Writing ids to %s" %output_file)
    result = pickle.dump(ids,open(output_file,"wb"))
    return result
github pydicom / deid / deid / identifiers / utils.py View on Github external
def load_identifiers(identifiers_file):
    '''load_identifiers (currently) just loads a pickle file
    '''
    bot.info("Loading %s" %identifiers_file)
    result = pickle.load(open(identifiers_file,"rb"))
    return result
github pydicom / deid / deid / main / identifiers.py View on Github external
# GET identifiers

    if do_get is True:
        ids = get_identifiers(dicom_files)

    if do_put is True:
        cleaned_files = replace_identifiers(
            dicom_files=dicom_files,
            ids=ids,
            deid=args.deid,
            overwrite=args.overwrite,
            output_folder=output_folder,
        )

        bot.info("%s %s files at %s" % (len(cleaned_files), args.format, output_folder))
github pydicom / deid / deid / main / identifiers.py View on Github external
output_folder = args.outfolder
    if output_folder is None:
        output_folder = tempfile.mkdtemp()

    # If a deid is given, check against format
    if args.deid is not None:
        params = load_deid(args.deid)
        if params["format"] != args.format:
            bot.error(
                "Format in deid (%s) doesn't match choice here (%s) exiting."
                % (params["format"], args.format)
            )
    # Get list of dicom files
    base = args.input
    if base is None:
        bot.info("No input folder specified, will use demo dicom-cookies.")
        base = get_dataset("dicom-cookies")
    basename = os.path.basename(base)
    dicom_files = list(get_files(base))  # todo : consider using generator functionality

    do_get = False
    do_put = False
    ids = None
    if args.action == "all":
        bot.info("GET and PUT identifiers from %s" % (basename))
        do_get = True
        do_put = True

    elif args.action == "get":
        do_get = True
        bot.info("GET and PUT identifiers from %s" % (basename))
github pydicom / deid / deid / config / __init__.py View on Github external
(later in the list overrides earlier loaded).
            default_base: load the default base before the user customizations. 
        '''
        if deid is None:
            deid = []

        if not isinstance(deid,list):
            deid = [deid]

        if base is True:
            deid.append(default_base)

        self._files = deid

        if len(deid) == 0:
            bot.info('You can add custom deid files with .load().')
        self.deid = load_combined_deid(deid)