In [1]:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import h5py
from importlib import reload
import sep
In [2]:
f = h5py.File('/Users/Owen/Dropbox/Data/ABL/SBL PIV data/RNV45-RI2.mat')
#list(f.keys())
Swirl = np.asarray(f['Swirl'])
X = np.asarray(f['X'])
Y = np.asarray(f['Y'])
X = np.transpose(X,(1,0))
Y = np.transpose(Y,(1,0))
Swirl = np.transpose(Swirl,(2,1,0))
NanLocs = np.isnan(Swirl)
uSize = Swirl.shape
In [3]:
plt.figure(figsize = [8,3])
plt.pcolor(X,Y,Swirl[:,:,1], cmap='RdBu');
plt.clim([-50, 50])
plt.axis('scaled')
plt.xlim([X.min(), X.max()])
plt.ylim([Y.min(), Y.max()])
plt.colorbar()
Out[3]:
In [4]:
#Find profile of swirl std
SwirlStd = np.std(np.nanmean(Swirl,axis=2),axis = 1)
plt.plot(SwirlStd,Y[:,1])
plt.ylabel('y(m)')
plt.xlabel('Swirl rms')
Out[4]:
In [5]:
Y[1].shape
Out[5]:
In [6]:
SwirlStd.shape
Out[6]:
In [4]:
#Normalize field by the std of Swirl
Swirl = Swirl/SwirlStd.reshape(uSize[0],1,1) #match the SwirlStd length (123) with the correct index in Swirl (also 123)
In [5]:
plt.figure(figsize = [8,3])
plt.pcolor(X,Y,Swirl[:,:,1], cmap='RdBu');
plt.clim([-200, 200])
plt.axis('scaled')
plt.xlim([X.min(), X.max()])
plt.ylim([Y.min(), Y.max()])
plt.colorbar()
Out[5]:
In [6]:
Swirl[NanLocs] = 0 #Get rid of nans for now
In [7]:
bkg = sep.Background(np.ascontiguousarray(Swirl[:,:,1]))
bkg_image = bkg.back()
plt.imshow(bkg_image, interpolation='nearest', cmap='gray', origin='lower')
plt.colorbar();
In [8]:
bkg_rms = bkg.rms()
plt.imshow(bkg_rms, interpolation='nearest', cmap='gray', origin='lower')
plt.colorbar();
In [ ]:
#creat filter kernal
kern = np.array([[1,2,1], [2,4,2], [1,2,1]]) #Basic default kernal
kern = np.array([[1,2,4,2,1],[2,3,5,3,2],[3,6,8,6,3],[2,3,5,3,2],[1,2,4,2,1]]) #Basic default kernal
from scipy.stats import multivariate_normal as mvnorm
x = np.linspace(-5, 5, 100)
y = mvnorm.pdf(x, mean=0, cov=1)
#plt.plot(x,y)
#mvnorm.pdf(
x = np.mgrid[-1:1:.01]
y = x;
r = (x**2+y**2)**0.5
kern = np.empty(x.shape)
#for i in kern.shape[0]
# kern[i,:] = mvnorm.pdf(r[i,:], mean=0, cov=1)
#plt.imshow(kern)
#y = mvnorm.pdf(x, mean=0, cov=1)
#pos = np.empty(x.shape + (2,))l
#pos[:, :, 0] = x; pos[:, :, 1] = y
In [74]:
x = np.mgrid[-10:10:1]
x.shape
Out[74]:
In [14]:
objects = sep.extract(np.ascontiguousarray(Swirl[:,:,1]), 1.5, err=bkg.globalrms,filter_kernel=kern)
np.ascontiguousarray(Swirl[:,:,1]).flags how to make array C contiguous
In [52]:
len(objects)
Out[52]:
In [15]:
from matplotlib.patches import Ellipse
#fig, ax = plt.subplots()
plt.figure(figsize = [8,3])
plt.pcolor(X,Y,Swirl[:,:,1], cmap='RdBu_r');
ax = plt.gca()
plt.clim([-50, 50])
plt.axis('scaled')
plt.xlim([X.min(), X.max()])
plt.ylim([Y.min(), Y.max()])
plt.colorbar()
scale = (X[1,-1]-X[1,1])/uSize[1]
#plt.plot(objects['x']*scale,objects['y']*scale,'go')
for i in range(len(objects)):
e = Ellipse(xy=(objects['x'][i]*scale, objects['y'][i]*scale),
width=6*objects['a'][i]*scale,
height=6*objects['b'][i]*scale,
angle=objects['theta'][i] * 180. / np.pi)
e.set_facecolor('none')
e.set_edgecolor('red')
ax.add_artist(e)
In [13]:
#objects['x']
scale = (X[1,-1]-X[1,1])/uSize[1]
objects['x']*scale
Out[13]:
In [14]:
X[objects['x'],objects['y']]
In [ ]:
objects['x']
In [ ]: