From 358d8c1c70e68724f33fef2e9b9efbe04caebd77 Mon Sep 17 00:00:00 2001
From: Luke Simons <luke.simons@epfl.ch>
Date: Tue, 18 Mar 2025 09:25:57 +0100
Subject: [PATCH 1/7] Added ids for core_profiles.profiles_1d.e_field.parallel

---
 matlab/TCV_IMAS/tcv_get_ids_core_profiles.m | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/matlab/TCV_IMAS/tcv_get_ids_core_profiles.m b/matlab/TCV_IMAS/tcv_get_ids_core_profiles.m
index ef07977c..8c2678fb 100644
--- a/matlab/TCV_IMAS/tcv_get_ids_core_profiles.m
+++ b/matlab/TCV_IMAS/tcv_get_ids_core_profiles.m
@@ -375,6 +375,16 @@ for it=1:length(ids_core_profiles.time)
   temp_1d_desc.conductivity_parallel = signeo.label;
 end
 
+%% e_field
+% From IDS description:
+% Electric field, averaged on the magnetic surface. E.g for the parallel component, average(E.B) /
+% B0, using core_profiles/vacuum_toroidal_field/b0 [V.m^-1]
+for it=1:length(ids_core_profiles.time)
+  ids_core_profiles.profiles_1d{it}.e_field.parallel =
+    signeo.data(:,it).*(current_non_inductive.ohm.ohm_data.cd_dens.data(:,it));
+  temp_1d_desc.e_field.parallel = "\tcv_shot::top.results.ibs:johmav*\tcv_shot::top.results.ibs:signeo";
+end
+
 %% add descriptions for profiles_1d
 ids_core_profiles_description.profiles_1d = temp_1d_desc;
 
-- 
GitLab


From 7284ae45d19da158c9b99be83cd965acfc83dcb8 Mon Sep 17 00:00:00 2001
From: Luke Simons <luke.simons@epfl.ch>
Date: Tue, 18 Mar 2025 12:08:08 +0100
Subject: [PATCH 2/7] Added line wrap elipse

---
 matlab/TCV_IMAS/tcv_get_ids_core_profiles.m | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/matlab/TCV_IMAS/tcv_get_ids_core_profiles.m b/matlab/TCV_IMAS/tcv_get_ids_core_profiles.m
index 8c2678fb..36759e0b 100644
--- a/matlab/TCV_IMAS/tcv_get_ids_core_profiles.m
+++ b/matlab/TCV_IMAS/tcv_get_ids_core_profiles.m
@@ -380,7 +380,7 @@ end
 % Electric field, averaged on the magnetic surface. E.g for the parallel component, average(E.B) /
 % B0, using core_profiles/vacuum_toroidal_field/b0 [V.m^-1]
 for it=1:length(ids_core_profiles.time)
-  ids_core_profiles.profiles_1d{it}.e_field.parallel =
+  ids_core_profiles.profiles_1d{it}.e_field.parallel = ...
     signeo.data(:,it).*(current_non_inductive.ohm.ohm_data.cd_dens.data(:,it));
   temp_1d_desc.e_field.parallel = "\tcv_shot::top.results.ibs:johmav*\tcv_shot::top.results.ibs:signeo";
 end
-- 
GitLab


From 73dafc4eba71a2e52b28732b2555057354df9eb7 Mon Sep 17 00:00:00 2001
From: Luke Simons <luke.simons@epfl.ch>
Date: Wed, 19 Mar 2025 10:29:38 +0000
Subject: [PATCH 3/7] Changed current_inductive to current_non_inductive

---
 matlab/TCV_IMAS/tcv_get_ids_core_profiles.m | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/matlab/TCV_IMAS/tcv_get_ids_core_profiles.m b/matlab/TCV_IMAS/tcv_get_ids_core_profiles.m
index 36759e0b..a7178a2a 100644
--- a/matlab/TCV_IMAS/tcv_get_ids_core_profiles.m
+++ b/matlab/TCV_IMAS/tcv_get_ids_core_profiles.m
@@ -381,7 +381,7 @@ end
 % B0, using core_profiles/vacuum_toroidal_field/b0 [V.m^-1]
 for it=1:length(ids_core_profiles.time)
   ids_core_profiles.profiles_1d{it}.e_field.parallel = ...
