Skip to content
Snippets Groups Projects
Commit c3767654 authored by Olivier Sauter's avatar Olivier Sauter
Browse files

start generic profiles fit/gui

git-svn-id: https://spcsvn.epfl.ch/repos/TCV/gdat/trunk@5864 d63d8f72-b253-0410-a779-e742ad2e26cf
parent 7e23fffb
No related branches found
No related tags found
No related merge requests found
File added
This diff is collapsed.
function [profile_structs_out,error_status] = get_profile_structure(profile_struct_in);
%
% get data from self-description in single profile_struct_in following description in get_profiles.m
%
% profile_struct_in, input single structure, and profile_structs_out, output array of structure
%
error_status=-1001;
profile_struct_def = profile_struct_in;
data_request = profile_struct_def.keyword;
shot = profile_struct_def.shot;
i_structs_out = 0;
switch lower(data_request)
case {'ne_thomson','te_thomson','nete_thomson'}
i_underscore = findstr(data_request,'_');
data_request_gdat = [data_request(1:i_underscore-1) '_rho'];
aa=gdat(shot,data_request_gdat,'fit',1,'equil',profile_struct_def.profiles_params.equil);
if strcmp(data_request(1:i_underscore-1),'nete')
% extract ne and te parts into several profile_struct
to_extract = {'ne','te'};
else
to_extract = {data_request(1:i_underscore-1)};
end
for i=1:length(to_extract)
i_structs_out = i_structs_out + 1;
profile_structs_out{i_structs_out} = profile_struct_def;
if strcmp(profile_struct_def.profiles_params.machine,'tcv')
profile_structs_out{i_structs_out}.keyword = [to_extract{i} '_thomson'];
profile_structs_out{i_structs_out}.provenance = aa.data_fullpath;
profile_structs_out{i_structs_out}.gdat_params = aa.gdat_params;
profile_structs_out{i_structs_out}.data = aa.(to_extract{i}).data;
profile_structs_out{i_structs_out}.t = aa.(to_extract{i}).t;
profile_structs_out{i_structs_out}.error_bar = aa.(to_extract{i}).error_bar;
profile_structs_out{i_structs_out}.units = aa.(to_extract{i}).units;
profile_structs_out{i_structs_out}.label = [to_extract{i} '\_thomson'];
profile_structs_out{i_structs_out}.grid.rhotornorm = aa.grids_1d.rhotornorm;
profile_structs_out{i_structs_out}.grid.rhopolnorm = aa.grids_1d.rhopolnorm;
profile_structs_out{i_structs_out}.grid.rhovolnorm = aa.grids_1d.rhovolnorm;
profile_structs_out{i_structs_out}.grid.psi = aa.grids_1d.psi;
elseif strcmp(profile_struct_def.profiles_params.machine,'aug')
% for AUG, extract core and edge parts into separate structures
% core
profile_structs_out{i_structs_out}.keyword = [to_extract{i} '_thomson_core'];
profile_structs_out{i_structs_out}.provenance = aa.data_fullpath;
profile_structs_out{i_structs_out}.gdat_params = aa.gdat_params;
profile_structs_out{i_structs_out}.data = aa.(to_extract{i}).core.data;
profile_structs_out{i_structs_out}.t = aa.(to_extract{i}).core.t;
profile_structs_out{i_structs_out}.error_bar = aa.(to_extract{i}).core.error_bar;
profile_structs_out{i_structs_out}.units = aa.(to_extract{i}).units;
profile_structs_out{i_structs_out}.label = [to_extract{i} '\_thomson\_core'];
profile_structs_out{i_structs_out}.grid.rhotornorm = aa.(to_extract{i}).core.rhotornorm;
profile_structs_out{i_structs_out}.grid.rhopolnorm = aa.(to_extract{i}).core.rhopolnorm;
profile_structs_out{i_structs_out}.grid.rhovolnorm = aa.(to_extract{i}).core.rhovolnorm;
profile_structs_out{i_structs_out}.grid.psi = aa.(to_extract{i}).core.psi;
% edge
i_structs_out = i_structs_out + 1;
profile_structs_out{i_structs_out} = profile_struct_def;
profile_structs_out{i_structs_out}.keyword = [to_extract{i} '_thomson_edge'];
profile_structs_out{i_structs_out}.provenance = aa.data_fullpath;
profile_structs_out{i_structs_out}.gdat_params = aa.gdat_params;
profile_structs_out{i_structs_out}.data = aa.(to_extract{i}).edge.data;
profile_structs_out{i_structs_out}.t = aa.(to_extract{i}).edge.t;
profile_structs_out{i_structs_out}.error_bar = aa.(to_extract{i}).edge.error_bar;
profile_structs_out{i_structs_out}.units = aa.(to_extract{i}).units;
profile_structs_out{i_structs_out}.label = [to_extract{i} '\_thomson\_edge'];
profile_structs_out{i_structs_out}.grid.rhotornorm = aa.(to_extract{i}).edge.rhotornorm;
profile_structs_out{i_structs_out}.grid.rhopolnorm = aa.(to_extract{i}).edge.rhopolnorm;
profile_structs_out{i_structs_out}.grid.rhovolnorm = aa.(to_extract{i}).edge.rhovolnorm;
profile_structs_out{i_structs_out}.grid.psi = aa.(to_extract{i}).edge.psi;
else
disp(['In get_profile_structures: not ready yet for machine = ' profile_struct_def.profiles_params.machine]);
end
end
case {'ne_ida', 'te_ida'}
otherwise
disp(['case = ' data_request ' not defined yet in get_profile_structure, ask O. Sauter']);
return
end
function [profile_struct,varargout] = get_profiles(shot,data_request_in,varargin);
%
% data_request_in: 1 or several of the optional keywords related to the machine options for profiles
% for example: 'te_thomson', or {'te_thomson','te_ece'}, or {'ne_thomson','te_thomson'}
% (case insensitive)
%
% varargin in pairs:
% 'equil',equil_source: equilibrium source: EQI(default), EQH, etc for AUG or LIUQE1 (default), LIUQE2, etc for TCV
% 'machine', machine_name: 'TCV', 'AUG' (default is the default in gdat, thus local machine)
%
% output profile_struct is an array of structure for each requested keyword:
%
% profile_struct{i}.data, .t, .error_bar, .label, .shot, .keyword, .provenance, .comment, .q (q profile)
% profile_struct{i}.grid.rhotornorm, .rhopolnorm, .rhovolnorm, .rovera, .psi, .phi, .vol, .provenance
%
% profile_struct = get_profiles; % returns the list of possible keywords in profile_struct{i}.keyword
%
error_status = -1;
% default output structure
i_init=1;
profile_struct{i_init}.data = [];
profile_struct{i_init}.t = [];
profile_struct{i_init}.error_bar = [];
profile_struct{i_init}.label = [];
profile_struct{i_init}.shot = [];
profile_struct{i_init}.keyword = [];
profile_struct{i_init}.provenance = [];
profile_struct{i_init}.comment = [];
profile_struct{i_init}.q = [];
profile_struct{i_init}.grid.rhotornorm = [];
profile_struct{i_init}.grid.rhopolnorm = [];
profile_struct{i_init}.grid.rhovolnorm = [];
profile_struct{i_init}.grid.rovera = [];
profile_struct{i_init}.grid.psi = [];
profile_struct{i_init}.grid.phi = [];
profile_struct{i_init}.grid.vol = [];
profile_struct{i_init}.grid.provenance = [];
% default param
get_profiles_params.machine = [];
get_profiles_params.equil = [];
get_profiles_params.nverbose = [];
get_profiles_params.help.machine = 'machine to get data, aug or tcv at this stage';
get_profiles_params.help.equil = 'equilibrium source, use default of gdat as default';
get_profiles_params.help.nverbose = ...
'level of information written during the call to get_profiles, default=1, up to warnings but no details';
profile_struct{i_init}.profiles_params = get_profiles_params;
% defaults:
shot_eff = [];
if exist('shot') && ~isempty(shot); shot_eff = shot; end
data_request_eff = [];
if exist('data_request_in') && ~isempty(data_request_in)
if ischar(data_request_in)
data_request_eff{1} = data_request_in;
else
data_request_eff = data_request_in;
end
if ~iscell(data_request_eff)
disp('problem with data_request_in, expects string or cell of strings')
error_status=-2;
return
end
end
% get default machine
aa=gdat;
get_profiles_params.machine = aa.gdat_params.machine;
get_profiles_params.equil = aa.gdat_params.equil;
get_profiles_params.nverbose=1;
% extract parameters from pairs of varargin:
if nargin>=3
if mod(nargin-2,2)==0
for i=1:2:length(varargin)-1
if ischar(varargin{i})
% enforce lower case for any character driven input
if ischar(varargin{i+1})
get_profiles_params.(lower(varargin{i})) = lower(varargin{i+1});
else
get_profiles_params.(lower(varargin{i})) = varargin{i+1};
end
else
if get_profiles_params.nverbose>=1; warning(['varargin input argument nb: ' num2str(i) ...
' (nargin=' num2str(i+2) ') is incorrect, expects a character string']);
end
error_status=-11;
return
end
end
else
if get_profiles_params.nverbose>=1; ...
warning('number of varargin input arguments incorrect, cannot make pairs of parameters');
end
error_status=-12;
return
end
end
profile_struct{i_init}.profiles_params = get_profiles_params;
% list of keywords
keywords={'te_thomson','ne_thomson','vrot_cxrs','ni_cxrs','ti_cxrs','vpol_cxrs'};
keywords_tcv_only = [];
keywords_aug_only = {'te_ece','te_ida','ne_ida'};
if strcmp(get_profiles_params.machine,'tcv')
if ~isempty(keywords_tcv_only); keywords(end+1:end+length(keywords_tcv_only)) = keywords_tcv_only; end
elseif strcmp(get_profiles_params.machine,'aug')
if ~isempty(keywords_aug_only); keywords(end+1:end+length(keywords_aug_only)) = keywords_aug_only; end
else
if get_profiles_params.nverbose>=1
disp(['warning machine = ' get_profiles_params.machine ' is not known'])
return
end
end
keywords = sort(keywords);
if isempty(data_request_eff)
profile_struct{i_init}.keyword = keywords;
return
end
% fill in default structure for each data_requested keyword, ignore unexpected keywords
ieff = 0;
data_request_eff = sort(data_request_eff);
for i=1:length(data_request_eff)
if ~isempty(strmatch(data_request_eff{i},keywords,'exact'))
ieff = ieff + 1;
if ieff>1
profile_struct{ieff} = profile_struct{1};
end
profile_struct{ieff}.keyword = data_request_eff{i};
profile_struct{ieff}.shot = shot_eff;
else
if get_profiles_params.nverbose>=1
disp(['warning data_request = ' data_request_eff{i} ' is not available and ignored, ask O. Sauter'])
end
end
end
if ieff==0
profile_struct{i_init}.keyword = keywords;
return
end
% Now can fill in data using gdat calls (meaning that gdat calls should be more and more standardized as well to this structure)
% should use only profile_struct{ieff} to determine what to get, in order to make sure it is self-consistent and fully described
for i=1:length(profile_struct)
try
profile_struct{i} = get_profile_structure(profile_struct{i});
catch
if get_profiles_params.nverbose>=1
disp(['could not get_profile_structure for ' profile_struct{i}.keyword ', shot = ' num2str(profile_struct{i}.shot)]);
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment