Ejemplo n.º 1
0
 def __init__(self, ui_values):
     super().__init__()
     self.ui_values = ui_values
     self.single_wp_settings = self.set_single_wp_settings()
     self.erf_setup = ErfSetup(self.single_wp_settings)
     self.single_wp_result = self.make_single_wp_result()
     self.single_wp_plotter = self.setup_plotter()
Ejemplo n.º 2
0
def no_optimization(settings, new_values, queue):
    angles = np.deg2rad(np.array(new_values[DictKeys().angle_input_key]))
    widths = np.array(new_values[DictKeys().widths_input_key]) * um
    stripes = np.array(new_values[DictKeys().stripes_input_key]) * um

    new_erf_setup = ErfSetup(settings)

    x0 = np.array([*angles, *widths, *stripes]).flatten()
    f = new_erf_setup.erf(x0)
    output = Output(f, angles, widths, stripes, 'Single run', 1, 1, 1, 1)
    output.new_best = True
    queue.put(output)
Ejemplo n.º 3
0
def make_discrete_bruteforce_optimizer(**kwargs):
    settings = kwargs['settings']
    queue = kwargs['queue']

    new_dbo = DBO(settings, queue)
    combinations = new_dbo.get_combinations()
    # return if job is complete
    if not combinations:
        return

    for i, combination in enumerate(combinations):
        progress = {
            'task_cnt': i + 1,
            'total_task_cnt': len(combinations),
            'cur_combination': combination,
            'best_f': new_dbo.best_f
        }
        new_dbo.job_progress_output(progress)
        new_dbo.settings[new_dbo.const_widths_key] = combination
        erf_setup = ErfSetup(new_dbo.settings)
        new_optimizer = OptimizerSetup(erf_setup, settings, queue)
        new_optimizer.custom_callback = new_dbo.callback
        opt_res = new_optimizer.start_optimization()

        new_dbo.on_task_completion(combination, opt_res)
Ejemplo n.º 4
0
def make_optimizer(**kwargs):
    settings = kwargs['settings']
    queue = kwargs['queue']

    erf_setup = ErfSetup(settings)
    settings[DictKeys().process_name_key] = mp.current_process().name
    new_optimizer = OptimizerSetup(erf_setup, settings, queue)
    new_optimizer.start_optimization()
Ejemplo n.º 5
0
    def add_task_info(self):
        erf_setup = ErfSetup(self.settings)
        n, m = erf_setup.wp_cnt, erf_setup.freq_cnt

        self.task_info = {
            'freq_cnt': m,
            'wp_cnt': n,
            'opt_params': len(erf_setup.x0)
        }
Ejemplo n.º 6
0
    def set_selected_result(self, ui_values_dict):
        self.selected_result = Result(ui_values_dict)
        self.selected_result.erf_setup = ErfSetup(self.selected_result.result_settings)

        # calculate stuff that's required everytime a result is selected
        refractive_indices = self.selected_result.erf_setup.setup_ri(self.selected_result.stripes)
        self.selected_result.calculated_values['refractive_indices'] = refractive_indices

        m_matrix_stack = make_m_matrix_stack(self.selected_result.erf_setup, refractive_indices,
                                             self.selected_result.get_values())
        self.selected_result.calculated_values['m_matrix_stack'] = m_matrix_stack

        j_matrix_stack = make_j_matrix_stack(self.selected_result.erf_setup, refractive_indices,
                                             self.selected_result.get_values())
        self.selected_result.calculated_values['j_matrix_stack'] = j_matrix_stack

        if ui_values_dict[self.calculation_method_key] in 'Stokes':
            self.selected_result.calculated_values['intensities'] = calc_final_stokes_intensities(m_matrix_stack)
        else:
            self.selected_result.calculated_values['intensities'] = calc_final_jones_intensities(j_matrix_stack)

        self.selected_result.calculated_values['phase shift'] = calc_phase_shift(j_matrix_stack)

        self.result_selected = True
Ejemplo n.º 7
0
        return (t_max_angle and t_min_angle) and (
            t_min_width and t_max_width) and (t_min_stripe and t_max_stripe)


if __name__ == '__main__':
    from modules.settings.settings import Settings
    from erf_setup_v21 import ErfSetup
    import time
    from modules.identifiers.dict_keys import DictKeys

    settings_path = 'modules/results/archived/14-10-2020/18-24-27_OptimizationProcess-1/settings.json'
    settings_module = Settings()
    settings = settings_module.load_settings(settings_path)
    settings[DictKeys().calculation_method_key] = 'Jones'
    erf_setup = ErfSetup(settings)

    erf = erf_setup.erf

    iterations = 500

    np.seterr(all='ignore')
    x0 = np.ones(12) * 10**-6
    start_time = time.time()

    func = lambda x: np.sum(x**2)

    res = basinhopping(erf, x0, niter=iterations)
    print(res.x)
    total = time.time() - start_time
