Skip to content

Commit

Permalink
Merge pull request #7 from ZLLentz/psp-merge
Browse files Browse the repository at this point in the history
Package PSP with PyCA
  • Loading branch information
ZLLentz authored Dec 6, 2017
2 parents 6c6cc57 + dfb94b6 commit 54602a7
Show file tree
Hide file tree
Showing 20 changed files with 2,522 additions and 93 deletions.
7 changes: 4 additions & 3 deletions conda-recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ requirements:
- epics-base {{ EPICS }}*
- numpy {{ NPY_VER }}*

tests:
import:
pyca
test:
imports:
- pyca
- psp

about:
home: https://github.com/slaclab/pyca
Expand Down
192 changes: 192 additions & 0 deletions doc/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
# Makefile for Sphinx documentation
#

# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
PAPER =
BUILDDIR = build

# User-friendly check for sphinx-build
ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1)
$(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/)
endif

# Internal variables.
PAPEROPT_a4 = -D latex_paper_size=a4
PAPEROPT_letter = -D latex_paper_size=letter
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source
# the i18n builder cannot share the environment and doctrees with the others
I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source

.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest coverage gettext

help:
@echo "Please use \`make <target>' where <target> is one of"
@echo " html to make standalone HTML files"
@echo " dirhtml to make HTML files named index.html in directories"
@echo " singlehtml to make a single large HTML file"
@echo " pickle to make pickle files"
@echo " json to make JSON files"
@echo " htmlhelp to make HTML files and a HTML help project"
@echo " qthelp to make HTML files and a qthelp project"
@echo " applehelp to make an Apple Help Book"
@echo " devhelp to make HTML files and a Devhelp project"
@echo " epub to make an epub"
@echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
@echo " latexpdf to make LaTeX files and run them through pdflatex"
@echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx"
@echo " text to make text files"
@echo " man to make manual pages"
@echo " texinfo to make Texinfo files"
@echo " info to make Texinfo files and run them through makeinfo"
@echo " gettext to make PO message catalogs"
@echo " changes to make an overview of all changed/added/deprecated items"
@echo " xml to make Docutils-native XML files"
@echo " pseudoxml to make pseudoxml-XML files for display purposes"
@echo " linkcheck to check all external links for integrity"
@echo " doctest to run all doctests embedded in the documentation (if enabled)"
@echo " coverage to run coverage check of the documentation (if enabled)"

