Ticket #7208 (closed: fixed)

Opened 7 years ago

Last modified 5 years ago

Add a function to the IEventList interface to extract the event weights

Reported by: Martyn Gigg Owned by: Nick Draper
Priority: major Milestone: Release 2.6
Component: Python Keywords:
Cc: Blocked By:
Blocking: Tester: Peter Peterson

Description (last modified by Nick Draper) (diff)

and add it to the Python interface.

Similarly to how the getTofs method works.

Change History

comment:1 Changed 7 years ago by Nick Draper

  • Status changed from new to accepted
  • Owner set to Nick Draper

comment:2 Changed 7 years ago by Nick Draper

re #7208 Add getWeight and getWeightErrors to eventlist

This is also accessible via Python

el = ws.getEventList(0)
weightList = el.getWeights()

print len(weightList) # should contain the same number of weights as events in the event list
print weightList[0] #first value

Changeset: ae82a054862a4b4be586130b1f423db4f162b95d

Last edited 7 years ago by Nick Draper (previous) (diff)

comment:3 Changed 7 years ago by Nick Draper

Events without weights will always return event weights of 1 and errors of 1. Weighted events will return the weight and weight error values.

comment:4 Changed 7 years ago by Nick Draper

To test:

  1. check the unit tests pass, particularly the eventlist unit tests and python unit tests.
  2. run the following script
    ws=Load("CNCS_7860_event.nxs")
    el=ws.getEventList(37184)
    wl=el.getWeights()
    wel=el.getWeightErrors()
    print "count =",el.getNumberEvents(), "=", len(wl), "=", len(wel)
    print "weight sum =",numpy.sum(wl)
    print "error sum =",numpy.sum(wel)
    cws=CompressEvents(ws)
    cel=cws.getEventList(37184)
    cwl=cel.getWeights()
    cwel=cel.getWeightErrors()
    print "Compressed count =",cel.getNumberEvents(), "=", len(cwl), "=", len(cwel)
    print "Compressed weight sum =",numpy.sum(cwl)
    print "Compressed error sum =",numpy.sum(cwel)
    
  3. you should get these answers
    ws=Load("CNCS_7860_event.nxs")
    el=ws.getEventList(37184)
    wl=el.getWeights()
    wel=el.getWeightErrors()
    print "count =",el.getNumberEvents(), "=", len(wl), "=", len(wel)
    print "weight sum =",numpy.sum(wl)
    print "error sum =",numpy.sum(wel)
    cws=CompressEvents(ws)
    cel=cws.getEventList(37184)
    cwl=cel.getWeights()
    cwel=cel.getWeightErrors()
    print "Compressed count =",cel.getNumberEvents(), "=", len(cwl), "=", len(cwel)
    print "Compressed weight sum =",numpy.sum(cwl)
    print "Compressed error sum =",numpy.sum(cwel)
    

The errors differ due the the processing in CompressEvents that cannot be simply mimicked.

Last edited 7 years ago by Nick Draper (previous) (diff)

comment:5 Changed 7 years ago by Nick Draper

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

comment:6 Changed 7 years ago by Peter Peterson

  • Status changed from verify to verifying
  • Tester set to Peter Peterson

comment:7 Changed 7 years ago by Peter Peterson

  • Status changed from verifying to reopened
  • Resolution fixed deleted

Two reasons to bounce so far:

  • getTofs() no longer works in python
  • The returns should use the numpy helper to convert everything into numpy arrays

comment:8 Changed 7 years ago by Nick Draper

re #7208 wrapped arrays in numpy and fixed getTofs

GetTofs fails due a a line deleted by mistake (I'm suprised it compiled). Wrapped getweight, getweighterrors and getTofs in numpy arrays Added py unit test for getTofs

Changeset: 878792ae547fc2b8b044bdcbbd08f15f92fa8552

comment:9 Changed 7 years ago by Nick Draper

  • Status changed from reopened to accepted

comment:10 Changed 7 years ago by Nick Draper

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

To test:

  1. check the unit tests pass, particularly the eventlist unit tests and python unit tests.
  2. run the following script
    ws=Load("CNCS_7860_event.nxs")
    el=ws.getEventList(37184)
    wl=el.getWeights()
    wel=el.getWeightErrors()
    tofs=el.getTofs()
    print "count =",el.getNumberEvents(), "=", len(wl), "=", len(wel)
    print "weight sum =",numpy.sum(wl)
    print "error sum =",numpy.sum(wel)
    print "tofs sum =",numpy.sum(tofs)
    cws=CompressEvents(ws)
    cel=cws.getEventList(37184)
    cwl=cel.getWeights()
    cwel=cel.getWeightErrors()
    ctofs=cel.getTofs()
    print "Compressed count =",cel.getNumberEvents(), "=", len(cwl), "=", len(cwel)
    print "Compressed weight sum =",numpy.sum(cwl)
    print "Compressed error sum =",numpy.sum(cwel)
    print "Compressed tofs sum =",numpy.sum(ctofs)
    
  3. should give the answers
    count = 175 = 175 = 175
    weight sum = 175.0
    error sum = 175.0
    tofs sum = 9194645.59766
    Compressed count = 155 = 155 = 155
    Compressed weight sum = 175.0
    Compressed error sum = 163.18789493
    Compressed tofs sum = 8143774.69531
    

The errors differ due the the processing in CompressEvents that cannot be simply mimicked.

comment:11 Changed 7 years ago by Peter Peterson

  • Status changed from verify to verifying

comment:12 Changed 7 years ago by Peter Peterson

  • Status changed from verifying to closed

All good now.

comment:13 Changed 7 years ago by Nick Draper

  • Component changed from Mantid to Framework

comment:14 Changed 7 years ago by Nick Draper

  • Component changed from Framework to Python API
  • Description modified (diff)

comment:15 Changed 5 years ago by Stuart Campbell

This ticket has been transferred to github issue 8054

Note: See TracTickets for help on using tickets.