Main Content

Display Animation of Radar Images over GOES Backdrop

This example shows how to display NEXRAD radar images. The images cover the past 24 hours, sampled at one-hour intervals, for the United States using data from the IEM WMS server.

Search the WMS Database for the 'nexrad-n0r-wmst' layer. Synchronize the layer with the server.

wmst = wmsfind('nexrad-n0r-wmst','SearchField','layername'); 
wmst = wmsupdate(wmst); 

Search the WMS Database for a generated CONUS composite of GOES IR imagery. Synchronize the layer with the server.

goes = wmsfind('goes*conus*ir','SearchField','layername');
goes = wmsupdate(goes);

Create a map of the conterminous United States.

hfig = figure;
region = 'conus';
usamap(region)
borders = geoshow('usastatehi.shp','FaceColor','none');

Get the latitude and longitude limits of the map.

mstruct = gcm;
latlim = mstruct.maplatlimit;
lonlim = mstruct.maplonlimit;

Read the GOES layer to use as a backdrop image.

cellsize = 0.1;
[backdrop, R] = wmsread(goes,'ImageFormat','image/png', ...
   'Latlim',latlim,'Lonlim',lonlim,'Cellsize',cellsize);

Find the current time minus 24 hours. Set up frames to hold the data from getframe.

now_m24 = datestr(now-1);
hour_m24 = [now_m24(1:end-5) '00:00'];
hour = datenum(hour_m24);
hmap = [];
numFrames = 24;
frames = struct('cdata',[],'colormap',[]);
frames(numFrames) = frames;

Set the Visible property of the figure to 'off' to hide the figure while populating the frames. For each hour, obtain the hourly NEXRAD map data and combine it with a copy of the backdrop. Because of how this Web server handles PNG format, the resulting map data has an image with class double. Thus, you must convert it to uint8 before merging.

hfig.Visible = 'off';
for k=1:numFrames
    time = datestr(hour);
    [A,R] = wmsread(wmst,'Latlim',latlim,'Lonlim',lonlim, ...
        'Time',time,'CellSize',cellsize, ...
        'BackgroundColor',[0 0 0],'ImageFormat','image/png');
    delete(hmap)
    index = any(A > 0, 3);
    combination = backdrop;
    index = cat(3,index,index,index);
    combination(index) = uint8(255*A(index));
    hmap = geoshow(combination,R);
    uistack(borders,'top')
    title({wmst.LayerName,time})
    frames(k) = getframe(hfig);
    hour = hour + 1/24;
end

Set the Visible property of the figure to 'on'. View the movie loop three times at 1.5 frames per second.

hfig.Visible = 'on';
shg
movie(hfig,frames,3,1.5)

See Also

| |

Related Topics