基于python-bridge的python脚本运行环境
环境依赖
- nodejs
- python
- windows平台上自动安装配置好的python,其中包含了netCDF4-python、h5py、gdal等常用的气象和遥感数据处理相关python库。
- mac os、linux等平台上需另外安装配置python环境
使用示例
js代码
(async function () {
var path = require('path')
var Python = require('./index')
var python = new Python({
"searchPaths": [
path.join(__dirname, 'pythonScripts')
]
})
await python.exec('from netCDF4_node import *').catch((err) => {
python.close();
throw err
})
var ncOrHdf5FileName = path.join(__dirname, 'sampleData/FY4A-_AGRI--_N_REGC_1047E_L2-_CTT-_MULT_NOM_20190210073834_20190210074250_4000M_V0001.NC')
var result = await python.eval('readFile("' + ncOrHdf5FileName + '")')
.catch((err) => {
python.close();
throw err
})
console.log(result)
python.close();
})()
输出结果:
Variable {name: "CTT", attributes: Object, dataType: "float32", shape: Array(2), data: Float32Array(3044784), …}
index.js:29
65535
index.js:30
Array(2) [180, 311.4605712890625]