# -*- coding: utf-8 -*- import os import DTAutil import time import numpy as np import re class Measurement: x,T1,T2,dT = [],[],[],[] dTb = [] bBase = False base_a, base_b = 0,0 base_start, base_end = 0,0 Dbase_a = 0 Dbase_b = 0 alfa = 0 # heating speed bComplexBase = False baseUp_a, baseUp_b = 0,0 baseUp_start, baseUp_end = 0,0 DbaseUp_a = 0 DbaseUp_b = 0 basespline = None figtitle = "DTA mérés" bDiff = False dTdiffed = [] bIntegrated = False integrals = [] bTh = False Th_xmin, Th_xmax, Th_x = 0,0,0 Th_ymin, Th_ymax, Th = 0,0,0 bMp1 = False bMp2 = False mp1_a, mp1_b = 0,0 mp1_start, mp1_end = 0,0 Dmp1_a = 0 Dmp1_b = 0 mp2_a, mp2_b = 0,0 mp2_start, mp2_end = 0,0 Dmp2_a = 0 Dmp2_b = 0 bTmp = False Tmp = 0 Tmp_x = 0 maxT1 = 0 bMaxT1 = False directory = "" def __init__(self, path): self.open(path) def getdT(self): if(self.bBase): return self.dTb return self.dT def open(self, path): pathtrunc = path while(True): if(pathtrunc[-1] == '/'): self.directory = pathtrunc break else: pathtrunc = pathtrunc[:-1] if(len(pathtrunc) <= 0): print("Error while recursing for directory") return # workaround: first log message doesn't seem to go out, if log does not exist, create it if(not os.path.exists(self.directory+"OUTdta_fitlog.dat")): with open(self.directory+"OUTdta_fitlog.dat", "a") as f: print("", file=f) try: data0 = np.loadtxt(path,skiprows=10) except Exception as e: print("Could not load file") return t = time.localtime() current_time = time.strftime("%H:%M:%S", t) self.log("\nMegnyitva: "+path+" at ["+str(current_time)+"]\n") print("Megnyitva: "+path) try: os.chdir(self.directory) #print("Current working directory: {0}".format(os.getcwd())) except FileNotFoundError: print("Directory: {0} does not exist".format(self.directory)) except NotADirectoryError: print("{0} is not a directory".format(self.directory)) except PermissionError: print("You do not have permissions to cd to {0}".format(self.directory)) self.integrals = [] self.x,self.T1,self.T2,self.dT = DTAutil.process_data(data0) def log(self,text): with open(self.directory+"OUTdta_fitlog.dat", "a") as f: print(text, file=f) def fitreport(self,params, covs): perr = np.sqrt(np.diag(covs)) print("Final set of parameters Asymptotic Standard Error: ") print("======================= ==========================") for i in range(len(params)): print("Param-"+str(i)+": "+str(params[i])+" +/- "+str(perr[i])+" ("+ f'{abs(perr[i]/params[i]*100):.3e}'+"%)") with open(self.directory+"OUTdta_fitlog.dat", "a") as f: print("Final set of parameters Asymptotic Standard Error: ",file=f) print("======================= ==========================",file=f) for i in range(len(params)): print("Param-"+str(i)+": "+str(params[i])+" +/- "+str(perr[i])+" ("+ f'{abs(perr[i]/params[i]*100):.3e}'+"%)",file=f)