예제 #1
0
def detectCells(source, sink = None, method ="SpotDetection", processMethod = all, verbose = False, **parameter):
    """Detect cells in data
    
    This is a main script to start running the cell detection.    
    
    Arguments:
        source (str or array): Image source
        sink (str or None): destination for the results
        method (str or function): 
            ================ ============================================================
            Method           Description
            ================ ============================================================
            "SpotDetection"  uses predefined spot detection pipline
            "Ilastik"        uses predefined pipline with cell classification via Ilastik
            function         a user defined function
            ================ ============================================================
        processMethod (str or all): 'sequential' or 'parallel'. if all its choosen 
                                     automatically
        verbose (bool): print info
        **parameter (dict): parameter for the image procesing sub-routines
    
    Returns:
        
    """
    timer = Timer();
        
    # run segmentation
    if method == "SpotDetection":
        detectCells = ClearMap.ImageProcessing.SpotDetection.detectSpots;
    elif method == 'Ilastik':
        if ClearMap.ImageProcessing.Ilastik.Initialized:
            detectCells = ClearMap.ImageProcessing.IlastikClassification.classifyCells;
            processMethod = 'sequential';  #ilastik does parallel processing so force sequential processing here
        else:
            raise RuntimeError("detectCells: Ilastik not initialized, fix in Settings.py or use SpotDectection method instead!");
    else:
        raise RuntimeError("detectCells: invalid method %s" % str(method));
    
    if processMethod == 'sequential':
        result = sequentiallyProcessStack(source, sink = sink, function = detectCells, verbose = verbose, **parameter);  
    elif processMethod is all or processMethod == 'parallel':
        result = parallelProcessStack(source, sink = sink, function = detectCells, verbose = verbose, **parameter);  
    else:
        raise RuntimeError("detectCells: invalid processMethod %s" % str(processMethod));
    
    if verbose:
        timer.printElapsedTime("Total Cell Detection");
    
    return result;
예제 #2
0
def detectCells(source, sink = None, method ="SpotDetection", processMethod = all, verbose = False, **parameter):
    """Detect cells in data
    
    This is a main script to start running the cell detection.    
    
    Arguments:
        source (str or array): Image source
        sink (str or None): destination for the results
        method (str or function): 
            ================ ============================================================
            Method           Description
            ================ ============================================================
            "SpotDetection"  uses predefined spot detection pipline
            "Ilastik"        uses predefined pipline with cell classification via Ilastik
            function         a user defined function
            ================ ============================================================
        processMethod (str or all): 'sequential' or 'parallel'. if all its choosen 
                                     automatically
        verbose (bool): print info
        **parameter (dict): parameter for the image procesing sub-routines
    
    Returns:
        
    """
    timer = Timer();
        
    # run segmentation
    if method == "SpotDetection":
        detectCells = ClearMap.ImageProcessing.SpotDetection.detectSpots;
    elif method == 'Ilastik':
        if ClearMap.ImageProcessing.Ilastik.Initialized:
            detectCells = ClearMap.ImageProcessing.IlastikClassification.classifyCells;
            processMethod = 'sequential';  #ilastik does parallel processing so force sequential processing here
        else:
            raise RuntimeError("detectCells: Ilastik not initialized, fix in Settings.py or use SpotDectection method instead!");
    else:
        raise RuntimeError("detectCells: invalid method %s" % str(method));
    
    if processMethod == 'sequential':
        result = sequentiallyProcessStack(source, sink = sink, function = detectCells, verbose = verbose, **parameter);  
    elif processMethod is all or processMethod == 'parallel':
        result = parallelProcessStack(source, sink = sink, function = detectCells, verbose = verbose, **parameter);  
    else:
        raise RuntimeError("detectCells: invalid processMethod %s" % str(processMethod));
    
    if verbose:
        timer.printElapsedTime("Total Cell Detection");
    
    return result;
예제 #3
0
def detectCells(jobid,
                source,
                sink=None,
                method="SpotDetection",
                processMethod="sequential",
                verbose=False,
                **parameter):
    """Detect cells in data

    This is a main script to start running the cell detection.

    Arguments:
        source (str or array): Image source
        sink (str or None): destination for the results
        method (str or function):
            ================ ============================================================
            Method           Description
            ================ ============================================================
            "SpotDetection"  uses predefined spot detection pipline
            "Ilastik"        uses predefined pipline with cell classification via Ilastik
            function         a user defined function
            ================ ============================================================
        processMethod (str or all): 'sequential' or 'parallel'. if all its choosen
                                     automatically
        verbose (bool): print info
        **parameter (dict): parameter for the image procesing sub-routines

    TP: added JOBID for cluster jobs

    Returns:
    """
    timer = Timer()

    # run segmentation
    if method == "SpotDetection":
        detectCells = ClearMap.ImageProcessing.SpotDetection.detectSpots
    elif method == 'Ilastik':
        if ClearMap.ImageProcessing.Ilastik.Initialized:
            detectCells = ClearMap.ImageProcessing.IlastikClassification.classifyCells
            processMethod = 'sequential'
            #ilastik does parallel processing so force sequential processing here
        else:
            raise RuntimeError(
                "detectCells: Ilastik not initialized, fix in Settings.py or use SpotDectection method instead!"
            )
            print('Ilastik functionality disabled')
    else:
        raise RuntimeError("detectCells: invalid method %s" % str(method))
    print('ProcessMethod = {}'.format(processMethod))

    if processMethod == 'cluster':
        result, substack = sequentiallyProcessStack_usingCluster(
            jobid,
            pth_update(source),
            sink=pth_update(sink),
            function=detectCells,
            verbose=verbose,
            **parameter)
        if result == 'ENDPROCESS': return 'ENDPROCESS', 'ENDPROCESS'
    elif processMethod == 'sequential':
        result = sequentiallyProcessStack(source,
                                          sink=sink,
                                          function=detectCells,
                                          verbose=verbose,
                                          **parameter)
    elif processMethod is all or processMethod == 'parallel':
        result = parallelProcessStack(source,
                                      sink=sink,
                                      function=detectCells,
                                      verbose=verbose,
                                      **parameter)
    else:
        raise RuntimeError("detectCells: invalid processMethod %s" %
                           str(processMethod))

    if verbose:
        timer.printElapsedTime("Total Cell Detection")

    if processMethod == 'cluster':
        return result, substack
    else:
        return result
