Giter Club home page Giter Club logo

apstools's Introduction

apstools

Library of Python tools for use with the Bluesky framework at the APS.

GH tag GH release PyPI conda-forge
tag release PyPi conda-forge
Python version(s) Unit Tests Code Coverage License
Python version Unit Tests & Code Coverage Coverage Status license: ANL

Package Information

item description
author Pete R. Jemian
email [email protected]
copyright 2017-2024, UChicago Argonne, LLC
documentation versions: latest tagged release or development (main branch)
source https://github.com/BCDA-APS/apstools

See also

apstools's People

Contributors

canismarko avatar dependabot[bot] avatar gfabbris avatar mdecarabas avatar mrakitin avatar prjemian avatar tacaswell avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

apstools's Issues

contribution from USAXS: use only scaler channels with EPICS names

Must work with both EpicsScaler and ScalerCH devices

# will become part of APS_BlueSky_tools.devices
def use_EPICS_scaler_channels(scaler):
    """
    configure scaler for only the channels with names assigned in EPICS 
    """
    read_attrs = []
    for ch in scaler.channels.component_names:
        _nam = epics.caget("{}.NM{}".format(scaler.prefix, int(ch[4:])))
        if len(_nam.strip()) > 0:
            read_attrs.append(ch)
    scaler.channels.read_attrs = read_attrs

missing import

running this code:

In [3]:     APS_devices.AD_setup_FrameType(
   ...:         EPICS_PV_prefix["PG3 PointGrey Grasshopper3"], 
   ...:         scheme="DataExchange"
   ...:     )

produces this exception:

~/Apps/BlueSky/lib/python3.6/site-packages/APS_BlueSky_tools/devices.py in AD_setup_FrameType(prefix, scheme)
    840     template = "{}cam1:FrameType{}.{}"
    841     for field, value in db.items():
--> 842         epics.caput(template.format(prefix, "", field), value)
    843         epics.caput(template.format(prefix, "_RBV", field), value)
    844 

NameError: name 'epics' is not defined

BUG: 0.0.21 missing import

APS_BlueSky_tools/devices.py in ApsOperatorMessagesDevice()
     66 class ApsOperatorMessagesDevice(Device):
     67     """general messages from the APS main control room"""
---> 68     operators = Component(EpicsSignalRO, "OPS:message1", string=True)
     69     floor_coordinator = Component(EpicsSignalRO, "OPS:message2", string=True)
     70     fll_pattern = Component(EpicsSignalRO, "OPS:message3", string=True)

NameError: name 'EpicsSignalRO' is not defined

read from Excel spreadsheets

reading information from Excel spreadsheets is a major plus

bring in the routines developed for building the SAS2018 Conference Book

lissajous scan plan

Create a plan to scan a pair of axes in a lissajous trajectory. This has advantages over snake or typewriter scans each time under certain limitations. When reducing exposure of the sample to the beam is important, the snake or typewriter scan increase the sample exposure during acceleration and deceleration of the inner axis. In such scans, only one axis moved at a time. The inner axis traverses its range, then the outer axis is incremented.

In a lissajous scan, both axes move simultaneously along trajectories that are functions of time, each with a different frequency. There is an adjustable phase difference applied that remains constant through the scan.

With judicious choices of frequency for each axis, sampling density rivaling the snake or typewriter scan should be possible.

Ptychography is one particular application that comes to mind which could benefit from a lissajous scan.

references

per-axis tuning should allow override of signal names for complex devices

This line in PeakAxisTuner.tune():

    self.peak_stats = PeakStats(x=self.axis.name, y=self.det.name)

should allow for the signal to be named other than self.det.name.

For example, a signal from the swait record support might pick:

    self.peak_stats = PeakStats(x=self.axis.name, y=self.det.val.name)

is APS in operations mode?

The APS delivers X-ray beam in operations mode. At other times, the storage ring may have significant electron current but the beam is not available for X-ray users. The month-long maintenance periods, occurring three times yearly, are examples. It is still useful to use these periods for code development and maintenance. When beam lines add suspenders for low storage ring current or front end shutter closed, it would be useful to only add those when in operations. During a major shutdown, a beam line might implement a shutter software simulator in place of the physical controls to facilitate code maintenance.

Provide a boolean property function to declare if the APS is in an operations period as a method of the devices.ApsMachineParametersDevice() class.

support for XIA PF4 filter controls

The XIA PF4 filter is supported in EPICS synApps. Provide ophyd device support. The most common use at the APS is in the dual-PF4 box combination.

need standard subclass of EpicsMotor

ophyd.EpicsMotor device lacks:

  • .DESC description
  • .DVAL & .DRBV : dial coordinates
  • .RVAL & .RRBV : raw coordinates
  • .CNEN : enable servo mode

ophyd.EpicsMotor does support .FOFF as offset_frozen and .OFF as user_offset

test if area detector HDF5 plugin has been primed

As discussed in ophyd issue 598, test if the area detector instance is ready for data acquisition with Bluesky. If it is not ready, a TimeoutError exception will be raised when the HDF5 plugin is triggered.

This may not be specific to the HDF5 plugin. Other plugins might need similar tests.

