问题是,即使我的 netcdf 文件包含很多值,我也只获得第一个值作为输出。
import { NetCDFReader } from "netcdfjs";
fetch(
"http://localhost:8000/test/example_files/synthetic_square/dzdata_files/0/0_0.nc",
{ method: "GET" },
)
.then((response) => response.body.getReader().read())
.then((data) => {
let netcdfReader = new NetCDFReader(data.value);
let heights = netcdfReader.getDataVariable("heights");
let allHeights = new Float64Array(heights);
console.log(heights);
console.log(allHeights);
});
这是输出:
Array [ 0.2859144424892198 ]
0: 0.2859144424892198
length: 1
<prototype>: Array []
如何获取所有值?这里可能出了什么问题?
看起来
read()
方法一次只能获取一个值。
如果你尝试这样的事情会怎样?
import { NetCDFReader } from "netcdfjs";
fetch(
"http://localhost:8000/test/example_files/synthetic_square/dzdata_files/0/0_0.nc",
{ method: "GET" },
)
.then((response) => response.body.getReader())
.then((reader) => {
let data;
while (data = reader.read()) {
let netcdfReader = new NetCDFReader(data.value);
let heights = netcdfReader.getDataVariable("heights");
let allHeights = new Float64Array(heights);
console.log(heights);
console.log(allHeights);
}
});