Skip to content

Commit

Permalink
Change in operation to remove headers in computed data files.
Browse files Browse the repository at this point in the history
[before]: Use lib_make_convolution.py to delete headers in the calculated data file and perform the convolution calculation.
[after]: Use sim_trhepd_rheed_mb_connect.py to remove the headers of the calculated data file and lib_make_convolution.py to perform the convolution calculation.
  • Loading branch information
H-Iwamoto-research committed Sep 20, 2023
1 parent 499b10a commit 976feb1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 87 deletions.
87 changes: 1 addition & 86 deletions src/py2dmat/solver/lib_make_convolution.py
Original file line number Diff line number Diff line change
@@ -1,96 +1,15 @@
import numpy as np
import sys

def calc(Clines, omega, verbose_mode):
if verbose_mode:
#print('arg:filename=',args.filename)
print('omega =',omega)
def calc(RC_data_org, RC_data_cnv, number_of_beams, number_of_glancing_angles, omega, verbose_mode):

sigma = 0.5 * omega / (np.sqrt(2.0*np.log(2.0)))

#def g(x):
# g = (0.939437 / omega) * np.exp(-2.77259 * (x ** 2.0 / omega ** 2.0))
# return g
def g(x):
g = (1.0 / (sigma*np.sqrt(2.0*np.pi))) * np.exp(-0.5 * x ** 2.0 / sigma ** 2.0)

return g

# Read the file header
if verbose_mode:
print("debug:lib_make_convolution.py")
print(f"Clines[0:5]=",Clines[0:5])
#print(line)

line = Clines[0]

if line == ' FILE OUTPUT for UNIT3\n':
alpha_lines = 1
else:
alpha_lines = 0

if verbose_mode: print("debug alpha_lines=",alpha_lines)

number_of_lines = int(len(Clines))
number_of_header_lines = 4 + alpha_lines

if verbose_mode:
print("number_of_lines =", number_of_lines)
print("number_of_header_lines =", number_of_header_lines)

#degree_list = []
#C_list = []

#print("file header :", line)
line = Clines[1 + alpha_lines]
#print("file header :", line)
#sys.exit()
line = line.replace(",", "")
data = line.split()

number_of_azimuth_angles = int(data[0])
number_of_glancing_angles = int(data[1])
number_of_beams = int(data[2])

if verbose_mode:
print("number of azimuth angles = ", number_of_azimuth_angles)
print("number of glancing angles = ", number_of_glancing_angles)
print("number of beams = ", number_of_beams)

# Define the array for the rocking curve data.
# Note the components with (beam-index)=0 are the degree data
RC_data_org = np.zeros((number_of_glancing_angles, number_of_beams+1))
RC_data_cnv = np.zeros((number_of_glancing_angles, number_of_beams+1))

# Read the file header
line = Clines[2+ alpha_lines]
#print("file header :", line, end="")
line = Clines[3+ alpha_lines]
#print("file header :", line, end="")
line = line.replace(",", "")
data = line.split()
#print(data)

if verbose_mode:
"""
print("beam index (p,q): i p_i q_i")
for beam_index in range(number_of_beams):
print(beam_index, data[beam_index*2], data[beam_index*2+1])
"""
pass

for g_angle_index in range(number_of_glancing_angles):
line_index = number_of_header_lines + g_angle_index
line = Clines[ line_index ]
# print("data line: ", line_index, g_angle_index, line)
line = line.replace(",", "")
data = line.split()
# print(data)
RC_data_org[g_angle_index,0]=float(data[0])
RC_data_cnv[g_angle_index,0]=float(data[0])
for beam_index in range(number_of_beams):
RC_data_org[g_angle_index, beam_index+1] = data[beam_index+1]

angle_interval = RC_data_org[1,0] - RC_data_org[0,0]

if verbose_mode:
Expand All @@ -107,11 +26,7 @@ def g(x):
print("beam_index, index, index2, g(RC_data_org[index,0] - RC_data_org[index2,0]) =",beam_index, index, index2, g(RC_data_org[index,0] - RC_data_org[index2,0]))
RC_data_cnv[index, beam_index+1]=integral

#np.savetxt("convolution.txt", RC_data_cnv, fmt="%.5e")

if verbose_mode:
print("RC_data_cnv =\n",RC_data_cnv)

return RC_data_cnv

#np.savetxt("original.txt", RC_data_org, fmt="%.5e")
39 changes: 38 additions & 1 deletion src/py2dmat/solver/sim_trhepd_rheed_mb_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,14 +736,51 @@ def _calc_I_from_file(self):
Clines = file_input.readlines()
file_input.close()

# Extract STR results (glancing angle and intensity) from Clines.
# Read the file header
line = Clines[0]

if line == ' FILE OUTPUT for UNIT3\n':
alpha_lines = 1
else:
alpha_lines = 0

number_of_lines = int(len(Clines))
number_of_header_lines = 4 + alpha_lines

line = Clines[1 + alpha_lines]
line = line.replace(",", "")
data = line.split()

number_of_azimuth_angles = int(data[0])
number_of_glancing_angles = int(data[1])
number_of_beams = int(data[2])

# Define the array for the rocking curve data.
# Note the components with (beam-index)=0 are the degree data
RC_data_org = np.zeros((number_of_glancing_angles, number_of_beams+1))
RC_data_cnv = np.zeros((number_of_glancing_angles, number_of_beams+1))

for g_angle_index in range(number_of_glancing_angles):
line_index = number_of_header_lines + g_angle_index
line = Clines[ line_index ]
# print("data line: ", line_index, g_angle_index, line)
line = line.replace(",", "")
data = line.split()
# print(data)
RC_data_org[g_angle_index,0]=float(data[0])
RC_data_cnv[g_angle_index,0]=float(data[0])
for beam_index in range(number_of_beams):
RC_data_org[g_angle_index, beam_index+1] = data[beam_index+1]

if self.log_mode :
time_end = time.perf_counter()
self.detail_timer["load_STR_result"] += time_end - time_sta

if self.log_mode : time_sta = time.perf_counter()
verbose_mode = False
data_convolution = lib_make_convolution.calc(
Clines, self.omega, verbose_mode
RC_data_org, RC_data_cnv, number_of_beams, number_of_glancing_angles, self.omega, verbose_mode
)

self.all_convolution_I_calculated_list_normalized = []
Expand Down

0 comments on commit 976feb1

Please sign in to comment.