Skip to content

Instantly share code, notes, and snippets.

@j1ah0ng
Created March 14, 2019 17:41
Show Gist options
  • Save j1ah0ng/49a1f0da7f072c3e2ad127920d888bd0 to your computer and use it in GitHub Desktop.
Save j1ah0ng/49a1f0da7f072c3e2ad127920d888bd0 to your computer and use it in GitHub Desktop.
Generates a Riemann of a CSV dataset
import csv
import matplotlib.pyplot as plt
data = csv.reader(open('Lab25.csv'))
runNum = int(input("Enter run number: "))
minX = int(input("Enter x minimum: "))
delt = int(input("Enter x-axis domain: "))
run = runNum
runNum = (runNum - 1) * 3 + 1 # Edit to change the column
# Skip labels
null = next(data)
# Time base
time = 0.0001
# Create a global variable for the final summation
totalC = 0.0
rawData = []
avgData = []
# Yeet the raw data into a List
for row in data:
if len(row[runNum]) < 1:
break
if float(row[runNum]) < 0.001:
rawData.append(0)
continue
rawData.append(float(row[runNum]))
for x in range(len(rawData)):
nums = 0
tempSum = 0.0
for y in range(x-30, x+30):
if ( y < 0 ):
continue
if ( y >= len(rawData) ):
break
nums += 1
tempSum += float(rawData[y])
avgData.append(float(tempSum / nums))
maxX = minX + delt
plt.figure().suptitle("Figure "+str(run)+"b: Rolling Average for Run "+str(run))
plt.xlabel("Time (ten-thousandths of a second)")
plt.ylabel("Current (amperes)")
plt.axis([minX, maxX, 0, 0.014])
plt.plot(avgData)
plt.savefig('meanout'+str(run)+'.png', dpi=300)
plt.figure().suptitle("Figure "+str(run)+"a: Raw Data for Run "+str(run))
plt.xlabel("Time (ten-thousandths of a second)")
plt.ylabel("Current (amperes)")
plt.axis([minX, maxX, 0, 0.014])
plt.plot(rawData)
plt.savefig('rmeanout'+str(run)+'.png', dpi=300)
tSum = 0
for x in avgData:
tSum += x * time
print(tSum)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment