def saveImage(self): """Dump the current frame to a file""" outfile = datetime.datetime.now().strftime( "%Y%m%d-%H%M%S.%f") + ".tiff" if self.app: module_io = self.app.get_module("io") drc = module_io.get_experiment_directory() drc.mkdir(exist_ok=True, parents=True) outfile = drc / outfile try: flatfield, h = read_tiff(module_io.get_flatfield()) frame = apply_flatfield_correction(self.frame, flatfield) except: frame = self.frame h = {} else: frame = self.frame h = {} write_tiff(outfile, frame, header=h) print(" >> Wrote file:", outfile)
def apply_corrections(self, img, h): if self.flatfield is not None: img = remove_deadpixels(img, deadpixels=self.deadpixels) h['DeadPixelCorrection'] = True img = apply_flatfield_correction(img, flatfield=self.flatfield) h['FlatfieldCorrection'] = True return img, h
def __init__( self, buffer: list, # image buffer, list of (index [int], image data [2D numpy array], header [dict]) camera_length: float, # virtual camera length read from the microscope osc_angle: float, # degrees, oscillation angle of the rotation start_angle: float, # degrees, start angle of the rotation end_angle: float, # degrees, end angle of the rotation rotation_axis: float, # radians, specifies the position of the rotation axis acquisition_time: float, # seconds, acquisition time (exposure time + overhead) flatfield: str = 'flatfield.tiff'): if flatfield is not None: flatfield, h = read_tiff(flatfield) self.flatfield = flatfield self.headers = {} self.data = {} self.smv_subdrc = "data" while len(buffer) != 0: i, img, h = buffer.pop(0) self.headers[i] = h if self.flatfield is not None: self.data[i] = apply_flatfield_correction(img, self.flatfield) else: self.data[i] = img self.untrusted_areas = [] self.observed_range = set(self.data.keys()) self.complete_range = set( range(min(self.observed_range), max(self.observed_range) + 1)) self.missing_range = self.observed_range ^ self.complete_range self.data_shape = img.shape try: self.pixelsize = config.calibration.pixelsize_diff[ camera_length] # px / Angstrom except KeyError: self.pixelsize = 1 print( f"No calibrated pixelsize for camera length={camera_length}. Setting pixelsize to 1." ) logger.warning( f"No calibrated pixelsize for camera length={camera_length}. Setting pixelsize to 1." ) self.physical_pixelsize = config.camera.physical_pixelsize # mm self.wavelength = config.microscope.wavelength # angstrom # NOTE: Stretch correction - not sure if the azimuth and amplitude are correct anymore. self.do_stretch_correction = True self.stretch_azimuth = config.camera.stretch_azimuth self.stretch_amplitude = config.camera.stretch_amplitude self.distance = (1 / self.wavelength) * (self.physical_pixelsize / self.pixelsize) self.osc_angle = osc_angle self.start_angle = start_angle self.end_angle = end_angle self.rotation_axis = rotation_axis self.acquisition_time = acquisition_time #self.rotation_speed = get_calibrated_rotation_speed(osc_angle / self.acquisition_time) self.name = "Instamatic" from .XDS_template import XDS_template # hook XDS_template here, because it is difficult to override as a global self.XDS_template = XDS_template self.check_settings( ) # check if all required parameters are present, and fill default values if needed self.mean_beam_center, self.beam_center_std = self.get_beam_centers() logger.debug(f"Primary beam at: {self.mean_beam_center}")