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)

%load_ext autoreload
%autoreload 2

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, spatial, sparse
# from scipy.interpolate import interp1d
from scipy.io import loadmat, savemat
# 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')
ax0 = fig.add_subplot(1, 1, 1)



In [3]:
fft_pickle = 'ecoC01B05_tao1_wm0'

In [4]:
# do 2D IFFT myself and compare with numpy version
use_idx_max = 6

# ((psi, ((theta, phi, ui))))
with open('%s.pickle' % fft_pickle, 'rb') as handle:
    pickle_data = pickle.load(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)
th_freq = np.fft.fftfreq(ttheta.size, 1 / ttheta.size)
ph_freq = np.fft.fftshift(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 + tn * tl / tN)) / (tM * tN)
    print(tk, tl, tAkl)
    print((np.abs(tw3.imag) / np.abs(tw3)).max())
print((tw3 - tw).max(), (tw3 - tw2).max())


0 62 (12.322282060499273+186.54993062316677j)
0.9978255781505948
0 2 (12.32228206049927-186.54993062316677j)
1.949417348305176e-14
1 62 (-1.66261112101838-118.55247821283966j)
0.9999995120750792
31 2 (-1.662611121018379+118.55247821283966j)
5.84958253626296e-12
31 62 (-6.763320599799224-65.04220447451377j)
0.999977771663306
1 2 (-6.763320599799222+65.04220447451377j)
1.7102907182389048e-12
(0.09389979205627075+9.71445146547012e-17j) (4.191091917959966e-15+4.371503159461554e-15j)

In [5]:
# print values of primary frequence
print_idx_max = 20

# ((psi, ((theta, phi, ui))))
with open('%s.pickle' % fft_pickle, 'rb') as handle:
    pickle_data = pickle.load(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)
th_freq = np.fft.fftfreq(ttheta.size, 1 / ttheta.size)
ph_freq = np.fft.fftshift(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]
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 62 (12.322282060499273+186.54993062316677j)
  0 2 (12.32228206049927-186.54993062316677j)
* 1 62 (-1.66261112101838-118.55247821283966j)
  31 2 (-1.662611121018379+118.55247821283966j)
* 31 62 (-6.763320599799224-65.04220447451377j)
  1 2 (-6.763320599799222+65.04220447451377j)
* 1 0 (5.840870488550582-43.57639647516834j)
  31 0 (5.840870488550581+43.57639647516834j)
* 2 0 (-3.3748645574344365+18.366389851436942j)
  30 0 (-3.3748645574344365-18.366389851436942j)
* 2 62 (-0.3276035898825703+9.399733729705302j)
  30 2 (-0.3276035898825703-9.3997337297053j)
* 0 61 (-0.9266704645376043-7.324557978806616j)
  0 3 (-0.9266704645376043+7.324557978806615j)
* 30 62 (-1.2815269973502885-5.050734661111762j)
  2 2 (-1.281526997350288+5.050734661111759j)
* 31 3 (0.3067896714543265-4.318452578625892j)
  1 61 (0.30678967145432673+4.318452578625891j)
* 0 0 (-4.167786366297719+0j)
  0 60 (-0.7339741398981741-4.03885578867248j)

In [6]:
# 2D fft of Wx, Wy, Wz
importlib.reload(spf_tb)
use_uidx = 3 # 3: wx, 4: wy, 5: wz
tktl_list = [[0, 62], [1, 62], [31, 62], [1, 0]]
# use_idx_list = [[0], [1, 2], [3, 4], [5, 6]]

# ((psi, ((theta, phi, ui))))
with open('%s.pickle' % fft_pickle, 'rb') as handle:
    pickle_data = pickle.load(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 12.322282+186.549931i and 12.322282-186.549931i at (0, 62) and (0, 2)
absolute abs of imag part is 8.673617379884035e-19
use frequence pairs -1.662611-118.552478i and -1.662611+118.552478i at (1, 62) and (31, 2)
absolute abs of imag part is 6.938893903907228e-18
use frequence pairs -6.763321-65.042204i and -6.763321+65.042204i at (31, 62) and (1, 2)
absolute abs of imag part is 8.673617379884035e-19
use frequence pairs 5.840870-43.576396i and 5.840870+43.576396i at (1, 0) and (31, 0)
absolute abs of imag part is 3.469446951953614e-18
/anaconda3/envs/py35/lib/python3.5/site-packages/scipy/optimize/minpack.py:808: OptimizeWarning: Covariance of the parameters could not be estimated
  category=OptimizeWarning)
use frequence pairs 12.322282+186.549931i and 12.322282-186.549931i at (0, 62) and (0, 2)
use frequence pairs -1.662611-118.552478i and -1.662611+118.552478i at (1, 62) and (31, 2)
use frequence pairs -6.763321-65.042204i and -6.763321+65.042204i at (31, 62) and (1, 2)
use frequence pairs 5.840870-43.576396i and 5.840870+43.576396i at (1, 0) and (31, 0)
absolute abs of imag part is 6.938893903907228e-18
Out[6]:
True

In [7]:
# 2D fft of Wx, Wy, Wz, investigate Amp and \alpha as function of \psi
importlib.reload(spf_tb)
use_uidx = 3 # 3: wx, 4: wy, 5: wz
tktl = [0, 62]

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

for tpsi, table_psi_data in pickle_data[:]:
    tw = table_psi_data[use_uidx][2].values
    spf_tb.show_fft_fit(tw, tktl, ttheta, tphi)


use frequence pairs 12.322282+186.549931i and 12.322282-186.549931i at (0, 62) and (0, 2)
absolute abs of imag part is 8.673617379884035e-19
use frequence pairs 7.224083+139.006877i and 7.224083-139.006877i at (0, 62) and (0, 2)
absolute abs of imag part is 3.469446951953614e-18
/anaconda3/envs/py35/lib/python3.5/site-packages/scipy/optimize/minpack.py:808: OptimizeWarning: Covariance of the parameters could not be estimated
  category=OptimizeWarning)
use frequence pairs 2.211306+77.184098i and 2.211306-77.184098i at (0, 62) and (0, 2)
absolute abs of imag part is 3.469446951953614e-18
use frequence pairs 0.168046+42.034554i and 0.168046-42.034554i at (0, 62) and (0, 2)
absolute abs of imag part is 8.673617379884035e-19
use frequence pairs 2.986588+56.769275i and 2.986588-56.769275i at (0, 62) and (0, 2)
absolute abs of imag part is 2.0687198856113594e-47
use frequence pairs 10.327617+111.494368i and 10.327617-111.494368i at (0, 62) and (0, 2)
absolute abs of imag part is 5.735151695798081e-47
use frequence pairs 18.957933+169.825834i and 18.957933-169.825834i at (0, 62) and (0, 2)
absolute abs of imag part is 6.938893903907228e-18
/anaconda3/envs/py35/lib/python3.5/site-packages/scipy/optimize/minpack.py:808: OptimizeWarning: Covariance of the parameters could not be estimated
  category=OptimizeWarning)
use frequence pairs 24.119143+193.063890i and 24.119143-193.063890i at (0, 62) and (0, 2)
absolute abs of imag part is 1.3877787807814457e-17
use frequence pairs 22.834926+165.805799i and 22.834926-165.805799i at (0, 62) and (0, 2)
absolute abs of imag part is 8.042749927373931e-47
/anaconda3/envs/py35/lib/python3.5/site-packages/scipy/optimize/minpack.py:808: OptimizeWarning: Covariance of the parameters could not be estimated
  category=OptimizeWarning)
use frequence pairs 16.485048+106.028963i and 16.485048-106.028963i at (0, 62) and (0, 2)
absolute abs of imag part is 6.938893903907228e-18
use frequence pairs 9.910474+53.221031i and 9.910474-53.221031i at (0, 62) and (0, 2)
absolute abs of imag part is 3.469446951953614e-18
use frequence pairs 7.477225+42.328066i and 7.477225-42.328066i at (0, 62) and (0, 2)
absolute abs of imag part is 1.7470526527517637e-47
use frequence pairs 9.695670+80.673651i and 9.695670-80.673651i at (0, 62) and (0, 2)
absolute abs of imag part is 6.938893903907228e-18
use frequence pairs 13.388211+143.051313i and 13.388211-143.051313i at (0, 62) and (0, 2)
absolute abs of imag part is 5.428919679139268e-47
use frequence pairs 14.777249+188.300775i and 14.777249-188.300775i at (0, 62) and (0, 2)
absolute abs of imag part is 8.212796229663827e-47

In [ ]:

Full 3D FFT version


In [384]:
fft_pickle = 'ecoC01B05_tau1_wm0_b'

In [385]:
# do 3D IFFT myself and compare with numpy version
importlib.reload(spf_tb)
use_idx_max = 6
use_uidx = 5 # 3: wx, 4: wy, 5: wz

# ((psi, ((theta, phi, ui), )))
with open('%s.pickle' % fft_pickle, 'rb') as handle:
    pickle_data = pickle.load(handle)
ttheta, tphi = pickle_data[0][1][0][:2]
tpsi = np.array([ti[0] for ti in pickle_data])
U_all = [[] for i in range(6)]
for tpsi, table_psi_data in pickle_data:
    for (ty, tx, tU), Ui in zip(table_psi_data, U_all):
        Ui.append((tpsi, ty, tx, tU))
tw = np.dstack([tU.values for _, _, _, tU in U_all[use_uidx]])

tw_fft = np.fft.fftn(tw)
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], ti[2]] = 1
tw_fft2 = tw_fft * idx
tw2 = np.fft.ifftn(tw_fft2)

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


1 1 0 (2099.122594069163-5.5981210027771e-06j)
1.0
31 63 0 (2099.122594069163+5.598120985051695e-06j)
4.061635852067786e-08
31 1 0 (-1827.2186834657691-3.5884381293276077e-06j)
1.0
1 63 0 (-1827.2186834657691+3.5884381755510495e-06j)
3.761438873663267e-14
1 63 2 (560.2854005256127+191.41794598717235j)
0.9999958331702751
31 1 14 (560.2854005256124-191.41794598717235j)
1.2748898129791376e-12
8.892132003382287e-15

In [386]:
# print values of primary frequence
importlib.reload(spf_tb)
print_idx_max = 100
use_uidx = 5 # 3: wx, 4: wy, 5: wz

# ((psi, ((theta, phi, ui), )))
with open('%s.pickle' % fft_pickle, 'rb') as handle:
    pickle_data = pickle.load(handle)
ttheta, tphi = pickle_data[0][1][0][:2]
tpsi = np.array([ti[0] for ti in pickle_data])
U_all = [[] for i in range(6)]
for tpsi, table_psi_data in pickle_data:
    for (ty, tx, tU), Ui in zip(table_psi_data, U_all):
        Ui.append((tpsi, ty, tx, tU))
tw = np.dstack([tU.values for _, _, _, tU in U_all[use_uidx]])

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


    0 * [1, 1, 0]  (2099.122594069163-5.5981210027771e-06j) 2099.122594069163
        [31, 63, 0]  (2099.122594069163+5.598120985051695e-06j) 2099.122594069163
    2 * [31, 1, 0]  (-1827.2186834657691-3.5884381293276077e-06j) 1827.2186834657691
        [1, 63, 0]  (-1827.2186834657691+3.5884381755510495e-06j) 1827.2186834657691
    4 * [1, 63, 2]  (560.2854005256127+191.41794598717235j) 592.0815485117689
        [31, 1, 14]  (560.2854005256124-191.41794598717235j) 592.0815485117688
    6 * [31, 1, 2]  (560.2853940215208+191.41792073134854j) 592.0815341918405
        [1, 63, 14]  (560.2853940215208-191.41792073134854j) 592.0815341918405
    8 * [31, 63, 2]  (-496.4064319219047-321.2736806311276j) 591.300366581747
        [1, 1, 14]  (-496.4064319219047+321.2736806311275j) 591.300366581747
   10 * [1, 1, 2]  (-496.40643828187825-321.27367065113106j) 591.3003664985772
        [31, 63, 14]  (-496.40643828187825+321.273670651131j) 591.3003664985771
   12 * [0, 63, 14]  (235.2128439364814+486.3127504338104j) 540.2084534577232
        [0, 1, 2]  (235.2128439364814-486.3127504338104j) 540.2084534577232
   14 * [0, 63, 2]  (235.2128422040162-486.31273548670134j) 540.2084392475276
        [0, 1, 14]  (235.2128422040162+486.3127354867013j) 540.2084392475276
   16 * [0, 63, 0]  (518.7366380862838+4.1392973060100844e-06j) 518.7366380862838
        [0, 1, 0]  (518.7366380862838-4.139297284731966e-06j) 518.7366380862838
   18 * [30, 63, 0]  (-213.45250720383183+5.6899100784152866e-06j) 213.4525072038319
        [2, 1, 0]  (-213.45250720383183-5.689910053584455e-06j) 213.4525072038319
   20 * [30, 1, 0]  (-213.32024088220518+5.69643947721086e-06j) 213.32024088220527
        [2, 63, 0]  (-213.32024088220518-5.6964394665908826e-06j) 213.32024088220527
   22 * [30, 63, 14]  (-79.60775091498382-164.03928821590327j) 182.33563031980964
        [2, 1, 2]  (-79.60775091498381+164.03928821590324j) 182.3356303198096
   24 * [30, 63, 2]  (-79.60774819917563+164.039287976756j) 182.33562891893737
        [2, 1, 14]  (-79.60774819917563-164.039287976756j) 182.33562891893737
   26 * [30, 1, 14]  (-79.66004737478485-164.01079684261276j) 182.33284023648005
        [2, 63, 2]  (-79.66004737478485+164.01079684261276j) 182.33284023648005
   28 * [30, 1, 2]  (-79.66004468335899+164.0107966061807j) 182.33283884793963
        [2, 63, 14]  (-79.66004468335899-164.0107966061807j) 182.33283884793963
   30 * [31, 1, 1]  (74.42924217841504+43.68776060636678j) 86.30372250402858
        [1, 63, 15]  (74.42924217841504-43.68776060636678j) 86.30372250402858
   32 * [1, 63, 1]  (-67.91556474305793-42.49992905805999j) 80.11721353310176
        [31, 1, 15]  (-67.91556474305793+42.49992905805999j) 80.11721353310176
   34 * [3, 1, 0]  (-60.900202019993046-2.563162344611379e-06j) 60.9002020199931
        [29, 63, 0]  (-60.900202019993046+2.5631623069019602e-06j) 60.9002020199931
   36 * [29, 1, 0]  (-60.279694733454704+2.5635502613847963e-06j) 60.27969473345476
        [3, 63, 0]  (-60.27969473345468-2.563550226707674e-06j) 60.27969473345473
   38 * [3, 1, 2]  (-23.1941909416598+47.570355969322975j) 52.92361722790946
        [29, 63, 14]  (-23.194190941659784-47.57035596932297j) 52.92361722790945
   40 * [29, 63, 2]  (-23.194189758939647+47.57035450856249j) 52.92361539656954
        [3, 1, 14]  (-23.194189758939608-47.57035450856249j) 52.923615396569524
   42 * [29, 1, 14]  (-23.03859609382104-47.64179246523632j) 52.91991401424302
        [3, 63, 2]  (-23.03859609382102+47.641792465236335j) 52.91991401424302
   44 * [29, 1, 2]  (-23.03859491209289+47.64179099428658j) 52.91991217553935
        [3, 63, 14]  (-23.03859491209289-47.64179099428656j) 52.91991217553934
   46 * [1, 1, 15]  (2.9357881145470515-40.601910020688706j) 40.70791015492711
        [31, 63, 1]  (2.9357881145470555+40.601910020688706j) 40.70791015492711
   48 * [31, 63, 15]  (3.5773811336904995+39.41416166953044j) 39.57617712573522
        [1, 1, 1]  (3.5773811336904977-39.41416166953044j) 39.57617712573522
   50 * [0, 1, 1]  (35.941047802989814+16.451047272510593j) 39.52715362303713
        [0, 63, 15]  (35.94104780298981-16.45104727251059j) 39.52715362303712
   52 * [0, 1, 15]  (-29.427786656164514+15.263470694196513j) 33.15068875775178
        [0, 63, 1]  (-29.42778665616451-15.263470694196512j) 33.15068875775177
   54 * [4, 1, 0]  (-31.265159989294272-1.7234245366580999e-06j) 31.265159989294318
        [28, 63, 0]  (-31.26515998929424+1.7234245463898986e-06j) 31.26515998929429
   56 * [4, 63, 0]  (-31.17276321287066-1.7231266704780894e-06j) 31.17276321287071
        [28, 1, 0]  (-31.17276321287065+1.7231266411300376e-06j) 31.1727632128707
   58 * [4, 1, 2]  (-12.012682068406797+24.697770672847525j) 27.464238687522172
        [28, 63, 14]  (-12.012682068406784-24.697770672847522j) 27.464238687522162
   60 * [28, 63, 2]  (-12.012681285901238+24.697769444187028j) 27.464237240361513
        [4, 1, 14]  (-12.012681285901236-24.69776944418701j) 27.4642372403615
   62 * [4, 63, 2]  (-11.965059435439185+24.718494510085282j) 27.46209420526243
        [28, 1, 14]  (-11.965059435439182-24.71849451008527j) 27.46209420526242
   64 * [28, 1, 2]  (-11.965058648589117+24.71849328076697j) 27.46209275593357
        [4, 63, 14]  (-11.965058648589125-24.71849328076696j) 27.462092755933565
   66 * [2, 1, 1]  (18.84441259798899-17.62867893358588j) 25.804693509257202
        [30, 63, 15]  (18.84441259798899+17.62867893358588j) 25.804693509257202
   68 * [30, 1, 15]  (18.84018213321378+17.625561365611286j) 25.79947434087751
        [2, 63, 1]  (18.84018213321378-17.625561365611283j) 25.799474340877506
   70 * [2, 1, 15]  (-12.330901369629597-18.816584985729875j) 22.496999780253542
        [30, 63, 1]  (-12.330901369629595+18.81658498572987j) 22.49699978025354
   72 * [2, 63, 15]  (-12.326670947553664-18.81346739501426j) 22.492073538749782
        [30, 1, 1]  (-12.326670947553664+18.813467395014257j) 22.492073538749782
   74 * [5, 1, 0]  (-19.691743601088767-1.289165353597775e-06j) 19.69174360108881
        [27, 63, 0]  (-19.691743601088753+1.289165362517723e-06j) 19.691743601088795
   76 * [5, 63, 0]  (-19.57869294468451-1.284909476983172e-06j) 19.57869294468455
        [27, 1, 0]  (-19.578692944684477+1.284909453928697e-06j) 19.57869294468452
   78 * [27, 63, 14]  (-7.578276894057462-15.583789267283974j) 17.32872668750132
        [5, 1, 2]  (-7.578276894057446+15.58378926728398j) 17.328726687501316
   80 * [5, 1, 14]  (-7.5782763134888445-15.58378827285965j) 17.32872553931489
        [27, 63, 2]  (-7.5782763134888+15.583788272859643j) 17.32872553931486
   82 * [5, 63, 2]  (-7.553979109114113+15.588800103210648j) 17.322623618805345
        [27, 1, 14]  (-7.553979109114076-15.588800103210616j) 17.3226236188053
   84 * [5, 63, 14]  (-7.553978519785645-15.588799105274589j) 17.322622463760872
        [27, 1, 2]  (-7.553978519785668+15.588799105274553j) 17.322622463760847
   86 * [6, 1, 0]  (-13.827316644530093-1.0134259043269785e-06j) 13.82731664453013
        [26, 63, 0]  (-13.827316644530086+1.0134258581035368e-06j) 13.827316644530123
   88 * [6, 63, 0]  (-13.799984985273039-1.011363608655566e-06j) 13.799984985273076
        [26, 1, 0]  (-13.79998498527302+1.0113636157228293e-06j) 13.799984985273058
   90 * [29, 1, 15]  (7.322793065584608+10.590853427084307j) 12.875926164566083
        [3, 63, 1]  (7.322793065584607-10.590853427084305j) 12.87592616456608
   92 * [3, 1, 1]  (7.347095181811403-10.557689656280372j) 12.862527686614552
        [29, 63, 15]  (7.3470951818114+10.55768965628037j) 12.862527686614548
   94 * [26, 63, 14]  (-5.33603233018011-10.983100275892223j) 12.210722038398515
        [6, 1, 2]  (-5.3360323301800925+10.983100275892223j) 12.210722038398508
   96 * [26, 63, 2]  (-5.336031874338854+10.983099463873788j) 12.21072110881683
        [6, 1, 14]  (-5.336031874338847-10.983099463873788j) 12.210721108816827
   98 * [26, 1, 14]  (-5.322715852401689-10.986072025303912j) 12.20758299544072
        [6, 63, 2]  (-5.322715852401689+10.986072025303894j) 12.207582995440704

In [388]:
tktltj_list3 = ([0, 0, 0], [1, 1, 0], [31, 1, 0], [1, 63, 2], [31, 1, 2], [31, 63, 2], [1, 1, 2], [0, 63, 14], 
                [0, 63, 2], [0, 63, 0], [30, 63, 0], [30, 1, 0], [30, 63, 14])

t1 = [np.abs(tw_fft[tk, tl, tj]) for tk, tl, tj in idx_max]
plt.plot(t1, '.')
plt.xlim(-1, 50)
# plt.ylim(10, 100)


Out[388]:
(-1, 50)

In [390]:
importlib.reload(spf_tb)
use_uidx = 4 # 3: wx, 4: wy, 5: wz
tktltj_list1 = ([0, 0, 0], [0, 62, 0], [1, 62, 0], [31, 62, 0], [0, 62, 14], [0, 2, 14], [1, 0, 0], [31, 0, 2], 
                [31, 0, 14], [31, 62, 2], [31, 2, 14], [1, 2, 2], [31, 2, 2])
tktltj_list2 = ([0, 0, 0], [31, 0, 0], [0, 62, 0], [0, 0, 2], [1, 62, 0], [31, 62, 0], [0, 62, 14], [1, 0, 2], 
                [31, 0, 2], [0, 2, 14], [31, 62, 2], [31, 2, 14], [1, 2, 2])
tktltj_list3 = ([0, 0, 0], [1, 1, 0], [31, 1, 0], [1, 63, 2], [31, 1, 2], [31, 63, 2], [1, 1, 2], [0, 63, 14], 
                [0, 63, 2], [0, 63, 0], [30, 63, 0], [30, 1, 0], [30, 63, 14])
tktltj_list = [tktltj_list1, tktltj_list2, tktltj_list3][use_uidx - 3]
# tktltj_list = ([0, 62, 0], [1, 62, 0] )
# ((psi, ((theta, phi, ui), )))
with open('%s.pickle' % fft_pickle, 'rb') as handle:
    pickle_data = pickle.load(handle)
ttheta_all, tphi_all = pickle_data[0][1][0][:2]
tpsi_all = np.array([ti[0] for ti in pickle_data])
U_all = [[] for i in range(6)]
for _, table_psi_data in pickle_data:
    for (_, _, tU), Ui in zip(table_psi_data, U_all):
        Ui.append(tU)
tw = np.dstack(U_all[use_uidx])

# tw_fft, tw2, tw_fft2 = spf_tb.do_3dfft_major_conj(tw, tktltj_list)
tw_fft, tw2, tw_fft2 = spf_tb.do_3dfft_major(tw, tktltj_list)
# spf_tb.show_ui_psi(tw, ttheta_all, tphi_all, tpsi_all)
spf_tb.show_ui_psi(tw2, ttheta_all, tphi_all, tpsi_all)


use frequence 20306.988153+0.000000i at (0, 0, 0)
use frequence pairs 5887.066707+0.000027i and 5887.066707-0.000027i at (31, 0, 0) and (1, 0, 0)
use frequence pairs -1962.094861-0.000002i and -1962.094861+0.000002i at (0, 62, 0) and (0, 2, 0)
use frequence pairs 1149.590231+556.092067i and 1149.590231-556.092067i at (0, 0, 2) and (0, 0, 14)
use frequence pairs 1213.985127-0.000005i and 1213.985127+0.000005i at (1, 62, 0) and (31, 2, 0)
use frequence pairs 748.070025+0.000013i and 748.070025-0.000013i at (31, 62, 0) and (1, 2, 0)
use frequence pairs -577.867348+279.478401i and -577.867348-279.478401i at (0, 62, 14) and (0, 2, 2)
use frequence pairs -574.878888-278.084729i and -574.878888+278.084729i at (1, 0, 2) and (31, 0, 14)
use frequence pairs -574.878872-278.084716i and -574.878872+278.084716i at (31, 0, 2) and (1, 0, 14)
use frequence pairs -572.070998+276.770415i and -572.070998-276.770415i at (0, 2, 14) and (0, 62, 2)
use frequence pairs 142.418279+329.463790i and 142.418279-329.463790i at (31, 62, 2) and (1, 2, 14)
use frequence pairs 345.624603+91.957402i and 345.624603-91.957402i at (31, 2, 14) and (1, 62, 2)
use frequence pairs 136.621922+326.755822i and 136.621922-326.755822i at (1, 2, 2) and (31, 62, 14)
absolute abs of imag part is 8.326672684688674e-17
Out[390]:
True

In [393]:
tw2[0, 0, 0]


Out[393]:
0.946965332289727

In [313]:
# export frequence dates to mathematica
importlib.reload(spf_tb)

# ((psi, ((theta, phi, ui), )))
with open('%s.pickle' % fft_pickle, 'rb') as handle:
    pickle_data = pickle.load(handle)
ttheta_all, tphi_all = pickle_data[0][1][0][:2]
tpsi_all = np.array([ti[0] for ti in pickle_data])
U_all = [[] for i in range(6)]
for _, table_psi_data in pickle_data:
    for (_, _, tU), Ui in zip(table_psi_data, U_all):
        Ui.append(tU)

