ERA5-Land: error calculating hourly radiation

14 次查看(过去 30 天)
I need help with the code below. Code compares data from ERA5 and ERA5-Land. In ERA5-Land, precipitation and radiation data are accumulated throughout the day. Thus, the hour 00:00 does not represent the "zero value", because it contains the accumulated value of the previous hours. Hence the daily accumulation totals will be obtained by adding the values from 01:00 to 00:00-next day. The code needs to subtract the current time from the previous time (including 00:00 - 23:00). The hour 01:00 remains the same because it is accumulated for only one hour (00:00 to 01:00).
So in order to have the J/m2 for 05UTC, for example, we need to subtract J/m2 of 04 from 05. Only for 01UTC we dontt need to subtract from the previous time step.
I'm trying to apply this logic to the code, but I can't. Thanks if anyone can help me.
% Load the NetCDF file
nc = ncinfo('D:\ERA-Morocco\ERA5\surface_solar_radiation_downwards_2017_2022.nc');
data = ncread('D:\ERA-Morocco\ERA5\surface_solar_radiation_downwards_2017_2022.nc','ssrd');
% Get the dimensions of the data
lon = ncread('D:\ERA-Morocco\ERA5\surface_solar_radiation_downwards_2017_2022.nc','longitude');
lat = ncread('D:\ERA-Morocco\ERA5\surface_solar_radiation_downwards_2017_2022.nc','latitude');
time = ncread('D:\ERA-Morocco\ERA5\surface_solar_radiation_downwards_2017_2022.nc','time');
time = double(time); % Convert time to double data type
time = time/24 + datenum('1900-01-01 00:00:00'); % Convert to serial date numbers
% Get the number of years in the data
num_years = length(unique(year(time)));
i=5;
start_index = find(year(time)==(2016+i),1);
if i==1 % 2000
ndoys=366;
else
ndoys=365;
end
end_index = start_index + ndoys*24 - 1;
help=zeros(length(lon),length(lat),ndoys*24);
help(:,:,:) = data(:,:,start_index:end_index);
filename=strcat('D:\ERA-Morocco\ERA5-Land\surface_solar_radiation_downwards\',...
'surface_solar_radiation_downwards_',num2str(2016+i),'.nc');
era5land=ncread(filename, 'ssrd');
hour = mod(floor(time(start_index:end_index)*24), 24); % get the hour for each time point
% apply the conditional
era5land_hour = era5land;
for t = 2:numel(hour)
if hour(t) == 1
era5land_hour(:,:,t) = era5land(:,:,t);
else
era5land_hour(:,:,t) = (era5land(:,:,t) - era5land(:,:,t-1));
end
end
era5=zeros(size(era5land_hour));
for lvls=1:size(era5land_hour,3)
era5(:,:,lvls)=resizem(help(:,:,lvls),[size(era5land_hour,1),size(era5land_hour,2)]);
end
Here is the link with explanation: https://confluence.ecmwf.int/pages/viewpage.action?pageId=197702790 (So according to the link, the accumulations are over the 24 hours ending at 00 UTC i.e. the accumulation is during the previous day).

回答(1 个)

dpb
dpb 2023-4-20
编辑:dpb 2023-4-21
Seems very peculiar way to have done, but I'd just fix the date and then process by it instead...
% Load the NetCDF file
...
time = ncread('D:\ERA-Morocco\ERA5\surface_solar_radiation_downwards_2017_2022.nc','time');
time=datetime(1900,1,1,time,0,0); % Convert to datetime
%time=datetime(time/24+datenum('1900-01-01 00:00:00'),'ConvertFrom','datenum'); % Convert to datetime
ixHr0=(hour(time)==0; % locate rollover locations
time(ixHr0)=t(ixHr0)-days(1); % move them back to prior day
...
Since they're accumulating the data until the actual clock time recorded, the preciptation/radiation/whatever data then need to be rotated down one hour; each hour is actually that accumulated during the previous hour; hence the rollover to the next day. That would just be a
p=circshift(p,-1); % shift down, rotate fill last element w/ first
Then you'll have data from 0-23 hours all in the same day and all with the hour within which were accumulated.
Now, just use the date as the grouping variable and all will be well (and much simpler).

类别

Help CenterFile Exchange 中查找有关 Weather and Atmospheric Science 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by