def calculateStatistics(
    source,
    sink=None,
    calculateStatisticsParameter=None,
    method="Max",
    remove=True,
    processMethod=all,
    verbose=False,
    **parameter
):
    """Calculate statisticsfrom image data
    
    This is a main script to start extracting statistics of volumetric image data.    
    
    Arguments:
        source (str or array): Image source
        sink (str or None): destination for the results
        calculateStatisticsParameter (dict):
            ========= ==================== ===========================================================
            Name      Type                 Descritption
            ========= ==================== ===========================================================
            *method*  (str or function)    function to extract statistic, must be trivially distributable
                                           if None, do not extract information
            *remove*  (bool)               remove redundant overlap 
            *verbose* (bool or int)        print / plot information about this step                                 
            ========= ==================== ===========================================================
        method (str or function): 
        processMethod (str or all): 'sequential' or 'parallel'. if all its choosen automatically
        verbose (bool): print info
        **parameter (dict): parameter for the image processing sub-routines
    
    Returns:
        list of statistics
    """
    timer = Timer()

    method = getParameter(calculateStatisticsParameter, "method", method)
    remove = getParameter(calculateStatisticsParameter, "remove", remove)
    verbose = getParameter(calculateStatisticsParameter, "verbose", verbose)

    # run segmentation
    if remove:
        parameter = joinParameter({"chunkOverlap": 0}, parameter)

    if processMethod == "sequential":
        result = sequentiallyProcessStack(
            source,
            sink=sink,
            function=calculateStatisticsOnStack,
            join=joinStatistics,
            method=method,
            remove=remove,
            verbose=verbose,
            **parameter
        )
    elif processMethod is all or processMethod == "parallel":
        result = parallelProcessStack(
            source,
            sink=sink,
            function=calculateStatisticsOnStack,
            join=joinStatistics,
            method=method,
            remove=remove,
            verbose=verbose,
            **parameter
        )
    else:
        raise RuntimeError("calculateStatistics: invalid processMethod %s" % str(processMethod))

    if verbose:
        timer.printElapsedTime("Total Time Image Statistics")

    return result
예제 #5
0
def calculateStatistics(source,
                        sink=None,
                        calculateStatisticsParameter=None,
                        method="Max",
                        remove=True,
                        processMethod=all,
                        verbose=False,
                        **parameter):
    """Calculate statisticsfrom image data
    
    This is a main script to start extracting statistics of volumetric image data.    
    
    Arguments:
        source (str or array): Image source
        sink (str or None): destination for the results
        calculateStatisticsParameter (dict):
            ========= ==================== ===========================================================
            Name      Type                 Descritption
            ========= ==================== ===========================================================
            *method*  (str or function)    function to extract statistic, must be trivially distributable
                                           if None, do not extract information
            *remove*  (bool)               remove redundant overlap 
            *verbose* (bool or int)        print / plot information about this step                                 
            ========= ==================== ===========================================================
        method (str or function): 
        processMethod (str or all): 'sequential' or 'parallel'. if all its choosen automatically
        verbose (bool): print info
        **parameter (dict): parameter for the image processing sub-routines
    
    Returns:
        list of statistics
    """
    timer = Timer()

    method = getParameter(calculateStatisticsParameter, "method", method)
    remove = getParameter(calculateStatisticsParameter, "remove", remove)
    verbose = getParameter(calculateStatisticsParameter, "verbose", verbose)

    # run segmentation
    if remove:
        parameter = joinParameter({"chunkOverlap": 0}, parameter)

    if processMethod == 'sequential':
        result = sequentiallyProcessStack(source,
                                          sink=sink,
                                          function=calculateStatisticsOnStack,
                                          join=joinStatistics,
                                          method=method,
                                          remove=remove,
                                          verbose=verbose,
                                          **parameter)
    elif processMethod is all or processMethod == 'parallel':
        result = parallelProcessStack(source,
                                      sink=sink,
                                      function=calculateStatisticsOnStack,
                                      join=joinStatistics,
                                      method=method,
                                      remove=remove,
                                      verbose=verbose,
                                      **parameter)
    else:
        raise RuntimeError("calculateStatistics: invalid processMethod %s" %
                           str(processMethod))

    if verbose:
        timer.printElapsedTime("Total Time Image Statistics")

    return result