Skip to content

Commit

Permalink
Better plots, add units, handle 0 data more clear
Browse files Browse the repository at this point in the history
  • Loading branch information
TCallaghan2 committed Nov 5, 2024
1 parent 9acebab commit a5c3b4c
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 7 deletions.
33 changes: 33 additions & 0 deletions mfiles/GetUnits.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Typical fileName: 'Lat_Lon_Grid_ABUN....'
% or 'Lat_Lon_Survey_ABUN...'
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function units = GetUnits(fileName)
units ='';
k=strfind(fileName,'ABUN');
if k>0, units = 'scallops/m^2';end

k=strfind(fileName,'BIOM');
if k>0, units = 'g/m^2';end

k=strfind(fileName,'EBMS');
if k>0, units = 'metric tons';end

k=strfind(fileName,'FEFF');
if k>0, units = 'unitless';end

k=strfind(fileName,'FMOR');
if k>0, units = 'unitless';end

k=strfind(fileName,'LAND');
if k>0, units = 'scallops';end

k=strfind(fileName,'LNDW');
if k>0, units = 'grams';end

k=strfind(fileName,'LPUE');
if k>0, units = 'landings/day';end

k=strfind(fileName,'RECR');
if k>0, units = 'scallops/m^2';end
end
25 changes: 18 additions & 7 deletions mfiles/PlotLatLonGridSurvey.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

function PlotLatLonGridSurvey(surveyFname, gridFname, yrStart, tsPerYear, domain, yrSelect)

units = GetUnits(gridFname);

isOctave = (exist('OCTAVE_VERSION', 'builtin') ~= 0);
if isOctave
% used if called by command line
Expand Down Expand Up @@ -98,7 +100,7 @@ function PlotLatLonGridSurvey(surveyFname, gridFname, yrStart, tsPerYear, domain
for k=1:c
for n=1:r
% geoscatter does not accept 0.0, must be positive or NaN
if grid(n,k)<=0 ; grid(n,k) = NaN; end
if grid(n,k)<=0 ; grid(n,k) = realmin(); end
% saturate values
if grid(n,k)> saturate; grid(n,k) = saturate; end
end
Expand Down Expand Up @@ -180,7 +182,7 @@ function PlotLatLonGridSurvey(surveyFname, gridFname, yrStart, tsPerYear, domain
for k=1:numCol
for n=1:rSurvey
% geoscatter does not accept 0.0, must be positive or NaN
if survey(n,k)<=0 ; survey(n,k) = NaN; end
if survey(n,k)<=0 ; survey(n,k) = realmin(); end
end
end

Expand Down Expand Up @@ -276,9 +278,10 @@ function PlotLatLonGridSurvey(surveyFname, gridFname, yrStart, tsPerYear, domain
% plot figure for each year
for i=1:c
year = yrStart + i - 2 + offset;

if or(strcmp(domain, 'MA'), strcmp(domain, 'AL'))
thisTitle = [useTitle int2str(year) '_' int2str(100./mx_N(i)) '_MA_North'];
unitStr = [units, ' X ', num2str(mx_N(i),4)];
surveyLon = lonSurvey_N;
surveyLat = latSurvey_N;
if isOctave
Expand All @@ -291,6 +294,7 @@ function PlotLatLonGridSurvey(surveyFname, gridFname, yrStart, tsPerYear, domain
gridData = grid_N(:,i);
else
thisTitle = [useTitle int2str(year) '_' int2str(100./mx(i))];
unitStr = [units, ' X ', num2str(mx(i),4)];
surveyLon = lonSurvey;
surveyLat = latSurvey;
if isOctave
Expand All @@ -305,7 +309,7 @@ function PlotLatLonGridSurvey(surveyFname, gridFname, yrStart, tsPerYear, domain
PlotGrid(domain, thisTitle, isOctave, surveyLon, surveyLat, surveyData, gridLon, gridLat, gridData)
PlotRegion(isOctave, 'MA_North', cutNS, 1)
title(thisTitle, 'Interpreter', 'none');
SetColorbar(isOctave)
SetColorbar(isOctave, unitStr)
SizePaper(domain, isOctave)
saveas(gcf,[thisTitle '.pdf'])

Expand All @@ -315,7 +319,7 @@ function PlotLatLonGridSurvey(surveyFname, gridFname, yrStart, tsPerYear, domain
PlotGrid(domain, thisTitle, isOctave, lonSurvey_S, latSurvey_S, survey_S(:,i), lonGrid_S, latGrid_S, grid_S(:,i))
PlotRegion(isOctave, 'MA_South', cutNS, 1)
title(thisTitle, 'Interpreter', 'none');
SetColorbar(isOctave)
SetColorbar(isOctave, [units, ' X ', num2str(mx_S(i),4)])
SizePaper(domain, isOctave)
saveas(gcf,[thisTitle '.pdf'])
end
Expand All @@ -326,7 +330,7 @@ function PlotLatLonGridSurvey(surveyFname, gridFname, yrStart, tsPerYear, domain
PlotGrid(domain, thisTitle, isOctave, lonSurvey_NE, latSurvey_NE, survey_NE(:,i), lonGrid_NE, latGrid_NE, grid_NE(:,i))
PlotRegion(isOctave, 'GB', cutNS, 1)
title(thisTitle, 'Interpreter', 'none');
SetColorbar(isOctave)
SetColorbar(isOctave, [units, ' X ', num2str(mx_NE(i),4)])
SizePaper(domain, isOctave)
saveas(gcf,[thisTitle '.pdf'])
end
Expand Down Expand Up @@ -360,13 +364,18 @@ function SizePaper(domain, isOctave)
end %if isOctave
end % function

function SetColorbar(isOctave)
function SetColorbar(isOctave,units)
if isOctave
set(gca, 'color', [193 245 247]/255); %RGB as a fraction
h=get(gca,'title');
title = get(h,'String');
set(gca, 'title', [title char(10) units]);
c=rainbow(100);
else
geobasemap bluegreen
c=hot(100);
ax=gca;
ax.Subtitle = text(0.5,0.5,units);
end
colormap(c);
colorbar;
Expand Down Expand Up @@ -402,4 +411,6 @@ function PlotGrid(domain, thisTitle, isOctave, surveyLon, surveyLat, surveyData,
f.OuterPosition = [1963.4 -221.4 1000 1087.2];
end
end
% correct when data is all 0
if max(gridData) == realmin(), clim([realmin(), 0.001]); end
end

0 comments on commit a5c3b4c

Please sign in to comment.