How to compare two netcdf file (present to past data) by means of subtraction

2 views (last 30 days)
Hi Freinds
I have objective to find chlor conc. hotspot of particular month during successive year
For example I consider 2 year(2015 and 2016) nc data (Feb)month
I can extract the chlor_a data and plot with the below code
ncfile_1 = 'A20150322015059.L3m_MO_CHL_chlor_a_4km.nc';
lat_1 = ncread(ncfile_1,'lat') ;
lon_1 = ncread(ncfile_1,'lon') ;
chlor_a_1 = ncread(ncfile_1,'chlor_a');
[X_1,Y_1] = meshgrid(lon_1,lat_1) ;
nn = 1000;
xi_1 = linspace(30,100,nn) ;
yi_1 = linspace(0,30,nn) ;
[Xi_1,Yi_1] = meshgrid(xi_1,yi_1);
iwant_1 = interp2(X_1,Y_1,chlor_a_1',Xi_1,Yi_1)' ;
ind_1 = find(iwant_1>10 | iwant_1<0);
%ind = find(iwant_2 > 0 & iwant_1<10);
iwant_1(ind_1) = NaN;
%[min_val_1,min_ind_1] = min(iwant_1',[],'all','linear');
[min_val_1,min_ind_1] = min(reshape(iwant_1',[],1));
[r1_1,c1_1]=ind2sub(nn,min_ind_1);
x_min_1 = xi_1(c1_1);
y_min_1 = yi_1(r1_1);
%[max_val_1,max_ind_1] = max(iwant_1',[],'all','linear');
[max_val_1,max_ind_1] = max(reshape(iwant_1',[],1));
[r2_1,c2_1]=ind2sub(nn,max_ind_1);
x_max_1 = xi_1(c2_1);
y_max_1 = yi_1(r2_1);
figure(1)
pcolor(xi_1,yi_1,iwant_1'); shading interp;
c = colorbar;
cmap = jet(255);
cmap(:,2) = 0;
colormap(cmap)
caxis([0, 5])
hold on
plot(x_min_1,y_min_1,'k +', 'MarkerSize', 10);
plot(x_max_1,y_max_1,'m +', 'MarkerSize', 10);
hold off
legend('','min','max');
Image = getframe(gcf);
imwrite(Image.cdata, 'feb2015.tif');
--
ncfile_2 = 'A20160322016060.L3m_MO_CHL_chlor_a_4km.nc';
lat_2 = ncread(ncfile_2,'lat') ;
lon_2 = ncread(ncfile_2,'lon') ;
chlor_a_2 = ncread(ncfile_2,'chlor_a');
[X_2,Y_2] = meshgrid(lon_2,lat_2) ;
nn = 1000;
xi_2 = linspace(30,100,nn) ;
yi_2 = linspace(0,30,nn) ;
[Xi_2,Yi_2] = meshgrid(xi_2,yi_2);
iwant_2 = interp2(X_2,Y_2,chlor_a_2',Xi_2,Yi_2)' ;
ind = find(iwant_2>10 | iwant_2<0);
%ind = find(iwant_2 > 0 & iwant_2<10);
iwant_2(ind) = NaN;
%[min_val,min_ind] = min(iwant_2',[],'all','linear');
[min_val,min_ind] = min(reshape(iwant_2',[],1));
[r1,c1]=ind2sub(nn,min_ind);
x_min = xi_2(c1);
y_min = yi_2(r1);
%[max_val,max_ind] = max(iwant_2',[],'all','linear');
[max_val,max_ind] = max(reshape(iwant_2',[],1));
[r2,c2]=ind2sub(nn,max_ind);
x_max = xi_2(c2);
y_max = yi_2(r2);
figure(2)
pcolor(xi_2,yi_2,iwant_2'); shading interp;
c = colorbar;
cmap = jet(255);
cmap(:,2) = 0;
colormap(cmap)
caxis([0, 5])
hold on
plot(x_min,y_min,'k +', 'MarkerSize', 10);
plot(x_max,y_max,'m +', 'MarkerSize', 10);
hold off
legend('','min','max');
I find error while trying to execute below steps
need to save file in nc format for 1st file and same for next ...
by subtraction (present to past year) will spot seasonal trends
[+ve] value means max chlor_a conc. [-ve] value means less conc.
comparison will identify max persistence of chlor_a to identify hotspot
similary need to compare for weekly data to find the hotspot variation
data link
Kindly help, waitng for your suggestion and your valuable inputs
Thanks in advance
regards

Answers (0)

Categories

Find more on Interpolating Gridded Data 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!