コード例 #1
0
 def _singledata(self,data,action):
    if action == 'sqrt':
       return np.sqrt(data)
    elif action == 'abs':  #astype(np.abs(data[0]).dtype): hack to ensure right type is returned
       return np.abs(data)
    elif action == 'amp':
       return np.abs(data) 
    elif action == 'power':
       return np.abs(data)**2
    elif action == 'phase':
       if not typecomplex(data):  
          return np.zeros_like(data)
       else:  
          return np.arctan2(data.imag,data.real)
    elif action == 'num_nan':
       return np.sum(np.isnan(data))
    elif action == 'num_inf':
       return np.sum(np.isinf(data))
    elif action == 'num_neginf':
       return np.sum(np.isneginf(data))
    elif action == 'num_posinf':
       return np.sum(np.isposinf(data))
    elif action == 'dB':
       return 10.*np.log10(data)
    elif action == 'dBi':
       return 10.**(data/10.)
    elif action == 'ln' or action == 'log':
       return np.log(data)
    elif action == 'log10':
       return np.log10(data)
    elif action == 'exp':
       return np.exp(data)
    elif action == '10pow':
       return 10**data
    elif action == 'max':
       return np.max(data)
    elif action == 'min':
       return np.min(data)
    elif action == 'std':
       return np.std(data)
    elif action == 'var':
       return np.var(data)
    elif action == 'mean':
       return np.mean(data)
    elif action == 'med':
       return np.median(data)
    elif action == 'isnan':
       return np.isnan(data).astype(data.dtype)
    elif action == 'notnan':
       return (-np.isnan(data)).astype(data.dtype)
    else:
       return data
コード例 #2
0
def look2D(data, win, null=None, verbose=0):
    """
   Incoherent averaging (looking) routine

   Parameters
   ----------
   data : 2D array
      Input data
   win : int or list
      Filter window size in pixels
      scalar values use a square window
      list should be in order [across, down]
   null : float or complex
      Null value to exclude from filter window
   verbose : int
      1 = print line counter to screen; 0 = don't

   Output
   ------
   D : 2D array
      Filtered data
   """
    try:
        a = len(win)
        if a == 1:
            d0, d1 = np.int32(win[0]), np.int32(win[0])
        elif a == 2:
            d0, d1 = np.int32(win[0]), np.int32(win[1])
        else:
            print('Incorrect window:  must be list length 1 or 2')
            return None
    except:
        d0, d1 = np.int32(win), np.int32(win)

    if null:
        donul = 1
    else:
        donul, null = 0, -9.87654321e200

    shp = np.shape(data)
    data = data.flatten()
    dtyp = data.dtype

    outlen, inlen = (shp[0] // d1) * (shp[1] // d0), shp[0] * shp[1]

    if data.dtype == np.float32:
        out = _looks_mod.look2d_real(data, shp[1], d1, d0, outlen, donul, null,
                                     verbose)
    elif data.dtype == np.float64:
        out = _looks_mod.look2d_double(data, shp[1], d1, d0, outlen, donul,
                                       null, verbose)
    elif data.dtype == np.complex64:
        out = _looks_mod.look2d_cmplx(data, shp[1], d1, d0, outlen, donul,
                                      null, verbose)
    elif data.dtype == np.complex128:
        out = _looks_mod.look2d_dcmplx(data, shp[1], d1, d0, outlen, donul,
                                       null, verbose)
    else:
        print('Unsupported data type...defaulting to float or complex')
        dtyp = data.dtype
        if typecomplex(data):
            data = data.astype(np.complex64)
            out = _looks_mod.look2d_cmplx(data, shp[1], d1, d0, outlen, donul,
                                          null, verbose)
        else:
            data = data.astype(np.float32)
            out = _looks_mod.look2d_real(data, shp[1], d1, d0, outlen, donul,
                                         null, verbose)
        out = out.astype(dtyp)

    return out.reshape(-1, shp[1] // d0)
コード例 #3
0
 def _doubledata(self,data1,data2,action):
    if action == 'add':
       return data1 + data2
    elif action == 'sub':
       return data1 - data2
    elif action == 'mult':
       return data1 * data2
    elif action == 'div':
       return data1 / data2
    elif action == 'hypot':
       return np.hypot(data1,data2)
    elif action == 'pow':
       return data1**data2
    elif action == 'mod':
       return data1 % data2
    elif action == 'root':
       return data1**(1./data2)
    elif action == 'xmult':
       return data1*np.conj(data2)
    elif action == 'xcor' or action == 'xcor_amp' or action == 'xcor_phase':
       cor = (data1*np.conj(data2))/np.sqrt( data1*np.conj(data1) * data2*np.conj(data2))
       if action == 'xcor':
          return cor
       elif action == 'xcor_amp':
          return np.abs(cor)
       elif action == 'xcor_phase':
          if not typecomplex(data):  return np.zeros_like(cor)
          else:  return np.arctan2(cor.imag,cor.real)
    elif action == 'null2nan':
       mask = self._genmask(data1=data1,data2=data2,tol=1.e-7)
       data1[mask] = np.nan
       return data1
    elif action == 'nan2null':
       data1[np.isnan(data1)] = data2
       return data1
    elif action == 'inf2null':
       data1[np.isinf(data1)] = data2
       return data1   
    elif action == 'num_null':
       mask = self._genmask(data1=data1,data2=data2,tol=1.e-7)
       return np.sum(mask)
    elif action == 'gt':
       mask = data1 > data2
       return mask.astype(data1.dtype)
    elif action == 'ge':
       mask = data1 >= data2 
       return mask.astype(data1.dtype)
    elif action == 'lt':
       mask = data1 < data2 
       return mask.astype(data1.dtype) 
    elif action == 'le':
       mask = data1 <= data2 
       return mask.astype(data1.dtype)
    elif action == 'eq':
       mask = np.abs(data1 - data2) < 1.e-7 
       return mask.astype(data1.dtype)
    elif action == 'ne':
       mask = np.abs(data1 - data2) > 1.e-7
       return mask.astype(data1.dtype) 
    elif action == 'log_b':
       return np.log(data1)/np.log(data2) 
    elif action == 'subphz':
       return data1*np.exp(-1j*data2) 
    elif action == 'addphz':
       return data1*np.exp(1j*data2)  
    else:
       print('unrecognized option', action)