|
253 | 253 | },
|
254 | 254 | {
|
255 | 255 | "cell_type": "markdown",
|
256 |
| - "metadata": { |
257 |
| - "solution2": "hidden", |
258 |
| - "solution2_first": true |
259 |
| - }, |
| 256 | + "metadata": {}, |
260 | 257 | "source": [
|
261 | 258 | "#### Exercise 1\n",
|
262 | 259 | "Create a workflow to calculate a various powers of ``2`` using two nodes, one for ``IdentityInterface`` with ``iterables``, and one for ``Function`` interface to calculate power of ``2``."
|
|
266 | 263 | "cell_type": "code",
|
267 | 264 | "execution_count": null,
|
268 | 265 | "metadata": {
|
269 |
| - "solution2": "hidden" |
270 |
| - }, |
271 |
| - "outputs": [], |
272 |
| - "source": [ |
273 |
| - "# lets start from the Identity node\n", |
274 |
| - "from nipype import Function, Node, Workflow\n", |
275 |
| - "from nipype.interfaces.utility import IdentityInterface\n", |
276 |
| - "\n", |
277 |
| - "iden = Node(IdentityInterface(fields=['number']), name=\"identity\") \n", |
278 |
| - "iden.iterables = [(\"number\", range(8))]" |
279 |
| - ] |
280 |
| - }, |
281 |
| - { |
282 |
| - "cell_type": "code", |
283 |
| - "execution_count": null, |
284 |
| - "metadata": { |
285 |
| - "solution2": "hidden" |
286 |
| - }, |
287 |
| - "outputs": [], |
288 |
| - "source": [ |
289 |
| - "# the second node should use the Function interface\n", |
290 |
| - "\n", |
291 |
| - "def power_of_two(n):\n", |
292 |
| - " return 2**n\n", |
293 |
| - "\n", |
294 |
| - "# Create Node\n", |
295 |
| - "power = Node(Function(input_names=[\"n\"],\n", |
296 |
| - " output_names=[\"pow\"],\n", |
297 |
| - " function=power_of_two),\n", |
298 |
| - " name='power')" |
299 |
| - ] |
300 |
| - }, |
301 |
| - { |
302 |
| - "cell_type": "code", |
303 |
| - "execution_count": null, |
304 |
| - "metadata": { |
305 |
| - "solution2": "hidden" |
| 266 | + "solution2": "hidden", |
| 267 | + "solution2_first": true |
306 | 268 | },
|
307 | 269 | "outputs": [],
|
308 |
| - "source": [ |
309 |
| - "#and now the workflow\n", |
310 |
| - "wf_ex1 = Workflow(name=\"exercise1\")\n", |
311 |
| - "wf_ex1.connect(iden, \"number\", power, \"n\")\n", |
312 |
| - "res_ex1 = wf_ex1.run()\n", |
313 |
| - "\n", |
314 |
| - "# we can print the results\n", |
315 |
| - "for i in range(8):\n", |
316 |
| - " print(list(res_ex1.nodes())[i].result.outputs)" |
317 |
| - ] |
318 |
| - }, |
319 |
| - { |
320 |
| - "cell_type": "code", |
321 |
| - "execution_count": null, |
322 |
| - "metadata": {}, |
323 |
| - "outputs": [], |
324 | 270 | "source": [
|
325 | 271 | "# write your solution here"
|
326 | 272 | ]
|
|
333 | 279 | },
|
334 | 280 | "outputs": [],
|
335 | 281 | "source": [
|
336 |
| - "# lets start from theIdentity node\n", |
| 282 | + "# lets start from the Identity node\n", |
337 | 283 | "from nipype import Function, Node, Workflow\n",
|
338 | 284 | "from nipype.interfaces.utility import IdentityInterface\n",
|
339 | 285 | "\n",
|
340 |
| - "iden = Node(IdentityInterface(fields=['number']), name=\"identity\") \n", |
| 286 | + "iden = Node(IdentityInterface(fields=['number']), name=\"identity\")\n", |
341 | 287 | "iden.iterables = [(\"number\", range(8))]"
|
342 | 288 | ]
|
343 | 289 | },
|
|
350 | 296 | "outputs": [],
|
351 | 297 | "source": [
|
352 | 298 | "# the second node should use the Function interface\n",
|
353 |
| - "\n", |
354 |
| - "def power_of_two(n):\n", |
355 |
| - " return 2**n\n", |
356 |
| - "\n", |
357 |
| - "# Create Node\n", |
358 |
| - "power = Node(Function(input_names=[\"n\"],\n", |
359 |
| - " output_names=[\"pow\"],\n", |
360 |
| - " function=power_of_two),\n", |
361 |
| - " name='power')" |
362 |
| - ] |
363 |
| - }, |
364 |
| - { |
365 |
| - "cell_type": "code", |
366 |
| - "execution_count": null, |
367 |
| - "metadata": { |
368 |
| - "solution2": "hidden" |
369 |
| - }, |
370 |
| - "outputs": [], |
371 |
| - "source": [ |
372 |
| - "# lets start from theIdentity node\n", |
373 |
| - "from nipype import Function, Node, Workflow\n", |
374 |
| - "from nipype.interfaces.utility import IdentityInterface\n", |
375 |
| - "\n", |
376 |
| - "iden = Node(IdentityInterface(fields=['number']), name=\"identity\") \n", |
377 |
| - "iden.iterables = [(\"number\", range(8))]\n" |
378 |
| - ] |
379 |
| - }, |
380 |
| - { |
381 |
| - "cell_type": "code", |
382 |
| - "execution_count": null, |
383 |
| - "metadata": { |
384 |
| - "solution2": "hidden" |
385 |
| - }, |
386 |
| - "outputs": [], |
387 |
| - "source": [ |
388 |
| - "#and now the workflow\n", |
389 |
| - "wf_ex1 = Workflow(name=\"exercise1\")\n", |
390 |
| - "wf_ex1.connect(iden, \"number\", power, \"n\")\n", |
391 |
| - "res_ex1 = wf_ex1.run()\n", |
392 |
| - "\n", |
393 |
| - "# we can print the results\n", |
394 |
| - "for i in range(8):\n", |
395 |
| - " print(list(res_ex1.nodes())[i].result.outputs)" |
396 |
| - ] |
397 |
| - }, |
398 |
| - { |
399 |
| - "cell_type": "code", |
400 |
| - "execution_count": null, |
401 |
| - "metadata": { |
402 |
| - "solution2": "hidden" |
403 |
| - }, |
404 |
| - "outputs": [], |
405 |
| - "source": [ |
406 |
| - "# the second node should use the Function interface\n", |
407 |
| - "\n", |
408 | 299 | "def power_of_two(n):\n",
|
409 | 300 | " return 2**n\n",
|
410 | 301 | "\n",
|
|
0 commit comments