for i0 in (3, 4, 5):
    tw = np.dstack(U_all[i0])
    tw_fft = np.fft.fftn(tw)
    tname = '%s_w%d_fft.mat' % (fft_pickle, i0 - 2)
    savemat(tname, {'tw_fft': np.moveaxis(tw_fft[:, :, :], 0, -1)})
    print()
    print('save fft data of %dth component to %s. ' % (i0, tname))
    
#     print(tw_fft[0, 0, 0])
    tw_fft[0, 0, 0] = 0
    idx_max = np.dstack(np.unravel_index(np.argsort(np.abs(tw_fft).ravel()), tw_fft.shape))[0][::-1]
    use_idx_list1 = idx_max[0::2]
    use_idx_list2 = idx_max[1::2]
    t1 = np.hstack([tw_fft[tk, tl, tj] for tk, tl, tj in use_idx_list1])
    t2 = np.hstack([tw_fft[tk, tl, tj] for tk, tl, tj in use_idx_list2])
    tidx = np.argwhere(np.logical_not(np.isclose(t1, np.conj(t2))))
    tname = '%s_w%d_fft_idx.mat' % (fft_pickle, i0 - 2)
    savemat(tname, {'use_idx_list': use_idx_list1})
    print('save major index of fft data of %dth component to %s, unmatched case: ' % (i0, tname))
    for i0 in tidx[:1]:
        print('%5d: %3d, %3d, %3d, %15.5e, %15.5e' % (i0, use_idx_list1[i0, 0], use_idx_list1[i0, 1], use_idx_list1[i0, 2], 
                                                      np.real(t1[i0]), np.imag(t1[i0])))
        print('       %3d, %3d, %3d, %15.5e, %15.5e' % (use_idx_list2[i0, 0], use_idx_list2[i0, 1], use_idx_list2[i0, 2], 
                                         np.real(t2[i0]), np.imag(t2[i0])))


save fft data of 3th component to ecoC01B05_tau1_wm0_b_w1_fft.mat. 
save major index of fft data of 3th component to ecoC01B05_tau1_wm0_b_w1_fft_idx.mat, unmatched case: 
   55:  16,   0,   0,    -6.11482e+00,     0.00000e+00
         0,  62,  13,    -5.54428e+00,    -8.52658e-01

save fft data of 4th component to ecoC01B05_tau1_wm0_b_w2_fft.mat. 
save major index of fft data of 4th component to ecoC01B05_tau1_wm0_b_w2_fft_idx.mat, unmatched case: 
  413:   0,   0,   8,     5.86906e-03,     0.00000e+00
         1,   6,   6,    -2.25110e-03,     5.35876e-03

save fft data of 5th component to ecoC01B05_tau1_wm0_b_w3_fft.mat. 
save major index of fft data of 5th component to ecoC01B05_tau1_wm0_b_w3_fft_idx.mat, unmatched case: 

In [ ]:
# chech the conjunction pairs of FFT of rotation velocity. 
idx_max = np.dstack(np.unravel_index(np.argsort(np.abs(tw_fft).ravel()), tw_fft.shape))[0][::-1]
use_idx_list1 = idx_max[0::2]
use_idx_list2 = idx_max[1::2]
t1 = np.hstack([tw_fft[tk, tl, tj] for tk, tl, tj in use_idx_list1])
t2 = np.hstack([tw_fft[tk, tl, tj] for tk, tl, tj in use_idx_list2])
tidx = np.argwhere(np.logical_not(np.isclose(t1, np.conj(t2))))
for i0 in range(10):
    tk1, tl1, tj1 = use_idx_list1[i0]
    tk2 = tM - tk1 if tk1 > 0 else tk1
    tl2 = tN - tl1 if tl1 > 0 else tl1
    tj2 = tO - tj1 if tj1 > 0 else tj1
    print('%5d: %3d, %3d, %3d, %15.5e, %15.5e' % (i0, tk1, tl1, tj1, 
                                                  np.real(t1[i0]), np.imag(t1[i0])))
    print('       %3d, %3d, %3d, %15.5e, %15.5e' % (tk2, tl2, tj2, 
                                                    np.real(t1[i0]), np.imag(t1[i0])))
    print('       %3d, %3d, %3d, %15.5e, %15.5e' % (use_idx_list2[i0, 0], use_idx_list2[i0, 1], use_idx_list2[i0, 2], 
                                                    np.real(t2[i0]), np.imag(t2[i0])))

In [405]:
from sympy.parsing import mathematica
import sympy
from sympy.printing.latex import LatexPrinter, print_latex
from sympy.utilities.lambdify import lambdify, lambdastr
import inspect

def mm2py(mm_string, sym_list, modules):
    t12 = mathematica.mathematica(mm_string.replace('*^', '*10^'))
    t13 = sympy.lambdify(sym_list, t12, modules=modules)
    return t13

sym_list = (sympy.Symbol('theta'), sympy.Symbol('phi'), sympy.Symbol('psi'))
modules = ['numpy', ]
tw1_apx = '-0.0001866096570410253 + (-1.7029153048081684*^-6*Cos[62*phi] - 1960.88611819068*Sin[62*phi])/16384 + (279.32173923353105*Cos[2*phi + 2*psi] + 577.5209169432512*Sin[2*phi + 2*psi])/16384 + (-276.61411203034004*Cos[62*phi + 2*psi] - 571.7247600604117*Sin[62*phi + 2*psi])/16384 + (-6.114817144105495*Cos[2*theta] + 382.9878449974278*Sin[2*theta])/16384 + (-342.6737383563244*Cos[2*psi + 2*theta] + 166.50007489335445*Sin[2*psi + 2*theta])/16384 + (-326.49299534579876*Cos[2*phi + 2*psi + 2*theta] - 136.54707368952933*Sin[2*phi + 2*psi + 2*theta])/16384 + (-4.588689623494809*^-6*Cos[2*phi + 62*theta] - 1213.5905914763723*Sin[2*phi + 62*theta])/16384 + (0.000012727231708422586*Cos[62*phi + 62*theta] + 747.848109951239*Sin[62*phi + 62*theta])/16384 + (342.67373891716625*Cos[2*psi + 62*theta] - 166.5000738452281*Sin[2*psi + 62*theta])/16384 + (94.47535863228539*Cos[2*phi + 2*psi + 62*theta] - 339.70890817594295*Sin[2*phi + 2*psi + 62*theta])/16384 + (329.20060461853905*Cos[62*phi + 2*psi + 62*theta] + 142.34323812113675*Sin[62*phi + 2*psi + 62*theta])/16384 + (-91.76774684966742*Cos[2*phi + 14*psi + 62*theta] - 345.5050691031397*Sin[2*phi + 14*psi + 62*theta])/16384'
tw2_apx = '0.6197200974539849 + (-1962.0948612095603*Cos[62*phi] + 1.707528116724706*^-6*Sin[62*phi])/16384 + (1149.590231471158*Cos[14*psi] + 556.0920670954531*Sin[14*psi])/16384 + (-577.8673478225172*Cos[2*phi + 2*psi] + 279.47840108665457*Sin[2*phi + 2*psi])/16384 + (-572.0709983620775*Cos[62*phi + 2*psi] + 276.77041538443757*Sin[62*phi + 2*psi])/16384 + (5887.066706999647*Cos[62*theta] - 0.000026515346007727203*Sin[62*theta])/16384 + (136.62192184194265*Cos[2*phi + 2*psi + 2*theta] - 326.75582207414834*Sin[2*phi + 2*psi + 2*theta])/16384 + (-574.8788716391416*Cos[14*psi + 2*theta] - 278.08471606050534*Sin[14*psi + 2*theta])/16384 + (1213.9851268953007*Cos[2*phi + 62*theta] - 4.571595740233921*^-6*Sin[2*phi + 62*theta])/16384 + (748.0700251351213*Cos[62*phi + 62*theta] - 0.000012726440764286632*Sin[62*phi + 62*theta])/16384 + (142.4182788688823*Cos[62*phi + 2*psi + 62*theta] - 329.463789838122*Sin[62*phi + 2*psi + 62*theta])/16384 + (-574.8788879671743*Cos[14*psi + 62*theta] - 278.0847288505968*Sin[14*psi + 62*theta])/16384 + (345.6246033372179*Cos[2*phi + 14*psi + 62*theta] - 91.95740219001547*Sin[2*phi + 14*psi + 62*theta])/16384'
tw3_apx = '1.9074525687068844*^-16 + (518.7366380862838*Cos[63*phi] - 4.1392973060100844*^-6*Sin[63*phi])/16384 + (235.2128422040162*Cos[63*phi + 2*psi] + 486.31273548670134*Sin[63*phi + 2*psi])/16384 + (235.2128439364814*Cos[63*phi + 14*psi] - 486.3127504338104*Sin[63*phi + 14*psi])/16384 + (2099.122594069163*Cos[phi + 2*theta] + 5.5981210027771*^-6*Sin[phi + 2*theta])/16384 + (-496.40643828187825*Cos[phi + 2*psi + 2*theta] + 321.27367065113106*Sin[phi + 2*psi + 2*theta])/16384 + (560.2854005256127*Cos[63*phi + 2*psi + 2*theta] - 191.41794598717235*Sin[63*phi + 2*psi + 2*theta])/16384 + (-213.32024088220518*Cos[phi + 60*theta] - 5.69643947721086*^-6*Sin[phi + 60*theta])/16384 + (-213.45250720383183*Cos[63*phi + 60*theta] - 5.6899100784152866*^-6*Sin[63*phi + 60*theta])/16384 + (-79.60775091498382*Cos[63*phi + 14*psi + 60*theta] + 164.03928821590327*Sin[63*phi + 14*psi + 60*theta])/16384 + (-1827.2186834657691*Cos[phi + 62*theta] + 3.5884381293276077*^-6*Sin[phi + 62*theta])/16384 + (560.2853940215208*Cos[phi + 2*psi + 62*theta] - 191.41792073134854*Sin[phi + 2*psi + 62*theta])/16384 + (-496.4064319219047*Cos[63*phi + 2*psi + 62*theta] + 321.2736806311276*Sin[63*phi + 2*psi + 62*theta])/16384'

fun_w1_apx = lambda theta, phi, psi: mm2py(tw1_apx, sym_list, modules)(theta, phi, psi)
fun_w2_apx = lambda theta, phi, psi: mm2py(tw2_apx, sym_list, modules)(theta, phi, psi)
fun_w3_apx = lambda theta, phi, psi: mm2py(tw3_apx, sym_list, modules)(theta, phi, psi)

In [406]:
importlib.reload(spf_tb)
ttheta_all = np.linspace(0, np.pi, 33)
tphi_all = np.linspace(0, 2 * np.pi, 65)
tpsi_all = np.linspace(0, 2 * np.pi, 16, endpoint=False)

tw1 = np.dstack([fun_w1_apx(*np.meshgrid(ttheta_all, tphi_all, indexing='ij'), tpsi) for tpsi in tpsi_all])
tw2 = np.dstack([fun_w2_apx(*np.meshgrid(ttheta_all, tphi_all, indexing='ij'), tpsi) for tpsi in tpsi_all])
tw3 = np.dstack([fun_w3_apx(*np.meshgrid(ttheta_all, tphi_all, indexing='ij'), tpsi) for tpsi in tpsi_all])

In [402]:
spf_tb.show_ui_psi(tw1, ttheta_all, tphi_all, tpsi_all)


Out[402]:
True

In [403]:
spf_tb.show_ui_psi(tw2, ttheta_all, tphi_all, tpsi_all)


Out[403]:
True

In [404]:
spf_tb.show_ui_psi(tw3, ttheta_all, tphi_all, tpsi_all)


Out[404]:
True

In [419]:
sym_list = (sympy.Symbol('z'), sympy.Symbol('th0'), sympy.Symbol('ph0'), sympy.Symbol('ps0'), 
            sympy.Symbol('c01'), sympy.Symbol('c02'), sympy.Symbol('c03'))
modules = ['numpy', ]

theta_apx = 'th0 - 0.6197200974539849*c01*z*Cos[ph0] + 0.000036887909511729156*c01*z*Cos[61*ph0] + 0.11971987852173585*c01*z*Cos[63*ph0] - 0.1796590181579482*c01*z*Cos[ph0 - 62*th0] - 0.21669486384509337*c01*z*Cos[ph0 + 62*th0] + 0.03703584568714515*c01*z*Cos[3*ph0 + 62*th0] - 0.0001866096570410253*c01*z*Sin[ph0] - 1.4077184803886813*^-13*c01*z*Sin[61*ph0] - 1.0407847355752181*^-10*c01*z*Sin[63*ph0] - 8.091841433022218*^-10*c01*z*Sin[ph0 - 62*th0] + 9.492198373786016*^-10*c01*z*Sin[ph0 + 62*th0] - 1.4003569407637966*^-10*c01*z*Sin[3*ph0 + 62*th0]'
fun_theta_apx = lambda theta, phi, psi: mm2py(theta_apx, sym_list, modules)(theta, phi, psi)

In [423]:
# mm2py(theta_apx, sym_list, modules)
mm2py(theta_apx, sym_list, modules)(1, 1, 1, 1, -1, -1, -1)


Out[423]:
1.4050707199171542

In [ ]:

Obtain the third rank tensors of Risistant Matrix from the simulation results of passive microswimmer locomotion in shear flow.


In [635]:
importlib.reload(spf_tb)
use_uidx = 4 # 3: wx, 4: wy, 5: wz
with open('%s.pickle' % fft_pickle, 'rb') as handle:
    pickle_data = pickle.load(handle)
ttheta_all, tphi_all = pickle_data[0][1][0][:2]
if tphi_all[-1] < (2 * np.pi):
    tphi_all = np.hstack((tphi_all, 2 * np.pi))
if ttheta_all[-1] < (np.pi):
    ttheta_all = np.hstack((ttheta_all, np.pi))
tpsi_all = np.array([ti[0] for ti in pickle_data])
U_all = [[] for i in range(6)]
for _, table_psi_data in pickle_data:
    for (ttheta, tphi, tU), Ui in zip(table_psi_data, U_all):
        if tphi[-1] < (2 * np.pi):
            tU[2 * np.pi] = tU[0]
        if ttheta[-1] < (np.pi):
            tU = tU.append(tU.loc[0].rename(np.pi))
        Ui.append(tU)
tw = np.dstack(U_all[use_uidx])
# spf_tb.show_ui_psi(tw, ttheta_all, tphi_all, tpsi_all)

In [725]:
th2, ph2 = np.meshgrid(ttheta_all, tphi_all, indexing='ij')
p2 = np.dstack((np.sin(th2) * np.cos(ph2), np.sin(th2) * np.sin(ph2), np.cos(th2)))
p21 = np.dstack((p2[..., 1], p2[..., 2], p2[..., 0]))
th21 = np.arccos(p21[..., 2])
ph21 = np.arctan2(p21[..., 1], p21[..., 0])
ph21[ph21 < 0] = ph21[ph21 < 0] + 2 * np.pi

%matplotlib inline
figsize = np.array((16, 9)) * 0.3
dpi = 100

fig, axs = plt.subplots(1, 2, figsize=figsize, dpi=dpi)
fig.patch.set_facecolor('white')
axi = axs[0]
axi.contourf(th2, ph2, th21, 50, cmap = plt.get_cmap('jet'))
axi = axs[1]
axi.contourf(th2, ph2, ph21, 50, cmap = plt.get_cmap('jet'))
fig.tight_layout()

# fig, axs = plt.subplots(1, 2, figsize=figsize, dpi=dpi)
# fig.patch.set_facecolor('white')
# axi = axs[0]
# axi.contourf(th2, ph2, tw[..., 0], 50, cmap = plt.get_cmap('jet'))
# axi = axs[1]
# axi.contourf(th21, ph21, tw[..., 0], 50, cmap = plt.get_cmap('jet'))
# fig.tight_layout()



In [707]:
np.hstack((p_map, np.array(p_map) + 3)) % 3


Out[707]:
array([1, 0, 2, 1, 0, 2])

In [724]:
# p_map = [0, 2, 1]
# p_sign = [1, -1, 1]
# rot_psi = np.pi / 2

# p_map = [0, 1, 2]
# p_sign = [1, 1, 1]
# rot_psi = 0

# p_map = [1, 2, 0]
# p_sign = [1, 1, 1]
# rot_psi = np.pi

# p_map = [1, 0, 2]
# p_sign = [-1, 1, 1]
# rot_psi = np.pi / 2

p_map = [2, 1, 0]
p_sign = [1, -1, 1]
rot_psi = np.pi

# p_map = [2, 0, 1]
# p_sign = [1, 1, 1]
# rot_psi = np.pi / 2
figsize = np.array((16, 9)) * 0.9
dpi = 100

th2, ph2 = np.meshgrid(ttheta_all, tphi_all, indexing='ij')
p2 = np.dstack((np.sin(th2) * np.cos(ph2), np.sin(th2) * np.sin(ph2), np.cos(th2)))
p21 = np.dstack((p_sign[0] * p2[..., p_map[0]], p_sign[1] * p2[..., p_map[1]], p_sign[2] * p2[..., p_map[2]]))
th21 = np.arccos(p21[..., 2])
ph21 = np.arctan2(p21[..., 1], p21[..., 0])
ph21[ph21 < 0] = ph21[ph21 < 0] + 2 * np.pi

# fig, axs = plt.subplots(1, 2, figsize=figsize, dpi=dpi)
# fig.patch.set_facecolor('white')
# axi = axs[0]
# axi.contourf(th2, ph2, th21, 50, cmap = plt.get_cmap('jet'))
# axi = axs[1]
# axi.contourf(th2, ph2, ph21, 50, cmap = plt.get_cmap('jet'))
# fig.tight_layout()

# tpsi_all2 = (tpsi_all + rot_psi) % (2 * np.pi)
# tidx = np.argsort(tpsi_all2).astype(int)
# tpsi_all2 = tpsi_all
tidx = np.hstack((p_map, np.array(p_map) + 3))
for use_uidx in tidx: # 3: wx, 4: wy, 5: wz
    tw = p_sign[0] * p_sign[use_uidx % 3] * np.dstack(U_all[use_uidx])
    tw2 = []
    for i0 in range(tw.shape[-1]):
        intp_fun = interpolate.RectBivariateSpline(ttheta_all, tphi_all, tw[..., i0], kx=3, ky=3)
        tw2i = np.hstack([intp_fun(t1, t2) for t1, t2 in zip(th21.ravel(), ph21.ravel())]).reshape(th21.shape)
        tw2.append(tw2i)  
    tw2 = np.dstack(tw2)
    spf_tb.show_ui_psi(tw2, ttheta_all, tphi_all, tpsi_all)
#     spf_tb.show_ui_psi(tw2, ttheta_all, tphi_all, tpsi_all, polar=True)



In [ ]:

obtain gijk (hijk) from ux, uy, and uz (wx, wy, and wz)


In [1108]:
importlib.reload(spf_tb)
fft_pickle = 'ecoC01B05_tau1_wm0_b'

with open('%s.pickle' % fft_pickle, 'rb') as handle:
    pickle_data = pickle.load(handle)
ttheta_all, tphi_all = pickle_data[0][1][0][:2]
tpsi_all = np.array([ti[0] for ti in pickle_data])
U_all = [[] for i in range(6)]
for _, table_psi_data in pickle_data:
    for (ttheta, tphi, tU), Ui in zip(table_psi_data, U_all):
        Ui.append(tU)
# u_all = np.vstack([np.hstack([tU.unstack().values for tU in U_all[i0]]) for i0 in range(3)]).T
# w_all = np.vstack([np.hstack([tU.unstack().values for tU in U_all[i0 + 3]]) for i0 in range(3)]).T

# idx_all = []
# for tpsi, tU in zip(tpsi_all, U_all[0]):
#     t1 = np.vstack(tU.T.unstack().index.values)
#     idx_all.append(np.hstack((t1, tpsi * np.ones(t1.shape[0]).reshape((t1.shape[0], 1)))))
# idx_all = np.vstack(idx_all)

# # u_loc_all = np.vstack([np.dot(spf_tb.Rrot(*idx_all[i0]).T, u_all[i0]) for i0 in range(idx_all.shape[0])])
# # w_loc_all = np.vstack([np.dot(spf_tb.Rrot(*idx_all[i0]).T, w_all[i0]) for i0 in range(idx_all.shape[0])])
# wb = np.array((0, 1, 0))
# w_loc_all = np.vstack([np.dot(spf_tb.Rrot(*idx_all[i0]), (w_all[i0] - wb)) for i0 in range(idx_all.shape[0])])

In [1713]:
ttheta_all


Out[1713]:
array([0.        , 0.09817477, 0.19634954, 0.29452431, 0.39269908,
       0.49087385, 0.58904862, 0.68722339, 0.78539816, 0.88357293,
       0.9817477 , 1.07992247, 1.17809725, 1.27627202, 1.37444679,
       1.47262156, 1.57079633, 1.6689711 , 1.76714587, 1.86532064,
       1.96349541, 2.06167018, 2.15984495, 2.25801972, 2.35619449,
       2.45436926, 2.55254403, 2.6507188 , 2.74889357, 2.84706834,
       2.94524311, 3.04341788])

In [ ]:
U_all[1][0][ttheta_all]

In [1712]:
with pd.option_context('display.max_rows', None, 'display.max_columns', None, 'display.width', None):
    display(U_all[1][0])


