Skip to content

Commit

Permalink
Remove Verbose options from algorithms
Browse files Browse the repository at this point in the history
Replace with appropriate logging levels

Refs #10850
  • Loading branch information
DanNixon committed Jan 20, 2015
1 parent 238b183 commit 6c02875
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 155 deletions.
Expand Up @@ -28,8 +28,6 @@ def PyInit(self):
self.declareProperty('XMin', 0.0, doc='X value marking lower limit of curve to copy')
self.declareProperty('XMax', 0.0, doc='X value marking upper limit of curve to copy')

self.declareProperty('Verbose', defaultValue=False,
doc='Switch verbose output Off/On')
self.declareProperty('Plot', defaultValue=False,
doc='Switch plotting Off/On')
self.declareProperty('Save', defaultValue=False,
Expand Down Expand Up @@ -73,19 +71,18 @@ def PyExec(self):
output_cut_index = max_sample_index - self._positive_min_index - positive_diff_range_len - 1
new_array_len = 2 * max_sample_index - centre_range_len - 2 * positive_diff_range_len - 1

if self._verbose:
logger.notice('Sample array length = %d' % sample_array_len)
logger.information('Sample array length = %d' % sample_array_len)

logger.notice('Positive X min at i=%d, x=%f'
% (self._positive_min_index, sample_x[self._positive_min_index]))
logger.notice('Negative X min at i=%d, x=%f'
% (self._negative_min_index, sample_x[self._negative_min_index]))
logger.information('Positive X min at i=%d, x=%f'
% (self._positive_min_index, sample_x[self._positive_min_index]))
logger.information('Negative X min at i=%d, x=%f'
% (self._negative_min_index, sample_x[self._negative_min_index]))

logger.notice('Positive X max at i=%d, x=%f'
% (self._positive_max_index, sample_x[self._positive_max_index]))
logger.information('Positive X max at i=%d, x=%f'
% (self._positive_max_index, sample_x[self._positive_max_index]))

logger.notice('New array length = %d' % new_array_len)
logger.notice('Output array LR split index = %d' % output_cut_index)
logger.information('New array length = %d' % new_array_len)
logger.information('Output array LR split index = %d' % output_cut_index)

x_unit = mtd[self._sample].getAxis(0).getUnit().unitID()
v_unit = mtd[self._sample].getAxis(1).getUnit().unitID()
Expand Down Expand Up @@ -234,7 +231,6 @@ def _setup(self):
self._x_min = math.fabs(self.getProperty('XMin').value)
self._x_max = math.fabs(self.getProperty('XMax').value)

self._verbose = self.getProperty('Verbose').value
self._plot = self.getProperty('Plot').value
self._save = self.getProperty('Save').value

Expand Down Expand Up @@ -317,8 +313,7 @@ def _save_output(self):
SaveNexusProcessed(InputWorkspace=self._output_workspace,
Filename=file_path)

if self._verbose:
logger.notice('Output file : ' + file_path)
logger.information('Output file : ' + file_path)


def _plot_output(self):
Expand Down
Expand Up @@ -33,7 +33,6 @@ def PyInit(self):
doc='Output workspace')

self.declareProperty(name='Plot', defaultValue=False, doc='Switch Plot Off/On')
self.declareProperty(name='Verbose', defaultValue=False, doc='Switch Verbose 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')

Expand All @@ -52,14 +51,12 @@ def PyExec(self):
workdir = config['defaultsave.directory']
opath = os.path.join(workdir, self._output_workspace + '.nxs')
SaveNexusProcessed(InputWorkspace=self._output_workspace, Filename=opath)
if self._verbose:
logger.notice('Output file : ' + opath)
logger.information('Output file : ' + opath)

if self._plot:
self._plot_output()
else:
if self._verbose:
logger.notice('Dry run, will not run Fury')
logger.information('Dry run, will not run Fury')

self.setProperty('ParameterWorkspace', self._parameter_table)
self.setProperty('OutputWorkspace', self._output_workspace)
Expand All @@ -86,7 +83,6 @@ def _setup(self):
if self._output_workspace == '':
self._output_workspace = getWSprefix(self._sample) + 'iqt'

