-
Notifications
You must be signed in to change notification settings - Fork 3
Install Bluesky packages
revision: 2021-02-17
(Linux) Instructions to install bluesky packages into a new conda environment. Also short tests are shown for key packages.
This describes how to install the Python packages needed to run the Bluesky Framework at the Advanced Photon Source. The packages will be installed in a conda environment that is marked with a version corresponding to the APS Run Cycle for which is used. The environment setup file is configured with package and version requirements for the components to be used.
Comparable environment files for Windows and Mac OSX also may be
available. Check the repository directory for availability. For each
of these OS platforms, run the same conda env create -f env_file.yml
from a bash shell to create the conda environment.
- https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html
- https://uoa-eresearch.github.io/eresearch-cookbook/recipe/2014/11/20/conda/
- https://towardsdatascience.com/a-guide-to-conda-environments-bc6180fc533
- Use a conda environment to:
- allow local package customizations
- maintain stability when/if
/APSshare
is updated
- Use base environment: (
/APSshare/miniconda
)- bare minimum number of packages
- intended for use this way
- faster then
/APSshare/anaconda3/x86_64
to do administrative work
- Define
CONDA_ENVIRONMENT
environment variable in~/.bash_aliases
- Note:
/APSshare/anaconda3/Bluesky
requires no installation but cannot be customized by end users.
source /APSshare/miniconda/x86_64/bin/activate
export CONDA_ENVIRONMENT=bluesky_2021_1
After activating the base environment , create the Bluesky environment following these steps:
Use the bash
shell (if not already using it):
bash
Download file environment_2021_1.yml
to a temporary directory (such as
/tmp
on Linux). You only need this file once, to create the conda
environment:
cd /tmp
wget https://raw.githubusercontent.com/BCDA-APS/use_bluesky/main/python_installation/environment_2021_1.yml
The environment file is a text file in YAML format that describes the packages (and versions) that are needed.
Run the installer (takes ~10 minutes or so to finish, usually):
conda env create -f /tmp/environment_2021_1.yml
This will create the new conda environment bluesky_2021_1
.
This is the EPICS PV for the APS Storage Ring Current (the single quotes are needed by the python tests below):
export TEST_PV="'S:SRcurrentAI'"
If you have caget
as a command line tool, then check the PV without
any python code:
(bluesky_2021_1) jemian@wow /tmp $ caget S:SRcurrentAI
S:SRcurrentAI 102.255
This shows a test that the
pyepics
package has been
installed, loads in python, connects with an expected PV, and prints its
value.
(bluesky_2021_1) jemian@wow /tmp $ export TEST_PV="'S:SRcurrentAI'"
(bluesky_2021_1) jemian@wow /tmp $ python -c "import epics; print(epics.caget(${TEST_PV}))"
102.38126717909132
NOTE: In Bluesky, we don't call pyepics
directly but rather use
ophyd
to manage the use of
pyepics
..
Same test, now using ophyd
:
(bluesky_2021_1) jemian@wow /tmp $ python -c "import ophyd; pv= ophyd.EpicsSignal(${TEST_PV}, name='pv'); print(pv.get())"
101.78977005909132
Another ophyd
test, showing more information:
(bluesky_2021_1) jemian@wow /tmp $ python -c "import ophyd; pv= ophyd.EpicsSignal(${TEST_PV}, name='pv'); pv.wait_for_connection(); print(pv.read())"
{'pv': {'value': 101.81930405909134, 'timestamp': 1613588453.43987}}
Reformat
that information with the
apstools
package. (The
test command has become more complex so we'll build it by parts.)
(bluesky_2021_1) jemian@wow /tmp $ cmd="python -c \""
(bluesky_2021_1) jemian@wow /tmp $ cmd+="from apstools.utils import listdevice; "
(bluesky_2021_1) jemian@wow /tmp $ cmd+="import ophyd; "
(bluesky_2021_1) jemian@wow /tmp $ cmd+="pv= ophyd.EpicsSignal(${TEST_PV}, name='pv'); "
(bluesky_2021_1) jemian@wow /tmp $ cmd+="pv.wait_for_connection(); "
(bluesky_2021_1) jemian@wow /tmp $ cmd+="listdevice(pv)"
(bluesky_2021_1) jemian@wow /tmp $ cmd+=\"
(bluesky_2021_1) jemian@wow /tmp $ echo $cmd
python -c "from apstools.utils import listdevice; import ophyd; pv= ophyd.EpicsSignal('S:SRcurrentAI', name='pv'); pv.wait_for_connection(); listdevice(pv)"
(bluesky_2021_1) jemian@wow /tmp $ eval $cmd
==== ================== ==========================
name value timestamp
==== ================== ==========================
pv 102.31602881909133 2021-02-17 13:09:32.439845
==== ================== ==========================
If you are at an APS beamline, then show additional information about the storage ring:
(bluesky_2021_1) jemian@wow /tmp $ cmd="python -c \""
(bluesky_2021_1) jemian@wow /tmp $ cmd+="from apstools.utils import listdevice; "
(bluesky_2021_1) jemian@wow /tmp $ cmd+="from apstools.devices import ApsMachineParametersDevice; "
(bluesky_2021_1) jemian@wow /tmp $ cmd+="aps = ApsMachineParametersDevice(name='aps'); "
(bluesky_2021_1) jemian@wow /tmp $ cmd+="aps.wait_for_connection(); "
(bluesky_2021_1) jemian@wow /tmp $ cmd+="listdevice(aps)"
(bluesky_2021_1) jemian@wow /tmp $ cmd+=\"
(bluesky_2021_1) jemian@wow /tmp $ echo $cmd
python -c "from apstools.utils import listdevice; from apstools.devices import ApsMachineParametersDevice; aps = ApsMachineParametersDevice(name='aps'); aps.wait_for_connection(); listdevice(aps)"
(bluesky_2021_1) jemian@wow /tmp $ eval $cmd
========================================== ===================== ==========================
name value timestamp
========================================== ===================== ==========================
aps_current 102.03240813909133 2021-02-17 13:24:31.439878
aps_lifetime 9.16753387531647 2021-02-17 13:24:31.737008
aps_aps_cycle 2021-1 2021-02-17 13:24:31.863255
aps_machine_status USER OPERATIONS 2021-02-16 08:00:01.341010
aps_operating_mode Delivered Beam 2021-02-16 15:16:39.600022
aps_shutter_permit PERMIT 2021-02-16 15:16:39.601252
aps_fill_number 7.0 2021-02-16 15:16:39.600275
aps_orbit_correction 0.0 2021-01-25 15:01:30.180411
aps_global_feedback On 2021-02-16 15:06:38.076138
aps_global_feedback_h On 2021-02-17 13:24:31.423398
aps_global_feedback_v On 2021-02-17 13:24:31.423398
aps_operator_messages_operators Grodecki, Berg 2021-02-17 07:05:06.113157
aps_operator_messages_floor_coordinator Clay White (2-0101) 2021-02-17 07:51:19.871657
aps_operator_messages_fill_pattern 0+24x1 RHB 2021-01-30 23:37:24.294902
aps_operator_messages_last_problem_message Top-up resumed @11:53 2021-02-17 12:37:16.681556
aps_operator_messages_last_trip_message L1 VSWR trip 2021-02-17 12:37:16.680389
aps_operator_messages_message6 2021-02-17 12:37:31.121230
aps_operator_messages_message7 2021-01-21 18:01:22.341254
aps_operator_messages_message8 2021-01-21 18:01:18.413236
========================================== ===================== ==========================
Test diffractometer support package 'hklpy' is installed:
(bluesky_2021_1) jemian@wow /tmp $ python -c "import gi; gi.require_version('Hkl', '5.0'); import hkl.diffract ; print(hkl.diffract.Diffractometer.__doc__)"
Diffractometer pseudopositioner
.. autosummary::
~calc
~engine
~forward
~inverse
~_energy_changed
~_update_calc_energy
This has a corresponding calculation engine from **hklpy** that does
forward and inverse calculations.
If instantiating a specific diffractometer class such as `E4C`, `E6C`,
neither the `calc_inst` or the `calc_kw` parameters are required.
However, there is the option to either pass in a calculation
instance (with `calc_inst`) or keywords for the default calculation
class (using `calc_kw`) to instantiate a new one.
Parameters
----------
prefix : str
PV prefix for all components
calc_kw : dict, optional
Initializer arguments for the calc class
decision_fcn : callable, optional
The decision function to use when multiple solutions exist for a given
forward calculation. Defaults to arbitrarily picking the first
solution.
read_attrs : list, optional
Read attributes default to all pseudo and real positioners
configuration_attrs : list, optional
Defaults to the UB matrix and energy
parent : Device, optional
Parent device
name : str, optional
Device name
Attributes
----------
calc_class : sub-class of CalcRecip
Reciprocal calculation class used with this diffractometer.
If None (as in `hkl.diffract.Diffractometer`, `calc_inst` must be
specified upon initialization.
See Also
--------
:class:`hkl.diffract.E4CH`
:class:`hkl.diffract.E4CV`
:class:`hkl.diffract.E6C`
:class:`hkl.diffract.K4CV`
:class:`hkl.diffract.K6C`
:class:`hkl.diffract.Med2p3`
:class:`hkl.diffract.Petra3_p09_eh2`
:class:`hkl.diffract.SoleilMars`
:class:`hkl.diffract.SoleilSiriusKappa`
:class:`hkl.diffract.SoleilSiriusTurret`
:class:`hkl.diffract.SoleilSixs`
:class:`hkl.diffract.SoleilSixsMed1p2`
:class:`hkl.diffract.SoleilSixsMed2p2`
:class:`hkl.diffract.TwoC`
:class:`hkl.diffract.Zaxis`
In case you want to remove the conda environment (such as for reinstall):
conda deactivate
conda env remove -n ${CONDA_ENVIRONMENT}