<jupyter_start><jupyter_text>LatticeP.S.: Since ``phantasy`` is still under development, this APIs listed here might be changed.  Import modules/packages<jupyter_code>import phantasy
import matplotlib.pyplot as plt
%matplotlib inline<jupyter_output><empty_output><jupyter_text>Model Machine<jupyter_code>mp = phantasy.MachinePortal(machine='FRIB_VA', segment='LS1FS1')<jupyter_output>[2019-07-25T16:39:06.162] INFO: phantasy.library.operation.core: Load new machine: 'FRIB_VA', segment: 'LS1FS1'
[2019-07-25T16:39:06.165] INFO: phantasy.library.parser.config: Importing 'FRIB_VA' from '/home/tong/Dropbox/FRIB/work/phantasy-project/phantasy-machines/FRIB_VA'
[2019-07-25T16:39:06.167] INFO: phantasy.library.parser.config: Loading machine configuration file: /home/tong/Dropbox/FRIB/work/phantasy-project/phantasy-machines/FRIB_VA/phantasy.ini
[2019-07-25T16:39:06.170] INFO: phantasy.library.operation.lattice: Loading segment: 'LS1FS1'
[2019-07-25T16:39:06.174] WARNING: phantasy.library.operation.lattice: Default UNICORN policy will be applied.
[2019-07-25T16:39:06.176] INFO: phantasy.library.operation.lattice: Loading PV data from CSV/SQLite: /home/tong/Dropbox/FRIB/work/phantasy-project/phantasy-machines/FRIB_VA/ls1fs1/channels.csv
[2019-07-25T16:39:06.178] INFO: phantasy.library.pv.datasource: Set source to be CSV table: channels.csv.
[2019-07-25T16:39:06.357] INFO: phan[...]<jupyter_text>Inspect mp<jupyter_code>mp.inspect_mconf()<jupyter_output>machine config path  : /home/tong/Dropbox/FRIB/work/phantasy-project/phantasy-machines/FRIB_VA/phantasy.ini
----------------------
machine name         : FRIB_VA
----------------------
All valid lattices   : LEBT MEBT LS1 FS1 LS1FS1
----------------------
Section - COMMON
----------------------
root_data_dir        : ~/phantasy_data
segments             : LEBT MEBT LS1 FS1 LS1FS1
default_segment      : LEBT
----------------------
Section - FS1
----------------------
controls_protocol    : EPICS
s_end                : 80.000
config_file          : ./ls1fs1/phantasy.cfg
s_begin              : 0.0
cfs_tag              : phantasy.sys.FS1
cfs_property_names   : *
model                : flame
layout_file          : ./ls1fs1/layout.csv
settings_file        : ./ls1fs1/settings.json
loop                 : 0
cfs_url              : ./ls1fs1/channels.csv
----------------------
Section - LEBT
----------------------
controls_protocol    : EPICS
s_end                : 98.6300005
config_file          [...]<jupyter_text>Load another lattice (segment)<jupyter_code>mp.load_lattice('LS1')
# Please note: 'LS1' maybe not consistent with the real configuration, just for demonstration.
# The configuration for 'LS1' segment should be updated.<jupyter_output>[2019-07-25T16:39:22.048] INFO: phantasy.library.operation.core: Load new machine: 'FRIB_VA', segment: 'LS1'
[2019-07-25T16:39:22.056] INFO: phantasy.library.parser.config: Importing 'FRIB_VA' from '/home/tong/Dropbox/FRIB/work/phantasy-project/phantasy-machines/FRIB_VA'
[2019-07-25T16:39:22.060] INFO: phantasy.library.parser.config: Loading machine configuration file: /home/tong/Dropbox/FRIB/work/phantasy-project/phantasy-machines/FRIB_VA/phantasy.ini
[2019-07-25T16:39:22.063] INFO: phantasy.library.operation.lattice: Loading segment: 'LS1'
[2019-07-25T16:39:22.067] WARNING: phantasy.library.operation.lattice: Default UNICORN policy will be applied.
[2019-07-25T16:39:22.068] INFO: phantasy.library.operation.lattice: Loading PV data from CSV/SQLite: /home/tong/Dropbox/FRIB/work/phantasy-project/phantasy-machines/FRIB_VA/ls1fs1/channels.csv
[2019-07-25T16:39:22.070] INFO: phantasy.library.pv.datasource: Set source to be CSV table: channels.csv.
[2019-07-25T16:39:22.249] INFO: phantasy.l[...]<jupyter_text>List all loaded lattices<jupyter_code>mp.lattice_names
# Current working lattice:
mp.work_lattice_name
# Switch lattice to 'LINAC'
mp.use_lattice('LINAC')
# Current working lattice now:
mp.work_lattice_name<jupyter_output><empty_output><jupyter_text>Currently (``phantasy`` of version 0.5.0), one can operate lattice by explicitly getting working lattice,The future plan is most operation should be able to reach through ``MachinePortal``.  Get working lattice<jupyter_code>lat = mp.work_lattice_conf<jupyter_output><empty_output><jupyter_text>Inspect lattice<jupyter_code>print("Lattice name   : %s" % lat.name)
print("Machine name   : %s" % lat.mname)
print("Lattice groups : %s" % lat.group.keys())
## more to be shown, not final version.<jupyter_output>Lattice name   : LS1
Machine name   : FRIB_VA
Lattice groups : ['BPM', 'HCOR', 'CAV', 'SOL', 'VCOR', 'QUAD', 'PM']<jupyter_text>Locate ElementsTwo methods (to date) could be used to locate elements: ``get_elements()`` and ``next_elements()``.  get_elements()<jupyter_code># Invalid name:
lat.get_elements(name='NOEXISTS')
# name:
lat.get_elements(name='FS1_BMS:DCV_D2662')
# name pattern
lat.get_elements(name=['FS1_B?*D266?', 'LS1_B*DCV*'])
# multiple filters, e.g. type:
lat.get_elements(name=['FS1_B?*D266?', 'LS1_B*DCV*'], type='BPM')
assert lat.get_elements(name=['FS1_B?*D266?', 'LS1_B*DCV*'], type='BPM') == \
       lat.get_elements(name=['FS1_B?*D266?', 'LS1_B*DCV*'], type='BP?')
