Exemple #1
0
    def __init__(self, port=PORT, timeout=None, verbose=False,Nr=1,Nt=1,emulated = False):
        """
        Parameters
        ----------

        host : ip address
        port : port:1
        timeout: float
        verbose : boolean

        """
        self.emulated = emulated
        if "VNA_IP" in os.environ:
            host = os.environ["VNA_IP"]
        else:
            print "VNA IP not defined"
            exit
        if not self.emulated:
            try:
                self.host = host
                self._verbose = verbose
                self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                if timeout is not None:
                    self.s.settimout(timeout)
                    self._timeout = timeout

                self.s.connect((host, port))
            except socket.error as e:
                if self._verbose:
                    print 'SCPI>> connect({:s}:{:d}) failed {:s}', format(host, port, e)
                else:
                    pass
                    #self.emulated = True


        self.Nf   = 201
        self.getIdent()
        print self.ident
        #assert('E5072A' in self.ident), "E5072A not responding"
        self.freq()
        self.points()
        self.parS()
        self.avrg()
        self.ifband()
        self.power_level()

        #self.getdata()

        #initialization of the switch
        if (Nr!=1) and (Nt!=1) and not self.emulated:
            self.switch = sw.get_adapter()
            reattach=False
            if not self.switch:
                raise Exception("No device found")

            #self.switch.device
            self.switch.set_io_mode(0b11111111, 0b11111111, 0b00000000)
Exemple #2
0
    def __init__(self, port=PORT, timeout=None, verbose=False,Nr=1,Nt=1,emulated = False):
        """
        Parameters
        ----------

        host : ip address
        port : port:1
        timeout: float
        verbose : boolean

        """
        self.emulated = emulated
        if "VNA_IP" in os.environ:
            host = os.environ["VNA_IP"]
        else:
            print "VNA IP not defined"
            exit
        try:
            self.host = host
            self._verbose = verbose
            self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            if timeout is not None:
                self.s.settimout(timeout)
                self._timeout = timeout

            self.s.connect((host, port))
        except socket.error as e:
            if self._verbose:
                print 'SCPI>> connect({:s}:{:d}) failed {:s}', format(host, port, e)
            else:
                #self.emulated = True
                self.emulated = False


        
        self.Nf   = 201
        self.getIdent()
        print self.ident
        assert('E5072A' in self.ident), "E5072A not responding"
        self.freq()
        self.points()
        self.parS()
        self.avrg()
        self.ifband()
        
        #self.getdata()

        #initialization of the switch
        if (Nr!=1) and (Nt!=1) and not self.emulated:
            self.switch = sw.get_adapter()
            reattach=False
            if not self.switch:
                raise Exception("No device found")

            #self.switch.device
            self.switch.set_io_mode(0b11111111, 0b11111111, 0b00000000)
