Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

brief code review of 00-prep.py #9

Open
prjemian opened this issue Aug 6, 2019 · 5 comments
Open

brief code review of 00-prep.py #9

prjemian opened this issue Aug 6, 2019 · 5 comments
Assignees
Labels

Comments

@prjemian
Copy link
Contributor

prjemian commented Aug 6, 2019

Since #8 (comment), a short code review seems timely.

@prjemian
Copy link
Contributor Author

prjemian commented Aug 6, 2019

This line is not needed:

but we should convert:

to

RE = bluesky.RunEngine({})

@prjemian
Copy link
Contributor Author

prjemian commented Aug 6, 2019

Isn't this code only called once?

def getRunEngine(db=None):
"""
Return an instance of RunEngine. It is recommended to have only
one RunEngine per session.
"""
RE = RunEngine({})
db = db or metadata_db
RE.subscribe(db.insert)
RE.subscribe(BestEffortCallback())
RE.md['beamline_id'] = 'APS 6-BM-A'
RE.md['proposal_id'] = 'internal test'
RE.md['pid'] = os.getpid()
RE.md['login_id'] = USERNAME + '@' + HOSTNAME
RE.md['versions'] = {}
RE.md['versions']['apstools'] = apstools.__version__
RE.md['versions']['bluesky'] = bluesky.__version__
RE.md['versions']['databroker'] = databroker.__version__
RE.md['versions']['matplotlib'] = matplotlib.__version__
RE.md['versions']['numpy'] = np.__version__
RE.md['versions']['ophyd'] = ophyd.__version__
RE.md['SESSION_STARTED'] = datetime.isoformat(datetime.now(), " ")
return RE
RE = getRunEngine()

Seems that we could avoid creating a new function just for these once-only actions.

@prjemian
Copy link
Contributor Author

prjemian commented Aug 6, 2019

In this code, a Device is created each time the code is called, used, then disposed.

def hutch_light_on():
"""check PV for hutch lighting"""
calcs = apstools.synApps_ophyd.userCalcsDevice("6bma1:", name="calcs")

Seems like an expensive activity. Can the device creation be moved to the caller? Similar to changeset ab45c8c

@prjemian
Copy link
Contributor Author

prjemian commented Aug 6, 2019

Consider replacing

with show_ophyd_symbols() (new in apstools 1.1.8)

apstools.utils.show_ophyd_symbols()

Here is sample output (from my simulator):

In [4]: apstools.utils.show_ophyd_symbols()                                                                                         
======= ================================ ============= =========
name    ophyd structure                  EPICS PV      label(s) 
======= ================================ ============= =========
fourc   FourCircleDiffractometer                                
m1      EpicsMotor                       vm7:m1        motor    
m16     EpicsMotor                       vm7:m16       motor    
m2      EpicsMotor                       vm7:m2        motor    
m3      EpicsMotor                       vm7:m3        motor    
m4      EpicsMotor                       vm7:m4        motor    
m5      EpicsMotor                       vm7:m5        motor    
m6      EpicsMotor                       vm7:m6        motor    
m7      EpicsMotor                       vm7:m7        motor    
m8      EpicsMotor                       vm7:m8        motor    
noisy   EpicsSignalRO                    vm7:userCalc1 detectors
scaler  ScalerCH                         vm7:scaler1   detectors
shutter SimulatedApsPssShutterWithStatus                        
======= ================================ ============= =========

Out[4]: <pyRestTable.rest_table.Table at 0x7f8b01607208>

@prjemian
Copy link
Contributor Author

prjemian commented Aug 6, 2019

Consider adding a call to print_RE_md() just before these lines:

list_predefined_vars()
list_predefined_func()

apstools.utils.print_RE_md()

Here's example output from my simulator:

In [5]: apstools.utils.print_RE_md()                                                                                                
RunEngine metadata dictionary:
=========== ====================
key         value               
=========== ====================
beamline_id Linux Mint VM7      
login_id    mintadmin@mint-vm   
pid         28976               
proposal_id testing             
scan_id     205                 
versions    =========== ========
            key         value   
            =========== ========
            apstools    1.1.12  
            bluesky     1.5.3   
            databroker  0.13.0  
            epics       3.3.3   
            matplotlib  3.1.0   
            numpy       1.16.4  
            ophyd       1.3.3   
            pyRestTable 2020.0.2
            spec2nexus  2021.1.0
            =========== ========

Jasonzhouquan added a commit to Jasonzhouquan/ipython-s6bm that referenced this issue Aug 7, 2019
Improved sorting of imports.

Deleted function getRunEngine. Default databroker to mongodb.

Improved function hutch_light_on as suggested.

Added print_RE_md() and show_ophyd_symbols() as suggested.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants