Skip to content

Commit

Permalink
Add some examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
willrogers committed Aug 27, 2020
1 parent 91cf915 commit 7f41d14
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
27 changes: 27 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,33 @@ few cases. For example, the simulator has a number of lattice fields that the
live accelerator doesn't have; and the live machine has a few element fields
that the simulator doesn't.

Example
^^^^^^^

Note that you need an AT lattice that is compatible with Pytac. Some are provided
in ``atip/rings/``, otherwise try running the Matlab function
``atip/rings/create_lattice_matfile.m`` with an AT lattice loaded.

.. code-block::
>>> import pytac
>>> import atip
# Load the DIAD lattice from Pytac.
>>> lat = pytac.load_csv.load('DIAD')
# Load the AT sim into the Pytac lattice.
>>> atip.load_sim.load_from_filepath(lat, 'atip/rings/diad.mat')
# The initial beam position is zero.
>>> lat.get_value('x', data_source=pytac.SIM)
array([0., 0., 0., ..., 0., 0., 0.])
# Get the first horizontal corrector magnet and set its current to 1A.
>>> hcor1 = lat.get_elements('HSTR')[0]
>>> corr1.set_value('x_kick', 1, units=pytac.ENG, data_source=pytac.SIM)
# Now the x beam position has changed.
>>> lat.get_value('x', data_source=pytac.SIM)
array([0.00240101, 0.00240101, 0.00239875, ..., 0.00240393, 0.00240327,
0.00240327])
>>>
Virtual Accelerator:
--------------------

Expand Down
27 changes: 27 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,33 @@ This functionality is not documented here but an explanation of how it works
and how to use it may be found in the ``.rst`` files inside ATIP's ``virtac``
directory.

Example
-------

Note that you need an AT lattice that is compatible with Pytac. Some are provided
in ``atip/rings/``, otherwise try running the Matlab function
``atip/rings/create_lattice_matfile.m`` with an AT lattice loaded.

.. code-block::
>>> import pytac
>>> import atip
# Load the DIAD lattice from Pytac.
>>> lat = pytac.load_csv.load('DIAD')
# Load the AT sim into the Pytac lattice.
>>> atip.load_sim.load_from_filepath(lat, 'atip/rings/diad.mat')
# The initial beam position is zero.
>>> lat.get_value('x', data_source=pytac.SIM)
array([0., 0., 0., ..., 0., 0., 0.])
# Get the first horizontal corrector magnet and set its current to 1A.
>>> hcor1 = lat.get_elements('HSTR')[0]
>>> corr1.set_value('x_kick', 1, units=pytac.ENG, data_source=pytac.SIM)
# Now the x beam position has changed.
>>> lat.get_value('x', data_source=pytac.SIM)
array([0.00240101, 0.00240101, 0.00239875, ..., 0.00240393, 0.00240327,
0.00240327])
>>>
Contents:
=========

Expand Down

0 comments on commit 7f41d14

Please sign in to comment.