Exemple #3
0
    def calibh5(
        self,
        Nr=4,
        Nt=8,
        _filemesh5='measures',
        _filecalh5='mcalib',
        _filecal='cal_config.ini',
        _filevna='vna_config.ini',
        typ='full',
        gcalm=1,
        cables=[],
        author='',
        comment='',
    ):
        """  measure a calibration vector and store in h5 file

        Parameters
        ----------

        Nr : int
        Nt : int
        _filemesh5 : string
            measurement data file prefix
        _filecalh5 : string
            multi antenna calibration data file prefix
        _filecal : string
            variable parameters calibration .ini configuration file name
        _filevna : string
            vna .ini configuration file name
        typ : string
            'full' | 'single'
        gcalm : int
            selected calibration group of _filecalh5 (used only if typ=='single')
        cables : list of strings
        author
        comment

        """

        # set config
        # File from : ~/Pylayers_project/meas

        switch = sw.get_adapter()
        if not switch:
            raise Exception("No device found")
        switch.set_io_mode(0b11111111, 0b11111111, 0b00000000)
        #set the NI USB mode in order to use

        # store calibration vector in a hdf5 file

        # SISO case
        #     + calibration is saved in the measurement file
        #     + calibration variable parameters are read in _filecal
        #
        # MIMO case
        #     if typ is 'full'
        #       + calibration are saved in the calibration file
        #       + calibration variable parameters are read in _filecal
        #     else
        #       + a single channel calibration is saved in the measurement file
        #       + calibration variable parameters are read in _filecalh5
        #

        Mr = Nr
        Mt = Nt
        # SISO case
        if (Nr == 1) and (Nt == 1):
            fileh5w = pyu.getlong(_filemesh5, pstruc['DIRMES']) + '.h5'
            self.load_config_vna(_filename=_filevna)
            dcal = self.load_calconfig(_filename=_filecal)
        else:
            # MIMO case
            if typ == 'full':
                fileh5w = pyu.getlong(_filecalh5, pstruc['DIRMES']) + '.h5'
                self.load_config_vna(_filename=_filevna)
                dcal = self.load_calconfig(_filename=_filecal)
            if typ == 'single':
                Mr = 1
                Mt = 1

                fileh5w = pyu.getlong(_filemesh5, pstruc['DIRMES']) + '.h5'
                # dcal is obtained from _filecalh5 and gcal
                dcal = Mesh5(_filecalh5).get_dcal(gcalm)
                # In a future version it would be better to load from the
                # parameter which are in the MIMO calibration file instead
                # of thevna_config
                self.load_config_vna(_filename=_filevna)

        f = h5py.File(fileh5w, "a")
        try:
            ldataset = f.keys()
        except:
            ldataset = []

        lcal = filter(lambda x: 'cal' in x, ldataset)
        calname = 'cal' + str(len(lcal) + 1)
        cal = f.create_group(calname)

        tic = time.time()

        for iT in range(Mt):
            print "connect transmitter :", iT + 1
            switch.write_port(0, iT)
            for iR in range(Mr):
                switch.write_port(1, iR)
                print "connect receiver :", iR + 1
                c = ""
                while "g" not in c:
                    c = raw_input("Hit g key ")

                for k in dcal:
                    print "---------------------------------------------------------------------"
                    print "                 Configuration Parameters                            "
                    print dcal[k]
                    print "---------------------------------------------------------------------"

                    t1 = time.time()
                    for k2 in dcal[k]:
                        if k2 == 'nf':
                            self.points(dcal[k]['nf'], cmd='set')
                            print "set number of points  :", dcal[k]['nf']
                        if k2 == 'ifbhz':
                            self.ifband(ifbHz=dcal[k]['ifbhz'], cmd='set')
                            print "set number of ifbHz   :", dcal[k]['ifbhz']
                        if k2 == 'navrg':
                            self.avrg(b='ON',
                                      navrg=dcal[k]['navrg'],
                                      cmd='setavrg')
                        if k2 == 'power':
                            self.power_level(cmd='set', power=dcal[k]['power'])

                    #print "activation of the trigger via the BUS"
                    #get Nmeas calibration vector

                    tic_Dmeas = time.time()
                    print "beginning of the acquisition"
                    time.sleep(2)
                    Dmeas = self.getdata(chan=1,
                                         Nmeas=dcal[k]['nmeas'],
                                         calibration=True)
                    toc_Dmeas = time.time()
                    print "end of the acquisition (s) :", toc_Dmeas - tic_Dmeas

                    if ((iR == 0) and (iT == 0)):
                        cal.create_dataset(k,
                                           (dcal[k]['nmeas'], Mr, Mt, self.Nf),
                                           dtype=np.complex64)
                        cal[k].attrs['fminghz'] = self.fGHz[0]
                        cal[k].attrs['fmaxghz'] = self.fGHz[-1]
                        cal[k].attrs['time'] = time.ctime()
                        cal[k].attrs['author'] = author
                        cal[k].attrs['cables'] = cables
                        cal[k].attrs['comment'] = comment
                        cal[k].attrs['param'] = self.param
                        cal[k].attrs['nt'] = Nt
                        cal[k].attrs['nr'] = Nr
                        cal[k].attrs['nmeas'] = dcal[k]['nmeas']

                        if typ == 'single':
                            cal[k].attrs['_filecalh5'] = _filecalh5
                            cal[k].attrs['gcalm'] = gcalm

                    cal[k][:, iR, iT, :] = Dmeas[:, 0, 0, :]
                    cal[k].attrs['nf'] = self.Nf
                    cal[k].attrs['ifbhz'] = self.ifbHz
                    cal[k].attrs['navrg'] = self.navrg
                    cal[k].attrs['power'] = self.power

                    t2 = time.time()
                    print "duration set up (s) :", t2 - t1

        toc = time.time()

        print "---------------------------------------------------------"
        print "                   END of calibration                    "
        print " measurement time (s)                     :", toc - tic
        print "---------------------------------------------------------"

        f.close()
Exemple #4
0
import pylayers.measures.switch.ni_usb_6501 as sw
import time
switch = sw.get_adapter()
#reattach=False
if not switch:
    print("No device found")

#for each measurements, set up the NI USB 6501 mode : bit 1 means write and bit 0 read
#switch.set_io_mode(0b11111111, 0b11111111, 0b00000000)

#switch.write_port(1, 1) #select output 2 of the switch 1-4
#switch.write_port(1, 2) #select output 3 of the switch 1-4

#switch.write_port(0, 4) #select channel 5 of the switch 1-8
#switch.write_port(0, 5) #select channel 6 of the switch 1-8

#
#MIMO case
#

# tic = time.time()

# for k in range(8):
#     print "	Transmiter side (ULA 8) : output selected  ",k
#     switch.write_port(0,k)
#     for  l in range(4):
#         print "Receiver side (ULA 4) : output selected ",l
#         switch.write_port(1,l)
#         time.sleep(1) #time waiting of the switch between antennas
# toc = time.time()
# t = toc - tic
Exemple #5
0
    def calibh5(self,
                 Nr = 4,
                 Nt = 8,
                 _filemesh5 = 'measures',
                 _filecalh5 = 'mcalib',
                 _filecal = 'cal_config.ini',
                 _filevna='vna_config.ini',
                 typ = 'full',
                 gcalm = 1,
                 cables=[],
                 author='',
                 comment='',
                 ):
        """  measure a calibration vector and store in h5 file

        Parameters
        ----------

        Nr : int
        Nt : int
        _filemesh5 : string
            measurement data file prefix
        _filecalh5 : string
            multi antenna calibration data file prefix
        _filecal : string
            variable parameters calibration .ini configuration file name
        _filevna : string
            vna .ini configuration file name
        typ : string
            'full' | 'single'
        gcalm : int
            selected calibration group of _filecalh5 (used only if typ=='single')
        cables : list of strings
        author
        comment

        """

        # set config
        # File from : ~/Pylayers_project/meas

        switch = sw.get_adapter()
        if not switch:
            raise Exception("No device found")
        switch.set_io_mode(0b11111111, 0b11111111, 0b00000000) 
        #set the NI USB mode in order to use


        # store calibration vector in a hdf5 file

        # SISO case
        #     + calibration is saved in the measurement file
        #     + calibration variable parameters are read in _filecal
        #
        # MIMO case
        #     if typ is 'full'
        #       + calibration are saved in the calibration file
        #       + calibration variable parameters are read in _filecal
        #     else
        #       + a single channel calibration is saved in the measurement file
        #       + calibration variable parameters are read in _filecalh5
        #

        Mr = Nr
        Mt = Nt
        # SISO case
        if (Nr==1) and (Nt==1):
            fileh5w = pyu.getlong(_filemesh5, pstruc['DIRMES'])+'.h5'
            self.load_config_vna(_filename=_filevna)
            dcal = self.load_calconfig(_filename=_filecal)
        else:
        # MIMO case
            if typ=='full':
                fileh5w = pyu.getlong(_filecalh5, pstruc['DIRMES'])+'.h5'
                self.load_config_vna(_filename=_filevna)
                dcal = self.load_calconfig(_filename=_filecal)
            if typ=='single':
                Mr = 1
                Mt = 1

                fileh5w = pyu.getlong(_filemesh5, pstruc['DIRMES'])+'.h5'
                # dcal is obtained from _filecalh5 and gcal
                dcal = Mesh5(_filecalh5).get_dcal(gcalm)
                # In a future version it would be better to load from the 
                # parameter which are in the MIMO calibration file instead 
                # of thevna_config
                self.load_config_vna(_filename=_filevna)

        f = h5py.File(fileh5w, "a")
        try:
            ldataset = f.keys()
        except:
            ldataset = []

        lcal =  filter(lambda x : 'cal' in x, ldataset)
        calname = 'cal' + str(len(lcal)+1)
        cal = f.create_group(calname)

        tic = time.time()

        for iT in range(Mt):
            print "connect transmitter :", iT +1
            switch.write_port(0,iT)
            for iR in range(Mr):
                switch.write_port(1,iR)
                print "connect receiver :", iR + 1
                c = ""
                while "g" not in c:
                    c = raw_input("Hit g key ")

                for k in dcal:
                    print "---------------------------------------------------------------------"
                    print "                 Configuration Parameters                            "
                    print   dcal[k]
                    print "---------------------------------------------------------------------"
                    
                    t1 = time.time()
                    for k2 in dcal[k]:
                        if k2=='nf':
                            self.points(dcal[k]['nf'], cmd='set')
                            print "set number of points  :",dcal[k]['nf']
                        if k2=='ifbhz':
                            self.ifband(ifbHz=dcal[k]['ifbhz'], cmd='set')
                            print "set number of ifbHz   :",dcal[k]['ifbhz']
                        if k2=='navrg':
                            self.avrg(b='ON',navrg=dcal[k]['navrg'], cmd='setavrg')
                        if k2=='power':
                            self.power_level(cmd='set',power=dcal[k]['power'])

                    #print "activation of the trigger via the BUS"
                    #get Nmeas calibration vector

                    tic_Dmeas = time.time()
                    print "beginning of the acquisition"
                    time.sleep(2)
                    Dmeas = self.getdata(chan=1,Nmeas=dcal[k]['nmeas'],calibration=True)
                    toc_Dmeas = time.time()
                    print "end of the acquisition (s) :",toc_Dmeas-tic_Dmeas

                    if ((iR==0) and (iT==0)):
                        cal.create_dataset(k, (dcal[k]['nmeas'], Mr, Mt, self.Nf), dtype=np.complex64)
                        cal[k].attrs['fminghz']   = self.fGHz[0]
                        cal[k].attrs['fmaxghz']   = self.fGHz[-1]
                        cal[k].attrs['time']      = time.ctime()
                        cal[k].attrs['author']    = author
                        cal[k].attrs['cables']    = cables
                        cal[k].attrs['comment']   = comment
                        cal[k].attrs['param']     = self.param
                        cal[k].attrs['nt']        = Nt
                        cal[k].attrs['nr']        = Nr
                        cal[k].attrs['nmeas']     = dcal[k]['nmeas']
                        
                        if typ=='single':
                            cal[k].attrs['_filecalh5'] =_filecalh5 
                            cal[k].attrs['gcalm']= gcalm
                            
                    cal[k][:,iR,iT,:] = Dmeas[:,0,0,:]
                    cal[k].attrs['nf']        = self.Nf
                    cal[k].attrs['ifbhz']     = self.ifbHz
                    cal[k].attrs['navrg']     = self.navrg
                    cal[k].attrs['power']     = self.power

                    t2 =  time.time()
                    print "duration set up (s) :",t2-t1

        toc = time.time()

        print "---------------------------------------------------------"
        print "                   END of calibration                    "
        print " measurement time (s)                     :",toc-tic
        print "---------------------------------------------------------"

        f.close()
