diff --git a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/Symmetrise.py b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/Symmetrise.py index 4f498695472c..1244da9203ad 100644 --- a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/Symmetrise.py +++ b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/Symmetrise.py @@ -1,7 +1,9 @@ from mantid import logger, mtd -from mantid.api import PythonAlgorithm, AlgorithmFactory, MatrixWorkspaceProperty, ITableWorkspaceProperty, PropertyMode +from mantid.api import PythonAlgorithm, AlgorithmFactory, MatrixWorkspaceProperty, \ + ITableWorkspaceProperty, PropertyMode from mantid.kernel import Direction, IntArrayProperty -from mantid.simpleapi import CreateWorkspace, CopyLogs, CopySample, CopyInstrumentParameters, SaveNexusProcessed, CreateEmptyTableWorkspace, RenameWorkspace +from mantid.simpleapi import CreateWorkspace, CopyLogs, CopyInstrumentParameters, \ + SaveNexusProcessed, CreateEmptyTableWorkspace, RenameWorkspace import math import os.path @@ -37,7 +39,8 @@ def PyInit(self): Direction.Output), doc='Name to call the output workspace.') self.declareProperty(ITableWorkspaceProperty('OutputPropertiesTable', '', - Direction.Output, PropertyMode.Optional), doc='Name to call the properties output table workspace.') + Direction.Output, PropertyMode.Optional), + doc='Name to call the properties output table workspace.') def PyExec(self): @@ -61,8 +64,8 @@ def PyExec(self): # Get slice bounds of array try: self._calculate_array_points(sample_x, sample_array_len) - except Exception as e: - raise RuntimeError('Failed to calculate array slice boundaries: %s' % e.message) + except Exception as exc: + raise RuntimeError('Failed to calculate array slice boundaries: %s' % exc.message) max_sample_index = sample_array_len - 1 centre_range_len = self._positive_min_index + self._negative_min_index @@ -89,8 +92,10 @@ def PyExec(self): v_axis_data = mtd[self._sample].getAxis(1).extractValues() # Take the values we need from the original vertical axis - min_spectrum_index = mtd[self._sample].getIndexFromSpectrumNumber(int(self._spectra_range[0])) - max_spectrum_index = mtd[self._sample].getIndexFromSpectrumNumber(int(self._spectra_range[1])) + min_spectrum_index = mtd[self._sample].getIndexFromSpectrumNumber( + int(self._spectra_range[0])) + max_spectrum_index = mtd[self._sample].getIndexFromSpectrumNumber( + int(self._spectra_range[1])) new_v_axis_data = v_axis_data[min_spectrum_index:max_spectrum_index + 1] # Create an empty workspace with enough storage for the new data @@ -178,7 +183,8 @@ def validateInputs(self): num_sample_spectra, _ = CheckHistZero(input_workspace_name) min_spectra_number = mtd[input_workspace_name].getSpectrum(0).getSpectrumNo() - max_spectra_number = mtd[input_workspace_name].getSpectrum(num_sample_spectra - 1).getSpectrumNo() + max_spectra_number = mtd[input_workspace_name].getSpectrum( + num_sample_spectra - 1).getSpectrumNo() if spec_min < min_spectra_number: issues['SpectraRange'] = 'Minimum spectra must be greater than or equal to %d' % min_spectra_number @@ -239,7 +245,8 @@ def _setup(self): if len(self._spectra_range) == 0: num_sample_spectra, _ = CheckHistZero(self._sample) min_spectra_number = mtd[self._sample].getSpectrum(0).getSpectrumNo() - max_spectra_number = mtd[self._sample].getSpectrum(num_sample_spectra - 1).getSpectrumNo() + max_spectra_number = mtd[self._sample].getSpectrum( + num_sample_spectra - 1).getSpectrumNo() self._spectra_range = [min_spectra_number, max_spectra_number] self._output_workspace = self.getPropertyValue('OutputWorkspace') @@ -298,7 +305,8 @@ def _generate_props_table(self): props_table.addColumn('int', 'PositiveXMinIndex') props_table.addColumn('int', 'PositiveXMaxIndex') - props_table.addRow([int(self._negative_min_index), int(self._positive_min_index), int(self._positive_max_index)]) + props_table.addRow([int(self._negative_min_index), int(self._positive_min_index), + int(self._positive_max_index)]) self.setProperty('OutputPropertiesTable', self._props_output_workspace) diff --git a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/DensityOfStates.py b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/DensityOfStates.py index ed313b04e543..291d9fd08749 100644 --- a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/DensityOfStates.py +++ b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/DensityOfStates.py @@ -124,7 +124,9 @@ def PyExec(self): if k in self._ions: partial_ions[k] = v - partial_workspaces, sum_workspace = self._compute_partial_ion_workflow(partial_ions, frequencies, eigenvectors, weights) + partial_workspaces, sum_workspace = self._compute_partial_ion_workflow( + partial_ions, frequencies, + eigenvectors, weights) if self._sum_contributions: # Discard the partial workspaces @@ -147,7 +149,9 @@ def PyExec(self): eigenvectors = file_data[4] - partial_workspaces, sum_workspace = self._compute_partial_ion_workflow(self._ion_dict, frequencies, eigenvectors, weights) + partial_workspaces, sum_workspace = self._compute_partial_ion_workflow( + self._ion_dict, frequencies, + eigenvectors, weights) # Discard the partial workspaces for partial_ws in partial_workspaces: @@ -288,7 +292,8 @@ def _compute_partial_ion_workflow(self, partial_ions, frequencies, eigenvectors, scattering_x_section = mtd[self._ws_name].mutableSample().getMaterial().totalScatterXSection() if self._scale_by_cross_section != 'None': - Scale(InputWorkspace=self._ws_name, OutputWorkspace=self._ws_name, Operation='Multiply', Factor=scattering_x_section) + Scale(InputWorkspace=self._ws_name, OutputWorkspace=self._ws_name, + Operation='Multiply', Factor=scattering_x_section) partial_workspaces.append(partial_ws_name) RenameWorkspace(self._ws_name, OutputWorkspace=partial_ws_name) @@ -300,9 +305,11 @@ def _compute_partial_ion_workflow(self, partial_ions, frequencies, eigenvectors, sum_workspace = '__dos_sum' # Collect spectra into a single workspace - AppendSpectra(OutputWorkspace=sum_workspace, InputWorkspace1=partial_workspaces[0], InputWorkspace2=partial_workspaces[1]) + AppendSpectra(OutputWorkspace=sum_workspace, InputWorkspace1=partial_workspaces[0], + InputWorkspace2=partial_workspaces[1]) for ws_idx in xrange(2, len(partial_workspaces)): - AppendSpectra(OutputWorkspace=sum_workspace, InputWorkspace1=sum_workspace, InputWorkspace2=partial_workspaces[ws_idx]) + AppendSpectra(OutputWorkspace=sum_workspace, InputWorkspace1=sum_workspace, + InputWorkspace2=partial_workspaces[ws_idx]) # Sum all spectra SumSpectra(InputWorkspace=sum_workspace, OutputWorkspace=total_workspace) diff --git a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/ElasticWindowMultiple.py b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/ElasticWindowMultiple.py index 9349f30d0d17..ae1dbd3b9bd7 100644 --- a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/ElasticWindowMultiple.py +++ b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/ElasticWindowMultiple.py @@ -40,7 +40,8 @@ def PyInit(self): self.declareProperty(name='Range2Start', defaultValue='', doc='Range 2 start') self.declareProperty(name='Range2End', defaultValue='', doc='Range 2 end') - self.declareProperty(name='SampleEnvironmentLogName', defaultValue='sample', doc='Name of the sample environment log entry') + self.declareProperty(name='SampleEnvironmentLogName', defaultValue='sample', + doc='Name of the sample environment log entry') self.declareProperty(WorkspaceProperty('OutputInQ', '', Direction.Output), doc='Output workspace in Q') @@ -48,10 +49,12 @@ def PyInit(self): self.declareProperty(WorkspaceProperty('OutputInQSquared', '', Direction.Output), doc='Output workspace in Q Squared') - self.declareProperty(WorkspaceProperty('OutputELF', '', Direction.Output, PropertyMode.Optional), + self.declareProperty(WorkspaceProperty('OutputELF', '', Direction.Output, + PropertyMode.Optional), doc='Output workspace ELF') - self.declareProperty(WorkspaceProperty('OutputELT', '', Direction.Output, PropertyMode.Optional), + self.declareProperty(WorkspaceProperty('OutputELT', '', Direction.Output, + PropertyMode.Optional), doc='Output workspace ELT') self.declareProperty(name='Plot', defaultValue=False, doc='Plot result spectra') @@ -71,13 +74,13 @@ def validateInputs(self): if range_2_start != '': try: - val = float(range_2_start) + _ = float(range_2_start) except ValueError: issues['Range2Start'] = 'Range 2 start is not a double number' if range_2_end != '': try: - val = float(range_2_end) + _ = float(range_2_end) except ValueError: issues['Range2End'] = 'Range 2 end is not a double number' @@ -110,9 +113,12 @@ def PyExec(self): q2_ws = '__' + input_ws + '_q2' if self._range_2_start != '' and self._range_2_end != '': - ElasticWindow(InputWorkspace=input_ws, OutputInQ=q_ws, OutputInQSquared=q2_ws, - Range1Start=self._range_1_start, Range1End=self._range_1_end, - Range2Start=float(self._range_2_start), Range2End=float(self._range_2_end)) + ElasticWindow(InputWorkspace=input_ws, + OutputInQ=q_ws, OutputInQSquared=q2_ws, + Range1Start=self._range_1_start, + Range1End=self._range_1_end, + Range2Start=float(self._range_2_start), + Range2End=float(self._range_2_end)) else: ElasticWindow(InputWorkspace=input_ws, OutputInQ=q_ws, OutputInQSquared=q2_ws, Range1Start=self._range_1_start, Range1End=self._range_1_end) @@ -139,13 +145,19 @@ def PyExec(self): RenameWorkspace(InputWorkspace=q2_workspaces[0], OutputWorkspace=self._q2_workspace) else: # Append the spectra of the first two workspaces - AppendSpectra(InputWorkspace1=q_workspaces[0], InputWorkspace2=q_workspaces[1], OutputWorkspace=self._q_workspace) - AppendSpectra(InputWorkspace1=q2_workspaces[0], InputWorkspace2=q2_workspaces[1], OutputWorkspace=self._q2_workspace) + AppendSpectra(InputWorkspace1=q_workspaces[0], InputWorkspace2=q_workspaces[1], + OutputWorkspace=self._q_workspace) + AppendSpectra(InputWorkspace1=q2_workspaces[0], InputWorkspace2=q2_workspaces[1], + OutputWorkspace=self._q2_workspace) # Append to the spectra of each remaining workspace for idx in range(2, len(input_workspace_names)): - AppendSpectra(InputWorkspace1=self._q_workspace, InputWorkspace2=q_workspaces[idx], OutputWorkspace=self._q_workspace) - AppendSpectra(InputWorkspace1=self._q2_workspace, InputWorkspace2=q2_workspaces[idx], OutputWorkspace=self._q2_workspace) + AppendSpectra(InputWorkspace1=self._q_workspace, + InputWorkspace2=q_workspaces[idx], + OutputWorkspace=self._q_workspace) + AppendSpectra(InputWorkspace1=self._q2_workspace, + InputWorkspace2=q2_workspaces[idx], + OutputWorkspace=self._q2_workspace) # Delete the output workspaces from the ElasticWindow algorithms for q_ws in q_workspaces: @@ -193,12 +205,14 @@ def PyExec(self): if self._elt_workspace != '': logger.information('Creating ELT workspace') - # If the ELT workspace was not already created then create it here, otherwise just clone it + # If the ELT workspace was not already created then create it here, + # otherwise just clone it if self._elf_workspace == '': Transpose(InputWorkspace=self._q_workspace, OutputWorkspace=self._elt_workspace) SortXAxis(InputWorkspace=self._elt_workspace, OutputWorkspace=self._elt_workspace) else: - CloneWorkspace(InputWorkspace=self._elf_workspace, OutputWorkspace=self._elt_workspace) + CloneWorkspace(InputWorkspace=self._elf_workspace, + OutputWorkspace=self._elt_workspace) _normalize_to_lowest_temp(self._elt_workspace) diff --git a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/Fury.py b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/Fury.py index e478aa2674b4..70e6e93fd478 100644 --- a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/Fury.py +++ b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/Fury.py @@ -1,6 +1,6 @@ from mantid.simpleapi import * from mantid.api import PythonAlgorithm, AlgorithmFactory, MatrixWorkspaceProperty, PropertyMode -from mantid.kernel import StringListValidator, StringMandatoryValidator, Direction, logger +from mantid.kernel import Direction, logger from mantid import config import math import os @@ -20,9 +20,12 @@ def PyInit(self): optional=PropertyMode.Mandatory, direction=Direction.Input), doc="Name for the Resolution workspace.") - self.declareProperty(name='EnergyMin', defaultValue=-0.5, doc='Minimum energy for fit. Default=-0.5') - self.declareProperty(name='EnergyMax', defaultValue=0.5, doc='Maximum energy for fit. Default=0.5') - self.declareProperty(name='NumBins', defaultValue=1, doc='Decrease total number of spectrum points by this ratio through merging of intensities from neighbouring bins. Default=1') + self.declareProperty(name='EnergyMin', defaultValue=-0.5, + doc='Minimum energy for fit. Default=-0.5') + self.declareProperty(name='EnergyMax', defaultValue=0.5, + doc='Maximum energy for fit. Default=0.5') + self.declareProperty(name='NumBins', defaultValue=1, + doc='Decrease total number of spectrum points by this ratio through merging of intensities from neighbouring bins. Default=1') self.declareProperty(MatrixWorkspaceProperty('ParameterWorkspace', '', direction=Direction.Output, optional=PropertyMode.Optional), @@ -32,9 +35,12 @@ def PyInit(self): direction=Direction.Output, optional=PropertyMode.Optional), doc='Output workspace') - self.declareProperty(name='Plot', defaultValue=False, doc='Switch Plot Off/On') - self.declareProperty(name='Save', defaultValue=False, doc='Switch Save result to nxs file Off/On') - self.declareProperty(name='DryRun', defaultValue=False, doc='Only calculate and output the parameters') + self.declareProperty(name='Plot', defaultValue=False, + doc='Switch Plot Off/On') + self.declareProperty(name='Save', defaultValue=False, + doc='Switch Save result to nxs file Off/On') + self.declareProperty(name='DryRun', defaultValue=False, + doc='Only calculate and output the parameters') def PyExec(self): @@ -110,7 +116,8 @@ def _calculate_parameters(self): """ Calculates the Fury parameters and saves in a table workspace. """ - CropWorkspace(InputWorkspace=self._sample, OutputWorkspace='__Fury_sample_cropped', Xmin=self._e_min, Xmax=self._e_max) + CropWorkspace(InputWorkspace=self._sample, OutputWorkspace='__Fury_sample_cropped', + Xmin=self._e_min, Xmax=self._e_max) x_data = mtd['__Fury_sample_cropped'].readX(0) number_input_points = len(x_data) - 1 num_bins = number_input_points / self._number_points_per_bin @@ -135,7 +142,8 @@ def _calculate_parameters(self): except (AttributeError, IndexError): resolution = 0.0175 - logger.warning('Could not get resolution from IPF, using default value: %f' % resolution) + logger.warning('Could not get resolution from IPF, using default value: %f' % ( + resolution)) resolution_bins = int(round((2 * resolution) / self._e_width)) @@ -178,10 +186,14 @@ def _plot_output(self): def _add_logs(self): - AddSampleLog(Workspace=self._output_workspace, LogName='fury_resolution_ws', LogType='String', LogText=self._resolution) - AddSampleLog(Workspace=self._output_workspace, LogName='fury_rebin_emin', LogType='Number', LogText=str(self._e_min)) - AddSampleLog(Workspace=self._output_workspace, LogName='fury_rebin_ewidth', LogType='Number', LogText=str(self._e_width)) - AddSampleLog(Workspace=self._output_workspace, LogName='fury_rebin_emax', LogType='Number', LogText=str(self._e_max)) + AddSampleLog(Workspace=self._output_workspace, LogName='fury_resolution_ws', + LogType='String', LogText=self._resolution) + AddSampleLog(Workspace=self._output_workspace, LogName='fury_rebin_emin', + LogType='Number', LogText=str(self._e_min)) + AddSampleLog(Workspace=self._output_workspace, LogName='fury_rebin_ewidth', + LogType='Number', LogText=str(self._e_width)) + AddSampleLog(Workspace=self._output_workspace, LogName='fury_rebin_emax', + LogType='Number', LogText=str(self._e_max)) def _fury(self): @@ -197,7 +209,8 @@ def _fury(self): CheckHistSame(self._sample, 'Sample', self._resolution, 'Resolution') rebin_param = str(self._e_min) + ',' + str(self._e_width) + ',' + str(self._e_max) - Rebin(InputWorkspace=self._sample, OutputWorkspace='__sam_rebin', Params=rebin_param, FullBinsOnly=True) + Rebin(InputWorkspace=self._sample, OutputWorkspace='__sam_rebin', Params=rebin_param, + FullBinsOnly=True) Rebin(InputWorkspace=self._resolution, OutputWorkspace='__res_data', Params=rebin_param) Integration(InputWorkspace='__res_data', OutputWorkspace='__res_int') @@ -223,7 +236,8 @@ def _fury(self): # Crop nonsense values off workspace binning = int(math.ceil(mtd[self._output_workspace].blocksize() / 2.0)) bin_v = mtd[self._output_workspace].dataX(0)[binning] - CropWorkspace(InputWorkspace=self._output_workspace, OutputWorkspace=self._output_workspace, XMax=bin_v) + CropWorkspace(InputWorkspace=self._output_workspace, OutputWorkspace=self._output_workspace, + XMax=bin_v) # Clean up resolution workspaces DeleteWorkspace('__res_data') diff --git a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/IndirectILLReduction.py b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/IndirectILLReduction.py index acc78baa98ce..08e6684d5409 100644 --- a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/IndirectILLReduction.py +++ b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/IndirectILLReduction.py @@ -1,6 +1,7 @@ from mantid.simpleapi import * from mantid.kernel import StringListValidator, Direction -from mantid.api import DataProcessorAlgorithm, PropertyMode, AlgorithmFactory, FileProperty, FileAction, MatrixWorkspaceProperty +from mantid.api import DataProcessorAlgorithm, PropertyMode, AlgorithmFactory, \ + FileProperty, FileAction, MatrixWorkspaceProperty from mantid import config, logger, mtd import numpy as np @@ -12,39 +13,51 @@ class IndirectILLReduction(DataProcessorAlgorithm): def category(self): return "Workflow\\MIDAS;Inelastic;PythonAlgorithms" + def PyInit(self): #input options self.declareProperty(FileProperty('Run', '', action=FileAction.Load, extensions=["nxs"]), doc='File path of run.') - self.declareProperty(name='Analyser', defaultValue='silicon', validator=StringListValidator(['silicon']), + self.declareProperty(name='Analyser', defaultValue='silicon', + validator=StringListValidator(['silicon']), doc='Analyser crystal') - self.declareProperty(name='Reflection', defaultValue='111', validator=StringListValidator(['111']), + self.declareProperty(name='Reflection', defaultValue='111', + validator=StringListValidator(['111']), doc='Analyser reflection') - self.declareProperty(FileProperty('MapFile', '', action=FileAction.OptionalLoad, extensions=["xml"]), + self.declareProperty(FileProperty('MapFile', '', + action=FileAction.OptionalLoad, extensions=["xml"]), doc='Filename of the map file to use. If left blank the default will be used.') - self.declareProperty(name='MirrorMode', defaultValue=False, doc='Whether to use mirror mode') + self.declareProperty(name='MirrorMode', defaultValue=False, + doc='Whether to use mirror mode') #Output workspace properties - self.declareProperty(MatrixWorkspaceProperty("RawWorkspace", "", direction=Direction.Output), + self.declareProperty(MatrixWorkspaceProperty("RawWorkspace", "", + direction=Direction.Output), doc="Name for the output raw workspace created.") - self.declareProperty(MatrixWorkspaceProperty("ReducedWorkspace", "", direction=Direction.Output), + self.declareProperty(MatrixWorkspaceProperty("ReducedWorkspace", "", + direction=Direction.Output), doc="Name for the output reduced workspace created. If mirror mode is used this will be the sum of both" "the left and right hand workspaces.") - self.declareProperty(MatrixWorkspaceProperty("LeftWorkspace", "", optional=PropertyMode.Optional, direction=Direction.Output), + self.declareProperty(MatrixWorkspaceProperty("LeftWorkspace", "", + optional=PropertyMode.Optional, direction=Direction.Output), doc="Name for the left workspace if mirror mode is used.") - self.declareProperty(MatrixWorkspaceProperty("RightWorkspace", "", optional=PropertyMode.Optional, direction=Direction.Output), + self.declareProperty(MatrixWorkspaceProperty("RightWorkspace", "", + optional=PropertyMode.Optional, direction=Direction.Output), doc="Name for the right workspace if mirror mode is used.") # output options - self.declareProperty(name='Save', defaultValue=False, doc='Switch Save result to nxs file Off/On') - self.declareProperty(name='Plot', defaultValue=False, doc='Whether to plot the output workspace.') + self.declareProperty(name='Save', defaultValue=False, + doc='Switch Save result to nxs file Off/On') + self.declareProperty(name='Plot', defaultValue=False, + doc='Whether to plot the output workspace.') + def PyExec(self): self.log().information('IndirectILLreduction') @@ -77,7 +90,8 @@ def PyExec(self): self._reflection = self.getPropertyValue('Reflection') self._run_name = self._instrument_name + '_' + str(self._run_number) - AddSampleLog(Workspace=self._raw_workspace, LogName="mirror_sense", LogType="String", LogText=str(self._use_mirror_mode)) + AddSampleLog(Workspace=self._raw_workspace, LogName="mirror_sense", + LogType="String", LogText=str(self._use_mirror_mode)) logger.information('Nxs file : %s' % run_path) @@ -92,15 +106,15 @@ def PyExec(self): if self._plot: from IndirectImport import import_mantidplot - mp = import_mantidplot() - graph = mp.newGraph() + mtd_plot = import_mantidplot() + graph = mtd_plot.newGraph() for ws in output_workspaces: - mp.plotSpectrum(ws, 0, window=graph) + mtd_plot.plotSpectrum(ws, 0, window=graph) layer = graph.activeLayer() - layer.setAxisTitle(mp.Layer.Bottom, 'Energy Transfer (meV)') - layer.setAxisTitle(mp.Layer.Left, '') + layer.setAxisTitle(mtd_plot.Layer.Bottom, 'Energy Transfer (meV)') + layer.setAxisTitle(mtd_plot.Layer.Left, '') layer.setTitle('') self.setPropertyValue('RawWorkspace', self._raw_workspace) @@ -110,14 +124,11 @@ def PyExec(self): self.setPropertyValue('LeftWorkspace', self._red_left_workspace) self.setPropertyValue('RightWorkspace', self._red_right_workspace) + def _reduction(self): """ Run energy conversion for IN16B """ - from IndirectCommon import StartTime, EndTime - - StartTime('ILLindirect') - logger.information('Input workspace : %s' % self._raw_workspace) idf_directory = config['instrumentDefinition.directory'] @@ -125,7 +136,8 @@ def _reduction(self): ipf_path = os.path.join(idf_directory, ipf_name) LoadParameterFile(Workspace=self._raw_workspace, Filename=ipf_path) - AddSampleLog(Workspace=self._raw_workspace, LogName="facility", LogType="String", LogText="ILL") + AddSampleLog(Workspace=self._raw_workspace, LogName="facility", + LogType="String", LogText="ILL") if self._map_file == '': # path name for default map file @@ -139,11 +151,12 @@ def _reduction(self): logger.information('Map file : %s' % self._map_file) grouped_ws = self._run_name + '_group' - GroupDetectors(InputWorkspace=self._raw_workspace, OutputWorkspace=grouped_ws, MapFile=self._map_file, - Behaviour='Average') + GroupDetectors(InputWorkspace=self._raw_workspace, OutputWorkspace=grouped_ws, + MapFile=self._map_file, Behaviour='Average') monitor_ws = self._run_name + '_mon' - ExtractSingleSpectrum(InputWorkspace=self._raw_workspace, OutputWorkspace=monitor_ws, WorkspaceIndex=0) + ExtractSingleSpectrum(InputWorkspace=self._raw_workspace, + OutputWorkspace=monitor_ws, WorkspaceIndex=0) if self._use_mirror_mode: output_workspaces = self._run_mirror_mode(monitor_ws, grouped_ws) @@ -153,9 +166,9 @@ def _reduction(self): self._calculate_energy(monitor_ws, grouped_ws, self._red_workspace) output_workspaces = [self._red_workspace] - EndTime('ILLindirect') return output_workspaces + def _run_mirror_mode(self, monitor_ws, grouped_ws): """ Runs energy reduction with mirror mode. @@ -199,18 +212,24 @@ def _run_mirror_mode(self, monitor_ws, grouped_ws): nrmax = np.argmax(np.array(yr)) xrmax = xr[nrmax] xshift = xlmax - xrmax - ScaleX(InputWorkspace=self._red_right_workspace, OutputWorkspace=self._red_right_workspace, Factor=xshift, Operation='Add') - RebinToWorkspace(WorkspaceToRebin=self._red_right_workspace, WorkspaceToMatch=self._red_left_workspace, OutputWorkspace=self._red_right_workspace) + ScaleX(InputWorkspace=self._red_right_workspace, OutputWorkspace=self._red_right_workspace, + Factor=xshift, Operation='Add') + RebinToWorkspace(WorkspaceToRebin=self._red_right_workspace, + WorkspaceToMatch=self._red_left_workspace, + OutputWorkspace=self._red_right_workspace) #sum both workspaces together - Plus(LHSWorkspace=self._red_left_workspace, RHSWorkspace=self._red_right_workspace, OutputWorkspace=self._red_workspace) - Scale(InputWorkspace=self._red_workspace, OutputWorkspace=self._red_workspace, Factor=0.5, Operation='Multiply') + Plus(LHSWorkspace=self._red_left_workspace, RHSWorkspace=self._red_right_workspace, + OutputWorkspace=self._red_workspace) + Scale(InputWorkspace=self._red_workspace, OutputWorkspace=self._red_workspace, + Factor=0.5, Operation='Multiply') DeleteWorkspace(monitor_ws) DeleteWorkspace(grouped_ws) return [self._red_left_workspace, self._red_right_workspace, self._red_workspace] + def _calculate_energy(self, monitor_ws, grouped_ws, red_ws): """ Convert the input run to energy transfer @@ -220,18 +239,23 @@ def _calculate_energy(self, monitor_ws, grouped_ws, red_ws): @param red_ws :: name to call the reduced workspace """ x_range = self._monitor_range(monitor_ws) - Scale(InputWorkspace=monitor_ws, OutputWorkspace=monitor_ws, Factor=0.001, Operation='Multiply') + Scale(InputWorkspace=monitor_ws, OutputWorkspace=monitor_ws, Factor=0.001, + Operation='Multiply') - CropWorkspace(InputWorkspace=monitor_ws, OutputWorkspace=monitor_ws, Xmin=x_range[0], XMax=x_range[1]) - ScaleX(InputWorkspace=monitor_ws, OutputWorkspace=monitor_ws, Factor=-x_range[0], Operation='Add') + CropWorkspace(InputWorkspace=monitor_ws, OutputWorkspace=monitor_ws, + Xmin=x_range[0], XMax=x_range[1]) + ScaleX(InputWorkspace=monitor_ws, OutputWorkspace=monitor_ws, Factor=-x_range[0], + Operation='Add') - CropWorkspace(InputWorkspace=grouped_ws, OutputWorkspace=grouped_ws, Xmin=x_range[0], XMax=x_range[1]) - ScaleX(InputWorkspace=grouped_ws, OutputWorkspace=grouped_ws, Factor=-x_range[0], Operation='Add') + CropWorkspace(InputWorkspace=grouped_ws, OutputWorkspace=grouped_ws, Xmin=x_range[0], + XMax=x_range[1]) + ScaleX(InputWorkspace=grouped_ws, OutputWorkspace=grouped_ws, Factor=-x_range[0], + Operation='Add') Divide(LHSWorkspace=grouped_ws, RHSWorkspace=monitor_ws, OutputWorkspace=grouped_ws) formula = self._energy_range(grouped_ws) - ConvertAxisByFormula(InputWorkspace=grouped_ws, OutputWorkspace=red_ws, Axis='X', Formula=formula, - AxisTitle='Energy transfer', AxisUnits='meV') + ConvertAxisByFormula(InputWorkspace=grouped_ws, OutputWorkspace=red_ws, Axis='X', + Formula=formula, AxisTitle='Energy transfer', AxisUnits='meV') xnew = mtd[red_ws].readX(0) # energy array logger.information('Energy range : %f to %f' % (xnew[0], xnew[-1])) @@ -239,6 +263,7 @@ def _calculate_energy(self, monitor_ws, grouped_ws, red_ws): DeleteWorkspace(grouped_ws) DeleteWorkspace(monitor_ws) + def _monitor_range(self, monitor_ws): """ Get sensible values for the min and max cropping range @@ -257,6 +282,7 @@ def _monitor_range(self, monitor_ws): return x[imin], x[imax] + def _energy_range(self, ws): """ Calculate the energy range for the workspace @@ -282,4 +308,6 @@ def _energy_range(self, ws): return formula -AlgorithmFactory.subscribe(IndirectILLReduction) # Register algorithm with Mantid + +# Register algorithm with Mantid +AlgorithmFactory.subscribe(IndirectILLReduction) diff --git a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/JumpFit.py b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/JumpFit.py index 0d5e64bbfc4e..4b1ccd2e651a 100644 --- a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/JumpFit.py +++ b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/JumpFit.py @@ -37,7 +37,8 @@ def PyInit(self): def PyExec(self): - from mantid.simpleapi import ExtractSingleSpectrum, Scale, Fit, CopyLogs, AddSampleLog, DeleteWorkspace + from mantid.simpleapi import ExtractSingleSpectrum, Fit, CopyLogs, AddSampleLog, \ + DeleteWorkspace from mantid import logger, mtd from IndirectCommon import StartTime, EndTime @@ -47,7 +48,8 @@ def PyExec(self): # Select the width we wish to fit spectrum_ws = "__" + self._in_ws - ExtractSingleSpectrum(InputWorkspace=self._in_ws, OutputWorkspace=spectrum_ws, WorkspaceIndex=self._width) + ExtractSingleSpectrum(InputWorkspace=self._in_ws, OutputWorkspace=spectrum_ws, + WorkspaceIndex=self._width) logger.information('Cropping from Q= ' + str(self._q_min) + ' to ' + str(self._q_max)) in_run = mtd[self._in_ws].getRun() diff --git a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/ResNorm.py b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/ResNorm.py index c7dd0825540e..cd390e450878 100644 --- a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/ResNorm.py +++ b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/ResNorm.py @@ -1,73 +1,94 @@ from mantid.api import PythonAlgorithm, AlgorithmFactory from mantid.kernel import StringListValidator, StringMandatoryValidator from mantid.simpleapi import * -from mantid import config, logger, mtd +from mantid import config, logger import os + class ResNorm(PythonAlgorithm): - def category(self): - return "Workflow\\MIDAS;PythonAlgorithms" - - def summary(self): - return "This algorithm creates a group 'normalisation' file by taking a resolution file and fitting it to all the groups in the resolution (vanadium) data file which has the same grouping as the sample data of interest." - - def PyInit(self): - self.declareProperty(name='InputType',defaultValue='File',validator=StringListValidator(['File','Workspace']), doc='Origin of data input - File (.nxs) or Workspace') - self.declareProperty(name='Instrument',defaultValue='iris',validator=StringListValidator(['irs','iris','osi','osiris']), doc='Instrument') - self.declareProperty(name='Analyser',defaultValue='graphite002',validator=StringListValidator(['graphite002','graphite004']), doc='Analyser & reflection') - self.declareProperty(name='VanNumber',defaultValue='',validator=StringMandatoryValidator(), doc='Sample run number') - self.declareProperty(name='ResInputType',defaultValue='File',validator=StringListValidator(['File','Workspace']), doc='Origin of res input - File (_res.nxs) or Workspace') - self.declareProperty(name='ResNumber',defaultValue='',validator=StringMandatoryValidator(), doc='Resolution run number') - self.declareProperty(name='EnergyMin', defaultValue=-0.2, doc='Minimum energy for fit. Default=-0.2') - self.declareProperty(name='EnergyMax', defaultValue=0.2, doc='Maximum energy for fit. Default=0.2') - self.declareProperty(name='VanBinning', defaultValue=1, doc='Binning value (integer) for sample. Default=1') - self.declareProperty(name='Plot',defaultValue='None',validator=StringListValidator(['None','Intensity','Stretch','Fit','All']), doc='Plot options') - self.declareProperty(name='Verbose',defaultValue=True, doc='Switch Verbose Off/On') - self.declareProperty(name='Save',defaultValue=False, doc='Switch Save result to nxs file Off/On') - - def PyExec(self): - from IndirectImport import run_f2py_compatibility_test, is_supported_f2py_platform - - if is_supported_f2py_platform(): + def category(self): + return "Workflow\\MIDAS;PythonAlgorithms" + + + def summary(self): + return "This algorithm creates a group 'normalisation' file by taking a resolution file and fitting it to all the groups in the resolution (vanadium) data file which has the same grouping as the sample data of interest." + + + def PyInit(self): + self.declareProperty(name='InputType', defaultValue='File', + validator=StringListValidator(['File','Workspace']), + doc='Origin of data input - File (.nxs) or Workspace') + self.declareProperty(name='Instrument', defaultValue='iris', + validator=StringListValidator(['irs','iris','osi','osiris']), + doc='Instrument') + self.declareProperty(name='Analyser', defaultValue='graphite002', + validator=StringListValidator(['graphite002','graphite004']), + doc='Analyser & reflection') + self.declareProperty(name='VanNumber', defaultValue='', + validator=StringMandatoryValidator(), + doc='Sample run number') + self.declareProperty(name='ResInputType',defaultValue='File', + validator=StringListValidator(['File','Workspace']), + doc='Origin of res input - File (_res.nxs) or Workspace') + self.declareProperty(name='ResNumber', defaultValue='', + validator=StringMandatoryValidator(), + doc='Resolution run number') + self.declareProperty(name='EnergyMin', defaultValue=-0.2, + doc='Minimum energy for fit. Default=-0.2') + self.declareProperty(name='EnergyMax', defaultValue=0.2, + doc='Maximum energy for fit. Default=0.2') + self.declareProperty(name='VanBinning', defaultValue=1, + doc='Binning value (integer) for sample. Default=1') + self.declareProperty(name='Plot', defaultValue='None', + validator=StringListValidator(['None','Intensity','Stretch','Fit','All']), + doc='Plot options') + self.declareProperty(name='Save', defaultValue=False, + doc='Switch Save result to nxs file Off/On') + + + def PyExec(self): + from IndirectImport import run_f2py_compatibility_test, is_supported_f2py_platform + + if is_supported_f2py_platform(): import IndirectBayes as Main - run_f2py_compatibility_test() - - self.log().information('ResNorm input') - inType = self.getPropertyValue('InputType') - prefix = self.getPropertyValue('Instrument') - ana = self.getPropertyValue('Analyser') - van = self.getPropertyValue('VanNumber') - rinType = self.getPropertyValue('ResInputType') - res = self.getPropertyValue('ResNumber') - emin = self.getPropertyValue('EnergyMin') - emax = self.getPropertyValue('EnergyMax') - nbin = self.getPropertyValue('VanBinning') - - vname = prefix+van+'_'+ana+ '_red' - rname = prefix+res+'_'+ana+ '_res' - erange = [float(emin), float(emax)] - verbOp = self.getProperty('Verbose').value - plotOp = self.getPropertyValue('Plot') - saveOp = self.getProperty('Save').value - - workdir = config['defaultsave.directory'] - if inType == 'File': - vpath = os.path.join(workdir, vname+'.nxs') # path name for van nxs file - LoadNexusProcessed(Filename=vpath, OutputWorkspace=vname) - Vmessage = 'Vanadium from File : '+vpath - else: - Vmessage = 'Vanadium from Workspace : '+vname - if rinType == 'File': - rpath = os.path.join(workdir, rname+'.nxs') # path name for res nxs file - LoadNexusProcessed(Filename=rpath, OutputWorkspace=rname) - Rmessage = 'Resolution from File : '+rpath - else: - Rmessage = 'Resolution from Workspace : '+rname - if verbOp: - logger.notice(Vmessage) - logger.notice(Rmessage) - Main.ResNormRun(vname,rname,erange,nbin,verbOp,plotOp,saveOp) - -AlgorithmFactory.subscribe(ResNorm) # Register algorithm with Mantid + run_f2py_compatibility_test() + + self.log().information('ResNorm input') + inType = self.getPropertyValue('InputType') + prefix = self.getPropertyValue('Instrument') + ana = self.getPropertyValue('Analyser') + van = self.getPropertyValue('VanNumber') + rinType = self.getPropertyValue('ResInputType') + res = self.getPropertyValue('ResNumber') + emin = self.getPropertyValue('EnergyMin') + emax = self.getPropertyValue('EnergyMax') + nbin = self.getPropertyValue('VanBinning') + + vname = prefix+van+'_'+ana+ '_red' + rname = prefix+res+'_'+ana+ '_res' + erange = [float(emin), float(emax)] + plotOp = self.getPropertyValue('Plot') + saveOp = self.getProperty('Save').value + + workdir = config['defaultsave.directory'] + if inType == 'File': + vpath = os.path.join(workdir, vname+'.nxs') # path name for van nxs file + LoadNexusProcessed(Filename=vpath, OutputWorkspace=vname) + Vmessage = 'Vanadium from File : '+vpath + else: + Vmessage = 'Vanadium from Workspace : '+vname + if rinType == 'File': + rpath = os.path.join(workdir, rname+'.nxs') # path name for res nxs file + LoadNexusProcessed(Filename=rpath, OutputWorkspace=rname) + Rmessage = 'Resolution from File : '+rpath + else: + Rmessage = 'Resolution from Workspace : '+rname + logger.information(Vmessage) + logger.information(Rmessage) + Main.ResNormRun(vname,rname,erange,nbin,True,plotOp,saveOp) + + +# Register algorithm with Mantid +AlgorithmFactory.subscribe(ResNorm) diff --git a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/SofQWMoments.py b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/SofQWMoments.py index b7063f1e99da..18328047655e 100644 --- a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/SofQWMoments.py +++ b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/SofQWMoments.py @@ -1,6 +1,7 @@ # Algorithm to start Bayes programs from mantid.simpleapi import * -from mantid.api import DataProcessorAlgorithm, AlgorithmFactory, MatrixWorkspaceProperty, WorkspaceGroupProperty +from mantid.api import DataProcessorAlgorithm, AlgorithmFactory, MatrixWorkspaceProperty, \ + WorkspaceGroupProperty from mantid.kernel import Direction from mantid import logger