moved one half of ju_stream_adapter code into separate class
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
|
||||
from .addmask import calc_apply_additional_mask
|
||||
from .jfdata import JFData
|
||||
from .mask import calc_mask_pixels
|
||||
from .peakfind import calc_peakfinder_analysis
|
||||
from .radprof import calc_radial_integration
|
||||
|
42
dap/algos/jfdata.py
Normal file
42
dap/algos/jfdata.py
Normal file
@ -0,0 +1,42 @@
|
||||
import numpy as np
|
||||
|
||||
import jungfrau_utils as ju
|
||||
|
||||
from .addmask import calc_apply_additional_mask
|
||||
|
||||
|
||||
class JFData:
|
||||
|
||||
def __init__(self):
|
||||
self.ju_stream_adapter = ju.StreamAdapter()
|
||||
self.id_pixel_mask_corrected = None
|
||||
self.pixel_mask_pf = None
|
||||
|
||||
|
||||
def get_pixel_mask(self, results, double_pixels):
|
||||
pixel_mask_corrected = self.ju_stream_adapter.handler.get_pixel_mask(double_pixels=double_pixels)
|
||||
if pixel_mask_corrected is None:
|
||||
self.id_pixel_mask_corrected = None
|
||||
self.pixel_mask_pf = None
|
||||
return None
|
||||
|
||||
# starting from ju 3.3.1 pedestal file is cached in library, re-calculated only if parameters (and/or pedestal file) have changed
|
||||
new_id_pixel_mask_corrected = id(pixel_mask_corrected)
|
||||
old_id_pixel_mask_corrected = self.id_pixel_mask_corrected
|
||||
if new_id_pixel_mask_corrected == old_id_pixel_mask_corrected:
|
||||
return self.pixel_mask_pf
|
||||
|
||||
pixel_mask_pf = np.ascontiguousarray(pixel_mask_corrected)
|
||||
calc_apply_additional_mask(results, pixel_mask_pf) # changes pixel_mask_pf in place
|
||||
|
||||
self.id_pixel_mask_corrected = new_id_pixel_mask_corrected
|
||||
self.pixel_mask_pf = pixel_mask_pf
|
||||
|
||||
return pixel_mask_pf
|
||||
|
||||
|
||||
def get_saturated_pixels(self, image, double_pixels):
|
||||
return self.ju_stream_adapter.handler.get_saturated_pixels(image, double_pixels=double_pixels)
|
||||
|
||||
|
||||
|
@ -3,10 +3,9 @@ import os
|
||||
from random import randint
|
||||
from time import sleep
|
||||
|
||||
import jungfrau_utils as ju
|
||||
import numpy as np
|
||||
|
||||
from algos import calc_apply_additional_mask, calc_apply_threshold, calc_mask_pixels, calc_peakfinder_analysis, calc_radial_integration, calc_roi, calc_spi_analysis
|
||||
from algos import calc_apply_threshold, calc_mask_pixels, calc_peakfinder_analysis, calc_radial_integration, calc_roi, calc_spi_analysis, JFData
|
||||
from utils import json_load, read_bit
|
||||
from zmqsocks import ZMQSockets
|
||||
|
||||
@ -48,16 +47,14 @@ def work(backend_address, accumulator_host, accumulator_port, visualisation_host
|
||||
|
||||
pulse_id = 0
|
||||
|
||||
ju_stream_adapter = ju.StreamAdapter()
|
||||
jfdata = JFData()
|
||||
ju_stream_adapter = jfdata.ju_stream_adapter
|
||||
|
||||
zmq_socks = ZMQSockets(backend_address, accumulator_host, accumulator_port, visualisation_host, visualisation_port)
|
||||
|
||||
|
||||
pedestal_name_saved = None
|
||||
|
||||
pixel_mask_corrected = None
|
||||
pixel_mask_pf = None
|
||||
|
||||
n_aggregated_images = 1
|
||||
data_summed = None
|
||||
|
||||
@ -130,20 +127,10 @@ def work(backend_address, accumulator_host, accumulator_port, visualisation_host
|
||||
|
||||
data = np.ascontiguousarray(data)
|
||||
|
||||
# starting from ju 3.3.1 pedestal file is cached in library, re-calculated only if parameters (and/or pedestal file) are changed
|
||||
id_pixel_mask_1 = id(pixel_mask_corrected)
|
||||
pixel_mask_corrected = ju_stream_adapter.handler.get_pixel_mask(double_pixels=double_pixels)
|
||||
id_pixel_mask_2 = id(pixel_mask_corrected)
|
||||
pixel_mask_pf = jfdata.get_pixel_mask(results, double_pixels)
|
||||
|
||||
if id_pixel_mask_1 != id_pixel_mask_2:
|
||||
if pixel_mask_corrected is not None:
|
||||
pixel_mask_pf = np.ascontiguousarray(pixel_mask_corrected)
|
||||
calc_apply_additional_mask(results, pixel_mask_pf) # changes pixel_mask_pf in place
|
||||
else:
|
||||
pixel_mask_pf = None
|
||||
|
||||
if pixel_mask_corrected is not None:
|
||||
saturated_pixels_y, saturated_pixels_x = ju_stream_adapter.handler.get_saturated_pixels(image, double_pixels=double_pixels)
|
||||
if pixel_mask_pf is not None:
|
||||
saturated_pixels_y, saturated_pixels_x = jfdata.get_saturated_pixels(image, double_pixels)
|
||||
results["saturated_pixels"] = len(saturated_pixels_x)
|
||||
results["saturated_pixels_x"] = saturated_pixels_x.tolist()
|
||||
results["saturated_pixels_y"] = saturated_pixels_y.tolist()
|
||||
|
Reference in New Issue
Block a user