From cdcdacb8ab44e7c03927c2bc2ede0d21c433205f Mon Sep 17 00:00:00 2001 From: Maksim Rakitin Date: Tue, 19 Dec 2017 18:19:36 -0500 Subject: [PATCH 1/8] ENH: chxtools enhancements for better packaging --- chxtools/chx_wrapper.py | 238 +++++++++++++++++++++------------------- requirements.txt | 7 ++ 2 files changed, 133 insertions(+), 112 deletions(-) create mode 100644 requirements.txt diff --git a/chxtools/chx_wrapper.py b/chxtools/chx_wrapper.py index fc8994d..cf92c90 100755 --- a/chxtools/chx_wrapper.py +++ b/chxtools/chx_wrapper.py @@ -3,7 +3,8 @@ by LW 03/20/2015 some wrapper functions for ophyd """ -import Tkinter, tkFileDialog +from __future__ import print_function + def det_select(det): """ @@ -16,19 +17,19 @@ def det_select(det): calling sequence: det_select(det) """ try: - rm_det=ascan.user_detectors[0].name - ascan.user_detectors.remove(session_mgr[rm_det]) + rm_det=ascan.user_detectors[0].name + ascan.user_detectors.remove(session_mgr[rm_det]) ascan.default_triggers = [] ascan.default_detectors = [] - print 'removed previous default detector: ',rm_det - except: print 'list of detectors appeared to be empty...' - + print('removed previous default detector: {}'.format(rm_det)) + except: + print('list of detectors appeared to be empty...') + ascan.user_detectors.append(det) # add detector - new_def_det=ascan.user_detectors[0].name - - print '' - print 'new default detector: ',new_def_det - + new_def_det=ascan.user_detectors[0].name + + print('\nnew default detector: {}'.format(new_def_det)) + def cw_ascan(mot,xmin,xmax,npoints,acqt='default',pos_ret=True): """ @@ -43,30 +44,32 @@ def cw_ascan(mot,xmin,xmax,npoints,acqt='default',pos_ret=True): WILL NOT WORK FOR A LIST OF DETECTORS! """ # gather beamline information prior to starting the scan: - ini_motpos=caget(mot.record+'.RBV') + ini_motpos = caget(mot.record+'.RBV') # current detector: - acq_pv=session_mgr[ascan.user_detectors[0].name].pvname - + acq_pv = session_mgr[ascan.user_detectors[0].name].pvname + # set different exposure time for the scan, if requested: - if acqt!='default': + if acqt != 'default': try: - ini_expt=caget(acq_pv[2]) # initial exposure time + ini_expt = caget(acq_pv[2]) # initial exposure time session_mgr[ascan.user_detectors[0].name].acquire_time = acqt - print 'successfully set exposure time to [s]: ',acqt - except: print 'could not set exposure time to ',acqt - + print('successfully set exposure time to [s]: {}'.format(acqt)) + except: + print('could not set exposure time to {}'.format(acqt)) + # execute the scan ascan(mot,xmin,xmax,npoints) - + # put beamline back into initial state - if pos_ret==True: + if pos_ret is True: caput(mot.record+'.VAL',ini_motpos) - print 'returned axes to: ',ini_motpos - if acqt!='default': + print('returned axes to: {}'.format(ini_motpos)) + if acqt != 'default': try: session_mgr[ascan.user_detectors[0].name].acquire_time = ini_expt - print 'successfully reset exposure time to [s]: ',ini_expt - except: print 'could not reset exposure time to ',ini_expt + print('successfully reset exposure time to [s]: {}'.format(ini_expt)) + except: + print('could not reset exposure time to {}'.format(ini_expt)) def cw_dscan(mot,mdx,pdx,npoints,acqt='default',pos_ret=True): """ @@ -78,25 +81,27 @@ def cw_dscan(mot,mdx,pdx,npoints,acqt='default',pos_ret=True): WILL NOT WORK FOR A LIST OF DETECTORS! """ # current detector: - acq_pv=session_mgr[ascan.user_detectors[0].name].pvname - + acq_pv = session_mgr[ascan.user_detectors[0].name].pvname + # set different exposure time for the scan, if requested: - if acqt!='default': + if acqt != 'default': try: ini_expt=caget(acq_pv[2]) # initial exposure time session_mgr[ascan.user_detectors[0].name].acquire_time = acqt - print 'successfully set exposure time to [s]: ',acqt - except: print 'could not set exposure time to ',acqt - + print('successfully set exposure time to [s]: {}'.format(acqt)) + except: + print('could not set exposure time to {}'.format(acqt)) + # execute the scan dscan(mot,mdx,pdx,npoints) - #print 'finished scan' - - if acqt!='default': + #print('finished scan') + + if acqt != 'default': try: session_mgr[ascan.user_detectors[0].name].acquire_time = ini_expt - print 'successfully reset exposure time to [s]: ',ini_expt - except: print 'could not reset exposure time to ',ini_expt + print('successfully reset exposure time to [s]: {}'.format(ini_expt)) + except: + print('could not reset exposure time to {}'.format(ini_expt)) def cw_CCDseries(folder,filename,detector,imnum='default',startn=1,acqt='default',acqperiod='default'): """ @@ -118,7 +123,7 @@ def cw_CCDseries(folder,filename,detector,imnum='default',startn=1,acqt='default # get the detector name:: detector.pvname.split('}')[0]+'}' #get folder interactively: - + if folder == 'ia': root=Tkinter.Tk() root.withdraw() @@ -127,116 +132,125 @@ def cw_CCDseries(folder,filename,detector,imnum='default',startn=1,acqt='default # check whether target directory exists and create it, if it doesn't if not os.path.exists(folder): os.mkdir(folder) - os.chmod(folder,436) #make sure everybody can read an write + os.chmod(folder,436) #make sure everybody can read an write os.chmod(folder,stat.S_IRWXO) - print 'successfully created new directory: ',folder - - + print('successfully created new directory: {}'.format(folder)) + # put folder: r=caput(detector.pvname.split('}')[0]+'}TIFF1:FilePath', folder) # have some problem with syntax here... - if r==1: - print 'changed saving directory to: ',folder - else: print 'error: could not change directory for saving data files.' + if r == 1: + print('changed saving directory to: {}'.format(folder)) + else: + print('error: could not change directory for saving data files.') # put the filename: r=caput(detector.pvname.split('}')[0]+'}TIFF1:FileName', filename) # have some problem with syntax here... - if r==1: - print 'filename for saving: ',filename - else: print 'error: could not change file name for saving.' + if r == 1: + print('filename for saving: {}'.format(filename)) + else: + print('error: could not change file name for saving.') - # put start number caput(detector.pvname.split('}')[0]+'}TIFF1:FileNumber',startn) - + #gather information about current camera settings - acq_pv=session_mgr[ascan.user_detectors[0].name].pvname - ini_acq=caget(acq_pv.split('}')[0]+'}cam1:Acquire') # initial state: started or stopped - ini_mode=caget(acq_pv.split('}')[0]+'}cam1:ImageMode') # initial image mode: single [0], multiple [1], continous [2] - ini_expt=caget(acq_pv.split('}')[0]+'}cam1:AcquireTime') # initial exposure time - ini_acqperiod=caget(acq_pv.split('}')[0]+'}cam1:AcquirePeriod') # initial acquiring period - ini_imnum=caget(acq_pv.split('}')[0]+'}cam1:NumImages') # initial image number - - if acqt!='default': + acq_pv = session_mgr[ascan.user_detectors[0].name].pvname + ini_acq = caget(acq_pv.split('}')[0]+'}cam1:Acquire') # initial state: started or stopped + ini_mode = caget(acq_pv.split('}')[0]+'}cam1:ImageMode') # initial image mode: single [0], multiple [1], continous [2] + ini_expt = caget(acq_pv.split('}')[0]+'}cam1:AcquireTime') # initial exposure time + ini_acqperiod = caget(acq_pv.split('}')[0]+'}cam1:AcquirePeriod') # initial acquiring period + ini_imnum = caget(acq_pv.split('}')[0]+'}cam1:NumImages') # initial image number + + if acqt != 'default': try: caput(acq_pv.split('}')[0]+'}cam1:AcquireTime',acqt) - print 'successfully set exposure time to [s]: ',acqt - except: print 'could not set exposure time to ',acqt + print('successfully set exposure time to [s]: {}'.format(acqt)) + except: + print('could not set exposure time to {}'.format(acqt)) # stop camara: try: caput(acq_pv.split('}')[0]+'}cam1:Acquire',0) - print 'successfully stopped camera' - except: print 'could not stop camera' + print('successfully stopped camera') + except: + print('could not stop camera') # try to set image mode to multiple try: caput(acq_pv.split('}')[0]+'}cam1:ImageMode',1) - print 'successfully set ImageMode to "multiple"' - except: print 'could not set ImageMode to "multiple"' - if acqperiod!='default': - try: + print('successfully set ImageMode to "multiple"') + except: + print('could not set ImageMode to "multiple"') + if acqperiod != 'default': + try: caput(acq_pv.split('}')[0]+'}cam1:AcquirePeriod',acqperiod) - print 'successfully set acquiering period to: ',acqperiod - except: print 'could not set aquireing period to ',acqperiod + print('successfully set acquiering period to: {}'.format(acqperiod)) + except: + print('could not set aquireing period to {}'.format(acqperiod)) + # set number of images to be taken: - if imnum!='default': + if imnum != 'default': try: - caput(acq_pv.split('}')[0]+'}cam1:NumImages',imnum) - print 'successfully set number of images to: ',imnum - except: print 'could not set number of images to ',imnum - print 'going to start the acquisition...' + caput(acq_pv.split('}')[0]+'}cam1:NumImages', imnum) + print('successfully set number of images to: {}'.format(imnum)) + except: + print('could not set number of images to {}'.format(imnum)) + print('going to start the acquisition...') time.sleep(1) # start the acquisition!!! - caput(acq_pv.split('}')[0]+'}cam1:ArrayCounter',0)#set Images acquired (image counter) to 0 - - caput(detector.pvname.split('}')[0]+'}TIFF1:AutoSave',1) # start auto save - caput(acq_pv.split('}')[0]+'}cam1:Acquire',1) # start series acquisition - + caput(acq_pv.split('}')[0]+'}cam1:ArrayCounter',0) # set Images acquired (image counter) to 0 + + caput(detector.pvname.split('}')[0]+'}TIFF1:AutoSave',1) # start auto save + caput(acq_pv.split('}')[0]+'}cam1:Acquire',1) # start series acquisition + counting=0 current_file=caget(detector.pvname.split('}')[0]+'}TIFF1:FullFileName_RBV',as_string=True) while counting==0: - time.sleep(.5) - if caget(acq_pv.split('}')[0]+'}cam1:ArrayCounter_RBV')==imnum: counting=1 - if caget(detector.pvname.split('}')[0]+'}TIFF1:FullFileName_RBV',as_string=True)!=current_file: - current_file=caget(detector.pvname.split('}')[0]+'}TIFF1:FullFileName_RBV',as_string=True) - print 'file written: ',current_file - time.sleep(.1) - - print 'going to stop the acquisition...' + time.sleep(.5) + if caget(acq_pv.split('}')[0]+'}cam1:ArrayCounter_RBV') == imnum: + counting=1 + if caget(detector.pvname.split('}')[0]+'}TIFF1:FullFileName_RBV',as_string=True) != current_file: + current_file=caget(detector.pvname.split('}')[0]+'}TIFF1:FullFileName_RBV',as_string=True) + print('file written: {}'.format(current_file)) + time.sleep(.1) + + print('going to stop the acquisition...') time.sleep(.5) - caput(acq_pv.split('}')[0]+'}cam1:Acquire',0) # stop series acquisition (redundent...should have stopped already - caput(detector.pvname.split('}')[0]+'}TIFF1:AutoSave',0) # stop auto save - - print 'going to reset camera...' + caput(acq_pv.split('}')[0]+'}cam1:Acquire',0) # stop series acquisition (redundent...should have stopped already + caput(detector.pvname.split('}')[0]+'}TIFF1:AutoSave',0) # stop auto save + + print('going to reset camera...') #time.sleep(5) # put camera back into initial state: - if acqt!='default': + if acqt != 'default': try: caput(acq_pv.split('}')[0]+'}cam1:AcquireTime',ini_expt) - print 'successfully reset exposure time to [s]: ',ini_expt - except: print 'could not reset exposure time to ',ini_expt + print('successfully reset exposure time to [s]: {}'.format(ini_expt)) + except: + print('could not reset exposure time to {}'.format(ini_expt)) try: - caput(acq_pv.split('}')[0]+'}cam1:ImageMode',ini_mode) - print 'successfully reset ImageMode' - except: print 'could not reset ImageMode' + caput(acq_pv.split('}')[0]+'}cam1:ImageMode', ini_mode) + print('successfully reset ImageMode') + except: + print('could not reset ImageMode') try: - caput(acq_pv.split('}')[0]+'}cam1:Acquire',ini_acq) - print 'successfully reset camera acqusition mode' - except: print 'could not reset camera acquisition mode' + caput(acq_pv.split('}')[0]+'}cam1:Acquire', ini_acq) + print('successfully reset camera acqusition mode') + except: + print('could not reset camera acquisition mode') if acqperiod!='default': try: - caput(acq_pv.split('}')[0]+'}cam1:AcquirePeriod',ini_acqperiod) - print 'successfully reset acquisition period to [s]: ',ini_acqperiod - except: print 'could not reset acquisition period to ',ini_acqperiod + caput(acq_pv.split('}')[0]+'}cam1:AcquirePeriod', ini_acqperiod) + print('successfully reset acquisition period to [s]: {}'.format(ini_acqperiod)) + except: + print('could not reset acquisition period to {}'.format(ini_acqperiod)) if imnum!='default': try: - caput(acq_pv.split('}')[0]+'}cam1:NumImages',ini_imnum) - print 'successfully reset image numbers to: ',ini_imnum - except: print 'could not reset image numbers to ',ini_imnum + caput(acq_pv.split('}')[0]+'}cam1:NumImages', ini_imnum) + print('successfully reset image numbers to: {}'.format(ini_imnum)) + except: + print('could not reset image numbers to {}'.format(ini_imnum)) time.sleep(.5) try: - caput(acq_pv.split('}')[0]+'}cam1:Acquire',ini_acq) # restart camera if it was running before taking the series - print 'restarted camera' - except: print 'could not restart camera...' - - - - - + caput(acq_pv.split('}')[0]+'}cam1:Acquire', ini_acq) # restart camera if it was running before taking the series + print('restarted camera') + except: + print('could not restart camera...') + diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..2e17da8 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,7 @@ +numpy +matplotlib +h5py +pandas +pyepics +databroker + From 8acbbc10e65024081c6167c8ec14e083221f3374 Mon Sep 17 00:00:00 2001 From: Maksim Rakitin Date: Tue, 19 Dec 2017 18:32:57 -0500 Subject: [PATCH 2/8] Fixed handler2.py --- chxtools/handlers2.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/chxtools/handlers2.py b/chxtools/handlers2.py index 147d636..4391600 100644 --- a/chxtools/handlers2.py +++ b/chxtools/handlers2.py @@ -1,7 +1,8 @@ import numpy as np import h5py from pims import FramesSequence, Frame -from databroker import db +from databroker import Broker +from .handlers import LazyEigerHandler class EigerImages2(FramesSequence): @@ -96,8 +97,11 @@ def __call__(self, seq_id): # TODO Return a multi-dimensional PIMS seq. return EigerImages2(master_path, self._images_per_file, md=md) -db.fs.deregister_handler('AD_EIGER') -db.fs.deregister_handler('AD_EIGER2') +db = Broker.named('chx') + +db.reg.deregister_handler('AD_EIGER') +db.reg.deregister_handler('AD_EIGER2') + +db.reg.register_handler('AD_EIGER2', EigerHandler2) +db.reg.register_handler('AD_EIGER', LazyEigerHandler) -db.fs.register_handler('AD_EIGER2', EigerHandler2) -db.fs.register_handler('AD_EIGER', LazyEigerHandler) From 1a99e3cd693c1d79e7726a0bc89a19bd620d6204 Mon Sep 17 00:00:00 2001 From: Maksim Rakitin Date: Tue, 19 Dec 2017 18:54:24 -0500 Subject: [PATCH 3/8] Fix speckle.py --- chxtools/speckle.py | 4 ++-- requirements.txt | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/chxtools/speckle.py b/chxtools/speckle.py index 2f0dd0b..ada14e5 100644 --- a/chxtools/speckle.py +++ b/chxtools/speckle.py @@ -10,8 +10,8 @@ import numpy as np import time -from skxray.core import roi -from skxray.core.utils import bin_edges_to_centers, geometric_series +from skbeam.core import roi +from skbeam.core.utils import bin_edges_to_centers, geometric_series import logging logger = logging.getLogger(__name__) diff --git a/requirements.txt b/requirements.txt index 2e17da8..0db496f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,4 +4,6 @@ h5py pandas pyepics databroker +ophyd +scikit-beam From 9d3c1ec95e999f21ff61cad1eb015224af81d34d Mon Sep 17 00:00:00 2001 From: Maksim Rakitin Date: Tue, 19 Dec 2017 18:59:56 -0500 Subject: [PATCH 4/8] Fix pims_readers.edf --- chxtools/Time_Correlation_Functions.py | 2 +- requirements.txt | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/chxtools/Time_Correlation_Functions.py b/chxtools/Time_Correlation_Functions.py index 2f43052..826da4a 100644 --- a/chxtools/Time_Correlation_Functions.py +++ b/chxtools/Time_Correlation_Functions.py @@ -9,7 +9,7 @@ import numpy as np import sys import time -import skxray.core.roi as roi +import skbeam.core.roi as roi from matplotlib import gridspec import itertools diff --git a/requirements.txt b/requirements.txt index 0db496f..324a03b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,4 +6,5 @@ pyepics databroker ophyd scikit-beam +fabio From ecf2131621c6422a28552b3be2fcc79d2fc27c3b Mon Sep 17 00:00:00 2001 From: Maksim Rakitin Date: Tue, 19 Dec 2017 19:01:32 -0500 Subject: [PATCH 5/8] Add pims requirements for pims_readers.eiger --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 324a03b..01a1262 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,4 +7,5 @@ databroker ophyd scikit-beam fabio +pims From eb2e599ad8c959af3c34ec9ff76eba952fcaa06e Mon Sep 17 00:00:00 2001 From: Maksim Rakitin Date: Tue, 19 Dec 2017 19:09:37 -0500 Subject: [PATCH 6/8] Added final requirements for pv_explorer.run --- requirements.txt | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/requirements.txt b/requirements.txt index 01a1262..42642dc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,11 +1,13 @@ -numpy -matplotlib +atom +databroker +enaml +fabio h5py +matplotlib +numpy +ophyd pandas +pims pyepics -databroker -ophyd scikit-beam -fabio -pims From bef1cc19aef00845950af14a7cdda069deda9bd9 Mon Sep 17 00:00:00 2001 From: Maksim Rakitin Date: Tue, 19 Dec 2017 19:15:14 -0500 Subject: [PATCH 7/8] Update setup.py to install requirements.txt --- setup.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/setup.py b/setup.py index 1de5e85..1a900b8 100755 --- a/setup.py +++ b/setup.py @@ -7,6 +7,13 @@ from setuptools import setup, find_packages +no_git_reqs = [] +with open('requirements.txt') as f: + required = f.read().splitlines() + for r in required: + if not (r.startswith('git') or r.startswith('#') or r.strip() == ''): + no_git_reqs.append(r) + setup( name='chxtools', version=versioneer.get_version(), @@ -15,4 +22,5 @@ packages=find_packages(), package_data={'chxtools': ['X-ray_database/*.dat']}, include_package_data=True, + install_requires=no_git_reqs, ) From 91dc6ba057c0f8352cc7806c737c340c7d8f4d48 Mon Sep 17 00:00:00 2001 From: Maksim Rakitin Date: Tue, 19 Dec 2017 19:23:17 -0500 Subject: [PATCH 8/8] Add missing deps (scipy and cython) --- requirements.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/requirements.txt b/requirements.txt index 42642dc..9fa9cb8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ atom +cython databroker enaml fabio @@ -10,4 +11,5 @@ pandas pims pyepics scikit-beam +scipy