norm_phi 0.000000 0.098175 0.196350 0.294524 0.392699 0.490874 0.589049 0.687223 0.785398 0.883573 0.981748 1.079922 1.178097 1.276272 1.374447 1.472622 1.570796 1.668971 1.767146 1.865321 1.963495 2.061670 2.159845 2.258020 2.356194 2.454369 2.552544 2.650719 2.748894 2.847068 2.945243 3.043418 3.141593 3.239767 3.337942 3.436117 3.534292 3.632467 3.730641 3.828816 3.926991 4.025166 4.123340 4.221515 4.319690 4.417865 4.516039 4.614214 4.712389 4.810564 4.908739 5.006913 5.105088 5.203263 5.301438 5.399612 5.497787 5.595962 5.694137 5.792311 5.890486 5.988661 6.086836 6.185011
norm_theta
0.000000 -0.008981 -0.008482 -0.008035 -0.007655 -0.007359 -0.007156 -0.007056 -0.007062 -0.007173 -0.007385 -0.007691 -0.008079 -0.008532 -0.009036 -0.009568 -0.010111 -0.010641 -0.011140 -0.011588 -0.011967 -0.012264 -0.012466 -0.012567 -0.012561 -0.012450 -0.012237 -0.011931 -0.011544 -0.011090 -0.010587 -0.010054 -0.009512 -0.008981 -0.008482 -0.008035 -0.007655 -0.007359 -0.007156 -0.007056 -0.007062 -0.007173 -0.007385 -0.007691 -0.008079 -0.008532 -0.009036 -0.009568 -0.010111 -0.010641 -0.011140 -0.011588 -0.011967 -0.012264 -0.012466 -0.012567 -0.012561 -0.012450 -0.012237 -0.011931 -0.011544 -0.011090 -0.010587 -0.010054 -0.009512
0.098175 -0.010469 -0.010185 -0.009913 -0.009663 -0.009447 -0.009271 -0.009143 -0.009067 -0.009046 -0.009082 -0.009173 -0.009314 -0.009502 -0.009729 -0.009985 -0.010262 -0.010548 -0.010832 -0.011104 -0.011354 -0.011570 -0.011746 -0.011875 -0.011950 -0.011971 -0.011935 -0.011844 -0.011702 -0.011515 -0.011288 -0.011032 -0.010755 -0.010469 -0.010185 -0.009913 -0.009663 -0.009447 -0.009271 -0.009143 -0.009067 -0.009046 -0.009082 -0.009173 -0.009314 -0.009502 -0.009729 -0.009985 -0.010262 -0.010548 -0.010832 -0.011104 -0.011354 -0.011570 -0.011746 -0.011875 -0.011950 -0.011971 -0.011935 -0.011844 -0.011702 -0.011515 -0.011288 -0.011032 -0.010755
0.196350 -0.011555 -0.011604 -0.011624 -0.011616 -0.011579 -0.011515 -0.011427 -0.011317 -0.011191 -0.011052 -0.010906 -0.010759 -0.010617 -0.010484 -0.010367 -0.010269 -0.010195 -0.010146 -0.010126 -0.010134 -0.010171 -0.010235 -0.010323 -0.010433 -0.010560 -0.010699 -0.010844 -0.010991 -0.011133 -0.011265 -0.011383 -0.011480 -0.011555 -0.011604 -0.011624 -0.011616 -0.011579 -0.011515 -0.011427 -0.011317 -0.011191 -0.011052 -0.010906 -0.010759 -0.010617 -0.010484 -0.010367 -0.010269 -0.010195 -0.010146 -0.010126 -0.010134 -0.010171 -0.010235 -0.010323 -0.010433 -0.010560 -0.010699 -0.010844 -0.010991 -0.011133 -0.011265 -0.011383 -0.011480
0.294524 -0.012199 -0.012674 -0.013081 -0.013403 -0.013630 -0.013752 -0.013764 -0.013666 -0.013461 -0.013158 -0.012768 -0.012306 -0.011790 -0.011239 -0.010676 -0.010121 -0.009596 -0.009121 -0.008714 -0.008391 -0.008165 -0.008044 -0.008032 -0.008131 -0.008335 -0.008639 -0.009028 -0.009490 -0.010006 -0.010556 -0.011119 -0.011674 -0.012199 -0.012674 -0.013081 -0.013403 -0.013630 -0.013752 -0.013764 -0.013666 -0.013461 -0.013158 -0.012768 -0.012306 -0.011790 -0.011239 -0.010676 -0.010121 -0.009596 -0.009121 -0.008714 -0.008391 -0.008165 -0.008044 -0.008032 -0.008131 -0.008335 -0.008639 -0.009028 -0.009490 -0.010006 -0.010556 -0.011119 -0.011674
0.392699 -0.012374 -0.013335 -0.014191 -0.014907 -0.015457 -0.015819 -0.015980 -0.015933 -0.015680 -0.015231 -0.014602 -0.013819 -0.012912 -0.011914 -0.010865 -0.009805 -0.008774 -0.007813 -0.006958 -0.006242 -0.005692 -0.005331 -0.005171 -0.005219 -0.005472 -0.005921 -0.006549 -0.007332 -0.008239 -0.009236 -0.010284 -0.011344 -0.012374 -0.013335 -0.014191 -0.014907 -0.015457 -0.015819 -0.015980 -0.015933 -0.015680 -0.015231 -0.014602 -0.013819 -0.012912 -0.011914 -0.010865 -0.009805 -0.008774 -0.007813 -0.006958 -0.006242 -0.005692 -0.005331 -0.005171 -0.005219 -0.005472 -0.005921 -0.006549 -0.007332 -0.008239 -0.009236 -0.010284 -0.011344
0.490874 -0.012074 -0.013542 -0.014870 -0.016008 -0.016912 -0.017547 -0.017889 -0.017925 -0.017653 -0.017084 -0.016239 -0.015151 -0.013863 -0.012422 -0.010886 -0.009312 -0.007762 -0.006294 -0.004966 -0.003829 -0.002926 -0.002292 -0.001951 -0.001916 -0.002188 -0.002757 -0.003602 -0.004688 -0.005976 -0.007416 -0.008951 -0.010524 -0.012074 -0.013542 -0.014870 -0.016008 -0.016912 -0.017547 -0.017889 -0.017925 -0.017653 -0.017084 -0.016239 -0.015151 -0.013863 -0.012422 -0.010886 -0.009312 -0.007762 -0.006294 -0.004966 -0.003829 -0.002926 -0.002292 -0.001951 -0.001916 -0.002188 -0.002757 -0.003602 -0.004688 -0.005976 -0.007416 -0.008951 -0.010524
0.589049 -0.011310 -0.013261 -0.015046 -0.016598 -0.017855 -0.018771 -0.019309 -0.019450 -0.019187 -0.018530 -0.017506 -0.016152 -0.014522 -0.012678 -0.010692 -0.008638 -0.006597 -0.004646 -0.002861 -0.001311 -0.000055 0.000859 0.001396 0.001536 0.001272 0.000616 -0.000408 -0.001760 -0.003388 -0.005231 -0.007217 -0.009269 -0.011310 -0.013261 -0.015046 -0.016598 -0.017855 -0.018771 -0.019309 -0.019450 -0.019187 -0.018530 -0.017506 -0.016152 -0.014522 -0.012678 -0.010692 -0.008638 -0.006597 -0.004646 -0.002861 -0.001311 -0.000055 0.000859 0.001396 0.001536 0.001272 0.000616 -0.000408 -0.001760 -0.003388 -0.005231 -0.007217 -0.009269
0.687223 -0.010112 -0.012481 -0.014669 -0.016589 -0.018168 -0.019346 -0.020077 -0.020333 -0.020104 -0.019399 -0.018245 -0.016686 -0.014783 -0.012608 -0.010245 -0.007786 -0.005324 -0.002954 -0.000767 0.001151 0.002728 0.003904 0.004633 0.004888 0.004659 0.003954 0.002801 0.001244 -0.000657 -0.002830 -0.005192 -0.007650 -0.010112 -0.012481 -0.014669 -0.016589 -0.018168 -0.019346 -0.020077 -0.020333 -0.020104 -0.019399 -0.018245 -0.016686 -0.014783 -0.012608 -0.010245 -0.007786 -0.005324 -0.002954 -0.000767 0.001151 0.002728 0.003904 0.004633 0.004888 0.004659 0.003954 0.002801 0.001244 -0.000657 -0.002830 -0.005192 -0.007650
0.785398 -0.008524 -0.011212 -0.013711 -0.015923 -0.017763 -0.019162 -0.020065 -0.020437 -0.020264 -0.019553 -0.018330 -0.016644 -0.014559 -0.012154 -0.009524 -0.006768 -0.003993 -0.001304 0.001193 0.003403 0.005241 0.006638 0.007538 0.007909 0.007736 0.007025 0.005804 0.004120 0.002037 -0.000366 -0.002995 -0.005749 -0.008524 -0.011212 -0.013711 -0.015923 -0.017763 -0.019162 -0.020065 -0.020437 -0.020264 -0.019553 -0.018330 -0.016644 -0.014559 -0.012154 -0.009524 -0.006768 -0.003993 -0.001304 0.001193 0.003403 0.005241 0.006638 0.007538 0.007909 0.007736 0.007025 0.005804 0.004120 0.002037 -0.000366 -0.002995 -0.005749
0.883573 -0.006609 -0.009486 -0.012177 -0.014578 -0.016596 -0.018155 -0.019194 -0.019674 -0.019575 -0.018902 -0.017680 -0.015957 -0.013798 -0.011288 -0.008522 -0.005607 -0.002654 0.000223 0.002913 0.005311 0.007327 0.008884 0.009921 0.010399 0.010300 0.009627 0.008407 0.006686 0.004530 0.002022 -0.000743 -0.003657 -0.006609 -0.009486 -0.012177 -0.014578 -0.016596 -0.018155 -0.019194 -0.019674 -0.019575 -0.018902 -0.017680 -0.015957 -0.013798 -0.011288 -0.008522 -0.005607 -0.002654 0.000223 0.002913 0.005311 0.007327 0.008884 0.009921 0.010399 0.010300 0.009627 0.008407 0.006686 0.004530 0.002022 -0.000743 -0.003657
0.981748 -0.004440 -0.007357 -0.010103 -0.012573 -0.014670 -0.016316 -0.017446 -0.018016 -0.018006 -0.017415 -0.016265 -0.014603 -0.012490 -0.010009 -0.007256 -0.004335 -0.001359 0.001558 0.004303 0.006770 0.008865 0.010508 0.011636 0.012205 0.012194 0.011604 0.010456 0.008796 0.006686 0.004207 0.001455 -0.001465 -0.004440 -0.007357 -0.010103 -0.012573 -0.014670 -0.016316 -0.017446 -0.018016 -0.018006 -0.017415 -0.016265 -0.014603 -0.012490 -0.010009 -0.007256 -0.004335 -0.001359 0.001558 0.004303 0.006770 0.008865 0.010508 0.011636 0.012205 0.012194 0.011604 0.010456 0.008796 0.006686 0.004207 0.001455 -0.001465
1.079922 -0.002101 -0.004903 -0.007560 -0.009971 -0.012041 -0.013693 -0.014861 -0.015502 -0.015590 -0.015122 -0.014117 -0.012612 -0.010666 -0.008354 -0.005764 -0.002997 -0.000157 0.002645 0.005301 0.007709 0.009778 0.011427 0.012593 0.013233 0.013321 0.012853 0.011849 0.010346 0.008402 0.006092 0.003504 0.000738 -0.002101 -0.004903 -0.007560 -0.009971 -0.012041 -0.013693 -0.014861 -0.015502 -0.015590 -0.015122 -0.014117 -0.012612 -0.010666 -0.008354 -0.005764 -0.002997 -0.000157 0.002645 0.005301 0.007709 0.009778 0.011427 0.012593 0.013233 0.013321 0.012853 0.011849 0.010346 0.008402 0.006092 0.003504 0.000738
1.178097 0.000320 -0.002218 -0.004648 -0.006876 -0.008816 -0.010393 -0.011548 -0.012235 -0.012429 -0.012121 -0.011324 -0.010068 -0.008401 -0.006389 -0.004108 -0.001645 0.000904 0.003442 0.005871 0.008097 0.010035 0.011611 0.012764 0.013450 0.013643 0.013335 0.012539 0.011284 0.009620 0.007609 0.005330 0.002868 0.000320 -0.002218 -0.004648 -0.006876 -0.008816 -0.010393 -0.011548 -0.012235 -0.012429 -0.012121 -0.011324 -0.010068 -0.008401 -0.006389 -0.004108 -0.001645 0.000904 0.003442 0.005871 0.008097 0.010035 0.011611 0.012764 0.013450 0.013643 0.013335 0.012539 0.011284 0.009620 0.007609 0.005330 0.002868
1.276272 0.002728 0.000585 -0.001494 -0.003429 -0.005146 -0.006578 -0.007671 -0.008381 -0.008684 -0.008565 -0.008031 -0.007101 -0.005812 -0.004213 -0.002365 -0.000340 0.001785 0.003928 0.006006 0.007940 0.009655 0.011085 0.012177 0.012887 0.013189 0.013070 0.012537 0.011608 0.010320 0.008723 0.006876 0.004852 0.002728 0.000585 -0.001494 -0.003429 -0.005146 -0.006578 -0.007671 -0.008381 -0.008684 -0.008565 -0.008031 -0.007101 -0.005812 -0.004213 -0.002365 -0.000340 0.001785 0.003928 0.006006 0.007940 0.009655 0.011085 0.012177 0.012887 0.013189 0.013070 0.012537 0.011608 0.010320 0.008723 0.006876 0.004852
1.374447 0.005032 0.003387 0.001755 0.000199 -0.001220 -0.002449 -0.003440 -0.004155 -0.004566 -0.004658 -0.004427 -0.003882 -0.003045 -0.001946 -0.000629 0.000855 0.002451 0.004096 0.005727 0.007282 0.008700 0.009928 0.010918 0.011633 0.012044 0.012136 0.011905 0.011361 0.010525 0.009427 0.008112 0.006628 0.005032 0.003387 0.001755 0.000199 -0.001220 -0.002449 -0.003440 -0.004155 -0.004566 -0.004658 -0.004427 -0.003882 -0.003045 -0.001946 -0.000629 0.000855 0.002451 0.004096 0.005727 0.007282 0.008700 0.009928 0.010918 0.011633 0.012044 0.012136 0.011905 0.011361 0.010525 0.009427 0.008112 0.006628
1.472622 0.007144 0.006063 0.004941 0.003821 0.002747 0.001760 0.000898 0.000194 -0.000325 -0.000638 -0.000734 -0.000610 -0.000270 0.000274 0.000999 0.001878 0.002877 0.003958 0.005080 0.006198 0.007271 0.008257 0.009118 0.009822 0.010340 0.010654 0.010751 0.010627 0.010288 0.009746 0.009022 0.008143 0.007144 0.006063 0.004941 0.003821 0.002747 0.001760 0.000898 0.000194 -0.000325 -0.000638 -0.000734 -0.000610 -0.000270 0.000274 0.000999 0.001878 0.002877 0.003958 0.005080 0.006198 0.007271 0.008257 0.009118 0.009822 0.010340 0.010654 0.010751 0.010627 0.010288 0.009746 0.009022 0.008143
1.570796 0.008982 0.008489 0.007901 0.007240 0.006532 0.005803 0.005083 0.004399 0.003777 0.003241 0.002812 0.002506 0.002334 0.002304 0.002417 0.002668 0.003047 0.003540 0.004128 0.004788 0.005495 0.006222 0.006941 0.007624 0.008245 0.008781 0.009210 0.009517 0.009689 0.009720 0.009609 0.009360 0.008982 0.008489 0.007901 0.007240 0.006532 0.005803 0.005083 0.004399 0.003777 0.003241 0.002812 0.002506 0.002334 0.002304 0.002417 0.002668 0.003047 0.003540 0.004128 0.004788 0.005495 0.006222 0.006941 0.007624 0.008245 0.008781 0.009210 0.009517 0.009689 0.009720 0.009609 0.009360
1.668971 0.010470 0.010547 0.010476 0.010260 0.009908 0.009433 0.008854 0.008192 0.007473 0.006725 0.005977 0.005256 0.004592 0.004010 0.003531 0.003174 0.002953 0.002877 0.002948 0.003164 0.003516 0.003990 0.004569 0.005230 0.005948 0.006695 0.007443 0.008163 0.008827 0.009410 0.009890 0.010248 0.010470 0.010547 0.010476 0.010260 0.009908 0.009433 0.008854 0.008192 0.007473 0.006725 0.005977 0.005256 0.004592 0.004010 0.003531 0.003174 0.002953 0.002877 0.002948 0.003164 0.003516 0.003990 0.004569 0.005230 0.005948 0.006695 0.007443 0.008163 0.008827 0.009410 0.009890 0.010248
1.767146 0.011556 0.012142 0.012533 0.012715 0.012680 0.012429 0.011973 0.011329 0.010521 0.009582 0.008546 0.007454 0.006347 0.005269 0.004260 0.003359 0.002601 0.002015 0.001624 0.001443 0.001478 0.001728 0.002184 0.002828 0.003635 0.004574 0.005609 0.006701 0.007807 0.008886 0.009896 0.010797 0.011556 0.012142 0.012533 0.012715 0.012680 0.012429 0.011973 0.011329 0.010521 0.009582 0.008546 0.007454 0.006347 0.005269 0.004260 0.003359 0.002601 0.002015 0.001624 0.001443 0.001478 0.001728 0.002184 0.002828 0.003635 0.004574 0.005609 0.006701 0.007807 0.008886 0.009896 0.010797
1.865321 0.012199 0.013200 0.013967 0.014469 0.014687 0.014614 0.014252 0.013615 0.012728 0.011625 0.010349 0.008948 0.007476 0.005989 0.004545 0.003199 0.002002 0.001002 0.000236 -0.000265 -0.000484 -0.000411 -0.000050 0.000586 0.001472 0.002574 0.003850 0.005251 0.006723 0.008210 0.009655 0.011002 0.012199 0.013200 0.013967 0.014469 0.014687 0.014614 0.014252 0.013615 0.012728 0.011625 0.010349 0.008948 0.007476 0.005989 0.004545 0.003199 0.002002 0.001002 0.000236 -0.000265 -0.000484 -0.000411 -0.000050 0.000586 0.001472 0.002574 0.003850 0.005251 0.006723 0.008210 0.009655 0.011002
1.963495 0.012375 0.013669 0.014698 0.015423 0.015814 0.015858 0.015553 0.014910 0.013956 0.012726 0.011268 0.009637 0.007897 0.006113 0.004355 0.002689 0.001180 -0.000113 -0.001141 -0.001864 -0.002256 -0.002301 -0.001997 -0.001357 -0.000404 0.000825 0.002283 0.003913 0.005654 0.007439 0.009198 0.010865 0.012375 0.013669 0.014698 0.015423 0.015814 0.015858 0.015553 0.014910 0.013956 0.012726 0.011268 0.009637 0.007897 0.006113 0.004355 0.002689 0.001180 -0.000113 -0.001141 -0.001864 -0.002256 -0.002301 -0.001997 -0.001357 -0.000404 0.000825 0.002283 0.003913 0.005654 0.007439 0.009198 0.010865
2.061670 0.012075 0.013525 0.014691 0.015527 0.016001 0.016094 0.015804 0.015142 0.014134 0.012818 0.011245 0.009476 0.007578 0.005624 0.003688 0.001846 0.000168 -0.001281 -0.002445 -0.003280 -0.003754 -0.003849 -0.003562 -0.002902 -0.001896 -0.000582 0.000990 0.002760 0.004659 0.006614 0.008551 0.010395 0.012075 0.013525 0.014691 0.015527 0.016001 0.016094 0.015804 0.015142 0.014134 0.012818 0.011245 0.009476 0.007578 0.005624 0.003688 0.001846 0.000168 -0.001281 -0.002445 -0.003280 -0.003754 -0.003849 -0.003562 -0.002902 -0.001896 -0.000582 0.000990 0.002760 0.004659 0.006614 0.008551 0.010395
2.159845 0.011310 0.012777 0.013950 0.014784 0.015248 0.015323 0.015008 0.014314 0.013268 0.011911 0.010294 0.008481 0.006540 0.004546 0.002576 0.000704 -0.000997 -0.002462 -0.003632 -0.004466 -0.004930 -0.005008 -0.004695 -0.004003 -0.002960 -0.001605 0.000011 0.001824 0.003766 0.005762 0.007734 0.009608 0.011310 0.012777 0.013950 0.014784 0.015248 0.015323 0.015008 0.014314 0.013268 0.011911 0.010294 0.008481 0.006540 0.004546 0.002576 0.000704 -0.000997 -0.002462 -0.003632 -0.004466 -0.004930 -0.005008 -0.004695 -0.004003 -0.002960 -0.001605 0.000011 0.001824 0.003766 0.005762 0.007734 0.009608
2.258020 0.010112 0.011461 0.012521 0.013249 0.013618 0.013614 0.013238 0.012503 0.011439 0.010085 0.008496 0.006730 0.004858 0.002949 0.001078 -0.000684 -0.002270 -0.003617 -0.004675 -0.005402 -0.005772 -0.005770 -0.005396 -0.004664 -0.003602 -0.002251 -0.000662 0.001103 0.002977 0.004887 0.006760 0.008524 0.010112 0.011461 0.012521 0.013249 0.013618 0.013614 0.013238 0.012503 0.011439 0.010085 0.008496 0.006730 0.004858 0.002949 0.001078 -0.000684 -0.002270 -0.003617 -0.004675 -0.005402 -0.005772 -0.005770 -0.005396 -0.004664 -0.003602 -0.002251 -0.000662 0.001103 0.002977 0.004887 0.006760 0.008524
2.356194 0.008524 0.009645 0.010490 0.011026 0.011232 0.011100 0.010637 0.009859 0.008796 0.007491 0.005992 0.004359 0.002652 0.000939 -0.000716 -0.002249 -0.003602 -0.004720 -0.005563 -0.006098 -0.006305 -0.006175 -0.005713 -0.004938 -0.003878 -0.002574 -0.001077 0.000557 0.002264 0.003979 0.005636 0.007170 0.008524 0.009645 0.010490 0.011026 0.011232 0.011100 0.010637 0.009859 0.008796 0.007491 0.005992 0.004359 0.002652 0.000939 -0.000716 -0.002249 -0.003602 -0.004720 -0.005563 -0.006098 -0.006305 -0.006175 -0.005713 -0.004938 -0.003878 -0.002574 -0.001077 0.000557 0.002264 0.003979 0.005636 0.007170
2.454369 0.006610 0.007420 0.007978 0.008260 0.008257 0.007968 0.007404 0.006589 0.005552 0.004333 0.002981 0.001546 0.000085 -0.001348 -0.002697 -0.003910 -0.004940 -0.005749 -0.006305 -0.006586 -0.006584 -0.006296 -0.005735 -0.004921 -0.003886 -0.002670 -0.001318 0.000116 0.001578 0.003012 0.004362 0.005577 0.006610 0.007420 0.007978 0.008260 0.008257 0.007968 0.007404 0.006589 0.005552 0.004333 0.002981 0.001546 0.000085 -0.001348 -0.002697 -0.003910 -0.004940 -0.005749 -0.006305 -0.006586 -0.006584 -0.006296 -0.005735 -0.004921 -0.003886 -0.002670 -0.001318 0.000116 0.001578 0.003012 0.004362 0.005577
2.552544 0.004441 0.004896 0.005128 0.005129 0.004898 0.004443 0.003784 0.002944 0.001957 0.000860 -0.000305 -0.001492 -0.002655 -0.003752 -0.004738 -0.005577 -0.006236 -0.006689 -0.006920 -0.006920 -0.006689 -0.006236 -0.005578 -0.004740 -0.003754 -0.002659 -0.001495 -0.000308 0.000856 0.001953 0.002940 0.003780 0.004441 0.004896 0.005128 0.005129 0.004898 0.004443 0.003784 0.002944 0.001957 0.000860 -0.000305 -0.001492 -0.002655 -0.003752 -0.004738 -0.005577 -0.006236 -0.006689 -0.006920 -0.006920 -0.006689 -0.006236 -0.005578 -0.004740 -0.003754 -0.002659 -0.001495 -0.000308 0.000856 0.001953 0.002940 0.003780
2.650719 0.002101 0.002197 0.002105 0.001830 0.001382 0.000778 0.000041 -0.000799 -0.001712 -0.002661 -0.003611 -0.004524 -0.005365 -0.006103 -0.006709 -0.007159 -0.007437 -0.007531 -0.007438 -0.007163 -0.006715 -0.006112 -0.005377 -0.004537 -0.003626 -0.002677 -0.001728 -0.000816 0.000026 0.000765 0.001371 0.001822 0.002101 0.002197 0.002105 0.001830 0.001382 0.000778 0.000041 -0.000799 -0.001712 -0.002661 -0.003611 -0.004524 -0.005365 -0.006103 -0.006709 -0.007159 -0.007437 -0.007531 -0.007438 -0.007163 -0.006715 -0.006112 -0.005377 -0.004537 -0.003626 -0.002677 -0.001728 -0.000816 0.000026 0.000765 0.001371 0.001822
2.748894 -0.000319 -0.000547 -0.000923 -0.001433 -0.002058 -0.002773 -0.003552 -0.004363 -0.005176 -0.005959 -0.006683 -0.007319 -0.007844 -0.008236 -0.008481 -0.008570 -0.008498 -0.008269 -0.007892 -0.007382 -0.006757 -0.006043 -0.005265 -0.004455 -0.003643 -0.002860 -0.002137 -0.001501 -0.000976 -0.000583 -0.000338 -0.000248 -0.000319 -0.000547 -0.000923 -0.001433 -0.002058 -0.002773 -0.003552 -0.004363 -0.005176 -0.005959 -0.006683 -0.007319 -0.007844 -0.008236 -0.008481 -0.008570 -0.008498 -0.008269 -0.007892 -0.007382 -0.006757 -0.006043 -0.005265 -0.004455 -0.003643 -0.002860 -0.002137 -0.001501 -0.000976 -0.000583 -0.000338 -0.000248
2.847068 -0.002727 -0.003205 -0.003792 -0.004466 -0.005201 -0.005969 -0.006740 -0.007485 -0.008174 -0.008783 -0.009286 -0.009665 -0.009906 -0.009998 -0.009939 -0.009730 -0.009379 -0.008901 -0.008313 -0.007639 -0.006905 -0.006137 -0.005367 -0.004622 -0.003933 -0.003325 -0.002822 -0.002443 -0.002203 -0.002110 -0.002169 -0.002378 -0.002727 -0.003205 -0.003792 -0.004466 -0.005201 -0.005969 -0.006740 -0.007485 -0.008174 -0.008783 -0.009286 -0.009665 -0.009906 -0.009998 -0.009939 -0.009730 -0.009379 -0.008901 -0.008313 -0.007639 -0.006905 -0.006137 -0.005367 -0.004622 -0.003933 -0.003325 -0.002822 -0.002443 -0.002203 -0.002110 -0.002169 -0.002378
2.945243 -0.005032 -0.005655 -0.006350 -0.007092 -0.007850 -0.008597 -0.009303 -0.009941 -0.010487 -0.010919 -0.011222 -0.011383 -0.011397 -0.011262 -0.010983 -0.010573 -0.010046 -0.009422 -0.008726 -0.007985 -0.007226 -0.006480 -0.005775 -0.005137 -0.004591 -0.004159 -0.003856 -0.003695 -0.003682 -0.003817 -0.004095 -0.004505 -0.005032 -0.005655 -0.006350 -0.007092 -0.007850 -0.008597 -0.009303 -0.009941 -0.010487 -0.010919 -0.011222 -0.011383 -0.011397 -0.011262 -0.010983 -0.010573 -0.010046 -0.009422 -0.008726 -0.007985 -0.007226 -0.006480 -0.005775 -0.005137 -0.004591 -0.004159 -0.003856 -0.003695 -0.003682 -0.003817 -0.004095 -0.004505
3.043418 -0.007144 -0.007788 -0.008471 -0.009167 -0.009850 -0.010492 -0.011070 -0.011561 -0.011946 -0.012210 -0.012344 -0.012342 -0.012204 -0.011935 -0.011546 -0.011052 -0.010472 -0.009827 -0.009144 -0.008448 -0.007766 -0.007123 -0.006546 -0.006055 -0.005670 -0.005406 -0.005273 -0.005275 -0.005413 -0.005681 -0.006070 -0.006564 -0.007144 -0.007788 -0.008471 -0.009167 -0.009850 -0.010492 -0.011070 -0.011561 -0.011946 -0.012210 -0.012344 -0.012342 -0.012204 -0.011935 -0.011546 -0.011052 -0.010472 -0.009827 -0.009144 -0.008448 -0.007766 -0.007123 -0.006546 -0.006055 -0.005670 -0.005406 -0.005273 -0.005275 -0.005413 -0.005681 -0.006070 -0.006564

