Re: reading ascii grid data

From: Adam Phillips <asphilli_at_nyahnyahspammersnyahnyah>
Date: Mon, 20 Mar 2006 12:25:29 -0700

Hello all,

This was worked out offline but I thought some of you might be
interested in the solution. Jeff had data on a regular .125 x .125
degree grid covering only the northeast US (and not Ontario/western
Quebec or the Atlantic Ocean)... Thus, the ascii file only contained
grid points that had data, which was a complication.

The simplest approach was to set up a new array that spans from
min(lat)->max(lat) and from min(lon) to max(lon), complete with lat/lon
coordinate variables. One could then use coordinate subscripting to
place the data in the final array. (This approach will result in areas
that will be set to _FillValue, western Quebec for instance...)

Note that the method below wouldn't have worked if the grid was not
easily defined using the min/max lats/lons and the grid intervals.

a = asciiread("hadcm3_A1_1961.out",(/3862,3/),"float")
lats = a(:,0)
lons = a(:,1)

numlat = floattointeger(((max(lats)-min(lats))/.125)+1) ; # of lat pts
numlon = floattointeger(((max(lons)-min(lons))/.125)+1) ; # of lon pts
lat = fspan(min(lats),max(lats),numlat) ; create 1D lat array
lon = fspan(min(lons),max(lons),numlon) ; create 1D lon array

lat_at_units = "degrees_north"
lon_at_units = "degrees_east"
lat!0 = "lat"
lat&lat = lat
lon!0 = "lon"
lon&lon = lon

finarr = new((/dimsizes(lat),dimsizes(lon)/),"float",-999.)
finarr!0 = "lat"

finarr&lat = lat
finarr!1 = "lon"
finarr&lon = lon

do gg = 0,dimsizes(a(:,0))-1 ; loop thru each line, use
coordinate ; subscripting to place data in finarr
    finarr({a(gg,0)},{a(gg,1)}) = (/ a(gg,2) /)
end do


Jeff Van Dorn wrote:
> Hello,
> I have an ascii file in the form of:
> lat lon var
> 38.0625 -75.4375 0.315
> 38.0625 -75.5625 0.284
> 38.0625 -75.6875 0.260
> 38.0625 -75.8125 0.268
> and I'm first trying to read in this data using asciiread and then
> hopefully be able to produce a contour plot against a map; however I'm
> stuck at how to properly extract the latitude/longitudes from the
> file. I've seen the example at:
> however, for that instance the data being read appears to be a nice
> rectangular grid (e.g., 240 by 89, which equals the number of lines in
> the data file, 240x89 = 2130). I'm wondering is it possible to read in
> a grid that isn't a rectangular grid? For my case, I have 3862 lat/lon
> points (or lines in my file) to read in; however, in that set there are
> 80 unique lats and 110 unique lons, which I believe would then make a
> rectangular grid of 8800 total lat/lons. In order to do a similar
> approach to the example, do I need to create bogus values for the
> lat/lon points that aren't in my original set of data and then read in
> the entire 8800 points, or is there an alternative method to reading
> this data in so that I can produce a contour plot using the lat/lons in
> my file?
> Thanks for any help or suggestions.
> Jeff Van Dorn
> Atmos Research
> _______________________________________________
> ncl-talk mailing list

Adam Phillips			   
National Center for Atmospheric Research   tel: (303) 497-1726
ESSL/CGD/CAS                               fax: (303) 497-1333
P.O. Box 3000				
Boulder, CO 80307-3000
ncl-talk mailing list
Received on Mon Mar 20 2006 - 12:25:29 MST

This archive was generated by hypermail 2.2.0 : Wed Mar 29 2006 - 11:52:49 MST