Ignore:
Timestamp:
11/10/10 14:48:15 (13 years ago)
Author:
Kana Sugimoto
Message:

New Development: No

JIRA Issue: No

Ready for Test: Yes

Interface Changes: Yes

What Interface Changed:
+ An optional parameter 'prec (unsigned int)' is added to

scantable.get_time, python_Scantable::_gettime, ScantableWrapper::getTime and Scantable::getTime.

+ Also Scantable::fromatTime accepts 'prec' as a parameter.
+ scantable._get_column accepts args which will be passed to callback function.

Test Programs:

Put in Release Notes: No

Module(s): scantable

Description:

Add a parameter prec to scantable.get_time which specifies the precision of time returned.
The default value is prec=0.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/scantable.py

    r1938 r1947  
    725725        return outvec
    726726
    727     def _get_column(self, callback, row=-1):
     727    def _get_column(self, callback, row=-1, *args):
    728728        """
    729729        """
    730730        if row == -1:
    731             return [callback(i) for i in range(self.nrow())]
     731            return [callback(i, *args) for i in range(self.nrow())]
    732732        else:
    733733            if  0 <= row < self.nrow():
    734                 return callback(row)
    735 
    736 
    737     def get_time(self, row=-1, asdatetime=False):
     734                return callback(row, *args)
     735
     736
     737    def get_time(self, row=-1, asdatetime=False, prec=0):
    738738        """\
    739739        Get a list of time stamps for the observations.
     
    747747            asdatetime:   return values as datetime objects rather than strings
    748748
    749         """
    750         from time import strptime
     749            prec:         number of digits shown. Note this number is equals to
     750                          the digits of MVTime, i.e., 0<prec<3: dates with hh::
     751                          only, <5: with hh:mm:, <7 or 0: with hh:mm:ss,
     752                          and 6> : with hh:mm:ss.tt... (prec-6 t's added)
     753
     754        """
     755        #from time import strptime
    751756        from datetime import datetime
    752         times = self._get_column(self._gettime, row)
     757        times = self._get_column(self._gettime, row, prec)
    753758        if not asdatetime:
    754759            return times
    755         format = "%Y/%m/%d/%H:%M:%S"
     760        #format = "%Y/%m/%d/%H:%M:%S"
     761        format = "%Y/%m/%d/%H:%M:%S.%f"
     762        if prec < 7:
     763            nsub = 1 + (((6-prec)/2) % 3)
     764            substr = [".%f","%S","%M"]
     765            for i in range(nsub):
     766                format = format.replace(substr[i],"")
    756767        if isinstance(times, list):
    757             return [datetime(*strptime(i, format)[:6]) for i in times]
    758         else:
    759             return datetime(*strptime(times, format)[:6])
     768            #return [datetime(*strptime(i, format)[:6]) for i in times]
     769            return [datetime.strptime(i, format) for i in times]
     770        else:
     771            #return datetime(*strptime(times, format)[:6])
     772            return datetime.strptime(times, format)
    760773
    761774
Note: See TracChangeset for help on using the changeset viewer.