Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
mantidproject
mantid
Commits
eb80c08d
Commit
eb80c08d
authored
Jan 29, 2021
by
Hahn, Steven
Committed by
Peterson, Peter
Feb 12, 2021
Browse files
Initial implementation of RebinRagged
Signed-off-by:
Steven Hahn
<
hahnse@ornl.gov
>
parent
538d42ba
Changes
7
Hide whitespace changes
Inline
Side-by-side
Framework/PythonInterface/plugins/algorithms/AlignAndFocusPowderFromFiles.py
View file @
eb80c08d
...
...
@@ -19,7 +19,7 @@ PROPS_FOR_INSTR = ["PrimaryFlightPath", "SpectrumIDs", "L2", "Polar", "Azimuthal
CAL_FILE
,
GROUP_FILE
=
"CalFileName"
,
"GroupFilename"
CAL_WKSP
,
GRP_WKSP
,
MASK_WKSP
=
"CalibrationWorkspace"
,
"GroupingWorkspace"
,
"MaskWorkspace"
# AlignAndFocusPowder only uses the ranges
PROPS_IN_PD_CHARACTER
=
[
"DMin"
,
"DMax"
,
"TMin"
,
"TMax"
,
"CropWavelengthMin"
,
"CropWavelengthMax"
]
PROPS_IN_PD_CHARACTER
=
[
"DMin"
,
"DMax"
,
"Delta"
,
"TMin"
,
"TMax"
,
"CropWavelengthMin"
,
"CropWavelengthMax"
]
PROPS_FOR_ALIGN
=
[
CAL_FILE
,
GROUP_FILE
,
GRP_WKSP
,
CAL_WKSP
,
"OffsetsWorkspace"
,
MASK_WKSP
,
"MaskBinTable"
,
...
...
Framework/PythonInterface/plugins/algorithms/SNSPowderReduction.py
View file @
eb80c08d
...
...
@@ -159,7 +159,7 @@ class SNSPowderReduction(DistributedDataProcessorAlgorithm):
return
"The algorithm used for reduction of powder diffraction data obtained on SNS instruments (e.g. PG3) "
def
PyInit
(
self
):
self
.
copyProperties
(
'AlignAndFocusPowderFromFiles'
,
[
'Filename'
,
'PreserveEvents'
])
self
.
copyProperties
(
'AlignAndFocusPowderFromFiles'
,
[
'Filename'
,
'PreserveEvents'
,
'DMin'
,
'DMax'
,
'Delta'
])
self
.
declareProperty
(
"Sum"
,
False
,
"Sum the runs. Does nothing for characterization runs"
)
...
...
Framework/WorkflowAlgorithms/inc/MantidWorkflowAlgorithms/AlignAndFocusPowder.h
View file @
eb80c08d
...
...
@@ -74,6 +74,7 @@ private:
void
loadCalFile
(
const
std
::
string
&
calFilename
,
const
std
::
string
&
groupFilename
);
API
::
MatrixWorkspace_sptr
rebin
(
API
::
MatrixWorkspace_sptr
matrixws
);
API
::
MatrixWorkspace_sptr
rebinRagged
(
API
::
MatrixWorkspace_sptr
matrixws
);
API
::
MatrixWorkspace_sptr
conjoinWorkspaces
(
const
API
::
MatrixWorkspace_sptr
&
ws1
,
...
...
@@ -112,6 +113,7 @@ private:
int
m_resampleX
{
0
};
std
::
vector
<
double
>
m_dmins
;
std
::
vector
<
double
>
m_dmaxs
;
std
::
vector
<
double
>
m_delta
;
bool
dspace
{
false
};
double
xmin
{
0.0
};
double
xmax
{
0.0
};
...
...
Framework/WorkflowAlgorithms/src/AlignAndFocusPowder.cpp
View file @
eb80c08d
...
...
@@ -24,7 +24,6 @@
#include
"MantidKernel/InstrumentInfo.h"
#include
"MantidKernel/PropertyManager.h"
#include
"MantidKernel/PropertyManagerDataService.h"
#include
"MantidKernel/RebinParamsValidator.h"
#include
"MantidKernel/System.h"
using
Mantid
::
Geometry
::
Instrument_const_sptr
;
...
...
@@ -57,6 +56,7 @@ const std::string RESAMPLEX("ResampleX");
const
std
::
string
BIN_IN_D
(
"Dspacing"
);
const
std
::
string
D_MINS
(
"DMin"
);
const
std
::
string
D_MAXS
(
"DMax"
);
const
std
::
string
DELTA
(
"Delta"
);
const
std
::
string
TOF_MIN
(
"TMin"
);
const
std
::
string
TOF_MAX
(
"TMax"
);
const
std
::
string
WL_MIN
(
"CropWavelengthMin"
);
...
...
@@ -160,6 +160,9 @@ void AlignAndFocusPowder::init() {
std
::
make_unique
<
ArrayProperty
<
double
>>
(
PropertyNames
::
D_MAXS
),
"Maximum for Dspace axis. (Default 0.) "
);
mapPropertyName
(
PropertyNames
::
D_MAXS
,
"d_max"
);
declareProperty
(
std
::
make_unique
<
ArrayProperty
<
double
>>
(
PropertyNames
::
DELTA
),
"Step parameter for rebin"
);
mapPropertyName
(
PropertyNames
::
DELTA
,
"delta"
);
declareProperty
(
PropertyNames
::
TOF_MIN
,
EMPTY_DBL
(),
"Minimum for TOF axis. Defaults to 0. "
);
mapPropertyName
(
PropertyNames
::
TOF_MIN
,
"tof_min"
);
...
...
@@ -355,6 +358,7 @@ void AlignAndFocusPowder::exec() {
dspace
=
getProperty
(
PropertyNames
::
BIN_IN_D
);
auto
dmin
=
getVecPropertyFromPmOrSelf
(
PropertyNames
::
D_MINS
,
m_dmins
);
auto
dmax
=
getVecPropertyFromPmOrSelf
(
PropertyNames
::
D_MAXS
,
m_dmaxs
);
this
->
getVecPropertyFromPmOrSelf
(
PropertyNames
::
DELTA
,
m_delta
);
LRef
=
getProperty
(
PropertyNames
::
UNWRAP_REF
);
DIFCref
=
getProperty
(
PropertyNames
::
LOWRES_REF
);
const
bool
applyLorentz
=
getProperty
(
PropertyNames
::
LORENTZ
);
...
...
@@ -745,9 +749,18 @@ void AlignAndFocusPowder::exec() {
// this next call should probably be in for rebin as well
// but it changes the system tests
if
(
dspace
&&
m_resampleX
!=
0
)
{
m_outputW
=
rebin
(
m_outputW
);
if
(
m_processLowResTOF
)
m_lowResW
=
rebin
(
m_lowResW
);
if
(
m_delta
.
empty
())
{
m_outputW
=
rebin
(
m_outputW
);
}
else
{
m_outputW
=
rebinRagged
(
m_outputW
);
}
if
(
m_processLowResTOF
)
{
if
(
m_delta
.
empty
())
{
m_lowResW
=
rebin
(
m_lowResW
);
}
else
{
m_lowResW
=
rebinRagged
(
m_lowResW
);
}
}
}
m_progress
->
report
();
...
...
@@ -788,6 +801,10 @@ void AlignAndFocusPowder::exec() {
m_outputW
=
convertUnits
(
m_outputW
,
"TOF"
);
m_progress
->
report
();
if
(
!
dspace
&&
!
m_delta
.
empty
())
{
m_outputW
=
rebinRagged
(
m_outputW
);
}
// compress again if appropriate
m_outputEW
=
std
::
dynamic_pointer_cast
<
EventWorkspace
>
(
m_outputW
);
if
((
m_outputEW
)
&&
(
compressEventsTolerance
>
0.
))
{
...
...
@@ -902,7 +919,9 @@ AlignAndFocusPowder::convertUnits(API::MatrixWorkspace_sptr matrixws,
*/
API
::
MatrixWorkspace_sptr
AlignAndFocusPowder
::
rebin
(
API
::
MatrixWorkspace_sptr
matrixws
)
{
if
(
m_resampleX
!=
0
)
{
if
(
!
m_delta
.
empty
())
{
return
matrixws
;
}
else
if
(
m_resampleX
!=
0
)
{
// ResampleX
g_log
.
information
()
<<
"running ResampleX(NumberBins="
<<
abs
(
m_resampleX
)
<<
", LogBinning="
<<
(
m_resampleX
<
0
)
<<
", dMin("
...
...
@@ -948,6 +967,37 @@ AlignAndFocusPowder::rebin(API::MatrixWorkspace_sptr matrixws) {
}
}
//----------------------------------------------------------------------------------------------
/** Rebin
*/
API
::
MatrixWorkspace_sptr
AlignAndFocusPowder
::
rebinRagged
(
API
::
MatrixWorkspace_sptr
matrixws
)
{
API
::
IAlgorithm_sptr
alg
=
createChildAlgorithm
(
"Rebin"
);
g_log
.
information
()
<<
"running RebinRagged( "
;
size_t
numHist
=
m_outputW
->
getNumberHistograms
();
if
((
numHist
==
m_dmins
.
size
())
&&
(
numHist
==
m_dmaxs
.
size
()))
{
alg
->
setProperty
(
"XMin"
,
m_dmins
);
alg
->
setProperty
(
"XMax"
,
m_dmaxs
);
}
else
{
g_log
.
information
()
<<
"Number of dmin and dmax values don't match the "
<<
"number of workspace indices. Ignoring the parameters.
\n
"
;
}
g_log
.
information
()
<<
") started at "
<<
Types
::
Core
::
DateAndTime
::
getCurrentTime
()
<<
"
\n
"
;
for
(
double
param
:
m_params
)
{
if
(
isEmpty
(
param
))
{
g_log
.
warning
(
"encountered empty binning parameter"
);
}
}
alg
->
setProperty
(
"InputWorkspace"
,
matrixws
);
alg
->
setProperty
(
"OutputWorkspace"
,
matrixws
);
alg
->
setProperty
(
"Delta"
,
m_delta
);
alg
->
executeAsChildAlg
();
matrixws
=
alg
->
getProperty
(
"OutputWorkspace"
);
return
matrixws
;
}
//----------------------------------------------------------------------------------------------
/** Add workspace2 to workspace1 by adding spectrum.
*/
...
...
Testing/Data/SystemTest/VULCAN_189186.nxs.h5.md5
0 → 100644
View file @
eb80c08d
36faed5d88e736c0da6803f6a5d7ba28
Testing/Data/SystemTest/VULCAN_calibrate_2019_06_27.h5.md5
0 → 100644
View file @
eb80c08d
d3d4ff10ddf428506183a822effb5c5a
Testing/SystemTests/tests/framework/AlignAndFocusPowderFromFilesTest.py
View file @
eb80c08d
...
...
@@ -300,3 +300,45 @@ class AbsorptionCompare(systemtesting.MantidSystemTest):
assert
mtd
[
self
.
wksp_file
].
sample
().
getMaterial
().
name
()
==
'V'
# use standard method
return
(
self
.
wksp_mem
,
self
.
wksp_file
)
class
VulcanRaggedCompare
(
systemtesting
.
MantidSystemTest
):
cal_file
=
"VULCAN_calibrate_2019_06_27.h5"
data_file
=
'VULCAN_189186.nxs.h5'
def
cleanup
(
self
):
return
do_cleanup
(
self
.
cacheDir
)
def
requiredMemoryMB
(
self
):
return
3
*
1024
# GiB
def
requiredFiles
(
self
):
return
[
self
.
cal_file
,
self
.
data_file
]
def
runTest
(
self
):
self
.
cacheDir
=
getCacheDir
()
self
.
wksp_mem
=
os
.
path
.
basename
(
self
.
data_file
).
split
(
'.'
)[
0
]
self
.
wksp_mem
,
self
.
wksp_file
=
self
.
wksp_mem
+
'_mem'
,
self
.
wksp_mem
+
'_file'
# load then process
LoadEventAndCompress
(
Filename
=
self
.
data_file
,
OutputWorkspace
=
self
.
wksp_mem
,
MaxChunkSize
=
16
,
FilterBadPulses
=
0
)
LoadDiffCal
(
Filename
=
self
.
cal_file
,
InputWorkspace
=
self
.
wksp_mem
,
WorkspaceName
=
'PG3'
)
AlignAndFocusPowder
(
InputWorkspace
=
self
.
wksp_mem
,
OutputWorkspace
=
self
.
wksp_mem
,
GroupingWorkspace
=
'PG3_group'
,
CalibrationWorkspace
=
'PG3_cal'
,
MaskWorkspace
=
'PG3_mask'
,
Params
=-
.
0002
,
CompressTolerance
=
0.01
,
PrimaryFlightPath
=
60
,
SpectrumIDs
=
'1,2,3'
,
L2
=
'3.18,3.18,3.18'
,
Polar
=
'90,270,145'
,
Azimuthal
=
'0,0,0'
)
# everything inside the algorithm
AlignAndFocusPowderFromFiles
(
Filename
=
self
.
data_file
,
OutputWorkspace
=
self
.
wksp_file
,
GroupingWorkspace
=
'PG3_group'
,
CalibrationWorkspace
=
'PG3_cal'
,
MaskWorkspace
=
'PG3_mask'
,
Params
=-
.
0002
,
CompressTolerance
=
0.01
,
PrimaryFlightPath
=
60
,
SpectrumIDs
=
'1,2,3'
,
L2
=
'3.18,3.18,3.18'
,
Polar
=
'90,270,145'
,
Azimuthal
=
'0,0,0'
,
ReductionProperties
=
'__snspowderreduction_inner'
)
def
validateMethod
(
self
):
self
.
tolerance
=
1.0e-2
return
"ValidateWorkspaceToWorkspace"
def
validate
(
self
):
return
(
self
.
wksp_mem
,
self
.
wksp_file
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment