Skip to content

Commit f0bda26

Browse files
committed
The iterator can now return drude_parameters so tha thickness fitting can reuse them.
1 parent 7121e6b commit f0bda26

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed

examples/example_1_TMM_and_back/1_tmm_film_on_substrate.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
make_plots = True
88
tmm_spectra_dir = 'tmm_predicted_spectra/'
99

10-
noise = 0.5/100.0
10+
noise = 2.0/100.0
1111

1212
dlamda_min = 1
1313
lamda_min = 300

examples/example_1_TMM_and_back/2_TRANK_fit_spectra.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def fit_nk_f(lamda):
9292
dlamda_min = dlamda_min,
9393
dlamda_max = dlamda_max,
9494
delta_weight = 0.1, tolerance = 1e-5, interpolation_type = 'cubic',
95-
adaptation_threshold_max = 0.01, adaptation_threshold_min = 0.002,
95+
adaptation_threshold_max = 0.01, adaptation_threshold_min = 0.2/100,
9696
use_reducible_error = True,
9797
method='least_squares',
9898
KK_compliant = False,

examples/example_1_TMM_and_back/basic_setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def nk_f_air(lamda):
5656
######
5757
# this ugly hack only defines the TR_pair_list_generator if the data actually exists
5858
from os.path import isfile
59-
if isfile(tmm_spectra_dir+ '%i_deg_spectra.txt'%angle_list[0]):
59+
if isfile(tmm_spectra_dir+ '%i_deg_spectra.txt'%angle_list[1]):
6060

6161
spectrum_function_list = []
6262

iterator.py

+14-9
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ def error_adaptive_iterative_fit_spectra(
1717
reuse_mode = False,
1818
KK_compliant = False,
1919
use_free_drude = False,
20+
return_drude_params = False,
21+
sigma_bar0_guess = 0.0, lamda_tau_guess = 0.0, epsilon_f1p_guess = 0.0,
2022
interpolation_type = 'cubic',
2123
no_negative = True,
2224
interpolate_to_fine_grid_at_end = True,
@@ -77,7 +79,7 @@ def error_adaptive_iterative_fit_spectra(
7779
print ('dlamda_max: ' ,dlamda_max )
7880
print ('dlamda_min: ', dlamda_min )
7981
print ('delta_weight:', delta_weight)
80-
lamda_tau, sigma_bar0, epsilon_f1p = 0.0, 0.0, 0.0
82+
lamda_tau, sigma_bar0, epsilon_f1p = lamda_tau_guess, sigma_bar0_guess, epsilon_f1p_guess
8183

8284
# literally jury rigging the conidtion so it starts the loop, ugly, but cleaner than the alternatives
8385
num_new_points = len(lamda_list)
@@ -120,7 +122,7 @@ def error_adaptive_iterative_fit_spectra(
120122
# now we use the inputs
121123
t0 = time()
122124
if use_free_drude:
123-
inputs.update(dict( sigma_bar0_guess = sigma_bar0, lamda_tau_guess = lamda_tau, epsilon_f1p_guess = epsilon_f1p))
125+
inputs.update(dict( sigma_bar0_guess = sigma_bar0, lamda_tau_guess = lamda_tau, epsilon_f1p_guess = epsilon_f1p))
124126
fit_nk_f, lamda_tau, sigma_bar0, epsilon_f1p = fit_spectra_nk_sqr_drude_KK_compliant(**inputs)
125127
else:
126128
if KK_compliant:
@@ -284,8 +286,10 @@ def error_adaptive_iterative_fit_spectra(
284286
parameter_list_generator = parameter_list_generator, threads = threads)
285287
savetxt(data_directory+'fit_nk_fine.txt',array([lamda_fine, nk.real, nk.imag, array(rms_spectrum_fine)*100.0, array(reducible_error_spectrum_fine)*100.0 ]).T)
286288

287-
288-
return fit_nk_f, lamda_list
289+
if use_free_drude and return_drude_params:
290+
return fit_nk_f, lamda_list, lamda_tau, sigma_bar0, epsilon_f1p
291+
else:
292+
return fit_nk_f, lamda_list
289293

290294

291295

@@ -305,6 +309,7 @@ def scan_for_scaled_weight_crossover(
305309
use_free_drude = False,
306310
interpolation_type = 'cubic',
307311
no_negative = False,
312+
target_ratio = 1.0,
308313
threads = 0,
309314
data_directory ='TRANK_weight_scan/', method = 'least_squares', verbose = True, write_to_file = True,
310315
make_plots = True, show_plots = False, rms_file_format = 'rms_vs_weight.pdf' ):
@@ -382,13 +387,13 @@ def RMS(a):
382387
print('--> reducible/irreducible ratio %f' % (ratio))
383388

384389
if len(log_data) > 1:
385-
if log_data[-1][4] < 1.0 and log_data[-2][4] > 1.0: # decreasing case
390+
if log_data[-1][4] < target_ratio and log_data[-2][4] > target_ratio: # decreasing case
386391
cross_over_found = True
387-
if log_data[-1][4] > 1.0 and log_data[-2][4] < 1.0: # increasing case
392+
if log_data[-1][4] > target_ratio and log_data[-2][4] < target_ratio: # increasing case
388393
cross_over_found = True
389394

390395
if cross_over_found == False: # actually don't need to do this check, but now we only update if we are still searching
391-
if ratio > 1.0:
396+
if ratio > target_ratio:
392397
scaled_weight = scaled_weight* step_multiplier
393398
else:
394399
scaled_weight = scaled_weight/ step_multiplier
@@ -401,7 +406,7 @@ def RMS(a):
401406
scaled_weight_data = log_data[0]
402407
#simple linear interpolation is fast, and we dont have to worry about https://en.wikipedia.org/wiki/Runge%27s_phenomenon
403408
ratio_slope = ( ratio_data[-1] - ratio_data[-2] )/ (scaled_weight_data[-1] - scaled_weight_data[-2])
404-
scaled_weight_crossover = ( 1 - ratio_data[-2]) / ratio_slope + scaled_weight_data[-2]
409+
scaled_weight_crossover = ( target_ratio - ratio_data[-2]) / ratio_slope + scaled_weight_data[-2]
405410

406411

407412

@@ -419,7 +424,7 @@ def RMS(a):
419424

420425
figure()
421426
plot(scaled_weight_data,ratio_data , marker = 'o' )
422-
plot([scaled_weight_crossover],[1], marker = '+', label = 'scaled_weight_crossover')
427+
plot([scaled_weight_crossover],[target_ratio], marker = '+', label = 'scaled_weight_crossover')
423428
xlabel('scaled_weight')
424429
ylabel('reducible error:irreducible error ratio')
425430
legend()

0 commit comments

Comments
 (0)