ZH: indicate when k-finding find the same ks

This commit is contained in:
Eric Teunis de Boone 2023-01-11 02:18:36 +01:00
parent 0447df4f43
commit d5d1686a6b

View file

@ -11,6 +11,7 @@ from itertools import combinations, zip_longest, product
import matplotlib.pyplot as plt
import numpy as np
from os import path
import os
from scipy.interpolate import interp1d
from earsim import REvent
@ -165,6 +166,11 @@ if __name__ == "__main__":
antennas_fname = path.join(fname_dir, beacon.antennas_fname)
time_diffs_fname = 'time_diffs.hdf5' if not True else antennas_fname
## This is a file indicating whether the k-finding algorithm was
## stopped early. This happens when the ks do not change between
## two consecutive iterations.
run_break_fname = path.join(fname_dir, 'ca_breaked_run')
# create fig_dir
if fig_dir:
os.makedirs(fig_dir, exist_ok=True)
@ -267,6 +273,11 @@ if __name__ == "__main__":
x_fine = np.linspace(-scale2d, scale2d, 40)
y_fine = np.linspace(-scale2d, scale2d, 40)
## Remove run_break_fname if it exists
try:
os.remove(run_break_fname)
except OSError:
pass
##
## Do calculations on the grid
@ -377,8 +388,14 @@ if __name__ == "__main__":
# Abort if no improvement
if ( r!= 0 and (old_ks_per_loc == ks_per_loc[best_idx]).all() ):
print("No changes from previous grid, breaking")
# TODO: notate this case somewhere
print("No changes from previous grid, breaking at iteration {r} out of {N_runs}")
try:
with open(run_break_fname, 'wt', encoding='utf-8') as fp:
fp.write(f"Breaked at grid iteration {r} out of {N_runs}")
except:
pass
break
old_ks_per_loc = ks_per_loc[best_idx]