def __init__(self, pulse, inputSpulse, z): self.z = z self.pulse = pulse self.Spulse = np.fft.rfft((pulse)) self.mytransferfunction = np.fft.rfft((pulse)) / inputSpulse self.epsilon = dielcal( np.fft.rfft((pulse)) / inputSpulse, z, myglobalparameters) self.mynorm = np.linalg.norm(inputSpulse)
mesdata=np.loadtxt(pathwithsample) ## We load the signal of the measured pulse with sample myinputdatafromfile=inputdatafromfile myglobalparameters=globalparameters myinputdatafromfile.PulseInittotal=np.loadtxt(pathwithoutsample) ## We load the data of the measured reference pulse myglobalparameters.t=myinputdatafromfile.PulseInittotal[:,0]*1e-12 #this assumes input files are in ps ## We load the list with the time of the experiment nsample=len(myglobalparameters.t) myinputdatafromfile.Pulseinit=myinputdatafromfile.PulseInittotal[:,1] dt=myglobalparameters.t.item(2)-myglobalparameters.t.item(1) ## Sample rate myglobalparameters.freq = np.fft.rfftfreq(nsample, dt) ## We create a list with the frequencies for the spectrum myglobalparameters.w=myglobalparameters.freq*2*np.pi myinputdatafromfile.Spulseinit=(np.fft.rfft((myinputdatafromfile.Pulseinit))) ## We compute the spectrum of the measured reference pulse # myinputdatafromfile.Spulseinit=(fft_gpu((myinputdatafromfile.Pulseinit))) if myrank ==0: myinputdata=mydata(mesdata[:,1],myinputdatafromfile.Spulseinit,z) ## We create a variable containing the data related to the measured pulse with sample monepsilon=dielcal(np.fft.rfft((mesdata[:,1]))/myinputdatafromfile.Spulseinit,z,myglobalparameters) ## We search for the dielectric function using what we measured # monepsilon=dielcal(fft_gpu((mesdata[:,1]))/myinputdatafromfile.Spulseinit,z,myglobalparameters) ############################################################################## #parameters for the algorithm ############################################################################## """parameters for the optimization algorithm""" swarmsize=1000 maxiter=20 # ============================================================================= # calculating the delay to infer the index # ============================================================================= deltaT=myglobalparameters.t[np.argmax(myinputdata.pulse)]-myglobalparameters.t[np.argmax(myinputdatafromfile.Pulseinit)] #retard entre les deux max print("############################################################################################") print("############################################################################################")
nsample = len(myglobalparameters.t) myinputdatafromfile.Pulseinit = myinputdatafromfile.PulseInittotal[:, 1] dt = myglobalparameters.t.item(2) - myglobalparameters.t.item(1) myglobalparameters.freq = np.fft.rfftfreq(nsample, dt) myglobalparameters.w = myglobalparameters.freq * 2 * np.pi myinputdatafromfile.Spulseinit = (np.fft.rfft( (myinputdatafromfile.Pulseinit))) z = sanitised_input("\nEnter a value for the thickness in meters [m]:", float, 0) deltaz = sanitised_input( "\nEnter a value for the thickness uncertainty in %:", float, 0) / 100 myinputdata = mydata(mesdata[:, 1], myinputdatafromfile.Spulseinit, z) monepsilon = dielcal( np.fft.rfft((mesdata[:, 1])) / myinputdatafromfile.Spulseinit, z, myglobalparameters) ############################################################################## #parameters for the algorithm ############################################################################## """parameters for the algorithm""" swarmsize = 1000 maxiter = 20 algo = 2 #algorithm 1 stands for NumPy optimize swarm particle, #algorithm 2 - for PyOpt swarm particle ALPSO without parallelization // 3 - ALPSO with parallelization // # ============================================================================= # calculating the delay to infer the index # =============================================================================
def param_ini(self, thickness, uncertainty, path_without_sample, path_with_sample): global c, j self.z = thickness self.deltaz = uncertainty / 100 self.pathwithoutsample = path_without_sample self.pathwithsample = path_with_sample self.mesdata = np.loadtxt( self.pathwithsample ) ## We load the signal of the measured pulse with sample self.myinputdatafromfile.PulseInittotal = np.loadtxt( self.pathwithoutsample ) ## We load the data of the measured reference pulse self.myglobalparameters.t = self.myinputdatafromfile.PulseInittotal[:, 0] * 1e-12 #this assumes input files are in ps ## We load the list with the time of the experiment self.nsample = len(self.myglobalparameters.t) self.myinputdatafromfile.Pulseinit = self.myinputdatafromfile.PulseInittotal[:, 1] self.dt = self.myglobalparameters.t.item( 2) - self.myglobalparameters.t.item(1) ## Sample rate self.myglobalparameters.freq = np.fft.rfftfreq( self.nsample, self.dt) ## We create a list with the frequencies for the spectrum self.myglobalparameters.w = self.myglobalparameters.freq * 2 * np.pi self.myinputdatafromfile.Spulseinit = ( np.fft.rfft((self.myinputdatafromfile.Pulseinit)) ) ## We compute the spectrum of the measured reference pulse self.myinputdata = TDS.mydata( self.mesdata[:, 1], self.myinputdatafromfile.Spulseinit, self.z, self.myglobalparameters ) ## We create a variable containing the data related to the measured pulse with sample self.monepsilon = dielcal( np.fft.rfft( (self.mesdata[:, 1])) / self.myinputdatafromfile.Spulseinit, self.z, self.myglobalparameters ) ## We search for the dielectric function using what we measured # calculating the delay to infer the index self.deltaT = self.myglobalparameters.t[np.argmax( self.myinputdata.pulse)] - self.myglobalparameters.t[np.argmax( self.myinputdatafromfile.Pulseinit )] #retard entre les deux max self.deltaTTT = self.myglobalparameters.t[np.argmin( self.myinputdata.pulse)] - self.myglobalparameters.t[np.argmin( self.myinputdatafromfile.Pulseinit )] ## retard entre les deux min self.deltaTT = ( np.sum( np.square(self.myinputdata.pulse) * self.myglobalparameters.t) / np.sum(np.square(self.myinputdata.pulse)) - np.sum( np.square(self.myinputdatafromfile.Pulseinit) * self.myglobalparameters.t) / np.sum(np.square(self.myinputdatafromfile.Pulseinit)) ) #retard entre les deux barycentre, attention pour que ca fonctionne il faut que le rapport signal bruit soit le meme dans les deux cas !! self.refreshAll("Delay between the two maxima of the pulses:") self.refreshAll(f'delta T = {self.deltaT}') self.refreshAll(f'n = {1+self.deltaT*c/self.z}') #indice qui en derive self.refreshAll(f'epsillon = {np.square(1+self.deltaT*c/self.z)} \n' ) #indice qui en derive self.refreshAll("Delay between the two minima of the pulses:") self.refreshAll(f'delta T = {self.deltaTTT}') self.refreshAll( f'n = {1+self.deltaTTT*c/self.z}') #indice qui en derive self.refreshAll(f'epsillon = {np.square(1+self.deltaTTT*c/self.z)} \n' ) #indice qui en derive self.refreshAll( "Delay between the two energy barycenter of the pulses\n (beware that noise brings it to the middle for each one):" ) self.refreshAll(f'delta T= {self.deltaTT}') self.refreshAll(f'n = {self.deltaTT*c/self.z}') #indice qui en derive self.refreshAll(f'epsillon = {np.square(self.deltaTT*c/self.z)} \n' ) #indice qui en derive