[R-sig-Geo] Spatial rainfall or precipitation data

Matthew Landis landis at isciences.com
Tue Sep 13 19:43:42 CEST 2011



On 9/13/2011 10:57 AM, luca candeloro wrote:
> Hi everybody,
> I'm looking for satellite data about rainfall or precipitation...
> I think *
> ftp://disc2.nascom.nasa.gov/data/s4pa/TRMM_L3/TRMM_3B42_daily/2010/001/3B42_daily.2010.01.02.6.bin
> * could be what I'm looking for (as it's accessible via ftp, is 0.25°
> spatial resolution and daily temporal resolution), but I can't get correct
> values from this binary file (I read the documentation about data structure,
> it speaks about two-byte integer, but I can't understand how to get values).
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

-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~
Matthew Landis, Ph.D.
Research Scientist
ISciences, LLC
61 Main St. Suite 200
Burlington VT 05401
802.864.2999
~~~~~~~~~~~~~~~~~~~~~~~~~~



More information about the R-sig-Geo mailing list