在 R 中读取和绘制 .raw 文件数据

问题描述

我有包含气候数据的 .raw 文件数据。数据是由其他人(不是我)预处理的。

这是其他软件绘制的正确图像。

enter image description here

现在我想在 R 中绘制和重新分析数据。

我已经根据我在此处和其他地方找到的答案尝试了以下代码

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))

我得到了这个。

enter image description here

所以我回去检查我读到的数据。我发现我导入的数据不是数值。它看起来像这样:

> 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"

我也尝试过这样修改代码

> 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"

但是还是不行,因为数据的值应该在0.0到0.3之间,而不是2.25e+307或者00 00 c0 7f。

所以我的问题是如何正确导入 .raw 文件数据。

在此先感谢您的帮助。将不胜感激!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)