How to edit this code?

2 vues (au cours des 30 derniers jours)
BN
BN le 1 Nov 2019
Commenté : MarineM le 19 Mai 2021
Hello all,
Recently I was trying to download ECMWF ERA5 precipitation data. the precipitation has 3 dimensions (lon x lat x time) the format of the file is NetCDF. data are in hourly time steps. each day begins at 00:00 and ends at 23:00. The NetCDF file includes hourly data for a year, so it has 365*24=8760 time steps. I would like to convert these hourly data daily but one main issue stands in front of me. I explain my issue with a very simple example:
to cover total precipitation for 1st January 2017 (for example), we need two days of data:
A) 1st January 2017 time = 01 - 23 will give you total precipitation data to cover 00 - 23 UTC for 1st January 2017
B) 2nd January 2017 time = 00 will give you total precipitation data to cover 23 - 24 UTC for 1st January 2017
So I need a code that Starts every day at 01:00 and ends at 00:00 next day and saves this value as a value of one day, rather than takes each day's time range between 00:00 to 23:00. And do it for each day in the year.
I have 2 types of code that unfortunately didn't consider this issue. if you kindly please help me edit this code I would be grateful. let me know if any other questions you have.
Code number 1:
filename='download.nc'; %Name of netcdf file
ncdisp(filename) %show summary of nc
lat = ncread(filename,'latitude'); %reading latitude
lon = ncread(filename,'longitude'); %reading longitude
precip = ncread(filename,'tp'); %reading the main variable
t = ncread(filename,'time'); %read time
daily_precip = squeeze(nansum(reshape(precip, size(precip, 1), size(precip, 2), 24, []), 3));
dt = datetime(double(t)*3600, 'ConvertFrom', 'epochtime', 'Epoch', '01-Jan-1900');
[group, actualday] = discretize(dt, 'day');
daily_precip = splitapply(@(pages) {nansum(precip(:, :, pages), 3)}, (1:size(precip, 3))', group);
daily_precip = cat(3, daily_precip{:});
And the code numebr two:
filename='download.nc'; %Name of netcdf file
ncdisp(filename) %show summary of nc
lat = ncread(filename,'latitude'); %reading latitude
lon = ncread(filename,'longitude'); %reading longitude
precip = ncread(filename,'tp'); %reading the main variable
t = ncread(filename,'time'); %read time
tp_daily=zeros(size(precip,1),size(precip,2),365);
for ii=0:364
day=precip(:,:,ii*24+1:(ii+1)*24); %grab an entire day
tp_daily(:,:,ii+1)=nansum(day,3); % add the third dimension
end
please download my netcdf file using this link below:
Thank you everyone
  5 commentaires
BN
BN le 2 Nov 2019
If the variable was something like temperature that records every hour and independent from later hours, this was true, but here the variable is total precipitation. Each hour precipitation of one past hour will be recorded. So if we want to know how much rainfall was accrued in a total of the day, we need to analyze 00:00 of next day to understand the value for 23:00 to 00:00. Actually, this data is for the European Centre for Medium-Range Weather Forecasts (ECMWF) ERA5, which recently was released.
In the ERA5 page, the python code was presented for this purpose.
But unfortunately, still, now, the Matlab code doesn't exist. It could be beneficial for all students and researchers around the world if any Matlab code for this purpose exists.
Thank You :)
MarineM
MarineM le 19 Mai 2021
Hi, I have the same issue here. I am just wondering if 2 years later someone did discover a code for Matlab. Thank you :)

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Climate Science and Analysis 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