Skip to content
This repository has been archived by the owner on Jan 1, 2023. It is now read-only.

Commit

Permalink
TST #3
Browse files Browse the repository at this point in the history
  • Loading branch information
prjemian committed Nov 1, 2020
1 parent 659dbf8 commit cb7a0d5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
6 changes: 6 additions & 0 deletions profile_bluesky/startup/instrument/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,21 @@
from .iocs import check_iocs

logger.info("bluesky framework")
from .utils import rss_mem
logger.info("rss_mem: %d bytes", rss_mem().rss)

from .framework import *
logger.info("rss_mem: %d bytes", rss_mem().rss)

logger.info("configure instrument")
from .devices import *
logger.info("rss_mem: %d bytes", rss_mem().rss)
from .plans import *
logger.info("rss_mem: %d bytes", rss_mem().rss)
from .utils import *

from apstools.utils import *
logger.info("rss_mem: %d bytes", rss_mem().rss)

# ensure we get our own logger
from .session_logs import logger
10 changes: 5 additions & 5 deletions profile_bluesky/startup/instrument/framework/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
#_path = "/tmp" # make the SPEC file in /tmp (assumes OS is Linux)
_path = os.getcwd() # make the SPEC file in current working directory (assumes is writable)
specwriter.newfile(os.path.join(_path, specwriter.spec_filename))
callback_db['specwriter'] = RE.subscribe(specwriter.receiver)
# callback_db['specwriter'] = RE.subscribe(specwriter.receiver)

logger.info(f"writing to SPEC file: {specwriter.spec_filename}")
logger.info(" >>>> Using default SPEC file name <<<<")
logger.info(" file will be created when bluesky ends its next scan")
logger.info(f" to change SPEC file, use command: newSpecFile('title')")
# logger.info(f"writing to SPEC file: {specwriter.spec_filename}")
# logger.info(" >>>> Using default SPEC file name <<<<")
# logger.info(" file will be created when bluesky ends its next scan")
# logger.info(f" to change SPEC file, use command: newSpecFile('title')")


def spec_comment(comment, doc=None):
Expand Down
27 changes: 20 additions & 7 deletions profile_bluesky/startup/instrument/plans/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
from ..session_logs import logger
logger.info(__file__)

from ..devices import m1, noisy, calcs, calcouts
from ..framework import bec, RE, peaks, bp, sd
from ..utils import rss_mem
from bluesky import preprocessors as bpp
import apstools.utils
import numpy.random
import pyRestTable
from bluesky import preprocessors as bpp
from ..framework import bec, RE, peaks, bp, sd
from ..devices import m1, noisy, calcs, calcouts
import time


def example1():
Expand All @@ -30,15 +32,15 @@ def example1():
positioned somewhere between -1 to +1. Overscan that
range to find both sides of the peak.
This is a 2 scan procedure. First scan passes through
This is a 2 scan procedure. First scan passes through
the full range. Second scan is centered on the peak
and width of the first scan.
::
RE(bp.scan([noisy], m1, -2.1, 2.1, 23))
sig = peaks["fwhm"]["noisy"]; m1.move(peaks["cen"]["noisy"]); RE(bp.rel_scan([noisy], m1, -sig, +sig, 23))
1. replace ``RE()`` with ``yield from ``
2. break lines at ``;``
3. import objects as needed
Expand Down Expand Up @@ -74,6 +76,8 @@ def example_findpeak(number_of_scans=4, number_of_points=23):
cen = 0
results = []
for _again in range(number_of_scans):
t0 = time.time()
mem0 = rss_mem().rss
m1.move(cen)
yield from bp.rel_scan([noisy], m1, -k*fwhm, k*fwhm, number_of_points)
if "noisy" not in peaks["fwhm"]:
Expand All @@ -82,7 +86,11 @@ def example_findpeak(number_of_scans=4, number_of_points=23):
fwhm = peaks["fwhm"]["noisy"]
cen = peaks["cen"]["noisy"]
results.append((RE.md["scan_id"], cen, fwhm))

mem = rss_mem().rss
logger.info(
"dt = %.3f s, rss_mem: %d bytes, change = %d",
time.time() - t0, mem, mem - mem0)

tbl = pyRestTable.Table()
tbl.labels = "scan_id center FWHM".split()
for row in results:
Expand Down Expand Up @@ -110,8 +118,13 @@ def repeat_findpeak(iters=1):
# If plots are disabled, then the peak stats are not run
# so peak finding fails.
for _i in range(iters):
t0 = time.time()
mem0 = rss_mem().rss
apstools.utils.trim_plot_lines(bec, 4, m1, noisy)
change_peak()
yield from example_findpeak()
logger.info("Finished #%d of %d iterations", _i+1, iters)
mem = rss_mem().rss
logger.info(
"Finished #%d of %d iterations, dt=%.3f s, bytes=%d, bytes_changed=%d",
_i+1, iters, time.time() - t0, mem, mem - mem0)
# bec.enable_plots()

0 comments on commit cb7a0d5

Please sign in to comment.