def set_ponifile(self, ponifile=None): if ponifile is None: ponifile = self.poni.text() print ponifile try: self.ai = pyFAI.load(ponifile) except Exception as error: logger.error("file %s does not look like a poni-file, error %s" % (ponifile, error)) return self.pixel1.setText(str_(self.ai.pixel1)) self.pixel2.setText(str_(self.ai.pixel2)) self.dist.setText(str_(self.ai.dist)) self.poni1.setText(str_(self.ai.poni1)) self.poni2.setText(str_(self.ai.poni2)) self.rot1.setText(str_(self.ai.rot1)) self.rot2.setText(str_(self.ai.rot2)) self.rot3.setText(str_(self.ai.rot3)) self.splineFile.setText(str_(self.ai.detector.splineFile)) self.wavelength.setText(str_(self.ai._wavelength)) name = self.ai.detector.name.lower() if name in self.all_detectors: self.detector.setCurrentIndex(self.all_detectors.index(name)) else: self.detector.setCurrentIndex(self.all_detectors.index("detector"))
def select_flatfield(self): logger.debug("select_flatfield") flatfield = str(QtGui.QFileDialog.getOpenFileName()) if flatfield: self.flat_field.setText(str_(flatfield)) self.do_flat.setChecked(True) if is_hdf5(flatfield): path = HDF5Dialog.getPath(flatfield) self.flat_field_hdf5.setText(path or "")
def select_darkcurrent(self): logger.debug("select_darkcurrent") darkcurrent = str(QtGui.QFileDialog.getOpenFileName()) if darkcurrent: self.dark_current.setText(str_(darkcurrent)) self.do_dark.setChecked(True) if is_hdf5(darkcurrent): path = HDF5Dialog.getPath(darkcurrent) self.dark_current_hdf5.setText(path or "")
def dump(self, filename=None): """ Reads all parameters and returns them as a python dictionary @param filename: dump the content to a file as a JSON string @return: dictionary """ logger.debug("InputWidget.dump") res = {} res["wavelength"] = float_(self.wavelength.text()) * 1e-10 calibrant = {"do_dspacing": bool(self.do_dspacing.isChecked())} calibrant["file"] = str_(self.dspacing.text()).strip() calibrant["calibrant"] = str_(self.detector.currentText()) res["calibrant"] = calibrant detector = {"name": str_(self.detector.currentText()), "file":str(self.detectorfile.text()).strip(), "pixel1": float_(self.pixel1.text()), "pixel2":float_(self.pixel2.text())} res[detector] = detector data = {"file": str_(self.data_file.text()).strip(), "hdf5": str_(self.data_file_hdf5.text()).strip() or None} res["data"] = data mask = {"file": str_(self.mask_file.text()).strip(), "hdf5": str_(self.mask_file_hdf5.text()).strip() or None, "apply": bool(self.do_mask.isChecked())} res["mask"] = mask dark = {"file": str_(self.dark_current.text()).strip(), "hdf5": str_(self.dark_file_hdf5.text()).strip() or None, "apply": bool(self.do_dark.isChecked())} res["dark"] = dark flat = {"file": str_(self.flat_field.text()).strip(), "hdf5": str_(self.flat_file_hdf5.text()).strip() or None, "apply": bool(self.do_flat.isChecked())} res["flat"] = flat try: with open(filename, "w") as myFile: json.dump(res, myFile, indent=4) except IOError as error: logger.error("Error while saving config: %s" % error) else: logger.debug("Saved") return res
def select_flatfield(self): logger.debug("select_flatfield") flatfield = str(QtGui.QFileDialog.getOpenFileName()) if flatfield: self.flat_field.setText(str_(flatfield)) self.do_flat.setChecked(True)
def select_darkcurrent(self): logger.debug("select_darkcurrent") darkcurrent = str(QtGui.QFileDialog.getOpenFileName()) if darkcurrent: self.dark_current.setText(str_(darkcurrent)) self.do_dark.setChecked(True)
def restore(self, filename=".azimint.json"): """ restore from JSON file the status of the current widget @param filename: path where the config was saved @type filename: str """ logger.debug("Restore") if not os.path.isfile(filename): logger.error("No such file: %s" % filename) return data = json.load(open(filename)) setup_data = { "poni": self.poni.setText, # "detector": self.all_detectors[self.detector.getCurrentIndex()], "wavelength":lambda a:self.wavelength.setText(str_(a)), "splineFile":lambda a:self.splineFile.setText(str_(a)), "pixel1":lambda a: self.pixel1.setText(str_(a)), "pixel2":lambda a:self.pixel2.setText(str_(a)), "dist":lambda a:self.dist.setText(str_(a)), "poni1":lambda a:self.poni1.setText(str_(a)), "poni2":lambda a:self.poni2.setText(str_(a)), "rot1":lambda a:self.rot1.setText(str_(a)), "rot2":lambda a:self.rot2.setText(str_(a)), "rot3":lambda a:self.rot3.setText(str_(a)), "do_dummy": self.do_dummy.setChecked, "do_dark": self.do_dark.setChecked, "do_flat": self.do_flat.setChecked, "do_polarization": self.do_polarization.setChecked, "val_dummy":lambda a: self.val_dummy.setText(str_(a)), "delta_dummy":lambda a: self.delta_dummy.setText(str_(a)), "do_mask": self.do_mask.setChecked, "mask_file":lambda a:self.mask_file.setText(str_(a)), "dark_current":lambda a:self.dark_current.setText(str_(a)), "flat_field":lambda a:self.flat_field.setText(str_(a)), "polarization_factor":self.polarization_factor.setValue, "rad_pt":lambda a:self.rad_pt.setText(str_(a)), "do_2D":self.do_2D.setChecked, "azim_pt":lambda a:self.azim_pt.setText(str_(a)), "chi_discontinuity_at_0": self.chi_discontinuity_at_0.setChecked, "do_radial_range": self.do_radial_range.setChecked, "do_azimuthal_range": self.do_azimuthal_range.setChecked, "do_poisson": self.do_poisson.setChecked, "radial_range_min":lambda a:self.radial_range_min.setText(str_(a)), "radial_range_max":lambda a:self.radial_range_max.setText(str_(a)), "azimuth_range_min":lambda a:self.azimuth_range_min.setText(str_(a)), "azimuth_range_max":lambda a:self.azimuth_range_max.setText(str_(a)), "do_solid_angle": self.do_solid_angle.setChecked, } for key, value in setup_data.items(): if key in data: value(data[key]) if "unit" in data: unit = data["unit"].lower() if unit == "q_nm^-1": self.q_nm.setChecked(1) elif unit == "q_A^-1": self.q_A.setChecked(1) elif unit == "2th_deg": self.tth_deg.setChecked(1) elif unit == "2th_rad": self.tth_rad.setChecked(1) elif unit == "r_mm": self.r_mm.setChecked(1) if "detector" in data: detector = data["detector"].lower() if detector in self.all_detectors: self.detector.setCurrentIndex(self.all_detectors.index(detector))
def dump(self, filename=None): """ Reads all parameters and returns them as a python dictionary @param filename: dump the content to a file as a JSON string @return: dictionary """ logger.debug("InputWidget.dump") res = {} res["wavelength"] = float_(self.wavelength.text()) * 1e-10 calibrant = {"do_dspacing": bool(self.do_dspacing.isChecked())} calibrant["file"] = str_(self.dspacing.text()).strip() calibrant["calibrant"] = str_(self.detector.currentText()) res["calibrant"] = calibrant detector = { "name": str_(self.detector.currentText()), "file": str(self.detectorfile.text()).strip(), "pixel1": float_(self.pixel1.text()), "pixel2": float_(self.pixel2.text()) } res[detector] = detector data = { "file": str_(self.data_file.text()).strip(), "hdf5": str_(self.data_file_hdf5.text()).strip() or None } res["data"] = data mask = { "file": str_(self.mask_file.text()).strip(), "hdf5": str_(self.mask_file_hdf5.text()).strip() or None, "apply": bool(self.do_mask.isChecked()) } res["mask"] = mask dark = { "file": str_(self.dark_current.text()).strip(), "hdf5": str_(self.dark_file_hdf5.text()).strip() or None, "apply": bool(self.do_dark.isChecked()) } res["dark"] = dark flat = { "file": str_(self.flat_field.text()).strip(), "hdf5": str_(self.flat_file_hdf5.text()).strip() or None, "apply": bool(self.do_flat.isChecked()) } res["flat"] = flat try: with open(filename, "w") as myFile: json.dump(res, myFile, indent=4) except IOError as error: logger.error("Error while saving config: %s" % error) else: logger.debug("Saved") return res
def qfile_path_handl(self): self.load_img(str_(self.qfile_path.text()))
def restore(self, filename=".azimint.json"): """ restore from JSON file the status of the current widget @param filename: path where the config was saved @type filename: str """ logger.debug("Restore") if not op.isfile(filename): logger.error("No such file: %s" % filename) return data = json.load(open(filename)) setup_data = { "poni": self.poni.setText, # "detector": self.all_detectors[self.detector.getCurrentIndex()], "wavelength": lambda a: self.wavelength.setText(str_(a)), "splineFile": lambda a: self.splineFile.setText(str_(a)), "pixel1": lambda a: self.pixel1.setText(str_(a)), "pixel2": lambda a: self.pixel2.setText(str_(a)), "dist": lambda a: self.dist.setText(str_(a)), "poni1": lambda a: self.poni1.setText(str_(a)), "poni2": lambda a: self.poni2.setText(str_(a)), "rot1": lambda a: self.rot1.setText(str_(a)), "rot2": lambda a: self.rot2.setText(str_(a)), "rot3": lambda a: self.rot3.setText(str_(a)), "do_dummy": self.do_dummy.setChecked, "do_dark": self.do_dark.setChecked, "do_flat": self.do_flat.setChecked, "do_polarization": self.do_polarization.setChecked, "val_dummy": lambda a: self.val_dummy.setText(str_(a)), "delta_dummy": lambda a: self.delta_dummy.setText(str_(a)), "do_mask": self.do_mask.setChecked, "mask_file": lambda a: self.mask_file.setText(str_(a)), "dark_current": lambda a: self.dark_current.setText(str_(a)), "flat_field": lambda a: self.flat_field.setText(str_(a)), "polarization_factor": self.polarization_factor.setValue, "rad_pt": lambda a: self.rad_pt.setText(str_(a)), "do_2D": self.do_2D.setChecked, "azim_pt": lambda a: self.azim_pt.setText(str_(a)), "chi_discontinuity_at_0": self.chi_discontinuity_at_0.setChecked, "do_radial_range": self.do_radial_range.setChecked, "do_azimuthal_range": self.do_azimuthal_range.setChecked, "do_poisson": self.do_poisson.setChecked, "radial_range_min": lambda a: self.radial_range_min.setText(str_(a)), "radial_range_max": lambda a: self.radial_range_max.setText(str_(a)), "azimuth_range_min": lambda a: self.azimuth_range_min.setText(str_(a)), "azimuth_range_max": lambda a: self.azimuth_range_max.setText(str_(a)), "do_solid_angle": self.do_solid_angle.setChecked, } for key, value in setup_data.items(): if key in data: value(data[key]) if "unit" in data: unit = data["unit"].lower() if unit == "q_nm^-1": self.q_nm.setChecked(1) elif unit == "q_A^-1": self.q_A.setChecked(1) elif unit == "2th_deg": self.tth_deg.setChecked(1) elif unit == "2th_rad": self.tth_rad.setChecked(1) elif unit == "r_mm": self.r_mm.setChecked(1) if "detector" in data: detector = data["detector"].lower() if detector in self.all_detectors: self.detector.setCurrentIndex( self.all_detectors.index(detector))