-
Notifications
You must be signed in to change notification settings - Fork 1
feat: extract A/E model parameters and compute it in hit.py #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
48b60cd
add utilities to extract A/E model pars
tdixon97 a98e600
add function to get the reference calibration run
gipert c1808c8
refactor current model code and integrate into simflow
gipert e9072df
rename hpge_pars functions
gipert e4506cb
fix: docs, macOS ci
gipert d061bbe
fix: docs, macOS ci
gipert d817f24
adjust currmod plot
gipert 26fc767
Merge branch 'pulse_pars' of github.com:tdixon97/legend-simflow into …
gipert 7351af9
rename currmod fit param mean_AoE -> mean_aoe
gipert e2e2811
integrate A/E into hit.py
gipert 9bba6a4
rename function that aggregates hpges good for modeling
gipert b3e7c22
we don't want to model off or ac hpge detectors
gipert 9b3dcd2
add currmod plot targets
gipert 3f1adc4
docs update
gipert d70991c
move a max calculation to a separate function
gipert 9da5e38
code cosmetics
gipert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| import numpy as np | ||
| from lgdo import lh5 | ||
| from matplotlib.axes import Axes | ||
| from matplotlib.figure import Figure | ||
| from scipy.stats import norm | ||
|
|
||
| from legendsimflow import hpge_pars | ||
|
|
||
|
|
||
| def test_fit(): | ||
| t = np.linspace(-1000, 2000, 3001) | ||
| A = norm.pdf(t, loc=0, scale=50) | ||
|
|
||
| res = hpge_pars.fit_currmod(t, A) | ||
|
|
||
| assert isinstance(res[0], np.ndarray) | ||
| assert isinstance(res[1], np.ndarray) | ||
| assert isinstance(res[2], np.ndarray) | ||
|
|
||
|
|
||
| def test_get_index(legend_testdata): | ||
| ref_path = legend_testdata.get_path("lh5/prod-ref-l200/") | ||
| path = ref_path / Path("generated/tier/hit/cal/p03/r001") | ||
| files = [str(p) for p in path.glob("*")] | ||
|
|
||
| # we have to be very generous with the (low stats) test file | ||
| idx, file_idx = hpge_pars.lookup_currmod_fit_data( | ||
| files, "ch1084803/hit", ewin_center=100, ewin_width=20 | ||
| ) | ||
|
|
||
| assert idx > -1 | ||
| assert file_idx > -1 | ||
|
|
||
| # now read back in and check | ||
|
|
||
| energy = lh5.read( | ||
| "ch1084803/hit/cuspEmax_ctc_cal", files[file_idx], idx=[idx] | ||
| ).view_as("np") | ||
| AoE = lh5.read("ch1084803/hit/AoE_Classifier", files[file_idx], idx=[idx]).view_as( | ||
| "np" | ||
| ) | ||
|
|
||
| assert (energy > 90) & (energy < 110) | ||
| assert abs(AoE) < 1.5 | ||
|
|
||
|
|
||
| def test_get_waveform(legend_testdata): | ||
| times, wf = hpge_pars.get_current_pulse( | ||
| legend_testdata.get_path( | ||
| "lh5/prod-ref-l200/generated/tier/raw/cal/p03/r001/l200-p03-r001-cal-20230318T012144Z-tier_raw.lh5" | ||
| ), | ||
| "ch1084803/raw", | ||
| idx=0, | ||
| dsp_config=None, | ||
| dsp_output="waveform", | ||
| align=None, | ||
| ) | ||
|
|
||
| assert isinstance(times, np.ndarray) | ||
| assert isinstance(wf, np.ndarray) | ||
| assert len(times) == len(wf) | ||
|
|
||
|
|
||
| def test_plot(): | ||
| fig, ax = hpge_pars.plot_currmod_fit_result( | ||
| [1, 2, 3], [0, 10, 20], np.linspace(0, 3, 1000), np.linspace(0, 3, 1000) | ||
| ) | ||
|
|
||
| assert isinstance(fig, Figure) | ||
| assert isinstance(ax, Axes) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from legendsimflow import utils | ||
|
|
||
|
|
||
| def test_get_parameter_dict(): | ||
| popt = [100, 10, 60, 0.6, 100, 0.2, 60] | ||
|
|
||
| popt_dict = utils._curve_fit_popt_to_dict(popt) | ||
| assert len(popt_dict) == 8 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.