creating time series on specific coordinates rainfall using .nc

조회 수: 5 (최근 30일)
Rachele Franceschini
Rachele Franceschini 2023년 10월 3일
답변: Cris LaPierre 2023년 10월 3일
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 = ('GPCC_total_precipitation_mon_0.5x0.5_global_2017_v2020.0.nc');
% To get information about the nc file
ncinfo(ncfile)
% to display nc file
ncdisp(ncfile)
Here there is output
Format:
netcdf4
Dimensions:
time = 12 (UNLIMITED)
lon = 720
lat = 360
Variables:
time
Size: 12x1
Dimensions: time
Datatype: double
Attributes:
standard_name = 'time'
units = 'hours since 1891-1-1 00:00:00'
calendar = 'proleptic_gregorian'
axis = 'T'
lon
Size: 720x1
Dimensions: lon
Datatype: double
Attributes:
standard_name = 'longitude'
long_name = 'longitude'
units = 'degrees_east'
axis = 'X'
lat
Size: 360x1
Dimensions: lat
Datatype: double
Attributes:
standard_name = 'latitude'
long_name = 'latitude'
units = 'degrees_north'
axis = 'Y'
pr
Size: 720x360x12
Dimensions: lon,lat,time
Datatype: single
Attributes:
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

답변 (1개)

Cris LaPierre
Cris LaPierre 2023년 10월 3일
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,:);
plot(time,prData)
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.

카테고리

Help CenterFile Exchange에서 NetCDF에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by