LiberTEM/LiberTEM

View on GitHub
src/libertem/io/dataset/k2is.py

Summary

Maintainability
D
2 days
Test Coverage

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Open

            assert b.is_valid
Severity: Info
Found in src/libertem/io/dataset/k2is.py by bandit

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Open

            assert b.is_valid
Severity: Info
Found in src/libertem/io/dataset/k2is.py by bandit

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Open

            assert b.header['frame_id'] == frame_id
Severity: Info
Found in src/libertem/io/dataset/k2is.py by bandit

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Open

            assert b.is_valid, "first block is not valid!"
Severity: Info
Found in src/libertem/io/dataset/k2is.py by bandit

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Open

                assert predicate(self.get_block_by_index(current_upper))
Severity: Info
Found in src/libertem/io/dataset/k2is.py by bandit

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Open

            assert b.is_valid
Severity: Info
Found in src/libertem/io/dataset/k2is.py by bandit

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Open

            assert b.is_valid
Severity: Info
Found in src/libertem/io/dataset/k2is.py by bandit

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Open

            assert b.is_valid
Severity: Info
Found in src/libertem/io/dataset/k2is.py by bandit

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Open

            assert b.is_valid
Severity: Info
Found in src/libertem/io/dataset/k2is.py by bandit

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Open

            assert b.header['frame_id'] == frame_id
Severity: Info
Found in src/libertem/io/dataset/k2is.py by bandit

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Open

            assert all(b.header['frame_id'] == frame_id
                       for b in blocks)
Severity: Info
Found in src/libertem/io/dataset/k2is.py by bandit

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Open

            assert all(b.header['frame_id'] == frame_id
                       for b in blocks)
Severity: Info
Found in src/libertem/io/dataset/k2is.py by bandit

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Open

            assert b.is_valid, "last block is not valid!"
Severity: Info
Found in src/libertem/io/dataset/k2is.py by bandit

File k2is.py has 849 lines of code (exceeds 400 allowed). Consider refactoring.
Open

