[R-sig-Geo] Help converting matlab raster to R raster brick

cmundy Craig.Mundy at utas.edu.au
Sat Apr 6 14:23:00 CEST 2013


Hi Mike,

Needed to flip the y axis to get the orientation right. Levelplot() show
images that look like something I expected to see, and in the right part of
the world - all good.  I will need to check the x,y resolution of the
original matlab file, but it is in the right ballpark.

Thanks for the tip.

> test <- readMat("CraigMundy.mat")
> x <- brick(test$data[[2]], xmn = min(test$data[[4]]), xmx =
> max(test$data[[4]]), ymn = min(test$data[[3]]), ymx = max(test$data[[3]])) 
> x <- flip(x, direction="y")
> res(x)
[1] 0.04100 0.03528
> extent(x)
class       : Extent 
xmin        : 146.599 
xmax        : 148.321 
ymin        : -44.3339 
ymax        : -42.5699 



Michael Sumner-2 wrote
> Hi Craig, see the "array" method for ?brick:
> 
>  brick(x, xmn=0, xmx=1, ymn=0, ymx=1, crs=NA
> 
> So, something like
> 
> x <- brick(test$data[[2], xmn = min(test$data[[5]]), ymx =
> max(test$data[[5]]), ymn = min(test$data[[4]]), ymx = max(test$data[[4]]))
> 
> You might need to mess around to get the x/y ranges right, and figure out
> if you need to transpose or do other reorientations. This assumes the
> lon/lat vectors are regular so you should check that.
> 
> Cheers, Mike
> 
> 
> On Thu, Apr 4, 2013 at 9:00 AM, cmundy <

> Craig.Mundy at .edu

> > wrote:
> 
>> Hi All,
>>
>> I have been provided with a .mat file containing a time series of Sea
>> Surface Temperature data (50 x 42 cells with 92 time layers). It was a
>> "Struct" object in Matlab. I can happily import the file in to R using
>> R.matlab, creating a list as follows. My question is how then to convert
>> this to a raster brick?
>>
>> Thanks
>>
>> Craig
>>
>> > library(R.matlab)
>> > test <- readMat("CraigMundy.mat")
>> > str(test)
>> List of 2
>>  $ data :List of 9
>>   ..$ : num [1, 1:92] 734138 734139 734140 734141 734142 ...
>>   ..$ : num [1:50, 1:42, 1:92] 14.4 14.5 15.2 15.3 14.8 ...
>>   ..$ : num [1:50, 1] -44.3 -44.3 -44.3 -44.2 -44.2 ...
>>   ..$ : num [1, 1:42] 147 147 147 147 147 ...
>>   ..$ : num [1, 1] 101
>>   ..$ : chr [1, 1] " SST: 3 Day Composite"
>>   ..$ : num [1, 1] 0
>>   ..$ : num [1, 1] 34.5
>>   ..$ : num [1, 1] 0.44
>>   ..- attr(*, "dim")= int [1:3] 9 1 1
>>   ..- attr(*, "dimnames")=List of 3
>>   .. ..$ : chr [1:9] "Time" "Values" "Lat" "Long" ...
>>   .. ..$ : NULL
>>   .. ..$ : NULL
>>  $ times: chr [1:92, 1] "31-Dec-2009" "01-Jan-2010" "02-Jan-2010"
>> "03-Jan-2010" ...
>>  - attr(*, "header")=List of 3
>>   ..$ description: chr "MATLAB 5.0 MAT-file, Platform: PCWIN64, Created
>> on:
>> Thu Apr 04 11:29:53 2013                                                "
>>   ..$ version    : chr "5"
>>   ..$ endian     : chr "little"
>>
>>
>>
>> > version
>>                _
>> platform       x86_64-w64-mingw32
>> arch           x86_64
>> os             mingw32
>> system         x86_64, mingw32
>> status
>> major          3
>> minor          0.0
>> year           2013
>> month          04
>> day            03
>> svn rev        62481
>> language       R
>> version.string R version 3.0.0 (2013-04-03)
>> nickname       Masked Marvel
>>
>>
>>
>> --
>> View this message in context:
>> http://r-sig-geo.2731867.n2.nabble.com/Help-converting-matlab-raster-to-R-raster-brick-tp7583204.html
>> Sent from the R-sig-geo mailing list archive at Nabble.com.
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> 

> R-sig-Geo@

>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
> 
> 
> 
> -- 
> Michael Sumner
> Hobart, Australia
> e-mail: 

> mdsumner@

> 
> 	[[alternative HTML version deleted]]
> 
> _______________________________________________
> R-sig-Geo mailing list

> R-sig-Geo@

> https://stat.ethz.ch/mailman/listinfo/r-sig-geo





--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Help-converting-matlab-raster-to-R-raster-brick-tp7583204p7583222.html
Sent from the R-sig-geo mailing list archive at Nabble.com.



More information about the R-sig-Geo mailing list