def _setup_save_path(self): """ Prompt the user for a file to save comments and flags into. """ fail = True success = False info = "Where would you like to save comments and flags?" option = pick_item( [0, 1], [os.path.basename(self.filepath), "New MOSViz Table file"], label=info, title="Comment Setup") if option == 0: self.savepath = self.filepath elif option == 1: dirname = os.path.dirname(self.filepath) path = compat.getsavefilename(caption="New MOSViz Table File", basedir=dirname, filters="*.txt")[0] if path == "": return fail self.savepath = path else: return fail for v in self.session.application.viewers[0]: if isinstance(v, MOSVizViewer): if v.data_idx == self.data_idx: v.savepath = self.savepath self._layer_view.refresh() return success
def _setup_save_path(self): """ Prompt the user for a file to save comments and flags into. """ fail = True success = False info = "Where would you like to save comments and flags?" option = pick_item([0, 1], [os.path.basename(self.filepath), "New MOSViz Table file"], label=info, title="Comment Setup") if option == 0: self.savepath = self.filepath elif option == 1: dirname = os.path.dirname(self.filepath) path = compat.getsavefilename(caption="New MOSViz Table File", basedir=dirname, filters="*.txt")[0] if path == "": return fail self.savepath = path else: return fail for v in self.session.application.viewers[0]: if isinstance(v, MOSVizViewer): if v.data_idx == self.data_idx: v.savepath = self.savepath self._layer_view.refresh() return success
def preview(self): success = self.verify_input() if not success: self.statusBar().showMessage("Please fill in all fields") return t = self.make_catalog_table() if t is None: raise Exception("Spectra files were not found.") fb = list(t['id']) if len(fb) == 0: return row = pick_item(t, fb, title='Preview', label='Pick a target:') if row is None: return # Make cutouts using info in catalog. self.statusBar().showMessage("Making cutouts") output_path = os.path.join(self.save_path, self.output_dir_format) fits_cutouts, success_counter, success_table = go_make_cutouts( QTable(row), self.img_path, "cutouts", output_file_format=self.output_file_format, output_dir_format=output_path, clobber=True, apply_rotation=True, report=self.report) hdu = fits_cutouts[0] self.progress_bar.setMinimum(0) self.progress_bar.setMaximum(1) self.progress_bar.reset() QApplication.processEvents() if hdu is None: raise Exception("Could not make cutout. Object " "may be out of the image's range.") if self.session is not None: iv = StandaloneImageViewer(hdu.data, parent=self.session.application) iv.setWindowFlags(iv.windowFlags() | Qt.Tool) iv.show() else: import matplotlib.pyplot as plt plt.imshow(hdu.data) plt.show()
def preview(self): success = self.verify_input() if not success: self.statusBar().showMessage("Please fill in all fields") return fb, target_names = self.get_file_base() if len(fb) == 0: return fn = pick_item(fb, [os.path.basename(i) for i in fb], title='Preview', label='Pick a target:') if fb is None: return programName = os.path.basename(fn).split("_")[0] t, skipped = self.make_catalog_table([fn], target_names, programName) if t is None: raise Exception("Input spectra file has bad WCS and/or header.") #Make cutouts using info in catalog. self.statusBar().showMessage("Making cutouts") fits_cutouts, success_counter, success_table = go_make_cutouts( t, self.img_path, programName, output_file_format=self.output_file_format, output_dir_format=self.output_dir_format, clobber=True, apply_rotation=True, ispreview=True, report=self.report) hdu = fits_cutouts[0] self.progress_bar.setMinimum(0) self.progress_bar.setMaximum(1) self.progress_bar.reset() QApplication.processEvents() if hdu is None: raise Exception("Could not make cutout. " "Object may be out of the image's range.") if self.session is not None: iv = StandaloneImageViewer(hdu.data, parent=self.session.application) iv.setWindowFlags(iv.windowFlags() | Qt.Tool) iv.show() else: import matplotlib.pyplot as plt plt.imshow(hdu.data) plt.show()
def preview(self): success = self.verify_input() if not success: self.statusBar().showMessage("Please fill in all fields") return t = self.make_catalog_table() index = pick_item(range(len(t)), t["id"].tolist(), title='Preview', label='Pick a target:') if index is None: return t = QTable(t[index]) programName, file_extension = os.path.splitext(self.img_path) programName = os.path.basename(programName) #Make cutouts using info in catalog. self.statusBar().showMessage("Making cutouts") fits_cutouts, success_counter, success_table = go_make_cutouts( t, self.img_path, programName, output_file_format=self.output_file_format, output_dir_format=self.output_dir_format, clobber=True, apply_rotation=True, ispreview=True, report=self.report) hdu = fits_cutouts[0] self.progress_bar.setMinimum(0) self.progress_bar.setMaximum(1) self.progress_bar.reset() QApplication.processEvents() if hdu is None: raise Exception("Could not make cutout. " "Object may be out of the image's range.") if self.session is not None: iv = StandaloneImageViewer(hdu.data) iv.setWindowFlags(iv.windowFlags() | Qt.Tool) iv.show() else: import matplotlib.pyplot as plt plt.imshow(hdu.data) plt.show()
def preview(self): success = self.verify_input() if not success: self.statusBar().showMessage("Please fill in all fields") return t = self.make_catalog_table() if t is None: raise Exception("Spectra files were not found.") fb = list(t['id']) if len(fb) == 0: return row = pick_item(t, fb, title='Preview', label='Pick a target:') if row is None: return # Make cutouts using info in catalog. self.statusBar().showMessage("Making cutouts") output_path = os.path.join(self.save_path, self.output_dir_format) fits_cutouts, success_counter, success_table = go_make_cutouts( QTable(row), self.img_path, "cutouts", output_file_format=self.output_file_format, output_dir_format=output_path, clobber=True, apply_rotation=True, report=self.report) hdu = fits_cutouts[0] self.progress_bar.setMinimum(0) self.progress_bar.setMaximum(1) self.progress_bar.reset() QApplication.processEvents() if hdu is None: raise Exception("Could not make cutout. Object " "may be out of the image's range.") if self.session is not None: iv = StandaloneImageViewer(hdu.data, parent=self.session.application) iv.setWindowFlags(iv.windowFlags() | Qt.Tool) iv.show() else: import matplotlib.pyplot as plt plt.imshow(hdu.data) plt.show()
def custom_contour(self, *args): """ Draw contour of a specified component To change component programmatically change the `contour_component` class var :param args: arguments from toolbar """ components = self.cubeviz_layout.component_labels self.contour_component = pick_item(components, components, title='Custom Contour', label='Pick a component') if self.contour_component is None: return else: self.is_contour_active = True self.draw_contour()
def preview(self): success = self.verify_input() if not success: self.statusBar().showMessage("Please fill in all fields") return t = self.make_catalog_table() index = pick_item(range(len(t)) , t["id"].tolist(), title='Preview', label='Pick a target:') if index is None: return t = QTable(t[index]) programName, file_extension = os.path.splitext(self.img_path) programName = os.path.basename(programName) #Make cutouts using info in catalog. self.statusBar().showMessage("Making cutouts") fits_cutouts, success_counter, success_table = go_make_cutouts( t, self.img_path, programName, output_file_format=self.output_file_format, output_dir_format=self.output_dir_format, clobber=True, apply_rotation=True, ispreview=True, report=self.report) hdu = fits_cutouts[0] self.progress_bar.setMinimum(0) self.progress_bar.setMaximum(1) self.progress_bar.reset() QApplication.processEvents() if hdu is None: raise Exception("Could not make cutout. " "Object may be out of the image's range.") if self.session is not None: iv = StandaloneImageViewer(hdu.data) iv.setWindowFlags(iv.windowFlags() | Qt.Tool) iv.show() else: import matplotlib.pyplot as plt plt.imshow(hdu.data) plt.show()
def custom_contour(self, *args): """ Draw contour of a specified component To change component programmatically change the `contour_component` class var :param args: arguments from toolbar """ components = self.cubeviz_layout.component_labels self.contour_component = pick_item(components, components, title='Custom Contour', label='Pick a component') if self.contour_component is None: return else: self.is_contour_active = True self.draw_contour()
def custom_contour(self, *args): """ Draw contour of a specified component To change component programmatically change the `contour_component` class var :param args: arguments from toolbar """ self.is_contour_active = True components = self.cubeviz_layout.component_labels self.contour_component = pick_item(components, components, title='Custom Contour', label='Pick a component') if self.contour_component is None: # Edit toolbar menu to check the off option menu = self.toolbar.actions['cubeviz:contour'].menu() actions = menu.actions() for action in actions: if 'Off' == action.text(): action.setChecked(True) break self.remove_contour() else: self.draw_contour()