Created
September 4, 2020 01:57
-
-
Save kaizu/8efca2f51211a8b8e0ed3f42597a1708 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Test spot detection (Generation)\n", | |
"\n", | |
"This is a test suite." | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"!pip uninstall -y scopyon\n", | |
"!pip install git+https://github.com/ecell/scopyon\n", | |
"!pip freeze" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import scopyon" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Set physical parameters." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"config = scopyon.DefaultConfiguration()\n", | |
"config.update(\"\"\"\n", | |
"default:\n", | |
" magnification: 360\n", | |
" detector:\n", | |
" exposure_time: 0.033\n", | |
"\"\"\")" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"pixel_length = config.default.detector.pixel_length / config.default.magnification\n", | |
"L_2 = config.default.detector.image_size[0] * pixel_length * 0.5" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Set the number of processes to enable `multiprocessing`:" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"config.environ.processes = 20" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Prepare for generating inputs." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import numpy\n", | |
"rng = numpy.random.RandomState(123)\n", | |
"N = 1000" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Collect data." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"from pathlib import Path\n", | |
"artifacts = Path(\"./artifacts\")\n", | |
"artifacts.mkdir(parents=True, exist_ok=True)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"with open(artifacts / 'config.yaml', 'w') as f:\n", | |
" f.write(repr(config))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"for i in range(10):\n", | |
" inputs = rng.uniform(-L_2, +L_2, size=(N, 2))\n", | |
" numpy.save(artifacts / f'inputs{i:03d}.npy', inputs)\n", | |
" img, infodict = scopyon.form_image(inputs, config=config, rng=rng, full_output=True)\n", | |
" img.save(str(artifacts / f'image{i:03d}.npy'))\n", | |
" data = numpy.array([(row[2], row[3]) for row in infodict['true_data'].values()])\n", | |
" numpy.save(artifacts / f'data{i:03d}.npy', data)" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.7.5" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment