Skip to content

Commit

Permalink
plot modifications
Browse files Browse the repository at this point in the history
  • Loading branch information
GHilmarG committed Oct 30, 2023
1 parent f2cf147 commit 660e55d
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 36 deletions.
2 changes: 1 addition & 1 deletion PrintRunInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
function PrintRunInfo(CtrlVar)

fprintf(CtrlVar.fidlog,'\n \n');
fprintf(CtrlVar.fidlog,' ************************** Úa version: 26 October 2023 (alpha) ********************** \n');
fprintf(CtrlVar.fidlog,' ************************** %ca version: 26 October 2023 (alpha) ********************** \n',218);
fprintf(CtrlVar.fidlog,' Run starts at %s \n ',datetime);
fprintf(CtrlVar.fidlog,' Experiment: %s \n ',CtrlVar.Experiment);

Expand Down
4 changes: 2 additions & 2 deletions Ua2D.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
warning('off','MATLAB:triangulation:PtsNotInTriWarnId')
warning('off','MATLAB:decomposition:SaveNotSupported')
warning('off','MATLAB:decomposition:genericError')
parfevalOnAll(gcp(), @warning, 0, 'off','MATLAB:decomposition:genericError');
parfevalOnAll(gcp(), @warning, 0, 'off','MATLAB:decomposition:SaveNotSupported');
% parfevalOnAll(gcp(), @warning, 0, 'off','MATLAB:decomposition:genericError');
% parfevalOnAll(gcp(), @warning, 0, 'off','MATLAB:decomposition:SaveNotSupported');


%% initialize some variables
Expand Down
Binary file modified UaUtilities/PIG-TWG-RestartFile.mat
Binary file not shown.
142 changes: 110 additions & 32 deletions UaUtilities/PlotLatLonGrid.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,49 @@
function [Lat,Lon,X0,Y0,Clat,hlat,Clon,hlon,ax1,ax2]=PlotLatLonGrid(scale,dlat,dlon,LabelSpacing,Colour,isCircumpolar)

%%
% Plots a lat lon grid
% Plots a lat lon grid
%
% This is written for the Antarctica setting using polar stereographic coordinate system.
%
%
%
%
% [Lat,Lon,X0,Y0,Clat,hlat,Clon,hlon]=PlotLatLonGrid(scale,dlat,dlon,LabelSpacing,Colour,isCircumpolar)
%
%
% NOTE: Do not use figure zoom after this or the lat/lon lin will get misaligned!
% Inputes:
%
% scale ; scales the x and the y axis. For example if the x,y units are meters, but you want to plot using km as a
% distance units, set scale=1000
%
% dlat, dlon : distance between lat and lon lines, in degrees
%
% LableSpacing : affects the spacing between labels, default is LableSpacing=400. Increase to increase spacing between lat
% lon labels.
%
% Colour: color of the lat, lon lines
%
% isCircumpolar: set to true if the plot area is circumpolar, ie includes the pole itself.
%
%
% Outputs:
%
% Clat,hlat,Clon,hlon : These are the contour matrices and the contour objects. The contour objects allow the properties
% of the countour plots to be easily edited after the call.
%
%
%
% NOTE #1: Do not use figure zoom after this or the lat/lon lin will get misaligned!
% Despite best atempts I have not been able to link the axis and get the right behaviour.
%
% NOTE #2: As of Matlab2023b, Note#1 is no longer of relevance, which is good news!
%
%
% Example:
%
% load('PIG-TWG-RestartFile.mat','CtrlVarInRestartFile','MUA','F')
% Fig=FindOrCreateFigure("PIG-TWG lat/lon") ;
% CtrlVar=CtrlVarInRestartFile ;
% cbar=UaPlots(CtrlVar,MUA,F,"-speed-") ;
% hold on ;
% cbar=UaPlots(CtrlVar,MUA,F,"-speed-") ;
% hold on ;
% [~,~,~,~,~,hlat,~,hlon]=PlotLatLonGrid(1000) ; % often the colormap will have to be redefined after this call
% axis([-2000 -1000 -900 100])
% hlat.LineStyle="--"; hlon.LineStyle="--";
Expand All @@ -37,61 +61,106 @@
%%

fig = gcf;
ax1 = fig.CurrentAxes ;
ax1 = fig.CurrentAxes ;
tt=axis;

xmin=tt(1) ; xmax=tt(2) ; ymin=tt(3) ; ymax=tt(4) ;


%% create new axes for the lat/lon lines (never got this to work)
% ax2=axes ;
%
%
% ax2.Visible = 'off';
% ax2.XTick = [];
% ax2.YTick = [];
% hold on
% ax2.Position=ax1.Position;
% ax2.XLim=ax1.XLim;
% ax2.YLim=ax1.YLim;
ax2=[] ;
ax2=[] ;
%%


