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
21d133fd
Commit
21d133fd
authored
Jun 20, 2012
by
Gigg, Martyn Anthony
Browse files
Add python type for TimeSeriesProperty<int>. Refs #5488
parent
23894fee
Changes
4
Hide whitespace changes
Inline
Side-by-side
Code/Mantid/Framework/Kernel/src/Statistics.cpp
View file @
21d133fd
...
...
@@ -204,14 +204,27 @@ namespace Mantid
return
getNanStatistics
();
}
/// Getting statistics of a boolean array should just give a bunch of NaNs
template
<
>
DLLExport
Statistics
getStatistics
<
bool
>
(
const
vector
<
bool
>&
data
,
const
bool
sorted
)
{
UNUSED_ARG
(
sorted
);
UNUSED_ARG
(
data
);
return
getNanStatistics
();
}
// -------------------------- concrete instantiations
template
DLLExport
Statistics
getStatistics
<
double
>
(
const
vector
<
double
>
&
,
const
bool
);
template
DLLExport
Statistics
getStatistics
<
int32_t
>
(
const
vector
<
int32_t
>
&
,
const
bool
);
template
DLLExport
Statistics
getStatistics
<
int64_t
>
(
const
vector
<
int64_t
>
&
,
const
bool
);
template
DLLExport
std
::
vector
<
double
>
getZscore
<
double
>
(
const
vector
<
double
>
&
,
const
bool
);
template
DLLExport
std
::
vector
<
double
>
getZscore
<
int32_t
>
(
const
vector
<
int32_t
>
&
,
const
bool
);
template
DLLExport
std
::
vector
<
double
>
getZscore
<
int64_t
>
(
const
vector
<
int64_t
>
&
,
const
bool
);
template
DLLExport
std
::
vector
<
double
>
getModifiedZscore
<
double
>
(
const
vector
<
double
>
&
,
const
bool
);
template
DLLExport
std
::
vector
<
double
>
getModifiedZscore
<
int32_t
>
(
const
vector
<
int32_t
>
&
,
const
bool
);
template
DLLExport
std
::
vector
<
double
>
getModifiedZscore
<
int64_t
>
(
const
vector
<
int64_t
>
&
,
const
bool
);
}
// namespace Kernel
}
// namespace Mantid
Code/Mantid/Framework/PythonAPI/src/kernel_exports.cpp
View file @
21d133fd
...
...
@@ -200,6 +200,42 @@ namespace PythonAPI
.
def
(
"nthTime"
,
&
TimeSeriesProperty
<
double
>::
nthTime
)
;
register_ptr_to_python
<
TimeSeriesProperty
<
int32_t
>*>
();
register_ptr_to_python
<
const
TimeSeriesProperty
<
int32_t
>*>
();
class_
<
Mantid
::
Kernel
::
TimeSeriesProperty
<
int32_t
>
,
\
bases
<
Mantid
::
Kernel
::
Property
>
,
boost
::
noncopyable
>
(
"TimeSeriesProperty_int32_t"
,
no_init
)
.
def
(
"getStatistics"
,
&
Mantid
::
Kernel
::
TimeSeriesProperty
<
int32_t
>::
getStatistics
)
.
add_property
(
"value"
,
&
Mantid
::
Kernel
::
TimeSeriesProperty
<
int32_t
>::
valuesAsVector
)
.
add_property
(
"times"
,
&
Mantid
::
Kernel
::
TimeSeriesProperty
<
int32_t
>::
timesAsVector
)
.
def
(
"valueAsString"
,
&
TimeSeriesProperty
<
int32_t
>::
value
)
.
def
(
"size"
,
&
TimeSeriesProperty
<
int32_t
>::
size
)
.
def
(
"firstTime"
,
&
TimeSeriesProperty
<
int32_t
>::
firstTime
)
.
def
(
"firstValue"
,
&
TimeSeriesProperty
<
int32_t
>::
firstValue
)
.
def
(
"lastTime"
,
&
TimeSeriesProperty
<
int32_t
>::
lastTime
)
.
def
(
"lastValue"
,
&
TimeSeriesProperty
<
int32_t
>::
lastValue
)
.
def
(
"nthValue"
,
&
TimeSeriesProperty
<
int32_t
>::
nthValue
)
.
def
(
"nthTime"
,
&
TimeSeriesProperty
<
int32_t
>::
nthTime
)
;
register_ptr_to_python
<
TimeSeriesProperty
<
int64_t
>*>
();
register_ptr_to_python
<
const
TimeSeriesProperty
<
int64_t
>*>
();
class_
<
Mantid
::
Kernel
::
TimeSeriesProperty
<
int64_t
>
,
\
bases
<
Mantid
::
Kernel
::
Property
>
,
boost
::
noncopyable
>
(
"TimeSeriesProperty_int64_t"
,
no_init
)
.
def
(
"getStatistics"
,
&
Mantid
::
Kernel
::
TimeSeriesProperty
<
int64_t
>::
getStatistics
)
.
add_property
(
"value"
,
&
Mantid
::
Kernel
::
TimeSeriesProperty
<
int64_t
>::
valuesAsVector
)
.
add_property
(
"times"
,
&
Mantid
::
Kernel
::
TimeSeriesProperty
<
int64_t
>::
timesAsVector
)
.
def
(
"valueAsString"
,
&
TimeSeriesProperty
<
int64_t
>::
value
)
.
def
(
"size"
,
&
TimeSeriesProperty
<
int64_t
>::
size
)
.
def
(
"firstTime"
,
&
TimeSeriesProperty
<
int64_t
>::
firstTime
)
.
def
(
"firstValue"
,
&
TimeSeriesProperty
<
int64_t
>::
firstValue
)
.
def
(
"lastTime"
,
&
TimeSeriesProperty
<
int64_t
>::
lastTime
)
.
def
(
"lastValue"
,
&
TimeSeriesProperty
<
int64_t
>::
lastValue
)
.
def
(
"nthValue"
,
&
TimeSeriesProperty
<
int64_t
>::
nthValue
)
.
def
(
"nthTime"
,
&
TimeSeriesProperty
<
int64_t
>::
nthTime
)
;
class_
<
time_duration
>
(
"time_duration"
,
no_init
)
.
def
(
"hours"
,
&
time_duration
::
hours
,
"Returns the normalized number of hours"
)
.
def
(
"minutes"
,
&
time_duration
::
minutes
,
"Returns the normalized number of minutes +/-(0..59)"
)
...
...
Code/Mantid/Framework/PythonInterface/mantid/kernel/src/Exports/TimeSeriesProperty.cpp
View file @
21d133fd
...
...
@@ -12,9 +12,9 @@ namespace
/// Defines the getStatistics member for various types
#define DEF_GET_STATS(TYPE) DEF_GET_STATS_##TYPE
/// Doubles have a get stats member
#define DEF_GET_STATS_double
.def("getStatistics", &TimeSeriesProperty<double>::getStatistics)
#define DEF_GET_STATS_double
/// booleans do not have a get stats member
#define DEF_GET_STATS_bool
#define DEF_GET_STATS_bool
/// Macro to reduce copy-and-paste
#define EXPORT_TIMESERIES_PROP(TYPE, Prefix)\
...
...
@@ -33,7 +33,7 @@ namespace
.def("lastValue", &TimeSeriesProperty<TYPE>::lastValue) \
.def("nthValue", &TimeSeriesProperty<TYPE>::nthValue) \
.def("nthTime", &TimeSeriesProperty<TYPE>::nthTime) \
DEF_GET_STATS(TYPE
) \
.def("getStatistics", &TimeSeriesProperty<double>::getStatistics
) \
;
;
}
...
...
@@ -48,6 +48,22 @@ void export_TimeSeriesProperty_Bool()
EXPORT_TIMESERIES_PROP
(
bool
,
Bool
);
}
void
export_TimeSeriesProperty_Int32
()
{
EXPORT_TIMESERIES_PROP
(
int32_t
,
Int32
);
}
void
export_TimeSeriesProperty_Int64
()
{
EXPORT_TIMESERIES_PROP
(
int64_t
,
Int64
);
}
void
export_TimeSeriesProperty_String
()
{
EXPORT_TIMESERIES_PROP
(
std
::
string
,
String
);
}
void
export_TimeSeriesPropertyStatistics
()
{
class_
<
Mantid
::
Kernel
::
TimeSeriesPropertyStatistics
>
(
"TimeSeriesPropertyStatistics"
,
no_init
)
...
...
Code/Mantid/Framework/PythonInterface/test/python/TimeSeriesPropertyTest.py
View file @
21d133fd
...
...
@@ -3,13 +3,36 @@ from testhelpers import run_algorithm
class
TimeSeriesPropertyTest
(
unittest
.
TestCase
):
def
test_time_series_can_be_extracted
(
self
):
alg
=
run_algorithm
(
"Load"
,
Filename
=
"CNCS_7860_event.nxs"
,
child
=
True
)
ws
=
alg
.
getProperty
(
"OutputWorkspace"
).
value
log_series
=
ws
.
getRun
()[
"Phase1"
]
self
.
assertTrue
(
hasattr
(
log_series
,
"value"
))
self
.
assertTrue
(
hasattr
(
log_series
,
"times"
))
self
.
assertTrue
(
hasattr
(
log_series
,
"getStatistics"
))
_test_ws
=
None
def
setUp
(
self
):
if
self
.
_test_ws
is
None
:
alg
=
run_algorithm
(
"Load"
,
Filename
=
"LOQ49886.nxs"
,
child
=
True
)
self
.
__class__
.
_test_ws
=
alg
.
getProperty
(
"OutputWorkspace"
).
value
def
test_time_series_double_can_be_extracted
(
self
):
log_series
=
self
.
_test_ws
.
getRun
()[
"TEMP1"
]
self
.
_check_has_time_series_attributes
(
log_series
)
self
.
assertEquals
(
log_series
.
size
(),
63
)
self
.
assertAlmostEqual
(
log_series
.
nthValue
(
0
),
-
0.00161
)
def
test_time_series_int_can_be_extracted
(
self
):
log_series
=
self
.
_test_ws
.
getRun
()[
"raw_frames"
]
self
.
_check_has_time_series_attributes
(
log_series
)
self
.
assertEquals
(
log_series
.
size
(),
172
)
self
.
assertEquals
(
log_series
.
nthValue
(
0
),
17
)
def
test_time_series_string_can_be_extracted
(
self
):
log_series
=
self
.
_test_ws
.
getRun
()[
"icp_event"
]
self
.
_check_has_time_series_attributes
(
log_series
)
self
.
assertEquals
(
log_series
.
size
(),
11
)
self
.
assertEquals
(
log_series
.
nthValue
(
0
).
strip
(),
'CHANGE_PERIOD 1'
)
def
_check_has_time_series_attributes
(
self
,
log
):
self
.
assertTrue
(
hasattr
(
log
,
"value"
))
self
.
assertTrue
(
hasattr
(
log
,
"times"
))
self
.
assertTrue
(
hasattr
(
log
,
"getStatistics"
))
if
__name__
==
'__main__'
:
unittest
.
main
()
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