Mean Composite of netcdf images

조회 수: 3 (최근 30일)
Arnab Paul
Arnab Paul 2024년 3월 11일
답변: Udit06 2024년 3월 18일
I am stuck with a problem. I want to create a mean composite of multiple georeferenced .nc satelllite images. 1st problem is findling the study area. The images have my AOI in different position because of swath. Although I cropped the images based on desired lat and lon. Which cuased the 2nd problem. The cropped images have different dimensions. Someone suggested me to use meshgrid. Can someone give a clear vision how to create composite of multiple images
the code I have written so far is here.
fileDirectory = "input folder";
filename = dir(fullfile(fileDirectory, '*_reprojected_chl.nc'));
nFileDirectory = length(filename);
outputFolder = "output folder";
for i=1:nFileDirectory
nFileRrs = filename(i).name;
% Crop the data
min_lat = 26.5;
max_lat = 30.5;
min_lon = -95;
max_lon = -88.5;
data = ncread(fullfile(fileDirectory, nFileRrs), 'latitude'); % Replace with your actual variable name
latitude = double(data);
data = ncread(fullfile(fileDirectory, nFileRrs), 'longitude'); % Replace with your actual variable name
longitude = double(data);
data = ncread(fullfile(fileDirectory, nFileRrs), 'chl_image'); % Replace with your actual variable name
chl_image = double(data);
% Print lat/lon ranges
fprintf('File: %s, Latitude Range: %f to %f, Longitude Range: %f to %f\n', nFileRrs, min(latitude(:)), max(latitude(:)), min(longitude(:)), max(longitude(:)));
% Find row and column indices
[row_indices, col_indices] = find(latitude >= min_lat & latitude <= max_lat & ...
longitude >= min_lon & longitude <= max_lon);
clipped_chl_data = chl_image(min(row_indices):max(row_indices), min(col_indices):max(col_indices));
clipped_latitude = latitude(min(row_indices):max(row_indices), min(col_indices):max(col_indices));
clipped_longitude = longitude(min(row_indices):max(row_indices), min(col_indices):max(col_indices));
clipped_chl_data = clipped_chl_data';
clipped_latitude = clipped_latitude';
clipped_longitude = clipped_longitude';
% Get the dimensions of the clipped data
[r, c] = size(clipped_chl_data);
end

답변 (1개)

Udit06
Udit06 2024년 3월 18일
Hi Arnab,
Based on the code you have provided above, you've successfully looped through your .nc files, read the relevant data (latitude, longitude, and chl_image), and cropped the data to your Area of Interest (AOI). The next step would be to interpolate these cropped images to a common grid and then calculate the mean composite of these images.
You can follow the following steps for the same
1) Define a common grid
min_lat = 26.5;
max_lat = 30.5;
min_lon = -95;
max_lon = -88.5;
% Define the common grid's latitude and longitude boundaries and resolution
resolution_lat = 0.1; % adjust as per your requirement
resolution_lon = 0.1; % adjust as per your requirement
common_lat = min_lat:resolution_lat:max_lat;
common_lon = min_lon:resolution_lon:max_lon;
% Create the meshgrid for the common grid
[common_lon_grid, common_lat_grid] = meshgrid(common_lon, common_lat);
2) Interpolate each cropped image to the common grid
% Interpolate the current image to the common grid
interpolated_image = interp2(clipped_longitude, clipped_latitude, clipped_chl_data, common_lon_grid, common_lat_grid, 'linear'
You can refer to the following MathWorks documentation to understand more about meshgrid and interp2 functions.
I hope it helps.

카테고리

Help CenterFile Exchange에서 NetCDF에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by