def save_parameters(self): if not self.is_calibrated: raise NeXusError('No refinement performed') elif 'calibration' in self.entry['instrument']: if confirm_action( "Do you want to overwrite existing calibration data?"): del self.entry['instrument/calibration'] else: return self.entry['instrument/calibration'] = self.data if 'refinement' in self.entry['instrument/calibration']: if confirm_action('Overwrite previous refinement?'): del self.entry['instrument/calibration/refinement'] else: return self.entry['instrument/calibration/calibrant'] = ( self.parameters['calibrant'].value) process = NXprocess() process.program = 'pyFAI' process.version = pyFAI.version process.parameters = NXcollection() process.parameters['Detector'] = ( self.entry['instrument/detector/description']) pyFAI_parameter = self.pattern_geometry.getPyFAI() process.parameters['PixelSize1'] = pyFAI_parameter['pixel1'] process.parameters['PixelSize2'] = pyFAI_parameter['pixel2'] process.parameters['Distance'] = pyFAI_parameter['dist'] process.parameters['Poni1'] = pyFAI_parameter['poni1'] process.parameters['Poni2'] = pyFAI_parameter['poni2'] process.parameters['Rot1'] = pyFAI_parameter['rot1'] process.parameters['Rot2'] = pyFAI_parameter['rot2'] process.parameters['Rot3'] = pyFAI_parameter['rot3'] process.parameters['Wavelength'] = pyFAI_parameter['wavelength'] self.entry['instrument/calibration/refinement'] = process self.entry['instrument/monochromator/wavelength'] = ( self.parameters['wavelength'].value) self.entry['instrument/monochromator/energy'] = ( 12.398419739640717 / self.parameters['wavelength'].value) detector = self.entry['instrument/detector'] detector['distance'] = self.parameters['distance'].value detector['yaw'] = self.parameters['yaw'].value detector['pitch'] = self.parameters['pitch'].value detector['roll'] = self.parameters['roll'].value detector['beam_center_x'] = self.parameters['xc'].value detector['beam_center_y'] = self.parameters['yc'].value try: detector['polarization'] = self.pattern_geometry.polarization( factor=0.99, shape=detector['mask'].shape) except Exception: pass
def sum_scans(self): server = NXServer(self.experiment_directory) if not server.is_running(): raise NeXusError('Server not running') scan_filter = ';;'.join(("NeXus Files (*.nxs)", "Any Files (*.* *)")) preferred_name = os.path.join(self.sample_directory, self.sample + '_' + 'sum.nxs') scan_file = getSaveFileName(self, 'Choose Summed File Name', preferred_name, scan_filter) if not scan_file: return prefix = self.sample + '_' if not os.path.basename(scan_file).startswith(prefix): raise NeXusError("Summed file name must start with '%s'" % prefix) self.scan_label = self.get_label(scan_file) scan_dir = os.path.join(self.sample_directory, self.scan_label) scan_file = os.path.join(self.sample_directory, self.sample + '_' + self.scan_label + '.nxs') copy_file = os.path.join(self.sample_directory, self.scan_files[0]) if os.path.exists(scan_dir): if not confirm_action( "New scan directory already exists. Overwrite?"): return else: os.mkdir(scan_dir) copyfile(copy_file, scan_file) self.clean_scan(scan_file) self.treeview.tree.load(scan_file, 'rw') reduce = NXReduce(directory=scan_dir) for entry in reduce.entries: server.add_task('nxsum -d %s -e %s -o -s %s' % (scan_dir, entry, self.scan_list))
def save_parameters(self): if not self.is_calibrated: raise NeXusError('No refinement performed') elif 'refinement' in self.entry['instrument/calibration']: if confirm_action('Overwrite previous refinement?'): del self.entry['instrument/calibration/refinement'] else: return self.entry['instrument/calibration/calibrant'] = self.parameters['calibrant'].value process = NXprocess() process.program = 'pyFAI' process.version = pyFAI.version process.parameters = NXcollection() process.parameters['Detector'] = self.entry['instrument/detector/description'] pyFAI_parameter = self.pattern_geometry.getPyFAI() process.parameters['PixelSize1'] = pyFAI_parameter['pixel1'] process.parameters['PixelSize2'] = pyFAI_parameter['pixel2'] process.parameters['Distance'] = pyFAI_parameter['dist'] process.parameters['Poni1'] = pyFAI_parameter['poni1'] process.parameters['Poni2'] = pyFAI_parameter['poni2'] process.parameters['Rot1'] = pyFAI_parameter['rot1'] process.parameters['Rot2'] = pyFAI_parameter['rot2'] process.parameters['Rot3'] = pyFAI_parameter['rot3'] process.parameters['Wavelength'] = pyFAI_parameter['wavelength'] self.entry['instrument/calibration/refinement'] = process self.entry['instrument/monochromator/wavelength'] = self.parameters['wavelength'].value self.entry['instrument/monochromator/energy'] = 12.398419739640717 / self.parameters['wavelength'].value detector = self.entry['instrument/detector'] detector['distance'] = self.parameters['distance'].value detector['yaw'] = self.parameters['yaw'].value detector['pitch'] = self.parameters['pitch'].value detector['roll'] = self.parameters['roll'].value detector['beam_center_x'] = self.parameters['xc'].value detector['beam_center_y'] = self.parameters['yc'].value
def sum_scans(self): server = NXServer(self.experiment_directory) if not server.is_running(): raise NeXusError('Server not running') scan_filter = ';;'.join(("NeXus Files (*.nxs)", "Any Files (*.* *)")) preferred_name = os.path.join(self.sample_directory, self.sample+'_'+'sum.nxs') scan_file = getSaveFileName(self, 'Choose Summed File Name', preferred_name, scan_filter) if not scan_file: return prefix = self.sample + '_' if not os.path.basename(scan_file).startswith(prefix): raise NeXusError("Summed file name must start with '%s'" % prefix) self.scan_label = self.get_label(scan_file) scan_dir = os.path.join(self.sample_directory, self.scan_label) scan_file = os.path.join(self.sample_directory, self.sample+'_'+self.scan_label+'.nxs') copy_file = os.path.join(self.sample_directory, self.scan_files[0]) if os.path.exists(scan_dir): if not confirm_action( "New scan directory already exists. Overwrite?"): return else: os.mkdir(scan_dir) copyfile(copy_file, scan_file) self.clean_scan(scan_file) self.treeview.tree.load(scan_file, 'rw') reduce = NXReduce(directory=scan_dir) for entry in reduce.entries: server.add_task('nxsum -d %s -e %s -o -s %s' % (scan_dir, entry, self.scan_list))
def toggle_server(self): if self.pushbutton['server'].text() == 'Start Server': subprocess.run('nxserver start', shell=True) else: if confirm_action('Stop server?'): subprocess.run('nxserver stop', shell=True) self.server_status.setText(self.server.status()) if self.server.is_running(): self.pushbutton['server'].setText('Stop Server') else: self.pushbutton['server'].setText('Start Server')
def accept(self): if self.data is None: self.reject() else: if 'calibration' in self.entry['instrument']: if confirm_action( "Do you want to overwrite existing calibration data?"): del self.entry['instrument/calibration'] else: self.reject() return self.entry['instrument/calibration'] = self.data super(LoadDialog, self).accept() if 'Powder Calibration' in plotviews and self.plotview == plotviews['Powder Calibration']: self.plotview.close_view()
def accept(self): if self.data is None: self.reject() else: if 'calibration' in self.entry['instrument']: if confirm_action( "Do you want to overwrite existing calibration data?"): del self.entry['instrument/calibration'] else: self.reject() return self.entry['instrument/calibration'] = self.data super(LoadDialog, self).accept() if 'Powder Calibration' in plotviews and self.plotview == plotviews[ 'Powder Calibration']: self.plotview.close_view()
def clear_queue(self): if confirm_action('Clear server queue?'): self.server.clear()