Correct setting name for mask form file dataset; prepend all strak-finder-specific settings names with sf; Make streak-finder mask optional now that we have mask from file
This commit is contained in:
33
README.md
33
README.md
@@ -111,13 +111,13 @@ options:
|
||||
|
||||
Input parameters:
|
||||
* `'do_snr': 1/0` - Specifies whether to do whitefield and std correction, if selected - changes image and mask in place.
|
||||
* `'std_data_file': str` - hdf5 data file containing pre-calculated std.
|
||||
* `'std_dataset': str` - [optional] dataset containing pre-calculated std, defaults to `'entry/crystallography/std'`.
|
||||
* `'whitefield_data_file': str` - hdf5 data file containing pre-calculated white field.
|
||||
* `'whitefield_dataset': str` - [optional] dataset containing pre-calculated white field, defaults to `'entry/crystallography/whitefield'`.
|
||||
* `'mask_data_file': str` - hdf5 data file containing pre-calculated mask.
|
||||
* `'mask_dataset': str` - [optional] dataset containing pre-calculated mask, defaults to `'entry/instrument/detector/mask'`.
|
||||
* `'scale_whitefield': 1/0` - Specifies whether to scale whitefield to signal, useful if intensity jumps.
|
||||
* `'sf_std_data_file': str` - hdf5 data file containing pre-calculated std.
|
||||
* `'sf_std_dataset': str` - [optional] dataset containing pre-calculated std, defaults to `'entry/crystallography/std'`.
|
||||
* `'sf_whitefield_data_file': str` - hdf5 data file containing pre-calculated white field.
|
||||
* `'sf_whitefield_dataset': str` - [optional] dataset containing pre-calculated white field, defaults to `'entry/crystallography/whitefield'`.
|
||||
* `'sf_mask_data_file': str` - [optional] hdf5 data file containing pre-calculated mask.
|
||||
* `'sf_mask_dataset': str` - [optional] dataset containing pre-calculated mask, defaults to `'entry/instrument/detector/mask'`.
|
||||
* `'sf_scale_whitefield': 1/0` - Specifies whether to scale whitefield to signal, useful if intensity jumps.
|
||||
|
||||
* `'do_streakfinder_analysis': 1/0` - Specifies whether to execute the streak-finder algorithm.
|
||||
* `'sf_peak_structure_radius': int` - Connectivity structure radius for *peaks* detection.
|
||||
@@ -245,7 +245,7 @@ options:
|
||||
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"`.
|
||||
* `'mask_dataset': 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.
|
||||
|
||||
@@ -314,14 +314,17 @@ Example JSON for Convergent-Beam Diffraction Streak-Finder:
|
||||
"roi_y1": [],
|
||||
"roi_x2": [],
|
||||
"roi_y2": [],
|
||||
"do_snr": 0,
|
||||
"std_data_file": "/sf/instrument/exp/00m_mustermann/res/aux_data/streakfinder_metadata.h5",
|
||||
"std_dataset": "entry/crystallography/std",
|
||||
"whitefield_data_file": "/sf/bernina/exp/00m_mustermann/res/aux_data/streakfinder_metadata.h5",
|
||||
"whitefield_dataset": "entry/crystallography/whitefield",
|
||||
"mask_data_file": "/sf/bernina/exp/00m_mustermann/res/aux_data/JF_mask.h5",
|
||||
"": 1,
|
||||
"mask_file": "/sf/jungfrau/config/additional_mask/JF07T32V02.h5",
|
||||
"mask_dataset": "mask_data",
|
||||
"scale_whitefield": 0,
|
||||
"do_snr": 0,
|
||||
"sf_std_data_file": "/sf/instrument/exp/00m_mustermann/res/aux_data/streakfinder_metadata.h5",
|
||||
"sf_std_dataset": "entry/crystallography/std",
|
||||
"sf_whitefield_data_file": "/sf/bernina/exp/00m_mustermann/res/aux_data/streakfinder_metadata.h5",
|
||||
"sf_whitefield_dataset": "entry/crystallography/whitefield",
|
||||
"sf_mask_data_file": "/sf/bernina/exp/00m_mustermann/res/aux_data/JF_mask.h5",
|
||||
"sf_mask_dataset": "mask_data",
|
||||
"sf_scale_whitefield": 0,
|
||||
"do_streakfinder_analysis": 1,
|
||||
"sf_negative_handler": "zero",
|
||||
"sf_peak_structure_radius": 2,
|
||||
|
||||
@@ -13,7 +13,7 @@ def calc_apply_additional_mask_from_file(results, pixel_mask_pf):
|
||||
mask_file = results.get("mask_file", None)
|
||||
if not mask_file:
|
||||
return
|
||||
mask_dataset = results.get("mask_ds", DEFAULT_MASK_DATASET)
|
||||
mask_dataset = results.get("mask_dataset", DEFAULT_MASK_DATASET)
|
||||
|
||||
# Support for hdf5 and npy
|
||||
if mask_file.endswith(".npy"):
|
||||
|
||||
@@ -45,7 +45,6 @@ def calc_streakfinder_analysis(results, data, pf_pixel_mask):
|
||||
if do_snr:
|
||||
# Changes data and mask in-place
|
||||
data = cryst_data.snr[0].copy()
|
||||
np.multiply(pf_pixel_mask, cryst_data.mask, out=pf_pixel_mask)
|
||||
|
||||
try:
|
||||
_calc_streakfinder_analysis(results, cryst_data)
|
||||
@@ -56,40 +55,43 @@ def calc_streakfinder_analysis(results, data, pf_pixel_mask):
|
||||
|
||||
def _generate_cryst_data(results, data, pf_pixel_mask) -> CrystData:
|
||||
params_required = [
|
||||
"whitefield_data_file",
|
||||
"mask_data_file",
|
||||
"std_data_file",
|
||||
"scale_whitefield", # Bool
|
||||
"sf_whitefield_data_file",
|
||||
"sf_std_data_file",
|
||||
"sf_scale_whitefield", # Bool
|
||||
]
|
||||
|
||||
if not all(param in results.keys() for param in params_required):
|
||||
raise ValueError(f"ERROR: Not enough parameters for CBD correction. Skipping\n"
|
||||
f"{params_required=}")
|
||||
|
||||
whitefield_data_file = results["whitefield_data_file"]
|
||||
mask_data_file = results["mask_data_file"]
|
||||
std_data_file = results["std_data_file"]
|
||||
scale_whitefield = results["scale_whitefield"]
|
||||
whitefield_data_file = results["sf_whitefield_data_file"]
|
||||
std_data_file = results["sf_std_data_file"]
|
||||
scale_whitefield = results["sf_scale_whitefield"]
|
||||
|
||||
# Using CXI Store specification as default
|
||||
whitefield_dataset = results.get("whitefield_dataset", "entry/crystallography/whitefield")
|
||||
mask_dataset = results.get("mask_dataset", "entry/instrument/detector/mask")
|
||||
std_dataset = results.get("std_dataset", "entry/crystallography/std")
|
||||
whitefield_dataset = results.get("sf_whitefield_dataset", "entry/crystallography/whitefield")
|
||||
std_dataset = results.get("sf_std_dataset", "entry/crystallography/std")
|
||||
|
||||
num_threads = results.get("num_threads", DEFAULT_NUM_THREADS)
|
||||
num_threads = results.get("sf_num_threads", DEFAULT_NUM_THREADS)
|
||||
|
||||
with h5py.File(whitefield_data_file, "r") as hf:
|
||||
whitefield = hf[whitefield_dataset][:]
|
||||
|
||||
with h5py.File(mask_data_file, "r") as hf:
|
||||
mask = hf[mask_dataset][:].astype(np.bool)
|
||||
|
||||
with h5py.File(std_data_file, "r") as hf:
|
||||
std = hf[std_dataset][:]
|
||||
|
||||
mask_data_file = results.get("sf_mask_data_file", None)
|
||||
if mask_data_file is None:
|
||||
mask = pf_pixel_mask
|
||||
else:
|
||||
mask_dataset = results.get("sf_mask_dataset", "entry/instrument/detector/mask")
|
||||
with h5py.File(mask_data_file, "r") as hf:
|
||||
mask = hf[mask_dataset][:].astype(np.bool)
|
||||
mask *= pf_pixel_mask
|
||||
|
||||
data = CrystData(
|
||||
data=data[np.newaxis, :],
|
||||
mask=mask*pf_pixel_mask,
|
||||
mask=mask,
|
||||
std=std,
|
||||
whitefield=whitefield
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user