Skip to content

Commit

Permalink
separated frame3d.m, wrfout2frame3d works for real case
Browse files Browse the repository at this point in the history
  • Loading branch information
janmandel committed Nov 4, 2009
1 parent 1737e4e commit 9237c55
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 58 deletions.
91 changes: 91 additions & 0 deletions wrfv2_fire/test/em_fire/hill/frame3d.m
@@ -0,0 +1,91 @@
function frame3d(swind,amin,amax,astep,qstep,qs,...
fxlong,fxlat,xlong,xlat,zsf,fgrnhfx,uf,vf,u,v,w,ph,phb,hgt)

clf,hold off

r = size(fxlong)./(size(xlong)+1); % refinement ratio
ideal = all(xlong ==0); % not populated in ideal case

if ideal,
% do not have xlong and xlat in ideal case, but we made the coordinates up
% for fxlong and fxlat, so interpolate
n=size(xlong);
[xa,ya]=ndgrid(r(1)*[1/2:1:n(1)],r(2)*[1/2:1:n(2)]); % centers of atm cells in fire grid
axlong = interp2(fxlong,xa,ya); % fake coordinates for display
axlat = interp2(fxlat,xa,ya); % fake coordinates for display
xscale=1;
yscale=1;
else
axlong=xlong; axlat=xlat; % in real case, xlong xlat populated
er=6378e3; % earth radius in m
deg2rad=2*pi/360; % 1 degree in radians
% degrees to meters, long and lat
lat_deg2m=er*deg2rad;
long_deg2m=er*deg2rad*cos(deg2rad*mean(xlat(find(xlat))));
xscale=1/long_deg2m;
yscale=1/lat_deg2m;
end
aspect_ratio = [xscale yscale 1];

% compute the corresponding part of the fire grid
dmin=1+r.*(amin(1:2)-1);
dmax=r.*amax(1:2);

% surface colored by heat flux
i=dmin(1):dmax(1);j=dmin(2):dmax(2);
hs=surf(fxlong(i,j),fxlat(i,j),zsf(i,j),fgrnhfx(i,j),'EdgeColor','none','FaceAlpha',0.7);
caxis([0,1e6]); % for heat flux color
axis tight, colorbar
hold on
[c,hc]=contour3(fxlong(i,j),fxlat(i,j),zsf(i,j));
for h=hc(:)', set(h,'EdgeColor','black');end % color the contours black


% surface wind arrows
if swind,
ii=dmin(1):qstep(1):dmax(1);jj=dmin(2):qstep(2):dmax(2);
hq=quiver3(fxlong(ii,jj),fxlat(ii,jj),zsf(ii,jj),xscale*uf(ii,jj),yscale*vf(ii,jj),zeros(size(vf(ii,jj))),qs);
set(hq,'Color','black')
end

% geopotential altitude of the centers of lower cell face
% ph is perturbation from the background phb
% note ph and phb are staggered just as w
a = (ph+phb)/9.81;
% check if the lowest background geopotential height is terrain height
err_hgt = big(hgt-phb(:,:,1)/9.81)
% interpolate the geopotential and w velocity from staggered grid to cell centers
ac = (a(:,:,1:end-1)+a(:,:,2:end))/2;
wc = (w(:,:,1:end-1)+w(:,:,2:end))/2;
% interpolate u and v components of wind velocity from staggered grid to cell centers
uc = (u(1:end-1,:,:)+u(2:end,:,:))/2; % from front and rear face to the center
vc = (v(:,1:end-1,:)+v(:,2:end,:))/2; % from front and rear face to the center

% atmosphere wind arrows
ia=amin(1):astep(1):amax(1);
ja=amin(2):astep(2):amax(2);
colors={'white','red','green','blue','black'};
for k=amin(3):astep(3):amax(3),
q1=u(ia,ja,k)*xscale;
q2=v(ia,ja,k)*yscale;
q3=w(ia,ja,k);
hqa=quiver3(axlong(ia,ja),axlat(ia,ja),ac(ia,ja,k),q1,q2,q3,qs);
set(gca,'DataAspectRatio',[xscale yscale 1]);
i=1+mod(k-1,length(colors));
set(hqa,'Color',colors{i});
end

if ideal
xlabel('x (m)')
ylabel('y (m)')
else
% set(gca,'PlotBoxAspectRatioMode','auto');
xlabel('longitude (deg)')
ylabel('latitutude (deg)')
end
zlabel('z (m)')
set(gca,'DataAspectRatio',[xscale yscale 1]);
hold off
drawnow

end
66 changes: 8 additions & 58 deletions wrfv2_fire/test/em_fire/hill/hillframe.m
Expand Up @@ -5,22 +5,14 @@
disp(' >> ncload wrfrst_d01_0001-01-01_00:01:00')

% note the variables are read here without the WRF permutation of dimensions
ideal=1
ideal=1;
rst=1;

if ideal,
if rst,
u=u_2;
v=v_2;
w=w_2;
ph = ph_2;
r=[10,10]; % refinement factor
% do not have xlong and xlat in ideal case, but we made the coordinates up
% for fxlong and fxlat, so interpolate
n=size(xlong);
[xa,ya]=ndgrid(r(1)*[1/2:1:n(1)],r(2)*[1/2:1:n(2)]); % centers of atm cells in fire grid
axlong = interp2(fxlong,xa,ya); % fake coordinates for display
axlat = interp2(fxlat,xa,ya); % fake coordinates for display
else
axlong=xlong; axlat=xlat; % in real case, xlong xlat populated
end

clf
Expand All @@ -31,53 +23,11 @@

qstep=[5,5]; % quiver step for wind on the surface fire grid
astep=[1,1,1]; % quiver step for wind on the atmosphere grid
qs=1.5; % scaling for quiver arrows

qs=1.5; % scaling for quiver arrows
r=[10,10]; % refinement factor
swind=1; % plot surface wind

%-------------------------------------------------

% compute the corresponding part of the fire grid
dmin=1+r.*(amin(1:2)-1);
dmax=r.*amax(1:2);


% surface wind arrows
ii=dmin(1):qstep(1):dmax(1);jj=dmin(2):qstep(2):dmax(2);
hq=quiver3(fxlong(ii,jj),fxlat(ii,jj),zsf(ii,jj),qs*uf(ii,jj),qs*vf(ii,jj),zeros(size(vf(ii,jj))),0);
hold on
i=dmin(1):dmax(1);j=dmin(2):dmax(2);

% surface colored by heat flux
hs=surf(fxlong(i,j),fxlat(i,j),zsf(i,j),fgrnhfx(i,j),'EdgeColor','none','FaceAlpha',0.7); colorbar
[c,hc]=contour3(fxlong(i,j),fxlat(i,j),zsf(i,j));
for h=hc(:)', set(h,'EdgeColor','black');end

err_hgt = big(hgt-phb(:,:,1)/9.81) % the lowest background geopotential height is terrain height

% geopotential altitude of the centers of lower cell face
% ph is perturbation from the background phb
% note ph and phb are staggered just as w
a = (ph+phb)/9.81;

% interpolate the geopotential and w velocity from staggered grid to cell centers
ac = (a(:,:,1:end-1)+a(:,:,2:end))/2;
wc = (w(:,:,1:end-1)+w(:,:,2:end))/2;
% interpolate u and v components of wind velocity from staggered grid to cell centers
uc = (u(1:end-1,:,:)+u(2:end,:,:))/2; % from front and rear face to the center
vc = (v(:,1:end-1,:)+v(:,2:end,:))/2; % from front and rear face to the center

% atmosphere wind arrows
ia=amin(1):astep(1):amax(1);
ja=amin(2):astep(2):amax(2);
for k=amin(3):astep(3):amax(3),
hqa=quiver3(axlong(ia,ja),axlat(ia,ja),ac(ia,ja,k),... % position
qs*u(ia,ja,k),qs*v(ia,ja,k),qs*w(ia,ja,k),0); % wind arrow
end

caxis([0,1e6]); % for heat flux color
axis equal
xlabel('x (m)')
ylabel('y (m)')
zlabel('z (m)')
hold off
drawnow
frame3d(swind,amin,amax,astep,qstep,qs,...
fxlong,fxlat,xlong,xlat,zsf,fgrnhfx,uf,vf,u,v,w,ph,phb,hgt)
42 changes: 42 additions & 0 deletions wrfv2_fire/test/em_fire/hill/wrfout2frame3d.m
@@ -0,0 +1,42 @@
% function wrfout2frame3d(file,steps)
disp('1. file=''wrfout file''')
disp('2. steps=[1:20] % time steps to display')
disp('3. wrfout2frame3d')

fxlong =ncread(file,'FXLONG');
fxlat =ncread(file,'FXLAT');
xlong =ncread(file,'XLONG');
xlat =ncread(file,'XLAT');
zsf =ncread(file,'ZSF');
fgrnhfx=ncread(file,'FGRNHFX');
uf =ncread(file,'UF');
vf =ncread(file,'VF');
u =ncread(file,'U');
v =ncread(file,'V');
w =ncread(file,'W');
ph =ncread(file,'PH');
phb =ncread(file,'PHB');
hgt =ncread(file,'HGT');


% note the variables are read here without the WRF permutation of dimensions

amin=[15,15,1]; % the atm grid part to show
amax=[30,30,2];
amin=[1,1,1]; % the atm grid part to show
amax=[41,41,2];

qstep=[20,20]; % quiver step for wind on the surface fire grid
astep=[2,2,1]; % quiver step for wind on the atmosphere grid
qs=1e-3; % scaling for quiver arrows
swind=0; % do not display surface wind

%-------------------------------------------------

for k=steps,
frame3d(swind,amin,amax,astep,qstep,qs,...
fxlong(:,:,k),fxlat(:,:,k),xlong(:,:,k),xlat(:,:,k),...
zsf(:,:,k),fgrnhfx(:,:,k),uf(:,:,k),vf(:,:,k),...
u(:,:,:,k),v(:,:,:,k),w(:,:,:,k),...
ph(:,:,:,k),phb(:,:,:,k),hgt(:,:,k))
end

0 comments on commit 9237c55

Please sign in to comment.