From f9acffba105ecd92382316b9883bdb610a4ec668 Mon Sep 17 00:00:00 2001 From: sakul-45 <81963567+sakul-45@users.noreply.github.com> Date: Thu, 29 Jul 2021 17:58:36 +0200 Subject: [PATCH 1/5] Renaming and spelling correction --- TR_EPR_script.m | 2 +- average_maximum.m | 109 ++++++++++++++++++++++++++++++++++++ correct_magnetic_baseline.m | 6 +- pre_simulation_TREPR.m | 19 ++++--- simulation_TREPR.m | 4 +- 5 files changed, 126 insertions(+), 14 deletions(-) create mode 100644 average_maximum.m diff --git a/TR_EPR_script.m b/TR_EPR_script.m index e5a27f7..2df6956 100644 --- a/TR_EPR_script.m +++ b/TR_EPR_script.m @@ -12,7 +12,7 @@ datapath = 'C:\Users\lukas\Nextcloud\Uni\Bachelorarbeit\tr-epr-simulation\exampl [full_corr_data,params] = correct_magnetic_baseline(time_corr_data,params); -[norm_data,params] = normalize_data(full_corr_data,params); +[norm_data,params] = average_maximum(full_corr_data,params); [params] = pre_simulation_TREPR(params); diff --git a/average_maximum.m b/average_maximum.m new file mode 100644 index 0000000..f6c3606 --- /dev/null +++ b/average_maximum.m @@ -0,0 +1,109 @@ +function [dataOUT,params] = average_maximum(dataIN,params) +%AVERAGE_MAXIMUM normalizes data by max of region +% +% Usage: [dataOUT,params] = AVERAGE_MAXIMUM(dataIN,params), where dataIN +% is a dataset loaded via the LOAD_MATLAB or LOAD_BRUKER function. +% +% The function will show the input data and offer two input fields, where +% the left and right borders of the maximum's region should be set. +% By pressing "Apply" normalization to maximum will be executed and the +% graph changes to the normalized data. The borders of the maximum region +% and the mean of maxima will also be appended to the params struct. +% By pressing "Reset" the graph will return to show the original data. +% Exit the function by pressing "Done". + +%% creating UI +fig = figure; +fig.Name = 'Average of Data in Maximum'; +fig.Units = 'Normalized'; +fig.Position = [.2 .2 .6 .6]; +fig.Tag = 'Normalize'; + +%panel for plot +plotpanel = uipanel(fig); +plotpanel.Units = 'Normalized'; +plotpanel.Position = [.01 .06 .98 .92]; +%axes for plot +ax = axes(plotpanel); +ax.XLabel.String = 'Time'; +ax.YLabel.String = 'Intensity'; +%plot current data in figure with time as x axis +plot(ax,dataIN) +axis tight + +%create push buttons +a = uicontrol(fig,'Style','pushbutton'); +a.String = 'Apply'; +a.Units = 'Normalized'; +a.Position = [.52 .01 .15 .05]; +a.FontUnits = 'Normalized'; +a.FontSize = 0.6; +a.Tag = 'Apply'; +a.Callback = @NormApplyButtonPushed; + +r = uicontrol(fig,'Style','pushbutton'); +r.String = 'Reset'; +r.Units = 'Normalized'; +r.Position = [.68 .01 .15 .05]; +r.FontUnits = 'Normalized'; +r.FontSize = 0.6; +r.Tag = 'Reset'; +r.Callback = @NormResetButtonPushed; + +d = uicontrol(fig,'Style','pushbutton'); +d.String = 'Done'; +d.Units = 'Normalized'; +d.Position = [.84 .01 .15 .05]; +d.FontUnits = 'Normalized'; +d.FontSize = 0.6; +d.Tag = 'Done'; +d.Callback = @NormDoneButtonPushed; + +%create input fields +p1 = uicontrol(fig,'Style','edit'); +p1.String = 'Left point of max region'; +p1.Units = 'Normalized'; +p1.Position = [.01 .01 .24 .05]; +p1.HorizontalAlignment = 'left'; +p1.FontUnits = 'Normalized'; +p1.FontSize = 0.6; +p1.Tag = 'MaxRegionLeft'; + +p2 = uicontrol(fig,'Style','edit'); +p2.String = 'Right point of max region'; +p2.Units = 'Normalized'; +p2.Position = [.25 .01 .24 .05]; +p2.HorizontalAlignment = 'left'; +p2.FontUnits = 'Normalized'; +p2.FontSize = 0.6; +p2.Tag = 'MaxRegionRight'; + +uicontrol(p1); %passes focus to first input +uiwait(fig) + +%% Callback functions + function NormApplyButtonPushed(~,~) + left_point = str2double(get(p1,'String')); + right_point = str2double(get(p2,'String')); + %take mean of each field line between specified min and max time + maxima_mean = mean(dataIN([left_point right_point],:)); + %normalize amplitude to 1 by dividing by max of means + dataOUT = dataIN / max(maxima_mean); + %plotting result with time as x axis + plot(ax,dataOUT) + axis tight + %writing parameter + params.region_of_max = [left_point right_point]; + params.max_mean = maxima_mean / max(maxima_mean); + end + + function NormResetButtonPushed(~,~) + plot(ax,dataIN) + axis tight + end + + function NormDoneButtonPushed(~,~) + close 'Average of Data in Maximum' + end + +end diff --git a/correct_magnetic_baseline.m b/correct_magnetic_baseline.m index bd1cd3b..2debd1f 100644 --- a/correct_magnetic_baseline.m +++ b/correct_magnetic_baseline.m @@ -15,7 +15,7 @@ function [dataOUT,params] = correct_magnetic_baseline(dataIN,params) %% creating UI fig = figure; -fig.Name = 'Correct Magnetic Baseline'; +fig.Name = 'Correct Magnetic Field Baseline'; fig.Units = 'Normalized'; fig.Position = [.2 .2 .6 .6]; fig.Tag = 'CorrMagBase'; @@ -72,7 +72,7 @@ p1.FontSize = 0.6; p1.Tag = 'FieldPoints'; p2 = uicontrol(fig,'Style','edit'); -p2.String = 'No. points to cut'; +p2.String = 'No. points to cut before'; p2.Units = 'Normalized'; p2.Position = [.26 .01 .24 .05]; p2.HorizontalAlignment = 'left'; @@ -120,7 +120,7 @@ uiwait(fig) end function FieldDoneButtonPushed(~,~) - close 'Correct Magnetic Baseline' + close 'Correct Magnetic Field Baseline' end end diff --git a/pre_simulation_TREPR.m b/pre_simulation_TREPR.m index bb4d6d2..647064e 100644 --- a/pre_simulation_TREPR.m +++ b/pre_simulation_TREPR.m @@ -10,6 +10,9 @@ function [params] = pre_simulation_TREPR(params) % different relevant paramters of TREPR simulation. % By pressing "Apply" the simulation will be calculated and displayed. % The simulation parameters will be saved to the params struct. +% Note: Triplett popluations will be processed normalized, but must not +% be equal. +% "Done" will close the window. %% creating UI fig = figure; @@ -51,7 +54,7 @@ d.Callback = @PreSimDoneButtonPushed; %% create input and text fields (Triplet) textTrip = uicontrol(fig,'Style','text'); -textTrip.String = 'Triplett populations'; +textTrip.String = 'Triplet populations'; textTrip.Units = 'Normalized'; textTrip.Position = [.71 .94 .28 .05]; textTrip.HorizontalAlignment = 'center'; @@ -70,7 +73,7 @@ textTx.FontSize = 0.6; textTx.Tag = 'textTx'; InpTx = uicontrol(fig,'Style','edit'); -InpTx.String = '1'; +InpTx.String = '0.9'; InpTx.Units = 'Normalized'; InpTx.Position = [.75334 .89 .04333 .05]; InpTx.HorizontalAlignment = 'left'; @@ -88,7 +91,7 @@ textTy.FontSize = 0.6; textTy.Tag = 'textTy'; InpTy = uicontrol(fig,'Style','edit'); -InpTy.String = '1'; +InpTy.String = '1.0'; InpTy.Units = 'Normalized'; InpTy.Position = [.85001 .89 .04333 .05]; InpTy.HorizontalAlignment = 'left'; @@ -106,7 +109,7 @@ textTz.FontSize = 0.6; textTz.Tag = 'textTz'; InpTz = uicontrol(fig,'Style','edit'); -InpTz.String = '1'; +InpTz.String = '1.1'; InpTz.Units = 'Normalized'; InpTz.Position = [.94667 .89 .04333 .05]; InpTz.HorizontalAlignment = 'left'; @@ -116,7 +119,7 @@ InpTz.Tag = 'InpTz'; %% create input and text fields (D & E) textDE = uicontrol(fig,'Style','text'); -textDE.String = 'D tensor'; +textDE.String = 'ZFS parameters / MHz'; textDE.Units = 'Normalized'; textDE.Position = [.71 .77 .28 .05]; textDE.HorizontalAlignment = 'center'; @@ -153,7 +156,7 @@ textE.FontSize = 0.6; textE.Tag = 'textE'; InpE = uicontrol(fig,'Style','edit'); -InpE.String = '1/3 D'; +InpE.String = 'max D/3'; InpE.Units = 'Normalized'; InpE.Position = [.9225 .72 .0675 .05]; InpE.HorizontalAlignment = 'left'; @@ -208,9 +211,9 @@ InpG.FontUnits = 'Normalized'; InpG.FontSize = 0.6; InpG.Tag = 'InpG'; -%% create input and text fields (linewidth) +%% create input and text fields (linewidths) textLW = uicontrol(fig,'Style','text'); -textLW.String = 'Linewidth'; +textLW.String = 'Linewidths'; textLW.Units = 'Normalized'; textLW.Position = [.71 .43 .28 .05]; textLW.HorizontalAlignment = 'center'; diff --git a/simulation_TREPR.m b/simulation_TREPR.m index 0c9c731..af29e93 100644 --- a/simulation_TREPR.m +++ b/simulation_TREPR.m @@ -146,7 +146,7 @@ InpTz.Tag = 'InpTz'; %% create input and text fields (D & E) textDE = uicontrol(fig,'Style','text'); -textDE.String = 'D tensor variation'; +textDE.String = 'ZFS parameter variation / MHz'; textDE.Units = 'Normalized'; textDE.Position = [.71 .78 .28 .05]; textDE.HorizontalAlignment = 'center'; @@ -191,7 +191,7 @@ InpE.FontUnits = 'Normalized'; InpE.FontSize = 0.6; InpE.Tag = 'InpE'; -%% create input and text fields (linewidth) +%% create input and text fields (linewidths) textLW = uicontrol(fig,'Style','text'); textLW.String = 'Linewidth variations'; textLW.Units = 'Normalized'; From 296ff9c6f5011cb5062395422f8063ff3ada417b Mon Sep 17 00:00:00 2001 From: sakul-45 <81963567+sakul-45@users.noreply.github.com> Date: Thu, 29 Jul 2021 18:03:22 +0200 Subject: [PATCH 2/5] Autosave in Done button --- simulation_TREPR.m | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/simulation_TREPR.m b/simulation_TREPR.m index af29e93..963bf4b 100644 --- a/simulation_TREPR.m +++ b/simulation_TREPR.m @@ -25,6 +25,7 @@ eventdata.manExp.Harmonic = 0; % zeroth harmonic eventdata.manExp.Temperature = params.Triplett_pop; eventdata.simSys = params.Manual_Sys; %initialize simulation parameters eventdata.simExp = eventdata.manExp; +eventdata.SaveStat = 0; %counter if save button was pushed %% creating UI fig = figure; @@ -349,10 +350,16 @@ uiwait(fig) eventdata.simExp.Temperature = eventdata.BestSys.Temperature; %save fitted parameters to struct params.Fitted_Simulation = eventdata.BestSys; + eventdata.SaveStat = eventdata.SaveStat + 1; end function SimDoneButtonPushed(~,~) - close 'Simulation' + if eventdata.SaveStat == 0 + params.Fitted_Simulation = eventdata.BestSys; + close 'Simulation' + else + close 'Simulation' + end end end \ No newline at end of file From ce64931f6bdb734215a92570b45170b6809bb425 Mon Sep 17 00:00:00 2001 From: sakul-45 <81963567+sakul-45@users.noreply.github.com> Date: Thu, 29 Jul 2021 19:08:34 +0200 Subject: [PATCH 3/5] Fixed field vector importing --- TR_EPR_script.m | 6 ++++-- load_bruker.m | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/TR_EPR_script.m b/TR_EPR_script.m index 2df6956..5b813de 100644 --- a/TR_EPR_script.m +++ b/TR_EPR_script.m @@ -4,9 +4,11 @@ close all %Script for calling the functions of TR-EPR toolbox %path to dataset -datapath = 'C:\Users\lukas\Nextcloud\Uni\Bachelorarbeit\tr-epr-simulation\example_data.mat'; +% datapath = 'C:\Users\lukas\Nextcloud\Uni\Bachelorarbeit\tr-epr-simulation\example_data.mat'; +% [raw_data,params] = load_matlab(datapath); -[raw_data,params] = load_matlab(datapath); +datapath = 'C:\Users\lukas\Nextcloud\Uni\Bachelorarbeit\tr-epr-simulation\pentacene_355nm_481pt.DSC'; +[raw_data,params] = load_bruker(datapath); [time_corr_data,params] = correct_time_baseline(raw_data,params); diff --git a/load_bruker.m b/load_bruker.m index b6dd349..3de8487 100644 --- a/load_bruker.m +++ b/load_bruker.m @@ -47,7 +47,7 @@ params.Accumulations = bruker_params.AVGS; params.laser_shotreprate = "NOT RECORDED"; params.Field_Start = bruker_params.YMIN; params.Field_End = bruker_params.YMIN + bruker_params.YWID; -params.Field_Vector = cell2mat(bruker_axes(1,2)); +params.Field_Vector = cell2mat(bruker_axes(1,2)).'; params.mwFreq = bruker_params.MWFQ / 1e9; params.mwPower = bruker_params.MWPW * 1e3; params.QValue = "NOT RECORDED"; From 9bf1ba30f951970ecb70006d15f7f308fe2b230e Mon Sep 17 00:00:00 2001 From: sakul-45 <81963567+sakul-45@users.noreply.github.com> Date: Mon, 2 Aug 2021 11:39:00 +0200 Subject: [PATCH 4/5] renamed function --- normalize_data.m | 109 ----------------------------------------------- 1 file changed, 109 deletions(-) delete mode 100644 normalize_data.m diff --git a/normalize_data.m b/normalize_data.m deleted file mode 100644 index 81b3eab..0000000 --- a/normalize_data.m +++ /dev/null @@ -1,109 +0,0 @@ -function [dataOUT,params] = normalize_data(dataIN,params) -%NORMALISE_DATA normalizes data by max of region -% -% Usage: [dataOUT,params] = NORMALISE_DATA(dataIN,params), where dataIN -% is a dataset loaded via the LOAD_MATLAB or LOAD_BRUKER function. -% -% The function will show the input data and offer two input fields, where -% the left and right borders of the maximum's region should be set. -% By pressing "Apply" the normalization will be executed and the graph -% changes to the normalized data. The borders of the maximum region and -% the mean of maximums will also be appended to the params struct. -% By pressing "Reset" the graph will return to show the original data. -% Exit the function by pressing "Done". - -%% creating UI -fig = figure; -fig.Name = 'Normalize Data'; -fig.Units = 'Normalized'; -fig.Position = [.2 .2 .6 .6]; -fig.Tag = 'Normalize'; - -%panel for plot -plotpanel = uipanel(fig); -plotpanel.Units = 'Normalized'; -plotpanel.Position = [.01 .06 .98 .92]; -%axes for plot -ax = axes(plotpanel); -ax.XLabel.String = 'Time'; -ax.YLabel.String = 'Intensity'; -%plot current data in figure with time as x axis -plot(ax,dataIN) -axis tight - -%create push buttons -a = uicontrol(fig,'Style','pushbutton'); -a.String = 'Apply'; -a.Units = 'Normalized'; -a.Position = [.52 .01 .15 .05]; -a.FontUnits = 'Normalized'; -a.FontSize = 0.6; -a.Tag = 'Apply'; -a.Callback = @NormApplyButtonPushed; - -r = uicontrol(fig,'Style','pushbutton'); -r.String = 'Reset'; -r.Units = 'Normalized'; -r.Position = [.68 .01 .15 .05]; -r.FontUnits = 'Normalized'; -r.FontSize = 0.6; -r.Tag = 'Reset'; -r.Callback = @NormResetButtonPushed; - -d = uicontrol(fig,'Style','pushbutton'); -d.String = 'Done'; -d.Units = 'Normalized'; -d.Position = [.84 .01 .15 .05]; -d.FontUnits = 'Normalized'; -d.FontSize = 0.6; -d.Tag = 'Done'; -d.Callback = @NormDoneButtonPushed; - -%create input fields -p1 = uicontrol(fig,'Style','edit'); -p1.String = 'Left point of max region'; -p1.Units = 'Normalized'; -p1.Position = [.01 .01 .24 .05]; -p1.HorizontalAlignment = 'left'; -p1.FontUnits = 'Normalized'; -p1.FontSize = 0.6; -p1.Tag = 'MaxRegionLeft'; - -p2 = uicontrol(fig,'Style','edit'); -p2.String = 'Right point of max region'; -p2.Units = 'Normalized'; -p2.Position = [.25 .01 .24 .05]; -p2.HorizontalAlignment = 'left'; -p2.FontUnits = 'Normalized'; -p2.FontSize = 0.6; -p2.Tag = 'MaxRegionRight'; - -uicontrol(p1); %passes focus to first input -uiwait(fig) - -%% Callback functions - function NormApplyButtonPushed(~,~) - left_point = str2double(get(p1,'String')); - right_point = str2double(get(p2,'String')); - %take mean of each field line between specified min and max time - maxima_mean = mean(dataIN([left_point right_point],:)); - %normalize amplitude to 1 by dividing by max of means - dataOUT = dataIN / max(maxima_mean); - %plotting result with time as x axis - plot(ax,dataOUT) - axis tight - %writing parameter - params.region_of_max = [left_point right_point]; - params.max_mean = maxima_mean / max(maxima_mean); - end - - function NormResetButtonPushed(~,~) - plot(ax,dataIN) - axis tight - end - - function NormDoneButtonPushed(~,~) - close 'Normalize Data' - end - -end From dda28fdf6d8bbe63421b8f800e68716e5f71e111 Mon Sep 17 00:00:00 2001 From: sakul-45 <81963567+sakul-45@users.noreply.github.com> Date: Mon, 2 Aug 2021 11:42:06 +0200 Subject: [PATCH 5/5] trying to unstage --- example_data.xml | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/example_data.xml b/example_data.xml index 60c0d9f..04c6e78 100644 --- a/example_data.xml +++ b/example_data.xml @@ -11744,23 +11744,11 @@ 1 2 2150 - 70 + 75 8 0 0 0.71429 0.28571 - - 1 - 1.9934 - 2150.3379 - 66.695461 - 9 - 0 - 0 - 0.55912 - 0.44088 - 1 -