In [65]:
pickle_dict


Out[65]:
{'f_nodes': array([[-0.01056457,  0.00437599,  1.71373388],
        [-0.00437599, -0.01056457,  1.71373388],
        [ 0.01056457, -0.00437599,  1.71373388],
        ...,
        [ 0.29176567,  0.07896289,  0.26545571],
        [ 0.28729325,  0.07821732,  0.26519057],
        [ 0.28692785,  0.08151299,  0.26208675]]),
 'problem_kwargs': {'MPISIZE': 24,
  'Tfct': 1,
  'basei': 1,
  'belemshandle': 'belems',
  'bnodeshandle': 'bnodes',
  'center': array([0, 0, 0]),
  'ch': 3.0,
  'dist_hs': 0.5,
  'ds': 0.023333,
  'eT': -1.0,
  'eh': -1.0,
  'es': -1.0,
  'ffweightT': 2.0,
  'ffweightx': 2.0,
  'ffweighty': 2.0,
  'ffweightz': 2.0,
  'field_range': array([[-3, -3, -3],
         [ 3,  3,  3]]),
  'fileHandle': 'ecoC01B05_baseFlow',
  'getConvergenceHistory': False,
  'hfct': 1.0,
  'int_epsabs': 1e-200,
  'int_epsrel': 1e-10,
  'int_limit': 1000,
  'left_hand': False,
  'ls': 1.0,
  'matname': 'body1',
  'matrix_method': 'pf',
  'n_grid': array([10, 10, 10]),
  'n_node_threshold': 5000,
  'n_tail': 1,
  'ntT': 20,
  'nth': 20,
  'ph': 0.666667,
  'pickProblem': False,
  'plot_geo': False,
  'precondition_method': 'none',
  'rT1': 0.2,
  'rT2': 0.03,
  'region_type': 'rectangle',
  'rel_Uh': array([0., 0., 0., 0., 0., 0.]),
  'rel_Us': array([0., 0., 0., 0., 0., 0.]),
  'repeat_n': 1,
  'restart': False,
  'rh1': 0.2,
  'rh11': 0.3,
  'rh12': 0.1,
  'rh2': 0.03,
  'rot_norm': array([1, 0, 0]),
  'rot_theta': 0,
  'rs1': 0.5,
  'rs2': 0.166667,
  'save_vtk': False,
  'solve_method': 'gmres',
  'with_T_geo': False,
  'with_cover': 2,
  'zoom_factor': 1.0},
 'sumFT_Base_list': [array([ 1.35677111e-06,  9.08462313e-07, -3.00339206e-07, -1.67756939e-06,
         -7.06695221e-07, -7.92296530e-08]),
  array([ 4.53397711e-07,  2.44468094e-06, -1.55113643e-09, -7.74157675e-08,
          1.29278165e-06,  1.46682183e-07]),
  array([ 6.03758566e-06,  7.65828999e-06, -2.24176052e-06,  1.90766635e-05,
         -1.01795939e-05,  9.15257428e-07]),
  array([-1.56619721e-06,  9.46941180e-07, -2.77076536e-07,  6.32899575e-06,
          2.88359794e-06, -1.07913415e-06]),
  array([ 9.40749092e-06,  7.10063140e-06,  1.17369125e-05, -1.25618810e-05,
         -1.46881805e-05, -1.04639298e-06]),
  array([-4.33984934e-05, -1.30007224e-06,  5.83327036e-06,  7.39654459e-07,
         -1.21690266e-05, -4.44395622e-06]),
  array([-3.23884861e-12,  1.03387172e-11, -1.32034827e-11,  2.12432993e-11,
          2.70226932e-11,  4.30777621e-12]),
  array([-2.11985553e-11, -1.53957152e-10,  2.64876209e-12,  4.34312893e-11,
          2.84345026e-11,  1.18923772e-11]),
  array([-3.46425159e-12, -1.03470427e-12,  3.20939750e-14,  6.45634283e-12,
          1.67044114e-12,  8.07226490e-13]),
  array([-7.15932690e-07, -5.71356040e-08,  2.95644707e-07, -5.08068486e-07,
         -1.55310167e-05,  5.62852737e-09])],
 'u_nodes': array([[-0.01135974,  0.00470536,  1.74863799],
        [-0.00470536, -0.01135974,  1.74863799],
        [ 0.01135974, -0.00470536,  1.74863799],
        ...,
        [ 0.29122606,  0.08554284,  0.2740172 ],
        [ 0.28471724,  0.08445778,  0.27363133],
        [ 0.28418546,  0.08925406,  0.26911426]]),
 'uw_Base_list': [array([ 4.93774517e-03, -8.99508578e-03,  6.85076654e-03, -6.84757586e-04,
          9.67729782e-01,  1.27231163e-02]),
  array([ 8.73490227e-03, -3.04951663e-04,  9.22176811e-05, -6.28200631e-03,
         -3.59603870e-03, -2.60939819e-01]),
  array([-0.01776581, -0.01735206, -0.05823745, -0.03146625,  0.02636917,
          0.0252918 ]),
  array([ 0.00532147,  0.00478599,  0.00607358,  0.00262137, -0.01267284,
          0.53868783]),
  array([ 0.00987612, -0.0179897 ,  0.01370285, -0.00136997,  0.93545887,
          0.02544567]),
  array([ 2.13276729e-02, -6.80206271e-04,  6.09546251e-03, -9.80744726e-01,
         -2.25282906e-02,  4.62776593e-03]),
  array([-3.13832175e-13,  7.53768232e-13, -1.37302537e-12,  1.00000000e+00,
          1.35557020e-12,  3.50521297e-12]),
  array([-2.17152938e-12, -1.28505456e-11,  6.11104526e-13,  2.26368026e-12,
          1.00000000e+00,  1.20490652e-11]),
  array([-3.08628531e-13, -1.09422286e-13,  1.34169180e-14,  3.08983658e-13,
          8.97127441e-14,  1.00000000e+00]),
  array([ 6.35418425e-04, -2.19676135e-03,  4.02494122e-03, -1.31786126e-03,
         -1.23559401e-03, -7.57100877e-01])]}

