[R-sig-Geo] summing a variable number of rasters

emorway emorway at engr.colostate.edu
Wed Apr 27 00:36:02 CEST 2011


Hello,

I'm working with precipitation data as estimated by the reflectivity of a
radar 'sweep' (1 complete radar rotation).  Depending upon whether or not
there is a storm in the area, the NOAA radar will automatically speed up or
slow down.  This leads to a variable number of 'sweeps' for any given day. 
The problem I wish to solve is this:  I would like to sum all the sweeps for
each day of the year, keeping in mind that some days may have 140 sweeps and
others may have as many as 350 sweeps).  My initial approach has been to
create a text file containing the names of all the files in the directory
where the ascii grids reside.  I accomplished this from the command line
using the command: "DIR /B /O:n > filenames.txt"  

Each line of the file "filenames.txt" contains a name of a file in the
directory, for example:

KRGX_DPA_20090218_000100_native.asc
KRGX_DPA_20090218_000100_native.prj
KRGX_DPA_20090218_000700_native.asc
KRGX_DPA_20090218_000700_native.prj
KRGX_DPA_20090218_001300_native.asc
KRGX_DPA_20090218_001300_native.prj
KRGX_DPA_20090218_001900_native.asc
KRGX_DPA_20090218_001900_native.prj
KRGX_DPA_20090218_002400_native.asc
KRGX_DPA_20090218_002400_native.prj
.
.

The naming convention is uniform: KRGX_DPA_YYYYMMDD_HHMMSS_native.asc.  So,
to get the daily precipitation, I just need to sum up all of the files that
fall on February 18th, 2009, or February 19th, 2009, etc.  My problem is I
don't know how to code the loop in R to go through each day (and sometimes
there are days with missing/no data) and read in the appropriate rasters and
finally sum them and write out the result, preserving the header
information.  Each raster has the same header information, for example:

NCOLS 131
NROWS 131
XLLCORNER -1704975.0000000
YLLCORNER -5710237.5000000
CELLSIZE 4762.5000000
NODATA_VALUE -999.0000000
-999.0000000 -999.0000000 -999.0000000 -999.0000000 ...
-999.0000000 -999.0000000 -999.0000000 -999.0000000 ...
-999.0000000 -999.0000000 -999.0000000 -999.0000000 ...
-999.0000000 -999.0000000 -999.0000000 -999.0000000 ...
.
.
.

An example of a complete raster file is attached (I haven't checked if there
is
precip on this particular day or not) (the projection file is also
attached).  

Suggestions to help me get started are very much appreciated.
Eric

http://r-sig-geo.2731867.n2.nabble.com/file/n6307555/KRGX_DPA_20090605_173400_native.asc
KRGX_DPA_20090605_173400_native.asc 
http://r-sig-geo.2731867.n2.nabble.com/file/n6307555/KRGX_DPA_20090605_173400_native.prj
KRGX_DPA_20090605_173400_native.prj 


--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/summing-a-variable-number-of-rasters-tp6307555p6307555.html
Sent from the R-sig-geo mailing list archive at Nabble.com.



More information about the R-sig-Geo mailing list