# with hybrid types:
lat.get_elements(name=['FS1_B?*D266?', 'LS1_B*DCV*'], type=['BPM', 'QUAD'])
# get sub-lattice regarding to s-position range:
lat.get_elements(srange=(10, 11))
# multiple filters with srange:
lat.get_elements(name=['FS1_B?*D266?', 'LS1_B*DCV*'], type=['BPM', 'QUAD'], srange=(154, 155))<jupyter_output><empty_output><jupyter_text>next_elements()<jupyter_code># locate reference element:
ref_elem = lat.get_elements(name='*')[6]
ref_elem
# get the next element of ref_elem, i.e. the first element downstream
lat.next_elements(ref_elem)
# get the last one of the next two elements
lat.next_elements(ref_elem, count=2)
# get all of the next two elements
lat.next_elements(ref_elem, count=2, range='0::1')
# get all of the two elements before ref_elem
lat.next_elements(ref_elem, count=-2, range='0::1')
# get the next two BPM elements of ref_elem,
# return including ref_elem itself
lat.next_elements(ref_elem, count=2, type=['BPM'], ref_include=True, range='0::1')
# with hybrid types
lat.next_elements(ref_elem, count=2, type=['BPM', 'CAV'], range='0::1')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16374920432845322, 'fraction_numerical': 0.0612667091024825, 'mean_word_length': 4.503502626970228, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '55691', 'license': 'MIT', 'n_tokens_mistral': 2514, 'n_tokens_neox': 2293, 'n_words': 444, 'path': '01_Getting_Started/lattice.ipynb', 'repo_name': 'archman/notebook-warehouse', 'size': '6284'}