예제 #1
0
def connect(change):
    global connected
    global osa

    ip = ui.ip.value
    osa = Yokogawa(ip=ip)
    if change.new:
        connected = True
        osa.connected = True
        para = osa.settings
        lbd_start = para['centwlgth'] - para['span'] / 2
        lbd_end = para['centwlgth'] + para['span'] / 2
        print((1e9 * lbd_start, 1e9 * lbd_end))
        #ax.set_xlim([1e9*lbd_start, 1e9*lbd_end])
        figOSA.update_xaxes(range=[1e9 * lbd_start, 1e9 * lbd_end])
        ui.λ.value = (1e9 * lbd_start, 1e9 * lbd_end)
        ui.bandwidth.value = Bdwt_val[1e9 * para['bdwdth']]
        ui.res.index = int(para['resol'])
        ui.pts.value = int(para['pts'])

        trace = osa.trace
        figOSA.data[0].x = trace.lbd.values * 1e9
        figOSA.data[0].y = trace.S.values

    else:
        connected = False
        osa.connected = False
    print(connected)
예제 #2
0
 def update_res(self, change):
     ip = self.ui.ip.value
     if self.connected:
         with Yokogawa(ip=ip) as osa:
             para = osa.settings
         para['resol'] = change.new
         with Yokogawa(ip=ip) as osa:
             osa.settings = para
예제 #3
0
 def update_points(self, change):
     ip = self.ui.ip.value
     if self.connected:
         with Yokogawa(ip=ip) as osa:
             para = osa.settings
         para['pts'] = change.new
         with Yokogawa(ip=ip) as osa:
             osa.settings = para
             para = osa.settings
         self.ui.pts.value = int(para['pts'])
예제 #4
0
 def update_bdwt(self, change):
     ip = self.ui.ip.value
     if self.connected:
         with Yokogawa(ip=ip) as osa:
             para = osa.settings
         para['bdwdth'] = float(change.new.replace(' nm', ''))*1e-9
         with Yokogawa(ip=ip) as osa:
             osa.settings = para
             para = osa.settings
         self.ui.bandwidth.value = self._Bdwt_val[1e9*para['bdwdth']]
예제 #5
0
def update_res(change):
    ip = ui.ip.value
    if connected:
        para = osa.settings
        para['resol'] = change.new
        with Yokogawa(ip=ip) as osa:
            osa.settings = para
예제 #6
0
def connect(change):
    global connected
    global osa
    ip = ui.ip.value
    if change.new:
        connected = True
        with Yokogawa(ip=ip) as osa:
            para = osa.settings
            trace = osa.trace
            lbd_start = para['centwlgth'] - para['span']/2
            lbd_end = para['centwlgth'] + para['span']/2
            # print((1e9*lbd_start, 1e9*lbd_end))
            #ax.set_xlim([1e9*lbd_start, 1e9*lbd_end])

            figOSA.update_xaxes(range = [1e9*lbd_start, 1e9*lbd_end])
            ui.λ.value = (1e9*lbd_start, 1e9*lbd_end)
            ui.bandwidth.value = Bdwt_val[1e9*para['bdwdth']]
            try:
                ui.res.index = int(para['resol'])
            except:
                pass
            try:
                ui.pts.value = int(para['pts'])
            except:
                pass

            time.sleep(0.5)

            figOSA.data[0].x = trace.lbd.values*1e9
            figOSA.data[0].y = trace.S.values

    else:
        connected = False
예제 #7
0
    def save_data(self, change):
        ip = self.ui.ip.value
        fname = self.ui.picker.selected

        if fname:
            if not os.path.exists(self.ui.picker.selected):
                if self.ui.to_save.value.lower() == 'pc':
                    lbd = self.figOSA.data[0].x*1e-9
                    S = self.figOSA.data[0].y
                    df = pd.DataFrame(dict(lbd = lbd, S = S))

                    if len(self.figOSA.data) > 1:
                        for ii in range(1, len(self.figOSA.data)):
                            lbd = self.figOSA.data[0].x*1e-9
                            S = self.figOSA.data[0].y
                            dum = pd.DataFrame({f'lbd{ii}': lbd, f'S{ii}': S})
                            df = pd.concat([df, dum], axis = 1)
                    df.to_parquet(fname)
                else:
                    with Yokogawa(ip=ip) as osa:
                        if osa.connected:
                            trace = osa.trace
                            save_ok = True
                        else:
                            save_ok = False
                            print("Cannot coonect!!")
                    if save_ok:
                        trace.to_parquet(fname)
