Skip to content

Commit

Permalink
Refs #4454. Fix bleed test in diag.
Browse files Browse the repository at this point in the history
Also fix error in reporting the number of failures correctly.
  • Loading branch information
martyngigg committed Jan 12, 2012
1 parent b62c567 commit f638e8b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ namespace Mantid
/// Calculates the sum of solid angles of detectors for each histogram
API::MatrixWorkspace_sptr getSolidAngles(int firstSpec, int lastSpec);
/// Mask the outlier values to get a better median value
void maskOutliers(const double median, API::MatrixWorkspace_sptr countsWS);
int maskOutliers(const double median, API::MatrixWorkspace_sptr countsWS);
/// Do the tests and mask those that fail
int doDetectorTests(const API::MatrixWorkspace_sptr countsWS, const double median);

Expand Down
17 changes: 12 additions & 5 deletions Code/Mantid/Framework/Algorithms/src/MedianDetectorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ namespace Mantid
double median = calculateMedian(countsWS, excludeZeroes);
g_log.information() << "Median value = " << median << "\n";
// 2. Mask outliers
maskOutliers(median, countsWS);
int numFailed = maskOutliers(median, countsWS);
// 3. Recalulate the median
median = calculateMedian(countsWS, excludeZeroes);
g_log.information() << "Median value with outliers removed = " << median << "\n";

int numFailed = doDetectorTests(countsWS, median);
numFailed += doDetectorTests(countsWS, median);
g_log.information() << "Median test results:\n"
<< "\tNumber of failures - " << numFailed << "\n";

Expand Down Expand Up @@ -200,27 +200,34 @@ namespace Mantid
* Mask the outlier values to get a better median value.
* @param median The median value calculated from the current counts
* @param countsWS The counts workspace. Any outliers will be masked here
* @returns The number masked
*/
void MedianDetectorTest::maskOutliers(const double median, API::MatrixWorkspace_sptr countsWS)
int MedianDetectorTest::maskOutliers(const double median, API::MatrixWorkspace_sptr countsWS)
{
// Fractions of the median
const double out_lo = getProperty("LowOutlier");
const double out_hi = getProperty("HighOutlier");
const int64_t nhist = static_cast<int64_t>(countsWS->getNumberHistograms());
// Mask outliers
int numFailed(0);

PARALLEL_FOR1(countsWS)
for(int64_t i = 0; i < nhist; ++i)
{
const double value = countsWS->readY(i)[0];
if( (value < out_lo*median) && (value > 0.0) )
{
countsWS->maskWorkspaceIndex(i);
PARALLEL_ATOMIC
++numFailed;
}
if( value > out_hi*median )
else if( value > out_hi*median )
{
countsWS->maskWorkspaceIndex(i);
PARALLEL_ATOMIC
++numFailed;
}
}
return numFailed;
}


Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/scripts/Inelastic/DirectEnergyConversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ def init_idf_params(self):
try:
self.diag_bleed_test = self.get_default_parameter('diag_bleed_test')
self.diag_bleed_maxrate = self.get_default_parameter('diag_bleed_maxrate')
self.diag_bleed_pixels = self.get_default_parameter('diag_bleed_pixels')
self.diag_bleed_pixels = int(self.get_default_parameter('diag_bleed_pixels'))
self.diag_params.extend(['diag_bleed_maxrate','diag_bleed_pixels'])
except ValueError:
self.diag_bleed_test = False
Expand Down
22 changes: 15 additions & 7 deletions Code/Mantid/scripts/Inelastic/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,19 @@ def diagnose(white_int, **kwargs):
_add_masking(white_int, __white_masks, start_index, end_index)
DeleteWorkspace(__white_masks)
else:
raise RuntimeError('Invalid input for white run "%s"' % str(white_run))
raise RuntimeError('Invalid input for white run "%s"' % str(white_int))

#
# Zero total count check for sample counts
#
zero_count_failures = 0
if hasattr(parser, 'sample_counts'):
_add_masking(parser.sample_counts, white_int)
maskZero = FindDetectorsOutsideLimits(InputWorkspace=parser.sample_counts, OutputWorkspace='maskZero',
StartWorkspaceIndex=start_index, EndWorkspaceIndex=end_index,
LowThreshold=1e-10, HighThreshold=1e100).workspace()
checker = FindDetectorsOutsideLimits(InputWorkspace=parser.sample_counts, OutputWorkspace='maskZero',
StartWorkspaceIndex=start_index, EndWorkspaceIndex=end_index,
LowThreshold=1e-10, HighThreshold=1e100)
zero_count_failures = checker['NumberOfFailures'].value
maskZero = checker.workspace()
_add_masking(white_int, maskZero, start_index, end_index)
DeleteWorkspace(maskZero)

Expand All @@ -110,6 +113,7 @@ def diagnose(white_int, **kwargs):
_add_masking(parser.background_int, white_int)
__bkgd_mask, failures = _do_background_test(parser.background_int, parser.samp_lo,
parser.samp_hi, parser.samp_sig, parser.samp_zero, start_index, end_index)
test_results[2] = [str(__bkgd_mask), zero_count_failures + failures]
_add_masking(white_int, __bkgd_mask, start_index, end_index)
DeleteWorkspace(__bkgd_mask)

Expand All @@ -119,9 +123,10 @@ def diagnose(white_int, **kwargs):
if hasattr(parser, 'bleed_test') and parser.bleed_test:
if not hasattr(parser, 'sample_run'):
raise RuntimeError("Bleed test requested but the sample_run keyword has not been provided")
_bleed_masks, failures = _do_bleed_test(parser.sample_run, parser.bleed_maxrate, parser.bleed_pixels)
__bleed_masks, failures = _do_bleed_test(parser.sample_run, parser.bleed_maxrate, parser.bleed_pixels)
test_results[3] = [str(__bleed_masks), failures]
_add_masking(white_int, __bleed_masks)
DeleteWorkspace(_bleed_masks)
DeleteWorkspace(__bleed_masks)

if hasattr(parser, 'print_results') and parser.print_results:
print_test_summary(test_results)
Expand Down Expand Up @@ -284,7 +289,10 @@ def _do_bleed_test(sample_run, max_framerate, ignored_pixels):
max_framerate = float(data_ws.getInstrument().getNumberParameter('max-tube-framerate')[0])
if ignored_pixels is None:
ignored_pixels = int(data_ws.getInstrument().getNumberParameter('num-ignored-pixels')[0])

else:
# Make sure it is an int
ignored_pixels = int(ignored_pixels)

# What shall we call the output
lhs_names = lhs_info('names')
if len(lhs_names) > 0:
Expand Down

0 comments on commit f638e8b

Please sign in to comment.