Luca,

The below expands a bit on Matthew's response to get a working example:

library(raster)

# trmm template
trmm <- raster(xmn=0, xmx=360, ymn=-50, ymx=50, ncol=1440, nrow=400)

filename <- '3B42_daily.2010.01.02.6.bin'

# read values
trmm[] <- readBin(filename, 'double', n=576000, size = 4, endian='big')

# normalize (North up, -180..180)
x <- flip(rotate(trmm), 'y')

# write to geotif
x <- writeRaster(x, extension(filename, 'tif'))
plot(x)


or for a bunch of files

trmm <- raster(xmn=0, xmx=360, ymn=-50, ymx=50, ncol=1440, nrow=400)
files <- list.files(pattern='.bin')
for (f in files)  {   # for all files
  trmm[] <- readBin(f, 'double', n=576000, size = 4, endian='big')
  x <- flip(rotate(trmm), 'y')
  x <- writeRaster(x, extension(filename, 'tif'))
}


Robert

On Tue, Sep 13, 2011 at 10:43 AM, Matthew Landis <landis@isciences.com>wrote:

>
>
> 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<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
> ~~~~~~~~~~~~~~~~~~~~~~~~~~
>
>
> ______________________________**_________________
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/**listinfo/r-sig-geo<https://stat.ethz.ch/mailman/listinfo/r-sig-geo>
>

	[[alternative HTML version deleted]]

