extract portion of netCDF file based on latitide and longitude

19 次查看(过去 30 天)
Hi All,
I need to extract grid data from a nectCDF file. For example, if I provide the spatial extents in terms of latitude and longitudes, how can I extract data for the extent. Lat, long coordinates for the grid are: 9.84N,105.30E,10.02N,105.69E (first two are the coordinates of the lower left and second two are for the upper right). Please see the original (example.nc) netCDF file is attached inside the zipped folder.
I need to extract point data for the above spatila extent using the original file (example.nc)
Thanks in advance for the help.
  2 个评论
David Young
David Young 2014-3-25
Have you looked at the netCDF functions in MATLAB - ncinfo, ncread and so on? If you have, can you be more specific about what the difficulty is? For example, what goes wrong when you call them to read your data?
Damith
Damith 2014-3-26
Hi David,
I need to extract the 'r' value at the lat,long grid point location (4 corners of the rectangle) from the netCDF file.
Thanks,

请先登录,再进行评论。

采纳的回答

Ashish Uthama
Ashish Uthama 2014-3-26
编辑:Ashish Uthama 2014-3-26
Try using ncdisp first to look at the structure of your file. Usually, netcdf files have data defined on 'dimension' variables - lat and lon. So you would first read the lat and lon variables from the file ( ncread ).
>> lon = ncread('/tmp/example.nc','longitude')'
lon =
Columns 1 through 11
104.1250 104.3750 104.6250 104.8750 105.1250 105.3750 105.6250 105.8750 106.1250 106.3750 106.6250
Columns 12 through 13
106.8750 107.1250
>> lat = ncread('/tmp/example.nc','latitude')'
lat =
Columns 1 through 11
8.1250 8.3750 8.6250 8.8750 9.1250 9.3750 9.6250 9.8750 10.1250 10.3750 10.6250
Column 12
10.8750
You would then have to find the indices into lat and lon variables within which your grid lies. Use FIND to locate those indices:
>> latstart = find(lat>9.84,1, 'first')
latstart =
8
>> latend = find(lat<10.02,1, 'last')
latend =
8
Once you get these start/end indices to each of your variable dimension, you can use the partial read capability of NCREAD to read from your 'r' variable.
If you have to do this kind of operation frequently, consider wrapping this logic in a function.
(Note - have a look at the linked functions and examples. Give it a try and post back if you have trouble adapting this idea).
  3 个评论
Ashish Uthama
Ashish Uthama 2014-3-27
Have a look at ncread, and try out the example. Look at the second example in particular, which uses the start, count and stride inputs. You would only need the start and count inputs for your problem. Give it a try and post back if you get stuck.

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by