From 90c07a8f1a388440798ad8a08bac007ab7331253 Mon Sep 17 00:00:00 2001 From: Steve Williams <stephen.williams@stfc.ac.uk> Date: Fri, 1 Jul 2011 16:59:41 +0000 Subject: [PATCH] Correct unwanted case sensitivity in SANS batch mode, the user file and correct some errors re #3199 --- Code/Mantid/Framework/Algorithms/src/Q1D2.cpp | 25 ++++---- .../Framework/Algorithms/test/Q1D2Test.h | 62 ++++++++++++++++--- .../scripts/SANS/ISISCommandInterface.py | 10 +-- Code/Mantid/scripts/SANS/SANSBatchMode.py | 2 +- .../scripts/SANS/isis_reduction_steps.py | 28 ++++----- 5 files changed, 83 insertions(+), 44 deletions(-) diff --git a/Code/Mantid/Framework/Algorithms/src/Q1D2.cpp b/Code/Mantid/Framework/Algorithms/src/Q1D2.cpp index 329c8112fc1..72d265733b9 100644 --- a/Code/Mantid/Framework/Algorithms/src/Q1D2.cpp +++ b/Code/Mantid/Framework/Algorithms/src/Q1D2.cpp @@ -90,7 +90,7 @@ void Q1D2::exec() const Geometry::ISpectraDetectorMap & inSpecMap = m_dataWS->spectraMap(); const int numSpec = static_cast<int>(m_dataWS->getNumberHistograms()); - Progress progress(this, 0.1, 1.0, numSpec+1); + Progress progress(this, 0.05, 1.0, numSpec+1); PARALLEL_FOR3(m_dataWS, outputWS, pixelAdj) for (int i = 0; i < numSpec; ++i) @@ -113,15 +113,11 @@ void Q1D2::exec() } //get the bins that are included inside the RadiusCut/WaveCutcut off, those to calculate for - size_t wavStart(0); - if (m_RCut > 1e-200) + const size_t wavStart = waveLengthCutOff(i); + if (wavStart >= m_dataWS->readY(i).size()) { - wavStart = waveLengthCutOff(i); - if (wavStart >= m_dataWS->readY(i).size()) - { - // all the spectra in this detector is out of range - continue; - } + // all the spectra in this detector are out of range + continue; } const size_t numWavbins = m_dataWS->readY(i).size()-wavStart; @@ -278,12 +274,16 @@ API::MatrixWorkspace_sptr Q1D2::setUpOutputWorkspace(const std::vector<double> & return outputWS; } /** Finds the first index number of the first wavelength bin that should included based on the -* the calculation: W = Wcut (Rcut-R)/Rcut. Must only be called if m_RCut > 0.0 +* the calculation: W = Wcut (Rcut-R)/Rcut * @param specInd spectrum that is being analysed * @return index number of the first bin to include in the calculation */ size_t Q1D2::waveLengthCutOff(const size_t specInd) const { + if ( !(m_RCut > 0) ) + { + return 0; + } //get the distance of between this detector and the origin, which should be the along the beam center const V3D posOnBank = m_dataWS->getDetector(specInd)->getPos(); double R = (posOnBank.X()*posOnBank.X())+(posOnBank.Y()*posOnBank.Y()); @@ -341,7 +341,7 @@ void Q1D2::pixelWeight(API::MatrixWorkspace_const_sptr pixelAdj, const size_t s if (pixelAdj) { weight *= pixelAdj->readY(specIndex)[0]; - error = pixelAdj->readE(specIndex)[0]; + error = weight*pixelAdj->readE(specIndex)[0]; } else { @@ -476,7 +476,7 @@ void Q1D2::getQBinPlus1(const MantidVec & OutQs, const double QToFind, MantidVec } if ( QToFind < *loc ) { - //QToFind was outside the array + //QToFind is outside the array leave loc == OutQs.begin() return; } } @@ -484,6 +484,7 @@ void Q1D2::getQBinPlus1(const MantidVec & OutQs, const double QToFind, MantidVec { if ( OutQs.empty() || QToFind > *(loc-1) ) { + //outside the array leave loc == OutQs.end() return; } } diff --git a/Code/Mantid/Framework/Algorithms/test/Q1D2Test.h b/Code/Mantid/Framework/Algorithms/test/Q1D2Test.h index 80b3782c12e..94fcf81535c 100644 --- a/Code/Mantid/Framework/Algorithms/test/Q1D2Test.h +++ b/Code/Mantid/Framework/Algorithms/test/Q1D2Test.h @@ -108,11 +108,10 @@ public: TS_ASSERT( boost::math::isnan(result->readY(0).back()) ) //empty bins are 0/0 - TS_ASSERT_DELTA( result->readE(0)[2], 4847257060, 10 ) - TS_ASSERT_DELTA( result->readE(0)[10], 4921866100, 100 ) + TS_ASSERT_DELTA( result->readE(0)[2], 404981, 10 ) + TS_ASSERT_DELTA( result->readE(0)[10], 489710.39, 100 ) TS_ASSERT( boost::math::isnan(result->readE(0)[7]) ) - Mantid::API::AnalysisDataService::Instance().remove(m_noGrav); } void testGravity() @@ -136,7 +135,7 @@ public: Mantid::API::MatrixWorkspace_sptr gravity, refNoGrav = boost::dynamic_pointer_cast<Mantid::API::MatrixWorkspace> - (Mantid::API::AnalysisDataService::Instance().retrieve(outputWS)); + (Mantid::API::AnalysisDataService::Instance().retrieve(m_noGrav)); TS_ASSERT_THROWS_NOTHING( gravity = boost::dynamic_pointer_cast<Mantid::API::MatrixWorkspace> (Mantid::API::AnalysisDataService::Instance().retrieve(outputWS)) ) @@ -151,8 +150,8 @@ public: TS_ASSERT_DELTA( gravity->readY(0)[10], 891346.9, 0.1 ) TS_ASSERT( boost::math::isnan(gravity->readY(0)[78]) ) - TS_ASSERT_DELTA( gravity->readE(0).front(), 3741978390, 10 ) - TS_ASSERT_DELTA( gravity->readE(0)[10], 4921866100, 100 ) + TS_ASSERT_DELTA( gravity->readE(0).front(), 329383, 1 ) + TS_ASSERT_DELTA( gravity->readE(0)[10], 489710, 1 ) TS_ASSERT( boost::math::isnan(gravity->readE(0)[77]) ) Mantid::API::AnalysisDataService::Instance().remove(outputWS); @@ -163,11 +162,12 @@ public: Mantid::Algorithms::Q1D2 Q1D; Q1D.initialize(); + const std::string outputWS("Q1D2Test_result"); TS_ASSERT_THROWS_NOTHING( Q1D.setProperty("DetBankWorkspace", m_inputWS); Q1D.setProperty("WavelengthAdj", m_wavNorm); Q1D.setPropertyValue("PixelAdj", m_pixel); - Q1D.setPropertyValue("OutputWorkspace", m_noGrav); + Q1D.setPropertyValue("OutputWorkspace", outputWS); Q1D.setPropertyValue("OutputBinning", "0.1,-0.02,0.5"); Q1D.setProperty("RadiusCut", 0.22); Q1D.setProperty("WaveCut", 8.0); @@ -178,7 +178,7 @@ public: Mantid::API::MatrixWorkspace_sptr result; TS_ASSERT_THROWS_NOTHING( result = boost::dynamic_pointer_cast<Mantid::API::MatrixWorkspace> - (Mantid::API::AnalysisDataService::Instance().retrieve(m_noGrav)) ) + (Mantid::API::AnalysisDataService::Instance().retrieve(outputWS)) ) TS_ASSERT(result) TS_ASSERT_EQUALS( result->getNumberHistograms(), 1 ) @@ -193,10 +193,52 @@ public: TS_ASSERT_DELTA( result->readY(0)[12], 503242.79, 0.1) TS_ASSERT( boost::math::isnan(result->readY(0).back()) ) - TS_ASSERT_DELTA( result->readE(0)[2], 4847257060, 10 ) - TS_ASSERT_DELTA( result->readE(0)[10], 4921866100, 100 ) + TS_ASSERT_DELTA( result->readE(0)[2], 404981, 1 ) + TS_ASSERT_DELTA( result->readE(0)[10], 489710, 100 ) TS_ASSERT( boost::math::isnan(result->readE(0)[7]) ) + } + + // here the cut parameters are set but should only affect detectors with lower R + void testNoCuts() + { + Mantid::Algorithms::Q1D2 Q1D; + Q1D.initialize(); + + const std::string outputWS("Q1D2Test_result"); + TS_ASSERT_THROWS_NOTHING( + Q1D.setProperty("DetBankWorkspace", m_inputWS); + Q1D.setProperty("WavelengthAdj", m_wavNorm); + Q1D.setPropertyValue("PixelAdj", m_pixel); + Q1D.setPropertyValue("OutputWorkspace", outputWS); + Q1D.setPropertyValue("OutputBinning", "0.1,-0.02,0.5"); + //this raduis is too small to exclude anything + Q1D.setProperty("RadiusCut", 0.05); + //this is the entire wavelength range + Q1D.setProperty("WaveCut", 30.0); + ) + TS_ASSERT_THROWS_NOTHING( Q1D.execute() ) + TS_ASSERT( Q1D.isExecuted() ) + Mantid::API::MatrixWorkspace_sptr nocuts, noGrav = + boost::dynamic_pointer_cast<Mantid::API::MatrixWorkspace> + (Mantid::API::AnalysisDataService::Instance().retrieve(m_noGrav)); + TS_ASSERT_THROWS_NOTHING( + nocuts = boost::dynamic_pointer_cast<Mantid::API::MatrixWorkspace> + (Mantid::API::AnalysisDataService::Instance().retrieve(outputWS)) ) + + TS_ASSERT(nocuts) + TS_ASSERT_EQUALS( nocuts->getNumberHistograms(), 1 ) + + for ( int i = 0; i < nocuts->readY(0).size(); ++i ) + { + TS_ASSERT_EQUALS( nocuts->readX(0)[i], noGrav->readX(0)[i] ) + if ( ! boost::math::isnan(nocuts->readY(0)[i]) ) + { + TS_ASSERT_EQUALS( nocuts->readY(0)[i], noGrav->readY(0)[i] ) + TS_ASSERT_EQUALS( nocuts->readE(0)[i], noGrav->readE(0)[i] ) + } + } + Mantid::API::AnalysisDataService::Instance().remove(m_noGrav); } diff --git a/Code/Mantid/scripts/SANS/ISISCommandInterface.py b/Code/Mantid/scripts/SANS/ISISCommandInterface.py index dbd1273ad2e..b1e5b26bb1e 100644 --- a/Code/Mantid/scripts/SANS/ISISCommandInterface.py +++ b/Code/Mantid/scripts/SANS/ISISCommandInterface.py @@ -437,11 +437,11 @@ def PlotResult(workspace, canvas=None): @param canvas: optional handle to an existing graph to write the plot to @return: a handle to the graph that was written to """ - try: - numSpecs = workspace.getNumberHistograms() - except AttributeError: - #ensure that we are dealing with a workspace handle rather than its name - workspace = MantidFramework.mtd[workspace] + #ensure that we are dealing with a workspace handle rather than its name + workspace = mtd[str(workspace)] + if workspace.isGroup(): + numSpecs = workspace[0].getNumberHistograms() + else: numSpecs = workspace.getNumberHistograms() try: diff --git a/Code/Mantid/scripts/SANS/SANSBatchMode.py b/Code/Mantid/scripts/SANS/SANSBatchMode.py index 6ab1140a1a6..37b6f2a5a6d 100644 --- a/Code/Mantid/scripts/SANS/SANSBatchMode.py +++ b/Code/Mantid/scripts/SANS/SANSBatchMode.py @@ -194,7 +194,7 @@ def parse_run(run_num, ext): """ if not run_num: return '', -1 - parts = run_num.split('p') + parts = run_num.upper().split('P') if len(parts) > 2: raise RuntimeError('Problem reading run number "'+run_num+'"') run_spec = parts[0]+ext diff --git a/Code/Mantid/scripts/SANS/isis_reduction_steps.py b/Code/Mantid/scripts/SANS/isis_reduction_steps.py index bf40a60f649..5beb4df7829 100644 --- a/Code/Mantid/scripts/SANS/isis_reduction_steps.py +++ b/Code/Mantid/scripts/SANS/isis_reduction_steps.py @@ -1135,25 +1135,21 @@ class TransmissionCalc(sans_reduction_steps.BaseTransmission): or estimates the proportion of neutrons that are transmitted through the sample """ + self.output_wksp = None #look for run files that contain transmission data test1, test2 = self._get_run_wksps(reducer) if test1 or test2: + #we can calculate the transmission from some experimental runs if self.calculated_samp: raise RuntimeError('Cannot use TransWorkspace() and TransmissionSample() together') - trans_ws = self.calculate(reducer) + self.output_wksp = self.calculate(reducer) else: - trans_ws = None + #they have supplied a transmission file use it if reducer.is_can(): - trans_ws = self.calculated_can + self.output_wksp = self.calculated_can else: - trans_ws = self.calculated_samp - if not trans_ws: - #if no transmission files were specified this isn't an error, we just do nothing - return None - - self.output_wksp = trans_ws+'_rebinned' - RebinToWorkspace(trans_ws, workspace, self.output_wksp) + self.output_wksp = self.calculated_samp def _get_run_wksps(self, reducer): """ @@ -1576,17 +1572,17 @@ class UserFile(ReductionStep): _issueWarning("L/SP lines are ignored") return - if limits.startswith('Q/RCut'): - limits = limits.split('RCut') + if limits.upper().startswith('Q/RCUT'): + limits = limits.upper().split('RCUT') if len(limits) != 2: - _issueWarning("Badly formed L/Q/RCut line") + _issueWarning("Badly formed L/Q/RCUT line") else: reducer.to_Q.r_cut = float(limits[1]) return - if limits.startswith('Q/WCut'): - limits = limits.split('WCut') + if limits.upper().startswith('Q/WCUT'): + limits = limits.upper().split('WCUT') if len(limits) != 2: - _issueWarning("Badly formed L/Q/WCut line") + _issueWarning("Badly formed L/Q/WCUT line") else: reducer.to_Q.w_cut = float(limits[1]) return -- GitLab