動作環境
GeForce GTX 1070 (8GB)
ASRock Z170M Pro4S [Intel Z170chipset]
Ubuntu 14.04 LTS desktop amd64
TensorFlow v0.11
cuDNN v5.1 for Linux
CUDA v8.0
Python 2.7.6
IPython 5.1.0 -- An enhanced Interactive Python.
gcc (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4
GNU bash, version 4.3.8(1)-release (x86_64-pc-linux-gnu)
v0.1: http://qiita.com/7of9/items/09262a2ab01d037d169b
結果確認コードを変更して、Y, Z方向の電場Eの実部、虚部の値を扱えるようにした。
その中で学んだことが、Enumに相当するものの実装。
code v0.2
targetIdxの指定TARGET_IDX.EXR
をTARGET_IDX.EZI
などのように変更することで、Y, Zの電場の実部、虚部を切り替えることが可能。
Jupyter code
実行にはv0.1で作成したLN-INPUT-CSVが必要。
check_resultmap_170429.ipynb
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import numpy as np
import math
import sys
import matplotlib.pyplot as plt
import matplotlib.cm as cm
'''
v0.2 Mar. 03, 2017
- add [Elist] instead of each of [Exr, Exi, ...]
- add [targetIdx] for selection of the target item
- add enum [TARGET_IDX]
v0.1 Apr. 29, 2017
- use snippet from [check_resultmap_170329.ipynb] v0.2
'''
# codingrule:PEP8
src_data = np.genfromtxt('LN-INPUT-CSV', delimiter=',')
xpos, ypos, zpos = src_data[:, 0], src_data[:, 1], src_data[:, 2]
# Exr, Exi, Eyr, Eyi, Ezr, Ezi
Elist = [src_data[:, idx] for idx in range(3, 9)]
class TARGET_IDX:
EXR, EXI = 3, 4 # real and imaginary part of Ex
EYR, EYI = 5, 6 # those of Ey
EZR, EZI = 7, 8 # those of Ez
# get middle value for zpos
wrk = np.unique(zpos)
if len(wrk) % 2 == 0:
# let the number of items [even]
wrk = np.delete(wrk, max(wrk))
pickUpZvalue = np.median(wrk)
# parameters
SIZE_MAP_X = 30 # size of the image
SIZE_MAP_Y = 30
ZOOM_X = 15.0 #
ZOOM_Y = 15.0
SHIFT_X = 15.0 # to shift the center position
SHIFT_Y = 15.0
rmap = [[0.0 for yi in range(SIZE_MAP_Y)] for xi in range(SIZE_MAP_X)]
targetIdx = TARGET_IDX.EZI
# prepare map
for aline in zip(xpos, ypos, zpos, *Elist):
ax, ay, az = aline[0], aline[1], aline[2]
aTarget = aline[targetIdx]
if abs(az - pickUpZvalue) > sys.float_info.epsilon:
continue
xidx = (SIZE_MAP_X * ax / ZOOM_X + SHIFT_X).astype(int)
yidx = (SIZE_MAP_Y * ay / ZOOM_Y + SHIFT_Y).astype(int)
if xidx < 0 or xidx >= SIZE_MAP_X:
continue
if yidx < 0 or yidx >= SIZE_MAP_Y:
continue
rmap[xidx][yidx] = aTarget # overwrite
# draw map
wrkarr = np.array(rmap)
figmap = np.reshape(wrkarr, (SIZE_MAP_X, SIZE_MAP_Y))
plt.imshow(figmap, extent=(0, SIZE_MAP_X, 0, SIZE_MAP_Y), cmap=cm.jet)
plt.show()
結果
v0.3
Elist
の取得方法について、読みやすい実装方法を教えていただきました。
情報感謝です。
Elist = [src_data[:, idx] for idx in range(3, 9)]
から以下のように変更しました。
Elist = src_data.T[3:9]
Jupyter code.
check_resultmap_170429
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import numpy as np
import math
import sys
import matplotlib.pyplot as plt
import matplotlib.cm as cm
'''
v0.3 Mar. 03, 2017
- [Elist] is extracted using matrix transposition
v0.2 Mar. 03, 2017
- add [Elist] instead of each of [Exr, Exi, ...]
- add [targetIdx] for selection of the target item
- add enum [TARGET_IDX]
v0.1 Apr. 29, 2017
- use snippet from [check_resultmap_170329.ipynb] v0.2
'''
# codingrule:PEP8
src_data = np.genfromtxt('LN-INPUT-CSV', delimiter=',')
xpos, ypos, zpos = src_data[:, 0], src_data[:, 1], src_data[:, 2]
# Exr, Exi, Eyr, Eyi, Ezr, Ezi
Elist = src_data.T[3:9]
class TARGET_IDX:
EXR, EXI = 3, 4 # real and imaginary part of Ex
EYR, EYI = 5, 6 # those of Ey
EZR, EZI = 7, 8 # those of Ez
# get middle value for zpos
wrk = np.unique(zpos)
if len(wrk) % 2 == 0:
# let the number of items [even]
wrk = np.delete(wrk, max(wrk))
pickUpZvalue = np.median(wrk)
# parameters
SIZE_MAP_X = 30 # size of the image
SIZE_MAP_Y = 30
ZOOM_X = 15.0 #
ZOOM_Y = 15.0
SHIFT_X = 15.0 # to shift the center position
SHIFT_Y = 15.0
rmap = [[0.0 for yi in range(SIZE_MAP_Y)] for xi in range(SIZE_MAP_X)]
targetIdx = TARGET_IDX.EYR
# prepare map
for aline in zip(xpos, ypos, zpos, *Elist):
ax, ay, az = aline[0], aline[1], aline[2]
aTarget = aline[targetIdx]
if abs(az - pickUpZvalue) > sys.float_info.epsilon:
continue
xidx = (SIZE_MAP_X * ax / ZOOM_X + SHIFT_X).astype(int)
yidx = (SIZE_MAP_Y * ay / ZOOM_Y + SHIFT_Y).astype(int)
if xidx < 0 or xidx >= SIZE_MAP_X:
continue
if yidx < 0 or yidx >= SIZE_MAP_Y:
continue
rmap[xidx][yidx] = aTarget # overwrite
# draw map
wrkarr = np.array(rmap)
figmap = np.reshape(wrkarr, (SIZE_MAP_X, SIZE_MAP_Y))
plt.imshow(figmap, extent=(0, SIZE_MAP_X, 0, SIZE_MAP_Y), cmap=cm.jet)
plt.show()