Problem when wrapping longitude dataset

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

 Akzeptierte Antwort

Chad Greene
Chad Greene am 13 Mai 2015

0 Stimmen

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 Kommentare

Melissa
Melissa am 13 Mai 2015
Bearbeitet: Melissa am 13 Mai 2015
This looks good! Except I would like to plot it using pcolor instead of worldmap, so it stays consistent with my other datasets. Is there a way to get this kind of output using that?
Thanks
Chad Greene
Chad Greene am 13 Mai 2015
Bearbeitet: Chad Greene am 13 Mai 2015
Strange! I see the striping you are referring to. Here's a manual workaround that also takes care of the vertical stripe of missing data at the prime meridian:
load lat
load lon
load data
lon = wrapTo180(lon_model);
[lon,lat] = meshgrid(linspace(min(lon),max(lon),length(lon)),...
linspace(-90,90,192));
fm = double(first_model');
fm = fm(:,[145:end 1:144]);
% Not sure if you want to do this masking:
greenland = landmask(lat,lon,'greenland');
antarctica = landmask(lat,lon,'antarctica');
fm(greenland) = 0;
fm(antarctica) = 0;
figure
pcolor(lon,lat,fm)
shading interp
set(gca,'color',rgb('ocean blue'))
borders('countries','k','nomap')
colormap(brewermap(1024,'OrRd'))
axis([-180 180 -82 86])
Chad Greene
Chad Greene am 13 Mai 2015
...and in case you're wondering I used landmask for to turn data for Greenland and Antarctica into zeros.
Melissa
Melissa am 14 Mai 2015
This works perfectly! Thank you so much.
However, if I wanted to keep the white vertical line there, how would I do that while keeping the rest of the blue lines out?
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
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])

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by