Skip to content

added new peak finder, optimized code - #84

Merged
iprafols merged 26 commits into
masterfrom
peak_finder_two_power_law
Dec 20, 2025
Merged

added new peak finder, optimized code#84
iprafols merged 26 commits into
masterfrom
peak_finder_two_power_law

Conversation

@iprafols

Copy link
Copy Markdown
Owner

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new two-power-law peak finder implementation and optimizes existing code, particularly in the statistics computation and random forest classifier modules.

  • Added PeakFinderTwoPowerLaw class with fitting logic for spectra analysis
  • Optimized compute_stats function by removing redundant type conversions and reorganizing calculations
  • Refactored predict_proba method to extract tree probability computation into a separate function

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 20 comments.

Show a summary per file
File Description
py/squeze/utils.py Added serialization support for np.int16 type
py/squeze/stats_utils.py Optimized compute_stats with dtype changes, added global probability constants, and removed conditional printing logic
py/squeze/random_forest_classifier.py Extracted predict_proba_tree function and updated dtype for indexs parameter; contains unreachable code after early returns
py/squeze/peak_finder_two_power_law.py New file implementing two-power-law peak finder with convergent fitting algorithm; contains spelling errors and incorrect NaN comparison
py/squeze/peak_finder_power_law.py Added optional return_bestfit parameter; contains spelling error in variable name
py/squeze/model.py Simplified probability calculation by removing NaN checks; old logic retained as comments
Comments suppressed due to low confidence (4)

py/squeze/random_forest_classifier.py:384

  • Unreachable code after return statement. Lines 366-384 will never execute and should be removed.
        output = np.zeros((len(X), self.num_categories))

        for tree_index in np.arange(self.num_trees):
            proba = np.zeros((len(X), self.num_categories))
            children_left = self.trees[tree_index]["children_left"]
            children_right = self.trees[tree_index]["children_right"]
            features = self.trees[tree_index]["feature"]
            thresholds = self.trees[tree_index]["threshold"]
            tree_proba = self.trees[tree_index]["proba"]
            indexs = np.arange(X.shape[0], dtype=int)
            if len(children_left) > sys.getrecursionlimit():
                sys.setrecursionlimit(int(len(children_left) * 1.2))
            search_nodes(X, children_left, children_right, features, thresholds,
                            tree_proba, proba, indexs, 0)
            output += proba

        output /= self.num_trees

        return output

py/squeze/model.py:47

  • This comment appears to contain commented-out code.
        #if np.isnan(row["PROB_CLASS3"]):
        #    prob = np.nan
        #else:
        #    prob = row["PROB_CLASS3"] + row["PROB_CLASS30"]

py/squeze/model.py:53

  • This comment appears to contain commented-out code.
        #if np.isnan(row["PROB_CLASS30"]):
        #    prob = np.nan
        #else:
        #    prob = row["PROB_CLASS30"]

py/squeze/random_forest_classifier.py:362

  • This statement is unreachable.
        output = np.array([
            predict_proba_tree(
                X,
                self.trees[tree_index]["children_left"],
                self.trees[tree_index]["children_right"],
                self.trees[tree_index]["feature"],
                self.trees[tree_index]["threshold"],
                self.trees[tree_index]["proba"],
                self.num_categories,
            )
            for tree_index in np.arange(self.num_trees)
        ]).sum() / self.num_trees

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

Comment thread py/squeze/peak_finder_two_power_law.py Outdated
Comment thread py/squeze/random_forest_classifier.py Outdated
Comment thread py/squeze/peak_finder_two_power_law.py Outdated
Comment thread py/squeze/model.py Outdated
Comment thread py/squeze/peak_finder_two_power_law.py Outdated
Comment thread py/squeze/peak_finder_two_power_law.py Outdated
Comment thread py/squeze/peak_finder_two_power_law.py Outdated
Comment thread py/squeze/model.py Outdated
Comment thread py/squeze/peak_finder_power_law.py
Comment thread py/squeze/peak_finder_two_power_law.py

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 25 out of 35 changed files in this pull request and generated 14 comments.

Comments suppressed due to low confidence (1)

py/squeze/tests/test_peakfinder.py:1

  • Missing space after '#' in comment. Should be '# find peak indices' for consistency with Python style guidelines.
"""

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

Comment thread py/squeze/tests/test_squeze_test.py Outdated
Comment thread py/squeze/candidates.py
Comment thread py/squeze/stats_utils.py
Comment thread py/squeze/peak_finder_two_power_law.py Outdated
Comment thread py/squeze/peak_finder.py Outdated
Comment thread py/squeze/tests/test_peakfinder.py Outdated
Comment thread py/squeze/tests/test_peakfinder.py Outdated
Comment thread py/squeze/tests/test_peakfinder.py Outdated
Comment thread py/squeze/tests/test_peakfinder.py Outdated
Comment thread py/squeze/tests/test_peakfinder.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 26 out of 36 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread py/squeze/peak_finder_power_law.py
Comment thread py/squeze/candidates.py Outdated
Comment thread py/squeze/tests/test_squeze_test.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 26 out of 36 changed files in this pull request and generated 16 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread py/squeze/candidates.py
Comment thread py/squeze/numba_utils.py
Comment thread py/squeze/random_forest_classifier.py
Comment thread py/squeze/peak_finder_two_power_law.py Outdated
Comment thread py/squeze/peak_finder_power_law.py
Comment thread py/squeze/tests/test_squeze_test.py
Comment thread py/squeze/random_forest_classifier.py
Comment thread py/squeze/stats_utils.py
Comment thread py/squeze/stats_utils.py
Comment thread py/squeze/peak_finder_two_power_law.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 26 out of 36 changed files in this pull request and generated 9 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread py/squeze/candidates.py
Comment thread py/squeze/peak_finder_power_law.py Outdated
Comment thread py/squeze/peak_finder_power_law.py Outdated
Comment thread py/squeze/numba_utils.py Outdated
Comment thread py/squeze/random_forest_classifier.py
Comment thread py/squeze/candidates.py Outdated
Comment thread py/squeze/random_forest_classifier.py
Comment thread py/squeze/peak_finder.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 26 out of 36 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread py/squeze/peak_finder_two_power_law.py Outdated
Comment thread py/squeze/stats_utils.py
Comment thread py/squeze/stats_utils.py
Comment thread py/squeze/stats_utils.py
Comment thread py/squeze/stats_utils.py
@iprafols
iprafols merged commit 342bf3e into master Dec 20, 2025
10 checks passed
@iprafols
iprafols deleted the peak_finder_two_power_law branch December 20, 2025 08:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants