diff --git a/crpptbx/data_generic_fit_gui.fig b/crpptbx/data_generic_fit_gui.fig new file mode 100644 index 0000000000000000000000000000000000000000..005e1354562fd55ec5fe1e019f147933600b2a70 Binary files /dev/null and b/crpptbx/data_generic_fit_gui.fig differ diff --git a/crpptbx/data_generic_fit_gui.m b/crpptbx/data_generic_fit_gui.m new file mode 100644 index 0000000000000000000000000000000000000000..c50400d6202c49dde03bbd2bf373634f469778d8 --- /dev/null +++ b/crpptbx/data_generic_fit_gui.m @@ -0,0 +1,605 @@ +function varargout = data_generic_fit_gui(varargin) +% DATA_GENERIC_FIT_GUI MATLAB code for data_generic_fit_gui.fig +% DATA_GENERIC_FIT_GUI, by itself, creates a new DATA_GENERIC_FIT_GUI or raises the existing +% singleton*. +% +% H = DATA_GENERIC_FIT_GUI returns the handle to a new DATA_GENERIC_FIT_GUI or the handle to +% the existing singleton*. +% +% DATA_GENERIC_FIT_GUI('CALLBACK',hObject,eventData,handles,...) calls the local +% function named CALLBACK in DATA_GENERIC_FIT_GUI.M with the given input arguments. +% +% DATA_GENERIC_FIT_GUI('Property','Value',...) creates a new DATA_GENERIC_FIT_GUI or raises the +% existing singleton*. Starting from the left, property value pairs are +% applied to the GUI before data_generic_fit_gui_OpeningFcn gets called. An +% unrecognized property name or invalid value makes property application +% stop. All inputs are passed to data_generic_fit_gui_OpeningFcn via varargin. +% +% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one +% instance to run (singleton)". +% +% See also: GUIDE, GUIDATA, GUIHANDLES + +% Edit the above text to modify the response to help data_generic_fit_gui + +% Last Modified by GUIDE v2.5 19-Apr-2016 12:03:30 + +% Begin initialization code - DO NOT EDIT +gui_Singleton = 1; +gui_State = struct('gui_Name', mfilename, ... + 'gui_Singleton', gui_Singleton, ... + 'gui_OpeningFcn', @data_generic_fit_gui_OpeningFcn, ... + 'gui_OutputFcn', @data_generic_fit_gui_OutputFcn, ... + 'gui_LayoutFcn', [] , ... + 'gui_Callback', []); +if nargin && ischar(varargin{1}) + gui_State.gui_Callback = str2func(varargin{1}); +end + +if nargout + [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); +else + gui_mainfcn(gui_State, varargin{:}); +end +% End initialization code - DO NOT EDIT + + +% --- Executes just before data_generic_fit_gui is made visible. +function data_generic_fit_gui_OpeningFcn(hObject, eventdata, handles, varargin) +% This function has no output args, see OutputFcn. +% hObject handle to figure +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) +% varargin command line arguments to data_generic_fit_gui (see VARARGIN) + +% Choose default command line output for data_generic_fit_gui +handles.output = hObject; + +% change defaults here to avoid changing .fig too much: +tension_left_def = str2double(get(handles.set_tension_left,'string')); +tension_left_def_eff = -1; +set(handles.set_tension_left,'string',num2str(tension_left_def_eff)); + +handles = init_data_generic_gui(handles); + +% Update handles structure +guidata(hObject, handles); + +% UIWAIT makes data_generic_fit_gui wait for user response (see UIRESUME) +% uiwait(handles.figure1); + + +% --- Outputs from this function are returned to the command line. +function varargout = data_generic_fit_gui_OutputFcn(hObject, eventdata, handles) +% varargout cell array for returning output args (see VARARGOUT); +% hObject handle to figure +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + +% Get default command line output from handles structure +varargout{1} = handles.output; + + +% --- Executes on slider movement. +function time_set_slider_Callback(hObject, eventdata, handles) +% hObject handle to time_set_slider (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + +% Hints: get(hObject,'Value') returns position of slider +% get(hObject,'Min') and get(hObject,'Max') to determine range of slider + +time_slide = get(hObject,'Value'); +time_eff = handles.data_time_int(1) + (time_slide-handles.slider_range(1))./diff(handles.slider_range).*(handles.data_time_int(end)-handles.data_time_int(1)); +handles.it_index_left = iround_os(handles.data_left.t,time_eff); +handles.it_index_right = iround_os(handles.data_right.t,time_eff); +set(handles.time_set_value,'string',num2str(time_eff)); + + +replot(handles); + +% --- Executes during object creation, after setting all properties. +function time_set_slider_CreateFcn(hObject, eventdata, handles) +% hObject handle to time_set_slider (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles empty - handles not created until after all CreateFcns called + +% Hint: slider controls usually have a light gray background. +if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) + set(hObject,'BackgroundColor',[.9 .9 .9]); +end + + + +function time_set_value_Callback(hObject, eventdata, handles) +% hObject handle to time_set_value (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + +% Hints: get(hObject,'String') returns contents of time_set_value as text +% str2double(get(hObject,'String')) returns contents of time_set_value as a double + +time = get(handles.time_set_value,'string'); +time = str2num(time); +handles.it_index_left = iround_os(handles.data_left.t,time) +handles.it_index_right = iround_os(handles.data_right.t,time) +time_slide = (time-handles.data_time_int(1))./(handles.data_time_int(end)-handles.data_time_int(1)).*diff(handles.slider_range) + handles.slider_range(1); +set(handles.time_set_slider,'Value',time_slide); + +replot(handles); + +guidata(hObject, handles); + +% --- Executes during object creation, after setting all properties. +function time_set_value_CreateFcn(hObject, eventdata, handles) +% hObject handle to time_set_value (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles empty - handles not created until after all CreateFcns called + +% Hint: edit controls usually have a white background on Windows. +% See ISPC and COMPUTER. +if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) + set(hObject,'BackgroundColor','white'); +end + +function replot(handles) +% hObject handle to time_set_value (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + +% Hints: get(hObject,'String') returns contents of time_set_value as text +% str2double(get(hObject,'String')) returns contents of time_set_value as a double + +% left plot + +ihold_left = get(handles.set_hold_left,'Value'); +if ihold_left ==0 + hold(handles.left_axes,'off'); +else + hold(handles.left_axes,'all'); +end +prov_list=unique(handles.data_left.perDt{handles.it_index_left}.provenance); +for i=1:length(prov_list) + ij=find(handles.data_left.perDt{handles.it_index_left}.provenance==prov_list(i)); + errorbar(handles.left_axes,handles.data_left.perDt{handles.it_index_left}.rho(ij),handles.data_left.perDt{handles.it_index_left}.data(ij),handles.data_left.perDt{handles.it_index_left}.error_bar(ij),'*'); + hold(handles.left_axes,'all'); +end +plot(handles.left_axes,handles.fit_left.rhofit,handles.fit_left.data(:,handles.it_index_left),'-'); +set(handles.left_axes,'XLim',[0 1.2]); +left_max = str2double(get(handles.set_left_max,'String')); +if left_max>0 + set(handles.left_axes,'YLim',[0 left_max]); +end + +% right +ihold_right = get(handles.set_hold_right,'Value'); +if ihold_right ==0 + hold(handles.right_axes,'off'); +else + hold(handles.right_axes,'all'); +end +prov_list=unique(handles.data_right.perDt{handles.it_index_right}.provenance); +for i=1:length(prov_list) + ij=find(handles.data_right.perDt{handles.it_index_right}.provenance==prov_list(i)); + errorbar(handles.right_axes,handles.data_right.perDt{handles.it_index_right}.rho(ij),handles.data_right.perDt{handles.it_index_right}.data(ij),handles.data_right.perDt{handles.it_index_right}.error_bar(ij),'*'); + hold(handles.right_axes,'all'); +end +plot(handles.right_axes,handles.fit_right.rhofit,handles.fit_right.data(:,handles.it_index_right),'-'); +set(handles.right_axes,'XLim',[0 1.2]); +right_max = str2double(get(handles.set_right_max,'String')); +if right_max>0 + set(handles.right_axes,'YLim',[0 right_max]); +end + +% lambda_left +if ihold_left ==0 + hold(handles.set_axes_lambda_left,'off'); +else + hold(handles.set_axes_lambda_left,'all'); +end +plot(handles.set_axes_lambda_left,handles.fit_left.rhofit,-handles.fit_left.dydrho(:,handles.it_index_left)./handles.fit_left.data(:,handles.it_index_left),'-'); + +% lambda_right +if ihold_right ==0 + hold(handles.set_axes_lambda_right,'off'); +else + hold(handles.set_axes_lambda_right,'all'); +end +plot(handles.set_axes_lambda_right,handles.fit_right.rhofit,-handles.fit_right.dydrho(:,handles.it_index_right)./handles.fit_right.data(:,handles.it_index_right),'-'); +set(handles.set_axes_lambda_right,'XAxisLocation','top') +set(handles.set_axes_lambda_right,'YAxisLocation','right') + +zoom(handles.left_axes,'on'); +zoom(handles.right_axes,'on'); + + +function set_shot_Callback(hObject, eventdata, handles) +% hObject handle to set_shot (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + +% Hints: get(hObject,'String') returns contents of set_shot as text +% str2double(get(hObject,'String')) returns contents of set_shot as a double + +shot = get(handles.set_shot,'String'); shot = str2num(shot); +handles.shot = shot; + +[fname,fpath] = uigetfile([{['*' num2str(shot) '*gen_signals*']},{'*shot*gen_signals* files'}; ... + {'*.mat'},{'*.mat files'};{'*'},{'All files'}],'Select a file with the data_in correct structure' ); + +handles.fname = fname; +handles.fpath = fpath; +data_gen = load(fullfile(fpath,fname)); +if isfield(data_gen,'gen_signals_data') + gen_signals = data_gen.gen_signals_data; +else + gen_signals = data_gen; +end +handles.gen_signals = gen_signals; + +fields_avail = fieldnames(gen_signals); +if length(fields_avail)>0 + set(handles.popup_data_left,'string',fields_avail); + set(handles.popup_data_right,'string',fields_avail); +else + disp(['problems with subfields in file: ',fullfile(fname,fpath)]); + return +end +if length(fields_avail)>=2 + set(handles.popup_data_right,'value',2); +end + +handles = init_data_generic_gui(handles); + +handles = refit(handles); +replot(handles); + +% Update handles structure +guidata(hObject, handles); + + +% --- Executes during object creation, after setting all properties. +function set_shot_CreateFcn(hObject, eventdata, handles) +% hObject handle to set_shot (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles empty - handles not created until after all CreateFcns called + +% Hint: edit controls usually have a white background on Windows. +% See ISPC and COMPUTER. +if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) + set(hObject,'BackgroundColor','white'); +end + +function handles_out = init_data_generic_gui(handles) +% hObject handle to time_set_value (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + +try + % left part do the fits + structs_left = get(handles.popup_data_left,'string'); + valeff = get(handles.popup_data_left,'value'); + struct_left = structs_left{valeff}; + % right part + structs_right = get(handles.popup_data_right,'string'); + valeff = get(handles.popup_data_right,'value'); + struct_right = structs_right{valeff}; + + handles.data_left = handles.gen_signals.(struct_left).combined_data; + handles.fit_left = handles.gen_signals.(struct_left).fit; + handles.data_right = handles.gen_signals.(struct_right).combined_data; + handles.fit_right = handles.gen_signals.(struct_right).fit; + handles.slider_range = [get(handles.time_set_slider,'Min') get(handles.time_set_slider,'Max')]; + handles.data_time_int = [min(handles.data_left.t(1),handles.data_left.t(end)) max(handles.data_left.t(1),handles.data_left.t(end))]; + time_prev = get(handles.time_set_value,'string'); + if strcmp(time_prev,'Edit Text') + time_def = 0.5; + handles.it_index_left = iround_os(handles.data_left.t,time_def); + handles.it_index_right = iround_os(handles.data_right.t,time_def); + set(handles.time_set_value,'string',num2str(time_def)); + time_slide = abs((time_def-handles.data_time_int(1))./(handles.data_time_int(end)-handles.data_time_int(1)).*diff(handles.slider_range) + handles.slider_range(1)); + if time_slide>1; time_slide=1; end + set(handles.time_set_slider,'Value',time_slide); + else + time = str2num(time_prev); + handles.it_index_left = iround_os(handles.data_left.t,time); + handles.it_index_right = iround_os(handles.data_right.t,time); + time_slide = abs((time-handles.data_time_int(1))./(handles.data_time_int(end)-handles.data_time_int(1)).*diff(handles.slider_range) + handles.slider_range(1)); + if time_slide>1; time_slide=1; end + set(handles.time_set_slider,'Value',time_slide); + end + + set(handles.set_shot,'string',num2str(handles.shot)); + +catch + % no such file + handles.data = []; + handles.fit = []; + handles.it_index = []; + set(handles.set_shot,'string','enter shot'); +end + +handles_out = handles; + + + +function set_tension_left_Callback(hObject, eventdata, handles) +% hObject handle to set_tension_left (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + +% Hints: get(hObject,'String') returns contents of set_tension_left as text +% str2double(get(hObject,'String')) returns contents of set_tension_left as a double + +handles = refit(handles); +replot(handles); +guidata(hObject, handles); + +% --- Executes during object creation, after setting all properties. +function set_tension_left_CreateFcn(hObject, eventdata, handles) +% hObject handle to set_tension_left (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles empty - handles not created until after all CreateFcns called + +% Hint: edit controls usually have a white background on Windows. +% See ISPC and COMPUTER. +if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) + set(hObject,'BackgroundColor','white'); +end + + + +function set_tension_right_Callback(hObject, eventdata, handles) +% hObject handle to set_tension_right (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + +% Hints: get(hObject,'String') returns contents of set_tension_right as text +% str2double(get(hObject,'String')) returns contents of set_tension_right as a double + +set_shot_Callback(hObject, eventdata, handles); + +% --- Executes during object creation, after setting all properties. +function set_tension_right_CreateFcn(hObject, eventdata, handles) +% hObject handle to set_tension_right (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles empty - handles not created until after all CreateFcns called + +% Hint: edit controls usually have a white background on Windows. +% See ISPC and COMPUTER. +if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) + set(hObject,'BackgroundColor','white'); +end + + + +function set_coeff_left_Callback(hObject, eventdata, handles) +% hObject handle to set_coeff_left (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + +% Hints: get(hObject,'String') returns contents of set_coeff_left as text +% str2double(get(hObject,'String')) returns contents of set_coeff_left as a double + +set_shot_Callback(hObject, eventdata, handles); + +% --- Executes during object creation, after setting all properties. +function set_coeff_left_CreateFcn(hObject, eventdata, handles) +% hObject handle to set_coeff_left (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles empty - handles not created until after all CreateFcns called + +% Hint: edit controls usually have a white background on Windows. +% See ISPC and COMPUTER. +if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) + set(hObject,'BackgroundColor','white'); +end + + + +function set_coeff_right_Callback(hObject, eventdata, handles) +% hObject handle to set_coeff_right (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + +% Hints: get(hObject,'String') returns contents of set_coeff_right as text +% str2double(get(hObject,'String')) returns contents of set_coeff_right as a double + +set_shot_Callback(hObject, eventdata, handles); + + +% --- Executes during object creation, after setting all properties. +function set_coeff_right_CreateFcn(hObject, eventdata, handles) +% hObject handle to set_coeff_right (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles empty - handles not created until after all CreateFcns called + +% Hint: edit controls usually have a white background on Windows. +% See ISPC and COMPUTER. +if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) + set(hObject,'BackgroundColor','white'); +end + + +% --- Executes on button press in set_hold_left. +function set_hold_left_Callback(hObject, eventdata, handles) +% hObject handle to set_hold_left (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + +ihold_left = get(handles.set_hold_left,'Value'); +if ihold_left ==0 + set(handles.set_hold_left,'String','Hold off'); +else + set(handles.set_hold_left,'String','Hold on'); +end + + +% --- Executes on button press in set_hold_right. +function set_hold_right_Callback(hObject, eventdata, handles) +% hObject handle to set_hold_right (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + +ihold_right = get(handles.set_hold_right,'Value'); +if ihold_right ==0 + set(handles.set_hold_right,'String','Hold off'); +else + set(handles.set_hold_right,'String','Hold on'); +end + + + +function set_time_interval_Callback(hObject, eventdata, handles) +% hObject handle to set_time_interval (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + +% Hints: get(hObject,'String') returns contents of set_time_interval as text +% str2double(get(hObject,'String')) returns contents of set_time_interval as a double + +set_shot_Callback(hObject, eventdata, handles); + +% --- Executes during object creation, after setting all properties. +function set_time_interval_CreateFcn(hObject, eventdata, handles) +% hObject handle to set_time_interval (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles empty - handles not created until after all CreateFcns called + +% Hint: edit controls usually have a white background on Windows. +% See ISPC and COMPUTER. +if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) + set(hObject,'BackgroundColor','white'); +end + + + +function set_left_max_Callback(hObject, eventdata, handles) +% hObject handle to set_left_max (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + +% Hints: get(hObject,'String') returns contents of set_left_max as text +% str2double(get(hObject,'String')) returns contents of set_left_max as a double + +replot(handles); + +% --- Executes during object creation, after setting all properties. +function set_left_max_CreateFcn(hObject, eventdata, handles) +% hObject handle to set_left_max (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles empty - handles not created until after all CreateFcns called + +% Hint: edit controls usually have a white background on Windows. +% See ISPC and COMPUTER. +if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) + set(hObject,'BackgroundColor','white'); +end + + + +function set_right_max_Callback(hObject, eventdata, handles) +% hObject handle to set_right_max (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + +% Hints: get(hObject,'String') returns contents of set_right_max as text +% str2double(get(hObject,'String')) returns contents of set_right_max as a double + +replot(handles); + +% --- Executes during object creation, after setting all properties. +function set_right_max_CreateFcn(hObject, eventdata, handles) +% hObject handle to set_right_max (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles empty - handles not created until after all CreateFcns called + +% Hint: edit controls usually have a white background on Windows. +% See ISPC and COMPUTER. +if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) + set(hObject,'BackgroundColor','white'); +end + + +% --- Executes on selection change in popup_data_left. +function popup_data_left_Callback(hObject, eventdata, handles) +% hObject handle to popup_data_left (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + +% Hints: contents = cellstr(get(hObject,'String')) returns popup_data_left contents as cell array +% contents{get(hObject,'Value')} returns selected item from popup_data_left + + +% --- Executes during object creation, after setting all properties. +function popup_data_left_CreateFcn(hObject, eventdata, handles) +% hObject handle to popup_data_left (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles empty - handles not created until after all CreateFcns called + +% Hint: popupmenu controls usually have a white background on Windows. +% See ISPC and COMPUTER. +if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) + set(hObject,'BackgroundColor','white'); +end + + +% --- Executes on selection change in popup_data_right. +function popup_data_right_Callback(hObject, eventdata, handles) +% hObject handle to popup_data_right (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + +% Hints: contents = cellstr(get(hObject,'String')) returns popup_data_right contents as cell array +% contents{get(hObject,'Value')} returns selected item from popup_data_right + + +% --- Executes during object creation, after setting all properties. +function popup_data_right_CreateFcn(hObject, eventdata, handles) +% hObject handle to popup_data_right (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles empty - handles not created until after all CreateFcns called + +% Hint: popupmenu controls usually have a white background on Windows. +% See ISPC and COMPUTER. +if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) + set(hObject,'BackgroundColor','white'); +end + +function handles_out=refit(handles_in) +% hObject handle to time_set_value (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + +% Hints: get(hObject,'String') returns contents of time_set_value as text +% str2double(get(hObject,'String')) returns contents of time_set_value as a double + +% redo the fits because some coefficients, tension have changed +% click on "shot" to reload a new data file + + +handles_out = handles_in; + +tension_left = get(handles_in.set_tension_left,'string'); tension_left = str2num(tension_left); +tension_right = get(handles_in.set_tension_right,'string'); tension_right = str2num(tension_right); +time_interval = get(handles_in.set_time_interval,'string'); time_interval = str2num(time_interval); +coeffs_left = get(handles_in.set_coeff_left,'string'); coeffs_left = str2num(coeffs_left); +coeffs_right = get(handles_in.set_coeff_right,'string'); coeffs_right = str2num(coeffs_right); + +% left part do the fits +structs_left = get(handles_in.popup_data_left,'string'); +valeff = get(handles_in.popup_data_left,'value'); +struct_left = structs_left{valeff}; +% right part +structs_right = get(handles_in.popup_data_right,'string'); +valeff = get(handles_in.popup_data_right,'value'); +struct_right = structs_right{valeff}; + +[gen_signals_left] = generic_fit(handles_in.shot,handles_in.gen_signals.(struct_left).raw_data,struct_left,time_interval,tension_left,coeffs_left,0); +[gen_signals_right] = generic_fit(handles_in.shot,handles_in.gen_signals.(struct_right).raw_data,struct_right,time_interval,tension_right,coeffs_right,0); + +handles_out.data_left = gen_signals_left.(struct_left).combined_data; +handles_out.fit_left = gen_signals_left.(struct_left).fit; +handles_out.data_right = gen_signals_right.(struct_right).combined_data; +handles_out.fit_right = gen_signals_right.(struct_right).fit; + diff --git a/crpptbx/get_profile_structure.m b/crpptbx/get_profile_structure.m new file mode 100644 index 0000000000000000000000000000000000000000..64c7971f24d973f97aec10ff9706b3f9900701a4 --- /dev/null +++ b/crpptbx/get_profile_structure.m @@ -0,0 +1,84 @@ +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 + diff --git a/crpptbx/get_profiles.m b/crpptbx/get_profiles.m new file mode 100644 index 0000000000000000000000000000000000000000..5fbd0cd5ff713fc525a60542e07c3a94629f8ba1 --- /dev/null +++ b/crpptbx/get_profiles.m @@ -0,0 +1,158 @@ +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 +