PIVPy graphics tutorial¶
[2]:
import xarray as xr
import numpy as np
from pivpy import io, pivpy, graphics
import matplotlib.pyplot as plt
[3]:
## Let's create a sample dataset
[4]:
df = io.create_sample_dataset()
df
[4]:
<xarray.Dataset> Dimensions: (t: 5, x: 8, y: 5) Coordinates: * x (x) float64 32.0 45.71 59.43 73.14 86.86 100.6 114.3 128.0 * y (y) float64 16.0 44.0 72.0 100.0 128.0 * t (t) int64 0 1 2 3 4 Data variables: u (x, y, t) float64 1.0 1.0 1.0 1.0 1.0 2.75 ... 8.0 8.0 8.0 8.0 8.0 v (x, y, t) float64 -0.1917 0.4701 -0.3205 ... 0.8455 0.5244 0.3326 chc (x, y, t) float64 1.0 1.0 1.0 1.0 1.0 1.0 ... 1.0 1.0 1.0 1.0 1.0 Attributes: variables: ['x', 'y', 'u', 'v'] units: ['pix', 'pix', 'pix/dt', 'pix/dt'] dt: 1.0 files:
xarray.Dataset
- t: 5
- x: 8
- y: 5
- x(x)float6432.0 45.71 59.43 ... 114.3 128.0
array([ 32. , 45.714286, 59.428571, 73.142857, 86.857143, 100.571429, 114.285714, 128. ])
- y(y)float6416.0 44.0 72.0 100.0 128.0
array([ 16., 44., 72., 100., 128.])
- t(t)int640 1 2 3 4
array([0, 1, 2, 3, 4])
- u(x, y, t)float641.0 1.0 1.0 1.0 ... 8.0 8.0 8.0 8.0
array([[[1. , 1. , 1. , 1. , 1. ], [2.75, 2.75, 2.75, 2.75, 2.75], [4.5 , 4.5 , 4.5 , 4.5 , 4.5 ], [6.25, 6.25, 6.25, 6.25, 6.25], [8. , 8. , 8. , 8. , 8. ]], [[1. , 1. , 1. , 1. , 1. ], [2.75, 2.75, 2.75, 2.75, 2.75], [4.5 , 4.5 , 4.5 , 4.5 , 4.5 ], [6.25, 6.25, 6.25, 6.25, 6.25], [8. , 8. , 8. , 8. , 8. ]], [[1. , 1. , 1. , 1. , 1. ], [2.75, 2.75, 2.75, 2.75, 2.75], [4.5 , 4.5 , 4.5 , 4.5 , 4.5 ], [6.25, 6.25, 6.25, 6.25, 6.25], [8. , 8. , 8. , 8. , 8. ]], [[1. , 1. , 1. , 1. , 1. ], [2.75, 2.75, 2.75, 2.75, 2.75], ... [6.25, 6.25, 6.25, 6.25, 6.25], [8. , 8. , 8. , 8. , 8. ]], [[1. , 1. , 1. , 1. , 1. ], [2.75, 2.75, 2.75, 2.75, 2.75], [4.5 , 4.5 , 4.5 , 4.5 , 4.5 ], [6.25, 6.25, 6.25, 6.25, 6.25], [8. , 8. , 8. , 8. , 8. ]], [[1. , 1. , 1. , 1. , 1. ], [2.75, 2.75, 2.75, 2.75, 2.75], [4.5 , 4.5 , 4.5 , 4.5 , 4.5 ], [6.25, 6.25, 6.25, 6.25, 6.25], [8. , 8. , 8. , 8. , 8. ]], [[1. , 1. , 1. , 1. , 1. ], [2.75, 2.75, 2.75, 2.75, 2.75], [4.5 , 4.5 , 4.5 , 4.5 , 4.5 ], [6.25, 6.25, 6.25, 6.25, 6.25], [8. , 8. , 8. , 8. , 8. ]]])
- v(x, y, t)float64-0.1917 0.4701 ... 0.5244 0.3326
array([[[-0.19173369, 0.47013406, -0.32054064, -0.0757848 , 0.08673771], [-0.06673369, 0.59513406, -0.19554064, 0.0492152 , 0.21173771], [ 0.05826631, 0.72013406, -0.07054064, 0.1742152 , 0.33673771], [ 0.18326631, 0.84513406, 0.05445936, 0.2992152 , 0.46173771], [ 0.30826631, 0.97013406, 0.17945936, 0.4242152 , 0.58673771]], [[-0.25754662, 0.23238447, -0.1176686 , 0.05972362, -0.23222527], [-0.13254662, 0.35738447, 0.0073314 , 0.18472362, -0.10722527], [-0.00754662, 0.48238447, 0.1323314 , 0.30972362, 0.01777473], [ 0.11745338, 0.60738447, 0.2573314 , 0.43472362, 0.14277473], [ 0.24245338, 0.73238447, 0.3823314 , 0.55972362, ... -0.28413527], [ 0.52145588, -0.36426683, 0.14361845, -0.21303802, -0.15913527], [ 0.64645588, -0.23926683, 0.26861845, -0.08803802, -0.03413527], [ 0.77145588, -0.11426683, 0.39361845, 0.03696198, 0.09086473], [ 0.89645588, 0.01073317, 0.51861845, 0.16196198, 0.21586473]], [[ 0.35206705, 0.12177763, 0.34548154, 0.02444069, -0.16737367], [ 0.47706705, 0.24677763, 0.47048154, 0.14944069, -0.04237367], [ 0.60206705, 0.37177763, 0.59548154, 0.27444069, 0.08262633], [ 0.72706705, 0.49677763, 0.72048154, 0.39944069, 0.20762633], [ 0.85206705, 0.62177763, 0.84548154, 0.52444069, 0.33262633]]])
- chc(x, y, t)float641.0 1.0 1.0 1.0 ... 1.0 1.0 1.0 1.0
array([[[1., 1., 1., 1., 1.], [1., 1., 1., 1., 1.], [1., 1., 1., 1., 1.], [1., 1., 1., 1., 1.], [1., 1., 1., 1., 1.]], [[1., 1., 1., 1., 1.], [1., 1., 1., 1., 1.], [1., 1., 1., 1., 1.], [1., 1., 1., 1., 1.], [1., 1., 1., 1., 1.]], [[1., 1., 1., 1., 1.], [1., 1., 1., 1., 1.], [1., 1., 1., 1., 1.], [1., 1., 1., 1., 1.], [1., 1., 1., 1., 1.]], [[1., 1., 1., 1., 1.], [1., 1., 1., 1., 1.], ... [1., 1., 1., 1., 1.], [1., 1., 1., 1., 1.]], [[1., 1., 1., 1., 1.], [1., 1., 1., 1., 1.], [1., 1., 1., 1., 1.], [1., 1., 1., 1., 1.], [1., 1., 1., 1., 1.]], [[1., 1., 1., 1., 1.], [1., 1., 1., 1., 1.], [1., 1., 1., 1., 1.], [1., 1., 1., 1., 1.], [1., 1., 1., 1., 1.]], [[1., 1., 1., 1., 1.], [1., 1., 1., 1., 1.], [1., 1., 1., 1., 1.], [1., 1., 1., 1., 1.], [1., 1., 1., 1., 1.]]])
- variables :
- ['x', 'y', 'u', 'v']
- units :
- ['pix', 'pix', 'pix/dt', 'pix/dt']
- dt :
- 1.0
- files :
[5]:
plt.figure(figsize=(10,10))
graphics.quiver(df.piv.average,arrScale=3,streamlines=True);
[6]:
plt.figure(figsize=(10,10))
# plot quiver of the first frame (t[0]), selected by .isel and apply quiver()
df.isel(t=0).piv.quiver(arrScale=7,streamlines=True)
[6]:
(<Figure size 720x720 with 1 Axes>,
<AxesSubplot:xlabel='x(pix)', ylabel='y (pix)'>)
[26]:
fig,ax = graphics.contour_plot(df.isel(t=-1),colbar='vertical')
fig.set_size_inches(6,6)
ax.set_xlabel('$x$ (pix)',fontsize=16);
[ ]: