Skip to content

Instantly share code, notes, and snippets.

Avatar

Dan Allan danielballan

View GitHub Profile
@danielballan
danielballan / example.py
Last active Sep 24, 2020
Excluding fields from a suitcase Serializer
View example.py
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 Sep 10, 2020
Thumbnail generator MVP
View README.md

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

See docstring for usage examples.

@danielballan
danielballan / README.md
Created Sep 2, 2020
testing main access from in process
View README.md

Put these in a directory together and run:

python test.py
@danielballan
danielballan / README.md
Last active Aug 28, 2020
Use Resource to get at correct shape for dask array
View README.md
  1. Place this shape_workaround.py from this gist in your current working directory (so Python can import it).
  2. databroker-unpack inplace /nsls2/tmp/export/fxi_karen_2019_05_03_attempt5 fxi_karen_2019_05_03_attempt5
  3. Edit by hand the catalog.yml file that was placed by the databroker-unpack CLI to inject the custom Filler subclass defined in shape_workaround.py.
# ~/.local/share/intake/databroker_unpack_fxi_karen_2019_05_03_attempt5.yml
 sources:
   fxi_karen_2019_05_03_attempt5:
     args:
       paths:
@danielballan
danielballan / patch_acquire_changed.py
Created Jul 6, 2020
Clear status object once it is complete.
View patch_acquire_changed.py
class MyDetector(...):
def _acquire_changed(self, value=None, old_value=None, **kwargs):
super().acquire_changed(value=value, old_value=old_value, **kwargs)
if self._status.done:
# Clear the state to be ready for the next round.
self._status = None
@danielballan
danielballan / patch_acquire_changed.py
Created Jul 6, 2020
Clear status object once it is complete.
View patch_acquire_changed.py
class MyDetector(...):
def _acquire_changed(self, value=None, old_value=None, **kwargs):
super().acquire_changed(value=value, old_value=old_value, **kwargs)
if self._status.done:
# Clear the state to be ready for the next round.
self._status = None
View working_example.py
import threading
from bluesky.log import config_bluesky_logging
import numpy
from ophyd.sim import SynSignalWithRegistry
from ophyd import Component, Device, Signal, DeviceStatus
config_bluesky_logging(level="DEBUG")
@danielballan
danielballan / camera_device.py
Last active Jun 25, 2020
BMM camera ophyd integration
View camera_device.py
import os
import uuid
import threading
import itertools
import requests
from ophyd import Device, Component, Signal, DeviceStatus
from ophyd.areadetector.filestore_mixins import resource_factory
# See for resource_factory docstring
View bluesky_datagram_protocol.py
from asyncio import DatagramProtocol, gather, get_event_loop, sleep
from collections import deque
from functools import partial
from json import loads, dumps
from random import choices, random
from ophyd import Device
from ophyd.status import DeviceStatus, Status
CLIENT_PORT = 9870
View bluesky_datagram_protocol.py
from asyncio import DatagramProtocol, gather, get_event_loop, sleep
from collections import deque
from functools import partial
from json import loads, dumps
from random import choices, random
from ophyd import Device
from ophyd.status import DeviceStatus, Status
CLIENT_PORT = 9870
You can’t perform that action at this time.