From ec3c40f010b036a3d10ecd9f3f6c51450c0b09dc Mon Sep 17 00:00:00 2001
From: Olivier Sauter <olivier.sauter@epfl.ch>
Date: Wed, 4 Nov 2015 18:53:11 +0000
Subject: [PATCH] add mhd for aug and gdat_plot spectrogram for mhd

git-svn-id: https://spcsvn.epfl.ch/repos/TCV/gdat/trunk@5210 d63d8f72-b253-0410-a779-e742ad2e26cf
---
 crpptbx/AUG/aug_requests_mapping.m | 14 +++++++++++---
 crpptbx/gdat_plot.m                | 11 +++++++++++
 2 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/crpptbx/AUG/aug_requests_mapping.m b/crpptbx/AUG/aug_requests_mapping.m
index 28f2a130..bbb93eb0 100644
--- a/crpptbx/AUG/aug_requests_mapping.m
+++ b/crpptbx/AUG/aug_requests_mapping.m
@@ -135,9 +135,17 @@ switch lower(data_request)
   mapping.expression = [{'FPG'},{'k'}];
  case 'mhd'
   mapping.timedim = 1;
-  mapping.label = 'n=1,2, etc';
-  mapping.method = 'switchcase';
-  mapping.expression = '';
+  mapping.label = 'Odd and Even n';
+  mapping.method = 'expression';
+  mapping.expression = ['params_eff = gdat_data.gdat_params;params_eff.data_request={''MOD'',''OddN''}; ' ...
+                    'gdat_tmp=gdat_aug(shot,params_eff);gdat_tmp.data=reshape(gdat_tmp.data,length(gdat_tmp.data),1 );' ...
+		    'gdat_tmp.dim{1}=gdat_tmp.t;gdat_tmp.dim{2}=[1 2];gdat_tmp.x=gdat_tmp.dim{2};' ...
+		    'gdat_tmp.n_odd.data = gdat_tmp.data;gdat_tmp.n_odd.data_request=params_eff.data_request;' ...
+		    'params_eff.data_request={''MOD'',''EvenN''};' ...
+		    'gdat_tmp2=gdat_aug(shot,params_eff);gdat_tmp.data(:,2)=reshape(gdat_tmp2.data,length(gdat_tmp2.data),1);' ...
+		    'gdat_tmp.n_even.data = gdat_tmp2.data;gdat_tmp.n_even.data_request=params_eff.data_request;gdat_tmp.label={''n\_odd'',''n\_even''};' ...
+		    'gdat_tmp.full_path=''MOD/Odd in data and .n_odd; .n_even'';' ...
+		    'gdat_tmp.gdat_request=''mhd'';gdat_tmp.gdat_params.data_request=gdat_tmp.gdat_request;'];
  case 'ne'
   mapping.timedim = 2;
   mapping.method = 'switchcase';
diff --git a/crpptbx/gdat_plot.m b/crpptbx/gdat_plot.m
index 5a4b4110..8aabf51b 100644
--- a/crpptbx/gdat_plot.m
+++ b/crpptbx/gdat_plot.m
@@ -79,6 +79,17 @@ if prod(isfield(gdat_data,{'data','t'})) && ~isempty(gdat_data.data) && ~isempty
     % special case, add legend instead of ylabel
     delete(hylabel);
     legend(gdat_data.label,2);
+    % add spectrogram per signal
+    for i=1:size(gdat_data.data,2)
+      nfft=1024;
+      tmhdm=mean(reshape(gdat_data.t(1:nfft*fix(length(gdat_data.t)/nfft)),nfft,fix(length(gdat_data.t)/nfft)));
+      [B,F,T]=specgram(gdat_data.data(:,i),nfft,1/mean(diff(gdat_data.t)),hanning(nfft),nfft/2);
+      figure
+      imagesc(T+tmhdm(1),F/1e3,20*log10(abs(B)));axis xy;colormap jet;
+      ylabel('freq')
+      xlabel(gdat_data.dimunits{1})
+      title(gdat_data.label{i})
+    end
   end
 else
   disp('cannot plot gdat_data, has empty data or t field')
-- 
GitLab