def randshow(w1): while type(a1) != None: ch_num = random.randint(0, total_port * total_lambda - 1) print("Channel # = " + str(ch_num)) image = pattern_proc.pattern_gen(0, random.randint(20, 200), pattern_size).blazgrating() lcos1.pattern_show(w1, image, ch_num) if lcos1.pattern_show(w1, image, ch_num) == False: print("Fail to change pattern! No such label with THIS NAME") break image = pattern_proc.pattern_gen(0, random.randint(-200, 200), pattern_size).blazgrating()
def scan_ASE(self, w, ch_num, ang, pitch_range): num = w.objectName()[-1:] try: x = w.findChild( QtGui.QLabel, num + "_" + str(int(numpy.floor(ch_num / self.total_w))) + "_" + str( (ch_num % self.total_w))) except: return print("No such channel!") pattern_size = [0, 0] pattern_size[0] = x.width() pattern_size[1] = x.height() Grating_pitch = numpy.linspace(pitch_range[0], pitch_range[1], (pitch_range[1] - pitch_range[0])) if self.write_mode: target_name = str(datetime.date.today()) + "_scan_ch_" + str( round(ch_num, 3)) + '.xls' if os.path.exists("./" + target_name): target_name = target_name[:-4] + "_" + time.strftime( "%H_%M") + '.xls' book = xlwt.Workbook(target_name) sheet = book.add_sheet(time.strftime("%H_%M")) pm = Q8384(int(self.appui.Q8384_ADD.value())) print(pm.get_wavelength(), pm.get_wavelength().types) print(pm.get_power()) data = numpy.zeros( [len(pm.get_wavelength()) + 1, len(Grating_pitch) + 1]) for k, pitch in enumerate(Grating_pitch): image = pattern_proc.pattern_gen(ang, int(pitch), pattern_size).blazgrating() image = ImageQt.ImageQt(image) x.setPixmap(QtGui.QPixmap.fromImage(image)) x.repaint() pm.sweep() if self.write_mode: if k == 0: try: for m, n in enumerate(pm.get_wavelength()): sheet.write(0, m + 1, float(n)) data[0, m] = float(n) except: pass else: try: sheet.write(k, 0, round(pitch)) for m, n in enumerate(pm.get_power()): sheet.write(k, m + 1, float(n)) data[k, m] = float(n) except IndexError: pass if self.write_mode: book.save(target_name) return data
def focus(self): image = pattern_proc.pattern_gen(self.ui.p_ang.value(), self.ui.scanrange_max.value(), self.pattern_size).other(0) if self.ui.LCOS1.isChecked(): self.lcos1.pattern_show(self.w1, image, self.ui.ch_num.value()) if self.ui.LCOS2.isChecked(): self.lcos1.pattern_show(self.w1, image, self.ui.ch_num.value()) return True
def scan_one(self, w, ch_num, ang, pitch_range): num = w.objectName()[-1:] try: x = w.findChild( QtGui.QLabel, num + "_" + str(int(numpy.floor(ch_num / self.total_w))) + "_" + str( (ch_num % self.total_w))) except: return print("No such channel!") pattern_size = [0, 0] pattern_size[0] = x.width() pattern_size[1] = x.height() Grating_pitch = numpy.linspace(pitch_range[0], pitch_range[1], (pitch_range[1] - pitch_range[0])) if self.write_mode: target_name = str(datetime.date.today()) + "_scan_ch_" + str( round(ch_num, 3)) + '.xls' if os.path.exists("./" + target_name): target_name = target_name[:-4] + "_" + time.strftime( "%H_%M") + '.xls' book = xlwt.Workbook(target_name) sheet = book.add_sheet(time.strftime("%H_%M")) try: pm = Q8221(int(self.appui.Q8221_ADD.value())) except: self.error_mes_handler("Connection failed!") data = numpy.zeros([1, 2]) for k, pitch in enumerate(Grating_pitch): image = pattern_proc.pattern_gen(ang, int(pitch), pattern_size).blazgrating() image = ImageQt.ImageQt(image) x.setPixmap(QtGui.QPixmap.fromImage(image)) x.repaint() wlength = self.appui.wlength.value() wlength = self.appui.wlength.value() temp = str(round(self.pitch_to_ang(wlength, pitch), 3)) self.appui.answer_of_cal.setText(temp) self.appui.answer_of_cal.repaint() value = pm.read_power() self.error_mes_handler("Detected value" + str(value) + "\n") if self.write_mode: try: sheet.write(k, 0, round(pitch)) sheet.write(k, 1, value) data = numpy.concatenate( (data, numpy.array([round(pitch), value]).reshape(1, 2))) except IndexError: pass if self.write_mode: book.save(target_name) return numpy.delete(data, 0, 0)
def random_show(self, w): ch_num = random.randint(0, self.total_w * self.total_p - 1) image = pattern_proc.pattern_gen(random.randint(0, 360), random.randint(20, 200), self.pattern_size).blazgrating() self.pattern_show(w, image, ch_num) if self.pattern_show(w, image, ch_num) == False: print("Fail to change pattern! No such label with THIS NAME") return False else: return True
def Initialize_pattern(self, w): num = w.objectName()[-1:] x = w.findChild(QtGui.QLabel, num + "_0_0") pattern_size = [0, 0] pattern_size[0] = x.width() pattern_size[1] = x.height() LCOS_dict = {} try: open("LCOS.ini", "r") except FileNotFoundError: print("Fail to find LCOS.ini !") return False with open("LCOS.ini", "r") as f: LCOS_dict = OrderedDict(x.rstrip().split(None, 1) for x in f) n = 0 pix_pitch = 3.96 th = 0 wavelength = self.appui.wlength() for k, ang in LCOS_dict.items(): ang = float(ang) / 180 * numpy.pi pitch = (pix_pitch / wavelength * (numpy.sin(th + ang) - numpy.sin(th))) pix_num = 0 if pitch != 0: pix_num = int(numpy.round(1 / pitch)) image = pattern_proc.pattern_gen( 0, pix_num, [pattern_size[0], pattern_size[1]]).blazgrating() image = ImageQt.ImageQt(image) for m in range(self.total_p): x = w.findChild(QtGui.QLabel, num + "_" + str(m) + "_" + str(n)) try: x.setPixmap(QtGui.QPixmap.fromImage(image)) except AttributeError: print(num + "_" + str(m) + "_" + str(n)) return print("No such channel!!!") x.repaint() n = n + 1 return True