0001 function external = load_externaldata_COMPASS(external_in,opt_gui)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 if nargin == 0,
0013
0014
0015
0016 external.shotnum = 0;
0017 external.shotime = 0;
0018
0019
0020
0021 external.info.shotnum = 'Shot number';
0022 external.info.shotime = 'Shot time (s)';
0023
0024
0025
0026 external.expert.shotnum = 0;
0027 external.expert.shotime = 0;
0028
0029
0030
0031 external.values.shotnum = [0;Inf];
0032 external.values.shotime = [0;Inf];
0033
0034 return
0035
0036 end
0037
0038 if nargin < 2,
0039 opt_gui = false;
0040 end
0041
0042 shotnum = external_in.shotnum;
0043 shotime = external_in.shotime;
0044
0045
0046
0047 external = '';
0048 basestr = 'COMPASS';
0049
0050 if exist('cdb_client','file') == 2,
0051
0052 data_out = compass2luke(shotnum);
0053
0054 else
0055 [filename,pathname] = igetfile_jd(opt_gui,'*.mat',['Please select the COMPASS data file for shot # ',shotnum],'',0);
0056
0057 if filename ~= 0,
0058 load([pathname,filename],'data_out');
0059 else
0060 disp(' ');disp('--> Read remotely from COMPASS database');disp(' ');
0061 [remote,profilestr] = load_remoteprofiles_jd('IPP_ABACUS',false,true,'direct',NaN,true);
0062 [err_data,~,data_out] = matremote_jd('compass2luke',{shotnum},remote,matstandardjob_jd('runmat'));
0063
0064 if err_data ~= 0,
0065 return
0066 end
0067 end
0068 end
0069
0070 if shotime == 0,
0071 ishotime = round(length(data_out.efit.li.time_axis.data)/2);
0072 shotime = data_out.efit.li.time_axis.data(ishotime)/1e3;
0073 disp(' ');disp(['WARNING: The shot time has been enforced to ',num2str(shotime),' (s)']);disp(' ');
0074 else,
0075 ishotime = interp1(data_out.efit.li.time_axis.data,[1:length(data_out.efit.li.time_axis.data)],shotime,'nearest')
0076 shotime = data_out.efit.li.time_axis.data(ishotime)/1e3;
0077 disp(' ');disp(['WARNING: The nearest shot time is ',num2str(shotime),' (s)']);disp(' ');
0078 end
0079
0080
0081
0082
0083
0084
0085
0086 triangularity_lower_lcfs.t = data_out.efit.triangularity_lower_lcfs.time_axis.data(ishotime)/1e3;
0087 triangularity_lower_lcfs.data = data_out.efit.triangularity_lower_lcfs.data(ishotime);
0088 li.t = data_out.efit.li.time_axis.data(ishotime)/1e3;
0089 li.data = data_out.efit.li.data(ishotime);
0090 Ip.t = data_out.efit.Ip.time_axis.data(ishotime)/1e3;
0091 Ip.data = data_out.efit.Ip.data(ishotime);
0092 q.t = data_out.efit.q.time_axis.data(ishotime)/1e3;
0093 q.data = data_out.efit.q.data(ishotime,:);
0094
0095 psi_RZ.t = data_out.efit.psi_RZ.time_axis.data(ishotime)/1e3;
0096 psi_RZ.data = data_out.efit.psi_RZ.data(ishotime,:,:);
0097 psi_RZ.R = data_out.efit.psi_RZ.axis1.data(ishotime,:);
0098 psi_RZ.Z = data_out.efit.psi_RZ.axis2.data(ishotime,:);
0099 psi_n.data = data_out.efit.psi_n.data;
0100 psi_mag_axis.t = data_out.efit.psi_mag_axis.time_axis.data(ishotime)/1e3;
0101 psi_mag_axis.data = data_out.efit.psi_mag_axis.data(ishotime);
0102 psi_lcfs.t = data_out.efit.psi_lcfs.time_axis.data(ishotime)/1e3;
0103 psi_lcfs.data = data_out.efit.psi_lcfs.data(ishotime);
0104
0105 R_mag_axis.t = data_out.efit.R_mag_axis.time_axis.data(ishotime)/1e3;
0106 R_mag_axis.data = data_out.efit.R_mag_axis.data(ishotime,:,:);
0107 Z_mag_axis.t = data_out.efit.Z_mag_axis.time_axis.data(ishotime)/1e3;
0108 Z_mag_axis.data = data_out.efit.Z_mag_axis.data(ishotime,:,:);
0109 R_geom_axis.t = data_out.efit.R_geom_axis.time_axis.data(ishotime)/1e3;
0110 R_geom_axis.data = data_out.efit.R_geom_axis.data(ishotime,:,:);
0111 Z_geom_axis.t = data_out.efit.Z_geom_axis.time_axis.data(ishotime)/1e3;
0112 Z_geom_axis.data = data_out.efit.Z_geom_axis.data(ishotime,:,:);
0113
0114 B_vac_R_geom.t = data_out.efit.B_vac_R_geom.time_axis.data(ishotime)/1e3;
0115 B_vac_R_geom.data = data_out.efit.B_vac_R_geom.data(ishotime,:,:);
0116 RBphi.t = data_out.efit.RBphi.time_axis.data(ishotime)/1e3;
0117 RBphi.data = data_out.efit.RBphi.data(ishotime,:,:);
0118 FFprime.t = data_out.efit.FFprime.time_axis.data(ishotime)/1e3;
0119 FFprime.data = data_out.efit.FFprime.data(ishotime,:,:);
0120 pprime_static.t = data_out.efit.pprime_static.time_axis.data(ishotime)/1e3;
0121 pprime_static.data = data_out.efit.pprime_static.data(ishotime,:,:);
0122 p_stat.t = data_out.efit.p_stat.time_axis.data(ishotime)/1e3;
0123 p_stat.data = data_out.efit.p_stat.data(ishotime,:,:);
0124
0125 if isfield(data_out,'ne') && isfield(data_out,'te'),
0126 pne.t = shotime;
0127 pne.x = data_out.ne.axis1.data;
0128 pne.data = interp1(data_out.ne.time_axis.data/1e3,data_out.ne.data,shotime,'linear');
0129 pne.data = compass_ts_profile_fit(pne,psi_RZ,psi_n.data,psi_lcfs.data,psi_mag_axis.data);
0130
0131 pTe.t = shotime;
0132 pTe.x = data_out.te.axis1.data;
0133 pTe.data = interp1(data_out.te.time_axis.data/1e3,data_out.te.data/1e3,shotime,'linear');
0134 pTe.data = compass_ts_profile_fit(pTe,psi_RZ,psi_n.data,psi_lcfs.data,psi_mag_axis.data);
0135 else
0136 pne.t = [];
0137 pne.data = [];
0138 pTe.t = [];
0139 pTe.data = [];
0140 end
0141
0142
0143
0144 U_loop.t = shotime;
0145
0146 t_resample = 100;
0147 U_loop.data = interp1(data_out.U_loop.time_axis.data(t_resample/2:t_resample:end-t_resample/2)/1e3,compass_resample_data(data_out.U_loop.data,t_resample),shotime,'linear');
0148
0149 I_plasma.t = shotime;
0150
0151 I_plasma.data = interp1(data_out.I_plasma.time_axis.data(t_resample/2:t_resample:end-t_resample/2)/1e3,compass_resample_data(data_out.I_plasma.data,t_resample),shotime,'linear');
0152
0153
0154
0155
0156 external.basestr = basestr;
0157 external.shotnum = num2str(shotnum);
0158 external.shotime = shotime;
0159
0160 external.ohm.vloop = U_loop.data;
0161
0162 external.equil.shotnum = external.shotnum;
0163 external.equil.shotime = external.shotime;
0164
0165 external.equil.magnetic.I_plasma = I_plasma.data;
0166
0167 external.equil.magnetic.efit.triangularity_lower_lcfs = triangularity_lower_lcfs.data;
0168 external.equil.magnetic.efit.li = li.data;
0169 external.equil.magnetic.efit.Ip = Ip.data;
0170 external.equil.magnetic.efit.q = q.data;
0171
0172 external.equil.magnetic.efit.psi_RZ = reshape(psi_RZ.data,[length(psi_RZ.R),length(psi_RZ.Z)]);
0173 external.equil.magnetic.efit.psi_n = psi_n.data;
0174 external.equil.magnetic.efit.psi_mag_axis = psi_mag_axis.data;
0175 external.equil.magnetic.efit.psi_lcfs = psi_lcfs.data;
0176
0177 external.equil.magnetic.efit.R = psi_RZ.R;
0178 external.equil.magnetic.efit.Z = psi_RZ.Z;
0179 external.equil.magnetic.efit.R_mag_axis = R_mag_axis.data;
0180 external.equil.magnetic.efit.Z_mag_axis = Z_mag_axis.data;
0181 external.equil.magnetic.efit.R_geom_axis = R_geom_axis.data;
0182 external.equil.magnetic.efit.Z_geom_axis = Z_geom_axis.data;
0183
0184 external.equil.magnetic.efit.B_vac_R_geom = B_vac_R_geom.data;
0185 external.equil.magnetic.efit.RBphi = RBphi.data;
0186 external.equil.magnetic.efit.FFprime = FFprime.data;
0187 external.equil.magnetic.efit.pprime_static = pprime_static.data;
0188 external.equil.magnetic.efit.p_stat = p_stat.data;
0189
0190 external.equil.prof.pne = pne.data;
0191 external.equil.prof.pTe = pTe.data;
0192
0193 external.equil.prof.pspsin = psi_n.data;
0194 external.equil.prof.pne = pne.data;
0195 external.equil.prof.pTe = pTe.data;
0196 external.equil.prof.pTi = pTe.data/2;
0197 external.equil.prof.Zeff = 2;
0198 external.equil.prof.fi = [0,1,0];
0199 external.equil.prof.zZi = [1,1,1,6];
0200 external.equil.prof.zmi = [1,2,3,12];
0201
0202 external.id = ['COMPASS_',external.shotnum,'_',num2str(shotime,'%6.4f')];
0203
0204 if isnan_jd(external,0),
0205 disp('Warning : NaNs were found in the structure ''external'' : ')
0206 end
0207
0208 end
0209
0210 function [data_out] = compass_ts_profile_fit(data_in,psi_RZ,psi_n,psi_lcfs,psi_mag_axis)
0211
0212
0213
0214 x = data_in.x;
0215 ts = data_in.data;
0216
0217
0218
0219
0220 psi_ts = interp2(psi_RZ.R,psi_RZ.Z,squeeze(psi_RZ.data).',0.56,x,'spline');
0221 psin_ts = (psi_ts - psi_mag_axis)/(psi_lcfs - psi_mag_axis);
0222
0223 ipoints = find(x < 0.18);
0224
0225 ts_ptot = ts(ipoints);
0226
0227 figure,subplot(2,1,1)
0228 title('Thomson scattering density profile')
0229 hold on
0230 plot(x(ipoints),ts(ipoints) ,'rx');
0231 plot(x,ts,'b');
0232
0233 ylabel('Profile values');
0234 xlabel('Z coordinate [m]');
0235 hold off
0236
0237 ts_psin = psin_ts(ipoints);
0238
0239 sfactor = 0.999;
0240 ptot_fit = fit(psin_ts(ipoints), ts_ptot.', 'smoothingspline', 'SmoothingParam', sfactor);
0241 data_out = ptot_fit(psi_n);
0242
0243 subplot(2,1,2)
0244 hold on
0245 plot(psin_ts(ipoints), ts_ptot.', 'rx')
0246 plot(psi_n, data_out, 'b')
0247
0248 ylabel('Profile values')
0249 xlabel('Normalized \psi')
0250 hold off
0251
0252 end
0253
0254 function res = compass_resample_data(data, ww)
0255
0256
0257
0258
0259
0260
0261
0262
0263 data = reshape(data, [], 1);
0264
0265
0266 n_mod = mod(length(data), ww);
0267 data = data(1:end-n_mod);
0268
0269 data = reshape(data, ww, []);
0270 res = mean(data, 1);
0271
0272 end
0273