Skip to content

Commit

Permalink
TRR test suite fix (#167)
Browse files Browse the repository at this point in the history
* Try to fix TRR GUI test suite following PR #163

* Fixed bug in selection of fit function to be used for linearity
  • Loading branch information
jlenain authored Jan 17, 2025
1 parent 5151e86 commit a7e0226
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 71 deletions.
31 changes: 14 additions & 17 deletions src/nectarchain/user_scripts/dmousadi/TRR_scripts/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@
import sys
import tempfile

import matplotlib.pyplot as plt
from matplotlib.backends.backend_qt5 import NavigationToolbar2QT as NavigationToolbar
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
from PyQt5.QtCore import QProcess, QTimer
from PyQt5.QtWidgets import (
QApplication,
QComboBox,
QFileDialog,
QGroupBox,
QHBoxLayout,
QLabel,
Expand All @@ -40,29 +38,28 @@
QWidgetItem,
)

# Ensure the tests directory is in sys.path
test_dir = os.path.abspath("tests")
# Ensure the src directory is in sys.path
test_dir = os.path.abspath("src")
if test_dir not in sys.path:
sys.path.append(test_dir)

import deadtime_test

# Import test modules
import linearity_test
import pedestal_test
import pix_couple_tim_uncertainty_test
import pix_tim_uncertainty_test
import trigger_timing_test
import deadtime
import linearity
import pedestal
import pix_couple_tim_uncertainty
import pix_tim_uncertainty
import trigger_timing


class TestRunner(QWidget):
test_modules = {
"Linearity Test": linearity_test,
"Deadtime Test": deadtime_test,
"Pedestal Test": pedestal_test,
"Pixel Time Uncertainty Test": pix_tim_uncertainty_test,
"Time Uncertainty Between Couples of Pixels": pix_couple_tim_uncertainty_test,
"Trigger Timing Test": trigger_timing_test,
"Linearity Test": linearity,
"Deadtime Test": deadtime,
"Pedestal Test": pedestal,
"Pixel Time Uncertainty Test": pix_tim_uncertainty,
"Time Uncertainty Between Couples of Pixels": pix_couple_tim_uncertainty,
"Trigger Timing Test": trigger_timing,
}

def __init__(self):
Expand Down
13 changes: 2 additions & 11 deletions src/nectarchain/user_scripts/dmousadi/TRR_scripts/src/deadtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,15 @@

import argparse
import os
import pathlib
import pickle
import sys

import matplotlib.pyplot as plt
import numpy as np
from astropy import units as u
from iminuit import Minuit

from .tools_components import DeadtimeTestTool
from .utils import (
ExponentialFitter,
deadtime_and_expo_fit,
deadtime_labels,
err_ratio,
pois,
source_ids_deadtime,
)
from tools_components import DeadtimeTestTool
from utils import ExponentialFitter, deadtime_labels, source_ids_deadtime


def get_args():
Expand Down
17 changes: 6 additions & 11 deletions src/nectarchain/user_scripts/dmousadi/TRR_scripts/src/linearity.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,17 @@

import argparse
import os
import pathlib
import pickle
import sys

import matplotlib.pyplot as plt
import numpy as np
from lmfit.models import Model

from .tools_components import LinearityTestTool
from .utils import (
adc_to_pe,
from tools_components import LinearityTestTool
from utils import (
err_ratio,
err_sum,
filters,
linear_fit_function,
optical_density_390ns,
plot_parameters,
trasmission_390ns,
)
Expand Down Expand Up @@ -248,7 +243,7 @@ def main():
"linearity_range"
][1]
],
fit_function(
linear_fit_function(
true[
plot_parameters[name]["linearity_range"][0] : plot_parameters[name][
"linearity_range"
Expand Down Expand Up @@ -301,7 +296,7 @@ def main():

# residuals

pred = fit_function(true, a, b) # prediction
pred = linear_fit_function(true, a, b) # prediction
pred_err = a_err * true + b_err # a,b uncorrelated

resid = (ch_charge - pred) / ch_charge
Expand Down Expand Up @@ -331,7 +326,7 @@ def main():
ratio = ratio_sorted[:, 1]
ratio_std = ratio_sorted[:, 2]

model = model = Model(fit_function)
model = model = Model(linear_fit_function)
params = model.make_params(a=100, b=0)
ratio_fit = model.fit(
ratio[10:-4], params, weights=1 / ratio_std[10:-4], x=true[10:-4]
Expand All @@ -342,7 +337,7 @@ def main():
axs[2].errorbar(true, ratio, yerr=ratio_std, ls="", color="C1", marker="o")
axs[2].plot(
true[10:-4],
fit_function(
linear_fit_function(
true[10:-4], ratio_fit.params["a"].value, ratio_fit.params["b"].value
),
ls="-",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,8 @@

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from ctapipe.containers import EventType
from ctapipe_io_nectarcam.containers import NectarCAMDataContainer

from nectarchain.makers.calibration import PedestalNectarCAMCalibrationTool

from .tools_components import PedestalTool
from .utils import adc_to_pe, pe2photons, photons2pe
from tools_components import PedestalTool
from utils import adc_to_pe, pe2photons


def get_args():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

import matplotlib.pyplot as plt
import numpy as np

from .tools_components import ToMPairsTool
from tools_components import ToMPairsTool


def get_args():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@

import matplotlib.pyplot as plt
import numpy as np

from .tools_components import TimingResolutionTestTool
from .utils import pe2photons, photons2pe
from tools_components import TimingResolutionTestTool
from utils import pe2photons, photons2pe


def get_args():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
import os
import pathlib
import random
from itertools import combinations

import h5py
import hdf5plugin
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from astropy import units as u
from ctapipe.containers import EventType, Field
from ctapipe.core.traits import ComponentNameList, Integer
from ctapipe_io_nectarcam import constants
from ctapipe_io_nectarcam.containers import NectarCAMDataContainer
from lmfit.models import Model
from scipy.interpolate import InterpolatedUnivariateSpline
from scipy.signal import find_peaks
from utils import adc_to_pe, argmedian

from nectarchain.data.container import NectarCAMContainer
from nectarchain.makers import EventsLoopNectarCAMCalibrationTool
from nectarchain.makers.component import NectarCAMComponent
from nectarchain.utils import ComponentUtils

from .utils import adc_to_pe, argmedian


# overriding so we can have maxevents in the path
Expand Down Expand Up @@ -252,7 +246,7 @@ def finish(self, *args, **kwargs):

for thing in output_file:
group = output_file[thing]
dataset = group["ChargeContainer"]
dataset = group["ChargeContainer_0"]
data = dataset[:]
# print("data",data)
for tup in data:
Expand Down Expand Up @@ -622,7 +616,7 @@ def finish(self, bootstrap=False, *args, **kwargs):

for thing in output_file:
group = output_file[thing]
dataset = group["ToMContainer"]
dataset = group["ToMContainer_0"]
data = dataset[:]
# print("data",data)
for tup in data:
Expand Down Expand Up @@ -1042,7 +1036,7 @@ def finish(self, *args, **kwargs):

for thing in output_file:
group = output_file[thing]
dataset = group["PedestalContainer"]
dataset = group["PedestalContainer_0"]
data = dataset[:]
# print("data",data)
for tup in data:
Expand Down Expand Up @@ -1249,7 +1243,7 @@ def finish(self, *args, **kwargs):

for thing in output_file:
group = output_file[thing]
dataset = group["UCTSContainer"]
dataset = group["UCTSContainer_0"]
data = dataset[:]
for tup in data:
try:
Expand Down Expand Up @@ -1321,7 +1315,7 @@ def finish(self, *args, **kwargs):

for thing in output_file:
group = output_file[thing]
dataset = group["UCTSContainer"]
dataset = group["UCTSContainer_0"]
data = dataset[:]
# print("data",data)
for tup in data:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

import argparse
import os
import pathlib
import pickle
import sys

import matplotlib.pyplot as plt
import numpy as np

from .tools_components import TriggerTimingTestTool
from .utils import pe2photons
from tools_components import TriggerTimingTestTool
from utils import pe2photons


def get_args():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import matplotlib.pyplot as plt
import numpy as np
from astropy import units as u
from ctapipe.utils import get_dataset_path
from iminuit import Minuit
from lmfit.models import Model
from scipy.interpolate import interp1d
from scipy.stats import expon, poisson
Expand Down Expand Up @@ -421,7 +419,6 @@ def photons2pe(x):

# from federica's notebook
class ExponentialFitter:

"""
Represents an exponential fitter class that computes the expected distribution and the minus 2 log likelihood for a given dataset and exponential parameters.
Expand Down

0 comments on commit a7e0226

Please sign in to comment.