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
2a12e684
Commit
2a12e684
authored
Mar 05, 2021
by
Peterson, Peter
Browse files
Expose the geographical angles to python
The result is a read-only tuple. This is meant to simplify work elsewhere.
parent
715cb8fe
Changes
3
Hide whitespace changes
Inline
Side-by-side
Framework/PythonInterface/mantid/api/src/Exports/SpectrumInfo.cpp
View file @
2a12e684
...
...
@@ -14,6 +14,7 @@
#include
<boost/python/copy_const_reference.hpp>
#include
<boost/python/list.hpp>
#include
<boost/python/return_value_policy.hpp>
#include
<boost/python/tuple.hpp>
using
Mantid
::
SpectrumDefinition
;
using
Mantid
::
API
::
SpectrumInfo
;
...
...
@@ -27,6 +28,11 @@ SpectrumInfoPythonIterator make_pyiterator(SpectrumInfo &spectrumInfo) {
return
SpectrumInfoPythonIterator
(
spectrumInfo
);
}
PyObject
*
geographicalAngles
(
SpectrumInfo
&
spectrumInfo
,
const
size_t
index
)
{
const
auto
angles
=
spectrumInfo
.
geographicalAngles
(
index
);
return
incref
(
make_tuple
(
angles
.
first
,
angles
.
second
).
ptr
());
}
// Export SpectrumInfo
void
export_SpectrumInfo
()
{
class_
<
SpectrumInfo
,
boost
::
noncopyable
>
(
"SpectrumInfo"
,
no_init
)
...
...
@@ -55,6 +61,10 @@ void export_SpectrumInfo() {
"Returns the out-of-plane angle in radians angle w.r.t. to "
"vecPointingHorizontal "
"direction."
)
.
def
(
"geographicalAngles"
,
&
geographicalAngles
,
(
arg
(
"self"
),
arg
(
"index"
)),
"Returns the latitude and longitude for given spectrum index. "
"The returned value is a pair of (latitude, longitude)"
)
.
def
(
"l1"
,
&
SpectrumInfo
::
l1
,
arg
(
"self"
),
"Returns the distance from the source to the sample."
)
.
def
(
"l2"
,
&
SpectrumInfo
::
l2
,
(
arg
(
"self"
),
arg
(
"index"
)),
...
...
Framework/PythonInterface/test/python/mantid/api/SpectrumInfoTest.py
View file @
2a12e684
...
...
@@ -45,7 +45,6 @@ class SpectrumInfoTest(unittest.TestCase):
# One detector cleared. So not counted.
self
.
assertEqual
(
info
.
detectorCount
(),
2
)
def
test_isMonitor
(
self
):
""" Check if a monitor is present. """
info
=
self
.
_ws
.
spectrumInfo
()
...
...
@@ -73,6 +72,13 @@ class SpectrumInfoTest(unittest.TestCase):
info
=
self
.
_ws
.
spectrumInfo
()
self
.
assertEqual
(
type
(
info
.
twoTheta
(
1
)),
float
)
def
test_geogAngles
(
self
):
""" See if the returned value is a double (float in Python). """
info
=
self
.
_ws
.
spectrumInfo
()
lat
,
lon
=
info
.
geographicalAngles
(
1
)
self
.
assertEqual
(
type
(
lat
),
float
)
self
.
assertEqual
(
type
(
lon
),
float
)
def
test_signedTwoTheta
(
self
):
""" See if the returned value is a double (float in Python). """
info
=
self
.
_ws
.
spectrumInfo
()
...
...
@@ -127,7 +133,7 @@ class SpectrumInfoTest(unittest.TestCase):
"""
def
test_basic_iteration
(
self
):
info
=
self
.
_ws
.
spectrumInfo
()
expected_iterations
=
len
(
info
)
expected_iterations
=
len
(
info
)
actual_iterations
=
len
(
list
(
iter
(
info
)))
self
.
assertEqual
(
expected_iterations
,
actual_iterations
)
...
...
@@ -138,10 +144,10 @@ class SpectrumInfoTest(unittest.TestCase):
next
(
it
)
# skip first as detectors cleared
for
item
in
it
:
self
.
assertFalse
(
item
.
isMonitor
)
def
test_iterator_for_masked
(
self
):
info
=
self
.
_ws
.
spectrumInfo
()
# nothing should be masked
# nothing should be masked
it
=
iter
(
info
)
next
(
it
)
# skip first as detectors cleared
for
item
in
it
:
...
...
@@ -149,7 +155,7 @@ class SpectrumInfoTest(unittest.TestCase):
def
test_iterator_for_setting_masked
(
self
):
info
=
self
.
_ws
.
spectrumInfo
()
# nothing should be masked
# nothing should be masked
it
=
iter
(
info
)
next
(
it
)
# skip first as detectors cleared
for
item
in
it
:
...
...
@@ -218,7 +224,6 @@ class SpectrumInfoTest(unittest.TestCase):
with
self
.
assertRaises
(
OverflowError
):
info
.
position
(
-
1
)
"""
----------------------------------------------------------------------------
Exceptional Tests
...
...
@@ -316,7 +321,6 @@ class SpectrumInfoTest(unittest.TestCase):
with
self
.
assertRaises
(
TypeError
):
info
.
samplePosition
(
0.0
)
"""
----------------------------------------------------------------------------
SpectrumDefinition Tests
...
...
@@ -365,5 +369,6 @@ class SpectrumInfoTest(unittest.TestCase):
spectrumDefinition
=
info
.
getSpectrumDefinition
(
1
)
self
.
assertEqual
(
spectrumDefinition
[
0
],
(
1
,
0
))
if
__name__
==
'__main__'
:
unittest
.
main
()
docs/source/release/v6.1.0/framework.rst
View file @
2a12e684
...
...
@@ -23,6 +23,7 @@ Algorithms
Data Objects
------------
- exposed ``geographicalAngles`` method on :py:obj:`mantid.api.SpectrumInfo`
- :ref:`Run <mantid.api.Run>` has been modified to allow multiple goniometers to be stored.
Python
...
...
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