Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
mantid
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mantidproject
mantid
Commits
88043009
Commit
88043009
authored
9 years ago
by
Marina Ganeva
Browse files
Options
Downloads
Patches
Plain Diff
3 of 3 pylint warnings fixed
parent
24b96d8a
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Code/Mantid/Framework/PythonInterface/plugins/algorithms/DNSDetEffCorrVana.py
+48
-47
48 additions, 47 deletions
...k/PythonInterface/plugins/algorithms/DNSDetEffCorrVana.py
with
48 additions
and
47 deletions
Code/Mantid/Framework/PythonInterface/plugins/algorithms/DNSDetEffCorrVana.py
+
48
−
47
View file @
88043009
...
@@ -46,67 +46,68 @@ class DNSDetEffCorrVana(PythonAlgorithm):
...
@@ -46,67 +46,68 @@ class DNSDetEffCorrVana(PythonAlgorithm):
return
return
def
_dimensions_valid
(
self
,
data_ws
,
vana_ws
,
bkgr_ws
):
def
_dimensions_valid
(
self
):
"""
"""
Checks validity of the workspace dimensions:
Checks validity of the workspace dimensions:
all given workspaces must have the same number of dimensions
all given workspaces must have the same number of dimensions
and the same number of histograms
and the same number of histograms
and the same number of bins
and the same number of bins
"""
"""
nd
=
data
_
ws
.
getNumDims
()
nd
=
self
.
dataws
.
getNumDims
()
nh
=
data
_
ws
.
getNumberHistograms
()
nh
=
self
.
dataws
.
getNumberHistograms
()
nb
=
data
_
ws
.
blocksize
()
nb
=
self
.
dataws
.
blocksize
()
if
vana
_
ws
.
getNumDims
()
!=
nd
or
vana
_
ws
.
getNumberHistograms
()
!=
nh
or
vana
_
ws
.
blocksize
()
!=
nb
:
if
self
.
vanaws
.
getNumDims
()
!=
nd
or
self
.
vanaws
.
getNumberHistograms
()
!=
nh
or
self
.
vanaws
.
blocksize
()
!=
nb
:
self
.
log
().
error
(
"
The dimensions of Vanadium workspace are not valid.
"
)
self
.
log
().
error
(
"
The dimensions of Vanadium workspace are not valid.
"
)
return
False
return
False
if
bkg
r_
ws
.
getNumDims
()
!=
nd
or
bkg
r_
ws
.
getNumberHistograms
()
!=
nh
or
bkg
r_
ws
.
blocksize
()
!=
nb
:
if
self
.
bkgws
.
getNumDims
()
!=
nd
or
self
.
bkgws
.
getNumberHistograms
()
!=
nh
or
self
.
bkgws
.
blocksize
()
!=
nb
:
self
.
log
().
error
(
"
The dimensions of Background workspace are not valid.
"
)
self
.
log
().
error
(
"
The dimensions of Background workspace are not valid.
"
)
return
False
return
False
return
True
return
True
def
_norm_ws_exist
(
self
,
vana_ws
,
bkgr_ws
):
def
_norm_ws_exist
(
self
):
"""
"""
Checks whether the normalization workspaces exist
Checks whether the normalization workspaces exist
normalization workspaces are created by the loader,
normalization workspaces are created by the loader,
but could be ocasionally deleted by the user
but could be ocasionally deleted by the user
"""
"""
if
not
api
.
mtd
.
doesExist
(
bkg
r_
ws
.
getName
()
+
'
_NORM
'
):
if
not
api
.
mtd
.
doesExist
(
self
.
bkgws
.
getName
()
+
'
_NORM
'
):
self
.
log
().
error
(
"
Normalization workspace for
"
+
bkg
r_
ws
.
getName
()
+
"
is not found!
"
)
self
.
log
().
error
(
"
Normalization workspace for
"
+
self
.
bkgws
.
getName
()
+
"
is not found!
"
)
return
False
return
False
if
not
api
.
mtd
.
doesExist
(
vana
_
ws
.
getName
()
+
'
_NORM
'
):
if
not
api
.
mtd
.
doesExist
(
self
.
vanaws
.
getName
()
+
'
_NORM
'
):
self
.
log
().
error
(
"
Normalization workspace for
"
+
vana
_
ws
.
getName
()
+
"
is not found!
"
)
self
.
log
().
error
(
"
Normalization workspace for
"
+
self
.
vanaws
.
getName
()
+
"
is not found!
"
)
return
False
return
False
return
True
return
True
def
_vana_mean
(
self
,
vana_ws
,
vana_mean_ws_name
,
nd
=
2
):
def
_vana_mean
(
self
,
ws
):
"""
"""
checks whether the workspace with mean counts for Vanadium exists
checks whether the workspace with mean counts for Vanadium exists
creates one if not
creates one if not
"""
"""
if
api
.
mtd
.
doesExist
(
vana_mean_ws_name
):
if
api
.
mtd
.
doesExist
(
self
.
vana_mean_name
):
vana_mean
=
api
.
mtd
[
vana_mean_ws_name
]
nd
=
self
.
dataws
.
getNumDims
()
if
vana_mean
.
getNumDims
()
!=
nd
:
vmean
=
api
.
mtd
[
self
.
vana_mean_name
]
if
vmean
.
getNumDims
()
!=
nd
:
message
=
"
Specified VanadiumMean Workspace has wrong dimensions! Must be 2.
"
message
=
"
Specified VanadiumMean Workspace has wrong dimensions! Must be 2.
"
self
.
log
().
error
(
message
)
self
.
log
().
error
(
message
)
return
None
return
None
if
v
ana_
mean
.
getNumberHistograms
()
!=
1
:
if
vmean
.
getNumberHistograms
()
!=
1
:
message
=
"
Specified VanadiumMean Workspace has wrong number of histograms! Must be 1.
"
message
=
"
Specified VanadiumMean Workspace has wrong number of histograms! Must be 1.
"
self
.
log
().
error
(
message
)
self
.
log
().
error
(
message
)
return
None
return
None
if
v
ana_
mean
.
blocksize
()
!=
1
:
if
vmean
.
blocksize
()
!=
1
:
message
=
"
Specified VanadiumMean Workspace has wrong number of bins! Must be 1.
"
message
=
"
Specified VanadiumMean Workspace has wrong number of bins! Must be 1.
"
self
.
log
().
error
(
message
)
self
.
log
().
error
(
message
)
return
None
return
None
else
:
else
:
nh
=
vana
_
ws
.
getNumberHistograms
()
nh
=
self
.
vanaws
.
getNumberHistograms
()
v
ana_
mean
=
api
.
SumSpectra
(
vana_
ws
,
IncludeMonitors
=
False
)
/
nh
vmean
=
api
.
SumSpectra
(
ws
,
IncludeMonitors
=
False
)
/
nh
return
v
ana_
mean
return
vmean
def
_cleanup
(
self
,
wslist
):
def
_cleanup
(
self
,
wslist
):
"""
"""
...
@@ -116,17 +117,17 @@ class DNSDetEffCorrVana(PythonAlgorithm):
...
@@ -116,17 +117,17 @@ class DNSDetEffCorrVana(PythonAlgorithm):
api
.
DeleteWorkspace
(
w
)
api
.
DeleteWorkspace
(
w
)
return
return
def
_vana_correct
(
self
,
data_ws
,
vana_ws
,
bkgr_ws
,
vana_mean_ws_name
,
outws_name
):
def
_vana_correct
(
self
):
"""
"""
creates the corrected workspace
creates the corrected workspace
"""
"""
wslist
=
[]
wslist
=
[]
# 1. normalize Vanadium and Background
# 1. normalize Vanadium and Background
vana_normws
=
api
.
mtd
[
vana
_
ws
.
getName
()
+
'
_NORM
'
]
vana_normws
=
api
.
mtd
[
self
.
vanaws
.
getName
()
+
'
_NORM
'
]
bkg_normws
=
api
.
mtd
[
bkg
r_
ws
.
getName
()
+
'
_NORM
'
]
bkg_normws
=
api
.
mtd
[
self
.
bkgws
.
getName
()
+
'
_NORM
'
]
_vana_norm_
=
api
.
Divide
(
vana
_
ws
,
vana_normws
)
_vana_norm_
=
api
.
Divide
(
self
.
vanaws
,
vana_normws
)
wslist
.
append
(
_vana_norm_
.
getName
())
wslist
.
append
(
_vana_norm_
.
getName
())
_bkg_norm_
=
api
.
Divide
(
bkg
r_
ws
,
bkg_normws
)
_bkg_norm_
=
api
.
Divide
(
self
.
bkgws
,
bkg_normws
)
wslist
.
append
(
_bkg_norm_
.
getName
())
wslist
.
append
(
_bkg_norm_
.
getName
())
# 2. substract background from Vanadium
# 2. substract background from Vanadium
_vana_bg_
=
_vana_norm_
-
_bkg_norm_
_vana_bg_
=
_vana_norm_
-
_bkg_norm_
...
@@ -136,24 +137,24 @@ class DNSDetEffCorrVana(PythonAlgorithm):
...
@@ -136,24 +137,24 @@ class DNSDetEffCorrVana(PythonAlgorithm):
neg_values
=
np
.
where
(
arr
<
0
)[
0
]
neg_values
=
np
.
where
(
arr
<
0
)[
0
]
if
len
(
neg_values
):
if
len
(
neg_values
):
self
.
_cleanup
(
wslist
)
self
.
_cleanup
(
wslist
)
message
=
"
Background
"
+
bkg
r_
ws
.
getName
()
+
"
is higher than Vanadium
"
+
\
message
=
"
Background
"
+
self
.
bkgws
.
getName
()
+
"
is higher than Vanadium
"
+
\
vana
_
ws
.
getName
()
+
"
signal!
"
self
.
vanaws
.
getName
()
+
"
signal!
"
self
.
log
().
error
(
message
)
self
.
log
().
error
(
message
)
raise
RuntimeError
(
message
)
raise
RuntimeError
(
message
)
# 3. calculate correction coefficients
# 3. calculate correction coefficients
_vana_mean_ws_
=
self
.
_vana_mean
(
_vana_bg_
,
vana_mean_ws_name
,
data_ws
.
getNumDims
()
)
_vana_mean_ws_
=
self
.
_vana_mean
(
_vana_bg_
)
if
not
_vana_mean_ws_
:
if
not
_vana_mean_ws_
:
self
.
_cleanup
(
wslist
)
self
.
_cleanup
(
wslist
)
return
None
return
None
if
not
vana_mean_
ws_
name
:
if
not
self
.
vana_mean_name
:
wslist
.
append
(
_vana_mean_ws_
)
wslist
.
append
(
_vana_mean_ws_
)
_coef_ws_
=
api
.
Divide
(
LHSWorkspace
=
_vana_bg_
,
RHSWorkspace
=
_vana_mean_ws_
,
WarnOnZeroDivide
=
True
)
_coef_ws_
=
api
.
Divide
(
LHSWorkspace
=
_vana_bg_
,
RHSWorkspace
=
_vana_mean_ws_
,
WarnOnZeroDivide
=
True
)
wslist
.
append
(
_coef_ws_
)
wslist
.
append
(
_coef_ws_
)
# 4. correct raw data (not normalized!)
# 4. correct raw data (not normalized!)
api
.
Divide
(
LHSWorkspace
=
data
_
ws
,
RHSWorkspace
=
_coef_ws_
,
WarnOnZeroDivide
=
True
,
api
.
Divide
(
LHSWorkspace
=
self
.
dataws
,
RHSWorkspace
=
_coef_ws_
,
WarnOnZeroDivide
=
True
,
OutputWorkspace
=
outws_name
)
OutputWorkspace
=
self
.
outws_name
)
outws
=
api
.
mtd
[
outws_name
]
outws
=
api
.
mtd
[
self
.
outws_name
]
# cleanup
# cleanup
self
.
_cleanup
(
wslist
)
self
.
_cleanup
(
wslist
)
return
outws
return
outws
...
@@ -199,38 +200,38 @@ class DNSDetEffCorrVana(PythonAlgorithm):
...
@@ -199,38 +200,38 @@ class DNSDetEffCorrVana(PythonAlgorithm):
def
PyExec
(
self
):
def
PyExec
(
self
):
# Input
# Input
dataws
=
api
.
mtd
[
self
.
getPropertyValue
(
"
InputWorkspace
"
)]
self
.
dataws
=
api
.
mtd
[
self
.
getPropertyValue
(
"
InputWorkspace
"
)]
outws_name
=
self
.
getPropertyValue
(
"
OutputWorkspace
"
)
self
.
outws_name
=
self
.
getPropertyValue
(
"
OutputWorkspace
"
)
vanaws
=
api
.
mtd
[
self
.
getPropertyValue
(
"
VanaWorkspace
"
)]
self
.
vanaws
=
api
.
mtd
[
self
.
getPropertyValue
(
"
VanaWorkspace
"
)]
bkgws
=
api
.
mtd
[
self
.
getPropertyValue
(
"
BkgWorkspace
"
)]
self
.
bkgws
=
api
.
mtd
[
self
.
getPropertyValue
(
"
BkgWorkspace
"
)]
vana_mean
=
self
.
getPropertyValue
(
"
VanadiumMean
"
)
self
.
vana_mean
_name
=
self
.
getPropertyValue
(
"
VanadiumMean
"
)
if
not
self
.
_dimensions_valid
(
dataws
,
vanaws
,
bkgws
):
if
not
self
.
_dimensions_valid
():
raise
RuntimeError
(
"
Error: all input workspaces must have the same dimensions!.
"
)
raise
RuntimeError
(
"
Error: all input workspaces must have the same dimensions!.
"
)
# check if the _NORM workspaces exist
# check if the _NORM workspaces exist
if
not
self
.
_norm_ws_exist
(
vanaws
,
bkgws
):
if
not
self
.
_norm_ws_exist
():
message
=
"
Normalization workspace is not found!
"
message
=
"
Normalization workspace is not found!
"
raise
RuntimeError
(
message
)
raise
RuntimeError
(
message
)
# check sample logs, produce warnings if different
# check sample logs, produce warnings if different
drun
=
dataws
.
getRun
()
drun
=
self
.
dataws
.
getRun
()
vrun
=
vanaws
.
getRun
()
vrun
=
self
.
vanaws
.
getRun
()
brun
=
bkgws
.
getRun
()
brun
=
self
.
bkgws
.
getRun
()
self
.
_check_properties
(
drun
,
vrun
)
self
.
_check_properties
(
drun
,
vrun
)
self
.
_check_properties
(
vrun
,
brun
)
self
.
_check_properties
(
vrun
,
brun
)
# apply correction
# apply correction
outws
=
self
.
_vana_correct
(
dataws
,
vanaws
,
bkgws
,
vana_mean
,
outws_name
)
outws
=
self
.
_vana_correct
()
if
not
outws
:
if
not
outws
:
raise
RuntimeError
(
"
Correction failed. Invalid VanadiumMean workspace dimensions.
"
)
raise
RuntimeError
(
"
Correction failed. Invalid VanadiumMean workspace dimensions.
"
)
# copy sample logs from data workspace to the output workspace
# copy sample logs from data workspace to the output workspace
api
.
CopyLogs
(
InputWorkspace
=
dataws
.
getName
(),
OutputWorkspace
=
outws
.
getName
(),
api
.
CopyLogs
(
InputWorkspace
=
self
.
dataws
.
getName
(),
OutputWorkspace
=
outws
.
getName
(),
MergeStrategy
=
'
MergeReplaceExisting
'
)
MergeStrategy
=
'
MergeReplaceExisting
'
)
self
.
setProperty
(
"
OutputWorkspace
"
,
outws
)
self
.
setProperty
(
"
OutputWorkspace
"
,
outws
)
# clone the normalization workspace for data if it exists
# clone the normalization workspace for data if it exists
if
api
.
mtd
.
doesExist
(
dataws
.
getName
()
+
'
_NORM
'
):
if
api
.
mtd
.
doesExist
(
self
.
dataws
.
getName
()
+
'
_NORM
'
):
api
.
CloneWorkspace
(
InputWorkspace
=
dataws
.
getName
()
+
'
_NORM
'
,
OutputWorkspace
=
outws_name
+
'
_NORM
'
)
api
.
CloneWorkspace
(
InputWorkspace
=
self
.
dataws
.
getName
()
+
'
_NORM
'
,
OutputWorkspace
=
self
.
outws_name
+
'
_NORM
'
)
self
.
log
().
debug
(
'
DNSDetEffCorrVana: OK. The result has been saved to
'
+
outws_name
)
self
.
log
().
debug
(
'
DNSDetEffCorrVana: OK. The result has been saved to
'
+
self
.
outws_name
)
return
return
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment