Beispiel #1
0
    def __init__(self, path, data_col=1, debug=False):
        """
        data_col option gives the option to choose the data column
        from csv data file if more than one oscilloscope channel is used.
        Defaults to prior behaviour (i.e. chooses first data column), 
        but this can be changed by calling like so:
        DPO2000_csv('/foo/bar/filename.csv', data_col=2)
        """
        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 != 16:
                print("\t*** Warning, Data stream is thought to start at row index" + \
                        str(self.data_start) + ", instead of the expected 15.")

        self.data_col = data_col
        # File headers should be understood by drv_csv already
        metainfo = self.get_meta_col(self.data_col)

        # Convert the ASCII representation into numbers
        Pformat = []
        Pformat.append('Horizontal Scale')
        Pformat.append('Vertical Scale')
        Pformat.append('Sample Interval')
        Pformat.append('Record Length')
        Pformat.append('Filter Frequency')
        Pformat.append('Vertical Offset')
        Pformat.append('Probe Attenuation')
        csv_file.update_metainfo(self, Pformat, float)

        # Although some of the numbers are saved in float representation they really
        # ought 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
Beispiel #2
0
    def __init__(self, path, data_col=1, debug=False):
        """
        data_col option gives the option to choose the data column
        from csv data file if more than one oscilloscope channel is used.
        Defaults to prior behaviour (i.e. chooses first data column), 
        but this can be changed by calling like so:
        DPO2000_csv('/foo/bar/filename.csv', data_col=2)
        """
        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 != 16:
                print("\t*** Warning, Data stream is thought to start at row index" + \
                        str(self.data_start) + ", instead of the expected 15.")

        self.data_col = data_col
        # File headers should be understood by drv_csv already
        metainfo = self.get_meta_col(self.data_col)

        # Convert the ASCII representation into numbers
        Pformat = []
        Pformat.append('Horizontal Scale')
        Pformat.append('Vertical Scale')
        Pformat.append('Sample Interval')
        Pformat.append('Record Length')
        Pformat.append('Filter Frequency')
        Pformat.append('Vertical Offset')
        Pformat.append('Probe Attenuation')
        csv_file.update_metainfo(self, Pformat, float)

        # Although some of the numbers are saved in float representation they really
        # ought 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
Beispiel #3
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
        Pformat = []
        Pformat.append('Horizontal Scale')
        Pformat.append('Vertical Scale')
        Pformat.append('Sample Interval')
        Pformat.append('Record Length')
        Pformat.append('Trigger Point')
        Pformat.append('Yzero')
        Pformat.append('Vertical Offset')
        Pformat.append('Probe Atten')
        csv_file.update_metainfo(self, Pformat, float)

        # Although some of the numbers are saved in float representation they really
        # ought 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
Beispiel #4
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
        Pformat = []
        Pformat.append('Horizontal Scale')
        Pformat.append('Vertical Scale')
        Pformat.append('Sample Interval')
        Pformat.append('Record Length')
        Pformat.append('Trigger Point')
        Pformat.append('Yzero')
        Pformat.append('Vertical Offset')
        Pformat.append('Probe Atten')
        csv_file.update_metainfo(self, Pformat, float)

        # Although some of the numbers are saved in float representation they really
        # ought 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