def load_directory(path, basename=""): """ load_directory (path) Loads all the .VEC files in the directory into a single xarray dataset with variables and units added as attributes Input: directory : path to the directory with .vec files Output: data : xarray DataSet with dimensions: x,y,t and data arrays of u,v, attributes of variables and units See more: loadvec """ files = [f for f in os.listdir(path) if f.endswith(".vc7")] variables, units, rows, cols, dt, frame = parse_header(files[0]) data = [] for i, f in enumerate(files): data.append(loadvec(f, rows, cols, variables, units, dt, frame + i - 1)) combined = xr.concat(data, dim="t") combined.attrs["variables"] = variables combined.attrs["units"] = units combined.attrs["dt"] = dt combined.attrs["files"] = files return combined
# test_methods.py import xarray as xr from pivpy import io, pivpy import numpy as np import os f1 = 'Run000001.T000.D000.P000.H001.L.vec' f2 = 'Run000002.T000.D000.P000.H001.L.vec' path = './data/' _a = io.loadvec(os.path.join(path,f1)) _b = io.loadvec(os.path.join(path,f2)) def test_crop(): """ tests crop """ _c = _a.piv.crop([.6, 19.,-.6,-19.]) assert _c.u.shape == (59,59,1) _c = io.create_sample_dataset() _c = _c.sel(x = slice(30,90),y=slice(60,80)) assert _c.u.shape == (2,2,5) # note the last dimension is preserved def test_pan(): """ test a shift by dx,dy using pan method """ _a = io.loadvec(os.path.join(path,f1)) _c = _a.piv.pan(1.0,-1.0) # note the use of .piv. assert np.allclose(_c.coords['x'][0],1.312480) assert np.allclose(_c.coords['y'][0], -1.31248)
def test_pan(): """ test a shift by dx,dy using pan method """ _a = io.loadvec(os.path.join(path,f1)) _c = _a.piv.pan(1.0,-1.0) # note the use of .piv. assert np.allclose(_c.coords['x'][0],1.312480) assert np.allclose(_c.coords['y'][0], -1.31248)
def test_pan(): """ test a shift by dx,dy using pan method """ _a = io.loadvec(os.path.join(path, f1)) _c = _a.piv.pan(1.0, -1.0) # note the use of .piv. assert np.allclose(_c.coords['x'][0], 1.312480) assert np.allclose(_c.coords['y'][0], -1.31248)
# test_methods.py import xarray as xr from pivpy import io, pivpy import numpy as np import os f1 = 'Run000001.T000.D000.P000.H001.L.vec' f2 = 'Run000002.T000.D000.P000.H001.L.vec' path = './data/' _a = io.loadvec(os.path.join(path, f1)) _b = io.loadvec(os.path.join(path, f2)) def test_crop(): """ tests crop """ _c = _a.piv.crop([.6, 19., -.6, -19.]) assert _c.u.shape == (59, 59, 1) _c = io.create_sample_dataset() _c = _c.sel(x=slice(30, 90), y=slice(60, 80)) assert _c.u.shape == (2, 2, 5) # note the last dimension is preserved def test_pan(): """ test a shift by dx,dy using pan method """ _a = io.loadvec(os.path.join(path, f1)) _c = _a.piv.pan(1.0, -1.0) # note the use of .piv. assert np.allclose(_c.coords['x'][0], 1.312480) assert np.allclose(_c.coords['y'][0], -1.31248)
import xarray as xr from pivpy import io, pivpy, graphics import numpy as np import os f1 = 'Run000001.T000.D000.P000.H001.L.vec' path = './data/' _d = io.loadvec(os.path.join(path, f1)) def test_showscal(): graphics.showscal(_d, property='ken') def test_quiver(): graphics.quiver(_d) def test_xarray_plot(): _d.piv.vec2scal(property='curl') _d['w'].isel(t=0).plot.pcolormesh() def test_histogram(): graphics.histogram(_d)
def test_loadopenpivtxt(): data = io.loadvec(os.path.join(path,'exp1_001_b.txt'))
def test_loadvec(): data = io.loadvec(os.path.join(path,fname)) assert data['u'].shape == (63,63,1) assert data['u'][0,0,0] == 0.0 assert np.allclose(data.coords['x'][0],0.31248) assert 't' in data.dims