Skip to content

Commit

Permalink
Add a simple example
Browse files Browse the repository at this point in the history
  • Loading branch information
tfarago committed Sep 26, 2017
1 parent fbd2f50 commit e04ba94
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
30 changes: 30 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,36 @@ There are numerous examples of how to use *syris* described below which ship
directly with the code. Enjoy!


Usage
-----

The first thing you have to do is to initialize *syris* by the ``syris.init()``
function. After that you only need to do whatever is necessary for your program.
A simple white beam propagation example looks like this:

.. code-block:: python
import matplotlib.pyplot as plt
import numpy as np
import quantities as q
import syris
from syris.physics import propagate
from syris.bodies.simple import make_sphere
from syris.materials import make_henke
syris.init()
energies = np.arange(10, 30) * q.keV
n = 1024
pixel_size = 0.4 * q.um
distance = 2 * q.m
material = make_henke('PMMA', energies)
sample = make_sphere(n, n / 4 * pixel_size, pixel_size, material=material)
image = propagate([sample], (n, n), energies, distance, pixel_size).get()
plt.imshow(image)
plt.show()
Citation
--------

Expand Down
9 changes: 9 additions & 0 deletions docs/source/usage/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,15 @@ X-ray Source Blur
:members:


Simple
------

**simple.py**

.. automodule:: examples.simple
:members:


Trajectory
----------

Expand Down
28 changes: 28 additions & 0 deletions examples/simple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""Simple propagation example."""
import matplotlib.pyplot as plt
import numpy as np
import quantities as q
import syris
from syris.physics import propagate
from syris.bodies.simple import make_sphere
from syris.materials import make_henke
from util import show


def main():
syris.init()
energies = np.arange(10, 30) * q.keV
n = 1024
pixel_size = 0.4 * q.um
distance = 2 * q.m
material = make_henke('PMMA', energies)

sample = make_sphere(n, n / 4 * pixel_size, pixel_size, material=material)
image = propagate([sample], (n, n), energies, distance, pixel_size).get()

show(image)
plt.show()


if __name__ == '__main__':
main()

0 comments on commit e04ba94

Please sign in to comment.