Home > utilities > do_ph_change_plot.m

do_ph_change_plot

PURPOSE ^

Calculate the change in the given parameter (plotOPTS.var_plot) and plot

SYNOPSIS ^

function [Plots]=do_ph_change_plot(plotOPTS,FVCOM,startIdx)

DESCRIPTION ^

 Calculate the change in the given parameter (plotOPTS.var_plot) and plot
 accordingly.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [Plots]=do_ph_change_plot(plotOPTS,FVCOM,startIdx)
0002 % Calculate the change in the given parameter (plotOPTS.var_plot) and plot
0003 % accordingly.
0004 m_mappath;
0005 
0006 % For testing
0007 % startIdx=48; % Leak start
0008 % layerIdx=10; % Bottom layer
0009 % For testing
0010 
0011 % Check we have some of the required fields.
0012 if ~isfield(FVCOM,plotOPTS.var_plot)
0013     error('Need %s input to calculate change in %s.',plotOPTS.var_plot,plotOPTS.var_plot)
0014 end
0015 
0016 % Get the relevant time intervals
0017 if isempty(plotOPTS.save_intervals)
0018     plotOPTS.save_intervals=1:length(plotOPTS.Time_record);
0019     dontSave=1;
0020 else
0021     dontSave=0;
0022 end
0023 
0024 % Build a colour palette which matches Jerry's ranges.
0025 % Dark Red -> Red -> Amber -> Yellow -> Green -> Blue
0026 nColours=200;
0027 nColourIn=[1,nColours*0.15,nColours*0.6,nColours*0.75,nColours*0.9,nColours];
0028 nColourOut=1:nColours; % Gives a nice continuous palette.
0029 %                          DR    R     A    Y    G     B
0030 cRed=interp1(nColourIn,  [0.62, 0.9, 1    , 1  , 0  , 0.46],nColourOut);
0031 cGreen=interp1(nColourIn,[0   , 0  , 0.52 , 1  , 0.8, 0.63],nColourOut);
0032 cBlue=interp1(nColourIn, [0.2 , 0.2, 0    , 0  , 0  , 0.83],nColourOut);
0033 colourSpec=[cRed;cGreen;cBlue]';
0034 
0035 if isfield(plotOPTS,'altColours') && plotOPTS.altColours==1
0036     clear nColours nColourIn nColourOut colourSpec
0037     % Build a colour palette which matches Jerry's ranges.
0038     % Dark Red -> Red -> Amber -> Yellow -> Green -> Blue
0039     nColours=200;
0040     nColourIn=[1,nColours*0.1,nColours*0.2,nColours*0.3,nColours*0.4,nColours];
0041     nColourOut=1:nColours; % Gives a nice continuous palette.
0042     %                          DB    B     LB   DG    G     LG
0043     cRed=interp1(nColourIn,  [0   , 0   , 0   , 0.04, 0 , 0.2 ],nColourOut);
0044     cGreen=interp1(nColourIn,[0   , 0   , 0.2 , 0.51, 0.6, 0.76 ],nColourOut);
0045     cBlue=interp1(nColourIn, [0.4 , 0.6 , 0.79, 0.78, 0.6  , 0],nColourOut);
0046     colourSpec=flipud([cRed;cGreen;cBlue]');
0047 end
0048 
0049 dataToUse=single(FVCOM.(plotOPTS.var_plot));
0050 
0051 % Get the background condition. Depth average if necessary.
0052 if isfield(plotOPTS,'depth_average') && plotOPTS.depth_average
0053     bgPH=squeeze(mean(dataToUse(:,:,startIdx),2));
0054 else
0055     bgPH=squeeze(dataToUse(:,plotOPTS.nz_plot,startIdx));
0056 end
0057 
0058 % Are we depth averaging?
0059 if isfield(plotOPTS,'depth_average') && plotOPTS.depth_average
0060     phData=squeeze(mean(dataToUse,2));
0061 else
0062     phData=squeeze(dataToUse(:,plotOPTS.nz_plot,:));
0063 end
0064 % Check if we're doing the cumulative difference. For this to work, you
0065 % need to start your data import before the start of the leak.
0066 % if isfield(plotOPTS,'summed_ph') && plotOPTS.summed_ph
0067 %     phDiff=cumsum(diff(phData,[],2));
0068 % else
0069 %     % Otherwise, just do the difference from the start, ignoring all
0070 %     % previous steps i.e. for each successive time step, calculate the
0071 %     % difference between the current time step and the background
0072 %     % level.
0073 %     phDiff=phData-repmat(bgPH,1,size(phData,2));
0074 % end
0075 
0076 % Check if we're doing the cumulative difference
0077 % if isfield(plotOPTS,'summed_ph') && plotOPTS.summed_ph
0078 %     phDiff=cumsum(phDiff,2);
0079 % end
0080 
0081 % Since we're not doing the cumulative difference, just do the difference
0082 % relative to the background value
0083 phDiff=phData-repmat(bgPH,1,size(phData,2));
0084 
0085 
0086 figure(plotOPTS.figure); clf
0087 m_proj('UTM','lon',[plotOPTS.range_lon],'lat',[plotOPTS.range_lat],'zon',plotOPTS.zone,'ell','grs80')
0088 m_grid('box','fancy')
0089 m_usercoast(plotOPTS.coastline_file,'Color','k','LineWidth',3);
0090 [X,Y]=m_ll2xy(plotOPTS.mesh.lon,plotOPTS.mesh.lat,'clip','on');
0091 
0092 saveInc=1;
0093 for aa=1:length(plotOPTS.Time_record)
0094     % plot map with change
0095     hold on
0096     Plots(1).handles=patch('Vertices',[X,Y],'Faces',plotOPTS.mesh.tri,...
0097         'Cdata',phDiff(:,plotOPTS.save_intervals(aa)),...
0098         'edgecolor','interp','facecolor','interp');
0099     fprintf('Time step %i of %i\n',aa,length(plotOPTS.Time_record))
0100     caxis(plotOPTS.clims)
0101     colormap(colourSpec)
0102     ch=colorbar;
0103     set(ch,'FontSize',10);
0104     ylabel(ch,'pH change');
0105     % ylabel(ch,[plotOPTS.var_plot,' change'])
0106     % check if mesh elements are required
0107     if plotOPTS.do_mesh
0108         % plot vertices
0109         [X,Y]=m_ll2xy(plotOPTS.mesh.lon,plotOPTS.mesh.lat,'clip','on');
0110         patch('Vertices',[X,Y],'Faces',plotOPTS.mesh.tri,...
0111             'EdgeColor',[0.6 0.6 0.6],'FaceColor','none'); hold on
0112     end
0113 
0114     pause(plotOPTS.pause)
0115     if plotOPTS.save_output % Are we even trying to save figures?
0116         if saveInc<=length(plotOPTS.save_intervals) && plotOPTS.save_intervals(aa)==plotOPTS.save_intervals(saveInc) && ~dontSave
0117             % Save output
0118             fprintf('Saving figure... ')
0119             set(findobj(gcf,'Type','text'),'FontSize',10)
0120             %set(gcf,'PaperSize',fliplr(get(gcf,'PaperSize')))
0121             set(gcf,'PaperPositionMode','auto');
0122             set(gcf,'renderer','painters'); % for vector output in pdfs
0123             print(gcf,'-dpdf','-r600',[plotOPTS.FVCOM_plot_dir,plotOPTS.var_plot,'/pdf/',plotOPTS.fig_name,'_layer=',num2str(plotOPTS.nz_plot),'_',plotOPTS.var_plot,'_change_',num2str(plotOPTS.save_intervals(aa)),'.pdf']); % pdf
0124             %print(gcf,'-dpng','-r600',[plotOPTS.FVCOM_plot_dir,plotOPTS.var_plot,'/png/',plotOPTS.fig_name,'_layer=',num2str(plotOPTS.nz_plot),'_',plotOPTS.var_plot,'_change_',num2str(plotOPTS.save_intervals(aa)),'.png']); % png
0125             saveInc=saveInc+1;
0126             fprintf('done.\n')
0127         end
0128     end
0129 
0130     if aa~=length(plotOPTS.Time_record)
0131         delete(Plots(1).handles)
0132     end
0133 end
0134 
0135 return

Generated on Thu 19-Mar-2015 12:20:56 by m2html © 2005