Skip to content

Commit

Permalink
WIP: Fixes to work with collection-2020-2.0rc8 conda env
Browse files Browse the repository at this point in the history
  • Loading branch information
mrakitin committed Oct 27, 2021
1 parent 22c87d2 commit 8502195
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 65 deletions.
25 changes: 21 additions & 4 deletions startup/00-startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Set up a Broker.
# TODO clean this up
from bluesky_kafka import Publisher
from databroker import Broker
from databroker.v0 import Broker
from databroker.headersource.mongo import MDS
from databroker.assets.mongo import Registry

Expand Down Expand Up @@ -254,8 +254,17 @@ def bulk_register_datum_table(self, resource_uid, dkwargs_table, validate=False)


mds_db1 = MDS(_mds_config_db1, auth=False)
db1 = Broker(mds_db1, CompositeRegistry(_fs_config_db1))
cr1 = CompositeRegistry(_fs_config_db1)
db1 = Broker(mds_db1, cr1)

# Broker 2

mds_db2 = MDS(_mds_config_db2, auth=False)
cr2 = CompositeRegistry(_fs_config_db2)
db2 = Broker(mds_db2, cr2)


# wrapper for two databases
class CompositeBroker(Broker):
"""wrapper for two databases"""

Expand Down Expand Up @@ -521,7 +530,15 @@ def _epicssignal_get(self, *, as_string=None, connection_timeout=1.0, **kwargs):
if as_string is None:
as_string = self._string

with self._lock:
###########################################
# Usedf only for old ophyd 1.3.3 and older.
from distutils.version import LooseVersion
import ophyd
if ophyd.__version__ < LooseVersion('1.4'):
self._metadata_lock = self._lock
###########################################

with self._metadata_lock:
if not self._read_pv.connected:
if not self._read_pv.wait_for_connection(connection_timeout):
raise TimeoutError('Failed to connect to %s' %
Expand Down Expand Up @@ -560,7 +577,7 @@ def _epicssignal_get(self, *, as_string=None, connection_timeout=1.0, **kwargs):
from ophyd import EpicsSignalRO
from ophyd.areadetector import EpicsSignalWithRBV


EpicsSignal.get = _epicssignal_get
EpicsSignalRO.get = _epicssignal_get
EpicsSignalWithRBV.get = _epicssignal_get

6 changes: 3 additions & 3 deletions startup/13-mll.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ class HxnMLLSample(NamedDevice):
sz = Cpt(EpicsMotor, 'XF:03IDC-ES{ANC350:3-Ax:2}Mtr', doc='coarse z')

kill = Cpt(EpicsSignal, 'XF:03IDC-ES{Ppmac:1}KillAll-Cmd.PROC',
doc='kill all piezos')
doc='kill all piezos', kind='omitted')
zero = Cpt(EpicsSignal, 'XF:03IDC-ES{Ppmac:1}KillZero-Cmd.PROC',
doc='zero all piezos')
doc='zero all piezos', kind='omitted')
# sz1 = Cpt(EpicsMotor, 'XF:03IDC-ES{ANC350:3-Ax:3}Mtr', doc='coarse z1')
# sz1 was replaced with vz when controller 2 died

Expand Down Expand Up @@ -74,7 +74,7 @@ class HxnMLLDiffractionSample(NamedDevice):
dssz = Cpt(EpicsMotor, 'XF:03IDC-ES{Ppmac:1-dssz}Mtr', doc='fine_z')

kill = Cpt(EpicsSignal, 'XF:03IDC-ES{Ppmac:1-Diff}Kill-Cmd.PROC',
doc='kill all piezos')
doc='kill all piezos', kind='omitted')


smlld = HxnMLLDiffractionSample('', name='smlld')
Expand Down
4 changes: 2 additions & 2 deletions startup/15-zp.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ class HxnZPSample(NamedDevice):
smarthy = Cpt(SmarpodRotationAxis, axis=3, doc='smarpod theta around y')
smarthz = Cpt(SmarpodRotationAxis, axis=1, doc='smarpod theta around z')

kill = Cpt(EpicsSignal, 'XF:03IDC-ES{Ppmac:1-ZP}Kill-Cmd.PROC')
zero = Cpt(EpicsSignal, 'XF:03IDC-ES{Ppmac:1-ZP}Zero-Cmd.PROC')
kill = Cpt(EpicsSignal, 'XF:03IDC-ES{Ppmac:1-ZP}Kill-Cmd.PROC', kind='omitted')
zero = Cpt(EpicsSignal, 'XF:03IDC-ES{Ppmac:1-ZP}Zero-Cmd.PROC', kind='omitted')
mode = Cpt(EpicsSignal, 'XF:03IDC-ES{Ppmac:1-ZP}Mode-I')


Expand Down
11 changes: 8 additions & 3 deletions startup/21-xspress3.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from ophyd.device import (Component as Cpt)

from hxntools.detectors.xspress3 import (Xspress3FileStore,
Xspress3Channel)
from nslsii.detectors.xspress3 import (Xspress3FileStore,
Xspress3Channel)
from hxntools.detectors.hxn_xspress3 import HxnXspress3DetectorBase
import threading
from ophyd import DeviceStatus
Expand Down Expand Up @@ -139,7 +139,12 @@ def unstage(self, *args, **kwargs):


# Create directories on the xspress3 server, otherwise scans can fail:
xspress3.make_directories.put(True)
#====================================================================
# Note from DAMA: commented it out during the 2020-2 deployment visit.
# The corresponding code is in
# https://github.com/NSLS-II/nslsii/blob/master/nslsii/detectors/xspress3.py
#====================================================================
# xspress3.make_directories.put(True)


elem_K_list = np.array(['Na','Mg','Al','Si','P','S','Cl','Ar','K','Ca','Sc','Ti','V','Cr','Mn','Fe','Co','Ni','Cu','Zn','Ga','Ge','As','Se','Br','Kr','Rb','Sr','Y','Zr','Nb','Mo','Tc','Ru','Rh','Pd','Ag','Cd','In','Sn','Sb','Te','I','Xe','Cs','Ba','La','Hf','Ta','W','Re','Os','Ir','Pt','Au','Hg','Tl','Pb','Bi','Po','At','Rn','Fr','Ra','Ac','Ce','Pr','Nd','Pm','Sm','Eu','Gd','Tb','Dy','Ho','Er','Tm','Yb','Lu','Th','Pa','U','Np','Pu','Am','Cm','Bk','Cf'])
Expand Down
114 changes: 61 additions & 53 deletions startup/70-users_plans.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,12 @@ def mll_z_fly2d(z_start, z_end, z_num, mot1, start1, end1, num1, mot2, start2, e
yield from bps.mov(smlld.sbz, init_sz)
save_page()


def zp_z_2dscan(z_start, z_end, z_num, mot1, start1, end1, num1, mot2, start2, end2, num2, acq_time, elem='Co'):
"""This function hasn't been used for a while.
TODO: convert to use 'yield from ...'.
"""
z_step = (z_end - z_start)/z_num
init_sz = zps.zpsz.position
movr(zps.zpsz, z_start/1000)
Expand All @@ -122,6 +127,7 @@ def zp_z_2dscan(z_start, z_end, z_num, mot1, start1, end1, num1, mot2, start2, e
movr(zps.zpsz, z_step/1000)
mov(zps.zpsz, init_sz)


def go_det(det):

if det == 'merlin':
Expand Down Expand Up @@ -242,7 +248,7 @@ def mll_mosaic_scan(x_start, x_end, x_num, x_block, y_start, y_end, y_num, y_blo
#start mosaic scan
for i in range(y_block):
for j in range(x_block):
smll_sync_piezos()
yield from smll_sync_piezos()
RE(fly2d(smll.ssx, x_start, x_end, x_num, smll.ssy, y_start, y_end, y_num, acq_time, return_speed=40))
dx = x_block_size
movr_sx(dx)
Expand Down Expand Up @@ -2154,11 +2160,13 @@ def mono_m1(pf_start, pf_end, pf_num, b_start, b_end, b_num):


def smll_kill_piezos():
smll.kill.put(1)
# smll.kill.put(1)
yield from bps.mv(smll.kill, 1)
yield from bps.sleep(5)

def smll_zero_piezos():
smll.zero.put(1)
# smll.zero.put(1)
yield from bps.mv(smll.zero, 1)
yield from bps.sleep(3)

def smll_sync_piezos():
Expand All @@ -2177,7 +2185,7 @@ def movr_sx(dist):
print('Current ssy = %.3f' % c_ssy)
print('Current ssz = %.3f' % c_ssz)

smll_kill_piezos()
yield from smll_kill_piezos()

t_ssx = c_ssx + dist

Expand All @@ -2186,20 +2194,20 @@ def movr_sx(dist):

dx, dz = sample_to_lab(dxp, dzp, alpha)

movr(sx, dx)
movr(sz, dz)
yield from bps.movr(sx, dx)
yield from bps.movr(sz, dz)

dy = c_ssy -smll.ssy.position

movr(sy, dy)
yield from bps.movr(sy, dy)

sleep(5)
yield from bps.sleep(5)

smll_sync_piezos()
yield from smll_sync_piezos()

mov(ssx, t_ssx)
mov(ssy, c_ssy)
mov(ssz, c_ssz)
yield from bps.mov(ssx, t_ssx)
yield from bps.mov(ssy, c_ssy)
yield from bps.mov(ssz, c_ssz)

print('Post-move x = %.3f' % smll.ssx.position)
print('Post-move y = %.3f' % smll.ssy.position)
Expand All @@ -2215,7 +2223,7 @@ def mov_sx(t_pos):
print('Current ssy = %.3f' % c_ssy)
print('Current ssz = %.3f' % c_ssz)

smll_kill_piezos()
yield from smll_kill_piezos()

t_ssx = t_pos

Expand All @@ -2224,19 +2232,19 @@ def mov_sx(t_pos):

dx, dz = sample_to_lab(dxp, dzp, alpha)

movr(sx, dx)
movr(sz, dz)
yield from bps.movr(sx, dx)
yield from bps.movr(sz, dz)

dy = c_ssy - smll.ssy.position

movr(sy, dy)
yield from bps.movr(sy, dy)

sleep(5)
yield from bps.sleep(5)

smll_sync_piezos()
mov(ssx, t_ssx)
mov(ssy, c_ssy)
mov(ssz, c_ssz)
yield from smll_sync_piezos()
yield from bps.mov(ssx, t_ssx)
yield from bps.mov(ssy, c_ssy)
yield from bps.mov(ssz, c_ssz)

print('Post-move x = %.3f' % (smll.ssx.position))
print('Post-move y = %.3f' % (smll.ssy.position))
Expand All @@ -2253,26 +2261,26 @@ def movr_sy(dist):
print('Current ssy = %.3f' % c_ssy)
print('Current ssz = %.3f' % c_ssz)

smll_kill_piezos()
yield from smll_kill_piezos()

t_ssy = c_ssy + dist
dy = t_ssy - smll.ssy.position
movr(sy, dy)
yield from bps.movr(sy, dy)

dxp = c_ssx - smll.ssx.position
dzp = c_ssz - smll.ssz.position

dx, dz = sample_to_lab(dxp, dzp, alpha)

movr(sx, dx)
movr(sz, dz)
yield from bps.movr(sx, dx)
yield from bps.movr(sz, dz)

sleep(5)
yield from bps.sleep(5)

smll_sync_piezos()
mov(ssx, c_ssx)
mov(ssy, t_ssy)
mov(ssz, c_ssz)
yield from smll_sync_piezos()
yield from bps.mov(ssy, t_ssy)
yield from bps.mov(ssz, c_ssz)
yield from bps.mov(ssx, c_ssx)

print('Post-move x = %.3f' % smll.ssx.position)
print('Post-move y = %.3f' % smll.ssy.position)
Expand All @@ -2288,26 +2296,26 @@ def mov_sy(t_pos):
print('Current ssy = %.3f' % c_ssy)
print('Current ssz = %.3f' % c_ssz)

smll_kill_piezos()
yield from smll_kill_piezos()

t_ssy = t_pos
dy = t_ssy - smll.ssy.position
movr(sy, dy)
yield from bps.movr(sy, dy)

dxp = c_ssx - smll.ssx.position
dzp = c_ssz - smll.ssz.position

dx, dz = sample_to_lab(dxp, dzp, alpha)

movr(sbx, dx)
movr(sbz, dz)
yield from bps.movr(sbx, dx)
yield from bps.movr(sbz, dz)

sleep(5)
yield from bps.sleep(5)

smll_sync_piezos()
mov(ssx, c_ssx)
mov(ssy, t_ssy)
mov(ssz, c_ssz)
yield from smll_sync_piezos()
yield from bps.mov(ssx, c_ssx)
yield from bps.mov(ssy, t_ssy)
yield from bps.mov(ssz, c_ssz)

print('Post-move x = %.3f' % (smll.ssx.position))
print('Post-move y = %.3f' % (smll.ssy.position))
Expand All @@ -2324,20 +2332,20 @@ def movr_sz(dist):
print('Current ssy = %.3f' % c_ssy)
print('Current ssz = %.3f' % c_ssz)

smll_kill_piezos()
yield from smll_kill_piezos()

t_ssz = c_ssz + dist*np.cos(alpha)
dz = t_ssz - smll.dssz.position
dy = c_ssy - smll.dssy.position

movr(sbz, dz)
movr(dsy, dy/1000.0)
yield from bps.movr(sbz, dz)
yield from bps.movr(dsy, dy/1000.0)

sleep(5)
yield from bps.sleep(5)

smll_sync_piezos()
mov(dssy, c_ssy)
mov(dssz, t_ssz)
yield from smll_sync_piezos()
yield from bps.mov(dssy, c_ssy)
yield from bps.mov(dssz, t_ssz)

print('post-move x = %.3f' % smll.dssx.position)
print('Post-move y = %.3f' % smll.dssy.position)
Expand All @@ -2354,20 +2362,20 @@ def mov_sz(t_pos):
print('Current ssy = %.3f' % c_ssy)
print('Current ssz = %.3f' % c_ssz)

smll_kill_piezos()
yield from smll_kill_piezos()

t_ssz = t_pos
dz = (t_ssz - smll.ssz.position)/np.cos(alpha)
dy = c_ssy - smll.ssy.position

movr(sz, dz)
movr(sy, dy)
yield from bps.movr(sz, dz)
yield from bps.movr(sy, dy)

sleep(5)
yield from bps.sleep(5)

smll_sync_piezos()
mov(ssy, c_ssy)
mov(ssz, t_ssz)
yield from smll_sync_piezos()
yield from bps.mov(ssy, c_ssy)
yield from bps.mov(ssz, t_ssz)

print('Post-move x = %.3f' % smll.ssx.position)
print('Post-move y = %.3f' % smll.ssy.position)
Expand Down

0 comments on commit 8502195

Please sign in to comment.