基于给定lat和long的一个位置提取netcdf pr

时间:2018-04-17 21:48:15

标签: matlab netcdf coordinate

我正在使用MATLAB从netcdf文件中为特定的lat和long坐标提取整个时间段的pr变量。

我的位置有lat = 36和long = 9.15。 netcdf文件的纬度矩阵为453 X 453,经度矩阵为453 X 453。

变量:

lon              
       Size:       453x453
       Dimensions: x,y
       Datatype:   double
       Attributes:
                   standard_name = 'longitude'
                   long_name     = 'longitude'
                   units         = 'degrees_east'
lat              
       Size:       453x453
       Dimensions: x,y
       Datatype:   double
       Attributes:
                   standard_name = 'latitude'
                   long_name     = 'latitude'
                   units         = 'degrees_north'
time             
       Size:       1826x1
       Dimensions: time
       Datatype:   double
       Attributes:
                   standard_name = 'time'
                   units         = 'days since 1949-12-01'
                   calendar      = 'gregorian'
                   bounds        = 'time_bnds'
                   axis          = 'T'
                   long_name     = 'time'
pr               
       Size:       453x453x1826
       Dimensions: x,y,time
       Datatype:   single
       Attributes:
                   _FillValue    = 1.000000020040877e+20
                   grid_mapping  = 'Lambert_Conformal'
                   standard_name = 'precipitation_flux'
                   long_name     = 'precipitation'
                   units         = 'kg m-2 s-1'
                   cell_methods  = 'time: mean'
                   coordinates   = 'lat lon'

现在......我想找到netcdf文件的纬度和经度矩阵中最接近我的实际纬度和长坐标的点。

我是这样做的:

d = (mylat-Latnetcdf).^2+(mylong-Longnetcdf).^2; 
[~, ind] = min(d(:)); 
resultlat = lat(ind); %// use that index to obtain the result
resultlong = long(ind);

...这会返回ind = 50049。

...然后当我尝试使用以下方法从文件中提取pr变量时:

ncread(netcdfname,'pr', [50049,50049, 1], [1 1 inf]);

...它返回错误:

Error using netcdflib
The NetCDF library encountered an error during execution of 'getVarsFloat' function - 'Index exceeds dimension
bound (NC_EINVALCOORDS)'.

Error in netcdf.getVar (line 136)
    data = netcdflib(funcstr,ncid,varid,varargin{:});

Error in internal.matlab.imagesci.nc/read (line 635)
                data  = netcdf.getVar(gid, varid, ...

Error in ncread (line 58)
vardata = ncObj.read(varName, varargin{:});

1 个答案:

答案 0 :(得分:0)

来自bash中的命令行:

SELECT ad_media.ad_media_id, ad_media.ad_id 
FROM ad_media 
INNER JOIN action_states ON action_states.ad_id = ad_media.ad_id
INNER JOIN ads ON ads.ad_id = action_states.ad_id
LEFT JOIN ad_params ON ad_media.ad_id = ad_params.ad_id
WHERE action_states.state = 'reg'   
AND action_states.action_id = '1' 
AND action_states.timestamp::DATE BETWEEN '2018-04-17' AND '2018-04-17'
AND ads.category = '2010' AND ads.name = 'joe';