Getting Started

Archive

Getting history data via MEME is very straightforward. There is only one method: meme.archive.get().

>>> import meme.archive
>>> meme.archive.get(["MC00:ASTS:OUTSIDET", "PWR:MCC0:1:SITE"], from_time="1 day ago", to_time="now")
<Results snipped>

You can supply a list of PVs, or just a single PV. The from_time and to_time parameters can take strings of the form “1 day ago”, python datetime objects, or a mix:

>>> from datetime import datetime
>>> import meme.archive
>>> downtime_2016 = datetime(2016, 12, 20)
>>> meme.archive.get("GDET:FEE1:241:ENRC", from_time="1 year ago", to_time=downtime_2016)
<Results snipped>

The Archive Module Documentation provides details about the format that history data is returned as, and other useful tidbits.

Model

Interacting with the model takes an object oriented approach. To get model data, first make an instance of the meme.model.Model class, then call its methods to get the data you are interested in:

>>> from meme.model import Model
>>> m = Model()
>>> m.get_rmat('BPMS:LI24:801')
<6x6 np.ndarray>

The model module works this way to keep things fast: usually, its faster to get the full machine model once, then refer to it repeatedly, than it is to repeatedly ask the model service for small bits of information. Whenever you make a new instance of Model, you’ll get the latest data from the service.

>>> from meme.model import Model
>>> m = Model()
>>> for bpm in bpm_list:
>>>   r = m.get_rmat(from_device='BPM:IN20:221', to_device=bpm)

Note that in the above example, you don’t make a new Model inside the for loop. That would make you ask the service for the model data on every iteration of the loop, which would be very slow.

If you need to refresh the data for an existing Model instance, you can do that by calling meme.model.Model.refresh_all():

>>> from meme.model import Model
>>> m = Model()
>>> twiss = m.get_twiss('QUAD:LTU1:440')
>>> m.refresh_all() #The beam energy has changed and you want new model data.
>>> new_twiss = m.get_twiss('QUAD:LTU1:440')

The various get methods in the Model class are pretty flexible. You can input a list of names, a single name, etc. See the Model documentation for all the details.

Names

Getting lists of PV names is easy. If you know how to use aidalist, you know how to use meme.names.list_pvs():

>>> import meme.names
>>> all_bpm_tmit_pvs = meme.names.list_pvs("BPMS:%:%:TMIT")
<list of BPM TMIT PVs>

The directory service is very powerful, and lets you do fancy queries with sorting and filtering. You can specify a tag to search for, like an LCLS region:

>>> import meme.names
>>> L2_xcor_bacts = meme.names.list_pvs("XCOR:%:BACT", tag="L2", sort_by="z")
<list of XCOR BACT values for L2>

You can also get device names, or element names (aka MAD names), using the meme.names.list_devices() and meme.names.list_elements() functions. They take the same arguments as list_pvs(). To get a list of all BPM devices in the ‘BSYLTU’ line:

>>> import meme.names
>>> bsy_ltu_bpms = meme.names.list_devices("BPMS:%", tag="BSYLTU", sort_by="z")
['BPMS:BSYH:445', 'BPMS:BSYH:465', ...]

For more information about the syntax for searching, and other parameters you can pass to the various list functions, see the Names documentation.