Problem when wrapping longitude dataset

16 views (last 30 days)
Hello,
I have a global dataset that I would like to wrap. I want to change its longitude from [0 360] to [-180 180]. I can successfully wrapTo180 the longitude vector, but when I plot my data, there are lines sporadically across the map. There must be something wrong with the data that is making it do this.
Please help!!
I have attached my data so you can give it a whirl
Thanks,
Melissa

Accepted Answer

Chad Greene
Chad Greene on 13 May 2015
Does this work?
load lat
load lon
load data
[lon,lat] = meshgrid(wrapTo180(lon_model),lat_model);
worldmap('world')
pcolorm(lat,lon,double(first_model'))
And formatting with the help of rgb, borders, and brewermap,
setm(gca,'ffacecolor',rgb('ocean blue'))
borders('countries','k')
colormap(brewermap(1024,'OrRd'))
  6 Comments
Chad Greene
Chad Greene on 14 May 2015
I'm not sure why you want to keep that vertical line--it's an artifact of pcolor, which deletes a row and column of data. Before shifting fm with fm = fm(:,[145:end 1:144]);, pcolor would ignore the right-hand column of data, which was the column of data corresponding to the prime meridian. After the shift, pcolor discards the right-hand column of data east of New Zealand. If you want to arbitrarily discard a vertical line of data at the prime meridian, you can do so by
fm(:,144)=NaN;
which gives
Chad Greene
Chad Greene on 14 May 2015
Or if you don't want to get rid of any data, you can use imagesc instead of pcolor:
load lat
load lon
load data
fm = double(first_model');
fm = fm(:,[145:end 1:144]);
% Linear arrays of lat and lon:
lon = wrapTo180(lon_model);
lon = linspace(min(lon),max(lon),length(lon));
lat = linspace(-90,90,192);
% gridded lat/lon:
[long,latg] = meshgrid(lon,lat);
% landmask takes ~30 seconds:
land = landmask(latg,long);
% Set land NaNs to zero:
fm(land & isnan(fm)) = 0;
% Set ocean to -1:
fm(isnan(fm))=-1;
imagesc(lon,lat,fm);
axis xy
set(gca,'color',rgb('ocean blue'))
borders('countries','k','nomap')
bm = brewermap(1024,'OrRd');
colormap([rgb('ocean blue');bm])
axis([-180 180 -60 86])

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!