This notebook shows an example of how one can use vecpy in order to load manipulate and display analyzed PIV data.
here we import the package code so that we can use it next
import os, sys
# sys.path.append(os.path.abspath('../'))
import numpy as np
import xarray as xr
import matplotlib.pyplot as plt
%matplotlib inline
from pivpy import io, pivpy, graphics
# for the sake of this tutorial, ignore warnings
# import warnings
# warnings.filterwarnings('ignore')
In order to load the data, first we need to set up the path to the data directory. Following that we need to get a list of files names that we would like to view/analyze. Finally we very quickly load the data in to a list of vec instances.
# pointer to the directory with the data
path_to_data = os.path.abspath('../../tests/data/')
# list the directory
os.listdir(path_to_data)
# let's read only the files from the Run*
data = io.load_directory(path_to_data,basename='Run*',ext='.vec')
# let's check if it's read:
data.attrs['files']
first things first - show a quiver plot
fig, ax = graphics.quiver(data.isel(t=0), nthArr=2, arrScale=20)
fig, ax = graphics.quiver(data, nthArr=3, arrScale=5)
# we can read also a single file only into a 1 frame dataset
d = io.load_vec('/Users/alex/Documents/OpenPIV/pivpy/tests/data/Run000001.T000.D000.P000.H001.L.vec')
graphics.quiver(d,arrScale=10)
d.isel(t=0).differentiate(coord='x').differentiate(coord='y')['u'].plot.pcolormesh()
and a vorticity map
# prepare vorticity
d.piv.vec2scal(property='curl') # it will appear as d['w'] variable, 'w' for all scalar properties
# plot
fig, ax = graphics.contour_plot(d)
Also, velocity histograms in x and y directions
fig, ax = graphics.histogram(data, normed = True)
We can also plot a whole list of vec's as subplots:
fig, ax = graphics.quiver(data, nthArr=4, arrScale=10)
fig.set_size_inches(10, 6)
lets create a linear combinatino of our data and then see how to manipulate the coordinate system
Addition and Scalar multiplication
v = (data + 3*data - 2 * data.isel(t=0)) / 3.
graphics.quiver(v, arrScale=10)
Crop
v = v.piv.crop([5,15,-5,-15]) #(xmin, xmax, ymin, ymax)
graphics.quiver(v, arrScale=10)
Rotate
# v.piv.rotate(90) # not implemented
Translation of Coordinate System
# we can also use some default plot from xarray
data.piv.vorticity()
data.isel(t=0)['w'].plot(robust=True)
# low level quiver
plt.figure(figsize=(8,6))
plt.quiver(data.x,data.y,data.u[:,:,0], data.v[:,:,0] ,data.u[:,:,0]**2 + data.v[:,:,0]**2,scale=.75)
test = io.create_sample_field(rows=25,cols=5)
graphics.quiver(test,arrScale=5)