Skip to content

Instantly share code, notes, and snippets.

View danielballan's full-sized avatar

Dan Allan danielballan

View GitHub Profile
@danielballan
danielballan / logging-optimizations.md
Created January 28, 2021 16:47
Logging optimizations galaxy brain

Logging optimizations

We will examine the byte code to get a sense of how much work the interpreter is doing.

Setup

>>> import logging
>>> logger = logging.getLogger()
>>> from dis import dis
@danielballan
danielballan / aps_polar_example.py
Last active January 11, 2021 22:14 — forked from AbbyGi/README.md
APS 4-ID POLAR bluesky-widgets example
from bluesky_widgets.models.auto_plot_builders import AutoPlotter
from bluesky_widgets.models.plot_builders import Lines
from bluesky_widgets.models.plot_specs import AxesSpec, FigureSpec
from bluesky_widgets.qt.figures import QtFigures
import databroker
import numpy as np
def xanes(monitor, detector):
absorption = np.log(np.array(monitor) / np.array(detector)).reshape(-1, 4)
@danielballan
danielballan / patched_epics_motor.py
Created January 8, 2021 20:42
EpicsMotor alarm handling
from ophyd.epics_motor import EpicsMotor, required_for_connection, motor_done_move, AlarmSeverity
PatchedEpicsMotor(EpicsMotor):
@required_for_connection
@motor_done_move.sub_value
def _move_changed(self, timestamp=None, value=None, sub_type=None,
**kwargs):
'''Callback from EPICS, indicating that movement status has changed'''
was_moving = self._moving
@danielballan
danielballan / example.py
Created December 17, 2020 19:41
Data processing inside a plan, involving externally-stored data (e.g. images)
from ophyd.sim import img as detector
from bluesky.plan_stubs import open_run, stage, unstage, close_run, trigger_and_read, subscribe, unsubscribe
from bluesky_live.bluesky_run import BlueskyRun, DocumentCache
def plan():
"""
Take 10 shots with a detector and do some data processing on the result.
Key points
@danielballan
danielballan / README.md
Last active November 11, 2020 01:01
Area Detector + ophyd test harness

Run Area Detector

Start the container interactively.

sudo podman run -it --rm --name=area-detector -e AD_PREFIX=13SIM1: -p 5064:5064 -v /tmp:/tmp prjemian/synapps-6.1-ad-3.7:latest

In the container's shell:

@danielballan
danielballan / patch_databroker_for_lazy_filling.py
Last active October 29, 2020 18:21
Patch databroker to enable reading PDF TIFFs lazily
from databroker import Broker
db = Broker.named('pdf')
# Ooverride the dask-coersion code with an improved version
# that deals with the incomplete or wrong shape metadata from ophyd.
# This is proposed to be added to databroker in
# https://github.com/bluesky/databroker/pull/596/.
import dask
import dask.array
@danielballan
danielballan / example.ipynb
Last active October 19, 2020 20:23
New BlueskyRun work
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@danielballan
danielballan / example.py
Last active September 24, 2020 21:55
Excluding fields from a suitcase Serializer
import copy
from event_model import DocumentRouter, RunRouter
class Selector(DocumentRouter):
def __init__(self, exclude=None, **kwargs):
self._exclude = exclude or []
super().__init__(**kwargs)
def start(self, doc):
@danielballan
danielballan / README.md
Last active September 10, 2020 00:03
Thumbnail generator MVP

MVP for a thumbnail generator. Corners cut with ❤️.

See docstring for usage examples.

@danielballan
danielballan / README.md
Created September 2, 2020 18:49
testing main access from in process

Put these in a directory together and run:

python test.py