Skip to content

Commit

Permalink
Add some examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
willrogers committed Jul 23, 2021
1 parent 91cf915 commit 2e0b333
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
29 changes: 29 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,35 @@ 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')
>>> # Use the sim by default.
>>> lat.set_default_data_source(pytac.SIM)
>>> # The initial beam position is zero.
>>> lat.get_value('x')
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]
>>> hcor1.set_value('x_kick', 1, units=pytac.ENG)
>>> # Now the x beam position has changed.
>>> lat.get_value('x')
array([0.00240101, 0.00240101, 0.00239875, ..., 0.00240393, 0.00240327,
0.00240327])
>>>
Virtual Accelerator:
--------------------

Expand Down
29 changes: 29 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,35 @@ 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')
>>> # Use the sim by default.
>>> lat.set_default_data_source(pytac.SIM)
>>> # The initial beam position is zero.
>>> lat.get_value('x')
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]
>>> hcor1.set_value('x_kick', 1, units=pytac.ENG)
>>> # Now the x beam position has changed.
>>> lat.get_value('x')
array([0.00240101, 0.00240101, 0.00239875, ..., 0.00240393, 0.00240327,
0.00240327])
>>>
Contents:
=========

Expand Down

0 comments on commit 2e0b333

Please sign in to comment.