def Simulate(self): '''This method finds modal birefringence of the structure and simulates this for the defined channel dimentions''' self.create_Entrys() if messagebox.askyesno( "Warning! ", 'This may take several minutes\n Are you sure you want to continue?' ): messagebox.showinfo( "Simulation", 'You can see the see the remaining time in the run window') self.g = Channel(wl=0.64, pas=0.1, \ nc=1, nc_2=1, nc_3=1, Hc=0.8, \ LC=3.1, LB=5., LB_R=5., \ n1B=1, n1C=1.62, n1D=1, H1=2.3, \ n2B=1.62, n2C=1.62, n2D=1.62, H2=2, \ nsub=1.61, nsub_2=1.61, nsub_3=1.61, Hsub=2., OR=4) self.g.H2 = self.VaryH1LC_H2_Value self.g.VariaXY(X0=self.LC_1, X1=self.LC_2, dX=0.1, Y0=self.H1_1, Y1=self.H1_2, dY=0.1, fich=str(self.filename)) else: messagebox.showinfo( "Canceled", 'You have successfully canceled the simulation')
def Simulate(self): if messagebox.askyesno( "Warning! ", 'This may take several minutes\n Are you sure you want to continue?' ): messagebox.showinfo( "Simulation", 'You can see the see the remaining time in the run window') self.g = Channel(wl=self.WL.get(), pas=0.1, \ nc=self.nC_1.get(), nc_2=self.nC_2.get(), nc_3=self.nC_3.get(), Hc=0.8, \ LC=self.TChan.get(), LB=5., LB_R=5., \ n1B=self.nL1_1.get(), n1C=self.nL1_2.get(), n1D=self.nL1_3.get(), H1=self.TL_1.get(), \ n2B=self.nL2_1.get(), n2C=self.nL2_2.get(), n2D=self.nL2_3.get(), H2=self.TL_2.get(), \ nsub=self.nSub_1.get(), nsub_2=self.nSub_2.get(), nsub_3=self.nSub_3.get(), Hsub=2., OR=self.OPR.get()) self.g.H2 = self.H2value.get() self.g.VariaXY(X0=self.LC_1.get(), X1=self.LC_2.get(), dX=0.1, Y0=self.H1_1.get(), Y1=self.H1_2.get(), dY=0.1, fich=self.FileName.get()) else: messagebox.showinfo( "Canceled", 'You have successfully canceled the simulation')
def NumOf_guided_modes( self): # This will print angles which can give coupled light. print( "Coupling neff is calculated with equation\n n_eff=n_top.sin(\u03B8) + (m.(\u03BB/\u039B) \n where " "n_eff is effective refractive index, n_top is refractive index of the cover\n" "\u03B8 is coupling angle,m is diffraction mode, \u03BB is wavelength, and \u039B is grating period" ) self.g = Channel(wl=self.WL.get(), pas=0.1, \ nc=self.nC_1.get(), nc_2=self.nC_2.get(), nc_3=self.nC_3.get(), Hc=0.8, \ LC=self.TChan.get(), LB=5., LB_R=5., \ n1B=self.nL1_1.get(), n1C=self.nL1_2.get(), n1D=self.nL1_3.get(), H1=self.TL_1.get(), \ n2B=self.nL2_1.get(), n2C=self.nL2_2.get(), n2D=self.nL2_3.get(), H2=self.TL_2.get(), \ nsub=self.nSub_1.get(), nsub_2=self.nSub_2.get(), nsub_3=self.nSub_3.get(), Hsub=2., OR=self.OPR.get()) if self.g.NmaxPlan( ) == 0: # blow H2==0.9 NmaxPlan is 0 and it does not give good value. messagebox.showinfo( "Hey", 'It looks like NmaxPlan is {}'.format(self.g.NmaxPlan())) pass else: for i in np.real( (self.g.NumOf_guidedModes(Nmodes=self.Nmodes.get())[1:])): print( "For the {:.4f} mode there is one coupling angle at {:.4f}" .format(i, self.Nmode_effective(i)))
def Plot_indices(self): self.g = Channel(wl=self.WL.get(), pas=0.1, \ nc=self.nC_1.get(), nc_2=self.nC_2.get(), nc_3=self.nC_3.get(), Hc=0.8, \ LC=self.TChan.get(), LB=5., LB_R=5., \ n1B=self.nL1_1.get(), n1C=self.nL1_2.get(), n1D=self.nL1_3.get(), H1=self.TL_1.get(), \ n2B=self.nL2_1.get(), n2C=self.nL2_2.get(), n2D=self.nL2_3.get(), H2=self.TL_2.get(), \ nsub=self.nSub_1.get(), nsub_2=self.nSub_2.get(), nsub_3=self.nSub_3.get(), Hsub=2., OR=self.OPR.get()) self.g.Traceindice()
def Simulate_Var(self): self.g = Channel(wl=self.WL.get(), pas=0.1, \ nc=self.nC_1.get(), nc_2=self.nC_2.get(), nc_3=self.nC_3.get(), Hc=0.8, \ LC=self.TChan.get(), LB=5., LB_R=5., \ n1B=self.nL1_1.get(), n1C=self.nL1_2.get(), n1D=self.nL1_3.get(), H1=self.TL_1.get(), \ n2B=self.nL2_1.get(), n2C=self.nL2_2.get(), n2D=self.nL2_3.get(), H2=self.TL_2.get(), \ nsub=self.nSub_1.get(), nsub_2=self.nSub_2.get(), nsub_3=self.nSub_3.get(), Hsub=2., OR=self.OPR.get()) self.g.VariaX(X0=self.X1_var.get(),X1=self.X2_var.get(),dX=self.dX_var.get(),variable=self.Var_var.get()\ ,trace=True,Show_Struct=self.Show_Struct_var.get(),SaveFile=self.SaveFile_var.get(),fich=self.FileName_var.get())
def __init__(self,wl=0.64,pas=0.1,\ nc=1.,Hc=0.8,\ LB=5,LC=3.1,\ ng=1.62,H1=2.3, H2=2.,\ nsub=1.61,Hsub=2,OR=4 ): # --------- ridge Channel.__init__(self,wl=wl,pas=pas,nc=nc,nc_2=nc,nc_3=nc\ ,Hc=Hc,LB=LB,LB_R=LB,LC=LC,n1B=nc,n1D=nc,n1C=ng,H1=H1,\ n2B=ng,n2D=ng,n2C=ng,H2=H2,nsub=nsub,nsub_2=nsub,nsub_3=nsub,Hsub=Hsub,OR=OR)
def Plot_indices(self): '''This method plots refractive index of the structure''' self.create_Entrys() self.g = Channel(wl=self.WL, pas=0.1, \ nc=self.nC_1, nc_2=self.nC_2, nc_3=self.nC_3, Hc=0.8, \ LC=self.TChan, LB=5., LB_R=5., \ n1B=self.nL1_1, n1C=self.nL1_2, n1D=self.nL1_3, H1=self.TL_1, \ n2B=self.nL2_1, n2C=self.nL2_2, n2D=self.nL2_3, H2=self.TL_2, \ nsub=self.nSub_1, nsub_2=self.nSub_2, nsub_3=self.nSub_3, Hsub=2., OR=self.OPR) self.g.Traceindice()
def Solve(self): self.create_Entrys() self.g = Channel(wl=self.WL, pas=0.1, \ nc=self.nC_1, nc_2=self.nC_2, nc_3=self.nC_3, Hc=0.8, \ LC=self.TChan, LB=5., LB_R=5., \ n1B=self.nL1_1, n1C=self.nL1_2, n1D=self.nL1_3, H1=self.TL_1, \ n2B=self.nL2_1, n2C=self.nL2_2, n2D=self.nL2_3, H2=self.TL_2, \ nsub=self.nSub_1, nsub_2=self.nSub_2, nsub_3=self.nSub_3, Hsub=2., OR=self.OPR) self.g.Calcule(Nmodes=self.Nmodes_value) #self.g.Intensite() plt.show()
def NumOf_guided_modes( self): # This will print angles which can give coupled light. '''This method finds any differaction mode of a grating that matches with the guided modes of the structure and returns the angle''' self.create_Entrys() print( "Coupling neff is calculated with equation\n n_eff=n_top.sin(\u03B8) + (m.(\u03BB/\u039B) \n where " "n_eff is effective refractive index, n_top is refractive index of the cover\n" "\u03B8 is coupling angle,m is diffraction mode, \u03BB is wavelength, and \u039B is grating period" ) self.g = Channel(wl=self.WL, pas=0.1, \ nc=self.nC_1, nc_2=self.nC_2, nc_3=self.nC_3, Hc=0.8, \ LC=self.TChan, LB=5., LB_R=5., \ n1B=self.nL1_1, n1C=self.nL1_2, n1D=self.nL1_3, H1=self.TL_1, \ n2B=self.nL2_1, n2C=self.nL2_2, n2D=self.nL2_3, H2=self.TL_2, \ nsub=self.nSub_1, nsub_2=self.nSub_2, nsub_3=self.nSub_3, Hsub=2., OR=self.OPR) if self.g.NmaxPlan( ) == 0: # blow H2==0.9 NmaxPlan is 0 and it does not give good value. messagebox.showinfo( "Hey", 'It looks like NmaxPlan is {}'.format(self.g.NmaxPlan())) pass else: print("neff of the guided modes of the structure are: {}".format( self.g.NumOf_guidedModes(Nmodes=self.Nmodes_value)[1:])) just_Modes = ((self.g.NumOf_guidedModes( Nmodes=self.Nmodes_value)[1:])) theta = np.arange(0, 90, 0.001) # array of angles in degrees All_n_effectives_are = np.around( self.Nmode_effective(theta), decimals=4 ) #around function round to 4 decimals and neglect the rest. guided_modes_n_effectives_are_array = np.where( (np.where(All_n_effectives_are <= (np.amax(just_Modes)), All_n_effectives_are, 0)) >= (np.amin(just_Modes)), All_n_effectives_are, 0) guided_modes_n_effectives_are_index = np.where( guided_modes_n_effectives_are_array > 0) guided_modes_n_effectives_are = All_n_effectives_are[ guided_modes_n_effectives_are_index] guided_modes_n_effectives_theta_are = np.around( theta[guided_modes_n_effectives_are_index], decimals=1) s = guided_modes_n_effectives_are.size if s > 0: for i in range(0, s): print( "There is one guided mode at angle {} that has neff = {}" .format((guided_modes_n_effectives_theta_are[i]), guided_modes_n_effectives_are[i])) else: messagebox.showinfo( "Sorry", 'The is no coupling angle that match with guided modes')
def Solve(self): self.g = Channel(wl=self.WL.get(), pas=0.1, \ nc=self.nC_1.get(), nc_2=self.nC_2.get(), nc_3=self.nC_3.get(), Hc=0.8, \ LC=self.TChan.get(), LB=5., LB_R=5., \ n1B=self.nL1_1.get(), n1C=self.nL1_2.get(), n1D=self.nL1_3.get(), H1=self.TL_1.get(), \ n2B=self.nL2_1.get(), n2C=self.nL2_2.get(), n2D=self.nL2_3.get(), H2=self.TL_2.get(), \ nsub=self.nSub_1.get(), nsub_2=self.nSub_2.get(), nsub_3=self.nSub_3.get(), Hsub=2., OR=self.OPR.get()) self.g.Calcule(Nmodes=self.Nmodes.get(), trace=self.TraceIntensity_var.get(), traceMode=self.TraceMode_var.get()) plt.show()
class Mul_Ch_Wav_Mod_Sol(Frame): '''Help on Class multilayer channel waveguide mode solver: Usage: It can be used to solve light confinement modes inside a channel dielectric chiral structure. ''' def __init__(self, master): super().__init__(master) self.master = master self.grid() self.place() # creat variable to be updated by the user self.vnc1 = DoubleVar() self.vnc1.set(1.) self.vnc2 = DoubleVar() self.vnc2.set(1.) self.vnc3 = DoubleVar() self.vnc3.set(1.) self.vnL1_1 = DoubleVar() self.vnL1_1.set(1.) self.vnL1_2 = DoubleVar() self.vnL1_2.set(1.62) self.vnL1_3 = DoubleVar() self.vnL1_3.set(1.) self.vnL2_1 = DoubleVar() self.vnL2_1.set(1.62) self.vnL2_2 = DoubleVar() self.vnL2_2.set(1.62) self.vnL2_3 = DoubleVar() self.vnL2_3.set(1.62) self.vnSub1 = DoubleVar() self.vnSub1.set(1.61) self.vnSub2 = DoubleVar() self.vnSub2.set(1.61) self.vnSub3 = DoubleVar() self.vnSub3.set(1.61) self.vTL1 = DoubleVar() self.vTL1.set(2.3) self.vTL2 = DoubleVar() self.vTL2.set(2.) self.vTc = DoubleVar() self.vTc.set(3.1) self.vWL = DoubleVar() self.vWL.set(0.64) self.vOR = DoubleVar() self.vOR.set(4.0) self.vVaryH1LC_H1 = StringVar() self.vVaryH1LC_H1.set('1.0 to 4.0') self.vVaryH1LC_LC = StringVar() self.vVaryH1LC_LC.set('1.5 to 5.0') self.vVaryH1LC_H2 = DoubleVar() self.vVaryH1LC_H2.set(1.0) self.vVaryH1LC_SaveAs = StringVar() self.vVaryH1LC_SaveAs.set('Filename') self.vSimulat = DoubleVar() self.vSimulat.set(np.zeros((1, 1))) self.vgrating_period = DoubleVar() self.vgrating_period.set(0.83) self.vdiffraction_mode = DoubleVar() self.vdiffraction_mode.set(1) self.vNmodes = IntVar() self.vNmodes.set(2) #self.vVaryH1LC_SaveAs_loc = StringVar();self.vVaryH1LC_SaveAs_loc.set('C:/Users/Home')#location to save self.create_labels() self.create_Entrys() self.create_buttons() def create_Entrys(self): '''Here all the entries are defined''' self.nCover_1 = Entry(self, width=10, borderwidth=5, textvariable=self.vnc1) self.nCover_1.grid(row=1, column=3, padx=5, pady=5) self.nCover_2 = Entry(self, width=10, borderwidth=5, textvariable=self.vnc2) self.nCover_2.grid(row=1, column=2, padx=5, pady=5) self.nCover_3 = Entry(self, width=10, borderwidth=5, textvariable=self.vnc3) self.nCover_3.grid(row=1, column=1, padx=5, pady=5) self.nLayer1_1 = Entry(self, width=10, borderwidth=5, textvariable=self.vnL1_1) self.nLayer1_1.grid(row=2, column=3, padx=5, pady=5) self.nLayer1_2 = Entry(self, width=10, borderwidth=5, textvariable=self.vnL1_2) self.nLayer1_2.grid(row=2, column=2, padx=5, pady=5) self.nLayer1_3 = Entry(self, width=10, borderwidth=5, textvariable=self.vnL1_3) self.nLayer1_3.grid(row=2, column=1, padx=5, pady=5) self.nLayer2_1 = Entry(self, width=10, borderwidth=5, textvariable=self.vnL2_1) self.nLayer2_1.grid(row=3, column=3, padx=5, pady=5) self.nLayer2_2 = Entry(self, width=10, borderwidth=5, textvariable=self.vnL2_2) self.nLayer2_2.grid(row=3, column=2, padx=5, pady=5) self.nLayer2_3 = Entry(self, width=10, borderwidth=5, textvariable=self.vnL2_3) self.nLayer2_3.grid(row=3, column=1, padx=5, pady=5) self.nSubstrate_1 = Entry(self, width=10, borderwidth=5, textvariable=self.vnSub1) self.nSubstrate_1.grid(row=4, column=3, padx=5, pady=5) self.nSubstrate_2 = Entry(self, width=10, borderwidth=5, textvariable=self.vnSub2) self.nSubstrate_2.grid(row=4, column=2, padx=5, pady=5) self.nSubstrate_3 = Entry(self, width=10, borderwidth=5, textvariable=self.vnSub3) self.nSubstrate_3.grid(row=4, column=1, padx=5, pady=5) self.Thickness_Layer_1 = Entry(self, width=10, borderwidth=5, textvariable=self.vTL1) self.Thickness_Layer_1.grid(row=2, column=4, padx=5, pady=5) self.Thickness_Layer_2 = Entry(self, width=10, borderwidth=5, textvariable=self.vTL2) self.Thickness_Layer_2.grid(row=3, column=4, padx=5, pady=5) self.Thickness_channel = Entry(self, width=10, borderwidth=5, textvariable=self.vTc) self.Thickness_channel.grid(row=6, column=2, padx=5, pady=5) self.Wavelength = Entry(self, width=10, borderwidth=5, textvariable=self.vWL) self.Wavelength.grid(row=6, column=5, padx=5, pady=5) self.Optical_rotation = Entry(self, width=10, borderwidth=5, textvariable=self.vOR) self.Optical_rotation.grid(row=8, column=5, padx=5, pady=5) self.VaryH1LC_H1 = Entry(self, width=10, borderwidth=5, textvariable=self.vVaryH1LC_H1) self.VaryH1LC_H1.grid(row=13, column=1, padx=5, pady=5) self.VaryH1LC_LC = Entry(self, width=10, borderwidth=5, textvariable=self.vVaryH1LC_LC) self.VaryH1LC_LC.grid(row=13, column=3, padx=5, pady=5) self.VaryH1LC_H2 = Entry(self, width=5, borderwidth=5, textvariable=self.vVaryH1LC_H2) self.VaryH1LC_H2.grid(row=13, column=6, padx=5, pady=5) self.VaryH1LC_SaveAs = Entry(self.labelFrame1, width=10, borderwidth=5, textvariable=self.vVaryH1LC_SaveAs) self.VaryH1LC_SaveAs.grid(row=15, column=3, padx=5, pady=5) self.diffraction_mode_E = Entry(self, width=5, borderwidth=5, textvariable=self.vdiffraction_mode) self.diffraction_mode_E.grid(row=16, column=5, padx=5, pady=5) self.grating_period_E = Entry(self, width=5, borderwidth=5, textvariable=self.vgrating_period) self.grating_period_E.grid(row=17, column=5, padx=5, pady=5) self.NModes_E = Entry(self, width=5, borderwidth=5, textvariable=self.vNmodes) self.NModes_E.grid(row=10, column=5, padx=5, pady=5) #self.Simulat_file = Entry(self, width=10, borderwidth=5, textvariable=self.vSimulat_file);self.Simulat_file.grid(row=14, column=6, padx=5, pady=5) ######## self.nC_1 = float(self.nCover_1.get()) self.nC_2 = float(self.nCover_2.get()) self.nC_3 = float(self.nCover_3.get()) self.nL1_1 = float(self.nLayer1_1.get()) self.nL1_2 = float(self.nLayer1_2.get()) self.nL1_3 = float(self.nLayer1_3.get()) self.nL2_1 = float(self.nLayer2_1.get()) self.nL2_2 = float(self.nLayer2_2.get()) self.nL2_3 = float(self.nLayer2_3.get()) self.nSub_1 = float(self.nSubstrate_1.get()) self.nSub_2 = float(self.nSubstrate_2.get()) self.nSub_3 = float(self.nSubstrate_3.get()) self.TL_2 = float(self.Thickness_Layer_2.get()) self.TL_1 = float(self.Thickness_Layer_1.get()) self.TChan = float(self.Thickness_channel.get()) self.WL = float(self.Wavelength.get()) self.OPR = float(self.Optical_rotation.get()) self.VaryH1LC_H1_array = self.VaryH1LC_H1.get() self.VaryH1LC_LC_array = self.VaryH1LC_LC.get() self.VaryH1LC_H2_Value = float(self.VaryH1LC_H2.get()) # print(self.VaryH1LC_H1_array) self.H1_1 = np.fromstring(self.VaryH1LC_H1_array, dtype=float, sep='to')[0] self.H1_2 = np.fromstring(self.VaryH1LC_H1_array, dtype=float, sep='to')[1] self.LC_1 = np.fromstring(self.VaryH1LC_LC_array, dtype=float, sep='to')[0] self.LC_2 = np.fromstring(self.VaryH1LC_LC_array, dtype=float, sep='to')[1] #for the grating coupler self.filename = self.VaryH1LC_SaveAs.get() self.grating_period = float(self.grating_period_E.get()) self.diffraction_mode = int(self.diffraction_mode_E.get()) self.Nmodes_value = int(self.NModes_E.get()) def create_labels(self): '''Here all the labels are defined''' Label(self, text="Refractive indices").grid(row=0, column=2) Label(self, text=" Thickness").grid(row=0, column=4) Label(self, text='\u03BCm' + " (H1)", font='Verdana 10').place(x=400, y=63) Label(self, text='\u03BCm' + " (H2)", font='Verdana 10').place(x=400, y=100) Label(self, text="Cover").grid(row=1) Label(self, text="Layer 2").grid(row=2) Label(self, text="Layer 1").grid(row=3) Label(self, text="Substrate").grid(row=4) Label(self, text=" Channel (LC)").grid(row=5, column=2) Label(self, text='\u03BCm', font='Verdana 10').place(x=225, y=195) # unicode careters Label(self, text="").grid(row=7) Label(self, text="").grid(row=8) Label(self, text="").grid(row=9) #to creat space Label(self, text="").grid(row=10) Label(self, text="").grid(row=11) Label(self, text="").grid(row=12) Label(self, text="").grid(row=13) Label(self, text="").grid(row=14) Label(self, text="").grid(row=15) Label(self, text="").grid(row=16) Label(self, text="").grid(row=17) Label(self, text="").grid(row=18) Label(self, text=' \u03BB', font='Verdana 10').place(x=420, y=172) # unicode careters Label(self, text='\u03BCm', font='Times 12').place(x=480, y=195) Label(self, text=" OR", font='Times 12').place(x=415, y=230) # unicode careters Label(self, text=u'\u2070/mm', font='Verdana 10').place(x=480, y=255) # unicode careters self.labelFrame = LabelFrame(self, text="Choose file\nto plot") self.labelFrame.grid( column=5, row=14) ####################################################### self.labelFrame1 = LabelFrame(self, text="Save as") self.labelFrame1.grid(column=2, row=14) #create the structure Label(self, text="<---- LC ---->").place(x=81, y=235) Label(self, text="-" * 15).place(x=80, y=250) Label(self, text="|").place(x=80, y=258) Label(self, text="|").place(x=157, y=258) Label(self, text="|").place(x=80, y=275) Label(self, text="|").place(x=157, y=275) Label(self, text="-" * 15).place(x=170, y=285) Label(self, text="\u2191", font=10).place(x=165, y=253) Label(self, text="\u2193", font=10).place(x=165, y=271) Label(self, text="H1").place( x=165, y=268.5 ) # "H\u2081" H Subscript 1, Superscript is \uu207x(1,2,3...) Label(self, text="-" * 15).place(x=1, y=282) Label(self, text="-" * 50).place(x=1, y=320) Label(self, text="\u2191", font=10).place(x=245, y=288) Label(self, text="\u2193", font=10).place(x=245, y=306) Label(self, text="H2").place(x=245, y=303.5) Label(self, text="Vary\nH1 (\u03BCm) =").place(x=0, y=375) Label(self, text="Vary\nLC (\u03BCm) =").place(x=180, y=375) Label(self, text="@ constant H2 (\u03BCm) =").place(x=360, y=390) #Label(self, text="Save as:", font="Calibri 15").place(x=165, y=405) # Label(self, text="Choose file to plot", font="Calibri 12").place(x=365, y=405) Label(self, text="Diffraction mode # =").place(x=300, y=560) Label(self, text="Grating period (\u039B) =").place(x=305, y=595) Label(self, text="# of modes =").place(x=340, y=310) def create_buttons(self): '''Here all the buttons are defined''' Button(self, text="Plot_indices", fg='green', command=self.Plot_indices).grid(row=18, column=3) Button(self, text="Solve", fg='green', command=self.Solve).grid(row=18, column=2) Button(self, text="Close", fg='red', command=self.close_all).grid(row=18, column=0) Button(self, text="Close plots", fg='red', command=self.close_plots).grid(row=18, column=1) Button(self, text="Simulate", fg='Green', command=self.Simulate).grid(row=14, column=1) # Button(self, text="Plot image map\nof the simulation", fg='Green', command="").place(x=365, y=435) Button(self.labelFrame, text="Browse A File", command=self.fileDialog).grid( row=14, column=6 ) ####################################################### Button(self.labelFrame, text="Plot Ecc.", command=self.plot_simulate_ecc).grid(row=15, column=6) Button(self.labelFrame, text="Plot \u0394n", command=self.plot_simulate_dn).grid(row=16, column=6) Button(self, text="Coupling \u03B8", fg='green', command=self.NumOf_guided_modes).grid(row=18, column=5) #grating #Button(self.labelFrame1, text="Browse\n directory", command=self.fileDialog_saveas).grid(row=14, column=3) def Plot_indices(self): '''This method plots refractive index of the structure''' self.create_Entrys() self.g = Channel(wl=self.WL, pas=0.1, \ nc=self.nC_1, nc_2=self.nC_2, nc_3=self.nC_3, Hc=0.8, \ LC=self.TChan, LB=5., LB_R=5., \ n1B=self.nL1_1, n1C=self.nL1_2, n1D=self.nL1_3, H1=self.TL_1, \ n2B=self.nL2_1, n2C=self.nL2_2, n2D=self.nL2_3, H2=self.TL_2, \ nsub=self.nSub_1, nsub_2=self.nSub_2, nsub_3=self.nSub_3, Hsub=2., OR=self.OPR) self.g.Traceindice() def fileDialog_saveas(self): # to browse locaation of a file self.vVaryH1LC_SaveAs_loc = filedialog.askdirectory( initialdir="", title="Select the location" ) #(("all files", "*.*"), ("csv files", "*.csv"))) def fileDialog(self): # to brows the file '''This method gets the calls the location of a file from user call''' self.vSimulat = filedialog.askopenfilename( initialdir="", title="Select A File", filetype=(("all files", "*.*"), ( "csv files", "*.csv"))) #(("all files", "*.*"), ("csv files", "*.csv"))) self.df = pd.read_csv(self.vSimulat, sep=' ', comment='#', header=None) self.dr = self.df.to_numpy() #print(self.filename) def plot_simulate_ecc(self): '''This method plots eccentricity of the simulated data in the file called by the method fileDialog''' self.create_Entrys() fig, ax = plt.subplots(figsize=(8, 6)) #plt.title("Eccentricy as a function of channel dimensions") print("Optcal rotaion is: " + str(self.OPR)) self.DnCB = ((0.001 * (self.WL) * self.OPR) / 180 ) #CB=self.OPR*1e-3/180*self.WL print("Circular bireferengence (CB) is: " + str(self.DnCB)) im = plt.imshow(self.DnCB / (self.dr + np.sqrt(self.DnCB**2 + self.dr**2)), extent=[self.LC_1, self.LC_2, self.H1_1, self.H1_2], origin='lower') plt.xlabel("H1 (\u03BCm)") plt.ylabel("LC (\u03BCm)") divider = make_axes_locatable(ax) cax = divider.new_vertical(size="5%", pad=0.4, title="Eccentricity") fig.add_axes(cax) fig.colorbar(im, cax=cax, orientation="horizontal") ####################################################################################################### mshu x y labela wash karw # plt.savefig('colorbar_positioning_03.png', format='png', bbox_inches='tight') plt.hot() plt.show() plt.close() def printt(self): print(self.filename) def plot_simulate_dn(self): '''This method plots modal birefringence of the simulated data in the file called by the method fileDialog''' self.create_Entrys() fig, ax = plt.subplots(figsize=(8, 6)) #plt.title("Modal bireferengence as a function of channel dimensions") im = plt.imshow(self.dr, extent=[self.LC_1, self.LC_2, self.H1_1, self.H1_2], origin='lower') plt.xlabel("H1 (\u03BCm)") plt.ylabel("LC (\u03BCm)") divider = make_axes_locatable(ax) cax = divider.new_vertical(size="5%", pad=0.4, title="Modal bireferengence") fig.add_axes(cax) fig.colorbar(im, cax=cax, orientation="horizontal") # plt.savefig('colorbar_positioning_03.png', format='png', bbox_inches='tight') plt.hot() plt.show() plt.close() def close_all(self): '''This method closes everything it just has self.master.destroy() and plt.close('all')''' self.master.destroy() plt.close('all') def Solve(self): self.create_Entrys() self.g = Channel(wl=self.WL, pas=0.1, \ nc=self.nC_1, nc_2=self.nC_2, nc_3=self.nC_3, Hc=0.8, \ LC=self.TChan, LB=5., LB_R=5., \ n1B=self.nL1_1, n1C=self.nL1_2, n1D=self.nL1_3, H1=self.TL_1, \ n2B=self.nL2_1, n2C=self.nL2_2, n2D=self.nL2_3, H2=self.TL_2, \ nsub=self.nSub_1, nsub_2=self.nSub_2, nsub_3=self.nSub_3, Hsub=2., OR=self.OPR) self.g.Calcule(Nmodes=self.Nmodes_value) #self.g.Intensite() plt.show() def NumOf_guided_modes( self): # This will print angles which can give coupled light. '''This method finds any differaction mode of a grating that matches with the guided modes of the structure and returns the angle''' self.create_Entrys() print( "Coupling neff is calculated with equation\n n_eff=n_top.sin(\u03B8) + (m.(\u03BB/\u039B) \n where " "n_eff is effective refractive index, n_top is refractive index of the cover\n" "\u03B8 is coupling angle,m is diffraction mode, \u03BB is wavelength, and \u039B is grating period" ) self.g = Channel(wl=self.WL, pas=0.1, \ nc=self.nC_1, nc_2=self.nC_2, nc_3=self.nC_3, Hc=0.8, \ LC=self.TChan, LB=5., LB_R=5., \ n1B=self.nL1_1, n1C=self.nL1_2, n1D=self.nL1_3, H1=self.TL_1, \ n2B=self.nL2_1, n2C=self.nL2_2, n2D=self.nL2_3, H2=self.TL_2, \ nsub=self.nSub_1, nsub_2=self.nSub_2, nsub_3=self.nSub_3, Hsub=2., OR=self.OPR) if self.g.NmaxPlan( ) == 0: # blow H2==0.9 NmaxPlan is 0 and it does not give good value. messagebox.showinfo( "Hey", 'It looks like NmaxPlan is {}'.format(self.g.NmaxPlan())) pass else: #print("neff of the guided modes of the structure are: {}".format(self.g.NumOf_guidedModes(Nmodes=self.Nmodes_value)[1:])) #just_Modes = ((self.g.NumOf_guidedModes(Nmodes=self.Nmodes_value)[1:])) # theta = np.arange(0, 90, 0.001)# array of angles in degrees # All_n_effectives_are = np.around(self.Nmode_effective(theta), decimals=4)#around function round to 4 decimals and neglect the rest. # guided_modes_n_effectives_are_array = np.where((np.where( # All_n_effectives_are <= (np.amax(just_Modes)), All_n_effectives_are, 0)) >= (np.amin(just_Modes)), # All_n_effectives_are, 0) # guided_modes_n_effectives_are_index = np.where(guided_modes_n_effectives_are_array > 0) # guided_modes_n_effectives_are = All_n_effectives_are[guided_modes_n_effectives_are_index] # guided_modes_n_effectives_theta_are = np.around(theta[guided_modes_n_effectives_are_index], decimals=1) # s = guided_modes_n_effectives_are.size #effective_modes=np.real((self.g.NumOf_guidedModes(Nmodes=self.Nmodes_value)[1:])) # print((self.g.NumOf_guidedModes(Nmodes=self.Nmodes_value)[1])) for i in np.real( (self.g.NumOf_guidedModes(Nmodes=self.Nmodes_value)[1:])): print( "For the {} mode there is one coupling angle at {}".format( i, self.Nmode_effective(i))) # else: # messagebox.showinfo("Sorry",'The is no coupling angle that match with guided modes') def Nmode_effective( self, n_eff ): # to find n_e that is effective refractive index of the grating '''This method returns guided modes of the structure (not leaky modes)''' self.create_Entrys() #print(self.grating_period,self.diffraction_mode) n_top = np.average(np.array([self.nC_1, self.nC_2, self.nC_3])) if ((n_eff - (self.diffraction_mode * (self.WL / self.grating_period))) / (n_top)) > 1: theta = 0 elif ((n_eff - (self.diffraction_mode * (self.WL / self.grating_period))) / (n_top)) < 0: theta = 0 else: theta = np.rad2deg( np.arcsin( (n_eff - (self.diffraction_mode * (self.WL / self.grating_period))) / (n_top))) #n_e = ((n_top * (np.sin(np.rad2deg(one_theta)))) + (float(self.diffraction_mode) * (float(self.WL)/float(self.grating_period))))#n_top= np.average(np.arange(float(self.nC_1),float(self.nC_2),float(self.nC_3))) return theta def Simulate(self): '''This method finds modal birefringence of the structure and simulates this for the defined channel dimentions''' self.create_Entrys() if messagebox.askyesno( "Warning! ", 'This may take several minutes\n Are you sure you want to continue?' ): messagebox.showinfo( "Simulation", 'You can see the see the remaining time in the run window') self.g = Channel(wl=0.64, pas=0.1, \ nc=1, nc_2=1, nc_3=1, Hc=0.8, \ LC=3.1, LB=5., LB_R=5., \ n1B=1, n1C=1.62, n1D=1, H1=2.3, \ n2B=1.62, n2C=1.62, n2D=1.62, H2=2, \ nsub=1.61, nsub_2=1.61, nsub_3=1.61, Hsub=2., OR=4) self.g.H2 = self.VaryH1LC_H2_Value self.g.VariaXY(X0=self.LC_1, X1=self.LC_2, dX=0.1, Y0=self.H1_1, Y1=self.H1_2, dY=0.1, fich=str(self.filename)) else: messagebox.showinfo( "Canceled", 'You have successfully canceled the simulation') def close_plots(self): plt.close('all')
import numpy as np from tkinter import messagebox from Channels_multilayer import Channel g=Channel(wl=0.64,pas=0.1,nc=1., nc_2=1., nc_3=1.,Hc=0.8,\ LB=5, LC=3.2,LB_R=5,n1B=1.,n1C=1.620,n1D=1.,H1=2.3,\ n2B=1.62,n2C=1.62,n2D=1.62,H2=0.9,\ nsub=1.61,nsub_2=1.61,nsub_3=1.61,Hsub=2.,OR=4) print("All units are in \u03BCm") m = 1 lam = 0.64 theta = np.arange(0, 90, 0.01) #theta = theta.tolist() # print (theta) # print((g.NumOf_guidedModes(Nmodes=10))) # print((g.NumOf_guidedModes(Nmodes=10)[1:])) just_Modes = ((g.NumOf_guidedModes(Nmodes=5)[1:])) # print(np.amax(g.NumOf_guidedModes(Nmodes=10)[1:])) # print(np.amin(g.NumOf_guidedModes(Nmodes=10)[1:])) # print ("The angles are is "+str(theta)) n_top = 1.0 # float(input("Please inter refractive index of cover layer: ")) n_guiding = 1.62 # float(input("Please inter refractive index of guding layer: ")) n_bottom = 1.61 # float(input("Please inter refractive index of guding layer: ")) grating_period = 1000 / 1200 #np.arange(0.2,2,0.01)#float(input("Please inter grating period ")) def Nmode_effective(one_theta): n_e = ((n_top * (np.sin(np.rad2deg(one_theta)))) + (m * (lam / grating_period))) return n_e
class Mul_Ch_Wav_Mod_Sol(Frame): def __init__(self, master): super().__init__(master) self.master = master Frame.__init__(self, self.master) self.configure_gui() self.create_widgets() def configure_gui(self): # creates variable to be updated by the user. values are further obtained by the .get() method self.nC_1 = DoubleVar() self.nC_1.set(1.) self.nC_2 = DoubleVar() self.nC_2.set(1.) self.nC_3 = DoubleVar() self.nC_3.set(1.) self.nL1_1 = DoubleVar() self.nL1_1.set(1.) self.nL1_2 = DoubleVar() self.nL1_2.set(1.62) self.nL1_3 = DoubleVar() self.nL1_3.set(1.) self.nL2_1 = DoubleVar() self.nL2_1.set(1.62) self.nL2_2 = DoubleVar() self.nL2_2.set(1.62) self.nL2_3 = DoubleVar() self.nL2_3.set(1.62) self.nSub_1 = DoubleVar() self.nSub_1.set(1.61) self.nSub_2 = DoubleVar() self.nSub_2.set(1.61) self.nSub_3 = DoubleVar() self.nSub_3.set(1.61) self.TL_1 = DoubleVar() self.TL_1.set(2.3) self.TL_2 = DoubleVar() self.TL_2.set(2.) self.TChan = DoubleVar() self.TChan.set(3.1) self.WL = DoubleVar() self.WL.set(0.64) self.OPR = DoubleVar() self.OPR.set(1.97) self.vVaryH1LC_H1 = StringVar() self.vVaryH1LC_H1.set('1.0 to 4.0') self.vVaryH1LC_LC = StringVar() self.vVaryH1LC_LC.set('1.5 to 5.0') self.vVaryH1LC_H2 = DoubleVar() self.vVaryH1LC_H2.set(1.0) self.vVaryH1LC_SaveAs = StringVar() self.vVaryH1LC_SaveAs.set('Filename') self.vSimulat = DoubleVar() self.vSimulat.set(np.zeros((1, 1))) self.LC_1 = DoubleVar() self.LC_1.set(1.5) self.LC_2 = DoubleVar() self.LC_2.set(5.0) self.H1_1 = DoubleVar() self.H1_1.set(1.) self.H1_2 = DoubleVar() self.H1_2.set(4.) self.H2value = DoubleVar() self.H2value.set(1.) self.grating_period = DoubleVar() self.grating_period.set(0.83) self.diffraction_mode = IntVar() self.diffraction_mode.set(1) self.Nmodes = IntVar() self.Nmodes.set(2) self.TraceMode_var = BooleanVar() self.TraceMode_var.set(False) self.TraceIntensity_var = BooleanVar() self.TraceIntensity_var.set(True) self.FileName = StringVar() self.FileName.set("filename.ecc") self.dir_label = StringVar() self.dir_label.set( (os.getcwd() + "/" + self.FileName.get()).replace(os.sep, '/')) self.WorkDir = StringVar() #for the profile self.x_cut = DoubleVar() self.x_cut.set(3.1) self.y_cut = DoubleVar() self.y_cut.set(2.3) self.Var_var = StringVar() self.Var_var.set("n_rib") self.X1_var = DoubleVar() self.X1_var.set(1.614) self.X2_var = DoubleVar() self.X2_var.set(1.62) self.dX_var = DoubleVar() self.dX_var.set(0.001) self.addX_var = DoubleVar() self.addX_var.set(0.0) self.addY_var = DoubleVar() self.addY_var.set(0.0) self.FileName_var = StringVar() self.FileName_var.set("Data") self.Show_Struct_var = BooleanVar() self.Show_Struct_var.set(False) self.SaveFile_var = BooleanVar() self.SaveFile_var.set(True) self.Dn_diff_var = BooleanVar() self.Dn_diff_var.set(False) self.dir_label_var = StringVar() self.dir_label_var.set( (os.getcwd() + "/" + self.FileName_var.get()).replace(os.sep, '/')) def create_widgets(self): topframe = Frame(self.master) topframe.pack() nbook = ttk.Notebook(topframe) f1 = ttk.Frame(nbook) f2 = ttk.Frame(nbook) f3 = ttk.Frame(nbook) nbook.add(f1, text="Simulation") nbook.add(f2, text="Mapping") nbook.add(f3, text="Variable effect") nbook.pack() FrameDessous = Frame(self.master) FrameDessous.pack(side=BOTTOM) Button(FrameDessous, text="Close", fg='red', command=self.close_all).pack(side=LEFT) Button(FrameDessous, text="Close plots", fg='red', command=self.close_plots).pack(side=LEFT) #---- Tab 1 ------------- frame f1 tf1 = ttk.Frame(f1) tf1.pack() FrameStruct.LaFrame(tf1,\ self.nC_1,self.nC_2,self.nC_3,self.nL1_1,self.nL1_2,self.nL1_3,self.nL2_1,self.nL2_2,self.nL2_3,\ self.nSub_1,self.nSub_2,self.nSub_3,self.TL_1,self.TL_2,self.TChan).pack() FrameLbdaORMode.LaFrame(tf1, self.WL, self.OPR, self.Nmodes, self.TraceMode_var, self.TraceIntensity_var).pack() bf1 = ttk.Frame(f1) bf1.pack(side=BOTTOM) self.ButtonsSimulOne(bf1).pack() #----------- tab 2 ------------ frame f2 tf2 = ttk.Frame(f2) tf2.pack() FrameMapping.LaFrame(tf2,\ self.H1_1, self.H1_2, self.LC_1,self.LC_2, self.H2value\ ).pack(side=LEFT) FrameFileNameXY.LaFrame(tf2,\ self.FileName, self.x_cut, self.y_cut,self.dir_label).pack(side=LEFT) bf2 = ttk.Frame(f2) bf2.pack(side=BOTTOM) self.ButtonsMapping(bf2).pack() #----------- tab 3 ------------ frame f3 tf3 = ttk.Frame(f3) tf3.pack() FrameVariable.LaFrame(tf3, self.Var_var, self.X1_var, self.X2_var, self.dX_var, self.addX_var, self.addY_var, self.dir_label_var, self.FileName_var, self.Show_Struct_var, self.SaveFile_var, self.Dn_diff_var).pack(side=LEFT) bf3 = ttk.Frame(f3) bf3.pack(side=BOTTOM) self.ButtonsVariable(bf3).pack() def ButtonsSimulOne(self, topframe): frame = Frame(topframe, bd=3, pady=2) # frame.pack() Button(frame, text="Solve", fg='green', command=self.Solve).pack(side=LEFT) Button(frame, text="Plot_indices", fg='green', command=self.Plot_indices).pack(side=LEFT) return frame def ButtonsMapping(self, topframe): frame = Frame(topframe, bd=3, pady=2) self.Save_as_en = Button(topframe, text="Save As", command=lambda: self.file_save_as()) self.Save_as_en.pack(side=LEFT) Button(topframe, text="Simulate", fg='Green', command=self.Simulate).pack(side=LEFT) Button( topframe, text="Browse A File", command=lambda: self.my_fileDialog(tab="Mapping")).pack(side=LEFT) Button(topframe, text="Plot Ecc.", command=lambda: self.plot_simulate_ecc()).pack(side=LEFT) Button(topframe, text="Plot S3", command=lambda: self.plot_simulate_ecc(What_plot='S3')).pack( side=LEFT) Button(topframe, text="Plot \u0394n", command=self.plot_simulate_dn).pack(side=LEFT) Button(topframe, text="Plot profile_ecc", fg='green', command=lambda: self.plot_line_profile()).pack(side=LEFT) Button(topframe, text="Plot profile_S3", fg='green', command=lambda: self.plot_line_profile(What_plot='S3')).pack( side=LEFT) return frame def ButtonsVariable(self, topframe): frame = Frame(topframe, bd=3, pady=2) Button(topframe, text="Simulate", command=lambda: self.Simulate_Var()).pack(side=LEFT) Button( topframe, text="Browse A File", command=lambda: self.my_fileDialog(tab="Variable")).pack(side=LEFT) #Button(topframe, text="Plot DnSc",command=lambda:self.plot_simulate_ecc()).pack(side=LEFT) Button(topframe, text="Plot TE0TM0", fg='green', command=lambda: self.plot_Variable( What_plot=True, Add_point=False)).pack(side=LEFT) #Button(topframe, text="Add", command=lambda:self.plot_Variable(What_plot=True,Add_point=True)).pack(side=LEFT) return frame def Plot_indices(self): self.g = Channel(wl=self.WL.get(), pas=0.1, \ nc=self.nC_1.get(), nc_2=self.nC_2.get(), nc_3=self.nC_3.get(), Hc=0.8, \ LC=self.TChan.get(), LB=5., LB_R=5., \ n1B=self.nL1_1.get(), n1C=self.nL1_2.get(), n1D=self.nL1_3.get(), H1=self.TL_1.get(), \ n2B=self.nL2_1.get(), n2C=self.nL2_2.get(), n2D=self.nL2_3.get(), H2=self.TL_2.get(), \ nsub=self.nSub_1.get(), nsub_2=self.nSub_2.get(), nsub_3=self.nSub_3.get(), Hsub=2., OR=self.OPR.get()) self.g.Traceindice() def my_fileDialog(self, tab="Mapping"): # to brows the file if tab == "Mapping": self.vSimulat = filedialog.askopenfilename(initialdir=os.getcwd(),\ title="Select A File",filetypes=[('ecc',"*.ecc"),('All files', '*')]) if self.vSimulat: self.dr = np.loadtxt(self.vSimulat, delimiter=' ', comments='#') #self.df.to_numpy() self.line15 = open(self.vSimulat, "r").readlines()[15] if 'Dimentions of the graph are:' in self.line15: X = self.line15.strip('#') X = X.strip('Dimentions of the graph are:') X = X.strip('\n') self.dimentions_var = np.fromstring(X, dtype=np.float, sep=',') self.LC_1.set(self.dimentions_var[0]) self.LC_2.set(self.dimentions_var[1]) self.H1_1.set(self.dimentions_var[3]) self.H1_2.set(self.dimentions_var[4]) else: messagebox.showinfo( "Warning", 'please check your file to see if the dimentions are in line 15' ) else: messagebox.showinfo("Warning", 'Please choose a file to plot') elif tab == "Variable": self.Browse_var=filedialog.askopenfilename(initialdir=os.getcwd(),\ title="Select A File",filetypes=[('TE0TM0',"*.TE0TM0"),('All files', '*')]) if self.Browse_var: self.DnSc_TE0TM0 = np.loadtxt( self.Browse_var, delimiter=' ', comments='#') #self.df.to_numpy() else: messagebox.showinfo("Warning", 'Please choose a file to plot') def file_save_as(self): """Ask the user where to save the file and save it there. Returns True if the file was saved, and False if the user cancelled the dialog. """ self.save_as_path = filedialog.askdirectory( initialdir=os.getcwd(), title="Select As") #,filetypes=("json", "*.json") if self.save_as_path: os.chdir(self.save_as_path) self.dir_label.set( (os.getcwd() + "/" + self.FileName.get()).replace(os.sep, '/')) else: messagebox.showinfo("Warning", 'Please try again to save the file') def plot_line_profile(self, What_plot='ecc'): fig, main_ax = plt.subplots(figsize=(6, 6)) divider = make_axes_locatable(main_ax) top_ax = divider.append_axes("top", 1.05, pad=0.1, sharex=main_ax) right_ax = divider.append_axes("right", 1.05, pad=0.1, sharey=main_ax) self.curX = self.x_cut.get( ) # position of the vertical line They should be always a float with one decimal like 1.1 or 1.2 etc... self.curY = self.y_cut.get() # position of the horizontal line self.w_array = np.arange( self.LC_1.get(), self.LC_2.get(), 0.1 ) # introduce the x axis scale (xmin,xmax,step) we should know all these three parameters from the file we introduce in the next step self.h_array = np.arange( self.H1_1.get(), self.H1_2.get(), 0.1) # introduce the y axis scale (ymin,ymax,step) self.DnCB = ((0.001 * (float(self.WL.get())) * float(self.OPR.get())) / 180) ecc = (self.DnCB / (self.dr + np.sqrt(self.DnCB**2 + self.dr**2)) ) # define eccentricity matrix # make some labels invisible top_ax.xaxis.set_tick_params(labelbottom=False) right_ax.yaxis.set_tick_params(labelleft=False) main_ax.set_xlabel('W (\u03BCm)') main_ax.set_ylabel('H (\u03BCm)') top_ax.set_ylabel(r'E$_{cc}$') right_ax.set_xlabel(r'E$_{cc}$') z_max = 1 # z.max() self.curX = np.around(float(self.curX), 2) self.curY = np.around(float(self.curY), 2) if What_plot == 'S3': ecc = np.sin(2 * np.arctan( (np.real(ecc))**-1)) # this line is to plot S3 im = main_ax.imshow(ecc, cmap="nipy_spectral", extent=[ self.LC_1.get(), self.LC_2.get(), self.H1_1.get(), self.H1_2.get() ], origin='lower') main_ax.autoscale(enable=False) right_ax.autoscale(enable=False) top_ax.autoscale(enable=False) right_ax.set_xlim(right=z_max) top_ax.set_ylim(top=z_max) self.v_line = main_ax.axvline(self.curX, color='b') self.h_line = main_ax.axhline(self.curY, color='g') self.v_prof, = right_ax.plot( ecc[:, (np.argmax( np.where( np.around(self.w_array, 2) == self.curX, self.w_array, 0)) )], self.h_array, 'b-' ) # (np.argmax(np.where(np.around(self.h_array,2)==self.curY,self.h_array,0))) self.h_prof, = top_ax.plot( self.w_array, ecc[(np.argmax( np.where( np.around(self.h_array, 2) == self.curY, self.h_array, 0)) ), :], 'g-' ) # (np.argmax(np.where(np.around(self.w_array,2)==self.curX,self.w_array,0))) if What_plot == 'S3': cax = divider.new_vertical(size="5%", pad=0.4, title="Stokes parameter S3") else: cax = divider.new_vertical(size="5%", pad=0.4, title="Eccentricity") fig.add_axes(cax) fig.colorbar(im, cax=cax, orientation="horizontal") cax.set_xlim(0, 1) cax.set # plt.savefig('colorbar_positioning_03.png', format='png', bbox_inches='tight')################## plt.show() def plot_simulate_ecc(self, What_plot='ecc'): if self.vSimulat: fig, self.ax = plt.subplots(figsize=(8, 6)) #plt.title("Eccentricy as a function of channel dimensions") print("Optcal rotaion is: " + str(self.OPR.get())) self.DnCB = ((0.001 * (float(self.WL.get())) * float(self.OPR.get())) / 180) print("Circular bireferengence (CB) is: " + str(self.DnCB)) ecc = self.DnCB / (self.dr + np.sqrt(self.DnCB**2 + self.dr**2)) if What_plot == 'S3': ecc = np.sin(2 * np.arctan( (np.real(ecc))**-1)) # this line is to plot S3 im = plt.imshow(ecc, cmap="nipy_spectral", extent=[ self.LC_1.get(), self.LC_2.get(), self.H1_1.get(), self.H1_2.get() ], origin='lower') plt.xlabel('W (\u03BCm)') plt.ylabel('H (\u03BCm)') divider = make_axes_locatable(self.ax) if What_plot == 'S3': cax = divider.new_vertical(size="5%", pad=0.4, title="Stokes parameter S3") else: cax = divider.new_vertical(size="5%", pad=0.4, title="Eccentricity") fig.add_axes(cax) fig.colorbar(im, cax=cax, orientation="horizontal") ###################################################################################################### mshu x y labela wash karw # plt.savefig('colorbar_positioning_03.png', format='png', bbox_inches='tight') cid = fig.canvas.mpl_connect('button_press_event', self.onclick) plt.show() plt.close() else: messagebox.showinfo("Warning", 'Please choose a file to plot') def plot_simulate_dn(self): if self.vSimulat: fig, self.ax = plt.subplots(figsize=(8, 6)) #plt.title("Modal bireferengence as a function of channel dimensions") im = plt.imshow(self.dr,cmap="nipy_spectral",norm=colors.LogNorm(vmin=self.dr.min(),\ vmax=10*self.dr.max()),extent=[self.LC_1.get(), self.LC_2.get(), self.H1_1.get()\ ,self.H1_2.get()], origin='lower') plt.xlabel('W (\u03BCm)') plt.ylabel('H (\u03BCm)') divider = make_axes_locatable(self.ax) cax = divider.new_vertical(size="5%", pad=0.4, title="Modal bireferengence") fig.add_axes(cax) fig.colorbar(im, cax=cax, orientation="horizontal") # plt.savefig('colorbar_positioning_03.png', format='png', bbox_inches='tight') cid = fig.canvas.mpl_connect('button_press_event', self.onclick) plt.show() plt.close() else: messagebox.showinfo("Warning", 'Please choose a file to plot') def plot_Variable(self, to_Plot="TE0TM0", What_plot="DnSc_plot", Add_point=True): if self.DnSc_TE0TM0 is not None and to_Plot == "TE0TM0": if self.Dn_diff_var.get() is True: plt.plot(self.DnSc_TE0TM0.T[5], self.DnSc_TE0TM0.T[1], label="TE0") plt.plot(self.DnSc_TE0TM0.T[5], self.DnSc_TE0TM0.T[2], label="TM0") plt.xlabel(self.Var_var.get() + "_difference") else: plt.plot(self.DnSc_TE0TM0.T[0], self.DnSc_TE0TM0.T[1], label="TE0") plt.plot(self.DnSc_TE0TM0.T[0], self.DnSc_TE0TM0.T[2], label="TM0") plt.xlabel(self.Var_var.get()) plt.ylabel('TE0 & TM0 n_eff') plt.title("TE0 & TM0 dispersion curves") plt.legend() if What_plot: fig, (ax_top, ax_bottom) = plt.subplots(nrows=2, ncols=1, sharex=True, figsize=(12, 6)) fig.suptitle( "Modal bireferengence evolution Vs Channel refractive index" ) ax_top.set_ylabel("nTE - nTM (Δn)", fontsize=12, color='k') #(r"10$^{-5}$ X Δn") ax_bottom.set_ylabel(r"S$_3$", fontsize=12, color='k') ax_bottom.set_xlabel("Channel refractive index", fontsize=12, color='k') ax_top.grid(True) ax_bottom.grid(True) CB = ((0.001 * (self.WL.get()) * self.OPR.get()) / 180) ax_top.plot(self.DnSc_TE0TM0.T[0], self.DnSc_TE0TM0.T[3]) ax_bottom.plot(self.DnSc_TE0TM0.T[0], np.sin(np.arctan(CB / self.DnSc_TE0TM0.T[3]))) #plt.xlabel(self.Var_var.get()) plt.show() #elif What_plot and Add_point: # plt.scatter(self.addX_var.get(),self.addY_var.get()) else: messagebox.showinfo("Warning", 'Please choose a file to plot') def onclick(self, event): print('button=%d, x=%d, y=%d, xdata=%f, ydata=%f' % (event.button, event.x, event.y, event.xdata, event.ydata)) self.ax.plot(event.xdata, event.ydata, 'k+', markersize=15) plt.show() def close_all(self): # Button(self.root,text = 'Click Me', command=lambda:[self.funcA(), self.funcB(), self.funcC()]) self.master.destroy() plt.close('all') def Simulate_Var(self): self.g = Channel(wl=self.WL.get(), pas=0.1, \ nc=self.nC_1.get(), nc_2=self.nC_2.get(), nc_3=self.nC_3.get(), Hc=0.8, \ LC=self.TChan.get(), LB=5., LB_R=5., \ n1B=self.nL1_1.get(), n1C=self.nL1_2.get(), n1D=self.nL1_3.get(), H1=self.TL_1.get(), \ n2B=self.nL2_1.get(), n2C=self.nL2_2.get(), n2D=self.nL2_3.get(), H2=self.TL_2.get(), \ nsub=self.nSub_1.get(), nsub_2=self.nSub_2.get(), nsub_3=self.nSub_3.get(), Hsub=2., OR=self.OPR.get()) self.g.VariaX(X0=self.X1_var.get(),X1=self.X2_var.get(),dX=self.dX_var.get(),variable=self.Var_var.get()\ ,trace=True,Show_Struct=self.Show_Struct_var.get(),SaveFile=self.SaveFile_var.get(),fich=self.FileName_var.get()) def Solve(self): self.g = Channel(wl=self.WL.get(), pas=0.1, \ nc=self.nC_1.get(), nc_2=self.nC_2.get(), nc_3=self.nC_3.get(), Hc=0.8, \ LC=self.TChan.get(), LB=5., LB_R=5., \ n1B=self.nL1_1.get(), n1C=self.nL1_2.get(), n1D=self.nL1_3.get(), H1=self.TL_1.get(), \ n2B=self.nL2_1.get(), n2C=self.nL2_2.get(), n2D=self.nL2_3.get(), H2=self.TL_2.get(), \ nsub=self.nSub_1.get(), nsub_2=self.nSub_2.get(), nsub_3=self.nSub_3.get(), Hsub=2., OR=self.OPR.get()) self.g.Calcule(Nmodes=self.Nmodes.get(), trace=self.TraceIntensity_var.get(), traceMode=self.TraceMode_var.get()) plt.show() def NumOf_guided_modes( self): # This will print angles which can give coupled light. print( "Coupling neff is calculated with equation\n n_eff=n_top.sin(\u03B8) + (m.(\u03BB/\u039B) \n where " "n_eff is effective refractive index, n_top is refractive index of the cover\n" "\u03B8 is coupling angle,m is diffraction mode, \u03BB is wavelength, and \u039B is grating period" ) self.g = Channel(wl=self.WL.get(), pas=0.1, \ nc=self.nC_1.get(), nc_2=self.nC_2.get(), nc_3=self.nC_3.get(), Hc=0.8, \ LC=self.TChan.get(), LB=5., LB_R=5., \ n1B=self.nL1_1.get(), n1C=self.nL1_2.get(), n1D=self.nL1_3.get(), H1=self.TL_1.get(), \ n2B=self.nL2_1.get(), n2C=self.nL2_2.get(), n2D=self.nL2_3.get(), H2=self.TL_2.get(), \ nsub=self.nSub_1.get(), nsub_2=self.nSub_2.get(), nsub_3=self.nSub_3.get(), Hsub=2., OR=self.OPR.get()) if self.g.NmaxPlan( ) == 0: # blow H2==0.9 NmaxPlan is 0 and it does not give good value. messagebox.showinfo( "Hey", 'It looks like NmaxPlan is {}'.format(self.g.NmaxPlan())) pass else: for i in np.real( (self.g.NumOf_guidedModes(Nmodes=self.Nmodes.get())[1:])): print( "For the {:.4f} mode there is one coupling angle at {:.4f}" .format(i, self.Nmode_effective(i))) def Nmode_effective( self, n_eff ): # to find n_e that is effective refractive index of the grating '''This method returns guided modes of the structure (not leaky modes)''' #print(self.grating_period,self.diffraction_mode) n_top = np.average( np.array([self.nC_1.get(), self.nC_2.get(), self.nC_3.get()])) m = self.diffraction_mode.get() WL = self.WL.get() GP = self.grating_period.get() TheSin = (n_eff - m * WL / GP) / n_top if np.abs(TheSin) > 1: theta = 0 else: theta = np.rad2deg(np.arcsin(TheSin)) return theta def Simulate(self): if messagebox.askyesno( "Warning! ", 'This may take several minutes\n Are you sure you want to continue?' ): messagebox.showinfo( "Simulation", 'You can see the see the remaining time in the run window') self.g = Channel(wl=self.WL.get(), pas=0.1, \ nc=self.nC_1.get(), nc_2=self.nC_2.get(), nc_3=self.nC_3.get(), Hc=0.8, \ LC=self.TChan.get(), LB=5., LB_R=5., \ n1B=self.nL1_1.get(), n1C=self.nL1_2.get(), n1D=self.nL1_3.get(), H1=self.TL_1.get(), \ n2B=self.nL2_1.get(), n2C=self.nL2_2.get(), n2D=self.nL2_3.get(), H2=self.TL_2.get(), \ nsub=self.nSub_1.get(), nsub_2=self.nSub_2.get(), nsub_3=self.nSub_3.get(), Hsub=2., OR=self.OPR.get()) self.g.H2 = self.H2value.get() self.g.VariaXY(X0=self.LC_1.get(), X1=self.LC_2.get(), dX=0.1, Y0=self.H1_1.get(), Y1=self.H1_2.get(), dY=0.1, fich=self.FileName.get()) else: messagebox.showinfo( "Canceled", 'You have successfully canceled the simulation') def close_plots(self): plt.close('all')
#This is just plot evolution of TE0,TM0 neff and DN from the VariX method by changing the variables. from Channels_multilayer import Channel g=Channel(wl=0.64,pas=0.1,nc=1., nc_2=1., nc_3=1.,Hc=0.8,\ LB=5, LC=3.1,LB_R=5,n1B=1.,n1C=1.62,n1D=1.,H1=2.3,\ n2B=1.62,n2C=1.62,n2D=1.62,H2=2.,\ nsub=1.61,nsub_2=1.61,nsub_3=1.61,Hsub=2.,OR=2.5) #g.Calcule() g.VariaX(X0=1, X1=1.33, dX=0.01, variable='nc', trace=True, Show_Struct=False, fich="Data")