Home > utilities > do_ph_max_change_plot.m

do_ph_max_change_plot

PURPOSE ^

Calculate the change in pH and plot accordingly.

SYNOPSIS ^

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

DESCRIPTION ^

 Calculate the change in pH and plot accordingly.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [Plots]=do_ph_max_change_plot(plotOPTS,FVCOM,startIdx)
0002 % Calculate the change in pH and plot accordingly.
0003 m_mappath;
0004 
0005 % Check we have some of the required fields.
0006 if ~isfield(FVCOM,plotOPTS.var_plot)
0007     error('Need %s input to calculate change in %s.',plotOPTS.var_plot,plotOPTS.var_plot)
0008 end
0009 
0010 % Build a colour palette which matches Jerry's ranges.
0011 % Dark Red -> Red -> Amber -> Yellow -> Green -> Blue
0012 nColours=200;
0013 nColourIn=[1,nColours*0.15,nColours*0.6,nColours*0.75,nColours*0.9,nColours];
0014 nColourOut=1:nColours; % Gives a nice continuous palette.
0015 %                          DR    R     A    Y    G     B
0016 cRed=interp1(nColourIn,  [0.62, 0.9, 1    , 1  , 0  , 0.46],nColourOut);
0017 cGreen=interp1(nColourIn,[0   , 0  , 0.52 , 1  , 0.8, 0.63],nColourOut);
0018 cBlue=interp1(nColourIn, [0.2 , 0.2, 0    , 0  , 0  , 0.83],nColourOut);
0019 colourSpec=flipud([cRed;cGreen;cBlue]'); % flip since we have negative scale
0020 
0021 if isfield(plotOPTS,'altColours') && plotOPTS.altColours==1
0022     clear nColours nColourIn nColourOut colourSpec
0023     % Build a colour palette which matches Jerry's ranges.
0024     % Dark Red -> Red -> Amber -> Yellow -> Green -> Blue
0025     nColours=200;
0026     nColourIn=[1,nColours*0.1,nColours*0.2,nColours*0.3,nColours*0.4,nColours];
0027     nColourOut=1:nColours; % Gives a nice continuous palette.
0028     %                          DB    B     LB   DG    G     LG
0029     cRed=interp1(nColourIn,  [0   , 0   , 0   , 0.04, 0 , 0.2 ],nColourOut);
0030     cGreen=interp1(nColourIn,[0   , 0   , 0.2 , 0.51, 0.6, 0.76 ],nColourOut);
0031     cBlue=interp1(nColourIn, [0.4 , 0.6 , 0.79, 0.78, 0.6  , 0],nColourOut);
0032     colourSpec=[cRed;cGreen;cBlue]';
0033 end
0034 
0035 dataToUse=single(FVCOM.(plotOPTS.var_plot));
0036 
0037 % Get the background condition. Depth average if necessary.
0038 if isfield(plotOPTS,'depth_average') && plotOPTS.depth_average
0039     bgPH=squeeze(mean(dataToUse(:,:,startIdx),2));
0040 else
0041     bgPH=squeeze(dataToUse(:,plotOPTS.nz_plot,startIdx));
0042 end
0043 
0044 % Are we depth averaging?
0045 if isfield(plotOPTS,'depth_average') && plotOPTS.depth_average
0046     phData=squeeze(mean(dataToUse,2));
0047 else
0048     phData=squeeze(dataToUse(:,plotOPTS.nz_plot,:));
0049 end
0050 
0051 phDiff=phData-repmat(bgPH,1,size(phData,2));
0052 
0053 % Are we depth averaging?
0054 % if isfield(plotOPTS,'depth_average') && plotOPTS.depth_average
0055 %     % Calculate the difference for each time step from the initial
0056 %     % conditions.
0057 %     phDiff=squeeze(mean(FVCOM.(plotOPTS.var_plot),2))-repmat(bgPH,1,length(plotOPTS.Time_record));
0058 % else
0059 %     phDiff=squeeze(FVCOM.(plotOPTS.var_plot)(:,plotOPTS.nz_plot,:))-repmat(bgPH,1,size(FVCOM.(plotOPTS.var_plot),3));
0060 % end
0061 
0062 % Not doing cumulative differences any more
0063 % Check if we're doing the cumulative difference
0064 % if isfield(plotOPTS,'summed_ph') && plotOPTS.summed_ph
0065 %     phDiff=cumsum(phDiff,2);
0066 % end
0067 
0068 % Do the maximum change from initial conditions across all time steps (i.e.
0069 % not the cumulative change). abs() the difference to find the greatest
0070 % change, either increase or decrease.
0071 % We're also averaging here over the number of timesteps so that we can fix
0072 % the colour palette to something sensible.
0073 phDiffMax=min((phDiff),[],2); %./(size(plotOPTS.Time_record,2)*(plotOPTS.Time_record(2)-plotOPTS.Time_record(1)));
0074 figure(plotOPTS.figure); clf
0075 m_proj('UTM','lon',[plotOPTS.range_lon],'lat',[plotOPTS.range_lat],'zon',plotOPTS.zone,'ell','grs80')
0076 m_grid('box','fancy')
0077 m_usercoast(plotOPTS.coastline_file,'Color','k','LineWidth',3);
0078 [X,Y]=m_ll2xy(plotOPTS.mesh.lon,plotOPTS.mesh.lat,'clip','on');
0079 
0080 % plot map with pH change
0081 hold on
0082 Plots(1).handles=patch('Vertices',[X,Y],'Faces',plotOPTS.mesh.tri,...
0083     'Cdata',phDiffMax,'edgecolor','interp','facecolor','interp');
0084 caxis(plotOPTS.clims)
0085 colormap(flipud(colourSpec))
0086 ch=colorbar;
0087 set(ch,'FontSize',10);
0088 ylabel(ch,'pH change');
0089 % ylabel(ch,[plotOPTS.var_plot,' change'])
0090 % check if mesh elements are required
0091 if plotOPTS.do_mesh
0092     % plot vertices
0093     [X,Y]=m_ll2xy(plotOPTS.mesh.lon,plotOPTS.mesh.lat,'clip','on');
0094     patch('Vertices',[X,Y],'Faces',plotOPTS.mesh.tri,...
0095         'EdgeColor',[0.6 0.6 0.6],'FaceColor','none'); hold on
0096 end
0097 
0098 if plotOPTS.save_output % Are we even trying to save figures?
0099     % Save output
0100     fprintf('Saving figure... ')
0101     set(findobj(gcf,'Type','text'),'FontSize',10)
0102     %set(gcf,'PaperSize',fliplr(get(gcf,'PaperSize')))
0103     set(gcf,'PaperPositionMode','auto');
0104     set(gcf,'renderer','painters'); % for vector output in pdfs
0105     print(gcf,'-dpdf','-r600',[plotOPTS.FVCOM_plot_dir,plotOPTS.var_plot,'/pdf/',plotOPTS.fig_name,'_layer=',num2str(plotOPTS.nz_plot),'_',plotOPTS.var_plot,'_max_change.pdf']); % pdf
0106     %print(gcf,'-dpng','-r600',[plotOPTS.FVCOM_plot_dir,plotOPTS.var_plot,'/png/',plotOPTS.fig_name,'_layer=',num2str(plotOPTS.nz_plot),'_',plotOPTS.var_plot,'_max_change.png']); % png
0107     fprintf('done.\n')
0108 end
0109 
0110 
0111 return

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