# -*- coding: utf-8 -*-
"""
Created on Tue May 19 09:13:12 2015

@author: weber
"""
import numpy as np
import matplotlib.pyplot as plt
from pressure_traces import smoothing, compress, pressure_to_volume, pressure_to_temperature, volume_to_pressure, filename_parse, copy, pressure_fit

nonrfile = 'NR_00_in_00_mm_311K-1115t-40x-15-May-15-1425.txt'
reacfile = '00_in_00_mm_311K-1118t-40x-15-May-15-1301.txt'
nonrdata = np.fromfile(nonrfile, sep=' ')
nonrdata = np.reshape(nonrdata, (len(nonrdata)/2, 2))
_, _, _, npin, nfactor, _ = filename_parse(nonrfile)
reacdata = np.fromfile(reacfile, sep=' ')
reacdata = np.reshape(reacdata, (len(reacdata)/2, 2))
_, _, reacTin, rpin, rfactor, _ = filename_parse(reacfile)
reacoffs = 0
nonroffs = 0
comptime = 32
nonrend = 400
reacend = 80
reactime = reacdata[:, 0]
reacpres = reacdata[:, 1]*rfactor + rpin*1.01325/760
nonrtime = nonrdata[:, 0]
nonrpres = nonrdata[:, 1]*nfactor + npin*1.01325/760

reacsmpr = smoothing(reacpres)
nonrsmpr = smoothing(nonrpres)
reacpc, reacpci = compress(reacsmpr)
nonrpci = np.argmax(nonrsmpr)
reacztim = reactime - reactime[reacpci]
reacfreq = np.rint(1/reactime[1])
nonrfreq = np.rint(1/nonrtime[1])
nonrendidx = nonrend/1000*nonrfreq
reacendidx = reacend/1000*reacfreq
startpoint = comptime/1000*reacfreq

reacp = pressure_fit(reacsmpr, reacpci, reacfreq)
line = np.polyval(reacp, reactime)
stroke_pressure = reacsmpr[(reacpci - startpoint):(reacpci + 1 + reacoffs)]
post_pressure = nonrsmpr[(nonrpci + nonroffs):(nonrpci +
                         nonrendidx + nonroffs - reacoffs)]
print_pressure = reacsmpr[(reacpci - startpoint):(reacpci + reacendidx)]
time = np.arange(-comptime/1000, nonrend/1000, 1/reacfreq)
stroke_volume = pressure_to_volume(stroke_pressure, reacTin)
stroke_temperature = pressure_to_temperature(stroke_pressure, reacTin)
compressed_volume = stroke_volume[-1]
compressed_temperature = stroke_temperature[-1]
post_volume = pressure_to_volume(post_pressure,
                                 compressed_temperature,
                                 compressed_volume)
volume = np.concatenate((stroke_volume, post_volume[1:]))
pressure = volume_to_pressure(volume, stroke_pressure[0]*1E5, reacTin)

fig = plt.figure(1)
ax = fig.add_subplot(1, 1, 1)
ax.plot(reacztim, reacsmpr)
ax.plot(time[:len(print_pressure)], print_pressure)
ax.plot(time, pressure)
ax.plot(reacztim, line)
m = plt.get_current_fig_manager()
m.window.showMaximized()

print('{:.4f}'.format(stroke_pressure[0]))
copy('{:.4f}'.format(stroke_pressure[0]))

volout = np.vstack((time[::5] + comptime/1000, volume[::5])).transpose()
presout = np.vstack((time[:len(print_pressure):5] + comptime/1000, print_pressure[::5])).transpose()
np.savetxt('volume.csv', volout, delimiter=',')
np.savetxt('Tc__P0__T0_{}K_pressure.txt'.format(reacTin), presout, delimiter='\t')

@@ -128,16 +128,28 @@
  as plt%0A
+import yaml%0A
 from pre
@@ -294,128 +294,341 @@
 it%0A%0A
-nonrfile = 'NR_00_in_00_mm_311K-1115t-40x-15-May-15-1425.txt'%0Areacfile = '00_in_00_mm_311K-1118t-40x-15-May-15-1301.txt'
+with open('volume-trace.yaml') as yaml_file:%0A    y = yaml.load(yaml_file)%0A%0Anonrfile = y%5B'nonrfile'%5D%0Areacfile = y%5B'reacfile'%5D%0Acomptime = y%5B'comptime'%5D%0Anonrend = y%5B'nonrend'%5D%0Areacend = y%5B'reacend'%5D%0Atry:%0A    reacoffs = y%5B'reacoffs'%5D%0Aexcept KeyError:%0A    reacoffs = 0%0A%0Atry:%0A    nonroffs = y%5B'nonroffs'%5D%0Aexcept KeyError:%0A    nonroffs = 0%0A
 %0Anon
@@ -865,24 +865,24 @@
 ata)/2, 2))%0A
+
 _, _, reacTi
@@ -932,75 +932,8 @@
 le)%0A
-reacoffs = 0%0Anonroffs = 0%0Acomptime = 32%0Anonrend = 400%0Areacend = 80%0A
 reac

Remove configuration data from volume_trace