From 976feb1ad091b64dd58493c0b6c093e775f9887f Mon Sep 17 00:00:00 2001 From: hiwamoto Date: Wed, 20 Sep 2023 13:28:55 +0900 Subject: [PATCH] Change in operation to remove headers in computed data files. [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. --- src/py2dmat/solver/lib_make_convolution.py | 87 +------------------ .../solver/sim_trhepd_rheed_mb_connect.py | 39 ++++++++- 2 files changed, 39 insertions(+), 87 deletions(-) diff --git a/src/py2dmat/solver/lib_make_convolution.py b/src/py2dmat/solver/lib_make_convolution.py index 379e6a28..ae05e16a 100644 --- a/src/py2dmat/solver/lib_make_convolution.py +++ b/src/py2dmat/solver/lib_make_convolution.py @@ -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: @@ -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") diff --git a/src/py2dmat/solver/sim_trhepd_rheed_mb_connect.py b/src/py2dmat/solver/sim_trhepd_rheed_mb_connect.py index 56c986c9..33bf6afc 100644 --- a/src/py2dmat/solver/sim_trhepd_rheed_mb_connect.py +++ b/src/py2dmat/solver/sim_trhepd_rheed_mb_connect.py @@ -736,6 +736,43 @@ 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 @@ -743,7 +780,7 @@ def _calc_I_from_file(self): 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 = []