BigThonkers / ThonkTools

Revolutionary wrappers for stupid lab stuff.
1 stars 3 forks source link

Digit Error Function #11

Open munnich opened 5 years ago

munnich commented 5 years ago

This should work by reading the CSV file as a string and finding the last value of it, which can determine the final digit.

munnich commented 5 years ago

A function that does exactly the above. Only a digit error of 1 is currently implemented.

def digit_error(fname, offset=0):
    import numpy as np
    with open(fname, 'r') as myfile:
        data = myfile.read().replace(',', '.').replace('\n', ',').replace('  ', ',').replace("\t", ",")
    datarray = data.split(',')
    output = []
    for item in datarray:
        if item != '':
            output.append((item))
    internal = []
    item: str
    for item in output[offset:]:
        if '.' not in item:
            internal.append(1)
            continue
        num_parts = item.split('.')
        internal.append(float('0.' + '0' * (len(num_parts[1]) - 1) + '1'))
    output = np.array(internal)
    x = output[0::2]
    y = output[1::2]
    return [x, y]