Ticket #8300 (closed: fixed)

Opened 7 years ago

Last modified 5 years ago

Filtering Logs between times

Reported by: Owen Arnold Owned by: Owen Arnold
Priority: critical Milestone: Release 3.1
Component: Diffraction Keywords:
Cc: Blocked By:
Blocking: Tester: Wenduo Zhou

Description (last modified by Owen Arnold) (diff)

This is currently not possible for the end user. The following should provide the basis of an algorithm that would do it for us. In addition, It should be possible to:

  • Choose to filter keep only the selected interval
  • Choose to apply mean, median, max ... functions to the output.

Attachments

Filtering.py (689 bytes) - added by Owen Arnold 7 years ago.

Change History

Changed 7 years ago by Owen Arnold

comment:1 Changed 7 years ago by Owen Arnold

Updated Filtering example. Much better than previously attached example.

from mantid.kernel import DateAndTime
mtd.importAll()
ws = WISH00026110

def meanWithinRange(logname, starttime=None, endtime=None, operation="mean", inside = True):
        run = ws.getRun()
        tstart = run.startTime()
        tend = run.endTime()
        if starttime:
                tstart = tstart + (starttime * int(1e9))
        if  endtime:
                tend = run.startTime() + (endtime * int(1e9))
        temperature = run.getLogData(logname)
        times = numpy.array(temperature.times)
        values = numpy.array(temperature.value)
        if inside:
                mask = (tstart < times) & (times < tend) # Get times between filter start and end.
        else:
                mask = (tstart > times) | (times > tend)
        method = getattr(numpy, operation)
        return method(values[mask])
        

''' Gets mean from logs from start of run till end of run. '''
logname = 'Sample_Temp'
print meanWithinRange(logname)

''' Gets mean from logs from specified start till end of run. '''
starttime =  -10000 # seconds since the start of the run. Also accepts negative values
endtime = None # Defaults to the end of the run.
logname = 'Sample_Temp'
print meanWithinRange(logname, starttime=starttime, endtime=endtime, operation="max", inside=False)

comment:2 Changed 7 years ago by Owen Arnold

  • Status changed from new to inprogress

refs #8300. Filtering algorithm made.

Changeset: f2608d03a389004bc80997569d73ec6e559ef7e7

comment:3 Changed 7 years ago by Owen Arnold

refs #8300. Add Start and End time filtering.

Unit tested too.

Changeset: b95d71755442b815010fa526d3df4c806d11b891

comment:4 Changed 7 years ago by Owen Arnold

refs #8300. Add statistical methods.

Changeset: f0a699bf01ea3a9ca3a5f6a79ce39a3636f4844c

comment:5 Changed 7 years ago by Owen Arnold

refs #8300. Add wiki documentation.

Changeset: b51084e88e51889fe5ae47100ce44c4f505b87a2

comment:6 Changed 7 years ago by Owen Arnold

  • Description modified (diff)

comment:7 Changed 7 years ago by Owen Arnold

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

Tester. The unit tests show this working. You should however do the following.

  • Load ARGUS0026287 out of the AutoTest dir
  • Open MantidPlot and use the algorithm FilterLogByTime
  • Use the temperature-2-log in association with the algorithm documentation to apply filtering according to this algorithm.
Last edited 7 years ago by Owen Arnold (previous) (diff)

comment:8 Changed 7 years ago by Owen Arnold

  • Milestone changed from Backlog to Release 3.1

comment:9 Changed 7 years ago by Gesner Passos

  • Status changed from verify to verifying
  • Tester set to Gesner Passos

comment:10 Changed 7 years ago by Gesner Passos

  • Status changed from verifying to reopened
  • Resolution fixed deleted

This script pass if you uncomment the second line. But, fail as it is.

f, log = '/apps/mantid/systemtests/Data/SANS2D/SANS2D00005547.raw', 'temp2'
#f, log = '/apps/mantid/mantid/Test/AutoTestData/argus0026287.nxs', 'temperature_2_log'

ws = Load(Filename=f)

if isinstance(ws, tuple):
   ws = ws[0]
   
tempfilter,  stat = FilterLogByTime(ws, log )

temps = ws.getRun().getLogData(log).value
print type(temps)
print len(tempfilter)
print len(temps)
assert(len(tempfilter) == len(temps))

Besides, it is worth pointing out in the documentation that it works only for float numeric series.

comment:11 Changed 7 years ago by Owen Arnold

  • Status changed from reopened to inprogress

refs #8300. Make more robust about log type.

Changeset: 0eac2fe5c8146ccd07b412cebf5fa861cb71a177

comment:12 Changed 7 years ago by Owen Arnold

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

There actually isn't a problem here. The reason that the script above fails is because the run endTime is prior to the last collected log value. Note that if you do not specify StartTime or EndTime the algorithm takes these to be the startTime of the run and the endTime of the run respectively. That is why a single log value is being chopped off the end.

comment:13 Changed 7 years ago by Wenduo Zhou

  • Status changed from verify to verifying
  • Tester changed from Gesner Passos to Wenduo Zhou

comment:14 Changed 7 years ago by Wenduo Zhou

  • Status changed from verifying to reopened
  • Resolution fixed deleted

The algorithm works. But there should be more introduction on 'Method', especially the math on 'mean', 'median', 'mode' and etc.

comment:15 Changed 7 years ago by Owen Arnold

  • Status changed from reopened to inprogress

refs #8300 Documentation for Method property

Changeset: f08b4c237f6b62411518e1ebaafb907eb781e054

comment:16 Changed 7 years ago by Owen Arnold

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

comment:17 Changed 7 years ago by Wenduo Zhou

  • Status changed from verify to verifying

comment:18 Changed 7 years ago by Wenduo Zhou

  • Status changed from verifying to closed

Merge remote-tracking branch 'origin/feature/8300_filter_time'

Full changeset: 6ddc8b9d349b3dce41a8c1630e3a46c31675e169

comment:19 Changed 5 years ago by Stuart Campbell

This ticket has been transferred to github issue 9145

Note: See TracTickets for help on using tickets.