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
f2e33a31
Commit
f2e33a31
authored
12 years ago
by
Anders Markvardsen
Browse files
Options
Downloads
Plain Diff
Merge remote-tracking branch 'origin/feature/6742_maps_d4window'
parents
81ebfb2a
b75be43c
Loading
Loading
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Code/Mantid/scripts/Calibration/Examples/TubeCalibDemoMaps_D4.py
+72
-0
72 additions, 0 deletions
...ntid/scripts/Calibration/Examples/TubeCalibDemoMaps_D4.py
Code/Mantid/scripts/Calibration/tube_spec.py
+34
-16
34 additions, 16 deletions
Code/Mantid/scripts/Calibration/tube_spec.py
with
106 additions
and
16 deletions
Code/Mantid/scripts/Calibration/Examples/TubeCalibDemoMaps_D4.py
0 → 100644
+
72
−
0
View file @
f2e33a31
#
# TUBE CALIBRATION DEMONSTRATION PROGRAM FOR MAPS - Execute this
#
# Here we run the calibration of a selected part of MAPS
#
from
mantid.api
import
WorkspaceFactory
# For table worskspace of calibrations
from
tube_calib_fit_params
import
*
# To handle fit parameters
from
ideal_tube
import
*
# For ideal tube
from
tube_calib
import
*
# For tube calibration functions
from
tube_spec
import
*
# For tube specification class
# == Set parameters for calibration ==
path
=
r
"
C:/Temp/
"
# Path name of folder containing input and output files
filename
=
'
MAPS14919.raw
'
# Name of calibration run
rangeLower
=
2000
# Integrate counts in each spectra from rangeLower to rangeUpper
rangeUpper
=
10000
#
# Set initial parameters for peak finding
ExpectedHeight
=
-
1000.0
# Expected Height of Peaks (initial value of fit parameter)
ExpectedWidth
=
8.0
# Expected width of centre peak (initial value of fit parameter)
ExpectedPositions
=
[
4.0
,
85.0
,
128.0
,
165.0
,
252.0
]
# Expected positions of the edges and peak (initial values of fit parameters)
# Set what we want to calibrate (e.g whole intrument or one door )
CalibratedComponent
=
'
D4_window
'
# Calibrate D4 window
# Get calibration raw file and integrate it
rawCalibInstWS
=
Load
(
path
+
filename
)
#'raw' in 'rawCalibInstWS' means unintegrated.
print
"
Integrating Workspace
"
CalibInstWS
=
Integration
(
rawCalibInstWS
,
RangeLower
=
rangeLower
,
RangeUpper
=
rangeUpper
)
DeleteWorkspace
(
rawCalibInstWS
)
print
"
Created workspace (CalibInstWS) with integrated data from run and instrument to calibrate
"
# == Create Objects needed for calibration ==
#Create Calibration Table
calibrationTable
=
CreateEmptyTableWorkspace
(
OutputWorkspace
=
"
CalibTable
"
)
calibrationTable
.
addColumn
(
type
=
"
int
"
,
name
=
"
Detector ID
"
)
# "Detector ID" column required by ApplyCalbration
calibrationTable
.
addColumn
(
type
=
"
V3D
"
,
name
=
"
Detector Position
"
)
# "Detector Position" column required by ApplyCalbration
# Specify component to calibrate
thisTubeSet
=
TubeSpec
(
CalibInstWS
)
thisTubeSet
.
setTubeSpecByString
(
CalibratedComponent
)
# Get ideal tube
iTube
=
IdealTube
()
# The positions of the shadows and ends here are an intelligent guess.
iTube
.
setPositionsAndForm
([
-
0.65
,
-
0.22
,
-
0.00
,
0.22
,
0.65
],[
2
,
1
,
1
,
1
,
2
])
# Get fitting parameters
fitPar
=
TubeCalibFitParams
(
ExpectedPositions
,
ExpectedHeight
,
ExpectedWidth
)
print
"
Created objects needed for calibration.
"
# == Get the calibration and put results into calibration table ==
# also put peaks into PeakFile
getCalibration
(
CalibInstWS
,
thisTubeSet
,
calibrationTable
,
fitPar
,
iTube
,
PeakFile
=
path
+
'
TubeDemoMaps01.txt
'
)
print
"
Got calibration (new positions of detectors)
"
# == Apply the Calibation ==
ApplyCalibration
(
Workspace
=
CalibInstWS
,
PositionTable
=
calibrationTable
)
print
"
Applied calibration
"
# == Save workspace ==
SaveNexusProcessed
(
CalibInstWS
,
path
+
'
TubeCalibDemoMapsResult.nxs
'
,
"
Result of Running TCDemoMaps.py
"
)
print
"
saved calibrated workspace (CalibInstWS) into Nexus file TubeCalibDemoMapsResult.nxs
"
This diff is collapsed.
Click to expand it.
Code/Mantid/scripts/Calibration/tube_spec.py
+
34
−
16
View file @
f2e33a31
...
@@ -109,7 +109,7 @@ class TubeSpec:
...
@@ -109,7 +109,7 @@ class TubeSpec:
return
self
.
component
return
self
.
component
# We look for the component
# We look for the component
#
print self.specString,
print
"
Looking for
"
,
self
.
specString
,
comp
=
self
.
inst
.
getComponentByName
(
self
.
specString
)
comp
=
self
.
inst
.
getComponentByName
(
self
.
specString
)
...
@@ -126,27 +126,41 @@ class TubeSpec:
...
@@ -126,27 +126,41 @@ class TubeSpec:
@param tubeIx: index of Tube in specified set
@param tubeIx: index of Tube in specified set
@Return value: ID of first detector
and
number of detectors
@Return value: ID of first detector
,
number of detectors
and step between detectors +1 or -1
"""
"""
nTubes
=
self
.
getNumTubes
()
nTubes
=
self
.
getNumTubes
()
if
(
nTubes
<
0
):
if
(
nTubes
<
0
):
print
"
Error in listing tubes
"
print
"
Error in listing tubes
"
return
0
,
0
return
0
,
0
,
1
if
(
tubeIx
<
0
or
tubeIx
>=
nTubes
):
if
(
tubeIx
<
0
or
tubeIx
>=
nTubes
):
print
"
Tube index
"
,
tubeIx
,
"
out of range 0 to
"
,
nTubes
print
"
Tube index
"
,
tubeIx
,
"
out of range 0 to
"
,
nTubes
return
0
,
0
return
0
,
0
,
1
comp
=
self
.
tubes
[
tubeIx
]
comp
=
self
.
tubes
[
tubeIx
]
if
(
comp
!=
0
):
if
(
comp
!=
0
):
firstDet
=
comp
[
0
].
getID
()
firstDet
=
comp
[
0
].
getID
()
numDet
=
comp
.
nelements
()
numDet
=
comp
.
nelements
()
# Allow for reverse numbering of Detectors
lastDet
=
comp
[
numDet
-
1
].
getID
()
if
(
lastDet
<
firstDet
):
step
=
-
1
if
(
firstDet
-
lastDet
+
1
!=
numDet
):
print
"
Detector number range
"
,
firstDet
-
lastDet
+
1
,
"
not equal to number of detectors
"
,
numDet
print
"
Detectors not numbered continuously in this tube. Calibration will fail for this tube.
"
else
:
step
=
1
if
(
lastDet
-
firstDet
+
1
!=
numDet
):
print
"
Detector number range
"
,
lastDet
-
firstDet
+
1
,
"
not equal to number of detectors
"
,
numDet
print
"
Detectors not numbered continuously in this tube. Calibration will fail for this tube.
"
#print "First dectector ", firstDet," Last detector ", firstDet+numDet-1, "Number of detectors ", numDet
#print "First dectector ", firstDet," Last detector ", firstDet+numDet-1, "Number of detectors ", numDet
#print "First dectector ", firstDet," Last detector ", comp[numDet-1].getID()
else
:
else
:
print
self
.
specString
,
tubeIx
,
"
not found
"
print
self
.
specString
,
tubeIx
,
"
not found
"
return
0
,
0
return
0
,
0
,
1
return
firstDet
,
numDet
return
firstDet
,
numDet
,
step
def
getTubeLength
(
self
,
tubeIx
):
def
getTubeLength
(
self
,
tubeIx
):
"""
"""
...
@@ -204,21 +218,21 @@ class TubeSpec:
...
@@ -204,21 +218,21 @@ class TubeSpec:
def
getTubeByString
(
self
,
tubeIx
):
def
getTubeByString
(
self
,
tubeIx
):
"""
"""
Returns list of workspace indices of a tube specified by string (may be set of tubes)
Returns list of workspace indices of a tube set that has been specified by string
It assumes that all the pixels along the tube have consecutive detector IDs and
It assumes that all the pixels along the tube have consecutive detector IDs
the tube runs parallel to the Y-axis.
@param tubeIx: index of Tube in specified set
@param tubeIx: index of Tube in specified set
Return value: list of indices
Return value: list of indices
"""
"""
firstDet
,
numDet
=
self
.
getDetectorInfoFromTube
(
tubeIx
)
firstDet
,
numDet
,
step
=
self
.
getDetectorInfoFromTube
(
tubeIx
)
wkIds
=
[]
wkIds
=
[]
#print " First dectector", firstDet," Last detector", firstDet+numDet-1, "Number of detectors", numDet
#
print " First dectector", firstDet," Last detector", firstDet+numDet-1, "Number of detectors", numDet
#print "Histograms", self.ws.getNumberHistograms()
#
print "Histograms", self.ws.getNumberHistograms()
# First check we have one detector per histogram/workpsaceID/spectrum
# First check we have one detector per histogram/workpsaceID/spectrum
sp
=
self
.
ws
.
getSpectrum
(
10
)
sampleIndex
=
10
sp
=
self
.
ws
.
getSpectrum
(
sampleIndex
)
detids
=
sp
.
getDetectorIDs
()
detids
=
sp
.
getDetectorIDs
()
numDetsPerWkID
=
len
(
detids
)
numDetsPerWkID
=
len
(
detids
)
if
(
numDetsPerWkID
!=
1
):
if
(
numDetsPerWkID
!=
1
):
...
@@ -228,14 +242,18 @@ class TubeSpec:
...
@@ -228,14 +242,18 @@ class TubeSpec:
# Go and get workspace Indices
# Go and get workspace Indices
if
(
self
.
continuousIndicesInTube
):
if
(
self
.
continuousIndicesInTube
):
if
(
step
==
-
1
):
startDet
=
firstDet
-
numDet
+
1
else
:
startDet
=
firstDet
if
(
numDet
>
0
):
if
(
numDet
>
0
):
for
i
in
range
(
0
,
self
.
ws
.
getNumberHistograms
(),
numDet
):
for
i
in
range
(
0
,
self
.
ws
.
getNumberHistograms
(),
numDet
):
deti
=
self
.
ws
.
getDetector
(
i
)
deti
=
self
.
ws
.
getDetector
(
i
)
detID
=
deti
.
getID
()
detID
=
deti
.
getID
()
if
(
detID
>=
firs
tDet
and
detID
<
firs
tDet
+
numDet
):
if
(
detID
>=
star
tDet
and
detID
<
star
tDet
+
numDet
):
iPixel
=
detID
-
firstDet
iPixel
=
detID
-
firstDet
wkIds
=
range
(
i
-
iPixel
,
i
-
iPixel
+
numDet
)
wkIds
=
range
(
i
-
iPixel
,
i
-
iPixel
+
step
*
numDet
,
step
)
#print "Workspace indices",i-iPixel,"to",i-iPixel+numDet-1
#
print "Workspace indices",i-iPixel,"to",i-iPixel+numDet-1
else
:
#We can't assume continuous indices within tube, must loop over all indices (there are many).
else
:
#We can't assume continuous indices within tube, must loop over all indices (there are many).
if
(
numDet
>
0
):
if
(
numDet
>
0
):
...
...
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