Streak Finder algorithm for CBD experiment #2

Merged
augustin_s merged 46 commits from ext-dorofe_e/dap:chapman into main 2025-07-14 11:18:07 +02:00
4 changed files with 49 additions and 0 deletions
Showing only changes of commit d8e38df39a - Show all commits

View File

@@ -239,6 +239,16 @@ options:
Use the `'apply_additional_mask': 0/1` - Input flag to enable this functionality.
* **Additional Mask from file**
Alternative to previous additional masking, mask data is read from specified file. NumPy and HDF5 formats are supported.
Input parameters:
* `'apply_additional_mask': 1/0` - Input flag to enable this functionality.
* `'mask_file': str` - Path to the hdf5 or npy file with mask data.
* `'mask_ds': str` [Optional] - Name of the dataset containing mask in the hdf5 file, default is `"mask_data"`.
Algorithm Output:
* `'mask_from_file_applied': 1/0` - Indicates whether the algorithm ran successfully.
* **Filter based on pulse picker information**
If the event propagation capability is accessible for the detector and the pulse picker information is correctly configured for propagation, the filtration based on pulse picker information becomes feasible by using the

View File

@@ -1,5 +1,6 @@
from .addmask import calc_apply_additional_mask
from .addmaskfile import calc_apply_additional_mask_from_file
from .aggregation import calc_apply_aggregation
from .jfdata import JFData
from .mask import calc_mask_pixels

36
dap/algos/addmaskfile.py Normal file
View File

@@ -0,0 +1,36 @@
import h5py
import numpy as np
DEFAULT_MASK_DATASET = "mask_data"
def calc_apply_additional_mask_from_file(results, pixel_mask_pf):
apply_additional_mask = results.get("apply_additional_mask_from_file", False)
if not apply_additional_mask:
return
mask_file = results.get("mask_file", None)
if not mask_file:
return
mask_dataset = results.get("mask_ds", DEFAULT_MASK_DATASET)
# Support for hdf5 and npy
if mask_file.endswith(".npy"):
try:
mask = np.load(mask_file)
except Exception as error:
results["mask_error"] = f"Error loading mask data from NumPy file {mask_file}:\n{error}"
return
else:
try:
with h5py.File(mask_file, "r") as h5f:
mask = np.asarray(h5f[mask_dataset], dtype=np.bool)
except Exception as error:
results["mask_error"] = f"Error loading mask from hdf5 file {mask_file}:\n{error}"
return
try:
np.multiply(pixel_mask_pf, mask, out=pixel_mask_pf)
except Exception as error:
results["mask_error"] = f"Error applying additional mask from file {mask_file}:\n{error}"

View File

@@ -3,6 +3,7 @@ import numpy as np
import jungfrau_utils as ju
from .addmask import calc_apply_additional_mask
from .addmaskfile import calc_apply_additional_mask_from_file
class JFData:
@@ -58,6 +59,7 @@ class JFData:
pixel_mask_pf = np.ascontiguousarray(pixel_mask_corrected)
calc_apply_additional_mask(results, pixel_mask_pf) # changes pixel_mask_pf in place
calc_apply_additional_mask_from_file(results, pixel_mask_pf) # further changes pixel_mask_pf in place
self.id_pixel_mask_corrected = new_id_pixel_mask_corrected
self.pixel_mask_pf = pixel_mask_pf