def sxm_show(self): plt.close() plt.cla() fig = plt.figure() ax = fig.add_subplot() try: sxm = pySPM.SXM(self.current_file) except KeyError as err: QtWidgets.QMessageBox.warning( self, "Unable to read the file", "Unable to read the file: " + self.current_file + ", is it an available sxm file?", QtWidgets.QMessageBox.Yes, QtWidgets.QMessageBox.Yes) return channel = self.cfg.get("plot", "channel") cmap = self.cfg.get("plot", "cmap") if int(self.cfg.get("plot", "show_axis")) == 0: plt.axis('off') title = os.path.basename(self.current_file) if int(self.cfg.get("plot", "show_title")) == 0: title = "" if self.dataset_mode is True: title = "Dataset Mode: press 'x' as BAD, 'z' as GOOD" sxm.get_channel(channel).show(cmap=cmap, ax=ax, title=title) canvas = FigureCanvas(fig) self.setCentralWidget(canvas)
def __init__(self, filename_pattern, channel="Z"): self.filenames = filename_pattern self.scans = [spm.SXM(filename) for filename in self.filenames] self.smallest = 9999999 self.z_data = [] self.channel = channel for i, s in enumerate(self.scans): if channel == "Bias": pxs = s.get_channel("Bias").pixels else: pxs = s.get_channel("Z").pixels f = open(self.filenames[i], "r", encoding='latin-1') lines = f.readlines() scan_up = [ lines[i + 1 % len(lines)] for i, x in enumerate(lines) if x == ':SCAN_DIR:\n' ][0].strip() == 'up' if not scan_up: pxs = pxs[::-1] self.smallest = min(self.smallest, pxs.shape[0]) self.z_data.append(pxs) self._len = len(self.z_data) self._dtype = np.float32 self._frame_shape = (self.smallest, self.smallest) self.scan_size = self.scans[0].size self.meters_per_pixel = self.scan_size['real']['x'] / self.smallest
def sort_data(self, flag_path): if self.dataset_mode: self.statusBar.setStyleSheet("background-color: yellow") self.statusBar.showMessage('Saving: ' + self.current_file) path = os.path.join(self.dataset_dir, flag_path) index = self.dataset_cfg[ 'good_index'] if flag_path == 'good' else self.dataset_cfg[ 'bad_index'] filename = "{:05d}_Default.npy".format(index + 1) filename_ransac = "{:05d}_Ransac.npy".format(index + 1) # 感觉差不多没有对ransac处理 data = pySPM.SXM(self.current_file).get_channel( self.cfg.get("plot", "channel")).pixels resized_data = cv2.resize(data, (64, 64), interpolation=cv2.INTER_AREA) np.save(os.path.join(path, filename), resized_data) np.save(os.path.join(path, filename_ransac), resized_data) # deal with config.json if flag_path == 'good': self.dataset_cfg['good_index'] += 1 self.dataset_cfg['good'][self.dataset_cfg['good_index']] = { 'time': time.ctime(), 'saved_default': os.path.join(flag_path, filename), 'saved_ransac': os.path.join(flag_path, filename_ransac), 'source': self.current_file, 'source_dir': self.current_dir } if flag_path == 'bad': self.dataset_cfg['bad_index'] += 1 self.dataset_cfg['bad'][self.dataset_cfg['bad_index']] = { 'time': time.ctime(), 'saved_default': os.path.join(flag_path, filename), 'saved_ransac': os.path.join(flag_path, filename_ransac), 'source': self.current_file, 'source_dir': self.current_dir } # save it with open(self.dataset_cfg_file, 'w') as f: json.dump(self.dataset_cfg, f) self.statusBar.setStyleSheet("background-color: #98FB98") self.statusBar.showMessage('dataset saved: ' + self.current_file)
def save(self, sxmpath: str, savepath: str): if not sxmpath.endswith(".sxm"): return sxm = pySPM.SXM(sxmpath) channel = self.cfg.get("plot", "channel") sxm.get_channel(channel).show(cmap=self.cfg.get("save", "cmap")) if int(self.cfg.get("save", "show_title")) == 0: plt.title(None) try: if int(self.cfg.get("save", "show_axis")) == 0: plt.savefig(savepath, dpi=int(self.cfg.get("save", "fig_dpi")), bbox_inches='tight', pad_inches=0) else: plt.savefig(savepath, dpi=int(self.cfg.get("save", "fig_dpi"))) except PermissionError as e: QtWidgets.QMessageBox.warning( self, "unable to save", "Unable to save due to a PermissionError. Have you changed the the default path in Help-Options?", QtWidgets.QMessageBox.Yes, QtWidgets.QMessageBox.Yes)
def save(sxmpath: str, savepath: str, channel='Current'): if not sxmpath.endswith(".sxm"): return print("working with : "+sxmpath) sxm = pySPM.SXM(sxmpath) sxm.get_channel(channel).show(cmap='viridis') plt.savefig(savepath)
def show(sxmpath, channel='Current'): sxm = pySPM.SXM(sxmpath) sxm.get_channel(channel).show(cmap='viridis') plt.show()