Trying to shift/recenter map and data
21 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello, I have a 3-D dataset of sea surface temperatures. My matrix is of size 1440x721x1, where the first dimension is longitude, the second is lattitude, and the 3rd dimension is the averged sea surface temperatures at 1 time. My longtitude values run from 0 to 360 degrees, but I would like to recenter the data on the prime meridian (0 degrees). Ideally, I'd like to convert my 0 to 360 grid into a grid spanning from -180 to 180 and center the map and data on 180 degrees instead of 0. I've tried just about everything under the sun and end up with a result of either my data shifting and the map doesn't, or the map shifts and the data doesnt. Does anyone have any simple solutions to this?
figure(1)
pcolor(long,lat,array_1(:,:,1)');
shading flat
colorbar;xlabel('Longitude');ylabel('Latitude');
% axis([275 350 25 60]);
set(gca,'clim',[275 300]);
0 Commenti
Risposta accettata
Adam Danz
il 27 Lug 2021
Modificato: Adam Danz
il 28 Lug 2021
You can wrap your longitudinal values to [-180,180] using wrapTo180() which requires the mapping toolbox.
Edit:
You'll also need the wrapped X data to be in the same order as the original X data and then resort the color value matrix (array_1) to match the new order of the wrapped X data. That can get complicated depending on how your x data are arranaged. Assuming the x is a vector in ascending order, you can follow this demo using the data you provided in a comment below. Note that data on x=0 and x=360 will be combined after wrapping.
D1 = load('long.mat');
long = D1.long;
D2 = load('lat.mat');
lat = D2.lat;
D3 = load('sst2.mat');
sst2 = D3.sst2;
% Wrap longitudinal values and adjust order of C data according
% to the wrapped longitudinal values. This assumes the original
% longitudinal values are in ascending order.
assert(isequal(sort(long(:)), long(:)), 'This method assumes X was sorted in ascending order');
Xwrap = wrapTo180(long);
[XwrapSorted, XwrapOrder] = sort(Xwrap(:));
C = sst2(XwrapOrder,:);
% Plot original data
figure()
tiledlayout(2,1,'TileSpacing','compact')
nexttile()
pcolor(long,lat,sst2');
shading flat
colorbar;
xlabel('Longitude');
ylabel('Latitude');
set(gca,'clim',[275 300]);
title('Original data ([0,360])')
axis equal
axis tight
% Plot wrapped version
nexttile()
pcolor(XwrapSorted,lat,C');
shading flat
colorbar;xlabel('Longitude');ylabel('Latitude');
set(gca,'clim',[275 300]);
title('Wrapped data ([-180,180])')
axis equal
axis tight
7 Commenti
JMSE
il 2 Nov 2021
Modificato: JMSE
il 2 Nov 2021
Hi, I am facing a similar issue with the attached data. I want to recenter the data into a grid from 0 - 360. I am having a dataset with -180 to -180 and the aim is to extract data with lon: > 150 & 0 - 20. So, recentering the data would help to extract the desired dataset as one coherent set. With the snipped below I can extract a subset of e.g. lon > 150 & < 180, but not > 180 (or equivalent >0 within a 0-360 recentrered version.
So the example by @Adam Danz is already very helpful, but I am having a hard time to apply it to my case with the attached data.
Thank you!
dlat = load('prec_lat.mat');
lat = dlat.lat;
dlon = load('prec_lon.mat');
lon = dlon.lon;
dprec = load('prec.mat');
prec = dprec.prec;
J=find(lat > -30 & lat < 0);
K=find(lon > 150 & lon < 180);
precp=prec(J,K);
lonp=lon(K);
latp=lat(J);
figure;pcolor(lonp,latp,precp);shading flat
geoshow('landareas.shp', 'facecolor', 'k');
xlabel('longitude (°)'); ylabel('latitude (°)'); title('Precipitation 2021/12/19 00:00:00 - 00:00:29');
h=colorbar;
set(get(h,'ylabel'),'String','Rain rate (mm/h)');
hold on
plot(178.19,-16,'r*')
Thanks!
Judith
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!