From cd1985f851602f85c21a2f087051c63bbfa914b3 Mon Sep 17 00:00:00 2001 From: Alice Date: Wed, 11 Nov 2026 12:00:35 +0100 Subject: [PATCH] removed unneccessary dependancies --- jfcal/JungfrauCalibration.py | 1 - jfcal/__init__.py | 2 -- jfcal/plotting.py | 16 ++++++++-------- jfcal/utils.py | 15 ++++++++++----- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/jfcal/JungfrauCalibration.py b/jfcal/JungfrauCalibration.py index 3561bb3..4b398d4 100644 --- a/jfcal/JungfrauCalibration.py +++ b/jfcal/JungfrauCalibration.py @@ -2,7 +2,6 @@ import math import os from concurrent.futures import ThreadPoolExecutor from pathlib import Path -from pyexpat import model import time from aare import JungfrauDataFile, File, random_pixel, Pol1, Minimizer from aare.experimental import MultiThreadedFileReader diff --git a/jfcal/__init__.py b/jfcal/__init__.py index f070470..b9d2e15 100644 --- a/jfcal/__init__.py +++ b/jfcal/__init__.py @@ -1,5 +1,3 @@ -from .helpers import * - from .JungfrauCalibration import * from .JungfrauFitParameters import * diff --git a/jfcal/plotting.py b/jfcal/plotting.py index f08e70f..d3611f0 100644 --- a/jfcal/plotting.py +++ b/jfcal/plotting.py @@ -151,35 +151,35 @@ def plot_parameter_histogram(fitted_parameter: np.ndarray, parameter_name : str, case Parameters.ELASTIC_SCATTERING_INTERCEPT.value: data = fitted_parameter[:, :, 0].flatten() histogram = create_histogram_from_data(data, bin_range = bin_range, bin_width = bin_width) - ax = plot_histogram(histogram, histogram.axes[0].centers[:], xlabel=r"Elastic scattering intercept", label = f"Mean: {np.mean(data):.3f}\nStd: {np.std(data):.3f}", axis=axis) + ax = plot_histogram(histogram.values(), histogram.bin_centers(), xlabel=r"Elastic scattering intercept", label = f"Mean: {np.mean(data):.3f}\nStd: {np.std(data):.3f}", axis=axis) case Parameters.ELASTIC_SCATTERING_SLOPE.value: data = fitted_parameter[:, :, 1].flatten() histogram = create_histogram_from_data(data, bin_range = bin_range, bin_width = bin_width) - ax = plot_histogram(histogram, histogram.axes[0].centers[:], xlabel=r"Elastic scattering slope", label = f"Mean: {np.mean(data):.3f}\nStd: {np.std(data):.3f}", axis=axis) + ax = plot_histogram(histogram.values(), histogram.bin_centers(), xlabel=r"Elastic scattering slope", label = f"Mean: {np.mean(data):.3f}\nStd: {np.std(data):.3f}", axis=axis) case Parameters.K_ALPHA_MEAN.value: data = fitted_parameter[:, :, 2].flatten() histogram = create_histogram_from_data(data, bin_range = bin_range, bin_width = bin_width) - ax = plot_histogram(histogram, histogram.axes[0].centers[:], xlabel=r"$k_\alpha$ mean", label = f"Mean: {np.mean(data):.3f}\nStd: {np.std(data):.3f}", axis=axis) + ax = plot_histogram(histogram.values(), histogram.bin_centers(), xlabel=r"$k_\alpha$ mean", label = f"Mean: {np.mean(data):.3f}\nStd: {np.std(data):.3f}", axis=axis) case Parameters.SIGMA.value: data = fitted_parameter[:, :, 3].flatten() histogram = create_histogram_from_data(data, bin_range = bin_range, bin_width = bin_width) - ax = plot_histogram(histogram, histogram.axes[0].centers[:], xlabel=r"$\sigma$", label = f"Mean: {np.mean(data):.3f}\nStd: {np.std(data):.3f}", axis=axis) + ax = plot_histogram(histogram.values(), histogram.bin_centers(), xlabel=r"$\sigma$", label = f"Mean: {np.mean(data):.3f}\nStd: {np.std(data):.3f}", axis=axis) case Parameters.K_ALPHA_AMPLITUDE.value: data = fitted_parameter[:, :, 4].flatten() histogram = create_histogram_from_data(data, bin_range = bin_range, bin_width = bin_width) - ax = plot_histogram(histogram, histogram.axes[0].centers[:], xlabel=r"$k_\alpha$ amplitude", label = f"Mean: {np.mean(data):.3f}\nStd: {np.std(data):.3f}", axis=axis) + ax = plot_histogram(histogram.values(), histogram.bin_centers(), xlabel=r"$k_\alpha$ amplitude", label = f"Mean: {np.mean(data):.3f}\nStd: {np.std(data):.3f}", axis=axis) case Parameters.RATIO_AMPLITUDE_CHARGE_SHARING.value: data = fitted_parameter[:, :, 5].flatten() histogram = create_histogram_from_data(data, bin_range = bin_range, bin_width = bin_width) - ax = plot_histogram(histogram, histogram.axes[0].centers[:], xlabel=r"Ratio amplitude charge sharing", label = f"Mean: {np.mean(data):.3f}\nStd: {np.std(data):.3f}", axis=axis) + ax = plot_histogram(histogram.values(), histogram.bin_centers(), xlabel=r"Ratio amplitude charge sharing", label = f"Mean: {np.mean(data):.3f}\nStd: {np.std(data):.3f}", axis=axis) case Parameters.RATIO_MEAN_K_BETA.value: data = fitted_parameter[:, :, 6].flatten() histogram = create_histogram_from_data(data, bin_range = bin_range, bin_width = bin_width) - ax = plot_histogram(histogram, histogram.axes[0].centers[:], xlabel=r"Ratio $k_\beta$ mean", label = f"Mean: {np.mean(data):.3f}\nStd: {np.std(data):.3f}", axis=axis) + ax = plot_histogram(histogram.values(), histogram.bin_centers(), xlabel=r"Ratio $k_\beta$ mean", label = f"Mean: {np.mean(data):.3f}\nStd: {np.std(data):.3f}", axis=axis) case Parameters.RATIO_AMPLITUDE_K_BETA.value: data = fitted_parameter[:, :, 7].flatten() histogram = create_histogram_from_data(data, bin_range = bin_range, bin_width = bin_width) - ax = plot_histogram(histogram, histogram.axes[0].centers[:], xlabel=r"Ratio $k_\beta$ amplitude", label = f"Mean: {np.mean(data):.3f}\nStd: {np.std(data):.3f}", axis=axis) + ax = plot_histogram(histogram.values(), histogram.bin_centers(), xlabel=r"Ratio $k_\beta$ amplitude", label = f"Mean: {np.mean(data):.3f}\nStd: {np.std(data):.3f}", axis=axis) case _: raise ValueError(f"Unknown parameter name: {parameter_name}. Valid options are: {[param.value for param in Parameters]}") diff --git a/jfcal/utils.py b/jfcal/utils.py index a341a25..fa3f873 100644 --- a/jfcal/utils.py +++ b/jfcal/utils.py @@ -1,7 +1,6 @@ -import glob from pathlib import Path -import boost_histogram as bh +from aare import PixelHistogram import numpy as np from .DataClasses import HistogramResult, LinearFitResult, JungfrauCalibrationResult @@ -197,7 +196,7 @@ def create_histogram_from_data(data : np.ndarray, bin_range : tuple[float, float Parameters ---------- data : np.ndarray - The data to create the histogram from. + The 2d data to create the histogram from. bin_range : tuple[float, float], optional The range of the bins. Default is None, which means the range is determined from the data. bin_width : float, optional @@ -219,8 +218,14 @@ def create_histogram_from_data(data : np.ndarray, bin_range : tuple[float, float print("bin width: ", (bin_range[1] - bin_range[0]) / bins) else: bins = int((bin_range[1] - bin_range[0]) / bin_width) + + if data.ndim == 2: + rows, cols = data.shape + else: + raise ValueError(f"Data must be 2D or 3D, but got {data.ndim}D.") + + hist = PixelHistogram(rows = rows, cols = cols, n_bins = bins, xmin = bin_range[0], xmax = bin_range[1], n_threads = 8) + hist.fill_async(data) - hist = bh.Histogram(bh.axis.Regular(bins, bin_range[0], bin_range[1])) - hist.fill(data) return hist