質問編集履歴
1
補足説明を加えました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
pythonshellというライブラリを使って、Node.jsからpythonを実行しようとしています
|
6
6
|
|
7
|
-
そして、python上で求めた変数をNode.js上で表示させ思っています
|
7
|
+
そして、python上で求めた変数をNode.js上で表示させたいと思っています
|
8
8
|
|
9
9
|
### 発生している問題・エラーメッセージ
|
10
10
|
|
@@ -24,28 +24,212 @@
|
|
24
24
|
|
25
25
|
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
27
|
+
TypeError: self.stderrParser is not a function
|
28
|
+
|
29
|
+
at /Users/admin/Desktop/ws-v/node_js/node_modules/python-shell/index.js:302:42
|
30
|
+
|
31
|
+
at Array.forEach (<anonymous>)
|
32
|
+
|
33
|
+
at PythonShell.recieveInternal (/Users/admin/Desktop/ws-v/node_js/node_modules/python-shell/index.js:298:15)
|
34
|
+
|
35
|
+
at PythonShell.receiveStderr (/Users/admin/Desktop/ws-v/node_js/node_modules/python-shell/index.js:282:21)
|
36
|
+
|
37
|
+
at Socket.<anonymous> (/Users/admin/Desktop/ws-v/node_js/node_modules/python-shell/index.js:100:18)
|
38
|
+
|
39
|
+
at emitOne (events.js:116:13)
|
40
|
+
|
41
|
+
at Socket.emit (events.js:211:7)
|
42
|
+
|
43
|
+
at addChunk (_stream_readable.js:263:12)
|
44
|
+
|
45
|
+
at readableAddChunk (_stream_readable.js:250:11)
|
46
|
+
|
47
|
+
at Socket.Readable.push (_stream_readable.js:208:10)
|
48
|
+
|
49
|
+
```
|
50
|
+
|
51
|
+
Node.js
|
52
|
+
|
53
|
+
```
|
54
|
+
|
55
|
+
var {PythonShell} = require('python-shell');
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
var shell = new PythonShell('pysawit.py',{
|
60
|
+
|
61
|
+
mode: 'run',
|
62
|
+
|
63
|
+
scriptPath: './',
|
64
|
+
|
65
|
+
args: ['-i',"/Users/admin/Desktop/ws-v/python/examples/ini.txt", '-o',"/Users/admin/Desktop/ws-v/python/examples/ini.txt",'-n',22]
|
66
|
+
|
67
|
+
});
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
// facade.pyからの返事を待機
|
72
|
+
|
73
|
+
shell.on('message', data => {
|
74
|
+
|
75
|
+
// データを表示
|
76
|
+
|
77
|
+
console.log(data.result);
|
78
|
+
|
79
|
+
});
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
// 入力を終了
|
84
|
+
|
85
|
+
shell.end();
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
```
|
90
|
+
|
91
|
+
Python
|
92
|
+
|
93
|
+
```
|
94
|
+
|
95
|
+
def output_dailyrun(self, initialize=False):
|
96
|
+
|
97
|
+
"""
|
98
|
+
|
99
|
+
Prepare the list of daily model output, then retrieve and store their results.
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
# Arguments
|
104
|
+
|
105
|
+
initialize (bool): `True` to initialize the output dictionry, else
|
106
|
+
|
107
|
+
`False` to retrieve and store model output results in dictionary
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
# Returns
|
112
|
+
|
113
|
+
None:
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
"""
|
118
|
+
|
119
|
+
out = self.out
|
120
|
+
|
121
|
+
ops = self.model
|
122
|
+
|
123
|
+
if not initialize:
|
124
|
+
|
125
|
+
# 1. get results for daily properties:
|
126
|
+
|
127
|
+
ag_growth = ops.parts.pinnae.growth + ops.parts.rachis.growth + ops.parts.trunk.growth
|
128
|
+
|
129
|
+
veg_growth = ag_growth + ops.parts.roots.growth
|
130
|
+
|
131
|
+
out['age'] = ops.treeage
|
132
|
+
|
133
|
+
out['tmin'] = ops.daytmin
|
134
|
+
|
135
|
+
out['tmax'] = ops.daytmax
|
136
|
+
|
137
|
+
out['totalrad'], out['directrad'], out['diffuserad'] = ops.dayrad
|
138
|
+
|
139
|
+
out['wind'] = ops.daywind
|
140
|
+
|
141
|
+
out['rain'] = ops.dayrain
|
142
|
+
|
143
|
+
out['netrain'] = ops.netrain
|
144
|
+
|
145
|
+
out['ambientCO2'] = ops.co2ambient
|
146
|
+
|
147
|
+
out['LAI'] = ops.lai
|
148
|
+
|
149
|
+
out['pinnae'] = ops.parts.pinnae.weight
|
150
|
+
|
151
|
+
out['rachis'] = ops.parts.rachis.weight
|
152
|
+
|
153
|
+
out['trunk'] = ops.parts.trunk.weight
|
154
|
+
|
155
|
+
out['roots'] = ops.parts.roots.weight
|
156
|
+
|
157
|
+
out['male'] = ops.parts.maleflo.weight
|
158
|
+
|
159
|
+
out['female'] = ops.parts.femaflo.weight
|
160
|
+
|
161
|
+
out['bunches'] = ops.parts.bunches.weight
|
162
|
+
|
163
|
+
out['flowersex'] = ops.flowersex
|
164
|
+
|
165
|
+
out['VDM'] = ops.vdmwgt
|
166
|
+
|
167
|
+
out['TDM'] = ops.tdmwgt
|
168
|
+
|
169
|
+
out['assim_photosyn'] = ops.dayassim
|
170
|
+
|
171
|
+
out['assim_maint'] = ops.assim4maint
|
172
|
+
|
173
|
+
out['assim_growth'] = ops.assim4growth
|
174
|
+
|
175
|
+
out['assim_gen'] = ops.assim4gen
|
176
|
+
|
177
|
+
out['VDM_growth'] = ag_growth
|
178
|
+
|
179
|
+
out['TDM_growth'] = veg_growth
|
180
|
+
|
181
|
+
out['yield'] = ops.bunchyield
|
182
|
+
|
183
|
+
out['trunk_hgt'] = ops.trunkhgt
|
184
|
+
|
185
|
+
out['rootdepth'] = ops.rootdepth
|
186
|
+
|
187
|
+
out['rootzone_VWC'] = ops.rootwater.vwc
|
188
|
+
|
189
|
+
# out['rootzone_pF'] = ops.rootwater.pF
|
190
|
+
|
191
|
+
out['waterstress'] = ops.waterstresses.crop
|
192
|
+
|
193
|
+
out['actual_E'] = ops.aet.soil
|
194
|
+
|
195
|
+
out['actual_T'] = ops.aet.crop
|
196
|
+
|
197
|
+
out['pot_T'] = ops.dayet.crop
|
198
|
+
|
199
|
+
# out['runoff'] = ops.runoff
|
200
|
+
|
201
|
+
# add soil layers output to the list
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
# オブジェクトを作成
|
206
|
+
|
207
|
+
response = {"result": ops.rootwater.vwc}
|
208
|
+
|
209
|
+
# JSON文字列にして出力
|
210
|
+
|
211
|
+
print(json.dumps(response))
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
```
|
216
|
+
|
217
|
+
pythonのプログラムは長いので省略しています。
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
###試したこと
|
224
|
+
|
225
|
+
Node.jsのファイルとpythonのファイルは同じ階層にあって
|
226
|
+
|
227
|
+
python pysawit.py run -i "/Users/admin/Desktop/ws-v/node_js/python/examples/ini.txt" -o "/Users/admin/Desktop/ws-v/node_js/python/examples/output.txt" -n 22 で実行できます。
|
228
|
+
|
229
|
+
要するに、上のスクリプトをNode.jsで実行してpythonで求めた変数をNode.jsに送信して表示させたいのです。
|
230
|
+
|
231
|
+
情報が少なくて大変困っています。
|
232
|
+
|
233
|
+
下手な質問で申し訳ありませんが、どうか、ご指摘の方よろしくお願いします。
|
234
|
+
|
235
|
+
もう少し簡単なやり方があれば教えていただけるとありがたいです。
|