In [64]:
pickle_name = 'ecoC01B05_baseFlow'

with open('%s.pickle' % pickle_name, 'rb') as handle:
    pickle_dict = pickle.load(handle)

# print(np.vstack(pickle_dict['uw_Base_list']).shape)
uEbase_list = np.vstack(pickle_dict['uw_Base_list'])[1:6, 0:3]
uSbase_list = np.vstack(pickle_dict['uw_Base_list'])[6:9, 0:3]
wEbase_list = np.vstack(pickle_dict['uw_Base_list'])[1:6, 3:6]
wSbase_list = np.vstack(pickle_dict['uw_Base_list'])[6:9, 3:6]
print(wEbase_list)
print()
print(wSbase_list)
print()
print(uEbase_list)
print()
print(uSbase_list)
print()
print(pickle_dict['uw_Base_list'][9])


[[-0.00628201 -0.00359604 -0.26093982]
 [-0.03146625  0.02636917  0.0252918 ]
 [ 0.00262137 -0.01267284  0.53868783]
 [-0.00136997  0.93545887  0.02544567]
 [-0.98074473 -0.02252829  0.00462777]]

[[1.00000000e+00 1.35557020e-12 3.50521297e-12]
 [2.26368026e-12 1.00000000e+00 1.20490652e-11]
 [3.08983658e-13 8.97127441e-14 1.00000000e+00]]

[[ 8.73490227e-03 -3.04951663e-04  9.22176811e-05]
 [-1.77658091e-02 -1.73520598e-02 -5.82374515e-02]
 [ 5.32147082e-03  4.78599433e-03  6.07358035e-03]
 [ 9.87611809e-03 -1.79897016e-02  1.37028527e-02]
 [ 2.13276729e-02 -6.80206271e-04  6.09546251e-03]]

[[-3.13832175e-13  7.53768232e-13 -1.37302537e-12]
 [-2.17152938e-12 -1.28505456e-11  6.11104526e-13]
 [-3.08628531e-13 -1.09422286e-13  1.34169180e-14]]

[ 6.35418425e-04 -2.19676135e-03  4.02494122e-03 -1.31786126e-03
 -1.23559401e-03 -7.57100877e-01]

In [1681]:
# # dbg code 
# pickle_name = 'ecoC01B05_baseFlow'

# with open('%s.pickle' % pickle_name, 'rb') as handle:
#     pickle_dict = pickle.load(handle)

# # print(np.vstack(pickle_dict['uw_Base_list']).shape)
# uEbase_list = np.vstack(pickle_dict['uw_Base_list'])[1:6, 0:3]
# uSbase_list = np.vstack(pickle_dict['uw_Base_list'])[6:9, 0:3]
# wEbase_list = np.vstack(pickle_dict['uw_Base_list'])[1:6, 3:6]
# wSbase_list = np.vstack(pickle_dict['uw_Base_list'])[6:9, 3:6]
# print(wEbase_list)
# print(wSbase_list)
# # print(pickle_dict['uw_Base_list'][9])

# i0, i1, i2 = np.random.randint(tpsi_all.size), np.random.randint(ttheta_all.size), np.random.randint(tphi_all.size)
# i0, i1, i2 = 5, 12, 21
# tpsi = tpsi_all[i0]
# ttheta = ttheta_all[i1]
# tphi = tphi_all[i2]

# Eij_loc = spf_tb.Eij_loc(ttheta, tphi, tpsi)
# Sij_loc = spf_tb.Sij_loc(ttheta, tphi, tpsi)
# Ebase_fct = np.array([Eij_loc[0, 0], Eij_loc[2, 2], Eij_loc[0, 1], Eij_loc[0, 2], Eij_loc[1, 2]])
# Sbase_fct = np.array([Sij_loc[2, 1], Sij_loc[0, 2], Sij_loc[1, 0]])
# wE_loc = np.sum([a * b for a, b in zip(Ebase_fct, wEbase_list)], axis=0)
# wE = np.dot(spf_tb.Rrot(ttheta, tphi, tpsi), wE_loc)
# wS_loc = np.sum([a * b for a, b in zip(Sbase_fct, wSbase_list)], axis=0)
# wS = np.dot(spf_tb.Rrot(ttheta, tphi, tpsi), wS_loc)
# wS_cal_list.append(wS)
# tw_cal = wE + wS
# tw_sim = np.hstack((U_all[3][i0].iloc[i1].iloc[i2], U_all[4][i0].iloc[i1].iloc[i2], U_all[5][i0].iloc[i1].iloc[i2]))
# print(i0, i1, i2)
# print(ttheta, tphi, tpsi)
# print(tw_sim)
# print(tw_cal)
# print(tw_sim - tw_cal)

In [1682]:
importlib.reload(spf_tb)
pickle_name = 'ecoC01B05_baseFlow'

with open('%s.pickle' % pickle_name, 'rb') as handle:
    pickle_dict = pickle.load(handle)
