% browseABSSstats - display an ABSS statistics file % % browseABSSstats('file',filename) opens the file given by filename for browsing % % Written by Marinna Martini for the U.S. Geological Survey % Coastal & Marine Program Woods Hole Field Center, Woods Hole, MA % http://woodshole.er.usgs.gov/ Please report bugs to mmartini@usgs.gov % Last Modified by GUIDE v2.5 11-Jul-2008 09:57:14 function varargout = browseABSSstats(varargin) % Begin initialization code - DO NOT EDIT gui_Singleton = 0; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @browseABSSstats_OpeningFcn, ... 'gui_OutputFcn', @browseABSSstats_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 browseABSSstats is made visible. function browseABSSstats_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 browseABSSstats (see VARARGIN) % Choose default command line output for browseABSSstats handles.output = hObject; % figure1: 1.000034179687500e+002 % sliderColorMin: 1.060206298828125e+002 % axes1: 1.010040283203125e+002 % output: 1.000034179687500e+002 % slider 1 controls color min % slider 2 controls which ?? % slider 3 controls color max % look for a filename in the varargin handles.mydata.statsfile = []; for i = 1:length(varargin), if strcmp(varargin{i},'file'), handles.mydata.statsfile = varargin{i+1}; end end if isempty(handles.mydata.statsfile), [filename, pathname] = uigetfile('*.*','Open a netCDF file containing ABSS statistics data'); if ~filename, return; end handles.mydata.statsfile = fullfile(pathname, filename); end % open the netCDF file and do the basic checks cdf = netcdf(handles.mydata.statsfile); % for passing to other methods handles.mydata.cdf = cdf; set(handles.figure1,'UserData',cdf); % store the netCDF file pointer here so I can close it later set(handles.figure1,'DeleteFcn','if ~isempty(get(gcf,''UserData'')), close(get(gcf,''UserData'')); end'); % and this is the code that will close it if isempty(cdf), disp(['Unable to open netCDF file ',handles.mydata.statsfile]); return; end dimnames = ncnames(dim(cdf)); flag = 0; for i=1:length(dimnames), % make sure this is a statistics data file if strcmp(dimnames{i},'sample') || strcmp(dimnames{i},'profile'), flag = 1; end end if flag, disp('This is not a statistics file'); close(cdf); return; end % dimensioning and indexing setup % the depth dimension handles.mydata.ncells = length(cdf('depth')); if isempty(handles.mydata.ncells) || (handles.mydata.ncells < 1), handles.mydata.ncells = length(cdf('bin')); end if isempty(handles.mydata.ncells) || (handles.mydata.ncells < 1), handles.mydata.ncells = length(cdf('cell')); end for n=1:handles.mydata.ncells, handles.mydata.lstrings{n} = sprintf('%d',n); end handles.mydata.cells = [1 handles.mydata.ncells]; handles.mydata.icell = 1; % cell = bin % the time dimension (the burst start) handles.mydata.nbursts = length(cdf('time')); if isempty(handles.mydata.nbursts) || (handles.mydata.nbursts < 1), handles.mydata.nbursts = length(cdf('burst')); end if isempty(handles.mydata.nbursts) || (handles.mydata.nbursts < 1), handles.mydata.nbursts = length(cdf('TIM')); end handles.mydata.burstNum = 1:handles.mydata.nbursts; % need these for a lookup table disp('Reading in time stamps....') tj = cdf{'time'}(:); if ~isempty(tj), tj = tj+cdf{'time2'}(:)./(24*3600*1000); else tj = cdf{'TIM'}(:); end handles.mydata.tm = datenum(gregorian(tj)); % the other dimension (axis, pctile) handles.mydata.naxes = length(cdf('pctile')); handles.mydata.axes = cdf{'pctile'}(:); set(handles.editAxis,'Tooltipstring','enter the percentile to plot') set(handles.textAxis,'String','Percentile') if isempty(handles.mydata.naxes) || (handles.mydata.naxes < 1), handles.mydata.naxes = length(cdf('axis')); handles.mydata.axes = cdf{'axis'}(:); set(handles.editAxis,'Tooltipstring','enter the axis to plot') set(handles.textAxis,'String','Axis') end handles.mydata.iaxis = 1; % or pctile set(handles.editAxis,'String',sprintf('%d',handles.mydata.axes(1))); set(handles.text7,'string',sprintf('Now browsing file %s',handles.mydata.statsfile)) n=1; varnames = ncnames(var(cdf)); for i=1:length(varnames), % remove burstnum and time if strcmp(varnames{i},'burst') || strcmp(varnames{i},'profile') || ... strcmp(varnames{i},'depth') || strcmp(varnames{i},'lat') || strcmp(varnames{i},'lon') ||... strcmp(varnames{i},'time') || strcmp(varnames{i},'time2') ||... strcmp(varnames{i},'vrange') || strcmp(varnames{i},'pctile'), % do nothing else handles.mydata.varnames{n} = varnames{i}; n=n+1; end end handles.mydata.vartoplot = handles.mydata.varnames{1}; handles.mydata.newvar = 1; % when a new variable is selected % slider 1 - min color axis handles.mydata.ccmin = 1e-35; handles.mydata.ccmax = 0.0001; set(handles.text1,'string',sprintf('%g',handles.mydata.ccmin)); set(handles.text4,'string',sprintf('%g',handles.mydata.ccmax)); % slider 1 limits -- maybe change the view zoom for the number of samples set(handles.sliderColorMin,'Value',handles.mydata.ccmin,'Min',handles.mydata.ccmin,... 'Max',handles.mydata.ccmax,'SliderStep',[0.01 0.1]); set(handles.sliderColorMin,'Tooltipstring','Set the minimum of the color axis') % slider 3 - max color limit range selector - labels set(handles.text13,'string',sprintf('%g',handles.mydata.ccmin)); set(handles.text12,'string',sprintf('%g',handles.mydata.ccmax)); set(handles.sliderColorMax,'Value',handles.mydata.ccmin,'Min',handles.mydata.ccmin,... 'Max',handles.mydata.ccmax,'SliderStep',[0.01 0.1]); set(handles.sliderColorMax,'Tooltipstring','Select the maximum of the color axis') % slider 2 - pctile selector set(handles.textAxisMin,'string',sprintf('%g',handles.mydata.axes(1))); set(handles.textAxisMax,'string',sprintf('%g',handles.mydata.axes(end))); set(handles.sliderAxisPctile,'Value',handles.mydata.axes(1),'Min',handles.mydata.axes(1),... 'Max',handles.mydata.axes(end),'SliderStep',[0.01 0.1]); set(handles.sliderAxisPctile,'Tooltipstring','Select the percentile') % put varnames into listbox here set(handles.listboxVar2Plot,'string',handles.mydata.varnames,'Value',1); set(handles.listboxVar2Plot,'Tooltipstring','Select data to display') % put colormap names into listbox here handles.mydata.colormaps = {'default','jet','HSV','hot','cool','spring','summer','autumn',... 'winter','gray','bone','copper','pink','lines'}; handles.mydata.ccolormap = 'default'; % current color map set(handles.listboxColorMap,'string',handles.mydata.colormaps,'Value',1); set(handles.listboxColorMap,'Tooltipstring','Select colormap') % set contents of first and last bin set(handles.editFirstBin,'String',sprintf('%d',handles.mydata.cells(1))); set(handles.editFirstBin,'Tooltipstring','enter the first cell to plot') set(handles.editLastBin,'String',sprintf('%d',handles.mydata.cells(2))); set(handles.editLastBin,'Tooltipstring','enter the last cell to plot') % Update handles structure guidata(hObject, handles); % This sets up the initial plot - only do when we are invisible % so window can get raised using example. if strcmp(get(hObject,'Visible'),'off') updateplot(hObject, handles) end % UIWAIT makes browseABSSstats wait for user response (see UIRESUME) % uiwait(handles.figure1); %% ------------------ updates the plot - this is a user function function updateplot(hObject, handles) cdf = handles.mydata.cdf; vartoplot = handles.mydata.vartoplot; % this will be the selection ndims = length(dim(cdf{vartoplot})); cells = handles.mydata.cells(1):handles.mydata.cells(2); iaxis = handles.mydata.iaxis; axes(handles.axes1); cla; switch ndims, case 2, % time, depth data = cdf{vartoplot}(:, handles.mydata.cells(1):handles.mydata.cells(2)); case 3, % time, depth, pctile data = cdf{vartoplot}(:, handles.mydata.cells(1):handles.mydata.cells(2),iaxis); end if handles.mydata.newvar, dmin = gmin(gmin(data)'); dmax = gmax(gmax(data)'); dmed = gmedian(gmedian(data)'); dmean = gmean(gmean(data)'); dstd = gstd(gstd(data)'); sstep = (dmax-dmin)/10000; lstep = (dmax-dmin)/1000; smin = dmin; smax = dmed+dstd; set(handles.textDataLims,'string',sprintf('Data values range from %7g to %7g', dmin,dmax)); % reset the slider for the data for new variable limits set(handles.text1,'string',sprintf('%7g',smin)); set(handles.text4,'string',sprintf('%7g',smax)); set(handles.sliderColorMin,'Value',smin,'Min',smin,... 'Max',smax,'SliderStep',[0.01 0.1]); %[0.0001 0.001]); set(handles.text13,'string',sprintf('%7g',smin)); set(handles.text12,'string',sprintf('%7g',smax)); set(handles.sliderColorMax,'Value',smax,'Min',smin,... 'Max',smax,'SliderStep',[0.01 0.1]); %,[0.0001 0.001]); set(handles.editColorMinValue,'string',sprintf('%7g',smin)); set(handles.editColorMaxValue,'string',sprintf('%7g',smax)); handles.mydata.ccmin = smin; handles.mydata.ccmax = smax; %clims = [smin smax]; end if isnan(handles.mydata.ccmin) || isnan(handles.mydata.ccmax), clims = [handles.mydata.cmin handles.mydata.cmax]; disp('NaNs in color limits') elseif handles.mydata.ccmin > handles.mydata.ccmax, disp('min color limit greater than max') else clims = [handles.mydata.ccmin handles.mydata.ccmax]; end %disp(sprintf('clims are now %g %g',clims)) imagesc(handles.mydata.tm,cells,data',clims) datetick('x',6,'keepticks','keeplimits') colormap(handles.mydata.ccolormap); cbar=colorbar; set(get(cbar,'Ylabel'),'String',sprintf('%s for %s transducer', ... cdf{vartoplot}.units(:), cdf{vartoplot}.frequency(:))) %set(get(cbar,'Ylabel'),'String',cdf{vartoplot}.units(:)) ylabel(sprintf('cell #, from %5.2f to %5.2f m',... cdf{'depth'}([handles.mydata.cells(1) handles.mydata.cells(2)]))) if ndims == 3, text(0.1,1.1,sprintf('Percentile %g',handles.mydata.axes(iaxis)),'units','normalized'); end handles.mydata.newvar = 0; guidata(hObject, handles); % --- Outputs from this function are returned to the command line. function varargout = browseABSSstats_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 % --- Executes during object creation, after setting all properties. function sliderColorMin_CreateFcn(hObject, eventdata, handles) % hObject handle to sliderColorMin (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, change % 'usewhitebg' to 0 to use default. See ISPC and COMPUTER. usewhitebg = 1; if usewhitebg set(hObject,'BackgroundColor',[.9 .9 .9]); else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); end % The actual step size is a function of the specified SliderStep and the % total slider range (Max - Min). The default, [0.01 0.10], provides % a 1 percent change for clicks on the arrow button and a 10 percent % change for clicks in the trough. % --- Executes on slider movement. function sliderColorMin_Callback(hObject, eventdata, handles) % hObject handle to sliderColorMin (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 newvalue = get(hObject,'Value'); if newvalue < handles.mydata.ccmax, handles.mydata.ccmin = newvalue; else end set(handles.editColorMinValue,'string',sprintf('%g',handles.mydata.ccmin)); % Update handles structure guidata(hObject, handles); updateplot(hObject, handles); % --- Executes during object creation, after setting all properties. function sliderColorMax_CreateFcn(hObject, eventdata, handles) % hObject handle to sliderColorMax (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, change % 'usewhitebg' to 0 to use default. See ISPC and COMPUTER. usewhitebg = 1; if usewhitebg set(hObject,'BackgroundColor',[.9 .9 .9]); else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); end % --- Executes on slider movement. function sliderColorMax_Callback(hObject, eventdata, handles) % hObject handle to sliderColorMax (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 newvalue = get(hObject,'Value'); if newvalue > handles.mydata.ccmin, handles.mydata.ccmax = newvalue; else disp(sprintf('%7g new max value <= %7g color minimum',... newmax,handles.mydata.ccmin)) end set(handles.editColorMaxValue,'string',sprintf('%7g',handles.mydata.ccmax)); % Update handles structure guidata(hObject, handles); updateplot(hObject, handles); % --- Executes during object creation, after setting all properties. function listboxVar2Plot_CreateFcn(hObject, eventdata, handles) % hObject handle to listboxVar2Plot (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: listbox controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc set(hObject,'BackgroundColor','white'); else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); end % --- Executes on selection change in listboxVar2Plot. function listboxVar2Plot_Callback(hObject, eventdata, handles) % hObject handle to listboxVar2Plot (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = get(hObject,'String') returns listboxVar2Plot contents as cell array % contents{get(hObject,'Value')} returns selected item from listboxVar2Plot list = get(hObject,'String'); handles.mydata.vartoplot = list{get(hObject,'Value')}; handles.mydata.newvar = 1; % tell update plot that we have switched.. new data loading guidata(hObject, handles); updateplot(hObject, handles); % --- Executes on selection change in listboxColorMap. function listboxColorMap_Callback(hObject, eventdata, handles) % hObject handle to listboxColorMap (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = get(hObject,'String') returns listboxColorMap contents as cell array % contents{get(hObject,'Value')} returns selected item from listboxColorMap list = get(hObject,'String'); handles.mydata.ccolormap = list{get(hObject,'Value')}; guidata(hObject, handles); updateplot(hObject, handles); % --- Executes during object creation, after setting all properties. function listboxColorMap_CreateFcn(hObject, eventdata, handles) % hObject handle to listboxColorMap (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: listbox 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 editFirstBin_Callback(hObject, eventdata, handles) % hObject handle to editFirstBin (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 editFirstBin as text % str2double(get(hObject,'String')) returns contents of editFirstBin as a double newcell = round(str2double(get(hObject,'String'))); if newcell < 1, newcell = 1; end if newcell > handles.mydata.ncells, newcell = handles.mydata.ncells; end handles.mydata.cells(1) = newcell; handles.mydata.newvar = 1; % tell update plot that we have switched.. new data loading % Update handles structure guidata(hObject, handles); updateplot(hObject, handles); % --- Executes during object creation, after setting all properties. function editFirstBin_CreateFcn(hObject, eventdata, handles) % hObject handle to editFirstBin (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 editLastBin_Callback(hObject, eventdata, handles) % hObject handle to editLastBin (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 editLastBin as text % str2double(get(hObject,'String')) returns contents of editLastBin as a double newcell = round(str2double(get(hObject,'String'))); if newcell < 1, newcell = 1; end if newcell > handles.mydata.ncells, newcell = handles.mydata.ncells; end handles.mydata.cells(2) = newcell; handles.mydata.newvar = 1; % tell update plot that we have switched.. new data loading % Update handles structure guidata(hObject, handles); updateplot(hObject, handles); % --- Executes during object creation, after setting all properties. function editLastBin_CreateFcn(hObject, eventdata, handles) % hObject handle to editLastBin (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 slider movement. function sliderAxisPctile_Callback(hObject, eventdata, handles) % hObject handle to sliderAxisPctile (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 pctile = get(hObject,'Value'); newvalue = find(handles.mydata.axes > pctile,1,'first'); if newvalue < 1, newvalue = 1; end if newvalue > handles.mydata.naxes, newvalue = handles.mydata.naxes; end if ~isempty(newvalue), handles.mydata.iaxis = newvalue; set(handles.editAxis,'string',sprintf('%g',handles.mydata.axes(newvalue))); handles.mydata.newvar = 1; % tell update plot that we have switched.. new data loading % Update handles structure guidata(hObject, handles); updateplot(hObject, handles); end % --- Executes during object creation, after setting all properties. function sliderAxisPctile_CreateFcn(hObject, eventdata, handles) % hObject handle to sliderAxisPctile (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 editColorMaxValue_Callback(hObject, eventdata, handles) % hObject handle to editColorMaxValue (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 editColorMaxValue as text % str2double(get(hObject,'String')) returns contents of editColorMaxValue as a double newvalue = str2double(get(hObject,'String')); if newvalue > handles.mydata.ccmin, handles.mydata.ccmax = newvalue; else disp(sprintf('Value ignored: %7g <= %7g color minimum',... newmax,handles.mydata.ccmin)) end set(handles.editColorMaxValue,'string',sprintf('%7g',handles.mydata.ccmax)); % Update handles structure guidata(hObject, handles); updateplot(hObject, handles); function editColorMinValue_Callback(hObject, eventdata, handles) % hObject handle to editColorMinValue (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 editColorMinValue as text % str2double(get(hObject,'String')) returns contents of editColorMinValue as a double newvalue = get(hObject,'Value'); if newvalue < handles.mydata.ccmax, handles.mydata.ccmin = newvalue; else disp(sprintf('Value ignored: %7g >= %7g color maximum',... newvalue,handles.mydata.ccmax)) end set(handles.editColorMinValue,'string',sprintf('%g',handles.mydata.ccmin)); % Update handles structure guidata(hObject, handles); updateplot(hObject, handles); function editAxis_Callback(hObject, eventdata, handles) % hObject handle to editAxis (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 editAxis as text % str2double(get(hObject,'String')) returns contents of editAxis as a double pctile = str2double(get(hObject,'String')); newvalue = find(pctile >= handles.mydata.axes,1,'first'); if newvalue < 1, newvalue = 1; end if newvalue > handles.mydata.naxes, newvalue = handles.mydata.naxes; end if ~isempty(newvalue), handles.mydata.iaxis = newvalue; set(handles.editAxis,'string',sprintf('%g',handles.mydata.axes(newvalue))); handles.mydata.newvar = 1; % tell update plot that we have switched.. new data loading % Update handles structure guidata(hObject, handles); updateplot(hObject, handles); end % --- Executes during object creation, after setting all properties. function editAxis_CreateFcn(hObject, eventdata, handles) % hObject handle to editAxis (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