Ticket #1890 (closed: fixed)
Properties should return native types in python
Reported by: | Peter Peterson | Owned by: | Peter Peterson |
---|---|---|---|
Priority: | major | Milestone: | Iteration 27 |
Component: | Mantid | Keywords: | |
Cc: | Blocked By: | ||
Blocking: | Tester: | Martyn Gigg |
Description
It appears that all of the properties return a string for their value in python. This can be closed when
print type(RunProxy['gd_prtn_chrg']) <type 'float'>
Change History
comment:1 Changed 10 years ago by Peter Peterson
- Status changed from new to accepted
- Owner set to Peter Peterson
comment:2 Changed 10 years ago by Peter Peterson
A note from Martyn on this
Since Python can only cast to types it knows about, TimeSeriesProperty will need exporting to Python as well. You're correct in that this should happen in kernel_exports.cpp. The export will be along the lines of class_<TimeSeriesProperty<double>, bases<Property>,boost::noncopyable>('TimeSeriesProperty_dbl', no_init) .def( .. and the rest ) The biggest annoyance with things like TimeSeriesProperty is that it is templated and Python needs to export an actual type meaning that there would need to be an export for each templated type. What I've done in the past is define a macro for the export string so that I can easily define each type without too much hassle. If you have a look at the validator stuff below you'll see what I mean. It's a bit annoying I know but I haven't found a good way of dealing with templates/Python. For the numpy stuff, the routines are in MantidVecHelper.cpp. They are currently set up to build a numpy array from a MantidVec.
comment:8 Changed 10 years ago by Peter Peterson
- Status changed from accepted to verify
- Resolution set to fixed
comment:9 Changed 10 years ago by Martyn Gigg
(In [7447]) A minor tidy up after changes to properties for run objects so that the algorithm ones are consistent. This required access to getPointerToProperty on PropertyManager which Python couldn't get at through the TypedValue version. Now the properties from the run object and algorithm should behave in the same manner though. Re #1890
comment:10 Changed 10 years ago by Janik Zikovsky
- Status changed from verify to verifying
- Tester set to Janik Zikovsky
comment:11 Changed 10 years ago by Janik Zikovsky
- Status changed from verifying to reopened
- Resolution fixed deleted
Doubles and strings work, but it doesn't look to me like the TimeSeriesProperty goes all the way:
a=LoadSNSEventNexus(Filename="/home/8oz/data/PG3_1879_event.nxs", OutputWorkspace="PG3_1879") a=a.workspace() In [42]: b = a.getRun() In [43]: chrg = b["gd_prtn_chrg"] In [44]: print type(chrg.value) <type 'float'> In [45]: c = b["proton_charge"] In [46]: print type(c.value) <class 'libMantidPythonAPI.cpp_list_dbl'>
c.value can be iterated, but it would be best if it returned a native Python list...
comment:12 Changed 10 years ago by Nick Draper
- Milestone changed from Iteration 26 to Iteration 27
Bulk move of tickets to iteration 27, if your ticket is essential for Iteration 26 then move it back.
comment:14 Changed 10 years ago by Peter Peterson
- Status changed from accepted to verify
- Resolution set to fixed
This ticket was closed during Iteration 26 with a small amount of work left over in #2080.
comment:15 Changed 10 years ago by Martyn Gigg
- Status changed from verify to verifying
- Tester changed from Janik Zikovsky to Martyn Gigg
comment:16 Changed 10 years ago by Martyn Gigg
- Status changed from verifying to closed
Verified this along with ticket #2080 as they both related to the same issue.
Strings, doubles, ints and time series properties now appear as native python types.
comment:17 Changed 5 years ago by Stuart Campbell
This ticket has been transferred to github issue 2737