import os
import re
import glob
import math
import typing
Severity: Major
Found in src/libertem/io/dataset/k2is.py - About 1 day to fix

    Cyclomatic complexity is too high in method sync_sectors. (30)
    Open

        def sync_sectors(self):
            for b in self.first_blocks():
                assert b.is_valid, "first block is not valid!"
            # sync up all sectors to start with the same `block_count`
            block_with_max_idx = sorted(self.first_blocks(), key=lambda b: b.header['block_count'])[-1]
    Severity: Minor
    Found in src/libertem/io/dataset/k2is.py by radon

    Cyclomatic Complexity

    Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

    Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

    Construct Effect on CC Reasoning
    if +1 An if statement is a single decision.
    elif +1 The elif statement adds another decision.
    else +0 The else statement does not cause a new decision. The decision is at the if.
    for +1 There is a decision at the start of the loop.
    while +1 There is a decision at the while statement.
    except +1 Each except branch adds a new conditional path of execution.
    finally +0 The finally block is unconditionally executed.
    with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
    assert +1 The assert statement internally roughly equals a conditional statement.
    Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
    Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

    Source: http://radon.readthedocs.org/en/latest/intro.html

    K2ISDataSet has 24 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class K2ISDataSet(DataSet):
        """
        Read raw K2IS data sets. They consist of 8 .bin files and one .gtg file.
        Currently, data acquired using the STEMx unit is supported, metadata
        about the nav_shape is read from the .gtg file.
    Severity: Minor
    Found in src/libertem/io/dataset/k2is.py - About 2 hrs to fix

      Cyclomatic complexity is too high in method validate_sync. (11)
      Open

          def validate_sync(self):
              # first blocks should be valid:
              first_blocks = self.first_blocks()
              frame_id = first_blocks[0].header['frame_id']
              for b in first_blocks:
      Severity: Minor
      Found in src/libertem/io/dataset/k2is.py by radon

      Cyclomatic Complexity

      Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

      Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

      Construct Effect on CC Reasoning
      if +1 An if statement is a single decision.
      elif +1 The elif statement adds another decision.
      else +0 The else statement does not cause a new decision. The decision is at the if.
      for +1 There is a decision at the start of the loop.
      while +1 There is a decision at the while statement.
      except +1 Each except branch adds a new conditional path of execution.
      finally +0 The finally block is unconditionally executed.
      with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
      assert +1 The assert statement internally roughly equals a conditional statement.
      Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
      Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

      Source: http://radon.readthedocs.org/en/latest/intro.html

      Cyclomatic complexity is too high in function _k2is_read_ranges_tile_block. (7)
      Open

      @numba.njit(inline='always')
      def _k2is_read_ranges_tile_block(
          slices_arr, fileset_arr, slice_sig_sizes, sig_origins,
          inner_indices_start, inner_indices_stop, frame_indices, sig_size,
          px_to_bytes, bpp, frame_header_bytes, frame_footer_bytes, file_idxs,
      Severity: Minor
      Found in src/libertem/io/dataset/k2is.py by radon

      Cyclomatic Complexity

      Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

      Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

      Construct Effect on CC Reasoning
      if +1 An if statement is a single decision.
      elif +1 The elif statement adds another decision.
      else +0 The else statement does not cause a new decision. The decision is at the if.
      for +1 There is a decision at the start of the loop.
      while +1 There is a decision at the while statement.
      except +1 Each except branch adds a new conditional path of execution.
      finally +0 The finally block is unconditionally executed.
      with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
      assert +1 The assert statement internally roughly equals a conditional statement.
      Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
      Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

      Source: http://radon.readthedocs.org/en/latest/intro.html

      Function sync_sectors has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

          def sync_sectors(self):
              for b in self.first_blocks():
                  assert b.is_valid, "first block is not valid!"
              # sync up all sectors to start with the same `block_count`
              block_with_max_idx = sorted(self.first_blocks(), key=lambda b: b.header['block_count'])[-1]
      Severity: Minor
      Found in src/libertem/io/dataset/k2is.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

      Cyclomatic complexity is too high in method _set_sync_offset. (6)
      Open

          def _set_sync_offset(self):
              self._num_frames_w_shutter_active_flag_set = _get_num_frames_w_shutter_active_flag_set(
                  self._get_syncer(do_sync=False)
              )
              self._native_sync_offset = self._image_count - self._num_frames_w_shutter_active_flag_set
      Severity: Minor
      Found in src/libertem/io/dataset/k2is.py by radon

      Cyclomatic Complexity

      Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

      Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

      Construct Effect on CC Reasoning
      if +1 An if statement is a single decision.
      elif +1 The elif statement adds another decision.
      else +0 The else statement does not cause a new decision. The decision is at the if.
      for +1 There is a decision at the start of the loop.
      while +1 There is a decision at the while statement.
      except +1 Each except branch adds a new conditional path of execution.
      finally +0 The finally block is unconditionally executed.
      with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
      assert +1 The assert statement internally roughly equals a conditional statement.
      Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
      Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

      Source: http://radon.readthedocs.org/en/latest/intro.html

      Cyclomatic complexity is too high in class K2Syncer. (6)
      Open

      class K2Syncer:
          """
          Sync the 8 sectors of a K2IS data set. First, find the first complete frame and the
          last complete frame. Next, sync to the first frame with the shutter_active flag set.
          Finally, validate the first and last frames.
      Severity: Minor
      Found in src/libertem/io/dataset/k2is.py by radon

      Cyclomatic Complexity

      Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

      Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

      Construct Effect on CC Reasoning
      if +1 An if statement is a single decision.
      elif +1 The elif statement adds another decision.
      else +0 The else statement does not cause a new decision. The decision is at the if.
      for +1 There is a decision at the start of the loop.
      while +1 There is a decision at the while statement.
      except +1 Each except branch adds a new conditional path of execution.
      finally +0 The finally block is unconditionally executed.
      with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
      assert +1 The assert statement internally roughly equals a conditional statement.
      Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
      Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

      Source: http://radon.readthedocs.org/en/latest/intro.html

      Cyclomatic complexity is too high in method header. (6)
      Open

          @property
          def header(self):
              if self._header_raw is None:
                  with self.sector:
                      self.sector.seek(self.offset)
      Severity: Minor
      Found in src/libertem/io/dataset/k2is.py by radon

      Cyclomatic Complexity

      Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

      Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

      Construct Effect on CC Reasoning
      if +1 An if statement is a single decision.
      elif +1 The elif statement adds another decision.
      else +0 The else statement does not cause a new decision. The decision is at the if.
      for +1 There is a decision at the start of the loop.
      while +1 There is a decision at the while statement.
      except +1 Each except branch adds a new conditional path of execution.
      finally +0 The finally block is unconditionally executed.
      with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
      assert +1 The assert statement internally roughly equals a conditional statement.
      Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
      Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

      Source: http://radon.readthedocs.org/en/latest/intro.html

      Function _k2is_read_ranges_tile_block has 16 arguments (exceeds 8 allowed). Consider refactoring.
      Open

      def _k2is_read_ranges_tile_block(
      Severity: Major
      Found in src/libertem/io/dataset/k2is.py - About 1 hr to fix

        Function _set_sync_offset has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

            def _set_sync_offset(self):
                self._num_frames_w_shutter_active_flag_set = _get_num_frames_w_shutter_active_flag_set(
                    self._get_syncer(do_sync=False)
                )
                self._native_sync_offset = self._image_count - self._num_frames_w_shutter_active_flag_set
        Severity: Minor
        Found in src/libertem/io/dataset/k2is.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 _k2is_read_ranges_tile_block has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

        def _k2is_read_ranges_tile_block(
            slices_arr, fileset_arr, slice_sig_sizes, sig_origins,
            inner_indices_start, inner_indices_stop, frame_indices, sig_size,
            px_to_bytes, bpp, frame_header_bytes, frame_footer_bytes, file_idxs,
            slice_offset, extra, sig_shape,
        Severity: Minor
        Found in src/libertem/io/dataset/k2is.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 first_block_with_search has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            def first_block_with_search(self, predicate=lambda b: True, step=32 * 8 * 50):
                """
                Binary search variant of `first_block_with`, assuming that predicate is true
                from some index on, and stays true (at least for 10 * step).
                """
        Severity: Minor
        Found in src/libertem/io/dataset/k2is.py - About 45 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 _set_skip_frames_and_nav_shape has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def _set_skip_frames_and_nav_shape(self):
                nav_shape = _get_nav_shape(self._path)
                if nav_shape is not None:
                    # the sync flag appears to be set one frame too late, so
                    # we compensate here by setting a negative _skip_frames value.
        Severity: Minor
        Found in src/libertem/io/dataset/k2is.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

        Function "decode_k2is" has 8 parameters, which is greater than the 7 authorized.
        Open

        def decode_k2is(inp, out, idx, native_dtype, rr, origin, shape, ds_shape):

        A long parameter list can indicate that a new structure should be created to wrap the numerous parameters or that the function is doing too many things.

        Noncompliant Code Example

        With a maximum number of 4 parameters:

        def do_something(param1, param2, param3, param4, param5):
            ...
        

        Compliant Solution

        def do_something(param1, param2, param3, param4):
            ...
        

        Function "_k2is_read_ranges_tile_block" has 16 parameters, which is greater than the 7 authorized.
        Open

            slices_arr, fileset_arr, slice_sig_sizes, sig_origins,
            inner_indices_start, inner_indices_stop, frame_indices, sig_size,
            px_to_bytes, bpp, frame_header_bytes, frame_footer_bytes, file_idxs,
            slice_offset, extra, sig_shape,

        A long parameter list can indicate that a new structure should be created to wrap the numerous parameters or that the function is doing too many things.

        Noncompliant Code Example

        With a maximum number of 4 parameters:

        def do_something(param1, param2, param3, param4, param5):
            ...
        

        Compliant Solution

        def do_something(param1, param2, param3, param4):
            ...
        

        Take the required action to fix the issue indicated by this "FIXME" comment.
        Open

                # FIXME: hardcoded sig_dims

        FIXME tags are commonly used to mark places where a bug is suspected, but which the developer wants to deal with later.

        Sometimes the developer will not have the time or will simply forget to get back to that tag.

        This rule is meant to track those tags and to ensure that they do not go unnoticed.

        Noncompliant Code Example

        def divide(numerator, denominator):
          return numerator / denominator              # FIXME denominator value might be 0
        

        See

        Remove this commented out code.
        Open

            # assert np.mod(len(inp), 3) == 0

        Programmers should not comment out code as it bloats programs and reduces readability.

        Unused code should be deleted and can be retrieved from source control history if required.

        See

        • MISRA C:2004, 2.4 - Sections of code should not be "commented out".
        • MISRA C++:2008, 2-7-2 - Sections of code shall not be "commented out" using C-style comments.
        • MISRA C++:2008, 2-7-3 - Sections of code should not be "commented out" using C++ comments.
        • MISRA C:2012, Dir. 4.4 - Sections of code should not be "commented out"

        There are no issues that match your filters.

        Category
        Status