def __init__(self, image_file, **kwargs): '''Initialise the image structure from the given file.''' from dxtbx import IncorrectFormatError if not self.understand(image_file): raise IncorrectFormatError(self, image_file) FormatPYunspecified.__init__(self, image_file, **kwargs)
def understand(image_file): """Seems like the static method wastes a lot of effort here; it's not possible to just read the first few bytes; instead understand() reads the entire first data item in the file; an entire binary image. This data is then read again in the _start() method and again in the detectorbase constructor. """ try: with FormatPYunspecified.open_file(image_file, "rb") as fh: if six.PY3: data = pickle.load(fh, encoding="bytes") # lgtm # the '# lgtm' comment disables an lgtm false positive and # can be removed once we move to Python 3 only data = { key.decode("ascii"): value for key, value in data.items() } else: data = pickle.load(fh) except IOError: return False if "OSC_START" not in data or "OSC_RANGE" not in data: return True return data["OSC_RANGE"] <= 0
def understand(image_file): """Seems like the static method wastes a lot of effort here; it's not possible to just read the first few bytes; instead understand() reads the entire first data item in the file; an entire binary image. This data is then read again in the _start() method and again in the detectorbase constructor. """ try: stream = FormatPYunspecified.open_file(image_file, 'rb') import cPickle as pickle data = pickle.load(stream) except IOError,e: return False
def understand(image_file): """Seems like the static method wastes a lot of effort here; it's not possible to just read the first few bytes; instead understand() reads the entire first data item in the file; an entire binary image. This data is then read again in the _start() method and again in the detectorbase constructor. """ try: stream = FormatPYunspecified.open_file(image_file, 'rb') import cPickle as pickle data = pickle.load(stream) except IOError, e: return False
def understand(image_file): """Seems like the static method wastes a lot of effort here; it's not possible to just read the first few bytes; instead understand() reads the entire first data item in the file; an entire binary image. This data is then read again in the _start() method and again in the detectorbase constructor. """ try: with FormatPYunspecified.open_file(image_file, "rb") as fh: data = image_dict_to_unicode(pickle.load(fh, encoding="bytes")) except OSError: return False if "OSC_START" not in data or "OSC_RANGE" not in data: return True return data["OSC_RANGE"] <= 0
def ImageFactory(filename): global parameters if type(filename)==type("") and os.path.isfile(filename): from dxtbx.format.FormatPYunspecified import FormatPYunspecified assert FormatPYunspecified.understand(filename) I = FormatPYunspecified(filename).get_detectorbase() else: print "This is not a file; assume the data are in the defined dictionary format" I = NpyImage(filename, source_data=parameters.horizons_phil.indexing.data) I.readHeader(parameters.horizons_phil) I.translate_tiles(parameters.horizons_phil) #from xfel.cxi.display_powder_arcs import apply_gaussian_noise #apply_gaussian_noise(I,parameters.horizons_phil) if (parameters.horizons_phil.viewer.powder_arcs.show): from xfel.cxi.display_powder_arcs import superimpose_powder_arcs superimpose_powder_arcs(I,parameters.horizons_phil) return I
def _start(self): FormatPYunspecified.start_helper( self, version_token="distl.detector_format_version=CXI 5.1")
def _start(self): FormatPYunspecified.start_helper(self,version_token="distl.detector_format_version=CXI 7.d")
def __init__(self, image_file): '''Initialise the image structure from the given file.''' assert(self.understand(image_file)) FormatPYunspecified.__init__(self, image_file)
def NpyImageFactory(filename): from dxtbx.format.FormatPYunspecified import FormatPYunspecified img = FormatPYunspecified(filename) return img.get_detectorbase()
def __init__(self, image_file, **kwargs): '''Initialise the image structure from the given file.''' assert (self.understand(image_file)) FormatPYunspecified.__init__(self, image_file, **kwargs)