Skip to content

Commit

Permalink
added spec.getScanNumbersChronological(), spec.getFirstScanNumber(), and
Browse files Browse the repository at this point in the history
spec.getLastScanNumber()
  • Loading branch information
prjemian committed Feb 2, 2016
1 parent 5d86d00 commit cf50cd9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Change History
Production
**********

:2016.0201.0: added spec.getScanNumbersChronological(), spec.getFirstScanNumber(), and spec.getLastScanNumber()
:2016.0131.0: support new NeXus method for default/signal/axes/_indices,
`issue #43 <https://github.com/prjemian/spec2nexus/issues/43>`_
:2016.0130.0: fixed `issue #44 <https://github.com/prjemian/spec2nexus/issues/44>`_
Expand Down
22 changes: 19 additions & 3 deletions src/spec2nexus/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@
>>> spec_data = spec.SpecDataFile('path/to/my/spec_data.dat')
>>> print spec_data.fileName
path/to/my/spec_data.dat
>>> print 'first scan: ', spec_data.getMinScanNumber()
>>> print 'first scan: ', spec_data.getFirstScanNumber()
1
>>> print 'last scan: ', spec_data.getMaxScanNumber()
>>> print 'last scan: ', spec_data.getLastScanNumber()
22
Get plottable data from scan number 10:
Expand Down Expand Up @@ -117,6 +117,7 @@
import re #@UnusedImport
import os #@UnusedImport
import sys #@UnusedImport
import time
from spec2nexus.utils import get_all_plugins


Expand Down Expand Up @@ -284,11 +285,18 @@ def getScan(self, scan_number=0):
return None

def getScanNumbers(self):
'''return a sorted list of all scan numbers'''
'''return a list of all scan numbers sorted by scan number'''
def my_cmp(x, y):
return cmp(float(x), float(y))
return sorted(self.scans.keys(), my_cmp)

def getScanNumbersChronological(self):
'''return a list of all scan numbers sorted by date'''
def my_cmp(x, y):
return cmp(time.strptime(x.date), time.strptime(y.date))
scans = sorted(self.scans.values(), my_cmp)
return [_.scanNum for _ in scans]

def getMinScanNumber(self):
'''return the lowest numbered scan'''
return self.getScanNumbers()[0]
Expand All @@ -297,6 +305,14 @@ def getMaxScanNumber(self):
'''return the highest numbered scan'''
return self.getScanNumbers()[-1]

def getFirstScanNumber(self):
'''return the first scan'''
return self.getScanNumbersChronological()[0]

def getLastScanNumber(self):
'''return the last scan'''
return self.getScanNumbersChronological()[-1]

def getScanCommands(self, scan_list=None):
'''return all the scan commands as a list, with scan number'''
if scan_list is None:
Expand Down

0 comments on commit cf50cd9

Please sign in to comment.