Пример #1
0
 def __init__(self, path, debug = False):
     
     csv_file.__init__(self, path = path, debug = debug, analyse = True, \
                         field_delimiter = ',', text_delimiter = '')
     
     if debug:
         if self.cols != 2:
             print "\t*** Warning, the file does not contain exactly 2 data \
                     columns, it may not be a valid DPO2000 csv file."
         
         model = self.getrow(0)[:2]
         if (model[0] != 'Model') or (model[1][:4] != 'DPO2'):
             print "\t*** Warning, row 0 of the file does not match the \
                     expected model number description." + linesep + \
                     "\tExpecting 'Model':'DPO2', got '" + \
                     model[0] + "':'" + model[1][:4] + "' instead."
         
         if self.data_start != 15:
             print "\t*** Warning, Data stream is thought to start at row index" + \
                     str(self.data_start) + ", instead of the expected 15."
     
     # File headers should be understood by drv_csv already
     metainfo = self.metainfo
     
     # Convert the ASCII representation into numbers
     format = []
     format.append('Horizontal Scale')
     format.append('Vertical Scale') 
     format.append('Sample Interval')
     format.append('Record Length')
     format.append('Filter Frequency')
     format.append('Vertical Offset')
     format.append('Probe Attenuation')
     csv_file.update_metainfo(self, format, float)
         
     # Although some of the numbers are saved in float representation they really
     # ough to be int instead.
     #
     # Converting a float ASCII repr directly will caused an error.
     #    >>> int('2.500000e+03')
     #    Traceback (most recent call last):
     #      File "<stdin>", line 1, in ?
     #    ValueError: invalid literal for int(): 2.500000e+03
     #
     # Have to convert to float first:
     #   >>> int(float('2.500000e+03'))
     #   2500
     #
     format_cust = []
     format_cust.append('Record Length')
     format_cust.append('Probe Attenuation')
     csv_file.update_metainfo(self, format_cust, int)
     
     if debug:
         if metainfo['Record Length'] != self.rows - self.data_start:
             print "\t*** Warning, Record Length description (" + str(metainfo['Record Length']) \
                     + ") do not match the number of rows counted (" + str(self.rows - self.data_start) \
                     + ") in this file. This file maybe corrupted"
     
     self.metainfo = metainfo
     return
Пример #2
0
 def __init__(self, path, debug = False):
     
     csv_file.__init__(self, path = path, debug = debug, analyse = False, \
                         field_delimiter = ',', text_delimiter = '')
     
     if debug:
         if self.cols != 6:
             print "\t*** Warning, the file does not contain exactly 6 data \
                     columns, it may not be a valid TDS2000 csv file."
         
         model = self.getrow(15)[:2]
         if (model[0] != 'Model Number') or (model[1][:4] != 'TDS2'):
             print "\t*** Warning, row 15 of the file does not match the \
                     expected model number description." + linesep + \
                     "\tExpecting 'Model':'DPO2', got '" + \
                     model[0] + "':'" + model[1][:4] + "' instead."
             
     # Create the metainfo
     metainfo = {}
     info_pair = zip(self.getcolumn(0), self.getcolumn(1))
     
     info_pair.sort(key=itemgetter(0))
     for field, value in groupby(info_pair, key=itemgetter(0)):
         val = map(itemgetter(1), value)[0]
         if field is '':
             if val is '':
                 # Blank lines
                 continue
             # Orphan values
             metainfo['Unknown'] = val
         metainfo[field] = val
     
     # Update the object's metainfo
     self.metainfo.update(metainfo)
     
     # Convert the ASCII representation into numbers
     format = []
     format.append('Horizontal Scale')
     format.append('Vertical Scale') 
     format.append('Sample Interval')
     format.append('Record Length')
     format.append('Trigger Point')
     format.append('Yzero')
     format.append('Vertical Offset')
     format.append('Probe Atten')
     csv_file.update_metainfo(self, format, float)
     
     # Although some of the numbers are saved in float representation they really
     # ough to be int instead.
     #
     # Converting a float ASCII repr directly will caused an error.
     #    >>> int('2.500000e+03')
     #    Traceback (most recent call last):
     #      File "<stdin>", line 1, in ?
     #    ValueError: invalid literal for int(): 2.500000e+03
     #
     # Have to convert to float first:
     #   >>> int(float('2.500000e+03'))
     #   2500
     #
     format_cust = []
     format_cust.append('Record Length')
     format_cust.append('Trigger Point')
     csv_file.update_metainfo(self, format_cust, int)
     
     if debug:
         if self.metainfo['Record Length'] != self.rows:
             print "\t*** Warning, Record Length description (" + str(self.metainfo['Record Length']) \
                     + ") do not match the number of rows counted (" + str(self.rows) \
                     + ") in this file. This file maybe corrupted"
     
     return