def test_write_read_crystfel_file(tmpdir): geom = jf4m_geometry() path = str(tmpdir / 'test.geom') geom.write_crystfel_geom(filename=path, photon_energy=9000, adu_per_ev=0.0042, clen=0.101) loaded = JUNGFRAUGeometry.from_crystfel_geom(path) assert_geom_close(loaded, geom) assert loaded.metadata['crystfel']['adu_per_eV'] == 0.0042 assert loaded.metadata['crystfel']['clen'] == 0.101 # Load the geometry file with cfelpyutils and test the rigid groups geom_dict = load_crystfel_geometry(path) assert geom_dict['panels']['p0a0']['res'] == 1 / 75e-6 p3a7 = geom_dict['panels']['p3a7'] assert p3a7['min_ss'] == 256 assert p3a7['max_ss'] == 511 assert p3a7['min_fs'] == 768 assert p3a7['max_fs'] == 1023 # Check that metadata is written back to .geom file OK path2 = str(tmpdir / 'test2.geom') loaded.write_crystfel_geom(filename=path2, photon_energy=9000) re_loaded = JUNGFRAUGeometry.from_crystfel_geom(path) assert re_loaded.metadata == loaded.metadata
def from_crystfel_geom(cls, filename): """Read a CrystFEL format (.geom) geometry file. Returns a new geometry object. """ geom_dict = load_crystfel_geometry(filename) panels_by_data_coord = cls._cfel_panels_by_data_coord( geom_dict['panels']) n_modules = cls.n_modules if n_modules == 0: # Detector type with varying number of modules (e.g. JUNGFRAU) n_modules = max(c[0] for c in panels_by_data_coord) + 1 modules = [] for p in range(n_modules): tiles = [] modules.append(tiles) for a in range(cls.n_tiles_per_module): ss_slice, fs_slice = cls._tile_slice(a) d = panels_by_data_coord[p, ss_slice.start, fs_slice.start] tiles.append(GeometryFragment.from_panel_dict(d)) # Store some extra fields to write if we create another .geom file. # It's possible for these to have different values for different panels, # but it seems to be common to use them like headers, describing all # panels, and we're assuming that's the case here. cfel_md_keys = ('data', 'mask', 'adu_per_eV', 'clen') d1 = panels_by_data_coord[0, 0, 0] metadata = {'crystfel': {k: d1.get(k) for k in cfel_md_keys}} # TODO: photon_energy (not returned with cfelpyutils 1.0) return cls(modules, filename=filename, metadata=metadata)
def test_write_read_crystfel_file(tmpdir): geom = AGIPD_1MGeometry.from_quad_positions( quad_pos=[(-525, 625), (-550, -10), (520, -160), (542.5, 475)]) # Use the z dimension (coffset in .geom) geom = geom.offset((0, 0, 0.001), modules=np.s_[8:12]) path = str(tmpdir / 'test.geom') geom.write_crystfel_geom(filename=path, photon_energy=9000, adu_per_ev=0.0075, clen=0.2) loaded = AGIPD_1MGeometry.from_crystfel_geom(path) assert_geom_close(loaded, geom) # Load the geometry file with cfelpyutils and test the rigid groups geom_dict = load_crystfel_geometry(path) quad_gr0 = [ # 1st quadrant: p0a0 ... p3a7 'p{}a{}'.format(p, a) for p, a in product(range(4), range(8)) ] assert geom_dict['rigid_groups']['p0'] == quad_gr0[:8] assert geom_dict['rigid_groups']['p3'] == quad_gr0[-8:] assert geom_dict['rigid_groups']['q0'] == quad_gr0 assert geom_dict['panels']['p0a0']['res'] == 5000 # 5000 pixels/metre p3a7 = geom_dict['panels']['p3a7'] assert p3a7['min_ss'] == 448 assert p3a7['max_ss'] == 511 assert p3a7['min_fs'] == 0 assert p3a7['max_fs'] == 127
def test_write_read_crystfel_file(tmpdir): geom = LPD_1MGeometry.from_quad_positions([(11.4, 299), (-11.5, 8), (254.5, -16), (278.5, 275)]) path = str(tmpdir / 'test.geom') geom.write_crystfel_geom(filename=path) with open(path, 'r') as f: contents = f.read() with open(path, 'w') as f: f.write('clen = 0.119\n') f.write('adu_per_eV = 0.0075\n') f.write(contents) # Load the geometry file with cfelpyutils and test the ridget groups loaded = LPD_1MGeometry.from_crystfel_geom(path) np.testing.assert_allclose(loaded.modules[0][0].corner_pos, geom.modules[0][0].corner_pos) np.testing.assert_allclose(loaded.modules[0][0].fs_vec, geom.modules[0][0].fs_vec) geom_dict = load_crystfel_geometry(path) quad_gr0 = [ 'p0a0', 'p0a1', 'p0a2', 'p0a3', 'p0a4', 'p0a5', 'p0a6', 'p0a7', 'p0a8', 'p0a9', 'p0a10', 'p0a11', 'p0a12', 'p0a13', 'p0a14', 'p0a15', 'p1a0', 'p1a1', 'p1a2', 'p1a3', 'p1a4', 'p1a5', 'p1a6', 'p1a7', 'p1a8', 'p1a9', 'p1a10', 'p1a11', 'p1a12', 'p1a13', 'p1a14', 'p1a15', 'p2a0', 'p2a1', 'p2a2', 'p2a3', 'p2a4', 'p2a5', 'p2a6', 'p2a7', 'p2a8', 'p2a9', 'p2a10', 'p2a11', 'p2a12', 'p2a13', 'p2a14', 'p2a15', 'p3a0', 'p3a1', 'p3a2', 'p3a3', 'p3a4', 'p3a5', 'p3a6', 'p3a7', 'p3a8', 'p3a9', 'p3a10', 'p3a11', 'p3a12', 'p3a13', 'p3a14', 'p3a15' ] assert geom_dict['rigid_groups']['p0'] == quad_gr0[:16] assert geom_dict['rigid_groups']['p3'] == quad_gr0[-16:] assert geom_dict['rigid_groups']['q0'] == quad_gr0
def main(geometry_file, hostname, port): """ OnDA graphical user interface for crystallography. This program must connect to a running OnDA monitor for crystallography. If the monitor broacasts information on Bragg peaks and hit and saturation rates, this GUI will display their evolution over time, plus a real-time virtual powder pattern created using the detected peaks. GEOMETRY_FILE: the relative or absolute path to a file containing the detector geometry information (in CrystFEL format) to be used for visualization. HOSTNAME: the hostname where the GUI will listen for data. Optional: if not provided, it defaults to localhost (127.0.0.1). PORT: the port at which the GUI will listen for data. Optional: if not provided, it defaults to 12321. """ if hostname is None: hostname = "127.0.0.1" if port is None: port = 12321 geometry = cfel_crystfel.load_crystfel_geometry(geometry_file) app = QtGui.QApplication(sys.argv) _ = CrystallographyGui(geometry, hostname, port) sys.exit(app.exec_())
def test_write_read_crystfel_file(tmpdir): geom = AGIPD_500K2GGeometry.from_origin() path = str(tmpdir / 'test.geom') geom.write_crystfel_geom(filename=path, photon_energy=9000, adu_per_ev=0.0075, clen=0.2) loaded = AGIPD_500K2GGeometry.from_crystfel_geom(path) np.testing.assert_allclose(loaded.modules[0][0].corner_pos, geom.modules[0][0].corner_pos) np.testing.assert_allclose(loaded.modules[0][0].fs_vec, geom.modules[0][0].fs_vec) # Load the geometry file with cfelpyutils and test the rigid groups geom_dict = load_crystfel_geometry(path) quad_gr0 = [ # quadrant: p0a0 ... p7a7 'p{}a{}'.format(p, a) for p, a in product(range(8), range(8)) ] assert geom_dict['rigid_groups']['p0'] == quad_gr0[:8] assert geom_dict['rigid_groups']['p7'] == quad_gr0[-8:] assert geom_dict['rigid_groups']['q0'] == quad_gr0 assert geom_dict['panels']['p0a0']['res'] == 5000 # 5000 pixels/metre p3a7 = geom_dict['panels']['p3a7'] assert p3a7['min_ss'] == 448 assert p3a7['max_ss'] == 511 assert p3a7['min_fs'] == 0 assert p3a7['max_fs'] == 127
def main(geometry_file, hostname, port): # type: (Dict[str, Any], str, int) -> None """ OnDA frame viewer for crystallography. This program must connect to a running OnDA monitor for crystallography. If the monitor broadcasts detector frame data, this viewer will display it. The viewer will also show, overlayed on the frame data, any found Bragg peak. The data stream from the monitor can also be temporarily paused, and any of the last 10 displayed detector frames can be recalled for inspection. GEOMETRY_FILE: the relative or absolute path to a file containing the detector geometry information (in CrystFEL format) to be used for visualization. HOSTNAME: the hostname where viewer will listen for data. Optional: if not provided, it defaults to localhost (127.0.0.1). PORT: the port at which the viewer will listen for data. Optional: if not provided, it defaults to 12321. """ if hostname is None: hostname = "127.0.0.1" if port is None: port = 12321 geometry = cfel_crystfel.load_crystfel_geometry(geometry_file) app = QtGui.QApplication(sys.argv) _ = CrystallographyFrameViewer(geometry, hostname, port) sys.exit(app.exec_())
def detectorGeometryFromFile(input_file): # Create DetectorGeometry class from .geom file geometryDict = load_crystfel_geometry(input_file) panelDicts = geometryDict['panels'] panels = [ _detectorPanelFromDict(panelDicts[panel]) for panel in panelDicts ] return DetectorGeometry(panels=panels)
def from_crystfel_geom(cls, n_rows, n_columns, filename): from cfelpyutils.crystfel_utils import load_crystfel_geometry from extra_geom.detectors import GeometryFragment geom_dict = load_crystfel_geometry(filename) modules = [] for i_p in module_indices(n_rows * n_columns, detector="JungFrau"): i_a = 1 if i_p > 4 else 8 d = geom_dict['panels'][f'p{i_p}a{i_a}'] modules.append(GeometryFragment.from_panel_dict(d).corner_pos) return cls(n_rows, n_columns, modules)
def from_crystfel_geom(cls, filename): """Read a CrystFEL format (.geom) geometry file. Returns a new geometry object. """ geom_dict = load_crystfel_geometry(filename) modules = [] for p in range(16): tiles = [] modules.append(tiles) for a in range(8): d = geom_dict['panels']['p{}a{}'.format(p, a)] tiles.append(GeometryFragment.from_panel_dict(d)) return cls(modules, filename=filename)
def from_crystfel_geom(cls, filename): from cfelpyutils.crystfel_utils import load_crystfel_geometry from extra_geom.detectors import GeometryFragment geom_dict = load_crystfel_geometry(filename) modules = [] for p in range(cls.n_modules): tiles = [] modules.append(tiles) for a in range(cls.n_tiles_per_module): d = geom_dict['panels']['p{}a{}'.format(p, a)] tiles.append(GeometryFragment.from_panel_dict(d).corner_pos) return cls(modules)
def test_write_read_crystfel_file(tmpdir): geom = jf4m_geometry() path = str(tmpdir / 'test.geom') geom.write_crystfel_geom(filename=path, photon_energy=9000, adu_per_ev=0.0042, clen=0.101) loaded = JUNGFRAUGeometry.from_crystfel_geom(path) assert_geom_close(loaded, geom) # Load the geometry file with cfelpyutils and test the rigid groups geom_dict = load_crystfel_geometry(path) assert geom_dict['panels']['p0a0']['res'] == 1 / 75e-6 p3a7 = geom_dict['panels']['p3a7'] assert p3a7['min_ss'] == 256 assert p3a7['max_ss'] == 511 assert p3a7['min_fs'] == 768 assert p3a7['max_fs'] == 1023
def test_write_read_crystfel_file(args, tmpdir): epix, (nrow, ncol), pxsz, cls = args path = str(tmpdir / 'test.geom') epix.write_crystfel_geom(filename=path, photon_energy=9000, adu_per_ev=0.0042, clen=0.101) loaded = cls.from_crystfel_geom(path) assert_geom_close(loaded, epix) # Load the geometry file with cfelpyutils and test the rigid groups geom_dict = load_crystfel_geometry(path) assert geom_dict['panels']['p0a0']['res'] == 1 / pxsz assert len(geom_dict['panels']) == 4 p0a0 = geom_dict['panels']['p0a0'] assert p0a0['max_ss'] == nrow - 1 assert p0a0['min_ss'] == 0 assert p0a0['max_fs'] == ncol - 1 assert p0a0['min_fs'] == 0
def test_write_read_crystfel_file_2d(tmpdir): geom = AGIPD_500K2GGeometry.from_origin() path = str(tmpdir / 'test.geom') geom.write_crystfel_geom(filename=path, dims=('frame', 'ss', 'fs'), adu_per_ev=0.0075, clen=0.2) loaded = AGIPD_500K2GGeometry.from_crystfel_geom(path) np.testing.assert_allclose(loaded.modules[0][0].corner_pos, geom.modules[0][0].corner_pos) np.testing.assert_allclose(loaded.modules[0][0].fs_vec, geom.modules[0][0].fs_vec) # Load the geometry file with cfelpyutils and check some values geom_dict = load_crystfel_geometry(path) p3a7 = geom_dict['panels']['p3a7'] assert p3a7['dim_structure'] == ['%', 'ss', 'fs'] assert p3a7['min_ss'] == (3 * 512) + 448 assert p3a7['max_ss'] == (3 * 512) + 511 assert p3a7['min_fs'] == 0 assert p3a7['max_fs'] == 127
def main(): """Parse command line arguments and convert file""" logging.basicConfig(filename='recon.log', level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') parser = py_utils.MyArgparser(description='cheetahtodet') parser.add_argument('geom_fname', help='CrystFEL geometry file to convert to detector format') parser.add_argument('-M', '--mask', help='Path to detector style mask (0:good, 1:no_orient, 2:bad) in h5 file') parser.add_argument('--mask_dset', help='Data set in mask file. Default: /data/data', default='data/data') parser.add_argument('--dragonfly_mask', help='Whether mask has Dragonfly style values or not. (Default: false)', default=False, action='store_true') args = parser.special_parse_args() logging.info('Starting cheetahtodet...') logging.info(' '.join(sys.argv)) pm = read_config.get_detector_config(args.config_file, show=args.vb) # pylint: disable=invalid-name q_pm = read_config.compute_q_params(pm['detd'], pm['dets_x'], pm['dets_y'], pm['pixsize'], pm['wavelength'], pm['ewald_rad'], show=args.vb) output_folder = read_config.get_filename(args.config_file, 'emc', 'output_folder') # CrystFEL geometry files have coordinates in pixel size units geom = crystfel_utils.load_crystfel_geometry(args.geom_fname) pixmap = geometry_utils.compute_pix_maps(geom) x = pixmap.x y = pixmap.y z = pm['detd'] / pm['pixsize'] pm['pixsize'] = 1. det = detector.Detector() norm = np.sqrt(x*x + y*y + z*z) qscaling = 1. / pm['wavelength'] / q_pm['q_sep'] det.qx = x * qscaling / norm det.qy = y * qscaling / norm det.qz = qscaling * (z / norm - 1.) det.corr = pm['detd']*(pm['pixsize']*pm['pixsize']) / np.power(norm, 3.0) det.corr *= read_config.compute_polarization(pm['polarization'], x, y, norm) if args.mask is None: radius = np.sqrt(x*x + y*y) rmax = min(np.abs(x.max()), np.abs(x.min()), np.abs(y.max()), np.abs(y.min())) det.raw_mask = np.zeros(det.corr.shape, dtype='u1') det.raw_mask[radius > rmax] = 1 else: with h5py.File(args.mask, 'r') as fptr: det.raw_mask = fptr[args.mask_dset][:].astype('u1').flatten() if not args.dragonfly_mask: det.raw_mask = 2 - 2*det.raw_mask det.detd = pm['detd'] / pm['pixsize'] det.ewald_rad = pm['ewald_rad'] det_file = output_folder + '/' + os.path.splitext(os.path.basename(args.geom_fname))[0] try: import h5py det_file += '.h5' except ImportError: det_file += '.dat' logging.info('Writing detector file to %s', det_file) sys.stderr.write('Writing detector file to %s\n'%det_file) det.write(det_file)
def from_crystfel_geom(cls, filename): geom_dict = load_crystfel_geometry(filename) return cls(geom_dict, filename)
def convert_crystfel_to_dxtbx(geom_filename, output_filename, detdist_override=None): """ :param geom_filename: a crystfel geometry file https://www.desy.de/~twhite/crystfel/manual-crystfel_geometry.html :param output_filename: filename for a dxtbx experiment containing a single detector model (this is a json file) :param detdist_override: alter the detector distance stored in the crystfel geometry to this value (in millimeters) """ geom = load_crystfel_geometry(geom_filename) dxtbx_det = Detector() for panel_name in geom['panels'].keys(): P = geom['panels'][panel_name] FAST = P['fsx'], P['fsy'], P['fsz'] SLOW = P['ssx'], P['ssy'], P['ssz'] # dxtbx uses millimeters pixsize = 1 / P['res'] # meters pixsize_mm = pixsize * 1000 detdist = P['coffset'] + P['clen'] # meters detdist_mm = detdist * 1000 if detdist_override is not None: detdist_mm = detdist_override # dxtbx and crystfel both identify the outer corner of the first pixel in memory as the origin of the panel origin = P['cnx'] * pixsize_mm, P[ 'cny'] * pixsize_mm, -detdist_mm # dxtbx assumes crystal as at point 0,0,0 num_fast_pix = P["max_fs"] - P['min_fs'] + 1 num_slow_pix = P["max_ss"] - P['min_ss'] + 1 panel_description = { 'fast_axis': FAST, 'gain': 1.0, # I dont think nanoBragg cares about this parameter 'identifier': '', 'image_size': (num_fast_pix, num_slow_pix), 'mask': [], 'material': 'Si', 'mu': 0, # NOTE for a thick detector set this to appropriate value 'name': panel_name, 'origin': origin, 'pedestal': 0.0, # I dont think nanoBragg cares about this parameter 'pixel_size': (pixsize_mm, pixsize_mm), 'px_mm_strategy': { 'type': 'SimplePxMmStrategy' }, 'raw_image_offset': (0, 0), # not sure what this is 'slow_axis': SLOW, 'thickness': 0, # note for a thick detector set this to appropriate value 'trusted_range': (-1.0, 1e6), # set as you wish 'type': 'SENSOR_PAD' } dxtbx_node = Panel.from_dict(panel_description) dxtbx_det.add_panel(dxtbx_node) E = Experiment() E.detector = dxtbx_det El = ExperimentList() El.append(E) El.as_file(output_filename) # this can be loaded into nanoBragg
def set_corner_y(self, corner_y): self.corner_y = corner_y def Printer(self): print(self.name, self.array) #self.min_fs,self.min_ss,self.max_fs,self.max_ss) def set_array(self, matrix): self.array = matrix[self.min_ss:self.max_ss, self.min_fs:self.max_fs] def get_array(self): return self.array # parsefile to ditc the geom file global geom = c.load_crystfel_geometry( "/home/tsachanowski/CrystFELL_tutorial/5HT2B-Liu-2013.geom") # tworzy dict do plikow chirarcha drzewa def katalog(slownik): for x in slownik.keys(): if type(slownik[x] ) == h5py._hl.group.Group: #czyli dana nazwa jest grupa slownik[x] = {z: slownik[x][z] for z in slownik[x]} # slownik pod danym kluczem #ma katalog to z tego robie slownik ktory ajko klucz ma nazwe rzeczy w tym katalogu #a wartsoc to jest referencja do tego pliku/katalogu katalog(slownik[x]) return slownik
def __init__(self, source, monitor_parameters): # type: (str, parameters.MonitorParams) -> None """ An OnDA real-time monitor for serial x-ray crystallography experiments. This monitor processes detector data frames, optionally applying detector calibration, dark correction and gain correction. It detects Bragg peaks in each detector frame using the peakfinder8 algorithm from Cheetah. It provides information about the location and integrated intensity of each peak. Additionally, it calculates the evolution of the hit and saturation rates over time. It broadcasts all this information over a network socket for visualization by other programs. Optionally, it can also broadcast calibrated and corrected detector data frames. Arguments: source (str): a string describing the data source. The exact format of the string depends on the specific Data Recovery Layer currently being used. See the documentation of the relevant 'initialize_event_source' function. monitor_params (:class:`~onda.utils.parameters.MonitorParams`): an object storing the OnDA monitor parameters from the configuration file. """ super(OndaMonitor, self).__init__( process_func=self.process_data, collect_func=self.collect_data, source=source, monitor_params=monitor_parameters, ) if self.role == "worker": requested_calibration_algorithm = monitor_parameters.get_param( group="DetectorCalibration", parameter="calibration_algorithm", type_=str, ) if requested_calibration_algorithm is not None: calibration_alg = getattr(calib_algs, requested_calibration_algorithm) self._calibration = calibration_alg( calibration_file=monitor_parameters.get_param( group="DetectorCalibration", parameter="calibration_file", type_=str, required=True, )) else: # If no calibration is required, stores None in the 'calibration_alg' # attribute. self._calibration = None self._hit_frame_sending_counter = 0 self._non_hit_frame_sending_counter = 0 dark_data_filename = monitor_parameters.get_param( group="Correction", parameter="dark_filename", type_=str) dark_data_hdf5_path = monitor_parameters.get_param( group="Correction", parameter="dark_hdf5_path", type_=str) mask_filename = monitor_parameters.get_param( group="Correction", parameter="mask_filename", type_=str) mask_hdf5_path = monitor_parameters.get_param( group="Correction", parameter="mask_hdf5_path", type_=str) gain_map_filename = monitor_parameters.get_param( group="Correction", parameter="gain_filename", type_=str) gain_map_hdf5_path = monitor_parameters.get_param( group="Correction", parameter="gain_hdf5_path", type_=str) self._correction = gen_algs.Correction( dark_filename=dark_data_filename, dark_hdf5_path=dark_data_hdf5_path, mask_filename=mask_filename, mask_hdf5_path=mask_hdf5_path, gain_filename=gain_map_filename, gain_hdf5_path=gain_map_hdf5_path, ) geometry_filename = monitor_parameters.get_param( group="Crystallography", parameter="geometry_file", type_=str, required=True, ) geometry = crystfel_utils.load_crystfel_geometry(geometry_filename) pixelmaps = geometry_utils.compute_pix_maps(geometry) radius_pixel_map = pixelmaps.r pf8_detector_info = dynamic_import.get_peakfinder8_info( monitor_params=monitor_parameters) pf8_max_num_peaks = monitor_parameters.get_param( group="Peakfinder8PeakDetection", parameter="max_num_peaks", type_=int, required=True, ) pf8_adc_threshold = monitor_parameters.get_param( group="Peakfinder8PeakDetection", parameter="adc_threshold", type_=float, required=True, ) pf8_minimum_snr = monitor_parameters.get_param( group="Peakfinder8PeakDetection", parameter="minimum_snr", type_=float, required=True, ) pf8_min_pixel_count = monitor_parameters.get_param( group="Peakfinder8PeakDetection", parameter="min_pixel_count", type_=int, required=True, ) pf8_max_pixel_count = monitor_parameters.get_param( group="Peakfinder8PeakDetection", parameter="max_pixel_count", type_=int, required=True, ) pf8_local_bg_radius = monitor_parameters.get_param( group="Peakfinder8PeakDetection", parameter="local_bg_radius", type_=int, required=True, ) pf8_min_res = monitor_parameters.get_param( group="Peakfinder8PeakDetection", parameter="min_res", type_=int, required=True, ) pf8_max_res = monitor_parameters.get_param( group="Peakfinder8PeakDetection", parameter="max_res", type_=int, required=True, ) pf8_bad_pixel_map_fname = monitor_parameters.get_param( group="Peakfinder8PeakDetection", parameter="bad_pixel_map_filename", type_=str, ) if pf8_bad_pixel_map_fname is not None: pf8_bad_pixel_map_hdf5_path = monitor_parameters.get_param( group="Peakfinder8PeakDetection", parameter="bad_pixel_map_hdf5_path", type_=str, required=True, ) else: pf8_bad_pixel_map_hdf5_path = None self._peak_detection = cryst_algs.Peakfinder8PeakDetection( max_num_peaks=pf8_max_num_peaks, asic_nx=pf8_detector_info.asic_nx, asic_ny=pf8_detector_info.asic_ny, nasics_x=pf8_detector_info.nasics_x, nasics_y=pf8_detector_info.nasics_y, adc_threshold=pf8_adc_threshold, minimum_snr=pf8_minimum_snr, min_pixel_count=pf8_min_pixel_count, max_pixel_count=pf8_max_pixel_count, local_bg_radius=pf8_local_bg_radius, min_res=pf8_min_res, max_res=pf8_max_res, bad_pixel_map_filename=pf8_bad_pixel_map_fname, bad_pixel_map_hdf5_path=pf8_bad_pixel_map_hdf5_path, radius_pixel_map=radius_pixel_map, ) self._max_saturated_peaks = monitor_parameters.get_param( group="Crystallography", parameter="max_saturated_peaks", type_=int, required=True, ) self._min_num_peaks_for_hit = monitor_parameters.get_param( group="Crystallography", parameter="min_num_peaks_for_hit", type_=int, required=True, ) self._max_num_peaks_for_hit = monitor_parameters.get_param( group="Crystallography", parameter="max_num_peaks_for_hit", type_=int, required=True, ) self._saturation_value = monitor_parameters.get_param( group="Crystallography", parameter="saturation_value", type_=int, required=True, ) self._hit_frame_sending_interval = monitor_parameters.get_param( group="Crystallography", parameter="hit_frame_sending_interval", type_=int, ) self._non_hit_frame_sending_interval = monitor_parameters.get_param( group="Crystallography", parameter="non_hit_frame_sending_interval", type_=int, ) print("Starting worker: {0}.".format(self.rank)) sys.stdout.flush() if self.role == "master": self._speed_report_interval = monitor_parameters.get_param( group="Crystallography", parameter="speed_report_interval", type_=int, required=True, ) self._geometry_is_optimized = monitor_parameters.get_param( group="Crystallography", parameter="geometry_is_optimized", type_=bool, required=True, ) num_events_to_accumulate = monitor_parameters.get_param( group="DataAccumulator", parameter="num_events_to_accumulate", type_=int, required=True, ) self._data_accumulator = gen_algs.DataAccumulator( num_events_to_accumulate=num_events_to_accumulate) self._running_average_window_size = monitor_parameters.get_param( group="Crystallography", parameter="running_average_window_size", type_=int, required=True, ) self._hit_rate_running_window = collections.deque( [0.0] * self._running_average_window_size, maxlen=self._running_average_window_size, ) self._saturation_rate_running_window = collections.deque( [0.0] * self._running_average_window_size, maxlen=self._running_average_window_size, ) self._avg_hit_rate = 0 self._avg_sat_rate = 0 broadcast_socket_ip = monitor_parameters.get_param( group="Crystallography", parameter="broadcast_ip", type_=str) broadcast_socket_port = monitor_parameters.get_param( group="Crystallography", parameter="broadcast_port", type_=int) self._data_broadcast_socket = zmq_monitor.ZmqDataBroadcaster( hostname=broadcast_socket_ip, port=broadcast_socket_port) self._num_events = 0 self._old_time = time.time() self._time = None print("Starting the monitor...") sys.stdout.flush()
from cfelpyutils.crystfel_utils import load_crystfel_geometry from cfelpyutils.geometry_utils import apply_geometry_to_data HIGH_GAIN = 0 MEDIUM_GAIN = 1 LOW_GAIN = 2 DATA_KEY = 'data' GAIN_KEY = 'gain' PULSE_KEY = 'pulseId' TRAIN_KEY = 'trainId' CHEETAH_PATH = "/gpfs/exfel/u/scratch/MID/201802/p002200/cheetah/hdf5/r{0:04d}-data/XFEL-r{0:04d}-c{1:02d}.h5" OUT_PATH = "hdf5" CORES_COUNT = cpu_count() BG_ROI = (slice(5000), slice(None)) PUPIL_ROI = (slice(750, 1040), slice(780, 1090)) AGIPD_GEOM = load_crystfel_geometry( os.path.join(os.path.dirname(__file__), "agipd.geom")) def apply_agipd_geom(frame): return apply_geometry_to_data(frame, AGIPD_GEOM) def make_output_dir(path): try: os.makedirs(path) except OSError as error: if error.errno != errno.EEXIST: raise OSError(error.errno, error.strerror, error.filename)