Ejemplo n.º 1
0
def internal_nan_mask(a, x=None, y=None):
    """return a mask with True on internal nans."""

    if x is None:
        x = np.arange(np.shape(a)[1])
    if y is None:
        y = np.arange(np.shape(a)[0])

    sx = [np.min(x), np.max(x)]
    sy = [np.min(y), np.max(y)]

    # b is 1 where a is nan, 0 othewise
    #used to detect when a region is made of nans
    aisnan = np.where(np.isnan(a), True, False)
    #plt.figure(); plot_data(b,x,y)
    #plt.title('b')

    # s is different integer for each contiguous region, can be
    s = label(aisnan)[0]
    #plt.figure()
    #plot_data(s)

    #m_int mask of internal nan regions of a
    m_int = np.zeros(a.shape).astype(bool)
    for i in range(np.max(s) + 1):
        c = s == i
        if aisnan[c].all():
            #plt.figure()
            #plot_data(c,x,y)
            #for each one find hull and check if it touches borders
            p = matrix_to_points2(c, x, y)
            p = p[p[:, 2] != 0, :]  #keep only points of current region
            ssx = span(p[:, 0])  #ranges of points in region
            ssy = span(p[:, 1])
            #print(i,sx,sy,ssx,ssy)
            if (ssx[0] > sx[0] and ssx[1] < sx[1] and ssy[0] > sy[0]
                    and ssy[1] < sy[1]):
                #print(i,'internal')
                import pdb
                #pdb.set_trace()
                m_int = np.logical_or(m_int, c != 0)
            #print(len(np.where(m_int!=0)[0]))
            #plt.figure()
            #plot_points(p,scatter=1)
            #p=p[~np.isnan(p[:,2]),:]
            #h=points_find_hull(p)
            #plot_poly(h,'bo')
            '''
            if not(((h[0,:] <= min(x)).any() or 
                    (h[0,:] >= max(x)).any() or 
                    (h[1,:] <= min(y)).any() or 
                    (h[1,:] >= max(y))).any()):
                print(i,'internal')
                m_int=np.logical_or(m_int,c==1)    
            '''
    return m_int
Ejemplo n.º 2
0
def fitsAFM_reader(fitsfile, sizeum=None):
    """return x,y (vectors) and data (matrix) from fits file. AFM file"""
    a = fits.open(fitsfile)
    header = a[0].header
    data = a[0].data
    a.close()
    #z in m
    from pySurf.points import level_points
    data = level_points(data)

    assert data.shape[0] == data.shape[
        1]  #if not, it's first time it happens, check axis.
    x = np.linspace(1, sizeum[0], data.shape[0]) / 1000.  #convert in mm
    y = np.linspace(1, sizeum[1], data.shape[1]) / 1000.
    data = data * 1e6  #convert from m to um
    return matrix_to_points2(data, x, y)
Ejemplo n.º 3
0
 def topoints(self):
     return matrix_to_points2(self.data, self.x, self.y)
Ejemplo n.º 4
0
 def topoints(self):
     """convenience function to get points using matrix_to_points2."""
     return matrix_to_points2(self.data, self.x, self.y)