Ejemplo n.º 8
0
cst_path = r'/home/alex/Desktop/Projects/SimsV2_1/modules/cst/cst_results/SLE_l2_sent2hermans/SLE_l2_sent2hermans_4eck.txt'
cst_path = r'/home/alex/Desktop/Projects/SimsV2_1/modules/cst/cst_results/SLE_l2_sent2hermans/SLE_l2_sent2hermans_4eck_lowres.txt'
settings_module = Settings()
erf_settings = settings_module.load_settings(base_path / 'settings.json')

erf_settings[keys.frequency_resolution_multiplier_key] = 1
erf_settings[keys.min_freq_key] = 0.4
erf_settings[keys.max_freq_key] = 2.0
erf_settings[keys.weak_absorption_checkbox_key] = False
erf_settings[keys.calculation_method_key] = 'Jones'
erf_settings[keys.anisotropy_p_key] = 1
erf_settings[keys.anisotropy_s_key] = 1
erf_settings[keys.const_widths_key] = [0] * int(erf_settings[keys.wp_cnt_key])
erf_settings[keys.x_slicing_key] = [[0, 5], [5, 10], [10, 20]]

erf_setup = ErfSetup(erf_settings)
angles = np.load(base_path / 'angles.npy')
widths = np.load(base_path / 'widths.npy')
stripes = np.load(base_path / 'stripes.npy')

x = np.concatenate((angles, widths, stripes))

j_stack = erf_setup.get_j_stack(x)

intensity_x = calc_final_jones_intensities(j_stack)[0]
intensity_y = calc_final_jones_intensities(j_stack)[1]

erf_freqs = erf_setup.frequencies

cst_data_reader = CSTData(cst_path)
cst_freqs = cst_data_reader.f_s_parameters * 10**12
Ejemplo n.º 9
0
class SingleWaveplate(DictKeys):
    def __init__(self, ui_values):
        super().__init__()
        self.ui_values = ui_values
        self.single_wp_settings = self.set_single_wp_settings()
        self.erf_setup = ErfSetup(self.single_wp_settings)
        self.single_wp_result = self.make_single_wp_result()
        self.single_wp_plotter = self.setup_plotter()

    def set_single_wp_settings(self):
        single_wp_settings = self.ui_values.copy()
        single_wp_settings[self.wp_cnt_key] = 1
        single_wp_settings[self.const_angles_key] = [0]
        single_wp_settings[self.const_widths_key] = [0]
        single_wp_settings[self.width_pattern_key] = [1]
        single_wp_settings[self.x_slicing_key] = [[0, 1], [1, 2], [2, 4]]

        return single_wp_settings

    def make_single_wp_result(self):
        single_wp_result = Result()
        single_wp_result.erf_setup = self.erf_setup

        return single_wp_result

    def setup_plotter(self):
        single_wp_plotter = Plot()
        single_wp_plotter.result = self.single_wp_result
        single_wp_plotter.result.name = ''

        return single_wp_plotter

    def calculate_refractive_indices(self):
        stripe_width_mat1 = np.array(self.single_wp_settings[
            self.single_wp_stripe1_width_input_key]) * um
        stripe_width_mat2 = np.array(self.single_wp_settings[
            self.single_wp_stripe2_width_input_key]) * um
        refractive_indices = self.erf_setup.setup_ri(
            (stripe_width_mat1, stripe_width_mat2))

        return refractive_indices

    def calculate_intensities(self):
        refractive_indices = self.calculate_refractive_indices()
        angle = np.deg2rad(
            self.single_wp_settings[self.single_wp_angle_input_key])
        width = np.array(
            self.single_wp_settings[self.single_wp_width_input_key]) * um
        values = (angle, width, None)
        if self.single_wp_settings[self.calculation_method_key] in 'Stokes':
            m_matrix_stack = make_m_matrix_stack(self.erf_setup,
                                                 refractive_indices, values)
            int_x, int_y = calc_final_stokes_intensities(m_matrix_stack)
        else:
            j_matrix_stack = make_j_matrix_stack(self.erf_setup,
                                                 refractive_indices, values)
            int_x, int_y = calc_final_jones_intensities(j_matrix_stack)

        if self.ui_values[self.add_simple_transmission_checkbox_key]:
            db_transmission_coeff = 10 * np.log10(
                simple_transmission_coeff(self.erf_setup.eps_mat1))
        else:
            db_transmission_coeff = 10 * np.log10(
                np.ones_like(self.erf_setup.eps_mat1))

        db_transmission_coeff = db_transmission_coeff.reshape(int_x.shape)

        return db_transmission_coeff + int_x, db_transmission_coeff + int_y

    def calculate_zeroth_order_width(self, freq):
        refractive_indices = self.calculate_refractive_indices()
        f_index = np.argmin(np.abs(self.erf_setup.frequencies - freq))
        bf = np.float(
            np.abs(refractive_indices[0] - refractive_indices[1])[f_index])

        d_l2, d_l4 = c / (2 * freq * bf), c / (4 * freq * bf)
        return d_l2, d_l4

    def single_wp_refractive_indices_plot(self):
        n_s, n_p, k_s, k_p = self.calculate_refractive_indices()
        if self.ui_values[self.single_wp_plot_ns_checkbox_key]:
            self.single_wp_plotter.simple_plot(
                n_s,
                legend_label='n_s',
                fig_title='Single wp refractive indices')
        if self.ui_values[self.single_wp_plot_np_checkbox_key]:
            self.single_wp_plotter.simple_plot(
                n_p,
                legend_label='n_p',
                fig_title='Single wp refractive indices')
        if self.ui_values[self.single_wp_plot_ks_checkbox_key]:
            self.single_wp_plotter.simple_plot(
                k_s,
                legend_label='k_s',
                fig_title='Single wp refractive indices')
        if self.ui_values[self.single_wp_plot_kp_checkbox_key]:
            self.single_wp_plotter.simple_plot(
                k_p,
                legend_label='k_p',
                fig_title='Single wp refractive indices')

    def single_wp_intensity_plot(self):
        int_x, int_y = self.calculate_intensities()
        self.single_wp_plotter.simple_plot(
            int_x,
            legend_label='Int. after x polarizer',
            fig_title='Single wp intensities',
            y_label='Intensity (dB)')
        self.single_wp_plotter.simple_plot(
            int_y,
            legend_label='Int. after y polarizer',
            fig_title='Single wp intensities',
            y_label='Intensity (dB)')
Ejemplo n.º 10
0
from erf_setup_v21 import ErfSetup
from modules.identifiers.dict_keys import DictKeys
keys = DictKeys()

dir_path = Path(
    r'/home/alex/Desktop/Projects/SimsV2_1/modules/results/saved_results/SLE_l2_longrun_restarts/l2_200GHz_14-05-27_Thread-2'
)

settings_dict = Settings().load_settings(dir_path / 'settings.json')
print(settings_dict[keys.selected_material_data_path_key])
settings_dict[keys.weak_absorption_checkbox_key] = False
settings_dict[keys.calculation_method_key] = 'Jones'
settings_dict[keys.anisotropy_p_key] = 1
settings_dict[keys.anisotropy_s_key] = 1

erf_setup = ErfSetup(settings_dict)
erf = erf_setup.erf

angles_ = np.load(dir_path / 'angles.npy')
d_ = np.load(dir_path / 'widths.npy')
stripes_ = np.load(dir_path / 'stripes.npy')
stripes_ = np.array([0.000055, 0.0000205])

best_s0, best_s1 = 0, 0
best_bf = 0
for s0 in np.linspace(10, 80, 100):
    print(s0)
    for s1 in np.linspace(10, 80, 100):
        max_f = c / (2 * (s1 + s0) * um)
        max_f_range = np.where(max_f > erf_setup.frequencies)
        stripes_ = np.array([s0, s1]) * um
Ejemplo n.º 11
0
import itertools
from erf_setup_v21 import ErfSetup
from modules.utils.constants import *
import matplotlib.pyplot as plt

d_lst = np.array([520, 515, 495, 330, 310, 830, 635, 320])

from modules.settings.settings import Settings

path = '/home/alex/Desktop/Projects/SimsV2_1/modules/results/saved_results/fp_results_quartz_l4/fp_quartz_l4_12-27-02_Thread-3/settings.json'
settings_dict = Settings().load_settings(path)
erf_setup = ErfSetup(settings_dict)
erf = erf_setup.erf

angles = np.deg2rad([116.1, 236.6, 215.4, 195.0, 187.2])
d = np.array([290.0, 390.0, 430.0, 470.0, 500.0]) * um
stripes = np.array([49.0, 42.0]) * um

x0 = np.concatenate((angles, d, stripes))

frequencies = erf_setup.frequencies * Hz_to_THz
res0 = erf(x0)
int_x0, int_y0 = erf_setup.int_x, erf_setup.int_y
print(d)
print(res0)
print()
best_val = np.inf
best_combo = None
index_of_best = None
combinations = list(itertools.combinations(d_lst, 5))
for i, combination in enumerate(combinations):