Trying to shift/recenter map and data
25 views (last 30 days)
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?
% axis([275 350 25 60]);
Adam Danz on 27 Jul 2021
Edited: Adam Danz on 28 Jul 2021
You can wrap your longitudinal values to [-180,180] using wrapTo180() which requires the mapping toolbox.
Or you could use wrapToInterval() from the file exchange: wrapToInterval(long,[-180,180]);
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
title('Original data ([0,360])')
% Plot wrapped version
title('Wrapped data ([-180,180])')