# ddr_davis_data
Pakcage uses lvreader(1.2.0) to read and write .set file of Davis. lvreader is not installed with the package and hence it has to be installed separately. lvreader is not available on pypi (as of Sept 2022).
### Download and install lvreader
<a href="https://www.lavision.de/en/downloads/software/python_add_ons.php" target="_blank">Download *.zip* file of lvreader(1.2.0) from here</a>
Extract the *.zip* file. lvreader has good manual to understand its usage. For independent use of lvreader, user can follow the manual. We will install the lvreader in our sytem from the *.whl* (wheel) files.
Inside there are multiple *.whl* files. According to the python version, the resective file needs to be installed. for Python 3.9.0 install *lvreader-1.2.0-cp39-cp39-win_amd64.whl*. For Python 3.10 install *lvreader-1.2.0-cp310-cp310-win_amd64.whl*.
<sub>Above instructions assumes Windows as OS. For Linux the *.whl* file name changes which is easily distinguishable in the list of files.</sub>
Then open Anaconda powershell or cmd.exe. navigate to the extracted folder and perform the installation using pip.
```py
pip install lvreader-1.2.0-cp310-cp310-win_amd64.whl
```
<sub>Select the file name according to the Python version or-else the error will come.</sub>
We have installed lvreader and all its required dependecies in the system. Now we will install ddr_davis_data
### Install ddr_davis_data
Install ddr_davis_data using pip.
```py
pip install ddr_davis_data
```
### Instantiation
```py
import ddr_davis_data
import matplotlib.pyplot as plt
import numpy as np
import os
print(ddr_davis_data.version)
```
0.1.19
We need the filepath to Davis set. Here, we will take one average velocity set file. In Davis the files are arranges in chronological manner. The base or the first set (folder containing files) is of recorded images. Then folder inside the base set can be anything depending upon the processing performed. If background image is subtracted then, the next folder would contain subtracted images. Then next folder inside that folder would be instantaneous and then average velocity folder. The hierarchy of the folder depends upon the processing sequence performed. For the case shown here, the hierarchy is as follows.
```
recorded images
│ .im7 files - all images (from 0 to 100 or 1000)
│ ...
| background subtracted images.set
└───background subtracted images
│ .im7 files
│ ...
| instantaneous velocity fields.set
└───instantaneous velocity fields
│ .vc7 files containing Vx, Vy or Vz (depending upon type of PIV)
│ ...
| average velocity field.set
└───average velocity field
│ .vc7 files containing average of Vx, Vy or Vz (depending upon type of PIV)
│ ... another files depending upon the processing
```
In this case, we will take instantaneous set file. The set file is located in the parent directory of the folder as shown above. For the filepath, we can either give the path to *.set* file or folder path.
```py
filepath1 = r'D:\recorded images\background subtracted images\instantaneous velocity fields'
```
```python
s1 = ddr_davis_data.velocity_set(filepath = filepath1, load=True, rec_path=None, load_rec=False)
```
s1 is the velocity set object. If the set folder is in hierarchy of the recorded image, then load_rec=True will load the recording set as well. Loading recording set helps in accessing recoded or raw images. To make the instantiation of velocity_set faster with recording set, it is better to give recoding set folder-path directly to rec_path attribute above.
## Accessing data
Every set file has many of attributes such as *scales, offsets, limits, U0, V0, camera exposure time, Laser power, recording time, recording rate etc.*.
```py
s1.attributes
```
This will give the dictionary-like data of all the attributes attached with the s1 set file.
There are default and intuitive functions to get certain important attributes as follows.
```python
len(s1)
```
100
This gives the number of images in the velocity set.
```python
s1.recording_rate
```
10.0
gives the recording rate of the s1 set file. similary the time delta in between the frames can be accesssed by,
```python
s1.dt
```
49.0
Depending upon the way Davis packs the data, sometimes the attribute name changes and then the above functions might not work. At that time it is better to access data using
```py
s1.attributes
```
### Velocity data
Velocity data can be accessed by giving comonent name. Method returns the numpy_masked_array like data.
```python
s1.u(n=0)
```
masked_array(
data=[[--, --, --, ..., --, --, --],
[--, --, --, ..., --, --, --],
[--, --, --, ..., --, --, --],
...,
[--, --, --, ..., --, --, --],
[--, --, --, ..., --, --, --],
[--, --, --, ..., --, --, --]],
mask=[[ True, True, True, ..., True, True, True],
[ True, True, True, ..., True, True, True],
[ True, True, True, ..., True, True, True],
...,
[ True, True, True, ..., True, True, True],
[ True, True, True, ..., True, True, True],
[ True, True, True, ..., True, True, True]],
fill_value=0.0)
This is the $V_x$ velocity with masks. Mask crops the useful data from the overall image. During velocity calculation in Davis if Mask is enabled (geometric mask) then the output velocities will have mask accordingly. Mostly PIV frames are not 100% used for velocity measurements. Meaning if jet is flowing from center of the image then the corners of the image is rendered useless for velocity measurement. Masks helps in neglecting those areas. It only considers the area of interest.
Similarly $V_y$ can be accessed as follows.
```python
s1.v(n=21)
```
masked_array(
data=[[--, --, --, ..., --, --, --],
[--, --, --, ..., --, --, --],
[--, --, --, ..., --, --, --],
...,
[--, --, --, ..., --, --, --],
[--, --, --, ..., --, --, --],
[--, --, --, ..., --, --, --]],
mask=[[ True, True, True, ..., True, True, True],
[ True, True, True, ..., True, True, True],
[ True, True, True, ..., True, True, True],
...,
[ True, True, True, ..., True, True, True],
[ True, True, True, ..., True, True, True],
[ True, True, True, ..., True, True, True]],
fill_value=0.0)
n is the image number for which velocity is enquired. If there are 100 images then n ranges from 0 to 99. As s1 is instantaneous set file, it contains many *.vc7* files. But for average set file, there will be only one .vc7 file which will have average of velocity components, then n should be 0 (which is its default value).
```py
s1.vector_coords(n=0)
```
x= [[-1. -0.99659864 -0.99319728 ... -0.00680272 -0.00340136
0. ]
[-1. -0.99659864 -0.99319728 ... -0.00680272 -0.00340136
0. ]
[-1. -0.99659864 -0.99319728 ... -0.00680272 -0.00340136
0. ]
...
[-1. -0.99659864 -0.99319728 ... -0.00680272 -0.00340136
0. ]
[-1. -0.99659864 -0.99319728 ... -0.00680272 -0.00340136
0. ]
[-1. -0.99659864 -0.99319728 ... -0.00680272 -0.00340136
0. ]]
y= [[ 0. 0. 0. ... 0. 0.
0. ]
[-0.00452489 -0.00452489 -0.00452489 ... -0.00452489 -0.00452489
-0.00452489]
[-0.00904977 -0.00904977 -0.00904977 ... -0.00904977 -0.00904977
-0.00904977]
...
[-0.99095023 -0.99095023 -0.99095023 ... -0.99095023 -0.99095023
-0.99095023]
[-0.99547511 -0.99547511 -0.99547511 ... -0.99547511 -0.99547511
-0.99547511]
[-1. -1. -1. ... -1. -1.
-1. ]]
Returns tuples of numpy-array like data. The data is mesh-grid of $X$ and $Y$ coordinates of velocity vectors.
# Plotting
Contour, Streamline, Quiver etc. plots can be made from the meshgrid coordinate data and velocity vector data which we accessed above. There are special methods which is described below to output the data for plots and also there are plotting functions in the library to directly plot the data.
```py
s1.plot(n=10)
```
![png](https://github.com/dev-ddr/ddr_davis_data/blob/base/README_files/output_21_0.png?raw=true)
Above code directly access the ` lvreader.frame.VectorFrame.plot()` function. There are separate functions in the module to plot various informations.
### Plot filled contour
`ddr_davis_data.plot_contourf(*args,**kwargs)` is used to plot filled contour. There are 2 ways to use the function.
#### 1) Giving velocity_set as input
```py
fig = plt.figure(figsize=(3,1.5))
ax = fig.add_subplot(111)
ddr_davis_data.plot_contourf(ax=ax, vel_set=s1, n=10, z='velocity_magnitude', font_size=7,
ctitle='|V|',clabel='[m/s]',labelpad=10)
plt.show()
```
![png](https://github.com/dev-ddr/ddr_davis_data/blob/base/README_files/output_23_0.png?raw=true)
`n` is the image/frame number. `z` determines which scalar to plot. There are many options to that depending upon the Davis output file. Currently 'u,v,velocity_magnitude, omega_z, Wz, TKE' options are available. There is a workaround this method of plotting which we will see shortly. Other attributes can be understood from its name or from plot outcome.
##### Multiple axes
`ax` is the axes on which to plot the contour. If there are multiple subplots then this attribute is very helpful. Below code plots the $V_x$ and $V_y$ in two different subplots.
```py
fig = plt.figure(figsize=(8,2))
ax1 = fig.add_subplot(121)
ddr_davis_data.plot_contourf(ax=ax1, vel_set=s1, n=7, z='u', font_size=10,
ctitle='$V_x$',clabel='[m/s]',labelpad=10)
ax2 = fig.add_subplot(122)
ddr_davis_data.plot_contourf(ax=ax2, vel_set=s1, n=7, z='v', font_size=10,
ctitle='$V_y$',clabel='[m/s]',labelpad=10)
plt.show()
```
![png](https://github.com/dev-ddr/ddr_davis_data/blob/base/README_files/output_25_0.png?raw=true)
#### 2) Giving data as input
This method of plotting gives better control over the data to be plotted. In the previous example, we gave velocity_set as input. The plotting function makes the data inside using `z` value. If we make the data outside the function and give the data to plotting function then it will do the same thing, but we could do multiple mathematical manipulation of data before plotting.
`data` should be dictionary like object.
```py
d1 = s1.make_data(n=10)
```
Gives the dict output with 'x','y','u' and 'v' keys with numpy_masked array like values. To make the data ready for plotting `d1['z']` should be set to the scalar which we want to plot.
```py
fig = plt.figure(figsize=(8,2))
d1 = s1.make_data(n=10)
ax1 = fig.add_subplot(121)
d1['z'] = d1['u']
ddr_davis_data.plot_contourf(ax=ax1,data=d1,font_size=7,ctitle='$V_x$ [m/s]')
ax2 = fig.add_subplot(122)
d1['z'] = d1['v']
ddr_davis_data.plot_contourf(ax=ax2,data=d1,font_size=7,ctitle='$V_y$ [m/s]')
plt.show()
```
![png](https://github.com/dev-ddr/ddr_davis_data/blob/base/README_files/output_27_0.png?raw=true)
This will plot the same figure as plotted previously using velocity_set. Now here we could do mathematical manipulation of data before storing it to `d1['z']`. If both `vel_set` and `data` are defined then `data` is given the priority above `vel_set`.
#### Common colorbar and use of `vmax` and `vmin`
`vmax` and `vmin` comes handy when we want to plot common colorbar for multiple subfigures. below code shows the example for the same.
```py
vmin= -1
vmax= 0
colormap='hot'
fig = plt.figure(figsize=(5,1.5))
d1 = s1.make_data(n=10)
ax1 = fig.add_subplot(121)
d1['z'] = d1['u']
ddr_davis_data.plot_contourf(ax=ax1,data=d1,
vmax=vmax,vmin=vmin,add_colorbar=False,colormap=colormap)
ax2 = fig.add_subplot(122)
d1['z'] = d1['v']
ddr_davis_data.plot_contourf(ax=ax2,data=d1,
vmax=vmax,vmin=vmin,add_colorbar=False,colormap=colormap)
plt.tight_layout()
#adding colorbar to the right
plt.subplots_adjust(right=0.85)
ax = fig.add_axes([0.92,0.05,0.015,0.85])
ddr_davis_data.plot_colorbar(vmin=vmin,vmax=vmax,cax=ax,font_size=7,colormap=colormap,roundto=2,ctitle='$Common$ [m/s]')
plt.show()
```
![png](https://github.com/dev-ddr/ddr_davis_data/blob/base/README_files/output_29_0.png?raw=true)
In the above plots we have changed the type of `colormap` to *hot*.
### Plot quiver (vectors)
The method to plot the quiver is almost same as above. It shares the same code architechture. There is difference in `fracx` and `fracy` attributes, which controlls the amount of vectors displayed in $X$ and $Y$ axes respectively. The higher the number, less the amount of vectors displayed.
Vectors makes more sense when displayed over the contour plot. Hence below figure will plot vectors over the contour plot.
```py
fig = plt.figure(figsize=(3,1.5))
ax1 = fig.add_subplot(111)
d1 = s1.make_data(n=10)
#calculating velocity_magnitude
d1['z'] = (d1['u']**2 + d1['v']**2)**0.5
#plotting contour of velocity magnitude
ddr_davis_data.plot_contourf(ax=ax1,data=d1,font_size=7,ctitle='|V| [m/s]')
#plotting vectors, here the width and scale are adjusted for better vision
ddr_davis_data.plot_quiver(ax=ax1,data=d1,fracx=5,fracy=5,scale=20,width=0.007,color='#000000ff',normalize=True)
plt.show()
```
`normalize = True` attribute will normalize the velocity values. This helps when the velocity magnitudes changes very much within the plot.
![png](https://github.com/dev-ddr/ddr_davis_data/blob/base/README_files/output_31_0.png?raw=true)
### Plot streamlines
When data from `s1.make_data()` is supplied to `matplotlib.pyplot.streamplot()` then error of `strictly increasing array` pops up. Hence turnaround was to use 1D linear array. There is special function within the velocity_set object which gives the data to plot for streamlines.
```py
fig = plt.figure(figsize=(3,1.5))
ax1 = fig.add_subplot(111)
d1 = s1.make_data(n=10)
d1['z'] = (d1['u']**2 + d1['v']**2)**0.5
ddr_davis_data.plot_contourf(ax=ax1,data=d1,font_size=7,ctitle='|V| [m/s]')
d1 = s1.make_streamline_data(n=10)
ddr_davis_data.plot_streamlines(ax=ax1,data=d1,density=(5,5),linewidth=1,color='white',arrowsize=0.01)
plt.show()
```
![png](https://github.com/dev-ddr/ddr_davis_data/blob/base/README_files/output_33_0.png?raw=true)
here `arrowsize` is 0.01 for better visualization. But for some cases, default `arrowsize` gives good results.
## get $\omega_z$
There is a function to calculate $\omega_z$ from the data. The function accepts the data in dict like object form.
```py
d1 = s1.make_data(n=0)
d1 = get_omega_z(data=d1)
```
```d1['z']``` contains the calculated $\omega_z$ from the given data. You can further use this dict like data in plotting or any analysis.
Similarly there is function ```get_mod_V``` which accepts the same dict like data, and calculates the velocity magnitude. As this calculation is one line and you can do it easily, the usage of function is not specifically described here.
## Accessing recording images
Recording images can be accessed if `load_rec=True` in instantiation of velocity_set object. Also there should be recording *.set* files in the parent directory (at any level) of the velocity set file.
```python
s1 = ddr_davis_data.velocity_set(filepath = filepath1, load=True, rec_path=None, load_rec=True)
```
### plotting the image
The structure to plot image is similar to contour plot.
- make the data `d1 = s1.make_image_data(n=10)`
- plot the data `ddr_davis_data.plot_image(data=d1)`
```py
fig = plt.figure(figsize=(3,1.5))
ax1 = fig.add_subplot(111)
d1 = s1.make_image_data(n=10,frame=0)
ddr_davis_data.plot_image(ax=ax1,data=d1,vmin=0,vmax=60)
plt.show()
```
![png](https://github.com/dev-ddr/ddr_davis_data/blob/base/README_files/output_37_0.png?raw=true)
## Rotate bases
Davis considers the $V_x$ in horizontal direction and $V_y$ in vertical direction. But for some cases, the physical bases (coordinate system) can be different. Say, $45^{\circ}$. Then we need to project our vectors in that perticular bases. `rotate_bases()` function does the work for us. Rotation angle must be in degrees.
```python
vmin= -1
vmax= 1
colormap='cool'
fig = plt.figure(figsize=(5,1.5))
ax1 = fig.add_subplot(121)
d1 = s1.make_data(n=25)
d1['z'] = d1['u']
ddr_davis_data.plot_contourf(ax=ax1,data=d1,
vmax=vmax,vmin=vmin,add_colorbar=False,colormap=colormap)
ax1.set_title('original bases')
ax2 = fig.add_subplot(122)
# this function rotates the bases
d1 = ddr_davis_data.rotate_bases(d1,angle=45)
ddr_davis_data.plot_contourf(ax=ax2,data=d1,
vmax=vmax,vmin=vmin,add_colorbar=False,colormap=colormap)
ax2.set_title('rotated bases')
plt.tight_layout()
plt.subplots_adjust(right=0.85)
ax = fig.add_axes([0.92,0.05,0.015,0.85])
ddr_davis_data.plot_colorbar(vmin=vmin,vmax=vmax,cax=ax,font_size=7,
colormap=colormap,roundto=2,ctitle='$V_x$ [m/s]',cticks=5)
plt.show()
```
![png](https://github.com/dev-ddr/ddr_davis_data/blob/base/README_files/output_39_0.png?raw=true)
`rotate_bases()` function returns the same dict like data type with $V_x$ and $V_y$ projected on rotated bases. here X and Y axis are not rotated. Only the velocities are represented in new bases. So, now in new $V_x$ the x axis is aligned at $45^{\circ}$ from the horizontal.
> note that the axis are not rotated. Here the velocity and any point (x,y) is projected on new bases but the velocity vector is still of point (x,y).
## Rotate Coordinate axis
To rotate the coordinate system we can use the `rotate_coordinates_degrees()` function. Here input angle must be in degrees.
```python
vmin= -1
vmax= 1
colormap='cool'
fig = plt.figure(figsize=(5,1.5))
ax1 = fig.add_subplot(121)
d1 = s1.make_data(n=25)
d1['z'] = d1['u']
ddr_davis_data.plot_contourf(ax=ax1,data=d1,
vmax=vmax,vmin=vmin,add_colorbar=False,colormap=colormap)
ax2 = fig.add_subplot(122)
d1['x'],d1['y'] = ddr_davis_data.rotate_coordinates_degrees(d1['x'],d1['y'],angle=45)
ddr_davis_data.plot_contourf(ax=ax2,data=d1,
vmax=vmax,vmin=vmin,add_colorbar=False,colormap=colormap)
plt.tight_layout()
plt.subplots_adjust(right=0.85)
ax = fig.add_axes([0.92,0.05,0.015,0.85])
ddr_davis_data.plot_colorbar(vmin=vmin,vmax=vmax,cax=ax,font_size=7,
colormap=colormap,roundto=2,ctitle='$V_x$ [m/s]',cticks=5)
plt.show()
```
![png](https://github.com/dev-ddr/ddr_davis_data/blob/base/README_files/output_41_0.png?raw=true)
## Get data at a point
`get_data_at_point()` function gives the `z` value at `(px,py)` point from the domain.
```python
d1 = s1.make_data(n=25)
d1['z'] = d1['u']
print(ddr_davis_data.get_data_at_point(data=d1,px=20,py=50))
```
-1.3974445965482185
## Get data at (on) the line
`get_data_at_line()` function returns the x,y,z values. where x,y are points on the line and z is the scalar at al (x,y) points.
```python
d1 = s1.make_data(n=25)
d1['z'] = d1['u']
# getting data over the line
x,y,z = ddr_davis_data.get_data_at_line(data=d1,x1=-30,y1=20,x2=40,y2=50,n_points=100)
fig = plt.figure(figsize=(5,1.5))
ax1 = fig.add_subplot(121)
# plotting contour plot
ddr_davis_data.plot_contourf(data=d1,vmax=1,vmin=-1,ax=ax1,font_size=5,colormap='cool')
#plotting line over the contour plot
ax1.scatter(x,y,s=1,c='k')
ax2 = fig.add_subplot(122)
# plotting z values w.r.t y
ax2.scatter(y,z/z.max(),s=1,c='k')
plt.tight_layout()
plt.show()
```
![png](https://github.com/dev-ddr/ddr_davis_data/blob/base/README_files/output_46_0.png?raw=true)
## Saving the data to other directory in .npy format
We need to give the name to the set and the folder path where the set will be stored. The function stores the X, Y coordinates and stores the U and V velocities image wise in subfolder.
```py
set_foldpath = r'D:'
set_name = 'set1'
```
```python
ddr_davis_data.save_set(s1,set_name=set_name,set_foldpath=set_foldpath,
n_start=0,n_end=3,print_info=True)
```
saving velocities
0
1
2
`n_start` and `n_end` specifies the starting and ending velocity files to be stored. `print_info = False` will disable the output shown above
## Working with local data
We can give the path to above local set, and perform all the operation with velocity datas. As we have not saved any attributes we could not retrieve it with local data.
```python
# loading local set
ls1 = ddr_davis_data.local_set(set_name=set_name,set_foldpath=set_foldpath)
fig = plt.figure(figsize=(3,1.5))
#plotting the contour plot
d1 = ls1.make_data(n=2)
d1['z'] = d1['u']
ddr_davis_data.plot_contourf(data=d1,vmax=1,vmin=-1,colormap='cool',font_size=5)
plt.show()
```
![png](https://github.com/dev-ddr/ddr_davis_data/blob/base/README_files/output_53_0.png?raw=true)
we can get the length of the local set as follows
```python
print(len(ls1))
```
3
## Handling multiple velocitites frames
multiple velocities frames can be combined togather in single 3-D array. That array can be saved and retried later. We call this kind of multiple frames as `Us` and `Vs`.
```python
# make 3-D array
print(ls1.get_multiple_u(0,3).shape)
```
(222, 295, 3)
Save the `Us` and `Vs`.
```python
ls1.save_UVs(n_start=0,n_end=-1)
```
Load the `Us`
```python
print(ls1.Vs.shape)
```
(222, 295, 3)
---
---
Raw data
{
"_id": null,
"home_page": "https://github.com/ddrathod121294/ddr_davis_data",
"name": "ddr-davis-data",
"maintainer": null,
"docs_url": null,
"requires_python": "<4,>=3.10",
"maintainer_email": null,
"keywords": "ddr, davis, davis_data, davis_data_manager, ddr_davis_data",
"author": "Darshan Rathod",
"author_email": "darshan.rathod1994@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/79/45/20a3f586541ca6ad751827f024ea988549c2b307f5284d637e6c99874c91/ddr_davis_data-0.1.25.tar.gz",
"platform": null,
"description": "# ddr_davis_data\nPakcage uses lvreader(1.2.0) to read and write .set file of Davis. lvreader is not installed with the package and hence it has to be installed separately. lvreader is not available on pypi (as of Sept 2022).\n\n### Download and install lvreader\n<a href=\"https://www.lavision.de/en/downloads/software/python_add_ons.php\" target=\"_blank\">Download *.zip* file of lvreader(1.2.0) from here</a>\n\nExtract the *.zip* file. lvreader has good manual to understand its usage. For independent use of lvreader, user can follow the manual. We will install the lvreader in our sytem from the *.whl* (wheel) files.\nInside there are multiple *.whl* files. According to the python version, the resective file needs to be installed. for Python 3.9.0 install *lvreader-1.2.0-cp39-cp39-win_amd64.whl*. For Python 3.10 install *lvreader-1.2.0-cp310-cp310-win_amd64.whl*.\n\n<sub>Above instructions assumes Windows as OS. For Linux the *.whl* file name changes which is easily distinguishable in the list of files.</sub>\n\nThen open Anaconda powershell or cmd.exe. navigate to the extracted folder and perform the installation using pip.\n```py\npip install lvreader-1.2.0-cp310-cp310-win_amd64.whl\n```\n<sub>Select the file name according to the Python version or-else the error will come.</sub>\n\nWe have installed lvreader and all its required dependecies in the system. Now we will install ddr_davis_data\n\n### Install ddr_davis_data\nInstall ddr_davis_data using pip.\n```py\npip install ddr_davis_data\n```\n### Instantiation\n\n```py\nimport ddr_davis_data\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport os\n\nprint(ddr_davis_data.version)\n```\n\n 0.1.19\n \n\nWe need the filepath to Davis set. Here, we will take one average velocity set file. In Davis the files are arranges in chronological manner. The base or the first set (folder containing files) is of recorded images. Then folder inside the base set can be anything depending upon the processing performed. If background image is subtracted then, the next folder would contain subtracted images. Then next folder inside that folder would be instantaneous and then average velocity folder. The hierarchy of the folder depends upon the processing sequence performed. For the case shown here, the hierarchy is as follows.\n\n```\nrecorded images\n\u2502 .im7 files - all images (from 0 to 100 or 1000)\n\u2502 ...\n| background subtracted images.set\n\u2514\u2500\u2500\u2500background subtracted images\n \u2502 .im7 files\n \u2502 ...\n | instantaneous velocity fields.set\n \u2514\u2500\u2500\u2500instantaneous velocity fields\n \u2502 .vc7 files containing Vx, Vy or Vz (depending upon type of PIV)\n \u2502 ...\n | average velocity field.set\n \u2514\u2500\u2500\u2500average velocity field\n \u2502 .vc7 files containing average of Vx, Vy or Vz (depending upon type of PIV)\n \u2502 ... another files depending upon the processing\n```\nIn this case, we will take instantaneous set file. The set file is located in the parent directory of the folder as shown above. For the filepath, we can either give the path to *.set* file or folder path.\n\n```py\nfilepath1 = r'D:\\recorded images\\background subtracted images\\instantaneous velocity fields'\n```\n\n\n```python\ns1 = ddr_davis_data.velocity_set(filepath = filepath1, load=True, rec_path=None, load_rec=False)\n```\n\ns1 is the velocity set object. If the set folder is in hierarchy of the recorded image, then load_rec=True will load the recording set as well. Loading recording set helps in accessing recoded or raw images. To make the instantiation of velocity_set faster with recording set, it is better to give recoding set folder-path directly to rec_path attribute above.\n\n## Accessing data\n\nEvery set file has many of attributes such as *scales, offsets, limits, U0, V0, camera exposure time, Laser power, recording time, recording rate etc.*.\n```py\ns1.attributes\n```\nThis will give the dictionary-like data of all the attributes attached with the s1 set file.\nThere are default and intuitive functions to get certain important attributes as follows.\n\n\n```python\nlen(s1)\n```\n\n\n\n\n 100\n\n\n\nThis gives the number of images in the velocity set.\n\n\n```python\ns1.recording_rate\n```\n\n\n\n\n 10.0\n\n\n\ngives the recording rate of the s1 set file. similary the time delta in between the frames can be accesssed by,\n\n\n```python\ns1.dt\n```\n\n\n\n\n 49.0\n\n\n\nDepending upon the way Davis packs the data, sometimes the attribute name changes and then the above functions might not work. At that time it is better to access data using\n```py\ns1.attributes\n```\n\n### Velocity data\nVelocity data can be accessed by giving comonent name. Method returns the numpy_masked_array like data.\n\n\n```python\ns1.u(n=0)\n```\n\n\n\n\n masked_array(\n data=[[--, --, --, ..., --, --, --],\n [--, --, --, ..., --, --, --],\n [--, --, --, ..., --, --, --],\n ...,\n [--, --, --, ..., --, --, --],\n [--, --, --, ..., --, --, --],\n [--, --, --, ..., --, --, --]],\n mask=[[ True, True, True, ..., True, True, True],\n [ True, True, True, ..., True, True, True],\n [ True, True, True, ..., True, True, True],\n ...,\n [ True, True, True, ..., True, True, True],\n [ True, True, True, ..., True, True, True],\n [ True, True, True, ..., True, True, True]],\n fill_value=0.0)\n\n\n\nThis is the $V_x$ velocity with masks. Mask crops the useful data from the overall image. During velocity calculation in Davis if Mask is enabled (geometric mask) then the output velocities will have mask accordingly. Mostly PIV frames are not 100% used for velocity measurements. Meaning if jet is flowing from center of the image then the corners of the image is rendered useless for velocity measurement. Masks helps in neglecting those areas. It only considers the area of interest.\n\nSimilarly $V_y$ can be accessed as follows.\n\n\n```python\ns1.v(n=21)\n```\n\n\n\n\n masked_array(\n data=[[--, --, --, ..., --, --, --],\n [--, --, --, ..., --, --, --],\n [--, --, --, ..., --, --, --],\n ...,\n [--, --, --, ..., --, --, --],\n [--, --, --, ..., --, --, --],\n [--, --, --, ..., --, --, --]],\n mask=[[ True, True, True, ..., True, True, True],\n [ True, True, True, ..., True, True, True],\n [ True, True, True, ..., True, True, True],\n ...,\n [ True, True, True, ..., True, True, True],\n [ True, True, True, ..., True, True, True],\n [ True, True, True, ..., True, True, True]],\n fill_value=0.0)\n\n\n\nn is the image number for which velocity is enquired. If there are 100 images then n ranges from 0 to 99. As s1 is instantaneous set file, it contains many *.vc7* files. But for average set file, there will be only one .vc7 file which will have average of velocity components, then n should be 0 (which is its default value).\n\n```py\ns1.vector_coords(n=0)\n```\n\n x= [[-1. -0.99659864 -0.99319728 ... -0.00680272 -0.00340136\n 0. ]\n [-1. -0.99659864 -0.99319728 ... -0.00680272 -0.00340136\n 0. ]\n [-1. -0.99659864 -0.99319728 ... -0.00680272 -0.00340136\n 0. ]\n ...\n [-1. -0.99659864 -0.99319728 ... -0.00680272 -0.00340136\n 0. ]\n [-1. -0.99659864 -0.99319728 ... -0.00680272 -0.00340136\n 0. ]\n [-1. -0.99659864 -0.99319728 ... -0.00680272 -0.00340136\n 0. ]]\n y= [[ 0. 0. 0. ... 0. 0.\n 0. ]\n [-0.00452489 -0.00452489 -0.00452489 ... -0.00452489 -0.00452489\n -0.00452489]\n [-0.00904977 -0.00904977 -0.00904977 ... -0.00904977 -0.00904977\n -0.00904977]\n ...\n [-0.99095023 -0.99095023 -0.99095023 ... -0.99095023 -0.99095023\n -0.99095023]\n [-0.99547511 -0.99547511 -0.99547511 ... -0.99547511 -0.99547511\n -0.99547511]\n [-1. -1. -1. ... -1. -1.\n -1. ]]\n \n\nReturns tuples of numpy-array like data. The data is mesh-grid of $X$ and $Y$ coordinates of velocity vectors.\n\n# Plotting\nContour, Streamline, Quiver etc. plots can be made from the meshgrid coordinate data and velocity vector data which we accessed above. There are special methods which is described below to output the data for plots and also there are plotting functions in the library to directly plot the data.\n\n```py\ns1.plot(n=10)\n```\n\n\n \n![png](https://github.com/dev-ddr/ddr_davis_data/blob/base/README_files/output_21_0.png?raw=true)\n \n\n\nAbove code directly access the ` lvreader.frame.VectorFrame.plot()` function. There are separate functions in the module to plot various informations.\n\n### Plot filled contour\n\n`ddr_davis_data.plot_contourf(*args,**kwargs)` is used to plot filled contour. There are 2 ways to use the function.\n\n#### 1) Giving velocity_set as input\n```py\nfig = plt.figure(figsize=(3,1.5))\nax = fig.add_subplot(111)\n\nddr_davis_data.plot_contourf(ax=ax, vel_set=s1, n=10, z='velocity_magnitude', font_size=7,\n ctitle='|V|',clabel='[m/s]',labelpad=10)\nplt.show()\n```\n\n\n \n![png](https://github.com/dev-ddr/ddr_davis_data/blob/base/README_files/output_23_0.png?raw=true)\n \n\n\n`n` is the image/frame number. `z` determines which scalar to plot. There are many options to that depending upon the Davis output file. Currently 'u,v,velocity_magnitude, omega_z, Wz, TKE' options are available. There is a workaround this method of plotting which we will see shortly. Other attributes can be understood from its name or from plot outcome.\n\n##### Multiple axes\n`ax` is the axes on which to plot the contour. If there are multiple subplots then this attribute is very helpful. Below code plots the $V_x$ and $V_y$ in two different subplots.\n\n```py\nfig = plt.figure(figsize=(8,2))\n\nax1 = fig.add_subplot(121)\nddr_davis_data.plot_contourf(ax=ax1, vel_set=s1, n=7, z='u', font_size=10,\n ctitle='$V_x$',clabel='[m/s]',labelpad=10)\n\nax2 = fig.add_subplot(122)\nddr_davis_data.plot_contourf(ax=ax2, vel_set=s1, n=7, z='v', font_size=10,\n ctitle='$V_y$',clabel='[m/s]',labelpad=10)\n\nplt.show()\n```\n\n\n \n![png](https://github.com/dev-ddr/ddr_davis_data/blob/base/README_files/output_25_0.png?raw=true)\n \n\n\n#### 2) Giving data as input\nThis method of plotting gives better control over the data to be plotted. In the previous example, we gave velocity_set as input. The plotting function makes the data inside using `z` value. If we make the data outside the function and give the data to plotting function then it will do the same thing, but we could do multiple mathematical manipulation of data before plotting.\n\n`data` should be dictionary like object. \n```py\nd1 = s1.make_data(n=10)\n``` \nGives the dict output with 'x','y','u' and 'v' keys with numpy_masked array like values. To make the data ready for plotting `d1['z']` should be set to the scalar which we want to plot.\n\n```py\nfig = plt.figure(figsize=(8,2))\nd1 = s1.make_data(n=10)\n\nax1 = fig.add_subplot(121)\nd1['z'] = d1['u']\nddr_davis_data.plot_contourf(ax=ax1,data=d1,font_size=7,ctitle='$V_x$ [m/s]')\n\nax2 = fig.add_subplot(122)\nd1['z'] = d1['v']\nddr_davis_data.plot_contourf(ax=ax2,data=d1,font_size=7,ctitle='$V_y$ [m/s]')\n\nplt.show()\n```\n\n\n \n![png](https://github.com/dev-ddr/ddr_davis_data/blob/base/README_files/output_27_0.png?raw=true)\n \n\n\nThis will plot the same figure as plotted previously using velocity_set. Now here we could do mathematical manipulation of data before storing it to `d1['z']`. If both `vel_set` and `data` are defined then `data` is given the priority above `vel_set`.\n\n#### Common colorbar and use of `vmax` and `vmin`\n`vmax` and `vmin` comes handy when we want to plot common colorbar for multiple subfigures. below code shows the example for the same.\n```py\n\nvmin= -1\nvmax= 0\ncolormap='hot'\n\nfig = plt.figure(figsize=(5,1.5))\n\nd1 = s1.make_data(n=10)\n\nax1 = fig.add_subplot(121)\nd1['z'] = d1['u']\nddr_davis_data.plot_contourf(ax=ax1,data=d1,\n vmax=vmax,vmin=vmin,add_colorbar=False,colormap=colormap)\n\n\nax2 = fig.add_subplot(122)\nd1['z'] = d1['v']\nddr_davis_data.plot_contourf(ax=ax2,data=d1,\n vmax=vmax,vmin=vmin,add_colorbar=False,colormap=colormap)\n\nplt.tight_layout()\n#adding colorbar to the right\nplt.subplots_adjust(right=0.85)\nax = fig.add_axes([0.92,0.05,0.015,0.85])\nddr_davis_data.plot_colorbar(vmin=vmin,vmax=vmax,cax=ax,font_size=7,colormap=colormap,roundto=2,ctitle='$Common$ [m/s]')\n\nplt.show()\n```\n\n\n \n![png](https://github.com/dev-ddr/ddr_davis_data/blob/base/README_files/output_29_0.png?raw=true)\n \n\n\nIn the above plots we have changed the type of `colormap` to *hot*.\n\n### Plot quiver (vectors)\nThe method to plot the quiver is almost same as above. It shares the same code architechture. There is difference in `fracx` and `fracy` attributes, which controlls the amount of vectors displayed in $X$ and $Y$ axes respectively. The higher the number, less the amount of vectors displayed.\n\nVectors makes more sense when displayed over the contour plot. Hence below figure will plot vectors over the contour plot.\n```py\nfig = plt.figure(figsize=(3,1.5))\nax1 = fig.add_subplot(111)\n\nd1 = s1.make_data(n=10)\n#calculating velocity_magnitude\nd1['z'] = (d1['u']**2 + d1['v']**2)**0.5\n\n#plotting contour of velocity magnitude\nddr_davis_data.plot_contourf(ax=ax1,data=d1,font_size=7,ctitle='|V| [m/s]')\n#plotting vectors, here the width and scale are adjusted for better vision\nddr_davis_data.plot_quiver(ax=ax1,data=d1,fracx=5,fracy=5,scale=20,width=0.007,color='#000000ff',normalize=True)\nplt.show()\n```\n`normalize = True` attribute will normalize the velocity values. This helps when the velocity magnitudes changes very much within the plot.\n\n\n \n![png](https://github.com/dev-ddr/ddr_davis_data/blob/base/README_files/output_31_0.png?raw=true)\n \n\n\n### Plot streamlines\nWhen data from `s1.make_data()` is supplied to `matplotlib.pyplot.streamplot()` then error of `strictly increasing array` pops up. Hence turnaround was to use 1D linear array. There is special function within the velocity_set object which gives the data to plot for streamlines.\n```py\nfig = plt.figure(figsize=(3,1.5))\n\nax1 = fig.add_subplot(111)\nd1 = s1.make_data(n=10)\nd1['z'] = (d1['u']**2 + d1['v']**2)**0.5\n\nddr_davis_data.plot_contourf(ax=ax1,data=d1,font_size=7,ctitle='|V| [m/s]')\nd1 = s1.make_streamline_data(n=10)\nddr_davis_data.plot_streamlines(ax=ax1,data=d1,density=(5,5),linewidth=1,color='white',arrowsize=0.01)\nplt.show()\n```\n\n\n \n![png](https://github.com/dev-ddr/ddr_davis_data/blob/base/README_files/output_33_0.png?raw=true)\n \n\n\nhere `arrowsize` is 0.01 for better visualization. But for some cases, default `arrowsize` gives good results.\n\n## get $\\omega_z$\n\nThere is a function to calculate $\\omega_z$ from the data. The function accepts the data in dict like object form.\n\n```py\nd1 = s1.make_data(n=0)\nd1 = get_omega_z(data=d1)\n\n```\n\n```d1['z']``` contains the calculated $\\omega_z$ from the given data. You can further use this dict like data in plotting or any analysis.\n\nSimilarly there is function ```get_mod_V``` which accepts the same dict like data, and calculates the velocity magnitude. As this calculation is one line and you can do it easily, the usage of function is not specifically described here.\n\n## Accessing recording images\nRecording images can be accessed if `load_rec=True` in instantiation of velocity_set object. Also there should be recording *.set* files in the parent directory (at any level) of the velocity set file.\n\n\n```python\ns1 = ddr_davis_data.velocity_set(filepath = filepath1, load=True, rec_path=None, load_rec=True)\n```\n\n### plotting the image\nThe structure to plot image is similar to contour plot.\n- make the data `d1 = s1.make_image_data(n=10)`\n- plot the data `ddr_davis_data.plot_image(data=d1)`\n\n```py\nfig = plt.figure(figsize=(3,1.5))\nax1 = fig.add_subplot(111)\n\nd1 = s1.make_image_data(n=10,frame=0)\nddr_davis_data.plot_image(ax=ax1,data=d1,vmin=0,vmax=60)\nplt.show()\n```\n\n\n \n![png](https://github.com/dev-ddr/ddr_davis_data/blob/base/README_files/output_37_0.png?raw=true)\n \n\n\n## Rotate bases\nDavis considers the $V_x$ in horizontal direction and $V_y$ in vertical direction. But for some cases, the physical bases (coordinate system) can be different. Say, $45^{\\circ}$. Then we need to project our vectors in that perticular bases. `rotate_bases()` function does the work for us. Rotation angle must be in degrees.\n\n\n```python\nvmin= -1\nvmax= 1\ncolormap='cool'\n\nfig = plt.figure(figsize=(5,1.5))\n\nax1 = fig.add_subplot(121)\nd1 = s1.make_data(n=25)\nd1['z'] = d1['u']\nddr_davis_data.plot_contourf(ax=ax1,data=d1,\n vmax=vmax,vmin=vmin,add_colorbar=False,colormap=colormap)\nax1.set_title('original bases')\n\nax2 = fig.add_subplot(122)\n\n# this function rotates the bases\nd1 = ddr_davis_data.rotate_bases(d1,angle=45)\n\nddr_davis_data.plot_contourf(ax=ax2,data=d1,\n vmax=vmax,vmin=vmin,add_colorbar=False,colormap=colormap)\nax2.set_title('rotated bases')\n\nplt.tight_layout()\nplt.subplots_adjust(right=0.85)\nax = fig.add_axes([0.92,0.05,0.015,0.85])\nddr_davis_data.plot_colorbar(vmin=vmin,vmax=vmax,cax=ax,font_size=7,\n colormap=colormap,roundto=2,ctitle='$V_x$ [m/s]',cticks=5)\n\nplt.show()\n```\n\n\n \n![png](https://github.com/dev-ddr/ddr_davis_data/blob/base/README_files/output_39_0.png?raw=true)\n \n\n\n`rotate_bases()` function returns the same dict like data type with $V_x$ and $V_y$ projected on rotated bases. here X and Y axis are not rotated. Only the velocities are represented in new bases. So, now in new $V_x$ the x axis is aligned at $45^{\\circ}$ from the horizontal.\n> note that the axis are not rotated. Here the velocity and any point (x,y) is projected on new bases but the velocity vector is still of point (x,y).\n\n## Rotate Coordinate axis\nTo rotate the coordinate system we can use the `rotate_coordinates_degrees()` function. Here input angle must be in degrees.\n\n\n```python\nvmin= -1\nvmax= 1\ncolormap='cool'\n\nfig = plt.figure(figsize=(5,1.5))\n\nax1 = fig.add_subplot(121)\nd1 = s1.make_data(n=25)\nd1['z'] = d1['u']\nddr_davis_data.plot_contourf(ax=ax1,data=d1,\n vmax=vmax,vmin=vmin,add_colorbar=False,colormap=colormap)\n\nax2 = fig.add_subplot(122)\nd1['x'],d1['y'] = ddr_davis_data.rotate_coordinates_degrees(d1['x'],d1['y'],angle=45)\nddr_davis_data.plot_contourf(ax=ax2,data=d1,\n vmax=vmax,vmin=vmin,add_colorbar=False,colormap=colormap)\n\nplt.tight_layout()\nplt.subplots_adjust(right=0.85)\nax = fig.add_axes([0.92,0.05,0.015,0.85])\nddr_davis_data.plot_colorbar(vmin=vmin,vmax=vmax,cax=ax,font_size=7,\n colormap=colormap,roundto=2,ctitle='$V_x$ [m/s]',cticks=5)\n\nplt.show()\n```\n\n\n \n![png](https://github.com/dev-ddr/ddr_davis_data/blob/base/README_files/output_41_0.png?raw=true)\n \n\n\n## Get data at a point\n\n`get_data_at_point()` function gives the `z` value at `(px,py)` point from the domain.\n\n\n```python\nd1 = s1.make_data(n=25)\nd1['z'] = d1['u']\nprint(ddr_davis_data.get_data_at_point(data=d1,px=20,py=50))\n```\n\n -1.3974445965482185\n \n\n## Get data at (on) the line\n\n`get_data_at_line()` function returns the x,y,z values. where x,y are points on the line and z is the scalar at al (x,y) points.\n\n\n```python\nd1 = s1.make_data(n=25)\nd1['z'] = d1['u']\n\n# getting data over the line\nx,y,z = ddr_davis_data.get_data_at_line(data=d1,x1=-30,y1=20,x2=40,y2=50,n_points=100)\n\nfig = plt.figure(figsize=(5,1.5))\n\nax1 = fig.add_subplot(121)\n# plotting contour plot\nddr_davis_data.plot_contourf(data=d1,vmax=1,vmin=-1,ax=ax1,font_size=5,colormap='cool')\n#plotting line over the contour plot\nax1.scatter(x,y,s=1,c='k')\n\nax2 = fig.add_subplot(122)\n# plotting z values w.r.t y\nax2.scatter(y,z/z.max(),s=1,c='k')\n\nplt.tight_layout()\nplt.show()\n```\n\n\n \n![png](https://github.com/dev-ddr/ddr_davis_data/blob/base/README_files/output_46_0.png?raw=true)\n \n\n\n## Saving the data to other directory in .npy format\n\nWe need to give the name to the set and the folder path where the set will be stored. The function stores the X, Y coordinates and stores the U and V velocities image wise in subfolder.\n\n```py\nset_foldpath = r'D:'\nset_name = 'set1'\n```\n\n\n```python\nddr_davis_data.save_set(s1,set_name=set_name,set_foldpath=set_foldpath,\n n_start=0,n_end=3,print_info=True)\n```\n\n saving velocities\n 0\n 1\n 2\n \n\n`n_start` and `n_end` specifies the starting and ending velocity files to be stored. `print_info = False` will disable the output shown above\n\n## Working with local data\nWe can give the path to above local set, and perform all the operation with velocity datas. As we have not saved any attributes we could not retrieve it with local data.\n\n\n```python\n# loading local set\nls1 = ddr_davis_data.local_set(set_name=set_name,set_foldpath=set_foldpath)\n\nfig = plt.figure(figsize=(3,1.5))\n#plotting the contour plot\nd1 = ls1.make_data(n=2)\nd1['z'] = d1['u']\nddr_davis_data.plot_contourf(data=d1,vmax=1,vmin=-1,colormap='cool',font_size=5)\nplt.show()\n```\n\n\n \n![png](https://github.com/dev-ddr/ddr_davis_data/blob/base/README_files/output_53_0.png?raw=true)\n \n\n\nwe can get the length of the local set as follows\n\n\n```python\nprint(len(ls1))\n```\n\n 3\n \n\n## Handling multiple velocitites frames\nmultiple velocities frames can be combined togather in single 3-D array. That array can be saved and retried later. We call this kind of multiple frames as `Us` and `Vs`.\n\n\n```python\n# make 3-D array\nprint(ls1.get_multiple_u(0,3).shape)\n```\n\n (222, 295, 3)\n \n\nSave the `Us` and `Vs`.\n\n\n```python\nls1.save_UVs(n_start=0,n_end=-1)\n```\n\nLoad the `Us`\n\n\n```python\nprint(ls1.Vs.shape)\n```\n\n (222, 295, 3)\n \n\n---\n---\n",
"bugtrack_url": null,
"license": null,
"summary": "Package to handle davis data files",
"version": "0.1.25",
"project_urls": {
"Homepage": "https://github.com/ddrathod121294/ddr_davis_data"
},
"split_keywords": [
"ddr",
" davis",
" davis_data",
" davis_data_manager",
" ddr_davis_data"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "decb7b5d7a272ef30c4f32a3791965d79d101d3621748b870dc2c03ea7c2caef",
"md5": "c7ca1243a23456e3bd962e8b40beb16b",
"sha256": "d9b4f61e38fc0cf3dcc8e145532dd04c387e11f8b0df96927e0fe53941ee5b32"
},
"downloads": -1,
"filename": "ddr_davis_data-0.1.25-py3-none-any.whl",
"has_sig": false,
"md5_digest": "c7ca1243a23456e3bd962e8b40beb16b",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4,>=3.10",
"size": 21554,
"upload_time": "2024-05-04T05:44:03",
"upload_time_iso_8601": "2024-05-04T05:44:03.803388Z",
"url": "https://files.pythonhosted.org/packages/de/cb/7b5d7a272ef30c4f32a3791965d79d101d3621748b870dc2c03ea7c2caef/ddr_davis_data-0.1.25-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "794520a3f586541ca6ad751827f024ea988549c2b307f5284d637e6c99874c91",
"md5": "9339dd9af4e94292aaebd7b28cfb397a",
"sha256": "390f893098d3fcf2a5999d8745045ceac3726dc30ab214347a51729ce7e9aa26"
},
"downloads": -1,
"filename": "ddr_davis_data-0.1.25.tar.gz",
"has_sig": false,
"md5_digest": "9339dd9af4e94292aaebd7b28cfb397a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4,>=3.10",
"size": 26079,
"upload_time": "2024-05-04T05:44:05",
"upload_time_iso_8601": "2024-05-04T05:44:05.538050Z",
"url": "https://files.pythonhosted.org/packages/79/45/20a3f586541ca6ad751827f024ea988549c2b307f5284d637e6c99874c91/ddr_davis_data-0.1.25.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-05-04 05:44:05",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "ddrathod121294",
"github_project": "ddr_davis_data",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "ddr-davis-data"
}