示例#1
0
文件: decoder.py 项目: mbe9a/caik
    def caled(self, name=None):
        """
        [calibrated or averaged]  measurements  of a given dut
        
        Returns 
        --------
        out : dict skrf.Networks
        """

        if name is None:
            name = "measurement"  # default name
        frequency = self.frequency
        nf = len(frequency)

        caled = {}

        if isinstance(name, str):
            for k in self.dataset:
                ntwks = [l for l in self.dataset[k] if name in l.name]
                caled[k] = self.calset[k].apply_cal_to_list(ntwks)
                caled[k] = rf.average(caled[k])
        if isinstance(name, int):
            for k in self.dataset:
                caled[k] = self.calset[k].caled_ntwks[name]

        return caled
示例#2
0
文件: decoder.py 项目: mbe9a/caik
    def caled(self, name=None):
        '''
        [calibrated or averaged]  measurements  of a given dut
        
        Returns 
        --------
        out : dict skrf.Networks
        '''

        if name is None:
            name = 'measurement'  # default name
        frequency = self.frequency
        nf = len(frequency)

        caled = {}

        if isinstance(name, str):
            for k in self.dataset:
                ntwks = [l for l in self.dataset[k] if name in l.name]
                caled[k] = self.calset[k].apply_cal_to_list(ntwks)
                caled[k] = rf.average(caled[k])
        if isinstance(name, int):
            for k in self.dataset:
                caled[k] = self.calset[k].caled_ntwks[name]

        return caled
示例#3
0
文件: decoder.py 项目: mbe9a/caik
def decode_with_rotation(dir_, f="634ghz", cal=None, averaging=True):
    """
    decode a hadamard-encoded dataset at a given frequency
    
    
    Examples
    ----------
    f = '634ghz'
    dir_= '../CAI/Bar Image/hadamard_2/Primary'

    a = decode(dir_=dir_, f = f,averaging =True)
    matshow(rf.complex_2_db(a))
    cb = colorbar()
    #clim(-26,-25)
    grid(0)

    """
    hexs = os.listdir(dir_)

    # determine resolution and rank
    res = int(sqrt(len(hexs)))
    rank = int(log2(res))

    # calculate inverse hadamard-delta transform`T`
    # this can be pre-computed
    bins = [hex2bin(k, rank=rank) for k in hexs]
    T = array([array(list(k), dtype=int) for k in bins])
    T_inv = inv(T)

    # create measurement frame `M` in hadamard space.
    M = []

    for k in hexs:
        b = array(list(hex2bin(k, rank=rank)), dtype=int)
        n = rf.ran(dir_ + "/" + k)

        if cal is not None:
            n = cal.apply_cal_to_list(n)
        if averaging:
            n = rf.average(n.values())
        else:
            n = n[sorted(n.keys())[-1]]

        s = n[f].s[0, 0, 0]  # pull out single complex number
        m = s * b
        M.append(m)

    M = array(M)

    # transform the frame `M` in hadamard space to
    # frame `A` in delta space
    A = T_inv.dot(M)

    # pixels lay along the diagonal.
    A_diag = array([A[k, k] for k in range(res ** 2)])

    # reshape the diagonal matrix into the image
    a = A_diag.reshape(res, res)
    return a, A
示例#4
0
文件: decoder.py 项目: mbe9a/caik
def decode_with_rotation(dir_, f='634ghz', cal=None, averaging=True):
    '''
    decode a hadamard-encoded dataset at a given frequency
    
    
    Examples
    ----------
    f = '634ghz'
    dir_= '../CAI/Bar Image/hadamard_2/Primary'

    a = decode(dir_=dir_, f = f,averaging =True)
    matshow(rf.complex_2_db(a))
    cb = colorbar()
    #clim(-26,-25)
    grid(0)

    '''
    hexs = os.listdir(dir_)

    #determine resolution and rank
    res = int(sqrt(len(hexs)))
    rank = int(log2(res))

    # calculate inverse hadamard-delta transform`T`
    # this can be pre-computed
    bins = [hex2bin(k, rank=rank) for k in hexs]
    T = array([array(list(k), dtype=int) for k in bins])
    T_inv = inv(T)

    # create measurement frame `M` in hadamard space.
    M = []

    for k in hexs:
        b = array(list(hex2bin(k, rank=rank)), dtype=int)
        n = rf.ran(dir_ + '/' + k)

        if cal is not None:
            n = cal.apply_cal_to_list(n)
        if averaging:
            n = rf.average(n.values())
        else:
            n = n[sorted(n.keys())[-1]]

        s = n[f].s[0, 0, 0]  # pull out single complex number
        m = s * b
        M.append(m)

    M = array(M)

    # transform the frame `M` in hadamard space to
    # frame `A` in delta space
    A = T_inv.dot(M)

    # pixels lay along the diagonal.
    A_diag = array([A[k, k] for k in range(res**2)])

    #reshape the diagonal matrix into the image
    a = A_diag.reshape(res, res)
    return a, A
示例#5
0
 def raw_ntwk_of(self,dec,name):
     '''
     raw ntwk for a given mask, or pixel
     '''
     if isinstance(dec, tuple):
         ntwks = [self.raw_ntwk_of(k,name) for k in self.pixel2decs(*dec)]
         return rf.average(ntwks)
     ntwk = rf.ran(str(self.decs[dec]), contains=name).values()[0]
     
     return ntwk
示例#6
0
 def error_ntwk_of(self,dec):
     '''
     error ntwk for a given mask, or pixel
     '''
     if isinstance(dec, tuple):
         ntwks = [self.error_ntwk_of(k) for k in self.pixel2decs(*dec)]
         return rf.average(ntwks)
     
     ntwk = self.cal_of(dec).error_ntwk
     ntwk.name = dec
     return ntwk
示例#7
0
 def cor_ntwk_of(self,dec, name, loc='corrected'):
     '''
     corrected ntwk for a given mask, or pixel
     '''
     if isinstance(dec, tuple):
         if loc  == 'corrected':
             # decode in corrected-space
             ntwks = [self.cor_ntwk_of(k,name) for k in self.pixel2decs(*dec)]
             return rf.average(ntwks)
         elif loc =='measured':
             # decode in measured space
             m = self.raw_ntwk_of(dec,name)
             return self.cal_of(dec).apply_cal(m)
     
     # correct a measurement for a single mask
     return self.cal_of(dec).apply_cal(self.raw_ntwk_of(dec,name))
示例#8
0
文件: decoder.py 项目: arsenovic/caik
    def da(self):
        '''
        a xarray.DataArray object representing the entire data-set
        '''
        # return cached value if it exists
        if self._da is not None:
            return self._da
            
        hexs= self.hexs
        
        #determine resolution and rank 
        res = int(sqrt(len(hexs)))
        rank = int(log2(res))
        
        M=[] # will hold weighted masks
         
        for k in hexs:
            n = rf.ran(self.dir_+'/'+k)
            
            if self.cal is not None:
                n = self.cal.apply_cal_to_list(n)
            
            if self.averaging:
                n = rf.average(n.values())
            else:
                n = n[sorted(n.keys())[-1]]
            
            s = n.s[:,0,0].reshape(-1,1,1) # pull out single complex number
            
            m = hex2mask(k,rank=rank) 
            #copy mask allong frequency dimension
            m = expand_dims(m,0).repeat(s.shape[0],0) 
            m = m*s
            M.append(m)

        M= array(M)
        n.frequency.unit='ghz'
        da = DataArray(M, coords=[('mask_hex',hexs),
                                  ('f_ghz',n.frequency.f_scaled),
                                  ('row',range(res)),
                                  ('col',range(res))])
        
        self._da = da # cache it
        return da
