``````

In [1]:

# !/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on 20191125

@author: zhangji

test the linear relationship
U_t =?= U_sh + U_wm
U_t is the total velocity
U_sh is the velocity induced by shear flow
U_wm is the active velocity.
"""

# %pylab inline
# pylab.rcParams['figure.figsize'] = (25, 11)
# fontsize = 40

# import numpy as np
# import scipy as sp
# from scipy.optimize import leastsq, curve_fit
# from scipy import interpolate
# from scipy.interpolate import interp1d
# from scipy.io import loadmat, savemat
# # import scipy.misc

# import matplotlib
# from matplotlib import pyplot as plt
# from matplotlib import animation, rc
# import matplotlib.ticker as mtick
# from mpl_toolkits.axes_grid1.inset_locator import inset_axes, zoomed_inset_axes
# from mpl_toolkits.mplot3d import Axes3D, axes3d

# from sympy import symbols, simplify, series, exp
# from sympy.matrices import Matrix
# from sympy.solvers import solve

# from IPython.display import display, HTML
# from tqdm import tqdm_notebook as tqdm
# import pandas as pd
# import re
# from scanf import scanf
# import os
# import glob

# from codeStore import support_fun as spf
# from src.support_class import *
# from src import stokes_flow as sf

# rc('animation', html='html5')
# PWD = os.getcwd()
# font = {'size': 20}
# matplotlib.rc('font', **font)
# np.set_printoptions(linewidth=90, precision=5)

import os
import glob
import re
import pandas as pd
from scanf import scanf
import natsort
import numpy as np
import scipy as sp
from scipy.optimize import leastsq, curve_fit
from scipy import interpolate
from scipy import spatial
# from scipy.interpolate import interp1d
# import scipy.misc
import importlib
from IPython.display import display, HTML
import pickle

import matplotlib
from matplotlib import pyplot as plt
from matplotlib import colors as mcolors
from matplotlib import animation, rc
import matplotlib.ticker as mtick
from mpl_toolkits.axes_grid1.inset_locator import inset_axes, zoomed_inset_axes
from mpl_toolkits.mplot3d import Axes3D, axes3d
from matplotlib import ticker, cm
from mpl_toolkits.axes_grid1 import make_axes_locatable

from time import time
from src import support_class as spc
from src import jeffery_model as jm
from codeStore import support_fun as spf
from codeStore import support_fun_table as spf_tb

# %matplotlib notebook

%matplotlib inline
rc('animation', html='html5')
rc('text', usetex=True)
params = {'text.latex.preamble': [r'\usepackage{bm}', r'\usepackage{amsmath}']}
plt.rcParams.update(params)
fontsize = 40
figsize = (30, 16)
PWD = os.getcwd()

``````
``````

In [2]:

fig = plt.figure(figsize=(2, 2))
fig.patch.set_facecolor('white')

``````
``````

``````
``````

In [3]:

fft_pickle = 'hlxC01_tau1a'

``````
``````

In [4]:

with open('%s.pickle' % fft_pickle, 'rb') as handle:
tw = pickle_data[0][1][4][2].values
tw_fft = np.fft.fft2(tw)
tw_fft[0, 0]

``````
``````

Out[4]:

(1433.4416879076475+0j)

``````
``````

In [202]:

# do 2D IFFT myself and compare with numpy version
use_idx_max = 1

# ((psi, ((theta, phi, ui))))
with open('%s.pickle' % fft_pickle, 'rb') as handle:
ttheta, tphi = pickle_data[0][1][0][:2]
tpsi = np.array([ti[0] for ti in pickle_data])
tw = pickle_data[0][1][5][2].values

tw_fft = np.fft.fft2(tw)
th_freq = np.fft.fftfreq(ttheta.size, 1 / ttheta.size)
ph_freq = np.fft.fftfreq(tphi.size, 1 / tphi.size)
idx_max = np.dstack(np.unravel_index(np.argsort(np.abs(tw_fft).ravel()), tw_fft.shape))[0][::-1]

# numpy version IFFT
idx = np.zeros_like(tw_fft, dtype=bool)
for ti in idx_max[:use_idx_max]:
idx[ti[0], ti[1]] = 1
tw_fft2 = tw_fft * idx
tw2 = np.fft.ifft2(tw_fft2)

# do IFFT myself
tw3 = np.zeros_like(tw2)
tM, tN = tw_fft.shape
tm, tn = np.meshgrid(np.arange(tM), np.arange(tN), indexing='ij')
for tk, tl in idx_max[:use_idx_max]:
tAkl = tw_fft[tk, tl]
tw3 = tw3 + tAkl * np.exp(2 * np.pi * 1j * tm * tk / tM) / tM * \
np.exp(2 * np.pi * 1j * tn * tl / tN) / tN
print(tk, tl, tAkl)
print((np.abs(tw3.imag) / np.abs(tw3)).max())
print((tw3 - tw).max(), np.abs(tw3 - tw2).max())

``````
``````

0 1 (41.43437201119278+4.997383689261055j)
0.999989251311336
(0.08760196833067893+0.01216229602232495j) 3.0555271774230604e-17

``````
``````

In [6]:

# print values of primary frequence
print_idx_max = 20

# ((psi, ((theta, phi, ui))))
with open('%s.pickle' % fft_pickle, 'rb') as handle:
ttheta, tphi = pickle_data[0][1][0][:2]
tpsi = np.array([ti[0] for ti in pickle_data])
tw = pickle_data[0][1][3][2].values

tw_fft = np.fft.fft2(tw)
idx_max = np.dstack(np.unravel_index(np.argsort(np.abs(tw_fft).ravel()), tw_fft.shape))[0][::-1]
for i0, (tk, tl) in enumerate(idx_max[:print_idx_max]):
if not np.mod(i0, 2):
print('*', tk, tl, tw_fft[tk, tl])
else:
print(' ', tk, tl, tw_fft[tk, tl])

``````
``````

* 0 2 (3.4325658413780578-202.97501905454095j)
0 61 (3.4325658413780578+202.97501905454095j)
* 31 2 (7.957450693382612+100.50878266096345j)
1 61 (7.957450693382612-100.50878266096345j)
* 31 61 (-7.761270122781182-57.207434958553726j)
1 2 (-7.761270122781182+57.207434958553726j)
* 31 0 (3.0385152986246124+21.13258990018759j)
1 0 (3.0385152986246124-21.132589900187586j)
* 0 3 (-0.767417881391293+8.099140242165005j)
0 60 (-0.767417881391293-8.099140242165005j)
* 30 0 (-0.8079932045273466-6.925239150784718j)
2 0 (-0.8079932045273467+6.9252391507847175j)
* 0 4 (-0.6980948006319172+4.418253334465155j)
0 59 (-0.6980948006319172-4.418253334465155j)
* 0 1 (-0.48832050837783036-4.227743685383918j)
0 62 (-0.48832050837783036+4.227743685383918j)
* 0 0 (-3.7971307644025134+0j)
1 60 (-0.053966934112297825+3.753842780090676j)
* 31 3 (-0.053966934112297825-3.753842780090676j)
0 58 (-0.6844678593550718-3.10688138307184j)

``````
``````

In [7]:

print(tw.shape, tw_fft.shape, ttheta.shape, tphi.shape)

``````
``````

(32, 63) (32, 63) (32,) (63,)

``````
``````

In [8]:

# 2D fft of Wx, Wy, Wz
use_uidx = 3 # 3: wx, 4: wy, 5: wz
tktl_list = [[0, 2], [31, 2], [1, 2]]

# ((psi, ((theta, phi, ui))))
with open('%s.pickle' % fft_pickle, 'rb') as handle:
ttheta, tphi = pickle_data[0][1][0][:2]
tpsi = np.array([ti[0] for ti in pickle_data])
tw = pickle_data[0][1][use_uidx][2].values

for tktl in tktl_list:
if np.sum(tktl) < 1:
spf_tb.show_fft_major(tw, (tktl, ), ttheta, tphi)
else:
spf_tb.show_fft_fit(tw, tktl, ttheta, tphi)

spf_tb.show_fft_major(tw, tktl_list, ttheta, tphi)

``````
``````

use frequence pairs 3.432566-202.975019i and 3.432566+202.975019i at (0, 2) and (0, 61)
absolute abs of imag part is 4.249818523937006e-17
use frequence pairs 7.957451+100.508783i and 7.957451-100.508783i at (31, 2) and (1, 61)
absolute abs of imag part is 2.449359953878663e-17
use frequence pairs -7.761270+57.207435i and -7.761270-57.207435i at (1, 2) and (31, 61)
absolute abs of imag part is 1.3785497857514637e-17
use frequence pairs 3.432566-202.975019i and 3.432566+202.975019i at (0, 2) and (0, 61)
use frequence pairs 7.957451+100.508783i and 7.957451-100.508783i at (31, 2) and (1, 61)
use frequence pairs -7.761270+57.207435i and -7.761270-57.207435i at (1, 2) and (31, 61)
absolute abs of imag part is 7.623384997357543e-17

Out[8]:

True

``````