0001 function [equil_new,N_lav,rho_LUKE_ts_sr,rho_psi_ts_sr,T_ts_fit,N_ts_fit,T_ts_sr,dT_ts_sr,N_ts_sr,dN_ts_sr,T_rmse,N_rmse] = EAST_thomson_scattering_Tene_fit(equil,R_ts,Z_ts,T_ts,dT_ts,N_ts,dN_ts,R_hcn,display_mode,nefit_mode)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037 if nargin == 8,
0038 display_mode = 0;
0039 nefit_mode = 2;
0040 end
0041
0042 if nargin == 9,
0043 nefit_mode = 2;
0044 end
0045
0046 if ~isfield(equil,'id')
0047 equil.id = '';
0048 end
0049
0050 rho_LUKE = equil.ptx(:,1)./equil.ptx(end,1);
0051 psin_LUKE = equil.psi_apRp./equil.psi_apRp(end);
0052
0053 equil_RZ = pt2rz_jd(equil);
0054
0055 T = @(x,a,b)a*exp(-x.^2/b^2);
0056
0057 if nefit_mode == 1
0058 N = @(x,a,b)a*(1-x.*x).^b;
0059 elseif nefit_mode == 2
0060 N = @(x,a,b,c)a./(1+exp((x-b)/c));
0061 end
0062
0063
0064
0065
0066 [Z_ts_s,is] = sort(Z_ts,'descend');
0067 T_ts_s = T_ts(is);
0068 dT_ts_s = dT_ts(is);
0069
0070 nonLinMdl_T_ts_s = fitnlm(Z_ts_s,T_ts_s,@(p,x)T(x,p(1),p(2)),[max(T_ts_s),1],'Weights',dT_ts_s);
0071 Z_ts_s_ss = linspace(min(Z_ts_s),max(Z_ts_s),1000);
0072 T_ts_s_ss_fit = T(Z_ts_s_ss,nonLinMdl_T_ts_s.Coefficients.Estimate('p1'),nonLinMdl_T_ts_s.Coefficients.Estimate('p2'));
0073 Zp_T_ts_s_ss_fit = Z_ts_s_ss(find(T_ts_s_ss_fit==max(T_ts_s_ss_fit)));
0074
0075 disp(['Zp (EFIT) = ',num2str(round(100*equil.Zp*100)/100),' (cm), Zp (Thomson Scattering) = ',num2str(round(100*Zp_T_ts_s_ss_fit*100)/100),' (cm)']);
0076
0077 N_ts_s = N_ts(is)/1e19;
0078 dN_ts_s = dN_ts(is)/1e19;
0079 N_ts_s(find(N_ts_s>100)) = NaN;
0080 dN_ts_s(find(N_ts_s>100)) = NaN;
0081
0082 X_ts_s = (R_ts - equil.Rp)*ones(size(Z_ts_s));
0083 Y_ts_s = Z_ts_s - equil.Zp;
0084
0085 rho_LUKE_ts_s = psi2rho_jd(equil,interp2(equil_RZ.x,equil_RZ.y,equil_RZ.xypsi_apRp'/equil.psi_apRp(end),X_ts_s,Y_ts_s));
0086
0087 Y_hcn = linspace(min(equil.pty(end,:)),max(equil.pty(end,:)),1000);
0088 grad_Y_hcn = gradient(Y_hcn);
0089 X_hcn = (R_hcn - equil.Rp)*ones(size(Y_hcn));
0090
0091 rho_hcn = psi2rho_jd(equil,interp2(equil_RZ.x,equil_RZ.y,equil_RZ.xypsi_apRp'/equil.psi_apRp(end),X_hcn,Y_hcn));
0092
0093 [rho_LUKE_ts_sr,isr] = sort(rho_LUKE_ts_s,'descend');
0094 T_ts_sr = T_ts_s(isr);
0095 dT_ts_sr = dT_ts_s(isr);
0096 N_ts_sr = N_ts_s(isr);
0097 dN_ts_sr = dN_ts_s(isr);
0098
0099 nonLinMdl_T_ts_sr = fitnlm(rho_LUKE_ts_sr,T_ts_sr,@(p,x)T(x,p(1),p(2)),[max(T_ts_sr),1],'Weights',dT_ts_sr);
0100
0101 if nefit_mode == 1
0102 nonLinMdl_N_ts_sr = fitnlm(rho_LUKE_ts_sr,N_ts_sr,@(p,x)N(x,p(1),p(2)),[max(N_ts_sr),0.5],'Weights',dN_ts_sr);
0103 elseif nefit_mode == 2
0104 nonLinMdl_N_ts_sr = fitnlm(rho_LUKE_ts_sr,N_ts_sr,@(p,x)N(x,p(1),p(2),p(3)),[max(N_ts_sr),0.5,0.5],'Weights',dN_ts_sr);
0105 end
0106
0107 T_ts_fit = T(rho_LUKE,nonLinMdl_T_ts_sr.Coefficients.Estimate('p1'),nonLinMdl_T_ts_sr.Coefficients.Estimate('p2'));
0108
0109 if nefit_mode == 1
0110 N_ts_fit = N(rho_LUKE,nonLinMdl_N_ts_sr.Coefficients.Estimate('p1'),nonLinMdl_N_ts_sr.Coefficients.Estimate('p2'));
0111 N_hcn_fit = N(rho_hcn,nonLinMdl_N_ts_sr.Coefficients.Estimate('p1'),nonLinMdl_N_ts_sr.Coefficients.Estimate('p2'));
0112 elseif nefit_mode == 2
0113 N_ts_fit = N(rho_LUKE,nonLinMdl_N_ts_sr.Coefficients.Estimate('p1'),nonLinMdl_N_ts_sr.Coefficients.Estimate('p2'),nonLinMdl_N_ts_sr.Coefficients.Estimate('p3'));
0114 N_hcn_fit = N(rho_hcn,nonLinMdl_N_ts_sr.Coefficients.Estimate('p1'),nonLinMdl_N_ts_sr.Coefficients.Estimate('p2'),nonLinMdl_N_ts_sr.Coefficients.Estimate('p3'));
0115 end
0116
0117 N_hcn_fit(isnan(N_hcn_fit)) = 0;
0118 N_lav = sum(N_hcn_fit.*grad_Y_hcn)./sum(grad_Y_hcn);
0119
0120 if display_mode == 1
0121
0122 figure,plot(Z_ts_s,T_ts_s,'ro',Z_ts_s_ss,T_ts_s_ss_fit,equil.Zp,T_ts_s_ss_fit(find(T_ts_s_ss_fit==max(T_ts_s_ss_fit))),'kx',Zp_T_ts_s_ss_fit,T_ts_s_ss_fit(find(T_ts_s_ss_fit==max(T_ts_s_ss_fit))),'k+');grid on
0123 hold on,errorbar(Z_ts_s,T_ts_s,dT_ts_s,'ro');
0124 axis([min(Z_ts) max(Z_ts) 0 max(T_ts_s)]);
0125 title([strrep(equil.id,'_','-'),', raw Te profile (Thomson scattering)']),xlabel(['Z@R=',num2str(R_ts),' (m)']),ylabel('T_e (eV)')
0126 legend('Exp.','Fit',['Z_p(EFIT) = ',num2str(round(100*equil.Zp*100)/100),' (cm)'],['Z_p(Fit) = ',num2str(round(100*Zp_T_ts_s_ss_fit*100)/100),' (cm)'])
0127
0128 figure,plot(Z_ts_s,N_ts_sr,'ro');grid on
0129 hold on,errorbar(Z_ts_s,N_ts_sr,dN_ts_sr,'ro');
0130 axis([min(Z_ts) max(Z_ts) 0 max(N_ts_sr)]);
0131 title([strrep(equil.id,'_','-'),', raw Ne profile (Thomson scattering)']),xlabel(['Z@R=',num2str(R_ts),' (m)']),ylabel('N_e (10^{+19} m^{-3})')
0132
0133 figure,plot(rho_LUKE_ts_sr,T_ts_sr,'ro',rho_LUKE,T_ts_fit);grid on
0134 hold on,errorbar(rho_LUKE_ts_sr,T_ts_sr,dT_ts_sr,'ro');
0135 axis([0 1 0 max(T_ts_sr)]);
0136 title([strrep(equil.id,'_','-'),', Te profile for LUKE']),xlabel('\rho_{LUKE}'),ylabel('T_e (eV)')
0137 legend('Exp.','Fit')
0138
0139 figure,plot(rho_LUKE_ts_sr,N_ts_sr,'ro',rho_LUKE,N_ts_fit);grid on
0140 hold on,errorbar(rho_LUKE_ts_sr,N_ts_sr,dN_ts_sr,'ro');
0141 axis([0 1 0 max(N_ts_sr)]);
0142 title([strrep(equil.id,'_','-'),', Ne profile for LUKE']),xlabel('\rho_{LUKE}'),ylabel('N_e (10^{+19} m^{-3})')
0143 legend('Exp.',['Fit, <n_e> = ',num2str(round(N_lav*1000)/1000),' 10^{+19} m^{-3}'],'Location','SouthWest')
0144
0145 figure,plot(sqrt(rho2psi_jd(equil,rho_LUKE_ts_sr)),T_ts_sr,'ro',sqrt(psin_LUKE),T_ts_fit);grid on
0146 hold on,errorbar(sqrt(rho2psi_jd(equil,rho_LUKE_ts_sr)),T_ts_sr,dT_ts_sr,'ro');
0147 axis([0 1 0 max(T_ts_sr)]);
0148 title([strrep(equil.id,'_','-'),', Te profile for LUKE']),xlabel('\rho = sqrt(\psi_{n})'),ylabel('T_e (eV)')
0149 legend('Exp.','Fit')
0150
0151 figure,plot(sqrt(rho2psi_jd(equil,rho_LUKE_ts_sr)),N_ts_sr,'ro',sqrt(psin_LUKE),N_ts_fit);grid on
0152 hold on,errorbar(sqrt(rho2psi_jd(equil,rho_LUKE_ts_sr)),N_ts_sr,dN_ts_sr,'ro');
0153 axis([0 1 0 max(N_ts_sr)]);
0154 title([strrep(equil.id,'_','-'),', Ne profile for LUKE']),xlabel('\rho = sqrt(\psi_{n})'),ylabel('N_e (10^{+19} m^{-3})')
0155 legend('Exp.',['Fit, <n_e> = ',num2str(round(N_lav*1000)/1000),' 10^{+19} m^{-3}'],'Location','SouthWest')
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165 end
0166
0167 rho_psi_ts_sr = sqrt(rho2psi_jd(equil,rho_LUKE_ts_sr));
0168
0169 T_ts_sr = T_ts_sr/1000;
0170 dT_ts_sr = dT_ts_sr/1000;
0171 N_ts_sr = N_ts_sr*1e19;
0172 dN_ts_sr = dN_ts_sr*1e19;
0173 T_ts_fit = T_ts_fit/1000;
0174 N_ts_fit = N_ts_fit*1e19;
0175
0176 T_rmse = nonLinMdl_T_ts_sr.RMSE/1000;
0177 N_rmse = nonLinMdl_N_ts_sr.RMSE*1e19;
0178
0179
0180 equil_new = equil;
0181
0182 equil_new.pTe = T_ts_fit;
0183 equil_new.pne = N_ts_fit;
0184
0185
0186
0187
0188
0189
0190
0191
0192