def qasync_init(self): app = QtWidgets.QApplication([]) self.loop = QEventLoop(app) asyncio.set_event_loop(self.loop)
def main(): args = get_argparser().parse_args() app = QtWidgets.QApplication(sys.argv) loop = QEventLoop(app) asyncio.set_event_loop(loop) magic_spec = results.parse_magic(args.path) if magic_spec is not None: paths = results.find_results(day="auto", **magic_spec) if len(paths) != 1: QtWidgets.QMessageBox.critical( None, "Unable to resolve experiment path", f"Could not resolve '{args.path}: {paths}'") sys.exit(1) path = next(iter(paths.values())).path else: path = args.path try: file = h5py.File(path, "r") except Exception as e: QtWidgets.QMessageBox.critical(None, "Unable to load file", str(e)) sys.exit(1) try: datasets = file["datasets"] except KeyError: QtWidgets.QMessageBox.critical( None, "Not an ARTIQ results file", "No ARTIQ dataset records found in file: '{}'".format(args.path)) sys.exit(1) prefix = fetch_explicit_prefix(args) if prefix is not None: try: # 'axes' existed since the earliest schema revisions, so we can use it to # detect whether the file/prefix the user specified vaguely looks like it # has been generated by ndscan. datasets[prefix + "axes"][()] except KeyError: QtWidgets.QMessageBox.critical( None, "Not an ndscan file", "Datasets '{}*' in file '{}' do not look like ndscan results.". format(prefix, args.path)) sys.exit(1) prefixes = [prefix] else: prefixes = find_ndscan_roots(datasets) if not prefixes: QtWidgets.QMessageBox.critical( None, "Not an ndscan file", "No ndscan result datasets found in file: '{}'".format( args.path)) sys.exit(1) try: schema = extract_param_schema( pyon.decode(file["expid"][()])["arguments"]) except Exception as e: print("No ndscan parameter arguments found:", e) schema = None if schema is not None: print("Scan settings") print("=============") print() for s in dump_scan(schema): print(s) print() print() print("Overrides") print("=========") print() for s in dump_overrides(schema): print(s) print() try: context = Context() context.set_title(os.path.basename(args.path)) # Take source_id from first prefix. This is pretty arbitrary, but for # experiment-generated files, they will all be the same anyway. if (prefixes[0] + "source_id") in datasets: source = datasets[prefixes[0] + "source_id"][()] if isinstance(source, bytes): # h5py 3+ – can use datasets[…].asstr() as soon as we don't support # version 2 any longer. source = source.decode("utf-8") context.set_source_id(source) else: # Old ndscan versions had a rid dataset instead of source_id. context.set_source_id("rid_{}".format(datasets[prefixes[0] + "rid"][()])) roots = [HDF5Root(datasets, p, context) for p in prefixes] except Exception as e: QtWidgets.QMessageBox.critical( None, "Error parsing ndscan file", "Error parsing datasets in '{}': {}".format(args.path, e)) sys.exit(2) if len(roots) == 1: widget = PlotContainerWidget(roots[0].get_model()) else: label_map = shorten_to_unambiguous_suffixes( prefixes, lambda fqn, n: ".".join(fqn.split(".")[-(n + 1):])) widget = MultiRootWidget( OrderedDict( zip((strip_suffix(label_map[p], ".") for p in prefixes), roots)), context) widget.setWindowTitle(f"{context.get_title()} – ndscan.show") widget.show() widget.resize(800, 600) sys.exit(app.exec_())