creating time series on specific coordinates rainfall using .nc

9 views (last 30 days)
I downloaded the global-scale rainfall data from 2017 to 2021 from the climate.copernicus portal (climate.copernicus). The system downloaded an .nc file for each year.
I would first of all like to be able to merge these files if possible, or at a later date be able to plot the time series of rainfall from 2017 to 2021 on a single graph. Another important step is that I would like to be able to have the time series of a specific point with the following coordinates 58.491573, 25.778418; or alternatively use a rectangle where I can have the time series considering the centroid of the polygon. how can I do?
But at the end, I wasn't able to create one plot with data on x-axis and rainfall data on y-axis considenring specific coordinates.
For now I have this script that allows me to open the file and understand the internal variables.
ncfile = ('');
% To get information about the nc file
% to display nc file
Here there is output
time = 12 (UNLIMITED)
lon = 720
lat = 360
Size: 12x1
Dimensions: time
Datatype: double
standard_name = 'time'
units = 'hours since 1891-1-1 00:00:00'
calendar = 'proleptic_gregorian'
axis = 'T'
Size: 720x1
Dimensions: lon
Datatype: double
standard_name = 'longitude'
long_name = 'longitude'
units = 'degrees_east'
axis = 'X'
Size: 360x1
Dimensions: lat
Datatype: double
standard_name = 'latitude'
long_name = 'latitude'
units = 'degrees_north'
axis = 'Y'
Size: 720x360x12
Dimensions: lon,lat,time
Datatype: single
standard_name = 'lwe_precipitation_rate'
long_name = 'total monthly precipitation'
units = 'mm/month'
code = 20
_FillValue = 3.000000060858434e+33
missing_value = 3.000000060858434e+33
institution = 'DWD'
Then I split the data considering the Variables using this code
% to read a vriable 'var' exisiting in nc file
long = ncread(ncfile,'lon');
latt = ncread(ncfile,'lat');
time = ncread(ncfile,'time');
pr = ncread(ncfile, 'pr'); %rainfall data

Answers (1)

Cris LaPierre
Cris LaPierre on 3 Oct 2023
Look at the size info to figure out the dimensions of pr
  • First dimension is longitude
  • Second dimension is latitute
  • Third dimension is time
So if I wanted to extract all the pr values for a specific longitude and latitude, I would first figure out which row corresponds to the longitude of interest, and which column corresponds to the latitude of interest. Assuming the lon/lat coordinate exactly matches the data sample grid, that might look like this:
lon = 8.491573;
lat = 25.778418;
indx = long==lon;
indy = latt==lat;
prData = pr(indx,indy,:);
Since you have multiple files, the first step might be to use fileDatastore to load all the data first, and then work on the data. You can write a custom function that can load the data from a single file, and use that as the ReadFcn for you fileDatastore.




Community Treasure Hunt

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

Start Hunting!