self._verbose = self.getProperty('Verbose').value
self._plot = self.getProperty('Plot').value
self._save = self.getProperty('Save').value
self._dry_run = self.getProperty('DryRun').value
Expand Down
Expand Up @@ -43,7 +43,6 @@ def PyInit(self):
doc="Name for the right workspace if mirror mode is used.")

# output options
self.declareProperty(name='Verbose', defaultValue=False, doc='Switch Verbose Off/On')
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.')

Expand All @@ -58,7 +57,6 @@ def PyExec(self):
self._map_file = self.getProperty('MapFile').value

self._use_mirror_mode = self.getProperty('MirrorMode').value
self._verbose = self.getProperty('Verbose').value
self._save = self.getProperty('Save').value
self._plot = self.getProperty('Plot').value

Expand All @@ -81,8 +79,7 @@ def PyExec(self):

AddSampleLog(Workspace=self._raw_workspace, LogName="mirror_sense", LogType="String", LogText=str(self._use_mirror_mode))

if self._verbose:
logger.notice('Nxs file : %s' % run_path)
logger.information('Nxs file : %s' % run_path)

output_workspaces = self._reduction()

Expand All @@ -91,8 +88,7 @@ def PyExec(self):
for ws in output_workspaces:
file_path = os.path.join(workdir, ws + '.nxs')
SaveNexusProcessed(InputWorkspace=ws, Filename=file_path)
if self._verbose:
logger.notice('Output file : ' + file_path)
logger.information('Output file : ' + file_path)

if self._plot:
from IndirectImport import import_mantidplot
Expand Down Expand Up @@ -122,8 +118,7 @@ def _reduction(self):

StartTime('ILLindirect')

if self._verbose:
logger.notice('Input workspace : %s' % self._raw_workspace)
logger.information('Input workspace : %s' % self._raw_workspace)

idf_directory = config['instrumentDefinition.directory']
ipf_name = self._instrument_name + '_' + self._analyser + '_' + self._reflection + '_Parameters.xml'
Expand All @@ -141,8 +136,7 @@ def _reduction(self):
else:
raise ValueError("Failed to find default map file. Contact development team.")

if self._verbose:
logger.notice('Map file : %s' % self._map_file)
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,
Expand All @@ -154,8 +148,7 @@ def _reduction(self):
if self._use_mirror_mode:
output_workspaces = self._run_mirror_mode(monitor_ws, grouped_ws)
else:
if self._verbose:
logger.notice('Mirror sense is OFF')
logger.information('Mirror sense is OFF')

