reordered some functions
This commit is contained in:
+35
-25
@@ -6,28 +6,19 @@ Requires Convergent beam streak finder package installed:
|
||||
https://github.com/simply-nicky/streak_finder/
|
||||
(note g++ 11 required for building, numpy 2+ required)
|
||||
"""
|
||||
|
||||
import h5py
|
||||
import numpy as np
|
||||
|
||||
from streak_finder.label import Structure2D
|
||||
from streak_finder.streak_finder import detect_peaks, detect_streaks, filter_peaks
|
||||
from streak_finder._src.src.median import median
|
||||
|
||||
|
||||
DEFAULT_MIN_HIT_STREAKS = 5
|
||||
DEFAULT_NUM_THREADS = 16
|
||||
|
||||
|
||||
def _handle_negative_values(data, mask, handler: str):
|
||||
if not handler or np.all(data>=0):
|
||||
return
|
||||
if handler == "shift":
|
||||
# Shift to min=0
|
||||
data -= np.min(data)
|
||||
elif handler == "mask":
|
||||
mask[data<0] = np.nan
|
||||
elif handler == "zero":
|
||||
data[data<0] = 0
|
||||
|
||||
|
||||
def calc_streakfinder_analysis(results, data, pixel_mask):
|
||||
do_snr = results.get("do_snr", False)
|
||||
do_streakfinder_analysis = results.get("do_streakfinder_analysis", False)
|
||||
@@ -54,6 +45,19 @@ def calc_streakfinder_analysis(results, data, pixel_mask):
|
||||
|
||||
return data
|
||||
|
||||
|
||||
def _handle_negative_values(data, mask, handler: str):
|
||||
if not handler or np.all(data>=0):
|
||||
return
|
||||
if handler == "shift":
|
||||
# Shift to min=0
|
||||
data -= np.min(data)
|
||||
elif handler == "mask":
|
||||
mask[data<0] = np.nan
|
||||
elif handler == "zero":
|
||||
data[data<0] = 0
|
||||
|
||||
|
||||
def _calc_snr(results, data, pixel_mask):
|
||||
params_required = [
|
||||
"cbd_whitefield_data_file",
|
||||
@@ -97,6 +101,7 @@ def _calc_snr(results, data, pixel_mask):
|
||||
)
|
||||
return snr
|
||||
|
||||
|
||||
def _scale_whitefield(data, mask, whitefield, std, num_threads):
|
||||
mask = mask & (std > 0.0)
|
||||
y = np.divide(data, std, out=np.zeros_like(data), where=mask)[mask]
|
||||
@@ -106,19 +111,6 @@ def _scale_whitefield(data, mask, whitefield, std, num_threads):
|
||||
median(w * w, axis=0, num_threads=num_threads)
|
||||
whitefield *= scales
|
||||
|
||||
def _get_concentric_only_mask(x_center, y_center, crop_roi, streak_lines, threshold=0.33):
|
||||
if x_center is not None and y_center is not None:
|
||||
if crop_roi is not None:
|
||||
x_center -= crop_roi[0]
|
||||
y_center -= crop_roi[2]
|
||||
centers = np.mean(streak_lines.reshape(-1, 2, 2), axis=1)
|
||||
norm = np.stack([streak_lines[:, 3] - streak_lines[:, 1],
|
||||
streak_lines[:, 0] - streak_lines[:, 2]], axis=-1)
|
||||
r = centers - np.asarray([x_center, y_center])
|
||||
prod = np.sum(norm * r, axis=-1)[..., None]
|
||||
proj = r - prod * norm / np.sum(norm ** 2, axis=-1)[..., None]
|
||||
streaks_mask = np.sqrt(np.sum(proj ** 2, axis=-1)) / np.sqrt(np.sum(r ** 2, axis=-1)) < threshold
|
||||
return streaks_mask
|
||||
|
||||
def _calc_streakfinder_analysis(results, snr, mask):
|
||||
do_streakfinder_analysis = results.get("do_streakfinder_analysis", False)
|
||||
@@ -225,3 +217,21 @@ def _calc_streakfinder_analysis(results, snr, mask):
|
||||
results["streaks"] = list_result
|
||||
results["streak_lengths"] = streak_lengths
|
||||
results["bragg_counts"] = bragg_counts
|
||||
|
||||
|
||||
def _get_concentric_only_mask(x_center, y_center, crop_roi, streak_lines, threshold=0.33):
|
||||
if x_center is not None and y_center is not None:
|
||||
if crop_roi is not None:
|
||||
x_center -= crop_roi[0]
|
||||
y_center -= crop_roi[2]
|
||||
centers = np.mean(streak_lines.reshape(-1, 2, 2), axis=1)
|
||||
norm = np.stack([streak_lines[:, 3] - streak_lines[:, 1],
|
||||
streak_lines[:, 0] - streak_lines[:, 2]], axis=-1)
|
||||
r = centers - np.asarray([x_center, y_center])
|
||||
prod = np.sum(norm * r, axis=-1)[..., None]
|
||||
proj = r - prod * norm / np.sum(norm ** 2, axis=-1)[..., None]
|
||||
streaks_mask = np.sqrt(np.sum(proj ** 2, axis=-1)) / np.sqrt(np.sum(r ** 2, axis=-1)) < threshold
|
||||
return streaks_mask
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user