Exemple #6
0
    def meas(self,
               A,
               _fileh5='test.h5',
               gcal = 1,
               ical = 1,
               vel = 15,
               Nmeas = 1,
               pAnt = np.array([1.6,5.2,1.6]),
               vAnt = np.array([1.0,0.0,0.0]),
               comment = 'test',
               author = 'mamadou',
               ):
        """ measure MIMO channel over a set of points from AntArray and store in h5

        Parameters
        ----------

        A       : Aarray
        _fileh5 : string
            name of the h5 file containing calibration data
        gcal    : calibration group
        ical    : calibration index
        vel     : int
            scanner moving velocity
        Nmeas   : int
            Number of measurement
        pAnt : np.array(,3)
            Coordinates of non scanner antenna phase center
        vAnt : np.array(,3)
            Coordinates of non scanner antenna unitary vector

        """

        #initialization of the switch

        switch = sw.get_adapter()
        reattach=False
        if not switch:
            raise Exception("No device found")

        #switch.device
        switch.set_io_mode(0b11111111, 0b11111111, 0b00000000)

        # load the file containing the calibration data
        Dh5 = Mesh5(_fileh5)

        # open - sdata analysis
        Dh5.open('r')

        try:
            ldataset = Dh5.f.keys()
        except:
            raise IOError('no calibration in h5 file')

        lcal= [ eval(k.replace('cal','')) for k in ldataset if 'cal' in k ]
        lcal=np.array(lcal)

        if len(lcal)==1:
           gcal = lcal[0]
        else:
            if gcal not in lcal:
                raise IOError('Error calibration MIMO : File does not exist')
        Dh5.close()

        # read the chosen calibration and save parameters in ini file for VNA

        Dh5.readcal(gcal=gcal,ical=ical)
        # update vna_config.ini
        Dh5.saveini(ical=ical)
        # end of read and save
        # initialization of vna
        vna = SCPI()
        vna.load_config_vna()

        Npoint = A.p.shape[1]
        Nf = vna.Nf

        laxes = []
        if A.N[0]!=1:
            laxes.append('x')
        if A.N[1]!=1:
            laxes.append('y')
        if A.N[2]!=1:
            laxes.append('z')
        if A.N[3]!=1:
            laxes.append('a')

        lN =  [ A.N[k] for  k  in range(4) if A.N[k]!=1 ]

        Dh5.open('a')
        try:
            ldataset = Dh5.f.keys()
        except:
            ldataset = []

        lmes = [ldataset[k] for  k in range(len(ldataset))  if 'mes' in ldataset[k]]
        imes = [eval(k.replace('mes','')) for k in lmes]
        mesname = 'mes'+str((max(imes)+1))
        

        mes = Dh5.f.create_group(mesname)

        mes.attrs['time'] = time.ctime()
        mes.attrs['author'] = author
        mes.attrs['comment'] = comment
        mes.attrs['axes'] = laxes
        mes.attrs['axesn'] = lN
        mes.attrs['nr'] = self.Nr
        mes.attrs['nt'] = self.Nt
        mes.attrs['nmeas'] = Nmeas
        mes.attrs['pant'] = pAnt
        mes.attrs['vant'] = vAnt
        #mes.attrs['anchors']= self.anchors
        # here is the hard link between a measurement and its calibration 
        mes.attrs['gcal'] = "cal"+str(gcal)
        mes.attrs['ical'] = str(ical)

        # Metadata of measurement run (max(imes)+1) are stored
        Dh5.close()

        # Handling of spatial indexes and measurement number
        ik = np.arange(A.p.shape[1])
        ix,iy,iz,ia = k2xyza(ik,(A.N[0],A.N[1],A.N[2],A.N[3]))

        # k iterates on the total number of points
        
        for k in ik:
            # move the scanner to next position k
            self.mv(pt=A.p[:,k],vel=vel)
            # Waiting for a while
            time.sleep(1)
            # call vna for measurement
            tic = time.time()
            # Allocating required memory for storing data
            S = np.empty((Nmeas,self.Nr,self.Nt,Nf),dtype=complex)
            # Start of double loop over transmitting and receiving antennas
            for iT in range(self.Nt):
                switch.write_port(1,iT)
                for iR in range(self.Nr):
                    switch.write_port(0,iR)
                    time.sleep(0.1)

                    S21 = vna.getdata(Nmeas=Nmeas)
                   
                    S[:,iR,iT,:] = S21[:,0,0,:]
                    
            # saving the MIMO matrix in append mode

            Dh5.open('a')
            mes = Dh5.f[mesname]
            try:
                mes.create_group(str(ix[k]))
                try:
                    mes[str(ix[k])].create_group(str(iy[k]))
                    try:
                        mes[str(ix[k])][str(iy[k])].create_group(str(iz[k]))
                        mes[str(ix[k])][str(iy[k])][str(iz[k])].create_dataset(str(ia[k]),(Nmeas,self.Nr,self.Nt,Nf),dtype=np.complex64, data = S)
                    except:
                        mes[str(ix[k])][str(iy[k])][str(iz[k])].create_dataset(str(ia[k]),(Nmeas,self.Nr,self.Nt,Nf),dtype=np.complex64, data = S)
                except:
                    try:
                        mes[str(ix[k])][str(iy[k])].create_group(str(iz[k]))
                        mes[str(ix[k])][str(iy[k])][str(iz[k])].create_dataset(str(ia[k]),(Nmeas,self.Nr,self.Nt,Nf),dtype=np.complex64, data = S)
                    except:
                        mes[str(ix[k])][str(iy[k])][str(iz[k])].create_dataset(str(ia[k]),(Nmeas,self.Nr,self.Nt,Nf),dtype=np.complex64, data = S)
            except:
                try:
                    mes[str(ix[k])].create_group(str(iy[k]))
                    try: 
                        mes[str(ix[k])][str(iy[k])].create_group(str(iz[k]))
                        mes[str(ix[k])][str(iy[k])][str(iz[k])].create_dataset(str(ia[k]),(Nmeas,self.Nr,self.Nt,Nf),dtype=np.complex64, data = S)
                    except:
                        mes[str(ix[k])][str(iy[k])][str(iz[k])].create_dataset(str(ia[k]),(Nmeas,self.Nr,self.Nt,Nf),dtype=np.complex64, data = S)
                except:
                    try: 
                        mes[str(ix[k])][str(iy[k])].create_group(str(iz[k]))
                        mes[str(ix[k])][str(iy[k])][str(iz[k])].create_dataset(str(ia[k]),(Nmeas,self.Nr,self.Nt,Nf),dtype=np.complex64, data = S)
                    except:
                        mes[str(ix[k])][str(iy[k])][str(iz[k])].create_dataset(str(ia[k]),(Nmeas,self.Nr,self.Nt,Nf),dtype=np.complex64, data = S)

            mes[str(ix[k])][str(iy[k])][str(iz[k])][str(ia[k])].attrs['pt']=A.p[:,k]
            mes[str(ix[k])][str(iy[k])][str(iz[k])][str(ia[k])].attrs['pg']=self.pG  
            mes[str(ix[k])][str(iy[k])][str(iz[k])][str(ia[k])].attrs['pa']=self.pA    
        
            Dh5.close()
Exemple #7
0
import pylayers.measures.switch.ni_usb_6501 as sw
import time
switch = sw.get_adapter()
#reattach=False
if not switch:
    print("No device found")

#
#very important : to use at the beginning of the initialization of the switch
#for each measurements, set up the NI USB 6501 mode : bit 1 means write and bit 0 read
#

switch.set_io_mode(0b11111111, 0b11111111, 0b00000000) 

#
#SISO case
#

#example for use the switch 1 to 4
#switch 1 to 4 : port 1 is allowed

#switch.write_port(1, 1) #select output 2 of the switch 1-4
#switch.write_port(1, 2) #select output 3 of the switch 1-4

#example for use the switch 1 to 8
#switch 1 to 8 : port 0 is allowed    
#for each measurements, set up the NI USB 6501 mode : bit 1 means write and bit 0 read
#switch.set_io_mode(0b11111111, 0b11111111, 0b00000000) 


#switch.write_port(1, 1) #select output 2 of the switch 1-4