ERA5-Land: error calculating hourly radiation

9 vues (au cours des 30 derniers jours)
Diego le 20 Avr 2023
Modifié(e) : dpb le 21 Avr 2023
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\');
data = ncread('D:\ERA-Morocco\ERA5\','ssrd');
% Get the dimensions of the data
lon = ncread('D:\ERA-Morocco\ERA5\','longitude');
lat = ncread('D:\ERA-Morocco\ERA5\','latitude');
time = ncread('D:\ERA-Morocco\ERA5\','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)));
start_index = find(year(time)==(2016+i),1);
if i==1 % 2000
end_index = start_index + ndoys*24 - 1;
help(:,:,:) = data(:,:,start_index:end_index);
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);
era5land_hour(:,:,t) = (era5land(:,:,t) - era5land(:,:,t-1));
for lvls=1:size(era5land_hour,3)
Here is the link with explanation: (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).

Réponses (1)

dpb le 20 Avr 2023
Modifié(e) : dpb le 21 Avr 2023
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\','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).


En savoir plus sur Dates and Time 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!

Translated by