コード例 #1
0
 def get_data(self):
     prefix = self.get_prefix()
     if prefix:
         self.import_file = prefix
     else:
         self.import_file = self.get_directory()
     filenames = self.get_files()
     v0 = self.read_image(filenames[0])
     x = NXfield(range(v0.shape[1]), dtype=np.uint16, name='x')
     y = NXfield(range(v0.shape[0]), dtype=np.uint16, name='y')
     z = NXfield(range(1, len(filenames) + 1), dtype=np.uint16, name='z')
     v = NXfield(shape=(len(filenames), v0.shape[0], v0.shape[1]),
                 dtype=v0.dtype,
                 name='v')
     v[0] = v0
     if v._memfile:
         chunk_size = v._memfile['data'].chunks[0]
     else:
         chunk_size = v.shape[0] / 10
     self.progress_bar.setVisible(True)
     self.progress_bar.setRange(0, len(filenames))
     for i in range(0, len(filenames)):
         try:
             files = []
             for j in range(i, i + chunk_size):
                 files.append(filenames[j])
                 self.progress_bar.setValue(j)
             self.update_progress()
             v[i:i + chunk_size, :, :] = self.read_images(files)
         except IndexError as error:
             pass
     global maximum
     v.maximum = maximum
     return NXentry(NXdata(v, (z, y, x)))
コード例 #2
0
ファイル: readstack.py プロジェクト: tacaswell/nexpy
 def get_data(self):
     prefix = self.get_prefix()
     if prefix:
         self.import_file = prefix
     else:
         self.import_file = self.get_directory()       
     filenames = self.get_files()
     v0 = self.read_image(filenames[0])
     x = NXfield(range(v0.shape[1]), dtype=np.uint16, name='x')
     y = NXfield(range(v0.shape[0]), dtype=np.uint16, name='y')
     z = NXfield(range(1,len(filenames)+1), dtype=np.uint16, name='z')
     v = NXfield(shape=(len(filenames),v0.shape[0],v0.shape[1]),
                 dtype=v0.dtype, name='v')
     v[0] = v0
     if v._memfile:
         chunk_size = v._memfile['data'].chunks[0]
     else:
         chunk_size = v.shape[0]/10
     self.progress_bar.setVisible(True)
     self.progress_bar.setRange(0, len(filenames))
     for i in range(0, len(filenames)):
         try:
             files = []
             for j in range(i,i+chunk_size):
                 files.append(filenames[j])
                 self.progress_bar.setValue(j)
             self.update_progress()
             v[i:i+chunk_size,:,:] = self.read_images(files)
         except IndexError as error:
             pass
     global maximum
     v.maximum = maximum
     return NXentry(NXdata(v,(z,y,x)))
コード例 #3
0
    def get_data(self):
        prefix = self.get_prefix()
        if prefix:
            self.import_file = prefix
        else:
            self.import_file = self.get_directory()
        filenames = self.get_files()
        try:
            import fabio
        except ImportError:
            raise NeXusError("Please install the 'fabio' module")
        im = self.read_image(filenames[0])
        v0 = im.data
        x = NXfield(range(v0.shape[1]), dtype=np.uint16, name='x')
        y = NXfield(range(v0.shape[0]), dtype=np.uint16, name='y')
        z = NXfield(range(1, len(filenames)+1), dtype=np.uint16, name='z')
        v = NXfield(shape=(len(filenames), v0.shape[0], v0.shape[1]),
                    dtype=v0.dtype, name='v')
        v[0] = v0
        if v._memfile:
            chunk_size = v._memfile['data'].chunks[0]
        else:
            chunk_size = v.shape[0]/10
        self.progress_bar.setVisible(True)
        self.progress_bar.setRange(0, len(filenames))
        for i in range(0, len(filenames), chunk_size):
            try:
                files = []
                for j in range(i, i+chunk_size):
                    files.append(filenames[j])
                    self.progress_bar.setValue(j)
                self.update_progress()
                v[i:i+chunk_size, :, :] = self.read_images(files)
            except IndexError as error:
                pass
        global maximum
        v.maximum = maximum

        if im.getclassname() == 'CbfImage':
            note = NXnote(type='text/plain', file_name=self.import_file)
            note.data = im.header.pop('_array_data.header_contents', '')
            note.description = im.header.pop(
                '_array_data.header_convention', '')
        else:
            note = None

        header = NXcollection()
        for key, value in im.header.items():
            header[key] = value

        if note:
            return NXentry(
                NXdata(
                    v, (z, y, x),
                    CBF_header=note, header=header))
        else:
            return NXentry(NXdata(v, (z, y, x), header=header))