support blocking procedures in plans

Users will write and call procedural functions (non-data collection) for use during their plans and these functions are likely to have blocking calls. Provide support so these functions can be run in a separate thread. Requirements are that each function takes no arguments and must not return until its activities are complete.

apply packaging

  • python package
  • PyPI project
  • conda package
  • sphinx documentation
  • unit testing
  • travis-ci

newer document types have some content

these newer document might be use for console or other reporting (such as comments in SPEC file)

In [9]: RE(bp.count([alta_det]))
Transient Scan ID: 204     Time: 2018/07/27 09:43:07
Persistent Unique Scan ID: '9355a621-6067-4ab6-83d9-32c200c6afb7'
New stream: 'primary'                                                                                                                                                       
+-----------+------------+
|   seq_num |       time |
+-----------+------------+
custom_callback encountered: resource : {'spec': 'AD_HDF5', 'root': '/', 'resource_path': 'share1/USAXS_data/test/alta/2018/07/23/pilgrim_000000.h5', 'resource_kwargs': {'frame_per_point': 0}, 'path_semantics': 'posix', 'uid': 'eb6d3c38-2008-49e9-a90c-6c6cca8f08d7', 'run_start': '9355a621-6067-4ab6-83d9-32c200c6afb7'}
custom_callback encountered: datum : {'resource': 'eb6d3c38-2008-49e9-a90c-6c6cca8f08d7', 'datum_id': 'eb6d3c38-2008-49e9-a90c-6c6cca8f08d7/0', 'datum_kwargs': {'point_number': 0}}
|         1 | 09:43:09.4 |
+-----------+------------+
generator count ['9355a621'] (scan num: 204)



exit status: success
# descriptor(s): 1
# event(s): 1
Out[9]: ('9355a621-6067-4ab6-83d9-32c200c6afb7',)

Motor Limits Mixin

USAXS likes to set motor soft limits for various modes

Provide a mixin to access HLM & LLM fields, with some compatibility methods for get_lim and set_lim

discard ZMQ support code

This code, developed for the MONA project, is no longer needed or used. No point in keeping it.

Generalize how to set detector count time

relates to #23 and to bluesky/bluesky#997

Count time is implemented differently, based on the detector type (and conceivable other hardware-specific features). Here's the ones I know about now:

  • SynSignal : bps.mv(det.exposure_time, time))
  • EpicsScaler : bps.mv(det.preset_time, time)
  • ScalerCH : bps.mv(det.preset_time, time)
  • areadetector.DetectorBase : bps.mv(det.cam.acquire_time, time)

Supporting negative time to count against a monitor detector is only supported by EpicsScaler and ScalerCH in the underlying EPICS record support. That may have to drop from this feature request.

EPICS area detector support in BlueSky

How to get info (and/or data) from each new frame into BlueSky stream?

Current ophyd support was built around earlier AD version. The API has changed and that support fails.

a general technique for axis tuning should be established

As stated for the APS USAXS instrument, any axis should be able to have bespoke tuning, via a call to its self.axis.tune() method. The tune() method will be provided by a Mixin class which also provides an additional attribute tuner (a subclass of AxisTunerBase) that defaults to a standard tuner instance but may be changed to one customized for the axis.

A skeleton of this idea (for APS_BlueSky_tools.devices) is:

class TuningException(ValueError): 
    """Exception during execution of `AxisTunerBase` subclass"""
    pass

class AxisTunerBase(object):
    ok = False
    center = None
    def tune(md=md, **kwargs): ...
    def config(**kwargs): ...
    def peak_detected(): ...

class PeakAxisTuner(AxisTunerBase):
    """
    scan y v. x, then set x = x@max(y), iff max(y) >= 4*min(y), raise `TuningException` as needed
    """
    # implement algorithm from SPEC here (tune to signal peak)
    # see example: https://github.com/prjemian/ipython_ookhd/blob/master/profile_bluesky/startup/11-bs_sim_motors.py#L29
    pass

class Mixin(object):
    # Mixin MUST not provide __init__() method, instead use self.tuner.config()
    tuner = PeakAxisTuner()
    def tune(md=md, **kwargs):
        # TODO: prep
        if self.tuner is not None:
            yield from self.tuner.tune(md=md, **kwargs)
        # TODO: restore

exception from filewriter

from the SpecWriterCallback() filewriter:

/APSshare/anaconda3/BlueSky/lib/python3.6/site-packages/APS_BlueSky_tools/filewriters.py in receiver(self, key, document)
    211             msg = "custom_callback encountered: {} : {}".format(key, document)
    212             # raise ValueError(msg)
--> 213             logger.warn(msg)
    214         return
    215 

UnboundLocalError: local variable 'logger' referenced before assignment

In [4]: !geany /APSshare/anaconda3/BlueSky/lib/python3.6/site-packages/APS_BlueSky_tools/filewriters.py

SPEC writer: add newfile() command

Add newfile() command to SPEC writer class and make it write more than one scan per file. Also need to support re-opening an existing SPEC file.

  • pass file name (not path) when creating the instance, default to date/time file name in pwd if file name not provided
  • What about reset the scan_id with a newfile()?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.