In [1]:
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 [2]:
# pointer to the directory with the data
import pkg_resources as pkg
path_to_data = pkg.resource_filename('pivpy','data')
# list the directory
# os.listdir(path_to_data)
In [3]:
# let's read only the files from the Run*
data = io.load_directory(os.path.join(path_to_data,'Insight')) # you can add also: basename='day2a*',ext='.vec')
In [4]:
# let's check if it's read:
data.attrs['files']
Out[4]:
In [5]:
fig, ax = graphics.quiver(data.isel(t=0), nthArr=2, arrScale=20)
In [6]:
fig, ax = graphics.quiver(data.isel(t=0), nthArr=3, arrScale=5)
In [7]:
tmp = data.isel(t=0)
plt.quiver(tmp.x,tmp.y,tmp.u.T,tmp.v.T,scale=1)
Out[7]:
In [8]:
# we can read also a single file only into a 1 frame dataset
d = io.load_vec(os.path.join(path_to_data,'Insight/Run000001.T000.D000.P000.H001.L.vec'))
In [9]:
graphics.quiver(d.isel(t=0),arrScale=10)
Out[9]:
In [10]:
d.isel(t=0).differentiate(coord='x').differentiate(coord='y')['u'].plot.pcolormesh()
Out[10]:
and a vorticity map
In [11]:
# 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
In [12]:
fig, ax = graphics.histogram(data, normed = True)
We can also plot a whole list of vec's as subplots:
In [13]:
fig, ax = graphics.quiver(data.isel(t=0), nthArr=4, arrScale=10)
fig.set_size_inches(10, 6)
Addition and Scalar multiplication
In [14]:
v = (data + 3*data - 2 * data.isel(t=0)) / 3.
graphics.quiver(v.isel(t=-1), arrScale=10,units=data.attrs['units'])
Out[14]:
Crop
In [15]:
v = v.piv.crop([5,15,-5,-15]) #(xmin, xmax, ymin, ymax)
graphics.quiver(v.isel(t=-1), arrScale=10,units=data.attrs['units'])
Out[15]:
Rotate
In [16]:
# v.piv.rotate(90) # not implemented
Translation of Coordinate System
In [ ]:
# we can also use some default plot from xarray
data.piv.vorticity()
data.isel(t=0)['w'].plot(robust=True)
Out[ ]:
In [ ]:
# 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)
plt.gca().invert_yaxis()
In [ ]:
test = io.create_sample_field(rows=25,cols=5)
In [ ]:
graphics.quiver(test,arrScale=5,aspectratio='auto')
In [ ]:
data = io.load_vec(os.path.join(path_to_data,'openpiv/exp1_001_b.vec'))
In [ ]:
variables,units,rows,cols, dt, frame = io.parse_header(os.path.join(path_to_data,'openpiv/exp1_001_b.vec'))
variables,units,rows,cols, dt, frame
In [ ]:
data.piv.quiver()
In [ ]:
data = io.load_directory(os.path.join(path_to_data,'urban_canopy/'),ext='.vc7')
In [ ]:
data.piv.quiver(arrScale=40,colbar=True)
plt.gcf().set_size_inches(12,10)
In [ ]: