def new_zernike_window(app, args, pars={}): def quit(str1): e = QErrorMessage() e.showMessage(str1) sys.exit(e.exec_()) calib_file = None # argparse specified parameters can override pars if args.dm_parameters is not None: d = json.loads(args.dm_parameters.read()) pars = {**pars, **d} args.dm_parameters = args.dm_parameters.name # calibration from pars if 'calibration' in pars: calib_file = pars['calibration'] # calibration from argparse if args.dm_calibration is not None: calib_file = args.dm_calibration.name args.dm_calibration = calib_file # no calibration found, ask user for calibration if calib_file is None: fileName, _ = QFileDialog.getOpenFileName( None, 'Select a DM calibration', filter='H5 (*.h5);;All Files (*)') if not fileName: sys.exit() else: calib_file = path.abspath(fileName) pars['calibration'] = calib_file try: dminfo = RegLSCalib.query_calibration(calib_file) except Exception as e: quit(str(e)) calib_dm_name = dminfo[0] calib_dm_transform = dminfo[1] if args.dm_name is None: args.dm_name = calib_dm_name dm = open_dm(app, args, calib_dm_transform) try: with File(calib_file, 'r') as f: calib = RegLSCalib.load_h5py(f, lazy_cart_grid=True) except Exception as e: quit(f'Error loading calibration {pars["calibration"]}: {str(e)}') dmplot = get_suitable_dmplot(args, dm, calib) zwindow = DMWindow(None, dm, dmplot, calib, pars) zwindow.show() return zwindow
def load_parameters(app, args): def quit(str1): e = QErrorMessage() e.showMessage(str1) sys.exit(e.exec_()) if args.no_params: # blank parameters pars = {} elif args.params is not None: # command-line pars try: pars = json.load(args.params) except Exception: quit('cannot load ' + args.params.name) else: pars = {} if args.dm_calibration: args.dm_calibration.close() pars['calibration'] = path.abspath(args.dm_calibration.name) args.dm_calibration = pars['calibration'] def choose_calib_file(): fileName, _ = QFileDialog.getOpenFileName( None, 'Select a calibration', filter='H5 (*.h5);;All Files (*)') if not fileName: sys.exit() else: pars['calibration'] = path.abspath(fileName) if 'calibration' not in pars: choose_calib_file() try: dminfo = RegLSCalib.query_calibration(pars['calibration']) except Exception as e: quit(str(e)) return dminfo, pars