-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcylindermaker.py
More file actions
110 lines (98 loc) · 4.7 KB
/
cylindermaker.py
File metadata and controls
110 lines (98 loc) · 4.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import numpy as np
import os
import subprocess
import glob
import skimage as ski
import skimage.io
import matplotlib.pyplot as plt
import matplotlib
import ffmpeg
from tqdm import tqdm
import shutil
import time
#root = "D:\\myGit\\build\\scatter_bld_winter\\"
#data_dir = "D:\\myGit\\build\\scatter_bld_winter\\lambdas\\"
scattervol_path = "/home/ruijiao/A_research/build/scattersim/"
source_path = "/home/ruijiao/A_research/scattersim/" # Where the sample is from
data_path = source_path + "cylinder/"
sample_name = "cylinder_20_1_100_1.4_0.05j.npy"
files = os.listdir(data_path)
for f in files:
file = os.path.join(data_path, f)
os.chmod(file, 0o777)
os.remove(file)
# #-----------X-Y SIM----------------------
# result_npy = scattervol_path + "xz.npy"
# save_axis = 1 # Save xz plane
# N_lambda = 50
# lambda_min = 1
# lambda_max = 10
# # lambdas = np.linspace(lambda_max, lambda_min, N_lambda)
# nus = np.linspace(2 * np.pi / lambda_max, 2 * np.pi / lambda_min, N_lambda)
# lambdas = 1.0 / nus * 2 * np.pi
# # size = [28, 1, 10] # Size of the sample. 4 is the diamter of the cylinder(z)
# size = [20, 1, 4] # Size of the sample. 4 is the diamter of the cylinder(z)
# relative_slice = size[2]/2 # Use the bottom of the sample
# coefs = [80, 1]
# resolution = 8
# result_cw = scattervol_path + "volume.cw"
#-----------X-Z SIM----------------------
result_npy = scattervol_path + "xz.npy"
save_axis = 1 # Save xz plane
N_lambda = 9
lambda_min = 1
lambda_max = 5
lambdas = np.linspace(lambda_min, lambda_max, N_lambda)
# nus = np.linspace(2 * np.pi / lambda_max, 2 * np.pi / lambda_min, N_lambda)
# lambdas = 1.0 / nus * 2 * np.pi
size = [20, 1, 4] # Size of the sample. 4 is the diamter of the cylinder(z)
# size = [10, 10, 0.1] # Size of the sample. 4 is the diamter of the cylinder(z)
coefs = [100, 1]
resolution = 8
result_cw = scattervol_path + "volume.cw"
norm = plt.Normalize()
for lambdai in tqdm(range(len(lambdas))):
print("")
print("----------"+ str(lambdai+1) + "th loop-------------")
print("wavelength:" + str(lambdas[lambdai]))
start = time.time()
subprocess.run([scattervol_path+"scattervolume", "--sample", source_path+sample_name, "--size", str(size[0]), str(size[1]), str(size[2]),
"--coef", str(coefs[0]), str(coefs[1]), "--lambda", str(lambdas[lambdai]), "--output", result_cw], shell=False, capture_output=True)
mid = time.time()
print("Simulation for this loop: " + str(mid-start) + "s.")
subprocess.run([scattervol_path+"scatterviewsample", "--input", result_cw, "--nogui", "--extent", str(size[0]), "--output",
result_npy, "--axis", str(save_axis), "--slice", str(2**(resolution-1)), "--resolution", str(resolution)], shell=False, capture_output=True)
# subprocess.run([scattervol_path+"scatterview", "--input", result_cw, "--size", str(size[0]),
# "--nogui", "--resolution", str(resolution), "--output", result_npy, "--axis", str(save_axis),
# "--center", str(size[0]/2), str(size[0]/2), str(0), "--slice", str(relative_slice)], shell=True, capture_output=False)
end = time.time()
print("Visualization for this loop: " + str(end-mid) + "s.")
xz = np.load(result_npy)
Ey = np.real(xz[:, :, 1])
colors = plt.cm.RdYlBu_r(norm(Ey))[:, :, 0:3]
ski.io.imsave(data_path+"Ey_" + str(lambdai).zfill(3) + ".jpg", colors)
intensity = np.real(xz[:, :, 0] * np.conj(xz[:, :, 0]) + xz[:, :, 1] * np.conj(xz[:, :, 1]) + xz[:, :, 2] * np.conj(xz[:, :, 2]))
colors = plt.cm.magma(norm(intensity))[:, :, 0:3]
ski.io.imsave(data_path+"intensity_" + str(lambdai).zfill(3) + ".jpg", colors)
# subprocess.run("ffmpeg", "-i" "D:\\myGit\\build\\scatter_bld_winter\\lambdas\\*.png", "-o", 'video.mp4') \
# .run())
stream = ffmpeg.input(data_path + "Ey_%03d.jpg", framerate=7)
stream = ffmpeg.output(stream, data_path + "Ey.mp4")
try:
ffmpeg.run(stream, capture_stdout=True, capture_stderr=True, quiet=True, overwrite_output=True)
except ffmpeg.Error as e:
print('stdout:', e.stdout.decode('utf8'))
print('stderr:', e.stderr.decode('utf8'))
raise e
stream = ffmpeg.input(data_path + "intensity_%03d.jpg", framerate=7)
stream = ffmpeg.output(stream, data_path + "intensity.mp4")
try:
ffmpeg.run(stream, capture_stdout=True, capture_stderr=True, quiet=True, overwrite_output=True)
except ffmpeg.Error as e:
print('stdout:', e.stdout.decode('utf8'))
print('stderr:', e.stderr.decode('utf8'))
raise e
#out, err = (ffmpeg.input(data_path + "*.jpg", pattern_type='glob', framerate=25).output(data_path+"video.mp4") \
# .run())
#print(err)
a = 1