Changing the longitude of NetCDF from 0-360 to -180-180?
66 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I want to use the Tmax data from https://psl.noaa.gov/data/gridded/data.cpc.globaltemp.html. Tmax is in the format of netcdf and longitude range is from 0 to 360. I want to make the longitude range from -180 to 180 and exported the changed data so that next time when I use it, I can have the proper longitude.
The latitude starts from the north so the image is flipped. How can I also change the latitude so that I can have the latitude in the data attribute starting from south.
Does anyone know how to solve the problem?
Thanks.
0 commentaires
Réponses (1)
Austin M. Weber
le 10 Mar 2024
Modifié(e) : Austin M. Weber
le 10 Mar 2024
I am attaching a .mat file with some CPC Global Temperature data as an example.
load cpc.mat
% Convert latitude and longitude data into type 'double' (by default CPC
% lat/lon data are of type 'single' which is not valid for plotting on map axes)
lat = double(lat);
lon = double(lon);
% Convert lon from [0 360] to [-180 180]
mask = lon > 180;
lon(mask) = lon(mask) - 360;
% Flip lat from [90 -90] to [-90 90]
lat = flip(lat);
% Rotate tmax and flip so that the dimensions are 360x720 (instead of
% 720x360)
tmax = flipud(tmax');
% Plot
figure(1)
ax=axesm('braun'); % Use whatever map projection you prefer
pcolorm(lat, lon, tmax)
mlabel('on') % Longitude tick labels
plabel('on') % Latitude tick labels
colorbar
tightmap
framem
gridm
To save the data for later:
save('mydata.mat','lat','lon','tmax')
9 commentaires
Austin M. Weber
le 17 Mar 2024
Yes, the "line" at 0° longitude is actually not a line but rather missing data. This is an artifact of the original CDC data, which has longitude values ranging from 0.25° to 359.75°. The Earth is a sphere, so that means the original dataset did not include the longitude values that wrap back from 359.75° to 0.25°. Therefore, 1° of longitude is missing from the original data.
When we rescaled the longitudes from -180° to 180°, this missing 1° of longitude became centered at the prime meridian. The dataset simply doesn't contain longitude coordinates for that location, but this gap is covered up if you add a grid to the map.
Voir également
Catégories
En savoir plus sur NetCDF dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!