def _update_instrument_angles(self, workspace, q_values, wave): """ Updates the instrument angles in the specified workspace, using the specified wavelength and the specified Q-Values. This is required when calculating absorption corrections for indirect elastic. This is used only for ISIS instruments. :param workspace: The workspace whose instrument angles to update. :param q_values: The extracted Q-Values (MomentumTransfer) :param wave: The wavelength """ work_dir = config['defaultsave.directory'] k0 = 4.0 * math.pi / wave theta = 2.0 * np.degrees(np.arcsin(q_values / k0)) # convert to angle filename = 'Elastic_angles.txt' path = os.path.join(work_dir, filename) logger.information('Creating angles file : ' + path) handle = open(path, 'w') head = 'spectrum,theta' handle.write(head + " \n") for n in range(0, len(theta)): handle.write(str(n + 1) + ' ' + str(theta[n]) + "\n") handle.close() update_alg = self.createChildAlgorithm("UpdateInstrumentFromFile", enableLogging=False) update_alg.setProperty("Workspace", workspace) update_alg.setProperty("Filename", path) update_alg.setProperty("MoveMonitors", False) update_alg.setProperty("IgnorePhi", True) update_alg.setProperty("AsciiHeader", head) update_alg.setProperty("SkipFirstNLines", 1)
def _output_sample_logs(instrument, run_number, van_run_number, workspace, rb_num): def write_to_file(): with open(output_path, "w", newline="") as logfile: writer = csv.writer(logfile, ["Sample Log", "Avg Value"]) for log in output_dict: writer.writerow([log, output_dict[log]]) output_dict = {} sample_run = workspace.getRun() log_names = sample_run.keys() # Collect numerical sample logs. for name in log_names: try: output_dict[name] = sample_run.getPropertyAsSingleValue(name) except ValueError: logger.information( f"Could not convert {name} to a numerical value. It will not be included in the " f"sample logs output file.") focus_dir = path.join(output_settings.get_output_path(), "Focus") if not path.exists(focus_dir): makedirs(focus_dir) output_path = path.join(focus_dir, (instrument + "_" + run_number + "_" + van_run_number + "_sample_logs.csv")) write_to_file() if rb_num: focus_user_dir = path.join(output_settings.get_output_path(), "User", rb_num, "Focus") if not path.exists(focus_user_dir): makedirs(focus_user_dir) output_path = path.join(focus_user_dir, (instrument + "_" + run_number + "_" + van_run_number + "_sample_logs.csv")) write_to_file()
def set_current_calibration(self, success_info=None): if success_info: logger.information("Thread executed in " + str(success_info.elapsed_time) + " seconds.") self.current_calibration = deepcopy(self.pending_calibration) self.calibration_notifier.notify_subscribers(self.current_calibration) self.emit_update_fields_signal() self.pending_calibration.clear()
def _create_waves_indirect_elastic(self, workspace): """ Creates a wavelength workspace, from the workspace with the specified input workspace name, using an Elastic instrument definition file. E-Mode must be Indirect and the y-axis of the input workspace must be in units of Q. :param workspace: The input workspace. :return: The output wavelength workspace. """ self._indirect_elastic = True self._q_values = workspace.getAxis(1).extractValues() instrument_name = workspace.getInstrument().getName() self._isis_instrument = instrument_name == "IRIS" or instrument_name == "OSIRIS" # ---------- Load Elastic Instrument Definition File ---------- if self._isis_instrument: idf_name = instrument_name + '_elastic_Definition.xml' idf_path = os.path.join(config.getInstrumentDirectory(), idf_name) logger.information('IDF = %s' % idf_path) load_alg = self.createChildAlgorithm("LoadInstrument", enableLogging=True) load_alg.setProperty("Workspace", workspace) load_alg.setProperty("Filename", idf_path) load_alg.setProperty("RewriteSpectraMap", True) load_alg.execute() e_fixed = float(self._efixed) logger.information('Efixed = %f' % e_fixed) # ---------- Set Instrument Parameters ---------- sip_alg = self.createChildAlgorithm("SetInstrumentParameter", enableLogging=False) sip_alg.setProperty("Workspace", workspace) sip_alg.setProperty("ParameterName", 'EFixed') sip_alg.setProperty("ParameterType", 'Number') sip_alg.setProperty("Value", str(e_fixed)) sip_alg.execute() # ---------- Calculate Wavelength ---------- wave = math.sqrt(81.787 / e_fixed) logger.information('Wavelength = %f' % wave) workspace.getAxis(0).setUnit('Wavelength') # ---------- Format Input Workspace --------- convert_alg = self.createChildAlgorithm("ConvertToHistogram", enableLogging=False) convert_alg.setProperty("InputWorkspace", workspace) convert_alg.execute() workspace = self._crop_ws( convert_alg.getProperty("OutputWorkspace").value) # --------- Set wavelengths as X-values in Output Workspace ---------- waves = (0.01 * np.arange(-1, workspace.blocksize())) + wave logger.information('Waves for the dummy workspace: ' + str(waves)) nhist = workspace.getNumberHistograms() for idx in range(nhist): workspace.setX(idx, waves) if self._isis_instrument: workspace.replaceAxis(1, SpectraAxis.create(workspace)) self._update_instrument_angles(workspace, self._q_values, wave) return workspace