예제 #1
0
def test_datzygo_reader(wfile=None):

    import os
    import matplotlib.pyplot as plt
    from pySurf.data2D import plot_data
    from pySurf.data2D_class import Data2D
    from pySurf.readers.format_reader import datzygo_reader

    if wfile is None:
        #relpath
        wfile = r'/Volumes/GoogleDrive/Il mio Drive/progetti/sandwich/dati/09_02_27/botta di culo 1a.dat'
        #wfile= os.path.join(os.path.dirname(__file__),relpath)
    (d1, x1, y1) = datzygo_reader(wfile)
    dd1 = Data2D(d1, x1, y1)

    dd2 = Data2D(f, reader=datzygo_reader)

    plt.figure()
    plt.suptitle(wfile)
    plt.subplot(121)
    plt.title('object from data')
    dd1.plot(aspect='equal')
    plt.subplot(122)
    plt.title('object from reader ')
    dd2.plot(aspect='equal')
    return dd2
예제 #2
0
def plot_repeat(rfiles,outfile=None,dis=True,name = "",plot_func=plot_data_repeat_leveling,ro=None):
    """Functions to plot a list of files side to side (e.g. repeatability or reproducibility)
    with different levelings. Return list of Data2D objects.
    plot_func is a function that accepts a dlist and possibly accepts arguments
       outfile, dis and name (it can have them ignored in **kwargs, or not passed at all to plot_repeat).
    This way, becomes a wrapper around plot_func (that doesn't necessarily have to plot,
      just have an interface outfile, dis, name.
    
    2019/04/08 made function general.
    2018/11/02 moved to scripts. Modified to make it format independent acting on
    data rather than on file extracting the data part in outer routine plot_data_repeat_leveling
    in ."""
    
    plt.close('all')

    if ro is None:
        ro={'reader':fitsWFS_reader,
                'scale':(-1,-1,1),
                'units':['mm','mm','um'],
                'ytox':220/200,
                'ypix':101.6/120,
                'center':(0,0)}
    
    #if name is None:
    #    name = os.path.basename(outfile) if outfile is not None else ""
    
    dlist=[Data2D(file=wf1,**ro).level() for i,wf1 in enumerate(rfiles)]
    res = plot_func(dlist,outfile=outfile,dis=dis,name = name)
    
    
    return dlist
예제 #3
0
def process_set2(flist,names,outname,crop=None,dis=True):
    # from C1S15_4D_DI_calibration_181031.ipynb
    # called with:
    ypix=None #0.127901442999 #mm  
    ytox=220./200.  
    zscale=None #0.6328
    scale=(1000,-1000,0.001)

    outfolder=os.path.dirname(outname)
    outname=os.path.basename(outname)
    
    dlist=[Data2D(*matrix4D_reader(wf2,scale=scale,zscale=zscale,
       ypix=ypix,ytox=ytox,center=(0,0),strip=True),name=n,units=['mm','mm','um']) 
       for wf2,n in zip(flist,names)]
    np.mean(dlist).save(os.path.join(outfolder,outname+'_avg.dat'))
    
    plt.close('all')
    sx,sy=find_grid_size(len(dlist),3)
    f,axes=plt.subplots(sx,sy,sharex=True,sharey=True)
    for ax,d in zip(axes.flatten(),dlist):
        plt.sca(ax)
        d.plot()
        plt.clim(*remove_outliers(d.data,nsigma=2,itmax=3,span=1))
    for ax in axes.flatten()[:len(dlist)-1:-1]:
        f.delaxes(ax)

    maximize()
    plt.pause(0.1)
    plt.tight_layout(rect=[0,0,1,0.9])
    plt.suptitle ('Surfaces')
    if dis:
        display(plt.gcf())
    
    plt.savefig(os.path.join(outfolder,outname+'.png'))
    
    m_repr=[dcouples_plot([dd for dd in dlist])]
    if dis:
        display(plt.gcf())
    plt.savefig(os.path.join(outfolder,'diff_'+outname+'.png'))
    
    if crop is not None:
        dc=[d.crop(*crop).level() for d in dlist]
        m_repr=[dcouples_plot([dd for dd in dc])]
        if dis:
            display(plt.gcf())
        plt.savefig(os.path.join(outfolder,'diff_'+outname+'_crop.png'))
       
    return dlist
예제 #4
0
"""INPUT SETTINGS"""
plt.ion()
infolder = "G:\\My Drive\\materialsLabShared\\WFS_BONDING_TESTS\\181016_PCO2S06_Reproducibility"
file1 = "181016_01_PCO2S06_1009_08.fits"
file2 = "181016_02_PCO2S06_1009_08.fits"
scale = 101.6 / 116  #ratio between mm and pixels
ytox = 220. / 200  #aspect ratio of pixel
strip = True  # strip nan frame
""""""

rfiles = [os.path.join(infolder, f) for f in [file1, file1]]
dlist = [
    Data2D(*fitsWFS_reader(f,
                           scale=(scale, scale, 1),
                           center=(0, 0),
                           strip=strip,
                           ytox=ytox,
                           ypix=1),
           units=['mm', 'mm', 'um']) for f in rfiles
]
#dlist[1]=dlist[1].rotate(1.5) #rotate 1.5 deg for test

dl = [d.level((10, 0)) for d in dlist]
mref, mtrans = align_interactive(
    dl)  #with default argument return transformation to first coordinates

#work on individual data files (can be replaced by functions in WFS_repeatability to work on N files:
d1, d2 = dlist
d2t = d1.apply_transform(mtrans[1])
plt.figure()
diff = plot_difference(d1, d2t)
예제 #5
0
# Similarly, routines operating on profiles (y as a function of x as couples of vector x and y), are contained in class `pyProfile.Profile` and `pyProfile.profile` which have in many points interfaces similar to modules in `pySurf`. 
# 
# Here we will focus on `Data2D` object interface.
# 
# A first way to initialize such an object is by passing directly 2D data, (optionally) coordinates and options.
# 
# 

# %%
nx = 200
ny = 300
data = np.random.random(nx*ny).reshape(ny,nx)
x = np.arange(nx)*25
y = np.arange(ny)*10

D = Data2D(data,x,y,units=['mm','mm','um'])
#D.plot()


# %%
D.plot()

# %%
infolder=r'..\..\test\input_data\4D\180215_C1S06_cut'
fn = '180215_C1S01_RefSub.csv'
file = os.path.join(infolder,fn)

# %%
from pySurf.data2D_class import Data2D
from pySurf.instrumentReader import matrix4D_reader
예제 #6
0
    r = find_internal_rectangle(a, x, y)

    plot_poly([[r[0][0], r[1][0]], [r[0][1], r[1][0]], [r[0][1], r[1][1]],
               [r[0][0], r[1][1]], [r[0][0], r[1][0]]])

# plt.figure()

if __name__ == "__main__":
    # %%TEST

    nx, ny = 700, 500
    a = np.zeros(nx * ny).reshape(ny, nx)
    x = np.arange(nx) * 3 - 300
    y = np.arange(ny) * 5 - 500
    gd = Data2D(a, x, y, name='test_data')

    #gd.data[40:60,150:160]=1
    #gd.data[400:420,300:310]=1
    #gd.data[80:100,420:440]=1

    gd.data[50:60, 40:60] = 1
    gd.data[300:310, 600:620] = 1
    gd.data[420:440, 80:100] = 1

    gd.data[50:60, 340:360] = 1
    gd.data[420:440, 330:350] = 1
    gd.data[250:260, 40:60] = 1

    plt.close('all')
예제 #7
0
"""Despite differemt conventions, from 
https://docs.python.org/3/distutils/sourcedist.html
test/test*.py is included in manifest."""

# import pyxsurf
# pyxsurf.pySurf    #fails

print("TRY: import pySurf")
import pySurf
print("OK\n")

# >>> pySurf.data2D_class    #fails
print("import Data2D pyxsurf.pySurf.data2D_class ")
from pySurf.data2D_class import Data2D
print("OK\nData2D is:")
print(Data2D)
print("\n")
## <module 'pyxsurf.pySurf.hello' from 'C:\\Users\\User\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python37\\site-packages\\pyxsurf\\pySurf\\hello.py'>
# hello.hello()    #fails

print("Initialize empty Data2D object in `a`:")
a = Data2D()
print("---")
print(a)

print("Import points from pySurf as a module:")
from pySurf import points
print(points)
예제 #8
0
def display_diff(f1,f2,data=False,dis=True,crd=None):
    """calculates, plots and returns the difference of two data.
      It is just a diff-and-plot with a few added options and settings for color scale and reading files,
      can probably be replaced by more standard routines.

      f1 and f2 are file names, unless data is set, in that case they are interpreted as data.
      Data are plotted on common color scale, while range for difference crd can be imposed,
      otherwise is calculated on outlier removed difference."""

    #set units
    units=['mm','mm','nm']
    zscale=1000

    #load data in d1 and d2 according if arguments are data or filenames
    if not(data):
        d1=Data2D(file=f1,units=units,scale=(1000,-1000,zscale),center=(0,0))
        if f2 is not None:
            d2=Data2D(file=f2,units=units,scale=(1000,-1000,zscale),center=(0,0))
        else:
            d2=cp.deepcopy(d1)*0
            #d2.data=d2.data*0
    else:
        d1=Data2D(f1.data,f1.x,f1.y,units=units)
        if f2 is not None:
            d2=Data2D(f2.data,f2.x,f2.y,units=units)
        else:
            d2=cp.deepcopy(d1)*0
            #d2.data=d2.data*0

    #plane level and diff
    d1=d1.level()
    d2=d2.level()
    diff=(d1-d2).level()

    #calculate common color range
    cr1=remove_outliers(d1.data,span=True)
    cr2=remove_outliers(d2.data,span=True)
    cr=[min([cr1[0],cr2[0]]),max([cr1[0],cr2[1]])]
    if crd is None: #color range for difference.
        crd=remove_outliers(diff.data,span=True)

    #plot on three panels, prints stats
    plt.clf()
    plt.subplot(311)
    maximize()
    d1.plot()
    plt.clim(*cr)
    d1.printstats()
    plt.subplot(312)
    d2.plot()
    plt.clim(*cr)
    d2.printstats()
    plt.subplot(313)
    diff.plot()
    plt.clim(*crd)
    print ("diff 2 - 1 = ")
    diff.printstats()
    plt.tight_layout()
    #plt.clim(*cr)#[-0.0001,0.0001])
    if not(data):
        if f2 is not None:
            plt.title ('Difference %s - %s'%tuple(os.path.basename(ff) for ff in [f1,f2]))
        else:
            plt.title ('%s '%f2)
    plt.show()

    #print ("PV: ",span(diff.data,size=True),diff.units[-1])
    #print ("rms: ",np.nanstd(diff.data),diff.units[-1])
    return d1,d2,diff
예제 #9
0
            except NoOptionError:
                logging.info('option ' + cgtag + ' not found')
                #print('option '+cgtag+' not found')
                pass

    return imgdic


if __name__ == "__main__":

    import os
    from pySurf.data2D_class import Data2D

    datafolder = r'G:\My Drive\progetti\c_overcoating\esperimenti\20210129_dopamine\20210224_dopamine_clean'
    fn = 'Image00053.nid'
    file_name = os.path.join(datafolder, fn)

    #file_name=r'C:\Users\kovor\Documents\python\pyXTel\pySurf\test\input_data\AFM\02_test.nid'

    datadic = read_nid(file_name)
    data, x, y = datadic['Gr0-Ch1']
    print("read data of shape", data.shape)

    d = Data2D(data,
               x,
               y,
               units=['mm', 'mm', 'um'],
               scale=[1000., 1000., 1000000.])

    d.plot()
    plt.show()