Skip to content

Commit

Permalink
Refactor code for speed and clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
glenn-jocher committed Jun 20, 2024
1 parent 2c9e773 commit 5e76da6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<br>
<img src="https://raw.githubusercontent.com/ultralytics/assets/main/logo/Ultralytics_Logotype_Original.svg" width="320">
<a href="https://ultralytics.com" target="_blank"><img src="https://raw.githubusercontent.com/ultralytics/assets/main/logo/Ultralytics_Logotype_Original.svg" width="320" alt="Ultralytics logo"></a>

# 🚀 Introduction

Expand Down Expand Up @@ -84,7 +84,7 @@ For bug reports, feature requests, and contributions, head to [GitHub Issues](ht
<img src="https://github.com/ultralytics/assets/raw/main/social/logo-transparent.png" width="3%" alt="space">
<a href="https://www.tiktok.com/@ultralytics"><img src="https://github.com/ultralytics/assets/raw/main/social/logo-social-tiktok.png" width="3%" alt="Ultralytics TikTok"></a>
<img src="https://github.com/ultralytics/assets/raw/main/social/logo-transparent.png" width="3%" alt="space">
<a href="https://www.instagram.com/ultralytics/"><img src="https://github.com/ultralytics/assets/raw/main/social/logo-social-instagram.png" width="3%" alt="Ultralytics Instagram"></a>
<a href="https://ultralytics.com/bilibili"><img src="https://github.com/ultralytics/assets/raw/main/social/logo-social-bilibili.png" width="3%" alt="Ultralytics Instagram"></a>
<img src="https://github.com/ultralytics/assets/raw/main/social/logo-transparent.png" width="3%" alt="space">
<a href="https://ultralytics.com/discord"><img src="https://github.com/ultralytics/assets/raw/main/social/logo-social-discord.png" width="3%" alt="Ultralytics Discord"></a>
</div>
9 changes: 6 additions & 3 deletions test_singles.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@


def exp1(x, a, b, c):
# f(x) = a*exp(b*x)+c
"""Compute the exponential function f(x) = a*exp(b*x) + c for input array x."""
return a * np.exp(b * x) + c


def calibrate_energy(x):
# convert energy from samples to keV using known calibration points px, py
"""Convert energy from samples to keV using known calibration points and an exponential fitting function."""
px = np.array([0.0, 150, 173, 207]) # samples
py = np.array([0.0, 334, 511, 1274]) # keV (344 keV compton edge)

Expand All @@ -29,6 +29,9 @@ def calibrate_energy(x):


def test_singles(file="my_data_singles.txt"):
"""Tests single events data from a file, calibrates energy, identifies 511 keV candidates, and generates diagnostic
plots.
"""
x = np.loadtxt(file)
t, e, ch = x.transpose() # time (ps), energy (samples), channel
print("Read %s, %g events recorded over %gs" % (file, x.shape[0], (t.max() - t.min()) / 1e12))
Expand Down Expand Up @@ -58,7 +61,7 @@ def test_singles(file="my_data_singles.txt"):


def plots(x, e0, ecal, dt, efit_label):
# matplotlib plots
"""Generate and save various matplotlib and seaborn plots for given energy and time data arrays."""
# fig, ax = plt.subplots(2, 3, figsize=(9, 6))
# ax = ax.ravel()
# ax[0].hist(e0, np.linspace(0, 300, 300))
Expand Down

0 comments on commit 5e76da6

Please sign in to comment.