[Thread Prev][Thread Next][Index]

Re: [ferret_users] ascii grid format with header, read into ferret, convert to netCDF



Hi Matt,

There are so many permutations, that it seemed easiest to do an entire example.

Here's a dummy file derived from what you provided:

 ncols                  6
 nrows                 4
 xllcorner       588970.54128361004    
 yllcorner       4864497.1359059000    
 cellsize        100.00000   
 NODATA_value   -9999.0000
0.791   0.795   0.792   0.811   0.815   0.822
0.792   0.796   0.794   0.812   0.816   0.824
0.793   0.797   0.796   0.813   0.817   0.826
0.794   0.798   0.798   0.814   0.818   0.828
I'm not sure what to make of the xllcorner/yllcorner values, so I'll just make up my own coordinate system in the lines that follow

Here are Ferret commands to read and display the data in this file:
! set up to read the heading, only
define axis/x=1:6:1 xheading

define grid/x=xheading gheading
columns/grid=gheading/delimiter=" "/var=label,value  my_test_ascii_data.dat
 
! capture the values from the heading as Ferret symbols
list value  ! just fyi
define symbol columns `value[i=1]`

define symbol rows `value[i=2]`
define symbol badflag `value[i=6],prec=9`

! make up a coordinate system for the data 
define axis/x=100:200/npoints=($columns) xcoords
define axis/y=100:200/npoints=($rows) ycoords
define grid/x=xcoords/y=ycoords mygrid

! tell Ferret how to read the data
file/skip=6/var=myvar/columns=($columns)/grid=mygrid my_test_ascii_data.dat
set variable/bad=($badflag) myvar

! read and show the data
shade myvar
And here's the output




On 5/3/2013 3:25 PM, Matthew Cooper wrote:
Hi all,

I am working with ascii grid format data, meaning the first 6 rows of the file is header info, then the grid of data represents the model output at each grid cell (example attached):

 ncols                  347
 nrows                 979
 xllcorner       588970.54128361004     
 yllcorner       4864497.1359059000     
 cellsize        100.00000    
 NODATA_value   -9999.0000

0.79   0.79   0.79   0.81   0.81   0.82   ....1,ncols
0.79   0.79   0.79   0.81   0.81   0.82   ....
0.79   0.79   0.79   0.81   0.81   0.82   ....
0.79   0.79   0.79   0.81   0.81   0.82   ....
.
.
.
nrows,1

So, each value (0.79 for example) represents the precipitation at that 100x100 m grid cell. 

I have gone over the ferret documentation 2.5: Ascii data and there doesn't seem to be information about reading data in this format. For example I have tried:

yes? define axis/x=1:347:1 longax
yes? define axis/y=1:979:1 latax
yes? define grid/x=longax/y=latax gridd
yes? file/var=ppt/grid=gridd ppt_test.asc
yes? sh data
     currently SET data sets:
    1> ./ppt_test.asc  (default)
 name     title                             I         J         K         L         M         N
 PPT      PPT                              1:347     1:2       ...       ...       ...       ...


This isn't right.

I have one of these files for each timestep of the model run. I'd like to read these files into ferret, then stack all of the files into a netcdf file so I can arrange model runs by year, where each netcdf file contains 365 ascii files representing each day of the model run. 

Does ferret have the ability to read and store the header info? Would it be better if I changed the write command in my code to leave out the header info so it just gives a grid of output? 

Thank you in advance! To be clear, my primary question is how to properly read in the data in the format I described (example file attached). If possible, help on converting the batch of files into a netcdf would also be great.

Matt
--
Matt Cooper
M.S. candidate, Water Resources Science
College of Earth, Ocean and Atmospheric Sciences
Oregon State University



[Thread Prev][Thread Next][Index]
Contact Us
Dept of Commerce / NOAA / OAR / PMEL / Ferret

Privacy Policy | Disclaimer | Accessibility Statement