def export(self): from tifffile import imsave from pyqtgraph import FileDialog start_doc = getattr(self.catalog, self.stream).metadata['start'] if 'FileName' in start_doc: current_dir = str(Path(start_doc['FileName']).parent) current_name = Path(start_doc['FileName']).stem elif 'sample_name' in start_doc: current_dir = str( Path.home()) # sample name is usually just te file stem current_name = Path(start_doc['sample_name']).stem else: current_dir = Path.home() current_name = 'xicamNCEM_output' # Get a file path to save to in current directory fd = FileDialog() fd.setNameFilter("TIF (*.tif)") fd.setDirectory(current_dir) fd.selectFile(current_name) fd.setFileMode(FileDialog.AnyFile) fd.setAcceptMode(FileDialog.AcceptSave) if fd.exec_(): file_names = fd.selectedFiles()[0] outPath = Path(file_names) else: return if outPath.suffix != '.tif': outPath = outPath.with_suffix('.tif') scale0, units0 = self._get_physical_size() # Avoid overflow in field of view later if units0[0] == 'm': units0 = ['um', 'um'] scale0 = [ii * 1e6 for ii in scale0] # Change scale from pixel to 1/pixel FOV = [1 / ii for ii in scale0] # Add units to metadata for Imagej type output metadata = {'unit': units0[0]} # Get the data and change to float image = self.xarray[self.currentIndex, :, :].astype('f') imsave(outPath, image, imagej=True, resolution=FOV, metadata=metadata)