2

I have .raw file data which contained the climate data. The data was pre-processed by other people (not me).

This is the correct image plotted by other software.

enter image description here

Now I want to plot and re-analyze the data in R.

I have tried the code below based on answers I have found here and elsewhere:

image_width=961
image_height=481

library(hexView)

raw_image <- readRaw("D:/IDL/boa/sst_20200621-GRAD_MAG.raw")
image_matrix <- matrix(raw_image$fileRaw, nrow = image_height, ncol = image_width, byrow = TRUE)
plot(as.raster(image_matrix))

And I got this.

enter image description here

So I back to check the data I read. I found that the data I import isn't numerical values. It looks like this:

> str(raw_image)
List of 10
 $ width  : NULL
 $ offset : num 0
 $ nbytes : num 1848964
 $ fileRaw: raw [1:1848964] 00 00 c0 7f ...
 $ fileNum: NULL
 $ machine: chr "hex"
 $ type   : chr "char"
 $ size   : num 1
 $ endian : chr "little"
 $ signed : logi TRUE
 - attr(*, "class")= chr "rawBlock"

I also tried to modify the code like this:

> raw_image <- readRaw("D:/IDL/boa/sst_20200621-GRAD_MAG.raw", human="real")
> str(raw_image)
List of 10
 $ width  : NULL
 $ offset : num 0
 $ nbytes : num 1848964
 $ fileRaw: raw [1:1848964] 00 00 c0 7f ...
 $ fileNum: num [1:231120] 2.25e+307 2.25e+307 2.25e+307 2.25e+307 2.25e+307 ...
 $ machine: chr "hex"
 $ type   : chr "real"
 $ size   : num 8
 $ endian : chr "little"
 $ signed : logi TRUE
 - attr(*, "class")= chr "rawBlock"

But it still not work, because the value of the data should be between 0.0 to 0.3, not 2.25e+307 or 00 00 c0 7f.

So my question is how to correctly import the .raw file data.

Thanks in advance for any help. It will be much appreciated!

Sean Wu
  • 21
  • 2

0 Answers0