From 023b0ac080a59dae086362f2fb5b835fe7e74dfc Mon Sep 17 00:00:00 2001
From: Chatzilouka Aliki <aliki@lac7.epfl.ch>
Date: Wed, 13 Mar 2024 17:06:58 +0100
Subject: [PATCH] small changes, working get_core_sources now

---
 matlab/TCV_IMAS/tcv_get_ids_core_sources.m | 30 +++++++++++++++-------
 1 file changed, 21 insertions(+), 9 deletions(-)

diff --git a/matlab/TCV_IMAS/tcv_get_ids_core_sources.m b/matlab/TCV_IMAS/tcv_get_ids_core_sources.m
index 710b3e90..2d9d588f 100644
--- a/matlab/TCV_IMAS/tcv_get_ids_core_sources.m
+++ b/matlab/TCV_IMAS/tcv_get_ids_core_sources.m
@@ -32,7 +32,7 @@ ids_core_sources_description = [];
 source_template = ids_core_sources.source{1};
 profiles_template = source_template.profiles_1d{1};
 globals_template = source_template.global_quantities{1};
-%% get time grid and data form gdat & initialize source from template
+%% get time grid and data from gdat & initialize source from template
 ohm_gdat = gdat(shot,'ohm_data');
 % fix time grid to ohm time grid, same as bs
 t_grid = ohm_gdat.t; n_t = numel(t_grid); t_spacing = mean(diff(t_grid));
@@ -54,12 +54,13 @@ ids_core_sources.source{3}.identifier = id_ec;
 ids_core_sources.source{3}.profiles_1d(1:n_t) = {profiles_template};
 ids_core_sources.source{3}.global_quantities(1:n_t) = {globals_template};
 % load data
+%nb_launchers = size(aa.ec.ec_data.rho_max_pow_dens.data,1);
 ec_gdat = gdat(shot,'ec_data'); ec_data = ec_gdat.ec.ec_data;
-ec_time = ec_gdat.ec.ec_data.cd_dens.t;
+ec_time = ec_data.cd_dens.t;
 % interpolate totals on t_grid
-ec_total_pow = interp1(ec_data.p_abs_plasma.t,ec_data.p_abs_plasma.data(12,:),t_grid);
+ec_total_pow = interp1(ec_data.p_abs_plasma.t,ec_data.p_abs_plasma.data(10,:),t_grid); %the index 10 works for shot 56044
 ec_total_pow(isnan(ec_total_pow)) = 0;
-ec_total_cur = interp1(ec_data.p_abs_plasma.t,ec_data.cd_tot.data(12,:),t_grid);
+ec_total_cur = interp1(ec_data.cd_tot.t,ec_data.cd_tot.data(10,:),t_grid);
 ec_total_cur(isnan(ec_total_cur)) = 0;
 
 % bs
@@ -72,13 +73,24 @@ ids_core_sources.source{13}.global_quantities(1:n_t) = {globals_template};
 % load data
 bs_gdat = gdat(shot,'bs_data'); bs_data = bs_gdat.bs.bs_data;
 
-% nbi
+% nbi  
+id_nbi.description = 'Source from Neutral Beam Injection';
+id_nbi.index = 2; id_nbi.name = 'nbi';
 ids_core_sources.source{2} = source_template;
-% to be filled
+ids_core_sources.source{2}.identifier = id_nbi;
+ids_core_sources.source{2}.profiles_1d(1:n_t) = {profiles_template};
+ids_core_sources.source{2}.global_quantities(1:n_t) = {globals_template};
 
-% total
+
+% total  
+id_total.description = 'Total source; combines all sources';
+id_total.index = 1; id_total.name = 'total';
 ids_core_sources.source{1} = source_template;
-% to be filled
+ids_core_sources.source{1}.identifier = id_total;
+ids_core_sources.source{1}.profiles_1d(1:n_t) = {profiles_template};
+ids_core_sources.source{1}.global_quantities(1:n_t) = {globals_template};
+
+
 powers_gdat = gdat(shot,'powers');
 
 %% fill profiles for times n t_grid
@@ -93,7 +105,7 @@ for ii = 1:n_t
   ids_core_sources.source{7}.global_quantities{ii}.power = powers_gdat.ohm.data(ii);
     
   % ec, need to find matching time index\
-  ids_core_sources.source{3}.profiles_1d{ii}.time = t_grid(ii); % profiles time
+  ids_core_sources.source{3}.profiles_1d{ii}.time = t_grid(ii); % profiles time (should profiles time be ec_time?)
   ids_core_sources.source{3}.global_quantities{ii}.time = t_grid(ii); % globals time
   [~, ec_idx] = min(abs(ec_time-t_grid(ii)));
   if ec_time(ec_idx) == t_grid(ii) % same grid 
-- 
GitLab