Skip to content
Prev 12779 / 29559 Next

Spatial rainfall or precipitation data

On 9/13/2011 10:57 AM, luca candeloro wrote:
Luca, I haven't used the TRMM binary data specifically, but I've read in 
similar files into R.  It's a little tricky to go from binary data to 
something you can visualize, e.g. with the raster package.  I found that 
there was a fair bit of trial and error.

# This gives a vector of values
trmm.data <- readBin(file(trmm.data.file, open = 'rb'), size = 2, 
endian='little')

# If it looks like nonsense, you might try setting endian to 'swap' or 
'big',  or changing the 'size'

# assign to a raster layer
# The array might have to be transposed to work right
trmm.array <- array(trmm.data, dim = c(1440, 400))

trmm.raster <- raster(trmm.array, xmn = -180, xmx = 180, ymn = -50, ymx 
= 50,
     crs = '+proj=longlat +datum=WGS84 +ellps=WGS84')

plot(trmm.raster)
# If image doesn't look right, you might look into the rotate() and 
flip() functions in the raster package.

Good luck.

M