clean:
rm -rf $(BUILDDIR)/*

html:
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."

dirhtml:
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."

singlehtml:
$(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
@echo
@echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."

pickle:
$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
@echo
@echo "Build finished; now you can process the pickle files."

json:
$(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
@echo
@echo "Build finished; now you can process the JSON files."

htmlhelp:
$(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
@echo
@echo "Build finished; now you can run HTML Help Workshop with the" \
".hhp project file in $(BUILDDIR)/htmlhelp."

qthelp:
$(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
@echo
@echo "Build finished; now you can run "qcollectiongenerator" with the" \
".qhcp project file in $(BUILDDIR)/qthelp, like this:"
@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/PSP.qhcp"
@echo "To view the help file:"
@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/PSP.qhc"

applehelp:
$(SPHINXBUILD) -b applehelp $(ALLSPHINXOPTS) $(BUILDDIR)/applehelp
@echo
@echo "Build finished. The help book is in $(BUILDDIR)/applehelp."
@echo "N.B. You won't be able to view it unless you put it in" \
"~/Library/Documentation/Help or install it in your application" \
"bundle."

devhelp:
$(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
@echo
@echo "Build finished."
@echo "To view the help file:"
@echo "# mkdir -p $$HOME/.local/share/devhelp/PSP"
@echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/PSP"
@echo "# devhelp"

epub:
$(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
@echo
@echo "Build finished. The epub file is in $(BUILDDIR)/epub."

latex:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo
@echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
@echo "Run \`make' in that directory to run these through (pdf)latex" \
"(use \`make latexpdf' here to do that automatically)."

latexpdf:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo "Running LaTeX files through pdflatex..."
$(MAKE) -C $(BUILDDIR)/latex all-pdf
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."

latexpdfja:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo "Running LaTeX files through platex and dvipdfmx..."
$(MAKE) -C $(BUILDDIR)/latex all-pdf-ja
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."

text:
$(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
@echo
@echo "Build finished. The text files are in $(BUILDDIR)/text."

man:
$(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
@echo
@echo "Build finished. The manual pages are in $(BUILDDIR)/man."

texinfo:
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
@echo
@echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo."
@echo "Run \`make' in that directory to run these through makeinfo" \
"(use \`make info' here to do that automatically)."

info:
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
@echo "Running Texinfo files through makeinfo..."
make -C $(BUILDDIR)/texinfo info
@echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo."

gettext:
$(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
@echo
@echo "Build finished. The message catalogs are in $(BUILDDIR)/locale."

changes:
$(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
@echo
@echo "The overview file is in $(BUILDDIR)/changes."

linkcheck:
$(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
@echo
@echo "Link check complete; look for any errors in the above output " \
"or in $(BUILDDIR)/linkcheck/output.txt."

doctest:
$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
@echo "Testing of doctests in the sources finished, look at the " \
"results in $(BUILDDIR)/doctest/output.txt."

coverage:
$(SPHINXBUILD) -b coverage $(ALLSPHINXOPTS) $(BUILDDIR)/coverage
@echo "Testing of coverage in the sources finished, look at the " \
"results in $(BUILDDIR)/coverage/python.txt."

xml:
$(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml
@echo
@echo "Build finished. The XML files are in $(BUILDDIR)/xml."

pseudoxml:
$(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml
@echo
@echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml."
93 changes: 93 additions & 0 deletions doc/source/advanced.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
Advanced Uses
=============
While many of the use cases for this module will end with simple
:func:`.put` and :func:`.get` calls, **PSP** supports a number of
higher level functions to support a number of use cases.

Monitoring
^^^^^^^^^^
Often times the user may want to keep track of how a PV's value changes over
time. The :class:`.Pv` has a few internal methods that make this easy. Once the
PV is initialized, the most recent value can be quickly accessed from the
:attr:`.Pv.value`. Now if the object is unmonitored, this will only be updated
by a ``get`` call. While refreshing the channel information this way once or
twice in a script is fine, repeated calls can be cumbersome. This is where
monitor comes in. While the PV is actively being monitored, the value attribute
will be actively updated by an internal callback function. This mode of
operation can either be specified at the time of object initialization or later
by calling :meth:`monitor_start`. For example, here is a quick script that
looks at a PV and checks one second later if the value changed

.. code-block:: python
import time
from psp import PV
mon_pv = PV(<pvname>,monitor=True)
initial = mon_pv.value
time.sleep(5.0)
if not initial == mon_pv.value:
print 'PV value has changed!'
Sometimes checking the current value of the PV isn't enough, instead the
history of the PV needs to be tracked. Each PV object has a
:attr:`.Pv.monitor_append` attribute that determines how this data is stored.
In the default mode, as shown above, the ``value`` is overwritten and the class
moves on, but in the appending mode, each update is stored in the
:attr:`.Pv.values`. This allows the user to quickly keep track of rapidly moving PV.

.. code-block:: python
import time
from psp import PV
mon_pv = PV(<pvname>)
mon_pv.monitor_start(monitor_append=True)
time.sleep(5.0) #Wait for changes
if len(mon_pv.values) > 1:
print 'This PV has updated %s times' % len(mon_pv.values)
The class even has some built-in functionality to return some basic statistics
of the class with the :meth:`.Pv.monitor_get`. For most scalar values, this is
a perfect way to monitor an EPICS channel, but for large arrays and images, it
is prudent to not monitor for too long as it easy to put a large burden on
system memory.

User-Defined Callbacks
^^^^^^^^^^^^^^^^^^^^^^
Sometimes just keeping track of the PV value isn't enough, instead an action
should be performed whenever the PV updates or connects. Callbacks allow a
simple way to handle this all behind the scenes for you. The callback function
should accept one argument, see the :meth:`.Pv.add_connection_callback` or
:meth:`.Pv.add_monitor_callback` methods for more information about what this
arguement indicates. A quick example of this feature can be seen below:

.. code-block:: python
def updated(e):
print 'The PV has updated`
from psp import PV
mon_pv = PV(<pvname>)
cb_id = mon_pv.add_monitor_callback(updated) #The function returns an id
#for the callback
>>> mon_pv.monitor_start()
>>> mon_pv.put(5)
'The PV has updated'
>>> mon_pv.del_monitor_callback(cb_id) #Remove the callback
>>> mon_pv.put(2)
>>> #Print not executed, because callback was removed
There are two dictionaries ``mon_cbs`` and ``con_cbs`` where all of the
callbacks are kept in case you lose track of an id. While this example is
trivial, it is easy to imagine how this can be quickly adapted to make complex
control loops without the pain of creating threads to simultaneously watch PV
values.


Loading

0 comments on commit 54602a7

Please sign in to comment.