1111from tqdm import tqdm
1212from contextlib import nullcontext
1313from pyxalign import gpu_utils
14+ from pyxalign .api .enums import RoundType
1415from pyxalign .api .options .device import DeviceOptions
16+ from pyxalign .api .options .projections import SimulatedProbeOptions
1517from pyxalign .gpu_wrapper import device_handling_wrapper
1618
1719# from pyxalign.interactions.mask import ThresholdSelector, illum_map_threshold_plotter
18- from pyxalign .transformations .helpers import is_array_real
20+ from pyxalign .model_functions import symmetric_gaussian_2d
21+ from pyxalign .transformations .helpers import is_array_real , round_to_divisor
1922from IPython .display import display
20- from PyQt5 .QtWidgets import QApplication
2123import plotly .graph_objects as go
2224from plotly .subplots import make_subplots
2325
2628from pyxalign .timing .timer_utils import timer , InlineTimer
2729from pyxalign .api .types import ArrayType , r_type
2830
29- from PyQt5 .QtWidgets import QWidget
30-
3131
3232@memory_releasing_error_handler
3333@timer ()
@@ -387,45 +387,16 @@ def build_masks_from_threshold(
387387 return clip_masks (masks , threshold )
388388
389389
390- # class IlluminationMapMaskBuilder:
391- # """
392- # Class for building mask from the illumination map.
393- # """
394-
395- # def get_mask_base(
396- # self,
397- # probe: np.ndarray,
398- # positions: list[np.ndarray],
399- # projections: np.ndarray,
400- # use_fourier: bool = True,
401- # ):
402- # # The base for building the mask is the illumination map
403- # if use_fourier:
404- # self.masks = place_patches_fourier_batch(projections.shape, probe, positions)
405- # else:
406- # for i in range(len(positions)):
407- # self.masks = np.zeros_like(projections, dtype=r_type)
408- # get_illumination_map(self.masks[i], probe, positions[i])
409-
410- # def set_mask_threshold_interactively(self, projections: np.ndarray) -> float:
411- # # temporary bugfix: all windows need to be closed or else app.exec_() will
412- # # hang indefinitely. I am putting this temporary solution (which I don't like
413- # # very much) in place, because any changes will be overwritten once merged with
414- # # interactive_pma_gui anyway.
415- # app = QApplication.instance() or QApplication([])
416- # app.closeAllWindows()
417-
418- # # Use interactivity to decide mask threshold"
419- # self.threshold_selector = illum_map_threshold_plotter(
420- # self.masks, projections, init_thresh=0.01
421- # )
422- # self.threshold_selector.show()
423-
424- # app.exec_()
425- # threshold = self.threshold_selector.threshold
426- # return threshold
427-
428- # def clip_masks(self, thresh: Optional[float] = None):
429- # clip_idx = self.masks > thresh
430- # self.masks[:] = 0
431- # self.masks[clip_idx] = 1
390+ def get_simulated_probe_for_masks (
391+ probe : np .ndarray ,
392+ simulated_probe_options : SimulatedProbeOptions ,
393+ ):
394+ # simulated probe typically gives better results
395+ shape = probe .shape
396+ probe_width = round_to_divisor (
397+ shape [0 ] * simulated_probe_options .fractional_width ,
398+ round_type = RoundType .NEAREST ,
399+ divisor = 2 ,
400+ )
401+ probe = symmetric_gaussian_2d (shape , amplitude = 1 , sigma = probe_width )
402+ return probe
0 commit comments