Regridding Latitude/Longitude File
Show older comments
I am looking to regrid a lat/lon grid file similar to the picture below. Specifically, I am trying to upscale from a 2km domain to a 10km domain. Any suggestions help.
Answers (1)
Raag
on 17 Feb 2025
Hi YOlivo,
The issue in regridding your data from a 2km to 10km domain arises because a 10km grid cell corresponds to a 5x5 block of 2km cells, You will need to aggregate those blocks to obtain your new coarser grid.
Here are the steps to follow:
- Check that your original 2km data dimensions are multiple of 5
[nLat_2km, nLon_2km] = size(Z_2km);
if mod(nLat_2km, 5) ~= 0 || mod(nLon_2km, 5) ~= 0
error('Dimensions are not multiples of 5. Cannot block-average cleanly.');
end
- Reshape your data into bock of 5x5
nDivLat = nLat_2km / 5;
nDivLon = nLon_2km / 5;
Z_reshaped = reshape(Z_2km, 5, nDivLat, 5, nDivLon);
- Compute the average over each 5x5 block
Z_10km = squeeze(mean(mean(Z_reshaped, 1), 3));
- Construct the new latitude/longitude arrays
%If 'lat_2km' and 'lon_2km' are your original vectors,
%you can pick every 5th element to represent the new grid location:
lat_10km = lat_2km(1:5:end);
lon_10km = lon_2km(1:5:end);
For a better understanding of the above solution, refer to the following MATLAB documentations:
- reshape : https://www.mathworks.com/help/matlab/ref/double.reshape.html
- mean : https://www.mathworks.com/help/matlab/ref/mean.html
- squeeze : https://www.mathworks.com/help/matlab/ref/squeeze.html
Categories
Find more on Data Distribution Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!