self._calculate_energy(monitor_ws, grouped_ws, self._red_workspace)
output_workspaces = [self._red_workspace]
Expand All @@ -170,8 +163,7 @@ def _run_mirror_mode(self, monitor_ws, grouped_ws):
@param monitor_ws :: name of the monitor workspace
@param grouped_ws :: name of workspace with the detectors grouped
"""
if self._verbose:
logger.notice('Mirror sense is ON')
logger.information('Mirror sense is ON')

x = mtd[grouped_ws].readX(0) # energy array
mid_point = int((len(x) - 1) / 2)
Expand All @@ -185,8 +177,7 @@ def _run_mirror_mode(self, monitor_ws, grouped_ws):
self._calculate_energy(left_mon_ws, left_ws, self._red_left_workspace)
xl = mtd[self._red_left_workspace].readX(0)

if self._verbose:
logger.notice('Energy range, left : %f to %f' % (xl[0], xl[-1]))
logger.information('Energy range, left : %f to %f' % (xl[0], xl[-1]))

#right half
right_ws = self._run_name + '_right'
Expand All @@ -197,8 +188,7 @@ def _run_mirror_mode(self, monitor_ws, grouped_ws):
self._calculate_energy(right_mon_ws, right_ws, self._red_right_workspace)
xr = mtd[self._red_right_workspace].readX(0)

if self._verbose:
logger.notice('Energy range, right : %f to %f' % (xr[0], xr[-1]))
logger.information('Energy range, right : %f to %f' % (xr[0], xr[-1]))

xl = mtd[self._red_left_workspace].readX(0)
yl = mtd[self._red_left_workspace].readY(0)
Expand Down Expand Up @@ -243,9 +233,8 @@ def _calculate_energy(self, monitor_ws, grouped_ws, red_ws):
ConvertAxisByFormula(InputWorkspace=grouped_ws, OutputWorkspace=red_ws, Axis='X', Formula=formula,
AxisTitle='Energy transfer', AxisUnits='meV')

if self._verbose:
xnew = mtd[red_ws].readX(0) # energy array
logger.notice('Energy range : %f to %f' % (xnew[0], xnew[-1]))
xnew = mtd[red_ws].readX(0) # energy array
logger.information('Energy range : %f to %f' % (xnew[0], xnew[-1]))

DeleteWorkspace(grouped_ws)
DeleteWorkspace(monitor_ws)
Expand All @@ -264,8 +253,7 @@ def _monitor_range(self, monitor_ws):
im = np.argmax(np.array(y[nch - 21:nch - 1]))
imax = nch - 21 + im

if self._verbose:
logger.notice('Cropping range %f to %f' % (x[imin], x[imax]))
logger.information('Cropping range %f to %f' % (x[imin], x[imax]))

return x[imin], x[imax]

Expand All @@ -284,10 +272,9 @@ def _energy_range(self, ws):
freq = gRun.getLogData('Doppler.doppler_frequency').value
amp = gRun.getLogData('Doppler.doppler_amplitude').value

if self._verbose:
logger.notice('Wavelength : ' + str(wave))
logger.notice('Doppler frequency : ' + str(freq))
logger.notice('Doppler amplitude : ' + str(amp))
logger.information('Wavelength : ' + str(wave))
logger.information('Doppler frequency : ' + str(freq))
logger.information('Doppler amplitude : ' + str(amp))

vmax = 1.2992581918414711e-4 * freq * amp * 2.0 / wave # max energy
dele = 2.0 * vmax / npt
Expand Down
Expand Up @@ -40,7 +40,6 @@ def PyInit(self):
self.declareProperty(name='ScaleFactor', defaultValue=1.0, doc='Factor to scale resolution curve by')
self.declareProperty(name='Smooth', defaultValue=False, doc='Apply WienerSmooth to resolution')

self.declareProperty(name='Verbose', defaultValue=False, doc='Print more information to results log')
self.declareProperty(name='Plot', defaultValue=False, doc='Plot resolution curve')
self.declareProperty(name='Save', defaultValue=False, doc='Save resolution workspace as a Nexus file')

Expand Down Expand Up @@ -104,7 +103,6 @@ def _setup(self):
self._scale_factor = self.getProperty('ScaleFactor').value
self._smooth = self.getProperty('Smooth').value

self._verbose = self.getProperty('Verbose').value
self._plot = self.getProperty('Plot').value
self._save = self.getProperty('Save').value

Expand Down Expand Up @@ -133,8 +131,7 @@ def _post_process(self):
self.setProperty('OutputWorkspace', self._out_ws)

if self._save:
if self._verbose:
logger.notice("Resolution file saved to default save directory.")
logger.information("Resolution file saved to default save directory.")
SaveNexusProcessed(InputWorkspace=self._out_ws, Filename=self._out_ws + '.nxs')

if self._plot:
Expand Down
Expand Up @@ -25,7 +25,6 @@ def PyInit(self):
self.declareProperty(WorkspaceProperty('OutputWorkspace', '', direction=Direction.Output),
doc='Output workspace group')

self.declareProperty(name='Verbose', defaultValue=False, doc='Output more verbose message to log')
self.declareProperty(name='Plot', defaultValue=False, doc='Plot result workspace')
self.declareProperty(name='Save', defaultValue=False, doc='Save result workspace to nexus file in the default save directory')

Expand Down Expand Up @@ -57,16 +56,14 @@ def PyExec(self):

self.setProperty('OutputWorkspace', self._out_ws)

if self._verbose:
logger.notice('Transmission : ' + str(trans))
logger.information('Transmission : ' + str(trans))

# Save the tranmissin workspace group to a nexus file
if self._save:
workdir = config['defaultsave.directory']
path = os.path.join(workdir, self._out_ws + '.nxs')
SaveNexusProcessed(InputWorkspace=self._out_ws, Filename=path)
if self._verbose:
logger.notice('Output file created : ' + path)
logger.information('Output file created : ' + path)

# Plot spectra from transmission workspace
if self._plot:
Expand All @@ -83,7 +80,6 @@ def _setup(self):
self._sample_ws_in = self.getPropertyValue("SampleWorkspace")
self._can_ws_in = self.getPropertyValue("CanWorkspace")
self._out_ws = self.getPropertyValue('OutputWorkspace')
self._verbose = self.getProperty("Verbose").value
self._plot = self.getProperty("Plot").value
self._save = self.getProperty("Save").value

Expand All @@ -98,8 +94,7 @@ def _get_spectra_index(self, input_ws):
try:
analyser = instrument.getStringParameter('analyser')[0]
detector_1_idx = instrument.getComponentByName(analyser)[0].getID() - 1
if self._verbose:
logger.information('Got index of first detector for analyser %s: %d' % (analyser, detector_1_idx))
logger.information('Got index of first detector for analyser %s: %d' % (analyser, detector_1_idx))
except IndexError:
detector_1_idx = 2
logger.warning('Could not determine index of first detetcor, using default value.')
Expand All @@ -113,8 +108,7 @@ def _get_spectra_index(self, input_ws):
else:
monitor_2_idx = None

if self._verbose:
logger.information('Got index of monitors: %d, %s' % (monitor_1_idx, str(monitor_2_idx)))
logger.information('Got index of monitors: %d, %s' % (monitor_1_idx, str(monitor_2_idx)))
except IndexError:
monitor_1_idx = 0
monitor_2_idx = 1
Expand Down
Expand Up @@ -30,8 +30,6 @@ def PyInit(self):
self.declareProperty(name='Output', defaultValue='', direction=Direction.InOut,
doc='Output name')

self.declareProperty(name='Verbose', defaultValue=False,
doc='Output more verbose message to log')
self.declareProperty(name='Plot', defaultValue=False,
doc='Plot result workspace')
self.declareProperty(name='Save', defaultValue=False,
Expand All @@ -51,19 +49,18 @@ def PyExec(self):
spectrum_ws = "__" + self._in_ws
ExtractSingleSpectrum(InputWorkspace=self._in_ws, OutputWorkspace=spectrum_ws, WorkspaceIndex=self._width)

if self._verbose:
logger.notice('Cropping from Q= ' + str(self._q_min) + ' to ' + str(self._q_max))
in_run = mtd[self._in_ws].getRun()
try:
log = in_run.getLogData('fit_program')
if log:
val = log.value
logger.notice('Fit program was : ' + val)
except RuntimeError:
# If we couldn't find the fit program, just pass
pass
logger.information('Cropping from Q= ' + str(self._q_min) + ' to ' + str(self._q_max))
in_run = mtd[self._in_ws].getRun()
try:
log = in_run.getLogData('fit_program')
if log:
val = log.value
logger.notice('Fit program was : ' + val)
except RuntimeError:
# If we couldn't find the fit program, just pass
pass

logger.notice('Parameters in ' + self._in_ws)
logger.information('Parameters in ' + self._in_ws)

x_data = mtd[self._in_ws].readX(0)
m_max = x_data[-1]
Expand Down Expand Up @@ -136,7 +133,6 @@ def _setup(self):
self._q_min = self.getProperty('QMin').value
self._q_max = self.getProperty('QMax').value

self._verbose = self.getProperty('Verbose').value
self._plot = self.getProperty('Plot').value
self._save = self.getProperty('Save').value

Expand All @@ -149,8 +145,7 @@ def _process_output(self, workspace):
fit_path = os.path.join(workdir, workspace + '.nxs')
SaveNexusProcessed(InputWorkspace=workspace, Filename=fit_path)

if self._verbose:
logger.notice('Fit file is ' + fit_path)
logger.information('Fit file is ' + fit_path)

if self._plot:
from IndirectImport import import_mantidplot
Expand Down

0 comments on commit 6c02875

Please sign in to comment.