<commit_before># -*- coding: utf-8 -*-
from .helpers.waveguide import check_point as check_point_core
from .helpers.waveguide_shell import check_point as check_point_shell
from .helpers.output import output_array_to_file, output_sig_eps_png

import argparse
import math
import os


def write_eps(x_0, y_0, length, d, alpha, size_x, size_y, n_core, base_path):
    eps = []
    print('Start processing epsilon')
    for y in range(size_y):
        print('Processing [{}/{}]'.format(y, size_y - 1), end="\r")
        for x in range(size_x):
            if check_point_core(x - x_0, y - y_0, d, length, alpha):
                eps.append(n_core)
            else:
                eps.append(1)
    print('Finish processing epsilon')
    output_array_to_file(eps, base_path + '/epsilon.txt', size_x)
    return eps


def write_sig(x_0, y_0, length, d, d_shell, size_x, size_y, sig_shell, base_path):
    sig = []
    print('Start processing sigma')
    for y in range(size_y):
        print('Processing [{}/{}]'.format(y, size_y - 1), end="\r")
        for x in range(size_x):
            if check_point_shell(x - x_0, y - y_0, d, d_shell, length):
                sig.append(sig_shell)
            else:
                sig.append(0)
    print('Finish processing sigma')
    output_array_to_file(sig, base_path + '/sigma.txt', size_x)
    return sig


def write(lam_px, n_core, sig_shell, d_over_lam, alpha, num, sim_type):
    length = int(30 * lam_px)
    if alpha <= math.pi * 0.99:
        length = int(30 * lam_px + d_over_lam / 2 * math.tan(alpha / 2))
    d_shell = int(d_over_lam * lam_px + 2 * lam_px)
    size_x = int(30 * lam_px + length)
    size_y = int(10 * lam_px + d_shell)
    x_0 = int(10 * lam_px)
    y_0 = int(size_y / 2)
    base_path = './cone_v1_d={d_over_lam}_a={alpha_deg}_lam={lam_px}_n={n_core}_sig={sig_shell}'.format(
        d_over_lam=d_over_lam,
        alpha_deg=int(alpha),
        lam_px=lam_px,
        n_core=n_core,
        sig_shell=sig_shell
    )
    alpha = float(alpha) / 180.0 * math.pi
    if not os.path.exists(base_path):
        os.makedirs(base_path)
    eps  = write_eps(x_0, y_0, length, d_over_lam * lam_px, alpha, size_x, size_y, n_core, base_path)
    sig = write_sig(x_0, y_0, length, d_over_lam * lam_px, d_shell, size_x, size_y, sig_shell, base_path)
    write_conf(sim_type, x_0 - 10 * lam_px, y_0, lam_px, size_x, size_y, num, base_path)
    output_sig_eps_png(eps, sig, base_path + "/world", sig_shell, size_x, size_y)

def write_conf(sim_type, x_source, y_source, lam_px, size_x, size_y, num, base_path):
    i_big_out_first_x = 0
    i_big_out_last_x = size_x
    i_big_step = 5
    i_big_out_first_y = 0
    i_big_out_last_y = size_y

    start_time = 0
    end_time = num
    step_time = int(lam_px * math.sqrt(2))

    i_small_out_first_x = 0
    i_small_out_last_x = size_x
    i_small_step = 1
    i_small_out_first_y = 0
    i_small_out_last_y = size_y

    conf = '''SimulationType: {type}
Grid{type}: {size_x} {size_y}
Epsilon: epsilon.txt<commit_msg>fix period bug<commit_after># -*- coding: utf-8 -*-
from .helpers.waveguide import check_point as check_point_core
from .helpers.waveguide_shell import check_point as check_point_shell
from .helpers.output import output_array_to_file, output_sig_eps_png

import argparse
import math
import os


def write_eps(x_0, y_0, length, d, alpha, size_x, size_y, n_core, base_path):
    eps = []
    print('Start processing epsilon')
    for y in range(size_y):
        print('Processing [{}/{}]'.format(y, size_y - 1), end="\r")
        for x in range(size_x):
            if check_point_core(x - x_0, y - y_0, d, length, alpha):
                eps.append(n_core)
            else:
                eps.append(1)
    print('Finish processing epsilon')
    output_array_to_file(eps, base_path + '/epsilon.txt', size_x)
    return eps


def write_sig(x_0, y_0, length, d, d_shell, size_x, size_y, sig_shell, base_path):
    sig = []
    print('Start processing sigma')
    for y in range(size_y):
        print('Processing [{}/{}]'.format(y, size_y - 1), end="\r")
        for x in range(size_x):
            if check_point_shell(x - x_0, y - y_0, d, d_shell, length):
                sig.append(sig_shell)
            else:
                sig.append(0)
    print('Finish processing sigma')
    output_array_to_file(sig, base_path + '/sigma.txt', size_x)
    return sig


def write(lam_px, n_core, sig_shell, d_over_lam, alpha, num, sim_type):
    length = int(30 * lam_px)
    if alpha <= math.pi * 0.99:
        length = int(30 * lam_px + d_over_lam / 2 * math.tan(alpha / 2))
    d_shell = int(d_over_lam * lam_px + 2 * lam_px)
    size_x = int(30 * lam_px + length)
    size_y = int(10 * lam_px + d_shell)
    x_0 = int(10 * lam_px)
    y_0 = int(size_y / 2)
    base_path = './cone_v1_d={d_over_lam}_a={alpha_deg}_lam={lam_px}_n={n_core}_sig={sig_shell}'.format(
        d_over_lam=d_over_lam,
        alpha_deg=int(alpha),
        lam_px=lam_px,
        n_core=n_core,
        sig_shell=sig_shell
    )
    alpha = float(alpha) / 180.0 * math.pi
    if not os.path.exists(base_path):
        os.makedirs(base_path)
    eps  = write_eps(x_0, y_0, length, d_over_lam * lam_px, alpha, size_x, size_y, n_core, base_path)
    sig = write_sig(x_0, y_0, length, d_over_lam * lam_px, d_shell, size_x, size_y, sig_shell, base_path)
    write_conf(sim_type, x_0 - 10 * lam_px, y_0, lam_px, size_x, size_y, num, base_path)
    output_sig_eps_png(eps, sig, base_path + "/world", sig_shell, size_x, size_y)

def write_conf(sim_type, x_source, y_source, lam_px, size_x, size_y, num, base_path):
    i_big_out_first_x = 0
    i_big_out_last_x = size_x
    i_big_step = 5
    i_big_out_first_y = 0
    i_big_out_last_y = size_y

    start_time = 0
    end_time = num
    step_time = int(lam_px * math.sqrt(2) * 2)

    i_small_out_first_x = 0
    i_small_out_last_x = size_x
    i_small_step = 1
    i_small_out_first_y = 0
    i_small_out_last_y = size_y

    conf = '''SimulationType: {type}
Grid{type}: {size_x} {size_y}
Epsilon: epsilon.txt
{'fraction_non_alphanumeric': 0.11964256164156875, 'fraction_numerical': 0.01770643720006619, 'mean_word_length': 3.021290751829674, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2241168', 'n_tokens_mistral': 2479, 'n_tokens_neox': 2361, 'n_words': 520}