How can I extract a time series of variable for a specific location (specific longitude and latitude) from a CMIP5 experiment netCDF data set? (Answer 1)

Source of the discussion (Click Here)

Question:
I want to downscale temperature and precipitation output from some of the CMIP5 models for my country (Jordan) coordinates. but I failed until now to figure out how to extract a time series of precipitation and temperature for specific coordinates from the the NetCDF files that I downloaded form the CMIP5 data website.

Answer 1:
If you use Matlab you can use the commands ncdisp and ncread. With the command ncdisp you can obtain information about the file (attributes, variables, dimensions, units, etc.). And with the command ncread you can extract data for a given variable.
Otherwise, if you use R, there is a netcdf package (http://cran.r-project.org/web/packages/RNetCDF/index.html). Then, I think the commands to use would be file.inq.nc and var.get.nc. (NB: I haven’t used it so I cannot give you advice about it).
I show you an example using Matlab. I downloaded the file ‘pr_day_CNRM-CM5_rcp45_r1i1p1_20260101-20301231.nc’ from the project CMIP5 (precipitation in 2026-2030 according to the RCP4.5 scenario and CNRM-CM5 model).
I save the file name
>> file = ‘pr_day_CNRM-CM5_rcp45_r1i1p1_20260101-20301231.nc’;
Then, to display the file properties:
>> ncdisp(file)
Then you can know that the variables you are interested in are coded as lat (latitude), lon (longitude), time (time), and pr (precipitation). lat is a 128×1 vector, lon is a 256×1 vector, and time is a 1826×1 vector and pr is a 256x128x1826 array with the dimensions lonlattime.
With the following commands you can extract the longitude, latitude and time values of all the grid points:
>> longitude = ncread(file,’lon’);
>> latitude = ncread(file,’lat’);
>> time = ncread(file,’time’);
You can use the same instruction (with some additional input arguments) to extract precipitation data for a selection of coordinates and times:
vardata = ncread(source,varname,start,count,stride)
source is the file name
varname is the variable name
start is from where you want to start to read data for each dimension (in vector form)
count is how many data points do you want to read for each dimension (in vector form)
stride is the frequency of extraction data, i.e. each day, each two days, etc. (in vector form)
So, if you want to extract precipitation every day for the full period 2026-2030 between latitudes 39.9218ºN and 52.5286ºN, and between longitudes 0º and 11.25ºE you would have to type:
Precip = ncread(file,’pr’,[1 93 1], [9 10 Inf], [1 1 1]);
[1 93 1] is start, since longitude(1) = 0, latitude(93) = 39.9218, and you start at the first time measurement
[9 10 Inf] is count, since you want to extract data for 9 longitudes (longitude(9) = 11.25), for 10 latitudes (latitude(102) = 52.5286), and you use Inf to indicate you want all time points
[1 1 1] is stride, since you want to extract each longitude point, each latitude point and each time point
I hope this helps.

Simplest Way to Downscaling the GCMs

A good idea on how to downscale the GCMs and how to interpolate GCM data is in Netcdf format as follows:
_________________________

Simplest way to downscaling is these steps:1- download your cmip5 data (is in Netcdf format)2- extract your time series with Netcdf-Extractor there is in: https://agrimetsoft.com3- Save your time series to excel(and historical data should be in excel file)4- calculate this Coefficient c=Mean of Historical data/Mean of GCM(CMIP5 data) data5- multiply all GCM(CMIP5 data) data by c CoefficientYour data downscaled

Source (Click Here)