def create_flex_image (self, brightness=100, color_scheme=0, binning=1) : # XXX See also rstbx.slip_viewer.tile_generation._get_flex_image() typehash = str(self._raw.get_raw_data().__class__) if typehash.find('int') >= 0: from iotbx.detectors import FlexImage elif typehash.find('double') >= 0: from iotbx.detectors import FlexImage_d as FlexImage fi = FlexImage( binning=binning, brightness=brightness / 100, rawdata=self._raw.get_raw_data(), saturation=int(round(self._raw.get_detector()[0].get_trusted_range()[1])), vendortype=self._raw.__class__.__name__, color_scheme=color_scheme) #from scitbx.array_family import flex #print flex.max(self._raw.linearintdata), flex.min(self._raw.linearintdata) fi.setWindow(0.0, 0.0, 1) fi.adjust(color_scheme=color_scheme) fi.prep_string() return fi
def _get_flex_image( data, vendortype, binning=1, brightness=1.0, saturation=65535.0, show_untrusted=False, color_scheme=0, ): # This is a combination of the get_data_type() and get_flex_image() # functions from iotbx.detectors.detectorbase. XXX This may turn # out to be generally useful (see # e.g. rstbx.viewer.create_flex_image()), but where to place it? # dxtbx Format class? typehash = str(data.__class__) if typehash.find("int") >= 0: from iotbx.detectors import FlexImage elif typehash.find("double") >= 0: from iotbx.detectors import FlexImage_d as FlexImage return FlexImage( binning=binning, brightness=brightness, rawdata=data, saturation=int(round(saturation)), vendortype=vendortype, show_untrusted=show_untrusted, color_scheme=color_scheme, )
def event(self, evt, env): """The event() function is called for every L1Accept transition. It outputs the detector image associated with the event @p evt to the file system. @param evt Event data object, a configure object @param env Environment object """ super(mod_dump_bitmap, self).event(evt, env) if (evt.get('skip_event')): return # Where the sample-detector distance is not available, set it to # zero. distance = cspad_tbx.env_distance(self.address, env, self._detz_offset) if distance is None: distance = 0 # See r17537 of mod_average.py. device = cspad_tbx.address_split(self.address)[2] if device == 'Cspad': pixel_size = cspad_tbx.pixel_size saturated_value = cspad_tbx.cspad_saturated_value elif device == 'marccd': pixel_size = 0.079346 saturated_value = 2**16 - 1 from iotbx.detectors import FlexImage_d as FlexImage vendortype = device saturation = 65535 flex_img = FlexImage(rawdata=self.cspad_img, binning=self._binning, vendortype=vendortype, brightness=self._brightness, saturation=saturated_value) flex_img.setWindow(0, 0, 1) flex_img.adjust(color_scheme=self._color_scheme) flex_img.prep_string() import Image # XXX is size//self._binning safe here? pil_img = Image.fromstring('RGB', (flex_img.size2() // self._binning, flex_img.size1() // self._binning), flex_img.export_string) # The output path should not contain any funny characters which may # not work in all environments. This constructs a sequence number a # la evt_seqno() from the dictionary's timestamp. t = self.timestamp s = t[0:4] + t[5:7] + t[8:10] + t[11:13] + t[14:16] + t[17:19] + t[ 20:23] path = os.path.join(self._dirname, self._basename + s + '.' + self._ext) self._logger.info("Exporting %s" % path) tmp_stream = open(path, 'wb') pil_img.save(tmp_stream, format=self._format) tmp_stream.close()
def get_flex_image(self, binning=1, brightness=1.0): datatype = self.get_data_type() if datatype == "int": from iotbx.detectors import FlexImage elif datatype == "double": from iotbx.detectors import FlexImage_d as FlexImage return FlexImage(rawdata=self.linearintdata, binning=binning, vendortype=self.vendortype, brightness=brightness, saturation=int(getattr(self, "saturation", 65535)))
def create_flex_image (self, brightness=100, color_scheme=0, binning=1) : # XXX See also rstbx.slip_viewer.tile_generation._get_flex_image() typehash = str(self._raw.get_raw_data().__class__) if typehash.find('int') >= 0: from iotbx.detectors import FlexImage elif typehash.find('double') >= 0: from iotbx.detectors import FlexImage_d as FlexImage fi = FlexImage( binning=binning, brightness=brightness / 100, rawdata=self._raw.get_raw_data(), saturation=int(round(self._raw.get_detector()[0].get_trusted_range()[1])), vendortype=self._raw.__class__.__name__) #from scitbx.array_family import flex #print flex.max(self._raw.linearintdata), flex.min(self._raw.linearintdata) fi.setWindow(0.0, 0.0, 1) fi.adjust(color_scheme=color_scheme) fi.prep_string() return fi