CellProfiler/centrosome

View on GitHub
centrosome/threshold.py

Summary

Maintainability
F
5 days
Test Coverage

File threshold.py has 672 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# The help text for various thresholding options whose code resides here is in modules/identify.py


from __future__ import absolute_import
from __future__ import division
Severity: Major
Found in centrosome/threshold.py - About 1 day to fix

    Function get_threshold has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

    def get_threshold(
        threshold_method,
        threshold_modifier,
        image,
        mask=None,
    Severity: Minor
    Found in centrosome/threshold.py - About 2 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function get_mog_threshold has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

    def get_mog_threshold(image, mask=None, object_fraction=0.2):
        """Compute a background using a mixture of gaussians
        
        This function finds a suitable
        threshold for the input image Block. It assumes that the pixels in the
    Severity: Minor
    Found in centrosome/threshold.py - About 2 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function get_otsu_threshold has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

    def get_otsu_threshold(
        image,
        mask=None,
        two_class_otsu=True,
        use_weighted_variance=True,
    Severity: Minor
    Found in centrosome/threshold.py - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function get_threshold has 10 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def get_threshold(
    Severity: Major
    Found in centrosome/threshold.py - About 1 hr to fix

      Function get_global_threshold has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

      def get_global_threshold(threshold_method, image, mask=None, **kwargs):
          """Compute a single threshold over the whole image"""
          if mask is not None and not np.any(mask):
              return 1
      
      
      Severity: Minor
      Found in centrosome/threshold.py - About 1 hr to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function get_mog_threshold has 27 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      def get_mog_threshold(image, mask=None, object_fraction=0.2):
          """Compute a background using a mixture of gaussians
          
          This function finds a suitable
          threshold for the input image Block. It assumes that the pixels in the
      Severity: Minor
      Found in centrosome/threshold.py - About 1 hr to fix

        Function get_per_object_threshold has 8 arguments (exceeds 4 allowed). Consider refactoring.
        Open

        def get_per_object_threshold(
        Severity: Major
        Found in centrosome/threshold.py - About 1 hr to fix

          Function get_robust_background_threshold has 7 arguments (exceeds 4 allowed). Consider refactoring.
          Open

          def get_robust_background_threshold(
          Severity: Major
          Found in centrosome/threshold.py - About 50 mins to fix

            Function get_adaptive_threshold has 6 arguments (exceeds 4 allowed). Consider refactoring.
            Open

            def get_adaptive_threshold(
            Severity: Minor
            Found in centrosome/threshold.py - About 45 mins to fix

              Function get_otsu_threshold has 5 arguments (exceeds 4 allowed). Consider refactoring.
              Open

              def get_otsu_threshold(
              Severity: Minor
              Found in centrosome/threshold.py - About 35 mins to fix

                Function get_adaptive_threshold has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                def get_adaptive_threshold(
                    threshold_method, image, threshold, mask=None, adaptive_window_size=10, **kwargs
                ):
                    """Given a global threshold, compute a threshold per pixel
                    
                Severity: Minor
                Found in centrosome/threshold.py - About 35 mins to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Function sum_of_entropies has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                def sum_of_entropies(image, mask, binary_image):
                    """Bin the foreground and background pixels and compute the entropy 
                    of the distribution of points among the bins
                    """
                    mask = mask.copy()
                Severity: Minor
                Found in centrosome/threshold.py - About 35 mins to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Avoid too many return statements within this function.
                Open

                        return (np.var(fg) * nfg + np.var(bg) * nbg) / (nfg + nbg)
                Severity: Major
                Found in centrosome/threshold.py - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                      return np.sum(hfg * np.log2(hfg)) + np.sum(hbg * np.log2(hbg))
                  Severity: Major
                  Found in centrosome/threshold.py - About 30 mins to fix

                    Function get_per_object_threshold has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                    def get_per_object_threshold(
                        method,
                        image,
                        threshold,
                        mask=None,
                    Severity: Minor
                    Found in centrosome/threshold.py - About 25 mins to fix

                    Cognitive Complexity

                    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                    A method's cognitive complexity is based on a few simple rules:

                    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                    • Code is considered more complex for each "break in the linear flow of the code"
                    • Code is considered more complex when "flow breaking structures are nested"

                    Further reading

                    Similar blocks of code found in 2 locations. Consider refactoring.
                    Open

                                for k in range(class_count):
                                    norm = scipy.stats.norm(class_mean[k], class_std[k])
                                    pixel_class_prob[:, k] = class_prob[k] * norm.pdf(data)
                    Severity: Major
                    Found in centrosome/threshold.py and 1 other location - About 3 hrs to fix
                    centrosome/threshold.py on lines 475..477

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 68.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    Similar blocks of code found in 2 locations. Consider refactoring.
                    Open

                        for k in range(class_count):
                            norm = scipy.stats.norm(class_mean[k], class_std[k])
                            class_gaussian[:, k] = class_prob[k] * norm.pdf(level)
                    Severity: Major
                    Found in centrosome/threshold.py and 1 other location - About 3 hrs to fix
                    centrosome/threshold.py on lines 441..443

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 68.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    Similar blocks of code found in 2 locations. Consider refactoring.
                    Open

                        thresh_out_y_coords = np.linspace(
                            0.5, int(nblocks[1] * increment[1]) - 0.5, thresh_out.shape[1]
                    Severity: Major
                    Found in centrosome/threshold.py and 1 other location - About 1 hr to fix
                    centrosome/threshold.py on lines 276..277

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 49.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    Similar blocks of code found in 2 locations. Consider refactoring.
                    Open

                        thresh_out_x_coords = np.linspace(
                            0.5, int(nblocks[0] * increment[0]) - 0.5, thresh_out.shape[0]
                    Severity: Major
                    Found in centrosome/threshold.py and 1 other location - About 1 hr to fix
                    centrosome/threshold.py on lines 279..280

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 49.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    Similar blocks of code found in 2 locations. Consider refactoring.
                    Open

                        yEnd = int((nblocks[1] - 0.5) * increment[1])
                    Severity: Minor
                    Found in centrosome/threshold.py and 1 other location - About 35 mins to fix
                    centrosome/threshold.py on lines 259..259

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 33.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    Similar blocks of code found in 2 locations. Consider refactoring.
                    Open

                        xEnd = int((nblocks[0] - 0.5) * increment[0])
                    Severity: Minor
                    Found in centrosome/threshold.py and 1 other location - About 35 mins to fix
                    centrosome/threshold.py on lines 261..261

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 33.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    Similar blocks of code found in 2 locations. Consider refactoring.
                    Open

                        if np.product(hfg.shape) == 0:
                            hfg = np.ones((1,), int)
                    Severity: Minor
                    Found in centrosome/threshold.py and 1 other location - About 30 mins to fix
                    centrosome/threshold.py on lines 850..851

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 32.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    Similar blocks of code found in 2 locations. Consider refactoring.
                    Open

                        if np.product(hbg.shape) == 0:
                            hbg = np.ones((1,), int)
                    Severity: Minor
                    Found in centrosome/threshold.py and 1 other location - About 30 mins to fix
                    centrosome/threshold.py on lines 848..849

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 32.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    There are no issues that match your filters.

                    Category
                    Status