@@ -28,6 +28,7 @@ def error_adaptive_iterative_fit_spectra(
28
28
29
29
from TRANK import (fit_spectra_nk_sqr , fit_spectra_nk_sqr_KK_compliant ,
30
30
rms_error_spectrum , reducible_rms_error_spectrum , nk_plot , error_plot , try_mkdir )
31
+ from TRANK import compute_coarse_and_fine_grid
31
32
from time import time
32
33
from numpy import floor , log2 , ceil , linspace , diff , sqrt , mean , array , savetxt , percentile , argsort
33
34
from copy import deepcopy
@@ -37,7 +38,6 @@ def error_adaptive_iterative_fit_spectra(
37
38
from matplotlib .pylab import show
38
39
39
40
if reuse_mode == False : #picks lambda points accordingly
40
- from TRANK import compute_coarse_and_fine_grid
41
41
lamda_list , lamda_fine = compute_coarse_and_fine_grid (dlamda_max , dlamda_min , lamda_max , lamda_min )
42
42
dlamda_min = lamda_fine [1 ]- lamda_fine [0 ]
43
43
dlamda_max = lamda_list [1 ]- lamda_list [0 ]
@@ -51,19 +51,14 @@ def error_adaptive_iterative_fit_spectra(
51
51
52
52
53
53
else :
54
-
54
+ lamda_coarse , lamda_fine = compute_coarse_and_fine_grid ( dlamda_max , dlamda_min , lamda_max , lamda_min )
55
55
# Determines the fine grid based on the smallest delta lambda you have
56
56
dlamda_min_found = min (diff (lamda_list ))
57
57
power_of_2 = int (round ( log2 (dlamda_min_found / dlamda_min ) ))
58
58
#print( log2(dlamda_min_found/dlamda_min) )
59
- dlamda_min = dlamda_min_found / (2 ** power_of_2 ) # finds power of two spacing to match your dlamda_min
60
-
61
- ### use what we find
62
- dlamda_max = dlamda_max_found = max (diff (lamda_list ))
63
-
64
- nfine = ceil ((lamda_max - lamda_min )/ dlamda_min )
65
- lamda_fine = linspace (lamda_min , lamda_max , nfine + 1 )
66
- #print ('lamda_fine', lamda_fine)
59
+ if False : # in the past it made sense to retrive the dlamda_min and max from data
60
+ dlamda_min = dlamda_min_found / (2 ** power_of_2 ) # finds power of two spacing to match your dlamda_min
61
+ dlamda_max = dlamda_max_found = max (diff (lamda_list ))
67
62
68
63
if max_passes == 0 :
69
64
# this part guesses how many passes are required to reach the finest grid level
@@ -172,7 +167,7 @@ def error_adaptive_iterative_fit_spectra(
172
167
adaptation_threshold_max = adaptation_threshold_max ,
173
168
reducible_error_spectrum = reducible_error_spectrum ,
174
169
file_name = data_directory + rms_spectrum_file_format % pass_number ,
175
- title_string = 'Pass %i: Net RMS Error = %.3f %%' % ( pass_number , net_rms * 100 ),
170
+ title_string = 'Pass %i\n Non-Uniform RMS Error = %.3f %% \n Uniform Fine RMS Error = %.3f %%' % ( pass_number , net_rms * 100 , net_rms_fine * 100 ),
176
171
show_plots = show_plots )
177
172
178
173
nk_fig = nk_plot (lamda_list = lamda_list , lamda_fine = lamda_fine , nkf = fit_nk_f ,
@@ -189,7 +184,7 @@ def error_adaptive_iterative_fit_spectra(
189
184
adaptation_spectrum = rms_spectrum
190
185
191
186
192
- refinement_method = 'interpolate_and_check_all '
187
+ refinement_method = 'near_worst '
193
188
#### with our adaptation selection method set, we find new points
194
189
if refinement_method == 'near_worst' :
195
190
new_lamda_list = []
@@ -231,9 +226,17 @@ def error_adaptive_iterative_fit_spectra(
231
226
if ( (num_new_points + len (lamda_list )) > max_points ):
232
227
n_delete = num_new_points + len (lamda_list ) - max_points
233
228
sorted_indices = argsort (adaptation_spectrum )
229
+ ### remove edge indices
234
230
sorted_indices_without_edge_values = list (sorted_indices )
235
231
sorted_indices_without_edge_values .remove (0 )
236
232
sorted_indices_without_edge_values .remove (len (adaptation_spectrum )- 1 )
233
+
234
+ # now we remove any that would make a gap that is too large
235
+ for index_index in range (len (sorted_indices_without_edge_values )- 1 ,- 1 ,- 1 ):
236
+ index_to_check = sorted_indices_without_edge_values [index_index ]
237
+ if (lamda_list [index_to_check + 1 ] - lamda_list [index_to_check - 1 ]) > dlamda_max :
238
+ del sorted_indices_without_edge_values [index_index ] # we can't consider it, would make a large gap
239
+
237
240
indicies_to_delete = sorted_indices_without_edge_values [0 :n_delete ]
238
241
indicies_to_delete .sort (reverse = True )
239
242
0 commit comments