示例#9
0
文件: decoder.py 项目: mbe9a/caik
    def da(self):
        '''
        a xarray.DataArray object representing the entire data-set
        '''
        # return cached value if it exists
        if self._da is not None and caching:
            return self._da

        hexs = self.hexs
        res = self.res
        rank = self.rank

        M = []  # will hold weighted masks

        for k in hexs:
            n = rf.ran(self.dir_ + '/' + k)

            if self.cal is not None:
                n = self.cal.apply_cal_to_list(n)

            if self.averaging:
                n = rf.average(n.values())
            else:
                n = n[sorted(n.keys())[-1]]

            s = n.s[:, 0, 0].reshape(-1, 1,
                                     1)  # pull out single complex number

            m = hex2mask(k, rank=rank)
            #copy mask allong frequency dimension
            m = expand_dims(m, 0).repeat(s.shape[0], 0)
            m = m * s
            M.append(m)

        M = array(M)
        n.frequency.unit = 'ghz'
        da = DataArray(M,
                       coords=[('mask_hex', hexs),
                               ('f_ghz', n.frequency.f_scaled),
                               ('row', range(res)), ('col', range(res))])

        if caching:
            self._da = da
        return da
    fig.subplots_adjust(top=0.928,bottom=0.061,left=0.041,right=0.99,hspace=0.338,wspace=0.147)
    fig.savefig(output_path +'\\'+ fig.texts[0].get_text().replace(': ',' - ') + '.jpg')

#%%
plt.close(fig='all')
#%%

nominal = [rec for rec in a if all(['FFFF' in rec.serial,rec.temperature==rev_tdict[1],rec.voltage==rev_vdict[1]])]
wc = [rec for rec in a if all(['FFFF' in rec.serial,rec.temperature==rev_tdict[2],rec.voltage==rev_vdict[0]])]

#%%
nom_ary = np.zeros([4,6])
wc_ary = np.zeros([4,6])


i1o1 = rf.average([rec.rfobj for rec in nominal if (rec.state==rev_sdict[0])])
i2o1 = rf.average([rec.rfobj for rec in nominal if (rec.state==rev_sdict[1])])
i1o2 = rf.average([rec.rfobj for rec in nominal if (rec.state==rev_sdict[2])])
i2o2 = rf.average([rec.rfobj for rec in nominal if (rec.state==rev_sdict[3])])
k = 0
for ntwrk in [i1o1,i2o1,i1o2,i2o2]:
    nom_ary[k,:] = [ntwrk.s31['2.7GHz'].s_db[0,0,0],
                    ntwrk.s32['2.7GHz'].s_db[0,0,0],
                    ntwrk.s41['2.7GHz'].s_db[0,0,0],
                    ntwrk.s42['2.7GHz'].s_db[0,0,0],
                    ntwrk.s21['2.7GHz'].s_db[0,0,0],
                    ntwrk.s43['2.7GHz'].s_db[0,0,0]]
    k+=1


#%%
    if all([rec.temperature == rev_tdict[1], rec.voltage == rev_vdict[1]])
]
wc = [
    rec for rec in a
    if all([rec.temperature == rev_tdict[2], rec.voltage == rev_vdict[0]])
]

#%%
states_short = [state for state in states if 'CA' not in state]

#%%
nom_ary = np.zeros([len(states_short), 6])
wc_ary = np.zeros([len(states_short), 6])

nom_ave_dict = {
    state: rf.average([rec.rfobj for rec in nominal if (rec.state == state)])
    for state in states_short
}

wc_ave_dict = {
    state: rf.average([rec.rfobj for rec in nominal if (rec.state == state)])
    for state in states_short
}

#%%
line_lst = [
    'State,IL_490,IL_800,IL_960,' + 'ISO_490,ISO_800,ISO_960,' +
    'ISO_WCNom_490,ISO_WCNom_800,ISO_WCNom_960,' +
    'WC_IL_490,WC_IL_800,WC_IL_960,' + 'WC_ISO_490,WC_ISO_800,WC_ISO_960,\n'
]
for state in states_short: