From 32b9daafd30c321c15b4a7fd87a07af6c5d27c77 Mon Sep 17 00:00:00 2001 From: szymag Date: Sun, 27 Oct 2019 16:46:40 +0100 Subject: [PATCH 1/2] Implement all methods for data analysis of 1d defectde structure. --- src/interface/Random.yaml | 39 ------ src/interface/Rychly.yaml | 2 +- src/interface/phason.py | 265 +++++++++++++++++++++++++------------- src/interface/random.py | 41 ------ 4 files changed, 179 insertions(+), 168 deletions(-) delete mode 100644 src/interface/Random.yaml delete mode 100644 src/interface/random.py diff --git a/src/interface/Random.yaml b/src/interface/Random.yaml deleted file mode 100644 index f023c76..0000000 --- a/src/interface/Random.yaml +++ /dev/null @@ -1,39 +0,0 @@ -material_parameters: - Co: - Mo: 1.445e6 - l: 3.46e-17 - Py: - Mo: 0.86e6 - l: 2.80e-17 - Fe: - Mo: 1.752e6 - l: 1.09e-17 - Ni: - Mo: 0.484e6 - l: 5.84e-17 - YIG: - Mo: 0.194e6 - l: 1.7e-17 - -numerical_parameters: - fft_file: random_140_9.fft - rec_vector_x: None - rec_vector_y: None - output_file: "idos" - -physical_parameters: - mu0H0: 0.1 - gamma: 176e9 - mu0: 1.2566370614359173e-06 - -system_dimensions: - d: 30e-9 - a: 34307e-9 - b: None - x: 0 - angle: 90 - -q_vector: - start: 0.01 - end: 0.02 - dispersion_count: 1 diff --git a/src/interface/Rychly.yaml b/src/interface/Rychly.yaml index e904119..31b3a91 100644 --- a/src/interface/Rychly.yaml +++ b/src/interface/Rychly.yaml @@ -28,7 +28,7 @@ physical_parameters: system_dimensions: d: 30e-9 - a: 8099e-9 + a: 34307e-9 b: None x: 0 angle: 90 diff --git a/src/interface/phason.py b/src/interface/phason.py index b43419b..4ea3368 100644 --- a/src/interface/phason.py +++ b/src/interface/phason.py @@ -1,26 +1,15 @@ import numpy as np import matplotlib.pyplot as plt from src.fft_from_image.FFT import FFT -from src.fft_from_image.Sequences import Phason, Fibonacci, Periodic +from src.fft_from_image.Sequences import Phason, Fibonacci, Periodic, Random from src.io.DataReader import ParsingData from src.modes.MagnetizationProfile import Profile1D from src.interface.eigen_vector import do_program_1D from src.interface.dispersion import do_program_idos from src.drawing.Plot import Plot from src.utils.cProfiler import do_cprofile - -input_parameters = ParsingData('./src/interface/Rychly.yaml') - -repetition_seq = 10 -fib_number = 14 -green_stripes = 'Py' -gray_stripes = 'Co' -bloch_vec = [1e4, 0] - -samples_count = 100 -phasons = 5 -sample_number = 0 -sequence_type = 'F' +from multiprocessing import Pool +from matplotlib.patches import Rectangle def define_name_phason(phasons_percentage, sample_number, structure_type, path=None): @@ -45,22 +34,36 @@ def save_eig_vector(file_name): fft_file = file_name input_parameters.set_new_value(fft_file + '.fft', 'numerical_parameters', 'fft_file') input_parameters.set_new_value(file_name + '.vec', 'numerical_parameters', 'output_file') - print(input_parameters.output_file('')) + print('fft file: ' +str(fft_file), 'output: ' + str(input_parameters.output_file(''))) do_program_1D(input_parameters, green_stripes, gray_stripes, bloch_vec) -def plot_modes(mode_number, file_name): +def plot_modes(mode_number, file_name, structure_type, freq): plt.rc('xtick', labelsize='xx-large') plt.rc('ytick', labelsize='xx-large') - ax1 = plt.axes() - draw_structure(file_name, ax1) - mode(mode_number, file_name).generate_plot(ax1, 0) - - -def draw_structure(file_name, axis): + fig, axs = plt.subplots(5,figsize=(8, 10.56)) + print(axs) + size = 91*377/5 + for index, i in enumerate(axs): + print(size*index, size*(index+1)) + i.set_xlim(size*index, size*(index+1)) + draw_structure(file_name, i, structure_type) + mode(mode_number, file_name).generate_plot(i, 0) + axs[0].set_title('mode: ' + str(mode_number) + '\n' + +'frequency: ' + str(round(freq/1e9,3)) + ' GHz') + + +def draw_structure(file_name, axis, structure_type): + print(file_name) phasons = np.array(np.loadtxt(file_name + '.pos'), dtype=int) - fib = Fibonacci(repetition_seq, fib_number) - seq = fib.sequence_generator() + if structure_type == 'F': + struct = Fibonacci(repetition_seq, fib_number) + elif structure_type == "P": + struct = Periodic(repetition_seq, fib_number) + elif structure_type == "R": + struct = Random(repetition_seq, Fibonacci(repetition_seq, fib_number).fib_number(), + Fibonacci(repetition_seq, fib_number- 2).fib_number()) + seq = struct.sequence_generator() Plot(1).draw_structure(axis, seq, phasons, 91) @@ -77,32 +80,53 @@ def calculate_idos(file_name): def plot_idos(phasons_percentage, start_point, end_point, structure_type, orginal_struct, path=None): plt.style.use('seaborn') plt.rc('text', usetex=False) - plt.rc('xtick', labelsize='x-large') - plt.rc('ytick', labelsize='x-large') + plt.rc('xtick', labelsize='xx-large') + plt.rc('ytick', labelsize='xx-large') fig = plt.figure() ax = fig.add_subplot(111) - ax.set_xlabel('Frequency (GHz)', fontsize='x-large') - ax.set_ylabel('IDOS', fontsize='x-large') + ax.set_xlabel('Frequency (GHz)', fontsize='xx-large') + ax.set_ylabel('IDOS', fontsize='xx-large') fib = np.loadtxt(orginal_struct) - axins1 = ax.inset_axes([0.2, 0.7, 0.4, 0.3]) - idos_inset(axins1, [19.5, 23], [270, 300], 0.2) + # axins1 = ax.inset_axes([0.2, 0.7, 0.4, 0.3]) + # idos_inset(axins1, [19.5, 23], [270, 300], 0.2) + # + # axins3 = ax.inset_axes([0.5, 0.01, 0.4, 0.4]) + # idos_inset(axins3, [14.5, 16], [75, 115], 0.02) - axins3 = ax.inset_axes([0.5, 0.01, 0.4, 0.4]) - idos_inset(axins3, [14.5, 16], [75, 115], 0.02) + add_gaps_idos(ax) for i in range(start_point, end_point): a = np.loadtxt(define_name_phason(phasons_percentage, i, structure_type, path) + '.dys') - for j in [axins1, axins3, ax]: + for j in [ax]: Plot(1).idos(j, a, 'C0', alpha=0.02) - for j in [axins1, axins3, ax]: + for j in [ax]: Plot(1).idos(j, fib, 'C2', alpha=1) - + ax.set_xlim([9.98, 24]) + ax.set_ylim([0, 410]) ax.set_aspect(aspect=0.05) plt.tight_layout() +def color_generator(): + yield 'C4' + yield 'C1' + yield 'C2' + yield 'C3' + while True: + yield 'gray' + +def add_gaps_idos(axis): + x_axis = np.loadtxt('Fib_14.dys')/1e9 + x_axis = x_axis[30:] + gaps = x_axis[np.argsort(np.diff(x_axis))[-11:]][::-1] + gaps_width = np.sort(np.diff(x_axis))[-11:][::-1] + color = color_generator() + print(gaps_width) + for g, g_w in zip(gaps, gaps_width): + axis.add_patch(Rectangle((g, -4), g_w, 440.1,alpha=0.7, color=next(color))) + def idos_inset(axis_inset, xlim, ylim, aspect): axis_inset.set_xlim(xlim) @@ -114,44 +138,61 @@ def idos_inset(axis_inset, xlim, ylim, aspect): def calculate_localization(mode, grid): mod = mode / np.sum(abs(mode)) * grid - return 1 / grid * np.sum(np.log(abs(mod))) + return -1 / grid * np.sum(abs(mod)*np.log(abs(mod))) -def plot_localization(file_name, grid, title): +def plot_localization(file_name, grid, title, type=None): plt.style.use('seaborn') plt.rc('text', usetex=False) - plt.rc('xtick', labelsize='x-large') - plt.rc('ytick', labelsize='x-large') + plt.rc('xtick', labelsize='xx-large') + plt.rc('ytick', labelsize='xx-large') a = np.zeros(400) - mod = mode(0, file_name) for index in range(len(a)): - a[index] = calculate_localization(mod.spatial_distribution_dynamic_magnetization(grid, index)[1], grid) - print(index) + a[index] = calculate_localization(mod.spatial_distribution_dynamic_magnetization(grid, index)[1], grid) # calculation + np.savetxt(title + '.txt', a) + # a = np.loadtxt(title + ".txt") + currentAxis = plt.gca() + add_gaps(currentAxis, file_name) x_label = np.loadtxt(file_name + '.dys')[0:len(a)] - plt.scatter(x_label, a, s=25) - plt.ylabel('$\lambda$', fontsize='x-large') - plt.xlabel('Frequency (GHz)', fontsize='x-large') - plt.ylim([-8, 0.1]) - plt.title(title) - plt.savefig(title + '.svg') + if type == "ref": + plt.scatter(x_label/1e9, a, s=15, alpha=1, c="C1", linewidth=None, edgecolors=None) + else: + plt.scatter(x_label/1e9, a, s=15, alpha=0.2, c="C0", linewidth=None, edgecolors=None) + + plt.ylabel('$\lambda$', fontsize='xx-large') + plt.xlabel('Frequency (GHz)', fontsize='xx-large') + plt.ylim([-4, 0.1]) + plt.xlim([10,25]) + # plt.title(title) + + + +def add_gaps(axis, file_name): + x_axis = np.loadtxt('Fib_14.dys')/1e9 + x_axis = x_axis[20:] + gaps = x_axis[np.argsort(np.diff(x_axis))[-11:]] + gaps_width = np.sort(np.diff(x_axis))[-11:] + for g, g_w in zip(gaps, gaps_width): + axis.add_patch(Rectangle((g, -4), g_w, 4.1,alpha=0.1 , color="C2")) def plot_fmr(file_name, grid, title): plt.style.use('seaborn') plt.rc('text', usetex=False) - plt.rc('xtick', labelsize='x-large') - plt.rc('ytick', labelsize='x-large') + plt.rc('xtick', labelsize='xx-large') + plt.rc('ytick', labelsize='xx-large') a = np.zeros(400) mod = mode(0, file_name) for index in range(len(a)): a[index] = calculate_fmr(mod.spatial_distribution_dynamic_magnetization(grid, index)[1]) + x_label = np.loadtxt(file_name + '.dys')[0:len(a)] - # a[0] = 1000 + a[0] = 1000 plt.scatter(x_label, a, s=25) - plt.ylabel('Intensity', fontsize='x-large') - plt.xlabel('Frequency (GHz)', fontsize='x-large') + plt.ylabel('Intensity', fontsize='xx-large') + plt.xlabel('Frequency (GHz)', fontsize='xx-large') print(np.argsort(a)[-5:][::-1]) plt.title(title) plt.savefig(title + '.svg') @@ -164,24 +205,26 @@ def calculate_fmr(mode): def plot_gap_width(phasons, frequency_ranges, title): plt.style.use('seaborn') plt.rc('text', usetex=False) - plt.rc('xtick', labelsize='x-large') - plt.rc('ytick', labelsize='x-large') + plt.rc('xtick', labelsize='xx-large') + plt.rc('ytick', labelsize='xx-large') results = np.zeros((4, len(phasons))) error = np.zeros((4, len(phasons))) + color = color_generator() for num, freq in enumerate(frequency_ranges): + col = next(color) for index, i in enumerate(phasons): results[num][index], error[num][index] = calculate_gap_statisitc(i, 0, 100, 'F', freq) - plt.errorbar(phasons, results[num], error[num], fmt='--o', label='gap at: ' + str((freq[0] + freq[1])/2/1e9) + ' GHz') + plt.errorbar(phasons, results[num], error[num], fmt='--o', label='gap at: ' + str((freq[0] + freq[1])/2/1e9) + ' GHz', color=col) plt.legend() - plt.xlabel("Phasons", fontsize='x-large') - plt.ylabel("Gap width (GHz)", fontsize='x-large') + plt.xlabel("Phasons", fontsize='xx-large') + plt.ylabel("Gap width (GHz)", fontsize='xx-large') plt.savefig(title + '.svg') def calculate_gap_statisitc(phasons_percentage, start_point, end_point, structure_type, range_to_look): gaps = np.zeros(end_point - start_point) for index, i in enumerate(range(start_point, end_point)): - a = np.loadtxt(define_name_phason(phasons_percentage, i, structure_type) + '.dys') + a = np.loadtxt(define_name_phason(phasons_percentage, i, structure_type, './JEMS2019/fib/') + '.dys') gaps[index] = calculate_gap(a, range_to_look) return np.average(gaps)/1e9, np.std(gaps)/1e9 @@ -192,68 +235,116 @@ def calculate_gap(data, range_to_look): if __name__ == "__main__": + input_parameters = ParsingData('./src/interface/Rychly.yaml') + + repetition_seq = 10 + fib_number = 14 + green_stripes = 'Py' + gray_stripes = 'Co' + bloch_vec = [1e4, 0] + + samples_count = 100 + phasons = 5 + sample_number = 0 + sequence_type = 'F' """ calculate fft from disturbed structure """ - # for i in [5, 15, 25, 35, 45, 55, 65, 80, 100, 120, 140]: - # save_structure(i, samples_count, 'F') + # for i in [1, 2]: + # save_structure(i, samples_count, sequence_type) + # save_structure(144, samples_count, sequence_type) """ calculate modes """ - # for i in [5, 15, 25, 35, 45, 55, 65, 80, 100, 120, 140]: - # for j in range(10): - # file = define_name_phason(phasons, sample_number, sequence_type) - # file = define_name_phason(i, j, 'F') + # for i in [1, 2]: + # for j in range(5): + # file = define_name_phason(i, j, sequence_type) # save_eig_vector(file) # save_eig_vector('./f_coef_10*14') + """ Plot modes """ - # file = define_name_phason(25, 3, 'F') - # for i in [300, 302, 288, 291]: - # plot_modes(i, file) - # plt.show() + #import argparse + #parser = argparse.ArgumentParser() + #parser.add_argument("count", type=int) + #phas = parser.parse_args().count + #print(phas) + #for file_num in range(5): +# file = define_name_phason(phas, file_num, 'F', c) +# idos = np.loadtxt(file + '.dys') +# for i in range(400): +# plot_modes(i, file, 'F', idos[i+1]) +# plt.savefig('mode_' + str(i) + '_' + str(phas) + '_' + str(file_num) + '.svg') + + + + """ calculate idos structure """ - # input_parameters.set_new_value('./f_coef_10*14.txt', 'numerical_parameters', 'fft_file') - # input_parameters.set_new_value('Fib_14' + '.dys', 'numerical_parameters', 'output_file') + # input_parameters.set_new_value('./Periodic.fft', 'numerical_parameters', 'fft_file') + # input_parameters.set_new_value('Periodic' + '.dys', 'numerical_parameters', 'output_file') # do_program_idos(input_parameters, green_stripes, gray_stripes, bloch_vec) # # - # for phas in [5, 15, 25, 35, 45, 55, 65, 80, 100, 120, 140]: + # for phas in [5, 35, 65]: + # # for i in range(samples_count): - # file = define_name_phason(phas, i, 'F') + # file = define_name_phason(phas, i, 'F', './JEMS2019/fib/') + # print(file) # calculate_idos(file) + # for i in range(samples_count): + # file = define_name_phason(144, i, 'R') + # calculate_idos(file) """ plotting idos structure """ - # for i in [5, 15, 25, 35, 45, 55, 65, 80, 100, 120, 140]: - # plot_idos(i, 0, 100, 'F', './Fib_14.dys') + # for i in [5, 35, 45, 65]: + # plot_idos(i, 0, 100, 'F', './Fib_14.dys','./JEMS2019/fib/') + # plt.savefig('idos_' + str(i) + '.svg') + # plt.clf() + + plot_idos(144, 0, 100, 'R', './Fib_14.dys', './JEMS2019/random/') + plt.savefig('idos_' + str(144) + '.svg') + plt.clf() + # plt.savefig('idos_' + str(144) + '.svg') # # plt.show() # plt.savefig('idos_' + str(i) + '.svg') # plt.clf() # plt.close() + # plot_idos(144, 0, 100, 'R', './Fib_14.dys') + # plt.savefig('idos_' + 'random' + '.svg') """ plot localization factor """ - # for i in range(10): - # name = define_name_phason(140, i, 'F') - # plot_localization(name, 7000, 'lambda, 140 phason ' + str(i) + ' series') + # import argparse + # parser = argparse.ArgumentParser() + # parser.add_argument("count", type=int) + # phas = parser.parse_args().count + # print(phas) + # for i in range(5): + # name = define_name_phason(phas, i, 'F') + # print(name) + # plot_localization(name, 7000, 'lambda, ' + str(phas) + ' phasons ' + str(i) + ' series') + # # plt.clf() + # plot_localization('./Fib_14', 5000, 'lambda, 0 phason', 'ref') + # plt.savefig('lambda_' + str(phas) + '.png', dpi=200) - #plot_localization('./Fib_14', 5000, 'lambda, 0 phason') """ calculate fmr """ - # for i in range(3, 4): - # name = define_name_phason(25, i, 'F') - # plot_fmr(name, 7000, '5 phasons, '+ str(i) + ' series') - # plot_fmr('./Fib_14', 7000, '0 phasons') + # for phas in [5, 15, 25, 35, 45, 55, 65, 80, 100, 120, 140]: + # for i in range(5): + # name = define_name_phason(phas, i, 'P') + # plot_fmr(name, 7000, 'fmr ' + str(phas) + ' phasons, '+ str(i) + ' series') + # plt.clf() + #plot_fmr('./Fib_14', 7000, '0 phasons') """ - calculate localization + gaps_width """ - # a = [5, 15, 25, 35, 45, 55, 65, 80, 100, 120, 140] - # b = [(13.8e9, 14.2e9), (15e9, 15.5e9), (16.05e9, 19.4e9), (20.1e9, 21.7e9)] - # plot_gap_width(a, b, 'localization') + a = [5, 15, 25, 35, 45, 55, 65, 80, 100, 120, 140] + b = [(16.05e9, 19.4e9), (20.1e9, 21.7e9), (15e9, 15.5e9), (13.8e9, 14.2e9)] + plot_gap_width(a, b, 'localization') diff --git a/src/interface/random.py b/src/interface/random.py deleted file mode 100644 index 19ea1c1..0000000 --- a/src/interface/random.py +++ /dev/null @@ -1,41 +0,0 @@ -import numpy as np -import matplotlib.pyplot as plt -from matplotlib.patches import Rectangle -from src.fft_from_image.FFT import FFT -from src.eig_problem.EigenValueProblem import EigenValueProblem1D -from src.fft_from_image.Sequences import Phason, Fibonacci, Random -from src.io.DataReader import ParsingData -from src.modes.MagnetizationProfile import Profile1D - -input_parameters = ParsingData('./src/interface/Random.yaml') - -repetition_seq = 5 -structure_length = 377 # Fibonacci 14 -inclusion_count = 140 - - -def save_structure(inclusion_count, samples_count): - for i in range(samples_count): - r = Random(repetition_seq, structure_length, inclusion_count) - seq = r.sequence() - fft_seq = FFT().fft1d(seq) - np.savetxt('random_' + str(inclusion_count) + '_' + str(i) + '.fft', fft_seq) - np.savetxt('random_' + str(inclusion_count) + '_' + str(i) + '.pos', seq) - - -def draw_structure(inclusion_count, sample_number, ax): - random = np.array(np.loadtxt('./random_' + str(inclusion_count) + '_' + str(sample_number) + '.pos'), dtype=int) - for index, el in enumerate(random): - if el == 0: - ax.add_patch(Rectangle((index*91, 0), 91, 1, color='green', alpha=0.5, linewidth=0, edgecolor=None)) - else: - ax.add_patch(Rectangle((index*91, 0), 91, 1, color='gray', alpha=0.5, linewidth=0, edgecolor=None)) - - -if __name__ == "__main__": - #save_structure(inclusion_count, 10) - ax1 = plt.axes() - draw_structure(inclusion_count, 1, ax1) - ax1.set_xlim(0, 34307) - plt.show() - From 6660ab2e02374163e0133561ae92d2d247afb503 Mon Sep 17 00:00:00 2001 From: szymag Date: Sat, 29 Aug 2020 21:24:26 +0200 Subject: [PATCH 2/2] Add fuction for determining topological properties of spin waves --- src/drawing/Plot.py | 11 +- src/eig_problem/EigenValueProblem.py | 2 +- src/fft_from_image/FFT.py | 2 +- src/interface/Periodic.yaml | 2 +- src/interface/bragg.py | 320 +++++++++++++++++++++++++++ src/interface/dispersion.py | 2 +- src/interface/localization.py | 56 +++++ src/interface/phason.py | 247 ++++++++++++++++----- src/modes/MagnetizationProfile.py | 17 +- 9 files changed, 593 insertions(+), 66 deletions(-) create mode 100644 src/interface/bragg.py create mode 100644 src/interface/localization.py diff --git a/src/drawing/Plot.py b/src/drawing/Plot.py index 16c4b52..c5b39dd 100755 --- a/src/drawing/Plot.py +++ b/src/drawing/Plot.py @@ -118,7 +118,7 @@ def contour_plot(self, input_data): plt.show() def idos(self, axis, input_data, color, alpha): - axis.step(input_data / 1e9, np.arange(len(input_data)), color=color, alpha=alpha) + axis.scatter(input_data / 1e9, np.arange(len(input_data)), color=color, alpha=alpha, s=10) def fmr_freq_function_of_magnetic_field(self, begin_of_name_file, start_number, end_number, scaling_factor_x_axis=1): @@ -164,6 +164,7 @@ def create_legend_for_fmr(self, axis): def draw_structure(self, axis, sequence, phasons, stripe_width): seq = sequence + # print(seq) for i in phasons: seq[(i + 1) % len(seq)] = 2 seq[i] = -2 @@ -172,13 +173,13 @@ def draw_structure(self, axis, sequence, phasons, stripe_width): color=color, alpha=alpha, linewidth=0, edgecolor=None)) for index, el in enumerate(seq): if el == 0: - stripe(index, 'green', 0.5) + stripe(index, '#f9f9f9', 1) elif el == 1: - stripe(index, 'gray', 0.5) + stripe(index, '#56B4E9', 1) elif el < 0: - stripe(index, 'red', 0.4) + stripe(index, '#CC79A7', 1) elif el > 1: - stripe(index, 'red', 0.8) + stripe(index, '#D55E00', 1) def show_or_save_plot(self): if self.name_of_file is None: diff --git a/src/eig_problem/EigenValueProblem.py b/src/eig_problem/EigenValueProblem.py index 52a4294..501d191 100755 --- a/src/eig_problem/EigenValueProblem.py +++ b/src/eig_problem/EigenValueProblem.py @@ -37,7 +37,7 @@ def calculate_eigen_frequency(self, bloch_vector, bloch_vector_perp=0): gamma, mu0H0 = self.parameters.physical_constant() eigen_vector = self.solve_eigen_problem(bloch_vector, param=False, bloch_vector_perp=bloch_vector_perp) eigen_value = [i.imag * gamma * mu0H0 / 2.0 / np.pi for i in eigen_vector if i.imag > 0] - return np.array(list(sorted(eigen_value)[:400])) # TODO: create smarter choice + return np.array(list(sorted(eigen_value)[:])) # TODO: create smarter choice def calculate_eigen_vectors(self, bloch_vector=np.array([1, 1])): eigen_value, eigen_vector = self.solve_eigen_problem(bloch_vector, param=True) diff --git a/src/fft_from_image/FFT.py b/src/fft_from_image/FFT.py index a9530ca..95f9e67 100755 --- a/src/fft_from_image/FFT.py +++ b/src/fft_from_image/FFT.py @@ -118,7 +118,7 @@ def wywolaj_fft1d(self, typ_struktury, repeat, len_num): if __name__ == "__main__": - a = FFT().wywolaj_fft1d('F', 5, 11) + a = FFT().wywolaj_fft1d('F', 10, 14) #FFT().wypisz_do_pliku() #a = FFT().wypisz_do_pliku() diff --git a/src/interface/Periodic.yaml b/src/interface/Periodic.yaml index bca7aff..11c4d48 100644 --- a/src/interface/Periodic.yaml +++ b/src/interface/Periodic.yaml @@ -16,7 +16,7 @@ material_parameters: l: 1.7e-17 numerical_parameters: - fft_file: periodic_0.1_4.fft + fft_file: p_coef_10*377.fft rec_vector_x: None rec_vector_y: None output_file: "idos" diff --git a/src/interface/bragg.py b/src/interface/bragg.py new file mode 100644 index 0000000..f003ccf --- /dev/null +++ b/src/interface/bragg.py @@ -0,0 +1,320 @@ +import numpy as np +from scipy.signal import find_peaks +from src.fft_from_image.FFT import FFT +import matplotlib.pyplot as plt +import matplotlib +lattice_const = 34307e-9 + +# exchange constant +A = (1.1e-11*2)/2 + +# magnetization saturation +ms = (144*1.445e6 + 233*0.86e6)/377 +# thickness +d = 30e-9 + +mu0 = 1.2566370614359173e-06 +gamma = 176e9 + +lamb2 = (144*3.46e-17+233*2.80e-17)/377 +# external magnetic field +H = 0.1 + + +# wave vector +k = np.linspace(1e1,0.4e8, 400) + +def dispersion(k): + Nd=0.0 + omega0 = gamma*H + omegaM = gamma*mu0*ms + el_1 = omega0 + omegaM*lamb2*k*k + Nd*omegaM + el_2 = omega0 + omegaM*lamb2*k*k + (1-Nd)*omegaM + el_3 = omegaM**2/4*(1 - np.exp(-2*d*k)) + return np.sqrt(el_1*el_2+el_3) / 2 / np.pi / 1e9 + + +# dys = np.loadtxt('./src/interface/Fib_14.dys') /1e9 +dys = np.loadtxt('idos')/1e9 + + +# phason_dys = np.loadtxt('/media/szymag/Dane/ZFN/JEMS2019/fib/F_5_' + str(0) + '.dys') /1e9 +# coef = abs(FFT().wywolaj_fft1d('P', 10, 377)) +coef = np.transpose(np.loadtxt('/media/szymag/Dane/ZFN/JEMS2019/periodic/P_5_0.fft')) + +coef = coef[0] + coef[1]*1j +struct = abs(np.fft.ifft(coef)) +coef = coef[len(coef)//2:]/max(coef)*10 +coef = abs(coef[:]) + + +x_coef = 2*np.pi*np.arange(0, len(coef))/lattice_const +x = np.linspace(0, 1e8, len(dys)) + + +def get_peaks(height): + peaks = find_peaks(coef, height)[0] + for num, i in enumerate(peaks): + print(str(num) + ' peak at ' + str(x_coef[i]) + ' with height ' + str(coef[i])) + return peaks + + +def plot_peaks_idos(): + peaks = get_peaks(0.7) + print(peaks) + + # plt.vlines(x_coef[peaks], 0, 30) + # plt.scatter(x_coef[peaks], coef[peaks], color='r') + plt.scatter(x, dys) + # plt.plot(x_coef, coef) + plt.show() + + +def plot_gaps(): + relative_height = np.zeros(100) + relative_width = np.zeros(100) + peaks = get_peaks(0.7) + peak_num = input('Which one? ') + peak = peaks[int(peak_num)] + + for i in range(100): + phason_fft = abs(np.loadtxt('/media/szymag/Dane/ZFN/JEMS2019/fib/F_5_' + str(i) + '.fft').view(complex)) + phason_fft = phason_fft[len(phason_fft)//2:]/max(phason_fft)*10 + phason_fft = phason_fft[:len(dys)] + phason_dys = np.loadtxt('/media/szymag/Dane/ZFN/JEMS2019/fib/F_5_' + str(i) + '.dys') /1e9 + # print(peaks) + relative_height[i] = phason_fft[peak] / coef[peak] + relative_width[i] = phason_dys[peak] - phason_dys[peak-1] + plt.xlabel('Realtive value of Fourier components (%)') + plt.ylabel('Gap width (GHz)') + plt.scatter(relative_height, relative_width) + plt.show() + +def averaged_peaks(peak_pos): + full_peak = abs(np.loadtxt('./f_coef_10*14.fft').view(complex)) + full_peak = full_peak[len(full_peak)//2:]/max(full_peak) + full_peak = full_peak[:len(dys)] + full_peak = full_peak[peak_pos] + h = np.zeros(10) + s = np.zeros(10) + for j, phas in enumerate([5, 15, 25, 35, 45, 55, 65, 80, 100, 120]): + height = np.zeros(100) + for i in range(100): + phason_fft = abs(np.loadtxt('/media/szymag/Dane/ZFN/JEMS2019/fib/F_'+str(phas)+'_' + str(i) + '.fft').view(complex)) + + phason_fft = phason_fft[len(phason_fft)//2:]/max(phason_fft) + phason_fft = phason_fft[:len(dys)] + # plt.plot(phason_fft) + # plt.show() + height[i] = phason_fft[peak_pos] + h[j] = np.mean(1-height/full_peak) + s[j] = np.std(1-height/full_peak) + return 100*h, 100*s + +def averaged_gaps(gap_width, rang): + + g = np.zeros(10) + s = np.zeros(10) + for j, phas in enumerate([5, 15, 25, 35, 45, 55, 65, 80, 100, 120]): + gap = np.zeros(100) + for i in range(100): + phason_dys = np.loadtxt('/media/szymag/Dane/ZFN/JEMS2019/fib/F_'+str(phas)+'_' + str(i) + '.dys')[rang[0]:rang[1]] /1e9 + + # print(np.max(np.diff(phason_dys))) + gap[i] = np.max(np.diff(phason_dys)) + # plt.scatter(np.arange(len(phason_dys)), phason_dys) + # plt.show() + + g[j] = np.mean(1-gap/gap_width) + s[j] = np.std(1-gap/gap_width) + return 100*g, 100*s + +def gap_evolution(): + plt.style.use('seaborn-colorblind') + plt.rc('text', usetex=False) + matplotlib.rcParams['font.family'] = "Liberation Sans" + fig = plt.figure(figsize=(3.3,2.2)) + full_gap_1 = 0.52 + full_gap_2 = 3.22 + full_gap_3 = 1.62 + g, sy = averaged_gaps(full_gap_1, [80, 100]) + h, sx = averaged_peaks(89) + print(g) + plt.errorbar(h, g, xerr=sx, yerr=sy, fmt='o', label='Third widest gap') + g, sy = averaged_gaps(full_gap_2, [120, 200]) + h, sx = averaged_peaks(144) + print(g) + plt.errorbar(h, g, xerr=sx, yerr=sy, fmt='o', label='First widest gap') + g, sy = averaged_gaps(full_gap_3, [250, 350]) + h, sx = averaged_peaks(233) + print(g) + plt.errorbar(h, g, xerr=sx, yerr=sy, fmt='o', label='Second widest gap') + + plt.legend() + plt.xlabel('Peak height reduction (%)') + plt.ylabel('Gap width reduction (%)') + + # plt.show() + plt.tight_layout() + plt.savefig('width.svg') + + +def bragg_sub(series_count): + plt.style.use('seaborn-colorblind') + plt.rc('text', usetex=False) + fig = plt.figure(figsize=(14,10)) + gs = fig.add_gridspec(2,2) + ax1 = fig.add_subplot(gs[0, 0]) + ax2 = fig.add_subplot(gs[0, 1]) + ax3 = fig.add_subplot(gs[1, 0]) + # ax4 = fig.add_subplot(gs[2, 1]) + ax1.plot(k, dispersion(k)) + ax1.set_xlim([-0.3e7, 4e7]) + phason_dys = np.loadtxt('/media/szymag/Dane/ZFN/JEMS2019/fib/F_15_' + str(series_count) + '.dys') /1e9 + ax2.scatter(np.arange(len(phason_dys)), phason_dys, s=1) + ax2.plot(dispersion(k)) + phason_fft = abs(np.loadtxt('/media/szymag/Dane/ZFN/JEMS2019/fib/F_15_' + str(series_count) + '.fft').view(complex)) + phason_fft = phason_fft[len(phason_fft)//2:]/max(phason_fft) + phason_fft = phason_fft[:len(dys)] + full_peak = abs(np.loadtxt('./f_coef_10*14.fft').view(complex)) + full_peak = full_peak[len(full_peak)//2:]/max(full_peak) + full_peak = full_peak[:len(dys)] + + ax3.plot(2*np.pi*np.arange(0, len(phason_fft))/lattice_const, full_peak, alpha=0.5, ls='--', color='C0') + ax3.plot(2*np.pi*np.arange(0, len(phason_fft))/lattice_const, phason_fft) + ax3.set_xlim([-0.3e7,8e7]) + plt.tight_layout() + # plt.show() + + +def count_full_gap(idos): + basic_sep = (idos[1] - idos[0])/1. + gaps = np.diff(idos) + gaps = gaps[basic_sep < gaps] + gaps = np.sum(gaps) + return gaps/1e9 + + +def plot_full_gap_evolution(): + plt.style.use('seaborn-colorblind') + plt.rc('text', usetex=False) + matplotlib.rcParams['font.family'] = "Liberation Sans" + fig = plt.figure(figsize=(3.3,2.2)) + idos = np.loadtxt('./Fib_14.dys') + reference_gap = count_full_gap(idos) + print(reference_gap) + gaps = np.zeros(10) + for j, phas in enumerate([5, 15, 25, 35, 45, 55, 65, 80, 100, 120]): + tmp = np.zeros(100) + for i in range(100): + idos = np.loadtxt('/media/szymag/Dane/ZFN/JEMS2019/fib/F_'+str(phas)+'_' + str(i) + '.dys') + tmp[i] = count_full_gap(idos) + gaps[j] = 1 - np.mean(tmp)/reference_gap + plt.scatter([5, 15, 25, 35, 45, 55, 65, 80, 100, 120], gaps) + plt.xlabel('Phasons') + plt.ylabel('Gap width reduction (%)') + plt.tight_layout() + plt.savefig('gap_evolution.svg') + + +def hausdorff(idos, r): + import matplotlib.patches as patches + idos = idos/1e9 + # r *= 1e9 + + count_in = np.zeros(len(idos)) + for idx in range(1, len(idos)-1): + dist_right = idos[idx+1] - idos[idx] + dist_left = idos[idx] - idos[idx-1] + if dist_right/dist_left > 40: + # print(dist_right/dist_left) + count_in[idx] = 1 + if dist_left/dist_right > 20: + count_in[idx] = 1 + count_in[0] = 1 + count_in[-1] = 1 + pass_bang_edges = np.argwhere(count_in) + + fig,ax = plt.subplots(1) + count_hit = 0 + for idx in range(0, len(pass_bang_edges), 2): + pass_left = idos[pass_bang_edges[idx]][0] + pass_right = idos[pass_bang_edges[idx+1]][0] + w = pass_right - pass_left + h = 400 + + n1 = (pass_left // r)*r + r + n2 = (pass_right // r)*r + r + + if pass_left < n1 and pass_right <= n1: + # print(pass_left, pass_right, 1) + count_hit += 0 + elif pass_left < n1 and pass_right < n1+r: + count_hit += 2 + print('asas') + # print(pass_left, pass_right, 2) + elif pass_left < n1 and pass_right > (n1+r): + count_hit += int(1 + (n2-n1)//r) + # print(pass_left, pass_right, int(1 + (n2-n1)//r)) + else: + print('Someting wrong' + str(pass_left)) + plt.axvline(pass_left, 0, 400) + plt.axvline(pass_right, 0, 400) + ax.add_patch(patches.Rectangle((pass_left, 0), w, h, alpha=0.3)) + + plt.step(idos, np.arange(len(idos))) + plt.show() + return count_hit + + +# idos = np.loadtxt('./Fib_14.dys') +# idos = np.loadtxt('./Periodic.dys') +# idos = np.loadtxt('/media/szymag/Dane/ZFN/JEMS2019/fib/F_'+str(120)+'_' + str(0) + '.dys') +# idos = np.loadtxt('/media/szymag/Dane/ZFN/JEMS2019/periodic/P_'+str(5)+'_' + str(0) + '.dys') +# r = [0.3, 0.25, 0.2, 0.15, 0.1, 0.05, 0.04, 0.03, 0.02, 0.01, 0.005, 0.003, 0.002, 0.001] +# r = [0.01] +# nf = np.zeros(len(r)) +# for idx, el in enumerate(r): +# nf[idx] = np.log(hausdorff(idos, el)) + + +# from scipy.stats import linregress +# slope, intercept, r_value, p_value, std_err =linregress(np.log(idos[0]/r/1e9),nf) +# plt.scatter(np.log(idos[0]/r/1e9), nf) +# plt.xlabel('log(f0/r)') +# plt.ylabel('log(N(r)') +# plt.show() +# print(r_value**2, slope) +# print(hausdorff(idos, 0.8)) + +# plot_full_gap_evolution() +# plt.clf() +# gap_evolution() + +# for i in range(100): +# bragg_sub(i) +# plt.savefig('sub_' +str(i) +'.png', png=200) +# plt.close() + +# plot_peaks_idos() +# plt.plot(2*np.pi*np.arange(0, len(dys))/lattice_const, dys) +# plt.plot(np.linspace(0.01*2, 2*377, len(struct)), struct[:len(struct)]) +# plt.plot(2*np.pi*np.arange(0, len(coef))/lattice_const, coef[:len(coef)]) +# plt.plot(k, dispersion(k)) +# plt.ylim([10, 40]) +# plt.xlim([0,1.75e8]) + +# plot_peaks_idos() + + +# +# +# peaks = find_peaks(coef, 0.7)[0] +# print(peaks) +# # +# plt.scatter(x_coef[89], coef[89], color='r') +# plt.vlines(x_coef[peaks], 0, 50) +# plt.scatter(x, dys) +# plt.scatter(x, phason_dys) +# plt.plot(x_coef, coef) +# plt.plot(x, phason_fft) diff --git a/src/interface/dispersion.py b/src/interface/dispersion.py index 426fa1b..0bb3f74 100644 --- a/src/interface/dispersion.py +++ b/src/interface/dispersion.py @@ -72,5 +72,5 @@ def do_program_idos(input_param, mat_1, mat_2, bloch_vec): if __name__ == "__main__": # do_program_oblique() - do_program_idos() + do_program_idos(input_parameters, 'Co', 'Py', 1e3) # do_program_1D() diff --git a/src/interface/localization.py b/src/interface/localization.py new file mode 100644 index 0000000..a165855 --- /dev/null +++ b/src/interface/localization.py @@ -0,0 +1,56 @@ +import numpy as np +from scipy.signal import find_peaks +from src.fft_from_image.FFT import FFT +import matplotlib.pyplot as plt +import matplotlib +from src.io.DataReader import ParsingData +from src.modes.MagnetizationProfile import Profile1D + +dx_element = 20 +w = 1/5 +elements_count = 377 + +dx_count = dx_element * elements_count +x = np.arange(dx_count) + +input_parameters = ParsingData('./src/interface/Rychly.yaml') +loaded_modes = '/media/szymag/Dane/ZFN/JEMS2019/fib/F_5_0.vec' +idos = np.loadtxt('/media/szymag/Dane/ZFN/JEMS2019/fib/F_5_0.dys') +defects = np.loadtxt('/media/szymag/Dane/ZFN/JEMS2019/fib/F_5_0.pos') +defects = defects * dx_element + +modes = Profile1D(0, loaded_modes, None, input_parameters) + + + + +def count_distance_from_defect(defect_pos): + a = (np.abs(x - defect_pos))**w + b = (dx_count - np.abs(x - defect_pos))**w + c = np.stack((a, b)) + return np.min(c, axis=0) + # return a/np.max(a) + +def calculate_d(): + d = np.ones(dx_count) + for i in defects: + d = d*count_distance_from_defect(i) + return d / np.sum(d) + + +def calculate_localization(): + el = 400 + lam = np.zeros(el) + d = calculate_d() + for idx in range(el): + mode_1 = np.log(np.abs(modes.spatial_distribution_dynamic_magnetization(dx_count, idx)[1])) + mode_1 = mode_1 / np.max(mode_1) + lam[idx] = np.sum(mode_1*d) + + return lam, (1 - lam)/(1+lam) + +lam, m = calculate_localization() + +plt.scatter(idos, lam) +plt.scatter(idos, m) +plt.show() diff --git a/src/interface/phason.py b/src/interface/phason.py index 4ea3368..ab23e66 100644 --- a/src/interface/phason.py +++ b/src/interface/phason.py @@ -8,8 +8,22 @@ from src.interface.dispersion import do_program_idos from src.drawing.Plot import Plot from src.utils.cProfiler import do_cprofile -from multiprocessing import Pool +from matplotlib.colors import LogNorm +from scipy.ndimage.filters import gaussian_filter +import matplotlib from matplotlib.patches import Rectangle +input_parameters = ParsingData('./src/interface/Rychly.yaml') + +repetition_seq = 10 +fib_number = 14 +green_stripes = 'Py' +gray_stripes = 'Co' +bloch_vec = [1e4, 0] + +samples_count = 100 +phasons = 5 +sample_number = 0 +sequence_type = 'F' def define_name_phason(phasons_percentage, sample_number, structure_type, path=None): @@ -39,11 +53,13 @@ def save_eig_vector(file_name): def plot_modes(mode_number, file_name, structure_type, freq): - plt.rc('xtick', labelsize='xx-large') - plt.rc('ytick', labelsize='xx-large') - fig, axs = plt.subplots(5,figsize=(8, 10.56)) + plt.rc('xtick', labelsize='small') + plt.rc('ytick', labelsize='small') + plt.style.use('seaborn') + plt.rc('text', usetex=False) + fig, axs = plt.subplots(4,figsize=(5, 5)) print(axs) - size = 91*377/5 + size = 91*377/4/1000 for index, i in enumerate(axs): print(size*index, size*(index+1)) i.set_xlim(size*index, size*(index+1)) @@ -64,7 +80,7 @@ def draw_structure(file_name, axis, structure_type): struct = Random(repetition_seq, Fibonacci(repetition_seq, fib_number).fib_number(), Fibonacci(repetition_seq, fib_number- 2).fib_number()) seq = struct.sequence_generator() - Plot(1).draw_structure(axis, seq, phasons, 91) + Plot(1).draw_structure(axis, seq, phasons, 91/1000) def mode(mode_number, file_name): @@ -78,14 +94,15 @@ def calculate_idos(file_name): def plot_idos(phasons_percentage, start_point, end_point, structure_type, orginal_struct, path=None): - plt.style.use('seaborn') + plt.style.use('seaborn-colorblind') plt.rc('text', usetex=False) - plt.rc('xtick', labelsize='xx-large') - plt.rc('ytick', labelsize='xx-large') - fig = plt.figure() + # plt.rc('xtick', labelsize='x-large') + # plt.rc('ytick', labelsize='x-large') + # fig = plt.figure() + fig = plt.figure(figsize=(3.3,5)) ax = fig.add_subplot(111) - ax.set_xlabel('Frequency (GHz)', fontsize='xx-large') - ax.set_ylabel('IDOS', fontsize='xx-large') + ax.set_xlabel('Frequency (GHz)') + ax.set_ylabel('IDOS') fib = np.loadtxt(orginal_struct) @@ -95,18 +112,16 @@ def plot_idos(phasons_percentage, start_point, end_point, structure_type, orgina # axins3 = ax.inset_axes([0.5, 0.01, 0.4, 0.4]) # idos_inset(axins3, [14.5, 16], [75, 115], 0.02) - add_gaps_idos(ax) - - for i in range(start_point, end_point): - a = np.loadtxt(define_name_phason(phasons_percentage, i, structure_type, path) + '.dys') - for j in [ax]: - Plot(1).idos(j, a, 'C0', alpha=0.02) + # for i in range(start_point, end_point): + # a = np.loadtxt(define_name_phason(phasons_percentage, i, structure_type, path) + '.dys') + # for j in [axins1, axins3, ax]: + # Plot(1).idos(j, a, '#0A539E', alpha=1) + a = np.loadtxt(define_name_phason(phasons_percentage, i, structure_type, path) + '.dys') + Plot(1).idos(ax, a, '#0A539E', alpha=1) + # for j in [axins1, axins3, ax]: + # Plot(1).idos(j, fib, 'C2', alpha=1) - for j in [ax]: - Plot(1).idos(j, fib, 'C2', alpha=1) - ax.set_xlim([9.98, 24]) - ax.set_ylim([0, 410]) - ax.set_aspect(aspect=0.05) + # ax.set_aspect(aspect=0.05) plt.tight_layout() def color_generator(): @@ -233,6 +248,93 @@ def calculate_gap(data, range_to_look): range_to_look = [np.argmin(abs(data - i)) for i in range_to_look] return np.max(np.diff(data[range_to_look[0]:range_to_look[1]])) +def idos_histogram(phasons_percentage, structure_type, path): + plt.style.use('seaborn-colorblind') + plt.rc('text', usetex=False) + matplotlib.rcParams['font.family'] = "Liberation Sans" + + # file_x = [np.loadtxt(define_name_phason(phasons_percentage, 2, structure_type, path) + '.dys')/1e9 for i in range(100)] + file_x = [np.loadtxt('./Fib_14.dys')/1e9 for i in range(100)] + file_y = [np.arange(0, 400) for i in range(100)] + + x = np.concatenate(file_x, axis=None) + y = np.concatenate(file_y, axis=None) + + h, x, y= np.histogram2d(x, y, bins=(len(x)/100,len(y)/100)) + X, Y = np.meshgrid(x, y) + h = h.T/np.max(h) + from src.interface.bragg import dispersion + k = np.linspace(1e1,0.4e8, 400) + lattice_const = 34307e-9 + fig = plt.figure(figsize=(3.3,4.4)) + ax2 = fig.add_subplot(211) + ax = ax2.twiny() + # ax2.set_ylim([0, 0.4e8/2/np.pi*lattice_const]) + ax2.plot(k/2/np.pi*lattice_const, dispersion(k), color='C2', alpha=0) + ax.plot(np.arange(0,400), dispersion(k), color='C2') + ax2.tick_params(axis='x', labelcolor='C2') + ax.tick_params(axis='x', labelcolor='C0') + ax2.set_xlabel('Wavenumber (2$\pi$/a)', color="C2") + # Plot(1).idos(ax, np.loadtxt('./Fib_14.dys'), 'C2', alpha=0.5) + + a = np.arange(400) + # x_label = np.loadtxt('./Fib_14.dys') + + + # plt.scatter(x_label/1e9, a, s=0.7, alpha=1, c="C2", linewidth=None, edgecolors=None) + ax2.set_ylabel('Frequency (GHz)') + ax.set_xlabel('IDOS', color='C0') + # plt.ylim([-4, 0.1]) + # plt.xlim([10,22.5]) + + ax.pcolormesh(Y, X, gaussian_filter(h, sigma=1, order=0), cmap="Blues", norm=LogNorm(vmin=0.001, vmax=1)) + # ax.grid(True, linewidth=0.5) + + + ax.set_ylim([9.98, 24]) + + + # ax.plot(np.arange(400), dispersion(k), color='C2') + ax.set_ylim([9.98, 24]) + ax.set_xlim([-15, 410]) + plt.tight_layout() + # add_gaps_vertical(ax) + + ax1 = fig.add_subplot(212) + ax1.set_ylabel('Intenisty (arb. units)') + ax1.set_xlabel('Wavenumber (2$\pi$/a)', color="C2") + ax1.tick_params(axis='x', labelcolor='C2') + full_peak = abs(np.loadtxt('./f_coef_10*14.fft').view(complex)) + full_peak = full_peak[len(full_peak)//2:]/max(full_peak) + + coef = np.transpose(np.loadtxt('/media/szymag/Dane/ZFN/JEMS2019/fib/F_'+ str(phasons_percentage) +'_0.fft')) + coef = coef[0] + coef[1]*1j + struct = abs(np.fft.ifft(coef)) + coef = coef[len(coef)//2:]/max(coef) + coef = abs(coef[:]) + + x_coef = 2*np.pi*np.arange(0, len(coef))/lattice_const + ax1.set_xlim(-0.35e7/2/np.pi*lattice_const, 0.8e8/2/np.pi*lattice_const) + ax1.plot(np.arange(0, len(coef)), full_peak, color='C2') + # ax1.plot(np.arange(0, len(coef)), coef[:len(coef)], color='C2') + plt.tight_layout() + +def add_gaps(axis): + x_axis = np.loadtxt('Fib_14.dys')/1e9 + x_axis = x_axis[20:] + gaps = x_axis[np.argsort(np.diff(x_axis))[-11:]][::-1] + gaps_width = np.sort(np.diff(x_axis))[-11:][::-1] + for g, g_w in zip(gaps, gaps_width): + axis.add_patch(Rectangle((g, -4), g_w, 410,alpha=0.3 , color='gray', ec=None)) + +def add_gaps_vertical(axis): + y_axis = np.loadtxt('Fib_14.dys')/1e9 + y_axis = y_axis[20:] + gaps = y_axis[np.argsort(np.diff(y_axis))[-11:]][::-1] + gaps_width = np.sort(np.diff(y_axis))[-11:][::-1] + for g, g_w in zip(gaps, gaps_width): + axis.add_patch(Rectangle((-4, g), 410, g_w, alpha=0.3 , color='gray', ec=None)) + if __name__ == "__main__": input_parameters = ParsingData('./src/interface/Rychly.yaml') @@ -266,27 +368,35 @@ def calculate_gap(data, range_to_look): """ Plot modes """ - #import argparse - #parser = argparse.ArgumentParser() - #parser.add_argument("count", type=int) - #phas = parser.parse_args().count - #print(phas) - #for file_num in range(5): -# file = define_name_phason(phas, file_num, 'F', c) -# idos = np.loadtxt(file + '.dys') -# for i in range(400): -# plot_modes(i, file, 'F', idos[i+1]) -# plt.savefig('mode_' + str(i) + '_' + str(phas) + '_' + str(file_num) + '.svg') - - - - - + # file = define_name_phason(25, 3, 'F', '/media/szymag/Dane/ZFN/JEMS2019/fib/') + # for i in [300, 302, 288, 291]: + # plot_modes(i, file) + # plt.show() + + # ax1 = plt.axes() + # file_name = '/media/szymag/Dane/ZFN/JEMS2019/fib/F_15_3' + # idos = np.loadtxt('/media/szymag/Dane/ZFN/JEMS2019/fib/F_15_3.dys') + # # draw_structure(file_name, ax1) + # for i in range(30, 50): + # plot_modes(i, file_name, 'F', idos[i]) + # # ax1.set_xlim(10000) + # # plt.savefig('emty.svg') + # plt.savefig('./15p_3/mode_' + str(i) +'.svg') + # plt.close() + # plt.clf() """ calculate idos structure """ - # input_parameters.set_new_value('./Periodic.fft', 'numerical_parameters', 'fft_file') - # input_parameters.set_new_value('Periodic' + '.dys', 'numerical_parameters', 'output_file') + + # for phas in [15]: + # idos_histogram(phas, 'F', '/media/szymag/Dane/ZFN/JEMS2019/fib/') + # plt.xlabel('Frequency (GHz)') + # plt.ylabel('IDOS') + # plt.savefig('idos_' + str(phas) + '.svg') + # plt.clf() + # plt.cla() + # input_parameters.set_new_value('./f_coef_10*14.txt', 'numerical_parameters', 'fft_file') + # input_parameters.set_new_value('Fib_14' + '.dys', 'numerical_parameters', 'output_file') # do_program_idos(input_parameters, green_stripes, gray_stripes, bloch_vec) # # # for phas in [5, 35, 65]: @@ -301,16 +411,51 @@ def calculate_gap(data, range_to_look): """ plotting idos structure """ - # for i in [5, 35, 45, 65]: - # plot_idos(i, 0, 100, 'F', './Fib_14.dys','./JEMS2019/fib/') - # plt.savefig('idos_' + str(i) + '.svg') - # plt.clf() - - plot_idos(144, 0, 100, 'R', './Fib_14.dys', './JEMS2019/random/') - plt.savefig('idos_' + str(144) + '.svg') - plt.clf() - # plt.savefig('idos_' + str(144) + '.svg') - # # plt.show() + # for i in [5, 15, 25, 35, 45, 55, 65, 80, 100, 120, 140]: + for i in [45]: + idos_histogram(i, 'F', '/media/szymag/Dane/ZFN/JEMS2019/fib/') + # plt.show() + + plt.savefig('bragg.png', dpi=400) + + # mode_number = 50 + # idos = np.loadtxt('/media/szymag/Dane/ZFN/JEMS2019/fib/F_15_3.dys') + # for mode_number in range(400): + # + # plt.style.use('seaborn-colorblind') + # plt.rc('text', usetex=False) + # fig = plt.figure(figsize=(10,7)) + # gs = fig.add_gridspec(4,2) + # ax1 = fig.add_subplot(gs[:, 0]) + # ax2 = fig.add_subplot(gs[0, 1]) + # ax3 = fig.add_subplot(gs[1, 1]) + # ax4 = fig.add_subplot(gs[2, 1]) + # ax5 = fig.add_subplot(gs[3, 1]) + # # ax = fig.add_subplot(121) + # ax1.set_xlabel('Frequency (GHz)') + # ax1.set_ylabel('IDOS') + # + # a = np.loadtxt(define_name_phason(15, 3, 'F', '/media/szymag/Dane/ZFN/JEMS2019/fib/') + '.dys') + # Plot(1).idos(ax1, a, '#0A539E', alpha=1) + # + # + # + # axs = [ax2, ax3, ax4, ax5] + # size = 91*377/4/1000 + # + # ax1.scatter(idos[mode_number]/1e9, mode_number, s=100, color='r') + # for index, i in enumerate(axs): + # i.set_xlim(size*index, size*(index+1)) + # draw_structure('/media/szymag/Dane/ZFN/JEMS2019/fib/F_15_3', i, 'F') + # mode(mode_number, '/media/szymag/Dane/ZFN/JEMS2019/fib/F_15_3').generate_plot(i, 0) + # axs[0].set_title('mode: ' + str(mode_number) + '\n' + # +'frequency: ' + str(round(idos[mode_number]/1e9,3)) + ' GHz') + # plt.tight_layout() + # plt.savefig(str(mode_number) + '.png') + # plt.close(fig) + # plt.clf() + # plt.show() + # plt.savefig('idos_' + str(i) + '.svg') # plt.clf() # plt.close() diff --git a/src/modes/MagnetizationProfile.py b/src/modes/MagnetizationProfile.py index ee1805c..53200fb 100755 --- a/src/modes/MagnetizationProfile.py +++ b/src/modes/MagnetizationProfile.py @@ -79,10 +79,14 @@ def __init__(self, mode_number, load_data, name_of_file, input_parameter, **kwar self.field = kwargs['field'] def generate_plot(self, ax, color_index, dummy=False): - + # plt.style.use('seaborn') + # plt.rc('text', usetex=False) + # plt.rc('xtick', labelsize='small') + # plt.rc('ytick', labelsize='small') colors = ['C0', 'C3', 'C2'] x, magnetization = self.spatial_distribution_dynamic_magnetization(5000, self.mode_number) magnetization /= np.max(abs(magnetization)) + phase = np.abs(np.arctan2(magnetization.imag, magnetization.real)) parameter = np.array([0 if i < 0.5 * np.pi else 1 for i in phase]) if dummy: @@ -91,14 +95,15 @@ def generate_plot(self, ax, color_index, dummy=False): else: magnetization1 = np.ma.masked_where(parameter != 0, abs(magnetization) ** 2) magnetization2 = np.ma.masked_where(parameter == 0, abs(magnetization) ** 2) - ax.plot(x, magnetization1, colors[color_index] + '-', - x, magnetization2, colors[color_index] + '--') + ax.plot(x, magnetization1, 'k' + '-', + x, magnetization2, 'k' + '--') #ax.set_ylim(-0.05, 3) #plt.setp(ax, xticks=[-1100, 0, 1100], xticklabels=[r'$-\Lambda$', 0, r'$\Lambda$'], # yticks=[0]) - ax.set_xlabel('x ($\mu$m)', fontsize='xx-large') - ax.set_ylabel(r'|m|', fontsize='xx-large') + ax.set_xlabel('x ($\mu$m)') + ax.set_ylabel(r'|m|') + # self.output_plot() def output_plot(self): @@ -123,7 +128,7 @@ def spatial_distribution_dynamic_magnetization(self, grid, mode_number): x = np.linspace(0, self.lattice_const, grid) tmp = np.zeros(grid, dtype=complex) tmp[:] = self.inverse_discrete_fourier_transform(mode, x) - return x * 10 ** 9, tmp + return x * 10 ** 6, tmp def elementary_cell_reconstruction(self, grid): coefficient = np.transpose(np.loadtxt('c_coef_100.txt').view(complex))