Unidata/MetPy

View on GitHub

Showing 106 of 141 total issues

Function thickness_hydrostatic has a Cognitive Complexity of 21 (exceeds 15 allowed). Consider refactoring.
Open

def thickness_hydrostatic(pressure, temperature, mixing_ratio=None,
                          molecular_weight_ratio=mpconsts.nounit.epsilon, bottom=None,
                          depth=None):
    r"""Calculate the thickness of a layer via the hypsometric equation.

Severity: Minor
Found in src/metpy/calc/thermo.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 _merge_mandatory_temps has a Cognitive Complexity of 21 (exceeds 15 allowed). Consider refactoring.
Open

    def _merge_mandatory_temps(self, merged, parts, section, qcman, bgl, plast):
        """Process and merge mandatory temperature sections."""
        num_levels = len(parts[section]['PRES'])
        start_level = {
            'TTAA': 1,
Severity: Minor
Found in src/metpy/io/gempak.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

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

    uag, vag = ageostrophic_wind(z.T, u.T, v.T, 100. * units.kilometer,
                                 100. * units.kilometer, latitude)
Severity: Major
Found in tests/calc/test_kinematics.py and 1 other location - About 1 hr to fix
tests/calc/test_kinematics.py on lines 580..581

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 39.

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

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

    uag, vag = ageostrophic_wind(z.T, u.T, v.T, 100. * units.kilometer,
                                 100. * units.kilometer, latitude)
Severity: Major
Found in tests/calc/test_kinematics.py and 1 other location - About 1 hr to fix
tests/calc/test_kinematics.py on lines 568..569

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 39.

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

Function find_axis_number has a Cognitive Complexity of 19 (exceeds 15 allowed). Consider refactoring.
Open

    def find_axis_number(self, axis):
        """Return the dimension number of the axis corresponding to the given identifier.

        Parameters
        ----------
Severity: Minor
Found in src/metpy/xarray.py - About 55 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 plot has a Cognitive Complexity of 19 (exceeds 15 allowed). Consider refactoring.
Open

    def plot(self, plotter, data_dict):
        """Plot a collection of data using this layout for a station plot.

        This function iterates through the entire specified layout, pulling the fields named
        in the layout from `data_dict` and plotting them using `plotter` as specified
Severity: Minor
Found in src/metpy/plots/station_plot.py - About 55 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 advection has 13 arguments (exceeds 10 allowed). Consider refactoring.
Open

def advection(
Severity: Major
Found in src/metpy/calc/kinematics.py - About 50 mins to fix

    Function __init__ has a Cognitive Complexity of 18 (exceeds 15 allowed). Consider refactoring.
    Open

        def __init__(self, prod):
            """Initialize the values and labels from the product."""
            # Don't worry about super() since we're using our own lut assembled sequentially
            self.labels = []
            self.lut = []
    Severity: Minor
    Found in src/metpy/io/nexrad.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 obsdata has a Cognitive Complexity of 18 (exceeds 15 allowed). Consider refactoring.
    Open

        def obsdata(self):
            """Return the internal cached data."""
            if getattr(self, '_obsdata', None) is None:
                # Use a copy of data so we retain all of the original data passed in unmodified
                data = self.data
    Severity: Minor
    Found in src/metpy/plots/declarative.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

    Avoid deeply nested control flow statements.
    Open

                        if var2 is not None:
                            sounding[var2][i] = outdata[var2]
                i += 1
    Severity: Major
    Found in src/metpy/io/gempak.py - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                              if (self.grid_meta_int.missing_flag and idat == imiss):
                                  grid[j, i] = self.prod_desc.missing_float
                              else:
                                  if first:
                                      grid[j, i] = self.grid_meta_real.reference
      Severity: Major
      Found in src/metpy/io/gempak.py - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                                if ibit > 32:
                                    ibit -= 32
                                    iword += 1
        
        
        Severity: Major
        Found in src/metpy/io/gempak.py - About 45 mins to fix

          Function _decode_msg13 has a Cognitive Complexity of 18 (exceeds 15 allowed). Consider refactoring.
          Open

              def _decode_msg13(self, msg_hdr):
                  data = self._buffer_segment(msg_hdr)
                  if data:
                      data = struct.Struct(f'>{len(data) // 2:d}h').unpack(data)
                      # Legacy format doesn't have date/time and has fewer azimuths
          Severity: Minor
          Found in src/metpy/io/nexrad.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

          Avoid deeply nested control flow statements.
          Open

                              for param, val in sounding.items():
                                  if (param in ['PRES', 'TEMP', 'DWPT',
                                                'DRCT', 'SPED', 'HGHT']):
                                      adata[param] = val[i - 1]
                                      bdata[param] = val[iabove]
          Severity: Major
          Found in src/metpy/io/gempak.py - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                    if jshft > 0:
                                        jshft -= 32
                                        idat2 = self._fortran_ishift(packed_buffer[iword + 1], jshft)
                                        idat |= idat2
            
            
            Severity: Major
            Found in src/metpy/io/gempak.py - About 45 mins to fix

              Function _decode_msg31 has a Cognitive Complexity of 18 (exceeds 15 allowed). Consider refactoring.
              Open

                  def _decode_msg31(self, msg_hdr):
                      msg_start = self._buffer.set_mark()
                      data_hdr = self._buffer.read_struct(self.msg31_data_hdr_fmt)
                      if data_hdr.compression:
                          log.warning('Compressed message 31 not supported!')
              Severity: Minor
              Found in src/metpy/io/nexrad.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

              Avoid deeply nested control flow statements.
              Open

                                      if parts[section]['PRES'][i] != self.prod_desc.missing_float:
                                          qcman.append(parts[section]['PRES'][i])
              
              
              Severity: Major
              Found in src/metpy/io/gempak.py - About 45 mins to fix

                Function _unpack_packet_special_graphic_symbol has a Cognitive Complexity of 18 (exceeds 15 allowed). Consider refactoring.
                Open

                    def _unpack_packet_special_graphic_symbol(self, code, in_sym_block):
                        type_map = {3: 'Mesocyclone', 11: '3D Correlated Shear', 12: 'TVS',
                                    26: 'ETVS', 13: 'Positive Hail', 14: 'Probable Hail',
                                    15: 'Storm ID', 19: 'HDA', 25: 'STI Circle'}
                        point_feature_map = {1: 'Mesocyclone (ext.)', 3: 'Mesocyclone',
                Severity: Minor
                Found in src/metpy/io/nexrad.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

                Avoid deeply nested control flow statements.
                Open

                                    while not found:
                                        if sounding[var1][iabove] != missing:
                                            found = True
                                        else:
                                            iabove += 1
                Severity: Major
                Found in src/metpy/io/gempak.py - About 45 mins to fix

                  Function interpolate_to_grid has 12 arguments (exceeds 10 allowed). Consider refactoring.
                  Open

                  def interpolate_to_grid(x, y, z, interp_type='linear', hres=50000,
                  Severity: Major
                  Found in src/metpy/interpolate/grid.py - About 45 mins to fix
                    Severity
                    Category
                    Status
                    Source
                    Language