예제 #8
0
 def _repeatScan(self):
     self._scan = True
     ip = self.ui.ip.value
     with Yokogawa(ip=ip) as osa:
         print('Launching a Continuous scan')
         self.figOSA.data[0].x = []
         self.figOSA.data[0].y = []
         osa.scan = 'repeat'
         print('Launching a Continuous scan')
         while True: 
             time.sleep(0.01)
             trace = osa.trace
 
             if not(trace is None): 
                 x = trace.lbd*1e9
                 y = trace.S
                 if self.ui.freq_scale.value.lower() == 'frequency':
                     x = 1e-12*cts.c/(x*1e-9)
                 self.figOSA.data[0].x = x
                 self.figOSA.data[0].y = trace.S
             else:
                 time.sleep(0.25)
             if self._scan == False: 
                 print('!!!stop the loop!!!')
                 break
예제 #9
0
 def _singleScan(self):
     self._scan = True
     
     ip = self.ui.ip.value
     
     with Yokogawa(ip=ip) as osa:
         
         self.figOSA.data[0].x = []
         self.figOSA.data[0].y = []
         osa.scan = 'single'
         print('Launching a single scan')
         while True: 
             print('getting traces')
             time.sleep(0.01)
             trace = osa.trace
             if trace: 
                 x = trace.lbd*1e9
                 y = trace.S
                 if self.ui.freq_scale.value.lower() == 'frequency':
                     x = 1e-12*cts.c/(x*1e-9)
                 self.figOSA.data[0].x = x
                 self.figOSA.data[0].y = trace.S
             else:
                 print(trace)
             time.sleep(0.25)
             if self._scan == False: 
                 print('!!!stop the loop!!!')
                 break
예제 #10
0
def save_data(change):
    ip = ui.ip.value
    fname = ui.picker.selected
    if fname:
        if not os.path.exists(ui.picker.selected):
            with Yokogawa(ip=ip) as osa:
                trace = osa.trace
            trace.to_parquet(fname)
예제 #11
0
 def _stopScan(self):
     self._scan = False
     ip = self.ui.ip.value
     print(ip)
     time.sleep(0.5)
     with Yokogawa(ip=ip) as osa:
         osa.scan = 'stop'
         print('stopped')
         self._scan = False
예제 #12
0
def update_points(change):
    ip = ui.ip.value
    if connected:
        para = osa.settings
        para['pts'] = change.new
        with Yokogawa(ip=ip) as osa:
            osa.settings = para
            para = osa.settings
        ui.pts.value = int(para['pts'])
예제 #13
0
 def update_λ(self, change):
     ip = self.ui.ip.value
     if self.connected:
         # print(change.new)
         centwlgth =  (change.new[1] + change.new[0])/2
         span = (change.new[1] - change.new[0])
         time.sleep(1)
         with Yokogawa(ip=ip) as osa:
             para = osa.settings
         
         if self.DEBUG:
             print(para)
         para['centwlgth'] = centwlgth*1e-9
         para['span'] = span*1e-9
         if self.DEBUG:
             print(para)
         with Yokogawa(ip=ip) as osa:
             osa.settings = para
         self.figOSA.update_xaxes(range = change.new)
예제 #14
0
def scan_osa(change):
    global thread_osa
    global run_thread
    run_thread = False
    ip = ui.ip.value
    if connected:
        # osa.scan = change.new.lower()
        run_thread = False
        if change.new.lower() == 'single' or change.new.lower() == 'repeat':
            with Yokogawa(ip=ip) as osa:
                osa.scan = change.new.lower()
                run_thread = True
                thread_osa = threading.Thread(target=worker, args=(figOSA, osa))
                thread_osa.start()
        if change.new.lower() == 'stop':
            with Yokogawa(ip=ip) as osa:
                osa.scan = change.new.lower()

            print('Trying to kill the stuff')
            run_thread = False
예제 #15
0
def update_λ(change):
    ip = ui.ip.value
    if connected:
        # print(change.new)
        centwlgth =  (change.new[1] + change.new[0])/2
        span = (change.new[1] - change.new[0])
        with Yokogawa(ip=ip) as osa:
            para = osa.settings
            para['centwlgth'] = centwlgth*1e-9
            para['span'] = span*1e-9
            print(para)
            osa.settings = para

        figOSA.update_xaxes(range = change.new)