%% Setting values in the case of no or limited input

% First try to figure out if this is circumpolar
if nargin< 6 || isempty(isCircumpolar)
AxLimits=axis;
isCircumpolar=AxLimits(1) < 0 && AxLimits(2) > 0 && AxLimits(3) <0 && AxLimits(4) > 0 ;
end

if isCircumpolar

if nargin < 5
Colour='black';
if nargin< 4
LabelSpacing=1000;
if nargin< 3
dlon=45;
if nargin< 2
dlat=10;
if nargin==0
scale=1000 ;
end
end
end
end
end

else

if nargin < 5
Colour='black';
if nargin< 4
LabelSpacing=400;
if nargin< 3
dlon=10;
if nargin< 2
dlat=2.5 ;
if nargin==0
scale=1000 ;
end
end
end
end
end

end

%%

% set some plausible values if user has not defined those already
if isCircumpolar && isempty(dlat) && isempty(dlon) && isempty(LabelSpacing)

dlat=10;
dlon=45;
LabelSpacing=200;

else


if nargin<2 || isempty(dlat)
if isempty(dlat)
dlat=5;
end

if nargin<3 || isempty(dlon)
if isempty(dlon)
dlon=10;
end

if nargin<4 || isempty(LabelSpacing)
if isempty(LabelSpacing)
LabelSpacing=400;
end

if nargin<4 || isempty(Colour)
if isempty(Colour)
Colour='black';
end


if nargin<6
isCircumpolar=0;
end

end

lcol='k';

climCopy=clim;


[X0,Y0]=meshgrid(linspace(xmin,xmax,400),linspace(ymin,ymax,400));
Expand All @@ -102,29 +171,27 @@
I=Lat>-62; Lon(I)=NaN ; Lat(I)=NaN;
I=Lat>-64.9; Lon(I)=NaN;
I=Lat<-85.1 ; Lon(I)=NaN;
I=Lat<-86 ; Lat(I)=NaN ;
I=Lat<-86 ; Lat(I)=NaN ;
I=Lon<-171 ; Lon(I)=Lon(I)+360;
I=Lon<-170 ; Lon(I)=NaN;
end


hold on

if isCircumpolar
[Clat,hlat]=contour(ax1,X0,Y0,-Lat,[5:dlat:90],'LineColor',lcol,"LabelFormat","%2.0fS");
else
[Clat,hlat]=contour(ax1,X0,Y0,-Lat,[0:dlat:90],'LineColor',lcol,"LabelFormat","%2.0fS");
end

[Clat,hlat]=contour(ax1,X0,Y0,Lat,-90:dlat:90,LineColor=lcol,LabelFormat=@mylabelfunLat);


set(hlat,'ShowText','on','TextStep',get(hlat,'LevelStep')*2,'LabelSpacing',LabelSpacing)


[Clon,hlon]=contour(ax1,X0,Y0,Lon,[-180+dlon:dlon:185],LineColor=lcol,LabelFormat=@mylabelfun);
[Clon,hlon]=contour(ax1,X0,Y0,Lon,-180+dlon:dlon:185,LineColor=lcol,LabelFormat=@mylabelfunLon);
set(hlon,'ShowText','on','TextStep',get(hlon,'LevelStep')*2,'LabelSpacing',LabelSpacing)


hlon.LineColor=Colour ;
hlat.LineColor=Colour ;
hlon.LineColor=Colour ;
hlat.LineColor=Colour ;
clabel(Clat,hlat,Color=Colour,fontsize=9);
clabel(Clon,hlon,Color=Colour,fontsize=9)

Expand All @@ -135,20 +202,31 @@
% revert back to original axes


clim(climCopy) % set color axis limit to the value at the beginning of the call
% this is done here because the contour functions above might change the existing limites

function labels=mylabelfunLon(vals)

function labels=mylabelfun(vals)
% Degree=string(char(176))

labels= vals +"°E" ;
I=vals<0 ; labels(I) = -vals(I) + "°W" ;
I=vals==0 ; labels(I) = vals(I) ;

labels= vals +"E" ;
I=vals<0 ; labels(I) = -vals(I) +"W" ;
I=vals==0 ; labels(I) = vals(I) ;


end



function labels=mylabelfunLat(vals)


labels= vals +"°N" ;
I=vals<0 ; labels(I) = -vals(I) + "°S" ;
I=vals==0 ; labels(I) = vals(I) ;


end



Expand Down
2 changes: 1 addition & 1 deletion UaUtilities/UaPlots.m
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@


if options.PlotMuaBoundary
PlotMuaBoundary(CtrlVar,MUA,"k--");
PlotMuaBoundary(CtrlVar,MUA,"b--");
end

% Just guessing that this might be the most common case, the user can easily change afterwards anyhow.
Expand Down

0 comments on commit 660e55d

Please sign in to comment.