I have a simple csv file like this:
wavelength | exposure |
---|---|
550 | 2 |
560 | 3 |
570 | 10 |
580 | 2 |
590 | 5 |
600 | 6 |
I am trying to do a simple calculation between each item in the wavelength column and then eventually time.sleep for the related exposure time. The if loop for idx==0 seems to work well. But I cannot figure out how to better write the idx > 0: part. The calculation doesn't work well for the second items in the column. I can't figure out how to update the starting wavelength and subract it from the next item in the list. I want it to do 550-631.26 update currentwave to 550 then do 560-550 but in a loop so it automatically does 570-560 and so on
filelist = pd.read_csv(filename)
wavelist=filelist['wavelength']
exposurelist=filelist['exposure']
home = 631.26 #nm
rev = 9000 #steps = 1 nm conversion factor for wavelength to mechanical step, used for serial commands
for idx, wl in enumerate(wavelist):
if idx == 0:
diffwave = float(wl)-home
diffstep = diffwave*rev
diffstep = round(diffstep,0)
diffstep = int(diffstep)
if diffstep > 0:
diffstepstr = str('+' f'{diffstep}' + ' \r')
diffstepbyte = bytes(diffstepstr, 'ascii')
if diffstep <= 0:
diffstepstr = str(f'{diffstep}' + ' \r')
diffstepbyte = bytes(diffstepstr, 'ascii')
print(f"scan controller is moving by {diffstep} steps")
print(f"Moving scan controller {diffwave}nm to {wl}nm")
print(f"Holding for current exposure {exposurelist[idx]} seconds")
print(f"The exposure for {wl}nm was taken")
currentwave = wl
if idx > 0:
diffwave = wl-currentwave
diffstep = diffwave*rev
if diffstep > 0:
diffstepstr = str('+' f'{diffstep}' + ' \r')
diffstepbyte = bytes(diffstepstr, 'ascii')
if diffstep <= 0:
diffstepstr = str(f'{diffstep}' + ' \r')
diffstepbyte = bytes(diffstepstr, 'ascii')
print(f"scan controller is moving by {diffstep} steps")
print(f"Moving scan controller {diffwave}nm to {wl}nm")
print(f"Holding for current exposure {exposurelist[idx]} seconds")
print(f"The exposure for {wl}nm was taken")
if idx < len(wavelist)-1:
currentwave = [idx-1]