#!/usr/bin/python from __future__ import division from math import pi, log, sqrt from intervals import Interval import sys def read_tex_tab(name, xoffset = 0.0): with open(name) as f: f.readline() for line in f.readlines(): if line.strip() != r"\hline": line = [x.strip() for x in line.rstrip("\\\\\n").strip().split("&")] piezopos_um = float(line[2]) fname = line[3].split("(")[0].strip() if not fname.startswith("-"): yield (piezopos_um + xoffset, fname) def interval_from_gnuplot_pm(line): line = line.split("(")[0].strip() vname, rest = line.split("=", 1) vname = vname.strip() rest = rest.strip() a,da = map(float, rest.split("+/-")) vvalue = Interval(a - da, a + da) #print(vname, vvalue, line) return vname, vvalue def calc_lowpoint(fname): vars = {} miny = 10000 with open(fname) as f: for line in f: y = float(line.split(",")[4]) if y < miny: miny = y return miny #cat fits/F0054CH1.result |grep +/- # FIXME better to just do one since they are independent measurements! # -2.4 #items = list(read_tex_tab("positionsA.inc")) + FIXME #items = list(read_tex_tab("positionsA.inc", 0)) # -13.85)) #items = list(read_tex_tab("positionsA.inc", 1.73)) + list(read_tex_tab("positionsB.inc", -0.7)) # -13.85)) items = list(read_tex_tab("positionsB.inc", -13.85)) points = [] maxy = 0.0 for piezopos_um, fnamex in items: fname = "ALL00%s/F00%sCH1.CSV" % (fnamex, fnamex) #print(piezopos_um,fname) x = piezopos_um y = calc_lowpoint(fname) if y > maxy: maxy = y """ with open(fname) as f: for line in f: y = float(line.split(",")[4]) if y > maxy: maxy = y """ points.append((x,y)) def K(x, T_res): #sys.stderr.write("%s\n" % x) #if abs(1 - sqrt(T_res)) < 0.001: # return 1 # FIXME if x <= 0: result = (1 + sqrt(T_res))/(1 - sqrt(T_res)) # overcoupled else: result = (1 - sqrt(T_res))/(1 + sqrt(T_res)) # undercoupled #print("%s,%s,%s" % (piezopos_um,y,y)) return result #print("MAXY", maxy) # 0.58 # 0.628 # artificial 0.587 maxy = 0.587 # FIXME def renorm(y): return (y/maxy - 0.6)/0.4 points = [(x, renorm(y), K(x, renorm(y)), 1/(1 + 1/K(x, renorm(y))) if abs(K(x,renorm(y))) > 0.000001 else 0, y) for x,y in sorted(points)] #for p in points: # print(p) for x,y,K, E_photon,yorig in points: print("%s,%s,%s,%s,%s,%s" % (x,y,y,log(K), E_photon,yorig)) # TODO error # TODO what about 0? #gnuplot> plot "Q" using 1:2:2:3 with yerrorbars