% browseLISST - display a LISST file % % browseLISST('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 21-Jul-2008 13:31:13 function varargout = browseLISST(varargin) % Begin initialization code - DO NOT EDIT gui_Singleton = 0; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @browseLISST_OpeningFcn, ... 'gui_OutputFcn', @browseLISST_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 browseLISST is made visible. function browseLISST_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 browseLISST (see VARARGIN) % Choose default command line output for browseLISST 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.lisstfile = []; for i = 1:length(varargin), if strcmpi(varargin{i},'file'), handles.mydata.lisstfile = varargin{i+1}; end end if isempty(handles.mydata.lisstfile), [filename, pathname] = uigetfile({'*.cdf; *.nc','netCDF files'},'Select a netCDF file containing LISST data'); if ~filename, return; end handles.mydata.lisstfile = fullfile(pathname, filename); end % open the netCDF file and do the basic checks cdf = netcdf(handles.mydata.lisstfile); % 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.lisstfile]); return; end dimnames = ncnames(dim(cdf)); flag = 0; for i=1:length(dimnames), % make sure this is a LISST data file if strcmp(dimnames{i},'size') || strcmp(dimnames{i},'rings'), flag = 1; end end if ~flag, disp('This is not a LISST file'); close(cdf); return; end % dimensioning and indexing setup % the size class / ring dimension handles.mydata.nrings = length(cdf('rings')); if isempty(handles.mydata.nrings) || (handles.mydata.nrings < 1), handles.mydata.nrings = length(cdf('size')); end for n=1:handles.mydata.nrings, handles.mydata.lstrings{n} = sprintf('%d',n); end handles.mydata.rings = [1 handles.mydata.nrings]; handles.mydata.iring = 1; % 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)); set(handles.textFileName,'string',sprintf('Now browsing file %s',handles.mydata.lisstfile)) n=1; varnames = ncnames(var(cdf)); for i=1:length(varnames), % remove burstnum and time if strcmp(varnames{i},'depth') ||... strcmp(varnames{i},'lat') || strcmp(varnames{i},'lon') ||... strcmp(varnames{i},'time') || strcmp(varnames{i},'time2') ||... strcmp(varnames{i},'size') || strcmp(varnames{i},'rings') ||... strcmp(varnames{i},'zscat') || strcmp(varnames{i},'rec'), % 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.textColorMinMin,'string',sprintf('%g',handles.mydata.ccmin)); set(handles.textColorMinMax,'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.textColorMaxMin,'string',sprintf('%g',handles.mydata.ccmin)); set(handles.textColorMaxMax,'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') % 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.rings(1))); set(handles.editFirstBin,'Tooltipstring','enter the first cell to plot') set(handles.editLastBin,'String',sprintf('%d',handles.mydata.rings(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 browseLISST 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 axes(handles.axes1); cla; % two D variables if strcmp(vartoplot,'vconc') || strcmp(vartoplot,'intensity'), % time, ring, lat, lon data = cdf{vartoplot}(:, handles.mydata.rings(1):handles.mydata.rings(2), :, :); ndims = 2; if strcmp(vartoplot,'vconc'), rings = cdf{'size'}(handles.mydata.rings(1):handles.mydata.rings(2)); elseif strcmp(vartoplot,'intensity'), rings = cdf{'rings'}(handles.mydata.rings(1):handles.mydata.rings(2)); end elseif strcmp(vartoplot,'field_zscat') || strcmp(vartoplot,'factory_zscat') ||... strcmp(vartoplot,'ring_data'), data = cdf{vartoplot}(:); ndims = 0; else % time, depth, lat, lon data = cdf{vartoplot}(:, :, :, :); ndims = 1; end if ndims == 2, 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; if strcmp(vartoplot,'vconc'), smax = dmed+10*dstd; elseif strcmp(vartoplot,'intensity'), smax = dmax; end 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.textColorMinMin,'string',sprintf('%7g',smin)); set(handles.textColorMinMax,'string',sprintf('%7g',smax)); set(handles.sliderColorMin,'Value',smin,'Min',smin,... 'Max',smax,'SliderStep',[0.01 0.1]); %[0.0001 0.001]); set(handles.textColorMaxMin,'string',sprintf('%7g',smin)); set(handles.textColorMaxMax,'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 imagesc(handles.mydata.tm,rings,data',clims) datetick('x',6,'keepticks','keeplimits') colormap(handles.mydata.ccolormap); cbar=colorbar; set(get(cbar,'Ylabel'),'String',cdf{vartoplot}.units(:)) if strcmp(vartoplot,'vconc'), ylabel(sprintf('size, %s',cdf{'size'}.units(:))) elseif strcmp(vartoplot,'intensity'), ylabel(sprintf('Scatter angle, %s',cdf{'rings'}.units(:))) end else if ndims, plot(handles.mydata.tm,data) datetick('x',6,'keepticks','keeplimits') else plot(data) xlabel('Ring Number') end ylabel(sprintf('%s, %s',vartoplot,cdf{vartoplot}.units(:))) end handles.mydata.newvar = 0; guidata(hObject, handles); % --- Outputs from this function are returned to the command line. function varargout = browseLISST_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.nrings, newcell = handles.mydata.nrings; end handles.mydata.rings(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.nrings, newcell = handles.mydata.nrings; end handles.mydata.rings(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 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);