-    signeo.data(:,it).*(current_non_inductive.ohm.ohm_data.cd_dens.data(:,it));
+    signeo.data(:,it).*(current_inductive.ohm.ohm_data.cd_dens.data(:,it));
   temp_1d_desc.e_field.parallel = "\tcv_shot::top.results.ibs:johmav*\tcv_shot::top.results.ibs:signeo";
 end
 
-- 
GitLab


From 31afc6130c3bfacb941f157eec092b703f16db6b Mon Sep 17 00:00:00 2001
From: Luke Simons <luke.simons@epfl.ch>
Date: Thu, 20 Mar 2025 11:16:14 +0100
Subject: [PATCH 4/7] Changed name of variable from current_non_inductive to
 current_inductive

---
 matlab/TCV_IMAS/tcv_get_ids_core_profiles.m | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/matlab/TCV_IMAS/tcv_get_ids_core_profiles.m b/matlab/TCV_IMAS/tcv_get_ids_core_profiles.m
index a7178a2a..52c8a53a 100644
--- a/matlab/TCV_IMAS/tcv_get_ids_core_profiles.m
+++ b/matlab/TCV_IMAS/tcv_get_ids_core_profiles.m
@@ -99,10 +99,10 @@ global_quantities.ip = gdat(params_cores_profiles.shot,'ip','machine',machine);
 global_quantities_desc.ip = params_eff.data_request;
 
 params_eff.data_request = 'ohm_data';
-current_non_inductive = gdat(params_cores_profiles.shot,params_eff);
-global_quantities.current_non_inductive.data = current_non_inductive.ohm.ohm_data.cd_tot.data;
-global_quantities.current_non_inductive.t = current_non_inductive.ohm.ohm_data.cd_tot.t;
-global_quantities_desc.current_non_inductive = current_non_inductive.ohm.ohm_data.cd_tot.label;
+current_inductive = gdat(params_cores_profiles.shot,params_eff);
+global_quantities.current_non_inductive.data = current_inductive.ohm.ohm_data.cd_tot.data;
+global_quantities.current_non_inductive.t = current_inductive.ohm.ohm_data.cd_tot.t;
+global_quantities_desc.current_non_inductive = current_inductive.ohm.ohm_data.cd_tot.label;
 
 params_eff.data_request = 'bs_data';
 current_bootstrap = gdat(params_cores_profiles.shot,params_eff);
-- 
GitLab


From bca1c850568e1d7275c4f246550835b372356bf4 Mon Sep 17 00:00:00 2001
From: Luke Simons <luke.simons@epfl.ch>
Date: Thu, 20 Mar 2025 12:19:18 +0100
Subject: [PATCH 5/7] Renamed other instances of variable current_non_inductive
 in tcv_get_ids_core_profiles

---
 matlab/TCV_IMAS/tcv_get_ids_core_profiles.m | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/matlab/TCV_IMAS/tcv_get_ids_core_profiles.m b/matlab/TCV_IMAS/tcv_get_ids_core_profiles.m
index 52c8a53a..b8720c79 100644
--- a/matlab/TCV_IMAS/tcv_get_ids_core_profiles.m
+++ b/matlab/TCV_IMAS/tcv_get_ids_core_profiles.m
@@ -364,8 +364,8 @@ for it=1:length(ids_core_profiles.time)
     current_bootstrap.bs.bs_data.cd_dens.data(:,it);
   temp_1d_desc.j_bootstrap = current_bootstrap.bs.bs_data.cd_dens.label;
   ids_core_profiles.profiles_1d{it}.j_ohmic = ...
-    current_non_inductive.ohm.ohm_data.cd_dens.data(:,it);
-  temp_1d_desc.j_ohmic = current_non_inductive.ohm.ohm_data.cd_dens.label;
+    current_inductive.ohm.ohm_data.cd_dens.data(:,it);
+  temp_1d_desc.j_ohmic = current_inductive.ohm.ohm_data.cd_dens.label;
 end
 
 %% parallel conductivity (neoclassical)
-- 
GitLab


From 3f8b662cc50b7aec645ba615404eda65477f80bb Mon Sep 17 00:00:00 2001
From: Luke Simons <luke.simons@epfl.ch>
Date: Thu, 20 Mar 2025 12:45:08 +0100
Subject: [PATCH 6/7] Changed the calculation of current_non_inductive to be
 jtotal-johm-jbsav

---
 matlab/TCV_IMAS/tcv_get_ids_core_profiles.m | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/matlab/TCV_IMAS/tcv_get_ids_core_profiles.m b/matlab/TCV_IMAS/tcv_get_ids_core_profiles.m
index b8720c79..a8b2a1d9 100644
--- a/matlab/TCV_IMAS/tcv_get_ids_core_profiles.m
+++ b/matlab/TCV_IMAS/tcv_get_ids_core_profiles.m
@@ -100,9 +100,15 @@ global_quantities_desc.ip = params_eff.data_request;
 
 params_eff.data_request = 'ohm_data';
 current_inductive = gdat(params_cores_profiles.shot,params_eff);
-global_quantities.current_non_inductive.data = current_inductive.ohm.ohm_data.cd_tot.data;
+params_eff.data_request = '\tcv_shot::top.results.ibs:johmav';
+johmav = gdat(params_cores_profiles.shot,params_eff);
+params_eff.data_request = '\tcv_shot::top.results.ibs:jbsav';
+jbsav = gdat(params_cores_profiles.shot,params_eff);
+global_quantities.current_non_inductive.data = current_inductive.ohm.ohm_data.cd_tot.data- ...
+    johmav.data(end,:)-jbsav.data(end,:);
 global_quantities.current_non_inductive.t = current_inductive.ohm.ohm_data.cd_tot.t;
-global_quantities_desc.current_non_inductive = current_inductive.ohm.ohm_data.cd_tot.label;
+global_quantities_desc.current_non_inductive = [current_inductive.ohm.ohm_data.cd_tot.label ...
+    ' - ',johmav.label,' - ',jbsav.label];
 
 params_eff.data_request = 'bs_data';
 current_bootstrap = gdat(params_cores_profiles.shot,params_eff);
-- 
GitLab


From 30ab0fb3b5f238b4b4c0187a51a11c1d3149e22c Mon Sep 17 00:00:00 2001
From: Michele Marin <michele.marin@epfl.ch>
Date: Tue, 25 Mar 2025 11:39:16 +0100
Subject: [PATCH 7/7] Correcting currents and e-field. Still to remap from
 parallel to toroidal

---
 matlab/TCV_IMAS/tcv_get_ids_core_profiles.m | 75 ++++++++++++++-------
 1 file changed, 51 insertions(+), 24 deletions(-)

diff --git a/matlab/TCV_IMAS/tcv_get_ids_core_profiles.m b/matlab/TCV_IMAS/tcv_get_ids_core_profiles.m
index a8b2a1d9..8a93e18d 100644
--- a/matlab/TCV_IMAS/tcv_get_ids_core_profiles.m
+++ b/matlab/TCV_IMAS/tcv_get_ids_core_profiles.m
@@ -94,28 +94,34 @@ ids_core_profiles_description.vacuum_toroidal_field = [vacuum_toroidal_field_des
 % global_quantities_desc.* with description.
 % Use temp.* and temp_desc.* structures for temporary data
 
+%% Currents  MIGHT REQUIRE TOROIDAL->PARALLEL TRANSFORMATION
 params_eff.data_request='ip';
 global_quantities.ip = gdat(params_cores_profiles.shot,'ip','machine',machine);
 global_quantities_desc.ip = params_eff.data_request;
 
 params_eff.data_request = 'ohm_data';
 current_inductive = gdat(params_cores_profiles.shot,params_eff);
-params_eff.data_request = '\tcv_shot::top.results.ibs:johmav';
-johmav = gdat(params_cores_profiles.shot,params_eff);
-params_eff.data_request = '\tcv_shot::top.results.ibs:jbsav';
-jbsav = gdat(params_cores_profiles.shot,params_eff);
-global_quantities.current_non_inductive.data = current_inductive.ohm.ohm_data.cd_tot.data- ...
-    johmav.data(end,:)-jbsav.data(end,:);
-global_quantities.current_non_inductive.t = current_inductive.ohm.ohm_data.cd_tot.t;
-global_quantities_desc.current_non_inductive = [current_inductive.ohm.ohm_data.cd_tot.label ...
-    ' - ',johmav.label,' - ',jbsav.label];
+
+% current_inductive.data is smoothed
+% current_inductive.ohm.data and current_inductive.ohm.ohm_data.cd_tot.data are not. Unsmoothed data can be substituted below:
+%current_inductive.data = current_inductive.ohm.ohm_data.cd_tot.data;
+%current_inductive.label = current_inductive.ohm.ohm_data.cd_tot.label;
+
+current_inductive.data = current_inductive.data(1,:);
+current_inductive_desc = current_inductive.label(1);
 
 params_eff.data_request = 'bs_data';
-current_bootstrap = gdat(params_cores_profiles.shot,params_eff);
-global_quantities.current_bootstrap.data = current_bootstrap.bs.bs_data.cd_tot.data;
-global_quantities.current_bootstrap.t = current_bootstrap.bs.bs_data.cd_tot.t;
-global_quantities_desc.current_bootstrap = current_bootstrap.bs.bs_data.cd_tot.label;
+global_quantities.current_bootstrap = gdat(params_cores_profiles.shot,params_eff);
+
+% current_bootstrap.data is smoothed
+% current_bootstrap.ohm.data and current_bootstrap.ohm.ohm_data.cd_tot.data are not. Unsmoothed data can be substituted below:
+%global_quantities.current_bootstrap.data = global_quantities.current_bootstrap.ohm.ohm_data.cd_tot.data;
+%global_quantities.current_bootstrap.label = global_quantities.current_bootstrap.ohm.ohm_data.cd_tot.label;
 
+global_quantities.current_bootstrap.data = global_quantities.current_bootstrap.data(1,:);
+global_quantities_desc.current_bootstrap = global_quantities.current_bootstrap.label(1);
+
+%% Other global quantities
 params_eff.data_request = 'vloop';
 global_quantities.v_loop = gdat(params_cores_profiles.shot,params_eff);
 global_quantities_desc.v_loop = params_eff.data_request;
@@ -147,7 +153,7 @@ for i=1:length(global_quantities_fieldnames_eff)
   if ~any(strcmp(global_quantities_fieldnames_eff{i},special_fields))
     if ~isstruct(ids_core_profiles.global_quantities.(global_quantities_fieldnames_eff{i}))
       ids_core_profiles.global_quantities.(global_quantities_fieldnames_eff{i}) = ...
-          interpos(global_quantities.(global_quantities_fieldnames_eff{i}).t, ...
+          interpos_nan(global_quantities.(global_quantities_fieldnames_eff{i}).t, ...
           global_quantities.(global_quantities_fieldnames_eff{i}).data,ids_core_profiles.time,tens_time);
     else
       special_fields{end+1} = global_quantities_fieldnames_eff{i};
@@ -155,8 +161,26 @@ for i=1:length(global_quantities_fieldnames_eff)
   end
 end
 
-%% profiles_1d (cannot use eqdsk since not same radial mesh)
+%% Operations
+% Some data is already interpolated on the correct time grid at this point so operations should be done here
+% Interpolating what is not:
+current_inductive.data = ...
+    interpos_nan(current_inductive.t, ...
+    current_inductive.data,ids_core_profiles.time,tens_time);
+
+%ids_core_profiles.global_quantities.current_non_inductive = ids_core_profiles.global_quantities.ip - ...
+%        current_inductive.data - ids_core_profiles.global_quantities.current_bootstrap;
+%global_quantities_desc.current_non_inductive = string(global_quantities_desc.ip) + ' - ' + ...
+%        string(current_inductive_desc)  + ' - ' +string(global_quantities_desc.current_bootstrap);
 
+% In JINTRAC current_non_inductive includes the bootstrap current
+ids_core_profiles.global_quantities.current_non_inductive = ids_core_profiles.global_quantities.ip - ...
+        current_inductive.data;
+global_quantities_desc.current_non_inductive = string(global_quantities_desc.ip) + ' - ' + ...
+        string(current_inductive_desc);
+
+
+%% profiles_1d (cannot use eqdsk since not same radial mesh)
 % prepare area for ids_core_profiles.profiles_1d{*}.grid.area
 params_eff.data_request = 'area_rho';
 temp_1d.area = gdat(params_cores_profiles.shot,params_eff);
@@ -296,8 +320,8 @@ for it=1:length(ids_core_profiles.time)
   ids_core_profiles.profiles_1d{it}.ion{1}.density_thermal = ids_core_profiles.profiles_1d{it}.ion{1}.density;
   ids_core_profiles.profiles_1d{it}.ion{1}.pressure_thermal = 1.6022e-19.*ids_core_profiles.profiles_1d{it}.ion{1}.density_thermal ...
       .* ids_core_profiles.profiles_1d{it}.ion{1}.temperature;
-  ids_core_profiles.profiles_1d{it}.ion{1}.label = 'D+';
-  %
+  ids_core_profiles.profiles_1d{it}.ion{1}.name = 'D+';
+  
   ids_core_profiles.profiles_1d{it}.t_i_average = ids_core_profiles.profiles_1d{it}.ion{1}.temperature;
   ids_core_profiles.profiles_1d{it}.n_i_thermal_total = ids_core_profiles.profiles_1d{it}.ion{1}.density_thermal;
   ids_core_profiles.profiles_1d{it}.pressure_ion_total = 1.6022e-19 .* ids_core_profiles.profiles_1d{it}.n_i_thermal_total ...
@@ -317,7 +341,7 @@ for it=1:length(ids_core_profiles.time)
   ids_core_profiles.profiles_1d{it}.ion{2}.density_thermal = ids_core_profiles.profiles_1d{it}.ion{2}.density;
   ids_core_profiles.profiles_1d{it}.ion{2}.pressure_thermal = 1.6022e-19.*ids_core_profiles.profiles_1d{it}.ion{2}.density_thermal ...
       .* ids_core_profiles.profiles_1d{it}.ion{2}.temperature;
-  ids_core_profiles.profiles_1d{it}.ion{2}.label = 'C6+';
+  ids_core_profiles.profiles_1d{it}.ion{2}.name = 'C6+';
   % average/sums
   ids_core_profiles.profiles_1d{it}.t_i_average = ids_core_profiles.profiles_1d{it}.ion{1}.temperature;
   ids_core_profiles.profiles_1d{it}.n_i_thermal_total = ids_core_profiles.profiles_1d{it}.ion{1}.density_thermal + ...
@@ -363,12 +387,12 @@ for it=1:length(ids_core_profiles.time)
 end
 temp_1d_desc.magnetic_shear = 'from interpos with rhotor';
 
-%% Current densities
+%% Current densities, MIGHT REQUIRE TOROIDAL->PARALLEL TRANSFORMATION
 
 for it=1:length(ids_core_profiles.time)
   ids_core_profiles.profiles_1d{it}.j_bootstrap = ...
-    current_bootstrap.bs.bs_data.cd_dens.data(:,it);
-  temp_1d_desc.j_bootstrap = current_bootstrap.bs.bs_data.cd_dens.label;
+    global_quantities.current_bootstrap.bs.bs_data.cd_dens.data(:,it);
+  temp_1d_desc.j_bootstrap = global_quantities.current_bootstrap.bs.bs_data.cd_dens.label;
   ids_core_profiles.profiles_1d{it}.j_ohmic = ...
     current_inductive.ohm.ohm_data.cd_dens.data(:,it);
   temp_1d_desc.j_ohmic = current_inductive.ohm.ohm_data.cd_dens.label;
@@ -384,13 +408,16 @@ end
 %% e_field
 % From IDS description:
 % Electric field, averaged on the magnetic surface. E.g for the parallel component, average(E.B) /
-% B0, using core_profiles/vacuum_toroidal_field/b0 [V.m^-1]
+% B0, using core_profiles/vacuum_toroidal_field/b0 [V.m^-1]. It is quite constant. Is this correct?
 for it=1:length(ids_core_profiles.time)
+  %ids_core_profiles.profiles_1d{it}.e_field.parallel = ...
+  %  signeo.data(:,it).*(current_inductive.ohm.ohm_data.cd_dens.data(:,it));
   ids_core_profiles.profiles_1d{it}.e_field.parallel = ...
-    signeo.data(:,it).*(current_inductive.ohm.ohm_data.cd_dens.data(:,it));
-  temp_1d_desc.e_field.parallel = "\tcv_shot::top.results.ibs:johmav*\tcv_shot::top.results.ibs:signeo";
+    current_inductive.ohm.ohm_data.cd_dens.data(:,it)./signeo.data(:,it);
+  temp_1d_desc.e_field.parallel = "\tcv_shot::top.results.ibs:johmav / \tcv_shot::top.results.ibs:signeo";
 end
 
+
 %% add descriptions for profiles_1d
 ids_core_profiles_description.profiles_1d = temp_1d_desc;
 
-- 
GitLab