uEbase_list = np.vstack(pickle_dict['uw_Base_list'])[1:6, 0:3]
uSbase_list = np.vstack(pickle_dict['uw_Base_list'])[6:9, 0:3]
wEbase_list = np.vstack(pickle_dict['uw_Base_list'])[1:6, 3:6]
wSbase_list = np.vstack(pickle_dict['uw_Base_list'])[6:9, 3:6]
wE_fun = lambda theta, phi, psi: np.array((np.cos(phi)*np.sin(theta)*(np.cos(phi)*(np.cos(2*theta)*(0.01272114*np.cos(psi) + 0.002320485005*np.sin(psi)) + np.cos(theta)*(0.02524755 + 0.261018491*np.cos(psi)**2 + 0.53873059*np.cos(psi)*np.sin(psi))*np.sin(theta)) + np.sin(phi)*(-0.01272114*np.cos(theta)*np.sin(psi) + 0.269365295*np.cos(2*psi)*np.sin(theta) + np.cos(psi)*(0.002320485005*np.cos(theta) - 0.261018491*np.sin(psi)*np.sin(theta)))) + (np.cos(phi)*np.cos(psi)*np.cos(theta) - np.sin(phi)*np.sin(psi))*(np.cos(phi)*(np.cos(2*theta)*(-0.000682955*np.cos(psi) + 0.49037295500000005*np.sin(psi)) + np.cos(theta)*(-0.03147468 + 0.00628396028*np.cos(psi)**2 + 0.00261925*np.cos(psi)*np.sin(psi))*np.sin(theta)) + np.sin(phi)*(0.000682955*np.cos(theta)*np.sin(psi) + 0.001309625*np.cos(2*psi)*np.sin(theta) + np.cos(psi)*(0.49037295500000005*np.cos(theta) - 0.00628396028*np.sin(psi)*np.sin(theta)))) + (-(np.cos(psi)*np.sin(phi)) - np.cos(phi)*np.cos(theta)*np.sin(psi))*(np.cos(phi)*(np.cos(2*theta)*(0.46773080499999997*np.cos(psi) + 0.0112595912*np.sin(psi)) + np.cos(theta)*(0.026366300000000002 + 0.0035945814*np.cos(psi)**2 - 0.01267259*np.cos(psi)*np.sin(psi))*np.sin(theta)) + np.sin(phi)*(-0.467730805*np.cos(theta)*np.sin(psi) - 0.006336295*np.cos(2*psi)*np.sin(theta) + np.cos(psi)*(0.0112595912*np.cos(theta) - 0.0035945814*np.sin(psi)*np.sin(theta)))),np.sin(phi)*np.sin(theta)*(np.cos(phi)*(np.cos(2*theta)*(0.01272114*np.cos(psi) + 0.002320485005*np.sin(psi)) + np.cos(theta)*(0.02524755 + 0.261018491*np.cos(psi)**2 + 0.53873059*np.cos(psi)*np.sin(psi))*np.sin(theta)) + np.sin(phi)*(-0.01272114*np.cos(theta)*np.sin(psi) + 0.269365295*np.cos(2*psi)*np.sin(theta) + np.cos(psi)*(0.002320485005*np.cos(theta) - 0.261018491*np.sin(psi)*np.sin(theta)))) + (np.cos(psi)*np.cos(theta)*np.sin(phi) + np.cos(phi)*np.sin(psi))*(np.cos(phi)*(np.cos(2*theta)*(-0.000682955*np.cos(psi) + 0.49037295500000005*np.sin(psi)) + np.cos(theta)*(-0.03147468 + 0.00628396028*np.cos(psi)**2 + 0.00261925*np.cos(psi)*np.sin(psi))*np.sin(theta)) + np.sin(phi)*(0.000682955*np.cos(theta)*np.sin(psi) + 0.001309625*np.cos(2*psi)*np.sin(theta) + np.cos(psi)*(0.49037295500000005*np.cos(theta) - 0.00628396028*np.sin(psi)*np.sin(theta)))) + (np.cos(phi)*np.cos(psi) - np.cos(theta)*np.sin(phi)*np.sin(psi))*(np.cos(phi)*(np.cos(2*theta)*(0.46773080499999997*np.cos(psi) + 0.0112595912*np.sin(psi)) + np.cos(theta)*(0.026366300000000002 + 0.0035945814*np.cos(psi)**2 - 0.01267259*np.cos(psi)*np.sin(psi))*np.sin(theta)) + np.sin(phi)*(-0.467730805*np.cos(theta)*np.sin(psi) - 0.006336295*np.cos(2*psi)*np.sin(theta) + np.cos(psi)*(0.0112595912*np.cos(theta) - 0.0035945814*np.sin(psi)*np.sin(theta)))),np.sin(phi)*(np.cos(theta)**2*(0.002320485005*np.cos(psi) - 0.01272114*np.sin(psi)) + np.cos(theta)*(-0.47905188000000004 + 0.25804422*np.cos(2*psi) - 0.25044185480000003*np.cos(psi)*np.sin(psi))*np.sin(theta) + (-0.00155345785*np.cos(psi) + 0.00024383285000000002*np.cos(3*psi) + 0.0047391375699999995*np.sin(psi) - 0.0015971574299999997*np.sin(3*psi))*np.sin(theta)**2) + np.cos(phi)*(0.01272114*np.cos(psi)*np.cos(theta)**3 + np.cos(theta)*(0.013183150000000001 - 0.010862664995*np.cos(2*theta))*np.sin(psi) + ((0.0059712731000000005 - 0.0052883181*np.cos(2*psi))*np.cos(2*theta) + np.cos(theta)**2*(0.02524755 + 0.261018491*np.cos(psi)**2 + 0.5160884399999999*np.cos(psi)*np.sin(psi)))*np.sin(theta) + np.cos(psi)*np.cos(theta)*(0.009275264859999998 + 0.0031943148599999998*np.cos(2*psi) + 0.0009753313999999999*np.cos(psi)*np.sin(psi))*np.sin(theta)**2 + 0.022642150000000083*np.cos(psi)*np.sin(psi)*np.sin(theta)**3)))
U_cal_all = [[] for i in range(6)]

uS_cal_list = []
for i0 in range(tpsi_all.size):
    tpsi = tpsi_all[i0]
    tux = U_all[0][i0]
    tuy = U_all[1][i0]
    tuz = U_all[2][i0]
    tux_cal = tux.copy()
    tuy_cal = tuy.copy()
    tuz_cal = tuz.copy()
    for i1 in range(ttheta_all.size):
        ttheta = ttheta_all[i1]
        for i2 in range(tphi_all.size):
            tphi = tphi_all[i2]
            
            Eij_loc = spf_tb.Eij_loc(ttheta, tphi, tpsi)
            Sij_loc = spf_tb.Sij_loc(ttheta, tphi, tpsi)
            Ebase_fct = np.array([Eij_loc[0, 0], Eij_loc[2, 2], Eij_loc[0, 1], Eij_loc[0, 2], Eij_loc[1, 2]])
            Sbase_fct = np.array([Sij_loc[2, 1], Sij_loc[0, 2], Sij_loc[1, 0]])
            uE_loc = np.sum([a * b for a, b in zip(Ebase_fct, uEbase_list)], axis=0)
            uE = np.dot(spf_tb.Rrot(ttheta, tphi, tpsi), uE_loc)
            uS_loc = np.sum([a * b for a, b in zip(Sbase_fct, uSbase_list)], axis=0)
            uS = np.dot(spf_tb.Rrot(ttheta, tphi, tpsi), uS_loc)
            uS_cal_list.append(uS)
#             uS = np.array((0, 0, 0))
            tu_cal = uE + uS
            tux_cal.iloc[i1].iloc[i2] = tu_cal[0]
            tuy_cal.iloc[i1].iloc[i2] = tu_cal[1]
            tuz_cal.iloc[i1].iloc[i2] = tu_cal[2]
    U_cal_all[0].append(tux_cal)
    U_cal_all[1].append(tuy_cal)
    U_cal_all[2].append(tuz_cal)
# print(np.linalg.norm(np.vstack(uS_cal_list) - np.array((0, 0, 0)), axis=-1).max())

wS_cal_list = []
wE_err_list = []
for i0 in range(tpsi_all.size):
    tpsi = tpsi_all[i0]
    twx = U_all[3][i0]
    twy = U_all[4][i0]
    twz = U_all[5][i0]
    twx_cal = twx.copy()
    twy_cal = twy.copy()
    twz_cal = twz.copy()
    for i1 in range(ttheta_all.size):
        ttheta = ttheta_all[i1]
        for i2 in range(tphi_all.size):
            tphi = tphi_all[i2]
            
            Eij_loc = spf_tb.Eij_loc(ttheta, tphi, tpsi)
            Sij_loc = spf_tb.Sij_loc(ttheta, tphi, tpsi)
            Ebase_fct = np.array([Eij_loc[0, 0], Eij_loc[2, 2], Eij_loc[0, 1], Eij_loc[0, 2], Eij_loc[1, 2]])
            Sbase_fct = np.array([Sij_loc[2, 1], Sij_loc[0, 2], Sij_loc[1, 0]])
            wE_loc = np.sum([a * b for a, b in zip(Ebase_fct, wEbase_list)], axis=0)
            wE = np.dot(spf_tb.Rrot(ttheta, tphi, tpsi), wE_loc)
#             wE2 = wE_fun(ttheta, tphi, tpsi)
#             wE_err_list.append(wE - wE2)
            wS_loc = np.sum([a * b for a, b in zip(Sbase_fct, wSbase_list)], axis=0)
            wS = np.dot(spf_tb.Rrot(ttheta, tphi, tpsi), wS_loc)
            wS_cal_list.append(wS)
#             wS = np.array((0, 0.5, 0))
            tw_cal = wE + wS
            twx_cal.iloc[i1].iloc[i2] = tw_cal[0]
            twy_cal.iloc[i1].iloc[i2] = tw_cal[1]
            twz_cal.iloc[i1].iloc[i2] = tw_cal[2]
    U_cal_all[3].append(twx_cal)
    U_cal_all[4].append(twy_cal)
    U_cal_all[5].append(twz_cal)
# print(np.linalg.norm(np.vstack(wS_cal_list) - np.array((0, 0.5, 0)), axis=-1).max())
# print(np.linalg.norm(np.vstack(wE_err_list), axis=-1).max())

In [1697]:
for use_uidx in (0, 1, 2, 3, 4, 5):
    tu_cal = np.dstack(U_cal_all[use_uidx])
    spf_tb.show_ui_psi(tu_cal, ttheta_all, tphi_all, tpsi_all, dpi=200)



In [1698]:
for use_uidx in (3, 4, 5):
    tu = np.dstack(U_all[use_uidx])
    tu_cal = np.dstack(U_cal_all[use_uidx])
    t1 = tu_cal - tu
    print(np.abs(t1).max())
    spf_tb.show_ui_psi(t1, ttheta_all, tphi_all, tpsi_all, dpi=200)


0.0004479347188867111
0.00031504931884451803
0.000438265961148529

show the slice of base flows


In [1604]:
figsize = np.array((16, 9)) * 1
dpi = 100

t1, t2 = np.meshgrid(np.linspace(-3, 3, 30), np.linspace(-3, 3, 30), indexing='ij')
# u1, u2 = t1, -t2
# title = '$\\tilde{\\bm{u}}^{E1} = (x, -y, 0)$'
# xlabel, ylabel = '$x$', '$y$'

# u1, u2 = -t1, t2
# title = '$\\tilde{\\bm{u}}^{E2} = (0, -y, z)$'
# xlabel, ylabel = '$y$', '$z$'

# u1, u2 = t2, t1
# title = '$\\tilde{\\bm{u}}^{E3} = (y, x, 0)$'
# xlabel, ylabel = '$x$', '$y$'

u1, u2 = t2, t1
title = '$\\tilde{\\bm{u}}^{E4} = (z, 0, x)$'
xlabel, ylabel = '$x$', '$z$'

# u1, u2 = t2, t1
# title = '$\\tilde{\\bm{u}}^{E5} = (0, y, x)$'
# xlabel, ylabel = '$y$', '$z$'

fig, axs = plt.subplots(1, 1, figsize=figsize, dpi=dpi)
fig.patch.set_facecolor('white')
axi = axs
axi.quiver(t1, t2, u1, u2)
axi.axis('equal')
axi.set_title(title)
axi.set_xlabel(xlabel)
axi.set_ylabel(ylabel)
plt.tight_layout()



In [ ]:


In [61]:
from shutil import copyfile

# pickle_name = 'ecoC01B05_baseFlow'
# mdf_pickle_name = 'ecoC01B05_baseFlow_mdf'

# pickle_name = 'ecoB01_baseFlow'
# mdf_pickle_name = 'ecoB01_baseFlow_mdf'

# pickle_name = 'hlxC02B05_baseFlow'
# mdf_pickle_name = 'hlxC02B05_baseFlow_mdf'

# pickle_name = 'hlxC03B05_baseFlow'
# mdf_pickle_name = 'hlxC03B05_baseFlow_mdf'
with open('%s.pickle' % pickle_name, 'rb') as handle:
    pickle_dict = pickle.load(handle)
display(np.vstack(pickle_dict['uw_Base_list'])[1:6, 3:])

t1 = pickle_dict['uw_Base_list'].copy()
# for i0 in (0, 6, 7, 8, 9):
for i0 in (0, 1, 2, 3, 4, 5, 6, 7, 8, 9):
    t1[i0] = np.zeros_like(t1[i0])
# # t1[2][5] = pickle_dict['uw_Base_list'][2][5]
# ta1 = (pickle_dict['uw_Base_list'][4][3] + pickle_dict['uw_Base_list'][5][4]) / 2
# ta2 = (pickle_dict['uw_Base_list'][4][4] - pickle_dict['uw_Base_list'][5][3]) / 2
# t1[4][3] = ta1
# t1[4][4] = ta2
# t1[5][3] = -ta2
# t1[5][4] = ta1
# t1[9] = pickle_dict['uw_Base_list'][9]
# display(np.vstack(t1)[1:6, 3:])

# t1[2][5] = pickle_dict['uw_Base_list'][2][5]
ta2 = (pickle_dict['uw_Base_list'][4][4] + pickle_dict['uw_Base_list'][5][3]) / 2
t1[3][5] = pickle_dict['uw_Base_list'][3][5]
t1[4][4] = pickle_dict['uw_Base_list'][4][4]
t1[5][3] = pickle_dict['uw_Base_list'][5][3]
# t1[4][4] = -ta2
# t1[5][3] = -ta2
t1[9] = pickle_dict['uw_Base_list'][9]
display(np.vstack(t1)[1:6, 3:])

pickle_dict['uw_Base_list'] = t1
tname = '%s.pickle' % mdf_pickle_name
with open(tname, 'wb') as handle:
    pickle.dump(pickle_dict, handle, protocol=pickle.HIGHEST_PROTOCOL)
copyfile(tname, os.path.join(os.getcwd(), os.pardir, os.pardir, 'src', tname))
print('save table_data to %s' % tname)


array([[ 8.52557836e-06, -1.08471925e-06, -2.84475197e-07],
       [ 9.76759689e-06,  3.29143951e-08,  5.75166569e-07],
       [-9.69034533e-08, -2.98171981e-07,  9.65181431e-01],
       [-1.67252037e-07, -9.48863747e-01, -3.89043842e-06],
       [-3.79998248e-02, -7.90232568e-09,  2.52878755e-08]])
array([[ 0.        ,  0.        ,  0.        ],
       [ 0.        ,  0.        ,  0.        ],
       [ 0.        ,  0.        ,  0.96518143],
       [ 0.        , -0.94886375,  0.        ],
       [-0.03799982,  0.        ,  0.        ]])
save table_data to hlx2_rh11_1.000_ph_6.67_baseFlow_mdf.pickle

In [ ]: