Skip to content

Commit

Permalink
update default filenames
Browse files Browse the repository at this point in the history
  • Loading branch information
tdixon97 committed May 1, 2024
1 parent ec81281 commit 83877e6
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/pygama/evt/modules/geds.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ def apply_xtalk_correction(
calibrated_energy_name: str,
threshold: float = None,
xtalk_matrix_filename: str,
xtalk_rawid_name: str = "xtalk_rawids",
xtalk_matrix_name: str = "xtalk_matrix_negative",
positive_xtalk_matrix_name: str = "xtalk_matrix_positive",
xtalk_rawid_name: str = "xtc/xtalk_rawids",
xtalk_matrix_name: str = "xtc/xtalk_matrix_negative",
positive_xtalk_matrix_name: str = "xtc/xtalk_matrix_positive",
) -> types.VectorOfVectors:
"""Applies the cross-talk correction to the energy observable.
The format of `xtalk_matrix_filename` should be currently be a path to a lh5 file.
Expand Down
11 changes: 7 additions & 4 deletions src/pygama/evt/modules/xtalk.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import numpy as np
from lgdo import lh5

from pygama.lgdo import ls
from lgdo import ls

from .. import utils

Expand Down Expand Up @@ -94,9 +94,12 @@ def xtalk_corrected_energy(
uncalibrated_energies_no_nan = np.nan_to_num(uncalibrated_energies, 0)
calibrated_energies_no_nan = np.nan_to_num(calibrated_energies, 0)

energies_threshold = np.where(
calibrated_energies_no_nan < threshold, 0, uncalibrated_energies_no_nan
)
if threshold is not None:
energies_threshold = np.where(
calibrated_energies_no_nan < threshold, 0, uncalibrated_energies_no_nan
)
else:
energies_threshold = uncalibrated_energies_no_nan

energies_correction = -np.matmul(matrix, energies_threshold.T).T
return uncalibrated_energies + energies_correction
29 changes: 29 additions & 0 deletions tests/evt/test_build_evt.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,35 @@ def test_field_nesting(lgnd_test_data, files_config):
assert sorted(evt.sub2.keys()) == ["dummy", "multiplicity"]


def test_xtalk(lgnd_test_data,files_config):

config = {
"channels": {"geds_on": ["ch1084803", "ch1084804", "ch1121600"]},
"outputs": [
"sub1___timestamp",
"sub2___multiplicity",
"sub2___dummy",
],
"operations": {
"sub1___timestamp": {
"channels": "geds_on",
"aggregation_mode": "function",
"expression": "pygama.evt.modules.geds.apply_xtalk_correction(<...>,uncalibrated_energy_name='cuspEmax_ctc',calibrated_energy_name=\
'cuspEmax_ctc_cal',xtalk_matrix_filename='/data1/users/tdixon/cross_talk/l200-p08-r015-x-talk-matrix_trapTmax.lh5')"
}
}
}
build_evt(
files_config,
config=config,
wo_mode="of",
)

outfile = files_config["evt"][0]

evt = lh5.read("/evt", outfile)
show(outfile)

def test_spms_module(lgnd_test_data, files_config):
build_evt(
files_config,
Expand Down
2 changes: 1 addition & 1 deletion tests/evt/test_xtalk.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def test_xtalk_corrected_energy():

energy = np.array([[1, 2, 3], [4, 5, 6], [2, 0, 1], [0, 1, 0]])
matrix = np.array([[0, 0, 1], [1, 0, 2], [0, 2, 0]])
energy_corrected_zero_threshold = xtalk.xtalk_corrected_energy(energy, matrix, 0)
energy_corrected_zero_threshold = xtalk.xtalk_corrected_energy(energy, energy,matrix, None)

assert np.all(
energy_corrected_zero_threshold
Expand Down

0 comments on commit 83877e6

Please sign in to comment.