Ticket #2036 (closed: fixed)

Opened 10 years ago

Last modified 5 years ago

Add attributes to the Run object from python

Reported by: Peter Peterson Owned by: Peter Peterson
Priority: minor Milestone: Iteration 26
Component: Mantid Keywords:
Cc: Blocked By:
Blocking: Tester: Janik Zikovsky

Description

Since #1878 needs more help, expose adding properties to the Run object in python.

Change History

comment:1 Changed 10 years ago by Peter Peterson

  • Owner set to Peter Peterson
  • Status changed from new to accepted

comment:2 Changed 10 years ago by Peter Peterson

  • Status changed from accepted to verify
  • Resolution set to fixed

(In [7929]) Exposing setter for Run object to python. Fixes #2036.

comment:3 Changed 10 years ago by Michael Whitty

  • Status changed from verify to verifying
  • Tester set to Michael Whitty

comment:4 Changed 10 years ago by Michael Whitty

  • Status changed from verifying to reopened
  • Resolution fixed deleted

The setitem ([]) method appears to work.

However, can't then call getitem on the new element as we can on previous ones.

The below script illustrates this:

LoadRaw('C:\MANTID\Test\Data\irs21360.raw', 'irs21360')
run = mtd['irs21360'].getRun()

# Set new value
run['Testing'] = 1.234

# Show we can get already-set values
print run["run_number"].value

# Show the value is actually on the object
prop = run.getProperty('Testing')
print prop.name
print prop.value

# This line will raise a KeyError
print run['Testing']

comment:5 Changed 10 years ago by Peter Peterson

  • Status changed from reopened to accepted

comment:6 Changed 10 years ago by Peter Peterson

  • Status changed from accepted to verify
  • Resolution set to fixed

(In [8148]) Mutating the run object correcly. Fixes #2036.

comment:7 Changed 10 years ago by Janik Zikovsky

  • Status changed from verify to verifying
  • Tester changed from Michael Whitty to Janik Zikovsky

comment:8 Changed 10 years ago by Janik Zikovsky

  • Status changed from verifying to reopened
  • Resolution fixed deleted

I get an error when accessing a TimeSeriesProperty. Weirdly, the error keeps popping up no matter what I type afterwards. This is from the script interpreter (pg3 is from PG3_1879_event.nxs) :

>> ws = mtd["pg3"]
>> r = ws.getRun()
>> print r["run_number"].value
1879
>> pc = r["proton_charge"]
Traceback (most recent call last):
  File "<string>", line 44, in _ScopeInspector_GetFunctionAttributes
TypeError: No to_python (by-value) converter found for C++ type: std::vector<Mantid::Kernel::DateAndTime, std::allocator<Mantid::Kernel::DateAndTime> >
>> a = 1.2
Traceback (most recent call last):
  File "<string>", line 44, in _ScopeInspector_GetFunctionAttributes
TypeError: No to_python (by-value) converter found for C++ type: std::vector<Mantid::Kernel::DateAndTime, std::allocator<Mantid::Kernel::DateAndTime> >
>> anything_I_type = 123
Traceback (most recent call last):
  File "<string>", line 44, in _ScopeInspector_GetFunctionAttributes
TypeError: No to_python (by-value) converter found for C++ type: std::vector<Mantid::Kernel::DateAndTime, std::allocator<Mantid::Kernel::DateAndTime> >

comment:9 Changed 10 years ago by Peter Peterson

  • Status changed from reopened to accepted

comment:10 Changed 10 years ago by Peter Peterson

  • Status changed from accepted to verify
  • Resolution set to fixed

The problem exists only from the mantidplot python window and is better described in #2080. That is being left for the next release.

comment:11 Changed 10 years ago by Janik Zikovsky

  • Status changed from verify to verifying

comment:12 Changed 10 years ago by Janik Zikovsky

  • Status changed from verifying to closed

Confirmed working well in command-line python.

comment:13 Changed 5 years ago by Stuart Campbell

This ticket has been transferred to github issue 2883

Note: See TracTickets for help on using tickets.