Skip to content

Improved internal algorithm for generalized sizecomp #751

Description

@Rick-Methot-NOAA

A user configured a generalized sizecomp with narrow weight bins for the data. SS3 crashed without providing warning. The problem is that when the setup is using weight bins, a narrow population length bin can translate to weight range that is wider than the user-specified weight bins.
@N-DucharmeBarth-NOAA

The code is designed to detect where the population bin is completely within a data bin and assign all of that pop bin to the data bin, and to detect when there are multiple consecutive pop bins that fall within the same data bin range and assign all of them to that range. It also can detect when a pop bin stradles the upper edge of a data bin and apportion that pop bin to the current and nect data bin, then to correctly move on to the next pop bin.
However, the code cannot detect when the upper edge of a pop bin would skip over a data bin. When this happens, no warning is issued and a crash typically occurs.
Resolution: Completely replace the legacy sizefreq translation matrix with the rebin method. This is more efficient and completely robust to bin width specifications.

Activity

  1. added this to the 3.30.24.1 milestone on Feb 2, 2026
  2. Rick-Methot-NOAA commented on Feb 2, 2026

    @Rick-Methot-NOAA
    CollaboratorAuthor

    This routine might be the solution:

    C++ Routine: Linear Area Rebinning
    This implementation takes two vectors representing the boundaries (edges) of the source and destination bins, and one vector for the source counts.
    #include
    #include

    /**

    • Rebins frequency data from one set of boundaries to another.

    • @PARAM src_edges Boundaries of the original bins (size N+1).

    • @PARAM src_counts Frequency/counts in original bins (size N).

    • @PARAM dest_edges Boundaries of the new bins (size M+1).

    • @return Vector of rebinned frequency data (size M).
      */
      std::vector rebin(const std::vector& src_edges,
      const std::vector& src_counts,
      const std::vector& dest_edges) {

      std::vector dest_counts(dest_edges.size() - 1, 0.0);

      for (size_t i = 0; i < dest_counts.size(); ++i) {
      double d_low = dest_edges[i];
      double d_high = dest_edges[i + 1];

       for (size_t j = 0; j < src_counts.size(); ++j) {
           double s_low = src_edges[j];
           double s_high = src_edges[j + 1];
      
           // Calculate the overlap between [d_low, d_high] and [s_low, s_high]
           double overlap_low = std::max(d_low, s_low);
           double overlap_high = std::min(d_high, s_high);
      
           if (overlap_low < overlap_high) {
               double overlap_width = overlap_high - overlap_low;
               double src_bin_width = s_high - s_low;
               
               // Distribute source count proportionally to the overlap area
               dest_counts[i] += src_counts[j] * (overlap_width / src_bin_width);
           }
       }
      

      }
      return dest_counts;
      }

  3. modified the milestones: 3.30.24.1, 3.30.25 on Jun 25, 2026
  4. changed the title [-]need warning and improved logic for generalized sizecomp[/-] [+]Improved internal algorithm for generalized sizecomp[/+] on Oct 26, 2026
  5. added
    change loguse for issues that should appear in change log
    and removed
    in progressThis is being worked on in a branch
    on Oct 26, 2026
  6. moved this from In Progress to Done in ss3-issue-trackeron Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

change loguse for issues that should appear in change logcomposition

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions