From 3552a63f81689fd03f552b375fdaed72ba793724 Mon Sep 17 00:00:00 2001 From: Isabell Whiteley <46966503+iwhiteley@users.noreply.github.com> Date: Tue, 12 Aug 2025 13:42:42 +0100 Subject: [PATCH 01/30] First commit for longitudinal analysis, electrical noise --- .../+longitudinal/long_electrical_noise.m | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 code/+mpqc/+longitudinal/long_electrical_noise.m diff --git a/code/+mpqc/+longitudinal/long_electrical_noise.m b/code/+mpqc/+longitudinal/long_electrical_noise.m new file mode 100644 index 0000000..f85c833 --- /dev/null +++ b/code/+mpqc/+longitudinal/long_electrical_noise.m @@ -0,0 +1,21 @@ +function long_electrical_noise(data_dir) + + + +if nargin<1 + data_dir = pwd; +end +d = dir(data_dir); + + +n=1; +for ii=1:length(d) + tmp = d(ii); + if contains(tmp.name,'electrical_noise') + out(n) = generic_generator_template(tmp); + out(n).type = 'electrical_noise'; + out(n).plotting_func = @mpqc.plot.electrical_noise; + n=n+1; + end +end +end \ No newline at end of file From b2b1f84ef75a1a3725b9a973ad28b90651d0866c Mon Sep 17 00:00:00 2001 From: Isabell Whiteley <46966503+iwhiteley@users.noreply.github.com> Date: Fri, 15 Aug 2025 16:24:51 +0100 Subject: [PATCH 02/30] Code not working, debugging --- .../+longitudinal/long_electrical_noise.m | 49 ++++++++++++++++--- code/testscript.m | 2 + 2 files changed, 43 insertions(+), 8 deletions(-) create mode 100644 code/testscript.m diff --git a/code/+mpqc/+longitudinal/long_electrical_noise.m b/code/+mpqc/+longitudinal/long_electrical_noise.m index f85c833..d5dadd5 100644 --- a/code/+mpqc/+longitudinal/long_electrical_noise.m +++ b/code/+mpqc/+longitudinal/long_electrical_noise.m @@ -1,21 +1,54 @@ -function long_electrical_noise(data_dir) +function [d,out] = long_electrical_noise(data_dir) if nargin<1 data_dir = pwd; end -d = dir(data_dir); +% d = dir(fullfile(data_dir,'**\*.*')%,contains('electrical_noise')); +d = dir(fullfile(data_dir))%,'**\*.*')%,contains('electrical_noise')); +d(~[d.isdir]) = []; % removes the non directories - -n=1; +subD = cell(length(d)); for ii=1:length(d) - tmp = d(ii); - if contains(tmp.name,'electrical_noise') - out(n) = generic_generator_template(tmp); + % tmp = d(ii); + subDir = d(ii).name; + subD{ii} = dir(fullfile(subDir));%, contains('electrical_noise')); + if contains(subD{ii}.name, 'electrical_noise') out(n).type = 'electrical_noise'; out(n).plotting_func = @mpqc.plot.electrical_noise; - n=n+1; end + % dir(data_dir,d.name) +% if contains(d.name,'electrical_noise') +% disp(d.name) +% end end +% n =1; +% if contains(d.name, 'electrical_noise') +% out(n).type = 'electrical_noise'; +% out(n).plotting_func = @mpqc.plot.electrical_noise; +% end + +n=1; +% for ii=1:length(d) +% tmp = d(ii); +% if contains(tmp.name,'electrical_noise') +% % out(n) = generic_generator_template(tmp); +% out(n).type = 'electrical_noise'; +% out(n).plotting_func = @mpqc.plot.electrical_noise; +% n=n+1; +% else +% disp('No files') +% end +% end + +% t_im = single(imstack(:,:,ii)); +% [n,x] = hist(t_im(:),100); +% a=area(x,n); +% +% +% a.EdgeColor=[0,0,0.75]; +% a.FaceColor=[0.5,0.5,1]; +% a.LineWidth=2; + end \ No newline at end of file diff --git a/code/testscript.m b/code/testscript.m new file mode 100644 index 0000000..a1d6ebb --- /dev/null +++ b/code/testscript.m @@ -0,0 +1,2 @@ +a = 1 +[d,out] = mpqc.longitudinal.long_electrical_noise('C:\Users\Isabell\Desktop\2p-313_diagnostics\') \ No newline at end of file From bdca4423ea36295c9f03460a060c1d9b3696a678 Mon Sep 17 00:00:00 2001 From: Isabell Whiteley <46966503+iwhiteley@users.noreply.github.com> Date: Mon, 18 Aug 2025 11:41:03 +0100 Subject: [PATCH 03/30] Can give the microscope diagnostics file and code identifies all noise measurement files and reads the noise tif file to the workspace. Currently also prints the noise data in command window --- .../+longitudinal/long_electrical_noise.m | 53 ++++++++----------- 1 file changed, 22 insertions(+), 31 deletions(-) diff --git a/code/+mpqc/+longitudinal/long_electrical_noise.m b/code/+mpqc/+longitudinal/long_electrical_noise.m index d5dadd5..a1be07a 100644 --- a/code/+mpqc/+longitudinal/long_electrical_noise.m +++ b/code/+mpqc/+longitudinal/long_electrical_noise.m @@ -1,47 +1,38 @@ -function [d,out] = long_electrical_noise(data_dir) +function [d,out,noiseData] = long_electrical_noise(data_dir) if nargin<1 data_dir = pwd; end -% d = dir(fullfile(data_dir,'**\*.*')%,contains('electrical_noise')); -d = dir(fullfile(data_dir))%,'**\*.*')%,contains('electrical_noise')); -d(~[d.isdir]) = []; % removes the non directories -subD = cell(length(d)); +d = dir(fullfile(data_dir,'\**')); +n=1; for ii=1:length(d) - % tmp = d(ii); - subDir = d(ii).name; - subD{ii} = dir(fullfile(subDir));%, contains('electrical_noise')); - if contains(subD{ii}.name, 'electrical_noise') + tmp = d(ii); + + if contains(tmp.name,'electrical_noise') + out(n) = generic_generator_template(tmp); out(n).type = 'electrical_noise'; out(n).plotting_func = @mpqc.plot.electrical_noise; + [pathstr,out(n).name,ext] = fileparts(tmp.name); + n=n+1; + % else + % disp('No files') end - % dir(data_dir,d.name) -% if contains(d.name,'electrical_noise') -% disp(d.name) -% end end -% n =1; -% if contains(d.name, 'electrical_noise') -% out(n).type = 'electrical_noise'; -% out(n).plotting_func = @mpqc.plot.electrical_noise; -% end - -n=1; -% for ii=1:length(d) -% tmp = d(ii); -% if contains(tmp.name,'electrical_noise') -% % out(n) = generic_generator_template(tmp); -% out(n).type = 'electrical_noise'; -% out(n).plotting_func = @mpqc.plot.electrical_noise; -% n=n+1; -% else -% disp('No files') -% end -% end +function out = generic_generator_template(t_dir) + out.full_path_to_data = fullfile(t_dir.folder,t_dir.name); + out.type = []; + out.plotting_func = []; + out.name = []; +end +for i = 1:length(out) + if contains(out(i).full_path_to_data, '.tif') + noiseData(:,:,i) = imread(out(i).full_path_to_data); + end +end % t_im = single(imstack(:,:,ii)); % [n,x] = hist(t_im(:),100); % a=area(x,n); From 94215adca7678cfe2262003218b95a6289ef509e Mon Sep 17 00:00:00 2001 From: Isabell Whiteley <46966503+iwhiteley@users.noreply.github.com> Date: Mon, 18 Aug 2025 16:51:04 +0100 Subject: [PATCH 04/30] Started on analysis for changes to noise over time, not yet working --- .../+longitudinal/long_electrical_noise.m | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/code/+mpqc/+longitudinal/long_electrical_noise.m b/code/+mpqc/+longitudinal/long_electrical_noise.m index a1be07a..b9af170 100644 --- a/code/+mpqc/+longitudinal/long_electrical_noise.m +++ b/code/+mpqc/+longitudinal/long_electrical_noise.m @@ -1,4 +1,4 @@ -function [d,out,noiseData] = long_electrical_noise(data_dir) +function [d,out,noiseData,fwhm] = long_electrical_noise(data_dir) @@ -33,13 +33,21 @@ noiseData(:,:,i) = imread(out(i).full_path_to_data); end end -% t_im = single(imstack(:,:,ii)); -% [n,x] = hist(t_im(:),100); -% a=area(x,n); +noiseData = single(noiseData); +fwhm = 1; +% for t = 1:size(noiseData,3) % + t_im = noiseData(:,:,t); +% % figure; + [n,x] = hist(t_im(:),100); % plots all data as histogram +% % a=area(x,n); +% % a.EdgeColor=[0,0,0.75]; +% % a.FaceColor=[0.5,0.5,1]; +% % a.LineWidth=2; % -% a.EdgeColor=[0,0,0.75]; -% a.FaceColor=[0.5,0.5,1]; -% a.LineWidth=2; - + halfMaxVal(t) = max(n(:))/2; + leftIndex = find(n(:) >= halfMaxVal, 1, 'first'); + rightIndex = find(n(:) >= halfMaxVal, 1, 'last'); + fwhm(t) = n(rightIndex) - n(leftIndex); +% end end \ No newline at end of file From 35a0b8ec93d6c961477baeb567fe4b49ab706785 Mon Sep 17 00:00:00 2001 From: Isabell Whiteley <46966503+iwhiteley@users.noreply.github.com> Date: Fri, 22 Aug 2025 16:16:56 +0100 Subject: [PATCH 05/30] Added FWHM loop to check change over time --- .../+longitudinal/long_electrical_noise.m | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/code/+mpqc/+longitudinal/long_electrical_noise.m b/code/+mpqc/+longitudinal/long_electrical_noise.m index b9af170..866b32d 100644 --- a/code/+mpqc/+longitudinal/long_electrical_noise.m +++ b/code/+mpqc/+longitudinal/long_electrical_noise.m @@ -34,20 +34,25 @@ end end noiseData = single(noiseData); -fwhm = 1; -% for t = 1:size(noiseData,3) +% fwhm = 1; +for t = 1:size(noiseData,3) % t_im = noiseData(:,:,t); + % t_im = noiseData(:,:,2); % % figure; [n,x] = hist(t_im(:),100); % plots all data as histogram -% % a=area(x,n); -% % a.EdgeColor=[0,0,0.75]; -% % a.FaceColor=[0.5,0.5,1]; -% % a.LineWidth=2; + figure; + a=area(x,n); + a.EdgeColor=[0,0,0.75]; + a.FaceColor=[0.5,0.5,1]; + a.LineWidth=2; % - halfMaxVal(t) = max(n(:))/2; - leftIndex = find(n(:) >= halfMaxVal, 1, 'first'); + % halfMaxVal(t) = max(n(:))/2; + halfMaxVal = max(n(:))/2; + leftIndex = find(n(:) >= halfMaxVal, 1, 'first'); rightIndex = find(n(:) >= halfMaxVal, 1, 'last'); fwhm(t) = n(rightIndex) - n(leftIndex); -% end + % fwhm = n(rightIndex) - n(leftIndex); +end +figure; plot(fwhm) end \ No newline at end of file From a1d6accce6b876b972f226f800f5c148d7b54e42 Mon Sep 17 00:00:00 2001 From: Isabell Whiteley <46966503+iwhiteley@users.noreply.github.com> Date: Fri, 29 Aug 2025 10:46:25 +0100 Subject: [PATCH 06/30] Added Gaussian smoothing of the hist data and FWHM measurements --- .../+longitudinal/long_electrical_noise.m | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/code/+mpqc/+longitudinal/long_electrical_noise.m b/code/+mpqc/+longitudinal/long_electrical_noise.m index 866b32d..622dd3c 100644 --- a/code/+mpqc/+longitudinal/long_electrical_noise.m +++ b/code/+mpqc/+longitudinal/long_electrical_noise.m @@ -38,21 +38,24 @@ for t = 1:size(noiseData,3) % t_im = noiseData(:,:,t); - % t_im = noiseData(:,:,2); -% % figure; [n,x] = hist(t_im(:),100); % plots all data as histogram figure; - a=area(x,n); + a=area(n); a.EdgeColor=[0,0,0.75]; a.FaceColor=[0.5,0.5,1]; a.LineWidth=2; -% - % halfMaxVal(t) = max(n(:))/2; - halfMaxVal = max(n(:))/2; - leftIndex = find(n(:) >= halfMaxVal, 1, 'first'); - rightIndex = find(n(:) >= halfMaxVal, 1, 'last'); - fwhm(t) = n(rightIndex) - n(leftIndex); - % fwhm = n(rightIndex) - n(leftIndex); + hold on + m = smoothdata(n,'gaussian',5); + detail = interp1(x,m,[1:1000]); + b = plot(m); + b.LineWidth = 2; + + hold off + + halfMaxVal = max(detail(:))/2; + leftIndex = find(detail(:) >= halfMaxVal, 1, 'first'); + rightIndex = find(detail(:) >= halfMaxVal, 1, 'last'); + fwhm(t) = rightIndex -leftIndex; end figure; plot(fwhm) end \ No newline at end of file From f4c216b389daff16842ade3f0353e83ac611c087 Mon Sep 17 00:00:00 2001 From: Isabell Whiteley <46966503+iwhiteley@users.noreply.github.com> Date: Fri, 29 Aug 2025 10:54:51 +0100 Subject: [PATCH 07/30] now only looks for .tif files --- code/+mpqc/+longitudinal/long_electrical_noise.m | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/code/+mpqc/+longitudinal/long_electrical_noise.m b/code/+mpqc/+longitudinal/long_electrical_noise.m index 622dd3c..d7c8f88 100644 --- a/code/+mpqc/+longitudinal/long_electrical_noise.m +++ b/code/+mpqc/+longitudinal/long_electrical_noise.m @@ -6,12 +6,12 @@ data_dir = pwd; end -d = dir(fullfile(data_dir,'\**')); +d = dir(fullfile(data_dir,'\**\*.tif')); n=1; for ii=1:length(d) tmp = d(ii); - if contains(tmp.name,'electrical_noise') + if contains(tmp.name,'electrical_noise')% && contains(tmp.name) out(n) = generic_generator_template(tmp); out(n).type = 'electrical_noise'; out(n).plotting_func = @mpqc.plot.electrical_noise; @@ -51,11 +51,15 @@ b.LineWidth = 2; hold off - - halfMaxVal = max(detail(:))/2; + maxVal(t) = max(detail(:)); + halfMaxVal = maxVal(t)/2; leftIndex = find(detail(:) >= halfMaxVal, 1, 'first'); rightIndex = find(detail(:) >= halfMaxVal, 1, 'last'); fwhm(t) = rightIndex -leftIndex; end -figure; plot(fwhm) +figure; +subplot(2,1,1) +plot(maxVal) +subplot(2,1,2) +plot(fwhm) end \ No newline at end of file From abee3e6b5f2521af9b5fead1e61c07828d22a229 Mon Sep 17 00:00:00 2001 From: Isabell Whiteley <46966503+iwhiteley@users.noreply.github.com> Date: Fri, 29 Aug 2025 15:49:48 +0100 Subject: [PATCH 08/30] Added date labels for x axis on plots and gave brief description of the function --- .../+longitudinal/long_electrical_noise.m | 71 ++++++++++++------- 1 file changed, 47 insertions(+), 24 deletions(-) diff --git a/code/+mpqc/+longitudinal/long_electrical_noise.m b/code/+mpqc/+longitudinal/long_electrical_noise.m index d7c8f88..eef0900 100644 --- a/code/+mpqc/+longitudinal/long_electrical_noise.m +++ b/code/+mpqc/+longitudinal/long_electrical_noise.m @@ -1,6 +1,15 @@ function [d,out,noiseData,fwhm] = long_electrical_noise(data_dir) - - +% Longitudinal electrical noise plots +% +% mpqc.longitudinal.long_electrical_noise +% +% Purpose +% Plots of the maximum value and FWHM of electrical noise for each channel +% with PMTs off. If there is significant change in electrical noise, the FWHM +% distributions will likely increase in value. +% +% +% Isabell Whiteley, SWC AMF if nargin<1 data_dir = pwd; @@ -11,55 +20,69 @@ for ii=1:length(d) tmp = d(ii); - if contains(tmp.name,'electrical_noise')% && contains(tmp.name) + if contains(tmp.name,'electrical_noise') out(n) = generic_generator_template(tmp); out(n).type = 'electrical_noise'; out(n).plotting_func = @mpqc.plot.electrical_noise; + out(n).date = string(tmp.date); [pathstr,out(n).name,ext] = fileparts(tmp.name); n=n+1; - % else - % disp('No files') + % else + % disp('No files') end end -function out = generic_generator_template(t_dir) - out.full_path_to_data = fullfile(t_dir.folder,t_dir.name); - out.type = []; - out.plotting_func = []; - out.name = []; -end + function out = generic_generator_template(t_dir) + out.full_path_to_data = fullfile(t_dir.folder,t_dir.name); + out.type = []; + out.plotting_func = []; + out.name = []; + out.date = []; + end + for i = 1:length(out) if contains(out(i).full_path_to_data, '.tif') noiseData(:,:,i) = imread(out(i).full_path_to_data); end end + noiseData = single(noiseData); % fwhm = 1; for t = 1:size(noiseData,3) -% + % t_im = noiseData(:,:,t); [n,x] = hist(t_im(:),100); % plots all data as histogram - figure; - a=area(n); - a.EdgeColor=[0,0,0.75]; - a.FaceColor=[0.5,0.5,1]; - a.LineWidth=2; - hold on + % figure; + % a=area(n); + % a.EdgeColor=[0,0,0.75]; + % a.FaceColor=[0.5,0.5,1]; + % a.LineWidth=2; + % hold on m = smoothdata(n,'gaussian',5); detail = interp1(x,m,[1:1000]); - b = plot(m); - b.LineWidth = 2; - - hold off + % b = plot(m); + % b.LineWidth = 2; + % title(out(t).date) + % + % hold off maxVal(t) = max(detail(:)); halfMaxVal = maxVal(t)/2; - leftIndex = find(detail(:) >= halfMaxVal, 1, 'first'); + leftIndex = find(detail(:) >= halfMaxVal, 1, 'first'); rightIndex = find(detail(:) >= halfMaxVal, 1, 'last'); fwhm(t) = rightIndex -leftIndex; end -figure; + +xlabels = {out.date}; +figure; subplot(2,1,1) plot(maxVal) +xticks(1:length(xlabels)) +xticklabels(xlabels) +title('Max value') + subplot(2,1,2) plot(fwhm) +xticks(1:length(xlabels)) +xticklabels(xlabels) +title('FWHM') end \ No newline at end of file From 32a6ca21a101c837967b175ee452eccde9f1dd6b Mon Sep 17 00:00:00 2001 From: Isabell Whiteley <46966503+iwhiteley@users.noreply.github.com> Date: Mon, 1 Sep 2025 16:40:38 +0100 Subject: [PATCH 09/30] Changed load to scanImage_stackLoad to all PMT recordings are loaded into function. Added for loop to separate and track individual PMTs, not yet working --- .../+longitudinal/long_electrical_noise.m | 78 ++++++++++--------- 1 file changed, 41 insertions(+), 37 deletions(-) diff --git a/code/+mpqc/+longitudinal/long_electrical_noise.m b/code/+mpqc/+longitudinal/long_electrical_noise.m index eef0900..19f693d 100644 --- a/code/+mpqc/+longitudinal/long_electrical_noise.m +++ b/code/+mpqc/+longitudinal/long_electrical_noise.m @@ -42,47 +42,51 @@ for i = 1:length(out) if contains(out(i).full_path_to_data, '.tif') - noiseData(:,:,i) = imread(out(i).full_path_to_data); + % noiseData(:,:,i) = imread(out(i).full_path_to_data); + noiseData(:,:,:,i) = mpqc.tools.scanImage_stackLoad(out(i).full_path_to_data); end end noiseData = single(noiseData); -% fwhm = 1; -for t = 1:size(noiseData,3) - % - t_im = noiseData(:,:,t); - [n,x] = hist(t_im(:),100); % plots all data as histogram - % figure; - % a=area(n); - % a.EdgeColor=[0,0,0.75]; - % a.FaceColor=[0.5,0.5,1]; - % a.LineWidth=2; - % hold on - m = smoothdata(n,'gaussian',5); - detail = interp1(x,m,[1:1000]); - % b = plot(m); - % b.LineWidth = 2; - % title(out(t).date) - % - % hold off - maxVal(t) = max(detail(:)); - halfMaxVal = maxVal(t)/2; - leftIndex = find(detail(:) >= halfMaxVal, 1, 'first'); - rightIndex = find(detail(:) >= halfMaxVal, 1, 'last'); - fwhm(t) = rightIndex -leftIndex; -end +fwhm = 1; % TEMPORARY to allow script to run +for q = 1:size(noiseData,4) + for t = 1:size(noiseData,3) + % + subplot(2,2,t) + t_im = noiseData(:,:,t,q); + [n,x] = hist(t_im(:),100); % plots all data as histogram + figure; + a=area(n); + a.EdgeColor=[0,0,0.75]; + a.FaceColor=[0.5,0.5,1]; + a.LineWidth=2; + hold on + m = smoothdata(n,'gaussian',5); + detail = interp1(x,m,[1:1000]); + b = plot(m); + b.LineWidth = 2; + title(out(t).date) -xlabels = {out.date}; -figure; -subplot(2,1,1) -plot(maxVal) -xticks(1:length(xlabels)) -xticklabels(xlabels) -title('Max value') + hold off + % maxVal(t,q) = max(detail(:)); + % halfMaxVal = maxVal(t,q)/2; + % leftIndex = find(detail(:) >= halfMaxVal, 1, 'first'); + % rightIndex = find(detail(:) >= halfMaxVal, 1, 'last'); + % fwhm(t,q) = rightIndex -leftIndex; + end +end -subplot(2,1,2) -plot(fwhm) -xticks(1:length(xlabels)) -xticklabels(xlabels) -title('FWHM') +% xlabels = {out.date}; +% figure; +% subplot(2,1,1) +% plot(maxVal) +% xticks(1:length(xlabels)) +% xticklabels(xlabels) +% title('Max value') +% +% subplot(2,1,2) +% plot(fwhm) +% xticks(1:length(xlabels)) +% xticklabels(xlabels) +% title('FWHM') end \ No newline at end of file From acbc1b5d299d3d1bb5b8f0e4752c4819e21a0c1e Mon Sep 17 00:00:00 2001 From: Isabell Whiteley <46966503+iwhiteley@users.noreply.github.com> Date: Tue, 2 Sep 2025 11:29:05 +0100 Subject: [PATCH 10/30] Fixed plotting and titles so date is main title and PMT number is subplot title --- code/+mpqc/+longitudinal/long_electrical_noise.m | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/code/+mpqc/+longitudinal/long_electrical_noise.m b/code/+mpqc/+longitudinal/long_electrical_noise.m index 19f693d..223974f 100644 --- a/code/+mpqc/+longitudinal/long_electrical_noise.m +++ b/code/+mpqc/+longitudinal/long_electrical_noise.m @@ -49,13 +49,15 @@ noiseData = single(noiseData); fwhm = 1; % TEMPORARY to allow script to run -for q = 1:size(noiseData,4) - for t = 1:size(noiseData,3) +for q = 1:size(noiseData,4) % each date + figure; + for t = 1:size(noiseData,3) % each PMT % + subplot(2,2,t) t_im = noiseData(:,:,t,q); [n,x] = hist(t_im(:),100); % plots all data as histogram - figure; + a=area(n); a.EdgeColor=[0,0,0.75]; a.FaceColor=[0.5,0.5,1]; @@ -65,7 +67,8 @@ detail = interp1(x,m,[1:1000]); b = plot(m); b.LineWidth = 2; - title(out(t).date) + sgtitle(out(q).date) + title(['PMT # ',num2str(t)]) hold off % maxVal(t,q) = max(detail(:)); From b61b3f757eea52e3edd858478bec70f944c67b99 Mon Sep 17 00:00:00 2001 From: Isabell Whiteley <46966503+iwhiteley@users.noreply.github.com> Date: Tue, 2 Sep 2025 11:44:35 +0100 Subject: [PATCH 11/30] Updated FWHM and max value plots to separate each PMT --- .../+longitudinal/long_electrical_noise.m | 41 ++++++++++--------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/code/+mpqc/+longitudinal/long_electrical_noise.m b/code/+mpqc/+longitudinal/long_electrical_noise.m index 223974f..f263c32 100644 --- a/code/+mpqc/+longitudinal/long_electrical_noise.m +++ b/code/+mpqc/+longitudinal/long_electrical_noise.m @@ -48,7 +48,7 @@ end noiseData = single(noiseData); -fwhm = 1; % TEMPORARY to allow script to run +% fwhm = 1; % TEMPORARY to allow script to run for q = 1:size(noiseData,4) % each date figure; for t = 1:size(noiseData,3) % each PMT @@ -71,25 +71,28 @@ title(['PMT # ',num2str(t)]) hold off - % maxVal(t,q) = max(detail(:)); - % halfMaxVal = maxVal(t,q)/2; - % leftIndex = find(detail(:) >= halfMaxVal, 1, 'first'); - % rightIndex = find(detail(:) >= halfMaxVal, 1, 'last'); - % fwhm(t,q) = rightIndex -leftIndex; + maxVal(t,q) = max(detail(:)); + halfMaxVal = maxVal(t,q)/2; + leftIndex = find(detail(:) >= halfMaxVal, 1, 'first'); + rightIndex = find(detail(:) >= halfMaxVal, 1, 'last'); + fwhm(t,q) = rightIndex -leftIndex; end end -% xlabels = {out.date}; -% figure; -% subplot(2,1,1) -% plot(maxVal) -% xticks(1:length(xlabels)) -% xticklabels(xlabels) -% title('Max value') -% -% subplot(2,1,2) -% plot(fwhm) -% xticks(1:length(xlabels)) -% xticklabels(xlabels) -% title('FWHM') +for iii = 1:size(noiseData,3) % plotting FWHM and max value over time for each PMT + xlabels = {out.date}; + figure; + subplot(2,1,1) + plot(maxVal(iii,:)) + xticks(1:length(xlabels)) + xticklabels(xlabels) + title('Max value') + + subplot(2,1,2) + plot(fwhm(iii,:)) + xticks(1:length(xlabels)) + xticklabels(xlabels) + title('FWHM') +sgtitle(['PMT # ',num2str(iii)]) +end end \ No newline at end of file From 4c4588d2b66146ac8678aa0e3078eb4549f51fcf Mon Sep 17 00:00:00 2001 From: Isabell Whiteley <46966503+iwhiteley@users.noreply.github.com> Date: Wed, 3 Sep 2025 11:51:25 +0100 Subject: [PATCH 12/30] Changed to varargout, and made structure for previous outputs, moved generic_generator_template function to outside of long_elec func, added debug plots so can change to false if we don't want all the electrical noise histograms, reordered main for loop so data analysis done before plotting --- .../+longitudinal/long_electrical_noise.m | 204 ++++++++++-------- 1 file changed, 118 insertions(+), 86 deletions(-) diff --git a/code/+mpqc/+longitudinal/long_electrical_noise.m b/code/+mpqc/+longitudinal/long_electrical_noise.m index f263c32..e7e2e62 100644 --- a/code/+mpqc/+longitudinal/long_electrical_noise.m +++ b/code/+mpqc/+longitudinal/long_electrical_noise.m @@ -1,98 +1,130 @@ -function [d,out,noiseData,fwhm] = long_electrical_noise(data_dir) -% Longitudinal electrical noise plots -% -% mpqc.longitudinal.long_electrical_noise -% -% Purpose -% Plots of the maximum value and FWHM of electrical noise for each channel -% with PMTs off. If there is significant change in electrical noise, the FWHM -% distributions will likely increase in value. -% -% -% Isabell Whiteley, SWC AMF - -if nargin<1 - data_dir = pwd; -end +function varargout = long_electrical_noise(data_dir) + % Longitudinal electrical noise plots + % + % mpqc.longitudinal.long_electrical_noise + % + % Purpose + % Plots of the maximum value and FWHM of electrical noise for each channel + % with PMTs off. If there is significant change in electrical noise, the FWHM + % distributions will likely increase in value. + % + % + % Outputs + % out (optional) - structure containing key information and data. + % + % Isabell Whiteley, SWC AMF + + if nargin<1 + data_dir = pwd; + end -d = dir(fullfile(data_dir,'\**\*.tif')); -n=1; -for ii=1:length(d) - tmp = d(ii); - if contains(tmp.name,'electrical_noise') - out(n) = generic_generator_template(tmp); - out(n).type = 'electrical_noise'; - out(n).plotting_func = @mpqc.plot.electrical_noise; - out(n).date = string(tmp.date); - [pathstr,out(n).name,ext] = fileparts(tmp.name); - n=n+1; - % else - % disp('No files') + debugPlots = true; + + d = dir(fullfile(data_dir,'\**\*.tif')); % cTODO -- change "d" to a more descriptive name + n=1; + for ii=1:length(d) + tmp = d(ii); + + if contains(tmp.name,'electrical_noise') + plotting_template(n) = generic_generator_template(tmp); + plotting_template(n).type = 'electrical_noise'; + plotting_template(n).plotting_func = @mpqc.plot.electrical_noise; + plotting_template(n).date = string(tmp.date); + [pathstr,plotting_template(n).name,ext] = fileparts(tmp.name); + n=n+1; + % else + % disp('No files') + end + end + + + + for ii = 1:length(plotting_template) + if contains(plotting_template(ii).full_path_to_data, '.tif') + % noiseData(:,:,ii) = imread(out(i).full_path_to_data); + noiseData(:,:,:,ii) = mpqc.tools.scanImage_stackLoad(plotting_template(ii).full_path_to_data); + end end -end + + noiseData = single(noiseData); + % fwhm = 1; % TEMPORARY to allow script to run + for q = 1:size(noiseData,4) % each date + + if debugPlots + fig = mpqc.tools.returnFigureHandleForFile(sprintf('%s_%02d',mfilename,q)); + end + for t = 1:size(noiseData,3) % each PMT + % + + + % Extract data + t_im = noiseData(:,:,t,q); + [n,x] = hist(t_im(:),100); % plots all data as histogram + m = smoothdata(n,'gaussian',5); + detail = interp1(x,m,[1:1000]); + + maxVal(t,q) = max(detail(:)); + halfMaxVal = maxVal(t,q)/2; + leftIndex = find(detail(:) >= halfMaxVal, 1, 'first'); + rightIndex = find(detail(:) >= halfMaxVal, 1, 'last'); + fwhm(t,q) = rightIndex -leftIndex; - function out = generic_generator_template(t_dir) - out.full_path_to_data = fullfile(t_dir.folder,t_dir.name); - out.type = []; - out.plotting_func = []; - out.name = []; - out.date = []; + % Optionally plot + if debugPlots + subplot(2,2,t) + a=area(n); + a.EdgeColor=[0,0,0.75]; + a.FaceColor=[0.5,0.5,1]; + a.LineWidth=2; + hold on + b = plot(m); + b.LineWidth = 2; + sgtitle(plotting_template(q).date) + title(['PMT # ',num2str(t)]) + hold off + end + + + + end + end + + for ii = 1:size(noiseData,3) % plotting FWHM and max value over time for each PMT + xlabels = {plotting_template.date}; + fig = mpqc.tools.returnFigureHandleForFile(sprintf('%s_%02d',mfilename,ii)); + subplot(2,1,1) + plot(maxVal(ii,:)) + xticks(1:length(xlabels)) + xticklabels(xlabels) + title('Max value') + + subplot(2,1,2) + plot(fwhm(ii,:)) + xticks(1:length(xlabels)) + xticklabels(xlabels) + title('FWHM') + sgtitle(['PMT # ',num2str(ii)]) end -for i = 1:length(out) - if contains(out(i).full_path_to_data, '.tif') - % noiseData(:,:,i) = imread(out(i).full_path_to_data); - noiseData(:,:,:,i) = mpqc.tools.scanImage_stackLoad(out(i).full_path_to_data); + + % Output of the main function + if nargout>0 + out.directoryName = d; + out.noiseData = noiseData; + %out.fwhm = [plotting_template.fwhm]; + out.date ={plotting_template(:).date}; + varargout{1} = out; end -end -noiseData = single(noiseData); -% fwhm = 1; % TEMPORARY to allow script to run -for q = 1:size(noiseData,4) % each date - figure; - for t = 1:size(noiseData,3) % each PMT - % - - subplot(2,2,t) - t_im = noiseData(:,:,t,q); - [n,x] = hist(t_im(:),100); % plots all data as histogram - - a=area(n); - a.EdgeColor=[0,0,0.75]; - a.FaceColor=[0.5,0.5,1]; - a.LineWidth=2; - hold on - m = smoothdata(n,'gaussian',5); - detail = interp1(x,m,[1:1000]); - b = plot(m); - b.LineWidth = 2; - sgtitle(out(q).date) - title(['PMT # ',num2str(t)]) +end % close main funtion - hold off - maxVal(t,q) = max(detail(:)); - halfMaxVal = maxVal(t,q)/2; - leftIndex = find(detail(:) >= halfMaxVal, 1, 'first'); - rightIndex = find(detail(:) >= halfMaxVal, 1, 'last'); - fwhm(t,q) = rightIndex -leftIndex; - end -end -for iii = 1:size(noiseData,3) % plotting FWHM and max value over time for each PMT - xlabels = {out.date}; - figure; - subplot(2,1,1) - plot(maxVal(iii,:)) - xticks(1:length(xlabels)) - xticklabels(xlabels) - title('Max value') - subplot(2,1,2) - plot(fwhm(iii,:)) - xticks(1:length(xlabels)) - xticklabels(xlabels) - title('FWHM') -sgtitle(['PMT # ',num2str(iii)]) -end +function out = generic_generator_template(t_dir) + out.full_path_to_data = fullfile(t_dir.folder,t_dir.name); + out.type = []; + out.plotting_func = []; + out.name = []; + out.date = []; end \ No newline at end of file From 254924afb46c8b1593b17a55e4f9ebc8c93e5a52 Mon Sep 17 00:00:00 2001 From: Isabell Whiteley <46966503+iwhiteley@users.noreply.github.com> Date: Thu, 4 Sep 2025 16:41:17 +0100 Subject: [PATCH 13/30] Sorted data by date and time --- code/+mpqc/+longitudinal/long_electrical_noise.m | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/code/+mpqc/+longitudinal/long_electrical_noise.m b/code/+mpqc/+longitudinal/long_electrical_noise.m index e7e2e62..fe48fa7 100644 --- a/code/+mpqc/+longitudinal/long_electrical_noise.m +++ b/code/+mpqc/+longitudinal/long_electrical_noise.m @@ -38,7 +38,10 @@ end end - + % sort plotting_template data by the date/time + date_list = [plotting_template.date]; + [~,order] = sort(datenum(date_list,'dd-mm-yyyy hh:MM:ss'),1,'ascend'); + plotting_template = plotting_template(order); for ii = 1:length(plotting_template) if contains(plotting_template(ii).full_path_to_data, '.tif') From b3d509d2b37140011dcedaa9fe2ed327974d6b21 Mon Sep 17 00:00:00 2001 From: Isabell Whiteley <46966503+iwhiteley@users.noreply.github.com> Date: Thu, 4 Sep 2025 16:54:16 +0100 Subject: [PATCH 14/30] Updated output to include FWHM and max values, changed to output file name rather than the full directory, but not sure necessary --- code/+mpqc/+longitudinal/long_electrical_noise.m | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/code/+mpqc/+longitudinal/long_electrical_noise.m b/code/+mpqc/+longitudinal/long_electrical_noise.m index fe48fa7..93bc9d4 100644 --- a/code/+mpqc/+longitudinal/long_electrical_noise.m +++ b/code/+mpqc/+longitudinal/long_electrical_noise.m @@ -113,9 +113,11 @@ % Output of the main function if nargout>0 - out.directoryName = d; + out.fileName = {plotting_template(:).name}; out.noiseData = noiseData; - %out.fwhm = [plotting_template.fwhm]; + % out.fwhm = [plotting_template.fwhm]; + out.fwhm = fwhm; + out.maxValues = maxVal; out.date ={plotting_template(:).date}; varargout{1} = out; end From 415932df6c74385d7c32c2df880914eab9284efe Mon Sep 17 00:00:00 2001 From: Isabell Whiteley <46966503+iwhiteley@users.noreply.github.com> Date: Thu, 4 Sep 2025 17:40:08 +0100 Subject: [PATCH 15/30] Code clean up and minor edits to description --- code/+mpqc/+longitudinal/long_electrical_noise.m | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/code/+mpqc/+longitudinal/long_electrical_noise.m b/code/+mpqc/+longitudinal/long_electrical_noise.m index 93bc9d4..729b242 100644 --- a/code/+mpqc/+longitudinal/long_electrical_noise.m +++ b/code/+mpqc/+longitudinal/long_electrical_noise.m @@ -1,7 +1,8 @@ function varargout = long_electrical_noise(data_dir) % Longitudinal electrical noise plots % - % mpqc.longitudinal.long_electrical_noise + % mpqc.longitudinal.long_electrical_noise(maintenace_folder_path) + % TODO - change to varargin so can give a date range to use % % Purpose % Plots of the maximum value and FWHM of electrical noise for each channel @@ -34,7 +35,7 @@ [pathstr,plotting_template(n).name,ext] = fileparts(tmp.name); n=n+1; % else - % disp('No files') + % TODO add else for it no files found end end @@ -45,21 +46,18 @@ for ii = 1:length(plotting_template) if contains(plotting_template(ii).full_path_to_data, '.tif') - % noiseData(:,:,ii) = imread(out(i).full_path_to_data); noiseData(:,:,:,ii) = mpqc.tools.scanImage_stackLoad(plotting_template(ii).full_path_to_data); end end noiseData = single(noiseData); - % fwhm = 1; % TEMPORARY to allow script to run + for q = 1:size(noiseData,4) % each date if debugPlots fig = mpqc.tools.returnFigureHandleForFile(sprintf('%s_%02d',mfilename,q)); end for t = 1:size(noiseData,3) % each PMT - % - % Extract data t_im = noiseData(:,:,t,q); @@ -87,9 +85,6 @@ title(['PMT # ',num2str(t)]) hold off end - - - end end @@ -115,7 +110,6 @@ if nargout>0 out.fileName = {plotting_template(:).name}; out.noiseData = noiseData; - % out.fwhm = [plotting_template.fwhm]; out.fwhm = fwhm; out.maxValues = maxVal; out.date ={plotting_template(:).date}; From 15d338462185958f30524f6afc67c9e9ede47b37 Mon Sep 17 00:00:00 2001 From: Isabell Whiteley <46966503+iwhiteley@users.noreply.github.com> Date: Fri, 5 Sep 2025 16:23:52 +0100 Subject: [PATCH 16/30] Starting varargin for selecting starting date for the data to plot/analyse --- .../+longitudinal/long_electrical_noise.m | 49 +++++++++++++------ 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/code/+mpqc/+longitudinal/long_electrical_noise.m b/code/+mpqc/+longitudinal/long_electrical_noise.m index 729b242..096c9ab 100644 --- a/code/+mpqc/+longitudinal/long_electrical_noise.m +++ b/code/+mpqc/+longitudinal/long_electrical_noise.m @@ -1,7 +1,8 @@ -function varargout = long_electrical_noise(data_dir) +function varargout = long_electrical_noise(data_dir,varargin) % Longitudinal electrical noise plots % - % mpqc.longitudinal.long_electrical_noise(maintenace_folder_path) + % mpqc.longitudinal.long_electrical_noise(maintenace_folder_path, varargin) + % Optional inputs: Starting date % TODO - change to varargin so can give a date range to use % % Purpose @@ -24,24 +25,42 @@ d = dir(fullfile(data_dir,'\**\*.tif')); % cTODO -- change "d" to a more descriptive name n=1; - for ii=1:length(d) - tmp = d(ii); - if contains(tmp.name,'electrical_noise') - plotting_template(n) = generic_generator_template(tmp); - plotting_template(n).type = 'electrical_noise'; - plotting_template(n).plotting_func = @mpqc.plot.electrical_noise; - plotting_template(n).date = string(tmp.date); - [pathstr,plotting_template(n).name,ext] = fileparts(tmp.name); - n=n+1; - % else - % TODO add else for it no files found + for ii=1:length(d) + tmp = d(ii); + + if contains(tmp.name,'electrical_noise') + plotting_template(n) = generic_generator_template(tmp); + plotting_template(n).type = 'electrical_noise'; + plotting_template(n).plotting_func = @mpqc.plot.electrical_noise; + plotting_template(n).date = string(tmp.date); + [pathstr,plotting_template(n).name,ext] = fileparts(tmp.name); + n=n+1; + % else + % TODO add else for it no files found + end end - end - + + % if nargin>1 + % Can either choose not to find files before a date, or + % choose not to analyse files before the date, 2nd option + % more simple and done in same area as ordering by date + % + % end + + % sort plotting_template data by the date/time date_list = [plotting_template.date]; [~,order] = sort(datenum(date_list,'dd-mm-yyyy hh:MM:ss'),1,'ascend'); + + if nargin > 1 + % take out dates from the order based on the given input date + startDate = datetime(varargin{1}); + if plotting_template.date % is equal to or later than startDate keep + % order = order(withoutdates); + end + end + plotting_template = plotting_template(order); for ii = 1:length(plotting_template) From 9473591efca721473a150fe2ee0611b8cc20e2fe Mon Sep 17 00:00:00 2001 From: Isabell Whiteley <46966503+iwhiteley@users.noreply.github.com> Date: Wed, 18 Jun 2025 11:16:40 +0100 Subject: [PATCH 17/30] Minor update to README.md Fixed lens_paper function name typo and added electrical_noise main function --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index abbbe9e..af94fc5 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,9 @@ and for measuring field of view size using an EM grid. ## Main functions * `mpqc.record.PSF` to easily acquire PSF stacks with ScanImage. -* `mpqc.record.lens_tissue` to acquire standardised data from lens tissue. +* `mpqc.record.lens_paper` to acquire standardised data from lens tissue. * `mpqc.record.standard_light_source` to data from a standard light source +* `mpqc.record.electrical_noise` to measure the electrical noise of the PMTs. * `measurePSF` to estimate PSF size. For a demo, run `measurePSF('demo')`. * `Grid2MicsPerPixel` measures the number of microns per pixel along x and y by analyzing an image of an EM grid. * `mpqc.tools.meanFrame` plots the mean frame intensity as a function of time whilst you are scanning. From 12798d9f3b94fc185b5ce333829df677bf1cbfef Mon Sep 17 00:00:00 2001 From: Isabell Whiteley Date: Mon, 8 Sep 2025 12:24:46 +0100 Subject: [PATCH 18/30] Changed the date read to take from the file name rather than file creation date, bug fix for if data has been moved around and original date lost --- code/+mpqc/+longitudinal/long_electrical_noise.m | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/code/+mpqc/+longitudinal/long_electrical_noise.m b/code/+mpqc/+longitudinal/long_electrical_noise.m index 096c9ab..9bb8fc3 100644 --- a/code/+mpqc/+longitudinal/long_electrical_noise.m +++ b/code/+mpqc/+longitudinal/long_electrical_noise.m @@ -33,7 +33,7 @@ plotting_template(n) = generic_generator_template(tmp); plotting_template(n).type = 'electrical_noise'; plotting_template(n).plotting_func = @mpqc.plot.electrical_noise; - plotting_template(n).date = string(tmp.date); + plotting_template(n).date = string(datetime(regexp(tmp.name, '(\d{4}-\d{2}-\d{2})_(\d{2}-\d{2}-\d{2})','match'),'InputFormat','yyyy-MM-dd_HH-mm-ss')); [pathstr,plotting_template(n).name,ext] = fileparts(tmp.name); n=n+1; % else @@ -53,13 +53,13 @@ date_list = [plotting_template.date]; [~,order] = sort(datenum(date_list,'dd-mm-yyyy hh:MM:ss'),1,'ascend'); - if nargin > 1 - % take out dates from the order based on the given input date - startDate = datetime(varargin{1}); - if plotting_template.date % is equal to or later than startDate keep - % order = order(withoutdates); - end - end + % if nargin > 1 + % % take out dates from the order based on the given input date + % startDate = datetime(varargin{1}); + % % if plotting_template.date % is equal to or later than startDate keep + % % % order = order(withoutdates); + % % end + % end plotting_template = plotting_template(order); From a62e3ced878d1f5f2f27046b326bcdb649fc7803 Mon Sep 17 00:00:00 2001 From: Isabell Whiteley Date: Mon, 8 Sep 2025 15:02:32 +0100 Subject: [PATCH 19/30] Added varargin of a start date for plotting the data, currently input must be month-year, does not work with just year --- .../+longitudinal/long_electrical_noise.m | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/code/+mpqc/+longitudinal/long_electrical_noise.m b/code/+mpqc/+longitudinal/long_electrical_noise.m index 9bb8fc3..65da880 100644 --- a/code/+mpqc/+longitudinal/long_electrical_noise.m +++ b/code/+mpqc/+longitudinal/long_electrical_noise.m @@ -2,7 +2,7 @@ % Longitudinal electrical noise plots % % mpqc.longitudinal.long_electrical_noise(maintenace_folder_path, varargin) - % Optional inputs: Starting date + % Optional inputs: Starting date- month-year % TODO - change to varargin so can give a date range to use % % Purpose @@ -52,16 +52,30 @@ % sort plotting_template data by the date/time date_list = [plotting_template.date]; [~,order] = sort(datenum(date_list,'dd-mm-yyyy hh:MM:ss'),1,'ascend'); + plotting_template = plotting_template(order); - % if nargin > 1 - % % take out dates from the order based on the given input date - % startDate = datetime(varargin{1}); - % % if plotting_template.date % is equal to or later than startDate keep - % % % order = order(withoutdates); - % % end - % end + if nargin > 1 + % take out dates from the order based on the given input date + startDate = datetime(varargin{1}); + + % This will represent the index at which our (sorted) data is >= + % the given threshold value + startIndex = 1; + + % While the date at the current index is BEFORE our minimum date + % move the index along as we haven't found the threshold data point + % The loop will stop at the point at which our order[startIndex] + % is GREATER THAN OR EQUAL TO our given minimum date threshold + while [plotting_template(startIndex).date] < startDate + % if datetime(order) => datetime(startDate) % is equal to or later than startDate keep + % order = order(withoutdates); + startIndex = startIndex + 1; + end - plotting_template = plotting_template(order); + % Remove the data points before our minimum date by slicing + % from the found startIndex to the end of the list + plotting_template = plotting_template(startIndex:end); + end for ii = 1:length(plotting_template) if contains(plotting_template(ii).full_path_to_data, '.tif') From 3ce01471f24b9d2b55d9dbe67c8b4a4aff1734dd Mon Sep 17 00:00:00 2001 From: Isabell Whiteley Date: Mon, 8 Sep 2025 16:06:50 +0100 Subject: [PATCH 20/30] Added function return point if no electrical noise files found --- code/+mpqc/+longitudinal/long_electrical_noise.m | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/code/+mpqc/+longitudinal/long_electrical_noise.m b/code/+mpqc/+longitudinal/long_electrical_noise.m index 65da880..c7e6c1b 100644 --- a/code/+mpqc/+longitudinal/long_electrical_noise.m +++ b/code/+mpqc/+longitudinal/long_electrical_noise.m @@ -40,14 +40,11 @@ % TODO add else for it no files found end end - - % if nargin>1 - % Can either choose not to find files before a date, or - % choose not to analyse files before the date, 2nd option - % more simple and done in same area as ordering by date - % - % end - +if ~exist('plotting_template','var')% plotting_template == 0; +disp('No electrical noise files found') +varargout{1} = []; +return +end % sort plotting_template data by the date/time date_list = [plotting_template.date]; From fad1a2fa07601dc5dec56b2d043261e34df3f294 Mon Sep 17 00:00:00 2001 From: Isabell Whiteley Date: Mon, 8 Sep 2025 16:45:50 +0100 Subject: [PATCH 21/30] Cleaned up code and minor edits, BUG found- for some datasets, the PMT noise plots get replaced by FWHM and noise plots, in other datasets this does notr happen --- .../+longitudinal/long_electrical_noise.m | 268 +++++++++--------- 1 file changed, 130 insertions(+), 138 deletions(-) diff --git a/code/+mpqc/+longitudinal/long_electrical_noise.m b/code/+mpqc/+longitudinal/long_electrical_noise.m index c7e6c1b..18aef6a 100644 --- a/code/+mpqc/+longitudinal/long_electrical_noise.m +++ b/code/+mpqc/+longitudinal/long_electrical_noise.m @@ -1,159 +1,151 @@ function varargout = long_electrical_noise(data_dir,varargin) - % Longitudinal electrical noise plots - % - % mpqc.longitudinal.long_electrical_noise(maintenace_folder_path, varargin) - % Optional inputs: Starting date- month-year - % TODO - change to varargin so can give a date range to use - % - % Purpose - % Plots of the maximum value and FWHM of electrical noise for each channel - % with PMTs off. If there is significant change in electrical noise, the FWHM - % distributions will likely increase in value. - % - % - % Outputs - % out (optional) - structure containing key information and data. - % - % Isabell Whiteley, SWC AMF - - if nargin<1 - data_dir = pwd; - end +% Longitudinal electrical noise plots showing FWHM and max values over time +% +% mpqc.longitudinal.long_electrical_noise(maintenace_folder_path, varargin) +% Optional inputs: Starting date- month-year +% +% Purpose +% Plots of the maximum value and FWHM of electrical noise for each channel +% with PMTs off. If there is significant change in electrical noise, the FWHM +% distributions will likely increase in value. +% +% +% Outputs +% out (optional) - structure containing key information and data. +% +% Notes +% Currently plots for 4 PMT channels regardless of actual number of +% PMTs in system +% +% +% Isabell Whiteley, SWC AMF 2025 + +if nargin<1 + data_dir = pwd; +end - debugPlots = true; - - d = dir(fullfile(data_dir,'\**\*.tif')); % cTODO -- change "d" to a more descriptive name - n=1; - - for ii=1:length(d) - tmp = d(ii); - - if contains(tmp.name,'electrical_noise') - plotting_template(n) = generic_generator_template(tmp); - plotting_template(n).type = 'electrical_noise'; - plotting_template(n).plotting_func = @mpqc.plot.electrical_noise; - plotting_template(n).date = string(datetime(regexp(tmp.name, '(\d{4}-\d{2}-\d{2})_(\d{2}-\d{2}-\d{2})','match'),'InputFormat','yyyy-MM-dd_HH-mm-ss')); - [pathstr,plotting_template(n).name,ext] = fileparts(tmp.name); - n=n+1; - % else - % TODO add else for it no files found - end - end -if ~exist('plotting_template','var')% plotting_template == 0; -disp('No electrical noise files found') -varargout{1} = []; -return +debugPlots = true; + +maintenanceFiles = dir(fullfile(data_dir,'\**\*.tif')); +n=1; + +for ii=1:length(maintenanceFiles) + tmp = maintenanceFiles(ii); + + if contains(tmp.name,'electrical_noise') + plotting_template(n) = generic_generator_template(tmp); + plotting_template(n).type = 'electrical_noise'; + plotting_template(n).plotting_func = @mpqc.plot.electrical_noise; + plotting_template(n).date = string(datetime(regexp(tmp.name, '(\d{4}-\d{2}-\d{2})_(\d{2}-\d{2}-\d{2})','match'),'InputFormat','yyyy-MM-dd_HH-mm-ss')); + [pathstr,plotting_template(n).name,ext] = fileparts(tmp.name); + n=n+1; + end +end +if ~exist('plotting_template','var') + disp('No electrical noise files found') + varargout{1} = []; + return end - % sort plotting_template data by the date/time - date_list = [plotting_template.date]; - [~,order] = sort(datenum(date_list,'dd-mm-yyyy hh:MM:ss'),1,'ascend'); - plotting_template = plotting_template(order); - - if nargin > 1 - % take out dates from the order based on the given input date - startDate = datetime(varargin{1}); - - % This will represent the index at which our (sorted) data is >= - % the given threshold value - startIndex = 1; - - % While the date at the current index is BEFORE our minimum date - % move the index along as we haven't found the threshold data point - % The loop will stop at the point at which our order[startIndex] - % is GREATER THAN OR EQUAL TO our given minimum date threshold - while [plotting_template(startIndex).date] < startDate - % if datetime(order) => datetime(startDate) % is equal to or later than startDate keep - % order = order(withoutdates); - startIndex = startIndex + 1; - end +% sort plotting_template data by the date/time +date_list = [plotting_template.date]; +[~,order] = sort(datenum(date_list,'dd-mm-yyyy hh:MM:ss'),1,'ascend'); +plotting_template = plotting_template(order); + +if nargin > 1 % Optional variable for selecting starting date + startDate = datetime(varargin{1}); + startIndex = 1; - % Remove the data points before our minimum date by slicing - % from the found startIndex to the end of the list - plotting_template = plotting_template(startIndex:end); + while [plotting_template(startIndex).date] < startDate + startIndex = startIndex + 1; end - - for ii = 1:length(plotting_template) - if contains(plotting_template(ii).full_path_to_data, '.tif') - noiseData(:,:,:,ii) = mpqc.tools.scanImage_stackLoad(plotting_template(ii).full_path_to_data); - end + + plotting_template = plotting_template(startIndex:end); +end + +for ii = 1:length(plotting_template) + if contains(plotting_template(ii).full_path_to_data, '.tif') + noiseData(:,:,:,ii) = mpqc.tools.scanImage_stackLoad(plotting_template(ii).full_path_to_data); end - - noiseData = single(noiseData); +end - for q = 1:size(noiseData,4) % each date +noiseData = single(noiseData); +for q = 1:size(noiseData,4) % each date + + if debugPlots + fig = mpqc.tools.returnFigureHandleForFile(sprintf('%s_%02d',mfilename,q)); + end + for t = 1:size(noiseData,3) % each PMT + + % Extract data + t_im = noiseData(:,:,t,q); + [n,x] = hist(t_im(:),100); % plots all data as histogram + m = smoothdata(n,'gaussian',5); + detail = interp1(x,m,[1:1000]); + + maxVal(t,q) = max(detail(:)); + halfMaxVal = maxVal(t,q)/2; + leftIndex = find(detail(:) >= halfMaxVal, 1, 'first'); + rightIndex = find(detail(:) >= halfMaxVal, 1, 'last'); + fwhm(t,q) = rightIndex -leftIndex; + + % TODO Remove data where PMT does not exist + + % Optionally plot if debugPlots - fig = mpqc.tools.returnFigureHandleForFile(sprintf('%s_%02d',mfilename,q)); - end - for t = 1:size(noiseData,3) % each PMT - - % Extract data - t_im = noiseData(:,:,t,q); - [n,x] = hist(t_im(:),100); % plots all data as histogram - m = smoothdata(n,'gaussian',5); - detail = interp1(x,m,[1:1000]); - - maxVal(t,q) = max(detail(:)); - halfMaxVal = maxVal(t,q)/2; - leftIndex = find(detail(:) >= halfMaxVal, 1, 'first'); - rightIndex = find(detail(:) >= halfMaxVal, 1, 'last'); - fwhm(t,q) = rightIndex -leftIndex; - - % Optionally plot - if debugPlots - subplot(2,2,t) - a=area(n); - a.EdgeColor=[0,0,0.75]; - a.FaceColor=[0.5,0.5,1]; - a.LineWidth=2; - hold on - b = plot(m); - b.LineWidth = 2; - sgtitle(plotting_template(q).date) - title(['PMT # ',num2str(t)]) - hold off - end + subplot(2,2,t) + a=area(n); + a.EdgeColor=[0,0,0.75]; + a.FaceColor=[0.5,0.5,1]; + a.LineWidth=2; + hold on + b = plot(m); + b.LineWidth = 2; + sgtitle(plotting_template(q).date) + title(['PMT # ',num2str(t)]) + hold off end end - - for ii = 1:size(noiseData,3) % plotting FWHM and max value over time for each PMT - xlabels = {plotting_template.date}; - fig = mpqc.tools.returnFigureHandleForFile(sprintf('%s_%02d',mfilename,ii)); - subplot(2,1,1) - plot(maxVal(ii,:)) - xticks(1:length(xlabels)) - xticklabels(xlabels) - title('Max value') - - subplot(2,1,2) - plot(fwhm(ii,:)) - xticks(1:length(xlabels)) - xticklabels(xlabels) - title('FWHM') - sgtitle(['PMT # ',num2str(ii)]) - end +end - - % Output of the main function - if nargout>0 - out.fileName = {plotting_template(:).name}; - out.noiseData = noiseData; - out.fwhm = fwhm; - out.maxValues = maxVal; - out.date ={plotting_template(:).date}; - varargout{1} = out; - end +for ii = 1:size(noiseData,3) % plotting FWHM and max value over time for each PMT + xlabels = {plotting_template.date}; + fig = mpqc.tools.returnFigureHandleForFile(sprintf('%s_%02d',mfilename,ii)); + subplot(2,1,1) + plot(maxVal(ii,:)) + xticks(1:length(xlabels)) + xticklabels(xlabels) + title('Max value') + + subplot(2,1,2) + plot(fwhm(ii,:)) + xticks(1:length(xlabels)) + xticklabels(xlabels) + title('FWHM') + sgtitle(['PMT # ',num2str(ii)]) +end + + +% Output of the main function +if nargout>0 + out.fileName = {plotting_template(:).name}; + out.noiseData = noiseData; + out.fwhm = fwhm; + out.maxValues = maxVal; + out.date ={plotting_template(:).date}; + varargout{1} = out; +end end % close main funtion function out = generic_generator_template(t_dir) - out.full_path_to_data = fullfile(t_dir.folder,t_dir.name); - out.type = []; - out.plotting_func = []; - out.name = []; - out.date = []; +out.full_path_to_data = fullfile(t_dir.folder,t_dir.name); +out.type = []; +out.plotting_func = []; +out.name = []; +out.date = []; end \ No newline at end of file From 980bea5d5e4d9e397e2890cd9443391bded17a19 Mon Sep 17 00:00:00 2001 From: Isabell Whiteley Date: Tue, 9 Sep 2025 17:07:53 +0100 Subject: [PATCH 22/30] First commit for of longitudinal analysis for standard light source data, incomplete --- .../long_standard_light_source.m | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 code/+mpqc/+longitudinal/long_standard_light_source.m diff --git a/code/+mpqc/+longitudinal/long_standard_light_source.m b/code/+mpqc/+longitudinal/long_standard_light_source.m new file mode 100644 index 0000000..dcfa31a --- /dev/null +++ b/code/+mpqc/+longitudinal/long_standard_light_source.m @@ -0,0 +1,38 @@ +function varargout = long_standard_light_source(data_dir,varargin) +% Plots showing photon count of PMTs over time +% +% +% +% +% Isabell Whiteley, SWC AMF 2025 + +if nargin<1 + data_dir = pwd; +end + + +debugPlots = true; + +maintenanceFiles = dir(fullfile(data_dir,'\**\*.tif')); +n=1; + +for ii=1:length(maintenanceFiles) + tmp = maintenanceFiles(ii); + + if contains(tmp.name,'standard_light_source') + plotting_template(n) = generic_generator_template(tmp); + plotting_template(n).type = 'standard_light_source'; + plotting_template(n).plotting_func = @mpqc.plot.electrical_noise; + plotting_template(n).date = string(datetime(regexp(tmp.name, '(\d{4}-\d{2}-\d{2})_(\d{2}-\d{2}-\d{2})','match'),'InputFormat','yyyy-MM-dd_HH-mm-ss')); + [pathstr,plotting_template(n).name,ext] = fileparts(tmp.name); + n=n+1; + end +end +if ~exist('plotting_template','var') + disp('No standard light source files found') + varargout{1} = []; + return +end + + +end \ No newline at end of file From d31ea3c35a489cf56dce443cf2c3f7d94c08cda9 Mon Sep 17 00:00:00 2001 From: Isabell Whiteley Date: Wed, 10 Sep 2025 11:01:01 +0100 Subject: [PATCH 23/30] First commit of longitudinal power measurements, taking code from long_electrical_noise. --- code/+mpqc/+longitudinal/long_power.m | 67 +++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 code/+mpqc/+longitudinal/long_power.m diff --git a/code/+mpqc/+longitudinal/long_power.m b/code/+mpqc/+longitudinal/long_power.m new file mode 100644 index 0000000..9409816 --- /dev/null +++ b/code/+mpqc/+longitudinal/long_power.m @@ -0,0 +1,67 @@ +function varargout = long_power(data_dir,varargin) +% Function to track the changes in laser power over time +% +% +% +if nargin<1 + data_dir = pwd; +end + + +debugPlots = true; + +maintenanceFiles = dir(fullfile(data_dir,'\**\*.mat')); +n=1; + +for ii=1:length(maintenanceFiles) + tmp = maintenanceFiles(ii); + + if contains(tmp.name,'power') + plotting_template(n) = generic_generator_template(tmp); + plotting_template(n).type = 'power'; + plotting_template(n).plotting_func = @mpqc.plot.power; + plotting_template(n).date = string(datetime(regexp(tmp.name, '(\d{4}-\d{2}-\d{2})_(\d{2}-\d{2}-\d{2})','match'),'InputFormat','yyyy-MM-dd_HH-mm-ss')); + [pathstr,plotting_template(n).name,ext] = fileparts(tmp.name); + n=n+1; + end +end +if ~exist('plotting_template','var') + disp('No power measurement files found') + varargout{1} = []; + return +end + +% sort plotting_template data by the date/time +date_list = [plotting_template.date]; +[~,order] = sort(datenum(date_list,'dd-mm-yyyy hh:MM:ss'),1,'ascend'); +plotting_template = plotting_template(order); + +if nargin > 1 % Optional variable for selecting starting date + startDate = datetime(varargin{1}); + startIndex = 1; + + while [plotting_template(startIndex).date] < startDate + startIndex = startIndex + 1; + end + + plotting_template = plotting_template(startIndex:end); +end + + + +% Output of the main function +if nargout>0 + out.fileName = {plotting_template(:).name}; + out.date ={plotting_template(:).date}; + varargout{1} = out; +end + +end + +function out = generic_generator_template(t_dir) +out.full_path_to_data = fullfile(t_dir.folder,t_dir.name); +out.type = []; +out.plotting_func = []; +out.name = []; +out.date = []; +end \ No newline at end of file From 585b682345ec91fb754d95ec9d34dc0aeed08ff1 Mon Sep 17 00:00:00 2001 From: Isabell Whiteley Date: Wed, 10 Sep 2025 14:33:04 +0100 Subject: [PATCH 24/30] Plots all power measurements in one plot for overview, added wavelength to plotting_template --- code/+mpqc/+longitudinal/long_power.m | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/code/+mpqc/+longitudinal/long_power.m b/code/+mpqc/+longitudinal/long_power.m index 9409816..cb34945 100644 --- a/code/+mpqc/+longitudinal/long_power.m +++ b/code/+mpqc/+longitudinal/long_power.m @@ -21,6 +21,7 @@ plotting_template(n).type = 'power'; plotting_template(n).plotting_func = @mpqc.plot.power; plotting_template(n).date = string(datetime(regexp(tmp.name, '(\d{4}-\d{2}-\d{2})_(\d{2}-\d{2}-\d{2})','match'),'InputFormat','yyyy-MM-dd_HH-mm-ss')); + plotting_template(n).wavelength = regexp(tmp.name,'\d*(?=nm)','match'); [pathstr,plotting_template(n).name,ext] = fileparts(tmp.name); n=n+1; end @@ -47,12 +48,34 @@ plotting_template = plotting_template(startIndex:end); end +for ii = 1:length(plotting_template) + if contains(plotting_template(ii).full_path_to_data, '.mat') + powerData(ii) = load(plotting_template(ii).full_path_to_data); + % plotting_template(ii).wavelength = powerData.powerMeasurements.laser_wavelength; % this, or take from title of .mat file + hold on + plot([0:5:100],powerData(ii).powerMeasurements.observedPower,'.') + end +end +legend(plotting_template.date,'location', 'Northwest') +title(cell2mat(['Power at ', string(plotting_template(1).wavelength), 'nm'])) +xlabel('Percent power') +ylabel('Power (mW)') +hold off + +% identify wavelength +% plot curves on same plot +% different plot- plot the difference between curves + + + + % Output of the main function if nargout>0 out.fileName = {plotting_template(:).name}; out.date ={plotting_template(:).date}; + out.powerData = powerData; varargout{1} = out; end @@ -64,4 +87,5 @@ out.plotting_func = []; out.name = []; out.date = []; +out.wavelength = []; end \ No newline at end of file From 21364e750fe66308156058b0621dc841d49d607f Mon Sep 17 00:00:00 2001 From: Isabell Whiteley Date: Wed, 10 Sep 2025 16:30:34 +0100 Subject: [PATCH 25/30] Plots all power curves and changes in max power over time if wavelengths are the same --- code/+mpqc/+longitudinal/long_power.m | 54 +++++++++++++++++++-------- 1 file changed, 39 insertions(+), 15 deletions(-) diff --git a/code/+mpqc/+longitudinal/long_power.m b/code/+mpqc/+longitudinal/long_power.m index cb34945..7637fc7 100644 --- a/code/+mpqc/+longitudinal/long_power.m +++ b/code/+mpqc/+longitudinal/long_power.m @@ -21,7 +21,7 @@ plotting_template(n).type = 'power'; plotting_template(n).plotting_func = @mpqc.plot.power; plotting_template(n).date = string(datetime(regexp(tmp.name, '(\d{4}-\d{2}-\d{2})_(\d{2}-\d{2}-\d{2})','match'),'InputFormat','yyyy-MM-dd_HH-mm-ss')); - plotting_template(n).wavelength = regexp(tmp.name,'\d*(?=nm)','match'); + plotting_template(n).wavelength = cell2mat(regexp(tmp.name,'\d*(?=nm)','match')); [pathstr,plotting_template(n).name,ext] = fileparts(tmp.name); n=n+1; end @@ -48,23 +48,45 @@ plotting_template = plotting_template(startIndex:end); end -for ii = 1:length(plotting_template) - if contains(plotting_template(ii).full_path_to_data, '.mat') - powerData(ii) = load(plotting_template(ii).full_path_to_data); - % plotting_template(ii).wavelength = powerData.powerMeasurements.laser_wavelength; % this, or take from title of .mat file - hold on - plot([0:5:100],powerData(ii).powerMeasurements.observedPower,'.') +if isequal(plotting_template(:).wavelength) % if wavelength is the same + for ii = 1:length(plotting_template) + if contains(plotting_template(ii).full_path_to_data, '.mat') + % If power data is found, load it and find max value + powerData(ii) = load(plotting_template(ii).full_path_to_data); + maxPower(ii) = powerData(ii).powerMeasurements.observedPower(end); + + % Plot the power curves for each date + hold on + subplot(2,1,1) + plot([0:5:100],powerData(ii).powerMeasurements.observedPower,'.') + legend(plotting_template.date,'location', 'Northwest') + title(cell2mat(['Power at ', string(plotting_template(1).wavelength), 'nm'])) + xlabel('Percent power') + ylabel('Power (mW)') + hold off + end end + % Plot the maximum laser output over time + subplot(2,1,2) + plot(maxPower, '-*') + title('Maximum laser power') + xlabels = {plotting_template.date}; + xticks(1:length(xlabels)) + xticklabels(xlabels) + ylabel('Maximum power (mW)') +else + disp('Different wavelengths found') + powerData = []; + maxPower = []; + % separate plots for each wavelength end -legend(plotting_template.date,'location', 'Northwest') -title(cell2mat(['Power at ', string(plotting_template(1).wavelength), 'nm'])) -xlabel('Percent power') -ylabel('Power (mW)') -hold off -% identify wavelength -% plot curves on same plot -% different plot- plot the difference between curves + + +% identify wavelength - done +% plot curves on same plot - done +% separate plots based on wavelength +% max value to see decay of laser - done @@ -76,6 +98,8 @@ out.fileName = {plotting_template(:).name}; out.date ={plotting_template(:).date}; out.powerData = powerData; + out.maxPower = maxPower; + out.wavelength = {plotting_template(:).wavelength}; varargout{1} = out; end From 267cf76461ed49539c4d16a6277ff0b1ba4b8f7b Mon Sep 17 00:00:00 2001 From: Isabell Whiteley Date: Wed, 10 Sep 2025 16:56:41 +0100 Subject: [PATCH 26/30] Updated description of function, multiple wavelengths currently not working --- code/+mpqc/+longitudinal/long_power.m | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/code/+mpqc/+longitudinal/long_power.m b/code/+mpqc/+longitudinal/long_power.m index 7637fc7..4732710 100644 --- a/code/+mpqc/+longitudinal/long_power.m +++ b/code/+mpqc/+longitudinal/long_power.m @@ -1,8 +1,21 @@ function varargout = long_power(data_dir,varargin) % Function to track the changes in laser power over time + +% mpqc.longitudinal.long_power(maintenace_folder_path, varargin) +% Optional inputs: Starting date- month-year +% +% Purpose +% Plots the power at the objective from 0-100% and compares maximum output +% power over time. Used to monitor the health of a laser +% % +% Outputs +% out (optional) - structure containing key information and data. % % +% +% Isabell Whiteley, SWC AMF 2025 + if nargin<1 data_dir = pwd; end @@ -21,7 +34,7 @@ plotting_template(n).type = 'power'; plotting_template(n).plotting_func = @mpqc.plot.power; plotting_template(n).date = string(datetime(regexp(tmp.name, '(\d{4}-\d{2}-\d{2})_(\d{2}-\d{2}-\d{2})','match'),'InputFormat','yyyy-MM-dd_HH-mm-ss')); - plotting_template(n).wavelength = cell2mat(regexp(tmp.name,'\d*(?=nm)','match')); + plotting_template(n).wavelength = str2num(cell2mat(regexp(tmp.name,'\d*(?=nm)','match'))); [pathstr,plotting_template(n).name,ext] = fileparts(tmp.name); n=n+1; end @@ -78,7 +91,8 @@ disp('Different wavelengths found') powerData = []; maxPower = []; - % separate plots for each wavelength + % separate plots for each wavelength + % in R2025a numunique function may work end From 2de87bd18517d39bc13d4e85b1d6f7885ac824fd Mon Sep 17 00:00:00 2001 From: Isabell Whiteley Date: Thu, 11 Sep 2025 15:07:24 +0100 Subject: [PATCH 27/30] Added else if for specific wavelength varargin, not yet working as need parseInputVariable function to be moved location. --- code/+mpqc/+longitudinal/long_power.m | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/code/+mpqc/+longitudinal/long_power.m b/code/+mpqc/+longitudinal/long_power.m index 4732710..1c6ba4a 100644 --- a/code/+mpqc/+longitudinal/long_power.m +++ b/code/+mpqc/+longitudinal/long_power.m @@ -1,14 +1,17 @@ function varargout = long_power(data_dir,varargin) % Function to track the changes in laser power over time - +% % mpqc.longitudinal.long_power(maintenace_folder_path, varargin) -% Optional inputs: Starting date- month-year +% +% Optional inputs: +% 'startDate', month-year +% 'wavelength, value % % Purpose % Plots the power at the objective from 0-100% and compares maximum output % power over time. Used to monitor the health of a laser % -% +% % Outputs % out (optional) - structure containing key information and data. % @@ -20,6 +23,13 @@ data_dir = pwd; end + % process inputs + % addpath("+tools"); + optInputs = parseInputVariable(varargin{:}); + + % Extract critical input variable + selectWavelength = optInputs.wavelength; + % TODO Add to parseInputVariable startDate debugPlots = true; @@ -87,12 +97,22 @@ xticks(1:length(xlabels)) xticklabels(xlabels) ylabel('Maximum power (mW)') + +% elseif isequal(plotting_template(:).wavelength,selectWavelength) +elseif ~isempty(selectWavelength) + tempStruc = find(plotting_template(:).wavelength == selectWavelength); +% if wavelength given in varargin, plot only that wavelength and dates + else disp('Different wavelengths found') powerData = []; maxPower = []; % separate plots for each wavelength % in R2025a numunique function may work + + % plot wavelengths separately, but keep all dates - so assisgn NaN to + % unused dates. Make temporary structures so values are not permanently + % replaced end From 05dca7159e6a8be2b8792d6470c8046b3ab8bdb7 Mon Sep 17 00:00:00 2001 From: Isabell Whiteley Date: Thu, 11 Sep 2025 17:02:51 +0100 Subject: [PATCH 28/30] Working on separating plots for different wavelengths, partway there but not fully functional as yet --- code/+mpqc/+longitudinal/long_power.m | 60 ++++++++++++++++++++------- 1 file changed, 46 insertions(+), 14 deletions(-) diff --git a/code/+mpqc/+longitudinal/long_power.m b/code/+mpqc/+longitudinal/long_power.m index 1c6ba4a..d037266 100644 --- a/code/+mpqc/+longitudinal/long_power.m +++ b/code/+mpqc/+longitudinal/long_power.m @@ -23,13 +23,14 @@ data_dir = pwd; end - % process inputs - % addpath("+tools"); - optInputs = parseInputVariable(varargin{:}); - - % Extract critical input variable - selectWavelength = optInputs.wavelength; - % TODO Add to parseInputVariable startDate +% For elseif statement of wavelength given in varargin + % % process inputs + % % addpath("+tools"); + % optInputs = parseInputVariable(varargin{:}); + % + % % Extract critical input variable + % selectWavelength = optInputs.wavelength; + % % TODO Add to parseInputVariable startDate debugPlots = true; @@ -99,15 +100,46 @@ ylabel('Maximum power (mW)') % elseif isequal(plotting_template(:).wavelength,selectWavelength) -elseif ~isempty(selectWavelength) - tempStruc = find(plotting_template(:).wavelength == selectWavelength); -% if wavelength given in varargin, plot only that wavelength and dates +% elseif ~isempty(selectWavelength) +% tempStruc = find(plotting_template(:).wavelength == selectWavelength); +% % if wavelength given in varargin, plot only that wavelength and dates else - disp('Different wavelengths found') - powerData = []; - maxPower = []; - % separate plots for each wavelength + % disp('Different wavelengths found') + % powerData = []; + % maxPower = []; + for i = 1:length(plotting_template) + allWave(i) = plotting_template(i).wavelength; + end + wavelengthVals = unique(allWave); + numWavelength = length(wavelengthVals); +maxPower = cell(zeros(1:length(plotting_template)),zeros(1:length(wavelengthVals))); % Need to be cells because they will have empty values +powerData = cell(zeros(1:length(plotting_template)),zeros(1:length(wavelengthVals))); + for jj = 1:length(numWavelength) + figure; + for ii = 1:length(plotting_template) + + if contains(plotting_template(ii).full_path_to_data, '.mat') && isequal(plotting_template(ii).wavelength,wavelengthVals(jj)) + % If power data is found, load it and find max value + powerData(ii,jj) = load(plotting_template(ii).full_path_to_data); + maxPower(ii,jj) = powerData(ii).powerMeasurements.observedPower(end); + + + hold on + subplot(2,1,1) + plot([0:5:100],powerData(ii,jj).powerMeasurements.observedPower,'.') + legend(plotting_template.date,'location', 'Northwest') + title(cell2mat(['Power at ', string(wavelengthVals(jj)), 'nm'])) + xlabel('Percent power') + ylabel('Power (mW)') + hold off + end + end + end + % for ii = 1:length(numWavelength) + % end + % separate plots for each wavelength + % tried groupcounts % in R2025a numunique function may work % plot wavelengths separately, but keep all dates - so assisgn NaN to From 50aea7a8edd3d58d8f3040cd867478b542cde010 Mon Sep 17 00:00:00 2001 From: Isabell Whiteley <46966503+iwhiteley@users.noreply.github.com> Date: Mon, 15 Sep 2025 11:49:15 +0100 Subject: [PATCH 29/30] Small bug fixes on else statement, not fully working --- code/+mpqc/+longitudinal/long_power.m | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/code/+mpqc/+longitudinal/long_power.m b/code/+mpqc/+longitudinal/long_power.m index d037266..216b086 100644 --- a/code/+mpqc/+longitudinal/long_power.m +++ b/code/+mpqc/+longitudinal/long_power.m @@ -113,9 +113,9 @@ end wavelengthVals = unique(allWave); numWavelength = length(wavelengthVals); -maxPower = cell(zeros(1:length(plotting_template)),zeros(1:length(wavelengthVals))); % Need to be cells because they will have empty values -powerData = cell(zeros(1:length(plotting_template)),zeros(1:length(wavelengthVals))); - for jj = 1:length(numWavelength) +% maxPower = cell(length(plotting_template),length(wavelengthVals)); % Need to be cells because they will have empty values +% powerData = cell(length(plotting_template),length(wavelengthVals)); + for jj = 1:numWavelength figure; for ii = 1:length(plotting_template) @@ -126,9 +126,9 @@ hold on - subplot(2,1,1) + % subplot(2,1,1) plot([0:5:100],powerData(ii,jj).powerMeasurements.observedPower,'.') - legend(plotting_template.date,'location', 'Northwest') + legend(plotting_template(ii).date,'location', 'Northwest') % incorrect title(cell2mat(['Power at ', string(wavelengthVals(jj)), 'nm'])) xlabel('Percent power') ylabel('Power (mW)') From 619adb0ff0a72f6ccd284a4b6736a18885f2d171 Mon Sep 17 00:00:00 2001 From: Isabell Whiteley <46966503+iwhiteley@users.noreply.github.com> Date: Tue, 16 Sep 2025 16:39:01 +0100 Subject: [PATCH 30/30] Trying to check for different observedPower variable names, not yet working --- code/+mpqc/+longitudinal/long_power.m | 61 +++++++++++++++++---------- 1 file changed, 38 insertions(+), 23 deletions(-) diff --git a/code/+mpqc/+longitudinal/long_power.m b/code/+mpqc/+longitudinal/long_power.m index 216b086..a598204 100644 --- a/code/+mpqc/+longitudinal/long_power.m +++ b/code/+mpqc/+longitudinal/long_power.m @@ -34,6 +34,7 @@ debugPlots = true; +possibleFields = {'observedPower','observedPower_mW'}; maintenanceFiles = dir(fullfile(data_dir,'\**\*.mat')); n=1; @@ -77,7 +78,12 @@ if contains(plotting_template(ii).full_path_to_data, '.mat') % If power data is found, load it and find max value powerData(ii) = load(plotting_template(ii).full_path_to_data); - maxPower(ii) = powerData(ii).powerMeasurements.observedPower(end); + for i = 1:length(possibleFields) + if isfield(powerData.powerMeasurements,possibleFields{i}) + maxPower(ii) = powerData(ii).powerMeasurements.possibleFields{i}(end); + break + end + end % Plot the power curves for each date hold on @@ -99,10 +105,10 @@ xticklabels(xlabels) ylabel('Maximum power (mW)') -% elseif isequal(plotting_template(:).wavelength,selectWavelength) -% elseif ~isempty(selectWavelength) -% tempStruc = find(plotting_template(:).wavelength == selectWavelength); -% % if wavelength given in varargin, plot only that wavelength and dates + % elseif isequal(plotting_template(:).wavelength,selectWavelength) + % elseif ~isempty(selectWavelength) + % tempStruc = find(plotting_template(:).wavelength == selectWavelength); + % % if wavelength given in varargin, plot only that wavelength and dates else % disp('Different wavelengths found') @@ -115,17 +121,26 @@ numWavelength = length(wavelengthVals); % maxPower = cell(length(plotting_template),length(wavelengthVals)); % Need to be cells because they will have empty values % powerData = cell(length(plotting_template),length(wavelengthVals)); - for jj = 1:numWavelength - figure; - for ii = 1:length(plotting_template) - +for jj = 1:numWavelength + figure; + for ii = 1:length(plotting_template) + if contains(plotting_template(ii).full_path_to_data, '.mat') && isequal(plotting_template(ii).wavelength,wavelengthVals(jj)) % If power data is found, load it and find max value - powerData(ii,jj) = load(plotting_template(ii).full_path_to_data); - maxPower(ii,jj) = powerData(ii).powerMeasurements.observedPower(end); + + % powerData(ii,jj) =regexp(fileData.powerMeasurements,'observedPower'); + powerData(ii) = load(plotting_template(ii).full_path_to_data); + for i = 1:length(possibleFields) + if isfield(powerData.powerMeasurements,possibleFields{i}) + maxPower(ii,jj) = powerData(ii).powerMeasurements.possibleFields{i}(end); + break + end + end + % maxPower(ii,jj) = powerData(end); + % maxPower(ii,jj) = powerData(ii).powerMeasurements.observedPower(end); - hold on + hold on % subplot(2,1,1) plot([0:5:100],powerData(ii,jj).powerMeasurements.observedPower,'.') legend(plotting_template(ii).date,'location', 'Northwest') % incorrect @@ -134,17 +149,17 @@ ylabel('Power (mW)') hold off end - end - end - % for ii = 1:length(numWavelength) - % end - % separate plots for each wavelength - % tried groupcounts - % in R2025a numunique function may work - - % plot wavelengths separately, but keep all dates - so assisgn NaN to - % unused dates. Make temporary structures so values are not permanently - % replaced + end +end +% for ii = 1:length(numWavelength) +% end +% separate plots for each wavelength +% tried groupcounts +% in R2025a numunique function may work + +% plot wavelengths separately, but keep all dates - so assisgn NaN to +% unused dates. Make temporary structures so values are not permanently +% replaced end