Exemplo n.º 1
0
def matrix4D_reader(wfile, header=False, delimiter=',', *args, **kwargs):
    """temporary wrapper for new readers, replace call to matrix4D_reader
    with calls to read_data(wfile,reader=matrix4D_reader).
    
    read csv data with parameters extracted from header as saved by 4D.
    
    """
    from pySurf.readers.format_reader import csv4D_reader

    #import pdb
    #pdb.set_trace()
    return read_data(wfile, csv4D_reader, delimiter=delimiter, *args, **kwargs)
Exemplo n.º 2
0
def points_reader(wfile, *args, **kwargs):
    """temporary wrapper for points readers, read and register
    points and convert to 2D data"""
    from pySurf.readers.format_reader import points_reader
    return read_data(wfile, points_reader, *args, **kwargs)
Exemplo n.º 3
0
def fits_reader(wfile, *args, **kwargs):
    """temporary wrapper for new readers, replace call to fits_reader
    with calls to read_data(wfile,reader=fits_reader)"""
    from pySurf.readers.format_reader import fits_reader
    return read_data(wfile, fits_reader, *args, **kwargs)
Exemplo n.º 4
0
def matrixdat_reader(wfile, *args, **kwargs):
    """temporary wrapper for zygo metropro .dat binary files"""
    from pySurf.readers.format_reader import datzygo_reader
    return read_data(wfile, datzygo_reader, *args, **kwargs)
Exemplo n.º 5
0
def matrixsur_reader(wfile, *args, **kwargs):
    """temporary wrapper for new readers, replace call to matrixsur_reader
    with calls to read_data(wfile,reader=sur_reader)"""
    from pySurf.readers.format_reader import sur_reader
    return read_data(wfile, sur_reader, *args, **kwargs)
Exemplo n.º 6
0
def matrix_reader(wfile, *args, **kwargs):
    """temporary wrapper for new readers, replace call to matrix4D_reader
    with calls to read_data(wfile,reader=matrix4D_reader)"""
    from pySurf.data2D import data_from_txt
    return read_data(wfile, data_from_txt, *args, **kwargs)
Exemplo n.º 7
0
def matrixZygo_reader(wfile, *args, **kwargs):
    """temporary wrapper for new readers, replace call to matrixZygo_reader
    with calls to read_data(wfile,reader=csvZygo_reader)"""
    from pySurf.readers.format_reader import csvZygo_reader
    #pdb.set_trace()
    return read_data(wfile, csvZygo_reader, *args, **kwargs)
Exemplo n.º 8
0
    def __init__(
        self,
        data=None,
        x=None,
        y=None,
        file=None,
        reader=None,
        units=None,
        name=None,
        *args,
        **kwargs
    ):
        """
        A class for 2D data with coordinates and their analysis.
        
        Can be initialized with data | data, x, y | file | file, x, y.
        if x and y are coordinates if match number of elements, 
            or used as range if two element. 
        If provided together with file, they override x and y 
            read from file.
        
        Function methods return a copy with new values and don't alter original
           object. Reassign to variable to use as modifier:
           e.g. a=a.level( ... )

        Args:
            data (2D array or string): 2D data or file name (suitable reader must 
            provided).
            
            x, y (array): coordinates or ranges.
            
            file (str): alternative way to provide a data file.
            
            units (str array): 3-element array with units symbols for `x`, `y`, `data`  
            
            reader (function): reader function (see `pySurf.readers.instrumentReader`).
            
            name (str): sets the name of created object.  

            *args, **kwargs: optional arguments for `pySurf.data2D.register_data`. 
        """

        # from pySurf.readers.instrumentReader import reader_dic

        # pdb.set_trace()

        if isinstance(data, str):
            print("first argument is string, use it as filename")
            file = data
            data = None
        # pdb.set_trace()
        self.file = file  # initialized to None if not provided
        if file is not None:
            assert data is None
            # store in xrange values for x if were passed
            xrange = span(x) if x is not None else None
            yrange = span(y) if y is not None else None

            # pdb.set_trace()
            if reader is None:
                reader = auto_reader(file)  # returns a reader
            # calling without arguments skips register, however skips also reader argumnets, temporarily arranged with pop in read_data to strip all arguments for
            data, x, y = read_data(file, reader, *args, **kwargs)
            # register data and pass the rest to reader
            # pdb.set_trace()

            if np.size(x) == data.shape[1]:
                self.x = x
            elif np.size(x) == 2:
                # y and yrange are identical
                print("WARNING: 2 element array provided for X, uses as range.")
                x = np.linspace(*xrange, data.shape[1])
            elif xrange is not None:
                print(
                    "wrong number of elements for x (must be 2 or xsize_data [%i]), it is instead %i"
                    % (np.size(data)[1], np.size(x))
                )
                raise ValueError

            if np.size(y) == data.shape[0]:
                self.y = y
            elif np.size(y) == 2:
                # y and yrange are identical
                print("WARNING: 2 element array provided for Y, uses as range.")
                x = np.linspace(*yrange, data.shape[0])
            elif yrange is not None:
                print(
                    "wrong number of elements for y (must be 2 or ysize_data [%i]), it is instead %i"
                    % (np.size(data)[0], np.size(y))
                )
                raise ValueError

            # set self.header to file header if implemented in reader, otherwise set to empty string""
            try:
                # kwargs['header']=True
                # self.header=reader(file,header=True,*args,**kwargs)
                self.header = reader(file, header=True, *args, **kwargs)
            except TypeError:  # unexpected keyword if header is not implemented
                self.header = ""
                # raise
        else:
            if data is not None:
                if len(data.shape) != 2:
                    # pdb.set_trace()
                    print(
                        "WARNING: data are not bidimensional, results can be unpredictable!"
                    )
                if x is None:
                    x = np.arange(data.shape[1])
                if y is None:
                    y = np.arange(data.shape[0])

                # if data is not None:
                # se read_data calls register, this
                data, x, y = register_data(data, x, y, *args, **kwargs)
                # goes indented.

        self.data, self.x, self.y = data, x, y

        self.units = units
        if name is not None:
            self.name = name
        elif file is not None:
            self.name = os.path.basename(file)
        else:
            self.name = ""
Exemplo n.º 9
0
                         }
        ],
        [
            csvZygo_reader,
            os.path.join(pwd, testfolder,
                         r'input_data\zygo_data\171212_PCO2_Zygo_data.asc'), {
                             'strip': True,
                             'center': (10, 15),
                             'intensity': True
                         }
        ]
    ]

    plt.ion()
    #plt.close('all')
    for r, f, o in tests:  #reader,file,options
        print('reading data %s' % os.path.basename(f))
        plt.figure()
        plt.subplot(121)
        plot_data(*r(f))
        plt.title('raw data')
        plt.subplot(122)
        data, x, y = read_data(f, r, **o)
        plot_data(data, x, y)
        plt.title('registered')
        plt.suptitle(
            os.path.basename(f) + ' ' +
            ' '.join(["%s=%s" % (k, v) for k, v in o.items()]))
        plt.tight_layout()
        plt.show()