예제 #16
0
    def refreshTrace(self, change):
        ip = self.ui.ip.value
        if self.connected:
            with Yokogawa(ip=ip) as osa:
                if osa.connected:
                    trace = osa.trace

            x = trace.lbd*1e9
            y = trace.S
            if self.ui.freq_scale.value.lower() == 'frequency':
                x = 1e-12*cts.c/(x*1e-9)

            self.figOSA.data[0].x = x
            self.figOSA.data[0].y = trace.S
예제 #17
0
    def connect(self, change):
        ip = self.ui.ip.value
        if change.new:
            try_connect = 0
            while try_connect < 5:
                with Yokogawa(ip=ip) as osa:
                    # -- fetch the OSA state
                    if osa.connected:
                        try_connect += 1
                        print(try_connect)
                        identity  = osa.identity
                        if self.DEBUG:
                            print(f'Model:{identity}')
                            print(f'Model:{self.OSAmodel}')
                            print(f"Model:{self.OSAmodel[identity['model']]}")
                        if self.DEBUG:
                            print('Connected to the OSA')
                        try: 
                            para = osa.settings
                            if self.DEBUG:
                                print('Fetched parameters')
                        except Exception as err:
                            print(err)
                            
                        trace = osa.trace
                        if self.DEBUG:
                            print('Fetched traces')
                        
                        break
                    else:
                        try_connect += 1
                        print('Did not connect, retrying...')
                        time.sleep(0.5)
      
            self.figOSA.data[0].x = []
            self.figOSA.data[0].y = []
            # time.sleep(1)

            # close the socket, no need anymore
            # -- updating the UI
            if try_connect >=5:
                print("Couldn't connect to the OSA, please check the IP")
            else:
                self.connected = True
                if self.DEBUG:
                    print('Finished Connecting')

                model = identity['model']
                if self.DEBUG:
                    print(f"Model: {model}")
                self.ui.model.value =  f"Maker: {identity['maker']}\n"  + \
                                      f"Model: {model}\n" + \
                                      f"SN: {identity['SN']}\n\n" + \
                                      f"Spectral range:\n\t {self.OSAmodel[model]['span'][0]}nm - {self.OSAmodel[model]['span'][1]}nm\n"

                lbd_start = para['centwlgth'] - para['span']/2
                lbd_end = para['centwlgth'] + para['span']/2
                if self.DEBUG:
                    print(f'Start: {lbd_start}')
                    print(f'End: {lbd_end}')

                self.ui.λ.min =  self.OSAmodel[model]['span'][0]
                self.ui.λ.max =  self.OSAmodel[model]['span'][1]
                self.ui.λ.value = (1e9*lbd_start, 1e9*lbd_end)
                try:
                    self.ui.bandwidth.value = self._Bdwt_val[1e9*para['bdwdth']]
                except Exception as err:
                    if self.DEBUG:
                        print(f'Badnwidth Error: {err}')
                        print(f"Value: {1e9*para['bdwdth']}")

                try:
                    self.ui.res.index = int(para['resol'])
                except Exception as err:
                    if self.DEBUG:
                        print(f'Res Error: {err}')
                        print(f"Value: {para['resol']}")
                try:
                    self.ui.pts.value = int(para['pts'])
                except Exception as err:
                    if self.DEBUG:
                        print(f'Pts Error: {err}')
                        print(f"Value: {para['pts']}")

                self.figOSA.data[0].x = trace.lbd.values*1e9
                self.figOSA.data[0].y = trace.S.values
                self.figOSA.update_xaxes(autorange = True)
                self.figOSA.update_xaxes(autorange = False)
                self.figOSA.update_xaxes(range = [self.figOSA.layout.xaxis.range[0],
                                            self.figOSA.layout.xaxis.range[1]])

                self.figOSA.update_yaxes(autorange = True)
                time.sleep(0.2)
                self.figOSA.update_yaxes(autorange = False)
                self.figOSA.update_yaxes(range = [-59, self.figOSA.layout.yaxis.range[-1]])
                time.sleep(0.5)
                self.figOSA.update_yaxes(range = [-85, self.figOSA.layout.yaxis.range[-1]])

        else:
            self.connected = False
예제 #18
0
def select_trace(change):
    ip = ui.ip.value
    if connected:
        with Yokogawa(ip=ip) as osa:
            osa.trace = change.new.replace('Trace ', '')