Creat a new nc file after filling the missing data using interpolation
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello,
I was trying to fill the missing data using interpolation in a directory that has 100's of similar nc files. When I run the code, it went well. However, when I checked the data, all variables are filled with the same value in each variable. Would you please let me know what went wrong in the code? Thanks
% Specify the folder where the files are.
InFolder = 'Z:infolder';
filePattern = fullfile(InFolder, '*.nc');
inFiles = dir(filePattern);
outFolder = 'Z:infolder\new'
Loop for each nc-file
for i = 1:length(inFiles)
baseFileName = inFiles(i).name;
EDGEE = ncread(baseFileName,'EDGEE') ;
EDGEW = ncread(baseFileName,'EDGEW') ;
EDGES = ncread(baseFileName,'EDGES');
EDGEN = ncread(baseFileName,'EDGEN') ;
LONGXY = ncread(baseFileName,'LONGXY') ;
LATIXY = ncread(baseFileName,'LATIXY') ;
PSRF = ncread(baseFileName,'PSRF') ; PSRF = fillmissing(PSRF, 'linear') ;
time = ncread(baseFileName,'time') ; time = fillmissing(time,'linear') ;
TBOT = ncread(baseFileName,'TBOT') ; TBOT = fillmissing(TBOT,'linear') ;
WIND = ncread(baseFileName,'WIND') ; WIND = fillmissing(WIND,'linear') ;
RH = ncread(baseFileName,'RH') ; RH = fillmissing(RH,'linear') ;
FLDS = ncread(baseFileName,'FLDS') ; FLDS = fillmissing(FLDS,'linear') ;
FSDS = ncread(baseFileName,'FSDS') ; FSDS = fillmissing(FSDS,'linear') ;
PRECTmms = ncread(baseFileName,'PRECTmms') ; PRECTmms = fillmissing(PRECTmms,'linear') ;
zbot = ncread(baseFileName,'zbot') ; %for extracted data
% ZBOT = ncread(baseFileName,'ZBOT') ; %for main dataset before extraction
% Now Write the new file/s
% EDGEE
fullFileName = fullfile(outFolder, baseFileName);
nccreate(fullFileName,'EDGEE','Dimensions',{'scalar',1,length(EDGEE)}) ;
%%ncwrite(file2,'EDGEE',EDGEE) ;
ncwriteatt(fullFileName,'EDGEE','long_name','eastern edge in atmospheric data');
ncwriteatt(fullFileName,'EDGEE','units','degrees_east');
% EDGEW
nccreate(fullFileName,'EDGEW','Dimensions',{'scalar',1,length(EDGEW)}) ;
% ncwrite(file2,'EDGEW',EDGEW) ;
ncwriteatt(fullFileName,'EDGEW','long_name','western edge in atmospheric data');
ncwriteatt(fullFileName,'EDGEW','units','degrees_east');
% EDGES
nccreate(fullFileName,'EDGES','Dimensions',{'scalar',1,length(EDGES)}) ;
% ncwrite(file2,'EDGES',EDGES) ;
ncwriteatt(fullFileName,'EDGES','long_name','southern edge in atmospheric data');
ncwriteatt(fullFileName,'EDGES','units','degrees_north');
% EDGEN
nccreate(fullFileName,'EDGEN','Dimensions',{'scalar',1,length(EDGEN)}) ;
% ncwrite(file2,'EDGEN',EDGEN) ;
ncwriteatt(fullFileName,'EDGEN','long_name','northern edge in atmospheric data');
ncwriteatt(fullFileName,'EDGEN','units','degrees_north');
%LONGXY
nccreate(fullFileName,'LONGXY','Dimensions',{'lon',1,length(LONGXY),'lat',1,length(LATIXY)}) ;
% ncwrite(file2,'LONGXY',LONGXY) ;
ncwriteatt(fullFileName,'LONGXY','long_name','longitude');
ncwriteatt(fullFileName,'LONGXY','units','degrees_east');
% LATIXY
nccreate(fullFileName,'LATIXY','Dimensions',{'lon',1,length(LONGXY),'lat',1,length(LATIXY)}) ;
% ncwrite(fullFileName,'LATIXY',LATIXY) ;
ncwriteatt(fullFileName,'LATIXY','long_name','latitude');
ncwriteatt(fullFileName,'LATIXY','units','degrees_north');
% PSRF
nccreate(fullFileName,'PSRF','Dimensions',{'lon',1,length(LONGXY),'lat',1,length(LATIXY),'time',1,length(time)}) ;
% ncwrite(file2,'PSRF',PSRF) ;
ncwriteatt(fullFileName,'PSRF','long_name','surface pressure at the lowest atm level');
ncwriteatt(fullFileName,'PSRF','units','Pa');
ncwriteatt(fullFileName,'PSRF','model','time-dependent');
% ncwriteatt(fullFileName,'PSRF','_FillValue','1.000000020040877e+20');
% ncwriteatt(fullFileName,'PSRF','missing_value','1.000000020040877e+20');
% time
nccreate(fullFileName,'time','Dimensions',{'time',1,length(time)}) ;
% ncwrite(fullFileName,'time',time) ;
ncwriteatt(fullFileName,'time','long_name','UTC time');
ncwriteatt(fullFileName,'time','units','days since');
ncwriteatt(fullFileName,'time','calendar','noleap');
% TBOT
nccreate(fullFileName,'TBOT','Dimensions',{'lon',1,length(LONGXY),'lat',1,length(LATIXY),'time',1,length(time)}) ;
% ncwrite(fullFileName,'TBOT',TBOT) ;
ncwriteatt(fullFileName,'TBOT','long_name','temperature at the lowest atm level');
ncwriteatt(fullFileName,'TBOT','units','K');
ncwriteatt(fullFileName,'TBOT','model','time-dependent');
% ncwriteatt(fullFileName,'TBOT','_FillValue','1.000000020040877e+20');
% ncwriteatt(fullFileName,'TBOT','missing_value','1.000000020040877e+20');
% WIND
nccreate(fullFileName,'WIND','Dimensions',{'lon',1,length(LONGXY),'lat',1,length(LATIXY),'time',1,length(time)}) ;
% ncwrite(fullFileName,'WIND',WIND) ;
ncwriteatt(fullFileName,'WIND','long_name','wind at the lowest atm level');
ncwriteatt(fullFileName,'WIND','units','m/s');
ncwriteatt(fullFileName,'WIND','model','time-dependent');
% ncwriteatt(fullFileName,'WIND','_FillValue','1.000000020040877e+20');
% ncwriteatt(fullFileName,'WIND','missing_value','1.000000020040877e+20');
% RH
nccreate(fullFileName,'RH','Dimensions',{'lon',1,length(LONGXY),'lat',1,length(LATIXY),'time',1,length(time)}) ;
% ncwrite(fullFileName,'RH',RH) ;
ncwriteatt(fullFileName,'RH','long_name','relative humidity at the lowest atm level');
ncwriteatt(fullFileName,'RH','units','%');
ncwriteatt(fullFileName,'RH','model','time-dependant');
% ncwriteatt(fullFileName,'RH','_FillValue','1.000000020040877e+20');
% ncwriteatt(fullFileName,'RH','missing_value','1.000000020040877e+20');
% FLDS
nccreate(fullFileName,'FLDS','Dimensions',{'lon',1,length(LONGXY),'lat',1,length(LATIXY),'time',1,length(time)}) ;
% ncwrite(fullFileName,'FLDS',FLDS) ;
ncwriteatt(fullFileName,'FLDS','long_name','incident longwave radiation');
ncwriteatt(fullFileName,'FLDS','units','W/m2');
ncwriteatt(fullFileName,'FLDS','model','time-dependant');
% ncwriteatt(fullFileName,'FLDS','_FillValue','1.000000020040877e+20');
% ncwriteatt(fullFileName,'FLDS','missing_value','1.000000020040877e+20');
% FSDS
nccreate(fullFileName,'FSDS','Dimensions',{'lon',1,length(LONGXY),'lat',1,length(LATIXY),'time',1,length(time)}) ;
% ncwrite(file2,'FSDS',FSDS) ;
ncwriteatt(fullFileName,'FSDS','long_name','total incident solar radiation');
ncwriteatt(fullFileName,'FSDS','units','W/m2');
ncwriteatt(fullFileName,'FSDS','model','time-dependant');
% ncwriteatt(fullFileName,'FSDS','_FillValue','1.000000020040877e+20');
% ncwriteatt(fullFileName,'FSDS','missing_value','1.000000020040877e+20');
% PRECTmms
nccreate(fullFileName,'PRECTmms','Dimensions',{'lon',1,length(LONGXY),'lat',1,length(LATIXY),'time',1,length(time)}) ;
% ncwrite(fullFileName,'PRECTmms',PRECTmms) ;
ncwriteatt(fullFileName,'PRECTmms','long_name','total precipitation rate');
ncwriteatt(fullFileName,'PRECTmms','units','mm/s');
ncwriteatt(fullFileName,'PRECTmms','model','time-dependant');
% ncwriteatt(fullFileName,'PRECTmms','_FillValue','1.000000020040877e+20');
% ncwriteatt(fullFileName,'PRECTmms','missing_value','1.000000020040877e+20');
% % ZBOT
%
% nccreate(fullFileName,'ZBOT','Dimensions',{'lon',1,length(LONGXY),'lat',1,length(LATIXY)}) ;
% % ncwrite(fullFileName,'ZBOT',zbot) ;
% ncwriteatt(fullFileName,'ZBOT','long_name','observational height');
% ncwriteatt(fullFileName,'ZBOT','units','m');
% ncwriteatt(fullFileName,'ZBOT','model','time-dependant');
% % ncwriteatt(fullFileName,'ZBOT','_FillValue','1.000000020040877e+20');
% % ncwriteatt(fullFileName,'ZBOT','missing_value','1.000000020040877e+20');
% zbot
nccreate(fullFileName,'zbot','Dimensions',{'lon',1,length(LONGXY),'lat',1,length(LATIXY)}) ;
% ncwrite(fullFileName,'zbot',zbot) ;
ncwriteatt(fullFileName,'zbot','long_name','observational height');
ncwriteatt(fullFileName,'zbot','units','m');
ncwriteatt(fullFileName,'zbot','model','time-dependant');
% ncwriteatt(fullFileName,'zbot','_FillValue','1.000000020040877e+20');
% ncwriteatt(fullFileName,'zbot','missing_value','1.000000020040877e+20');
end
0 commentaires
Réponses (0)
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!