This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
av = create_averager(sin, 5 , monitored=True)
|
||||
tscan ([sin,av], 100, 0.1)
|
||||
@@ -0,0 +1,170 @@
|
||||
class GenericDevice(Nameable):
|
||||
cls=[ "ch.psi.pshell.device.GenericDevice", \
|
||||
"ch.psi.utils.Observable", \
|
||||
"ch.psi.pshell.device.Timestamped", \
|
||||
"java.lang.AutoCloseable", \
|
||||
"ch.psi.utils.Configurable", \
|
||||
"ch.psi.pshell.device.Record" ]
|
||||
|
||||
def __init__(self, name=None, cls=GenericDevice.cls):
|
||||
Nameable.__init__(self, name, cls)
|
||||
self.simulated=False
|
||||
self.state=State.Ready
|
||||
self.monitored=False
|
||||
self.polling=None
|
||||
self.cache=None
|
||||
self.age=None
|
||||
|
||||
|
||||
def addListener(self, listener):
|
||||
pass
|
||||
|
||||
def getListeners(self):
|
||||
pass
|
||||
|
||||
def removeListener(self, listener):
|
||||
pass
|
||||
|
||||
def removeAllListeners(self):
|
||||
pass
|
||||
|
||||
def getTimestamp(self):
|
||||
return 0
|
||||
|
||||
def getTimestampNanos(self):
|
||||
return 0
|
||||
|
||||
def getConfig(self):
|
||||
return None
|
||||
|
||||
def getState(self):
|
||||
return State.Ready
|
||||
|
||||
def waitState(self, state, timeout):
|
||||
return
|
||||
|
||||
def waitStateNot(self, state, timeout):
|
||||
pass
|
||||
|
||||
def initialize(self):
|
||||
pass
|
||||
|
||||
def isInitialized(self):
|
||||
return True
|
||||
|
||||
def waitInitialized(self, timeout):
|
||||
pass
|
||||
|
||||
def setSimulated(self):
|
||||
self.simulated = True
|
||||
|
||||
def isSimulated(self):
|
||||
return self.simulated
|
||||
|
||||
def isMonitored(self):
|
||||
return self.monitored
|
||||
|
||||
def setMonitored(self,monitored):
|
||||
self.monitored=self.monitored
|
||||
|
||||
def setPolling(self, interval):
|
||||
self.polling=interval
|
||||
|
||||
def getPolling(self):
|
||||
return self.polling
|
||||
|
||||
def isPollingBackground(self):
|
||||
return self.polling and self.polling>0
|
||||
|
||||
def setAccessType(self, mode):
|
||||
pass
|
||||
|
||||
def getAccessType(self):
|
||||
return None
|
||||
|
||||
def take(self):
|
||||
return self.cache
|
||||
|
||||
def getAge(self):
|
||||
return self.age
|
||||
|
||||
def request(self):
|
||||
self.update()
|
||||
|
||||
def update(self):
|
||||
pass
|
||||
|
||||
def setWaitSleep(self, value):
|
||||
pass
|
||||
|
||||
def getWaitSleep(self):
|
||||
return 5
|
||||
|
||||
def isPolled(self):
|
||||
return self.getPolling() > 0
|
||||
|
||||
def takeAsNumber(self):
|
||||
cache = take();
|
||||
try:
|
||||
return float(cache)
|
||||
except:
|
||||
return None
|
||||
|
||||
def close(self):
|
||||
pass
|
||||
|
||||
class Device(GenericDevice):
|
||||
cls="ch.psi.pshell.device.Device"
|
||||
|
||||
def __init__(self, name=None):
|
||||
GenericDevice.__init__(self, name, [Device.cls] + GenericDevice.cls)
|
||||
|
||||
def isReady():
|
||||
return getState()==State.Ready
|
||||
|
||||
def waitReady(self, timeout):
|
||||
return
|
||||
|
||||
def waitValue(self, value, timeout):
|
||||
return
|
||||
|
||||
def waitValueNot(self, value, timeout):
|
||||
return
|
||||
|
||||
def waitValueChange(self,timeout):
|
||||
return false
|
||||
|
||||
def waitCacheChange(self,timeout):
|
||||
return false
|
||||
|
||||
def getComponents(self):
|
||||
return None
|
||||
|
||||
def getComponent(self, name):
|
||||
return None
|
||||
|
||||
def getChildren(self):
|
||||
return None
|
||||
|
||||
def getChild(self, name):
|
||||
return None
|
||||
|
||||
def getParent(self):
|
||||
return None
|
||||
|
||||
def setTriggers(self,triggers):
|
||||
pass
|
||||
|
||||
def getTriggers(self):
|
||||
return None
|
||||
|
||||
def takeTimestamped(self,):
|
||||
return None
|
||||
|
||||
def isChild(self, device):
|
||||
return False
|
||||
|
||||
|
||||
|
||||
dev= Device("test")
|
||||
add_device(dev, True)
|
||||
@@ -0,0 +1,43 @@
|
||||
###################################################################################################
|
||||
#Manual scan: Manually setting positioners and reading back sensors, but still using
|
||||
#the standard data handling and plotting of built-in scans.
|
||||
###################################################################################################
|
||||
|
||||
|
||||
mu.setSpeed(10.0)
|
||||
|
||||
pos1 = mu
|
||||
pos2 = out
|
||||
det1 =rs1
|
||||
det2 = sin#rw1
|
||||
det3 = out#ri1
|
||||
|
||||
|
||||
|
||||
|
||||
MOTOR_RANGE = (0.0, 8.0)
|
||||
OUTPUT_SETPOINTS = (1.0, 2.0, 3.0)
|
||||
FIXED_X = True
|
||||
|
||||
writables_names = [pos1.getName(), pos2.getName()]
|
||||
readable_names = [det1.getName(), det2.getName()]
|
||||
start = [ MOTOR_RANGE[0] if FIXED_X else -1, OUTPUT_SETPOINTS[0]]
|
||||
stop = [ MOTOR_RANGE[1] if FIXED_X else -1, OUTPUT_SETPOINTS[-1]]
|
||||
steps = [int(MOTOR_RANGE[1]-MOTOR_RANGE[0]), len(OUTPUT_SETPOINTS)-1]
|
||||
|
||||
scan = ManualScan(writables_names, readable_names ,start, stop, steps, monitors = [sin])
|
||||
|
||||
|
||||
#This option is to plot the foe each output value one 1D series, instead of all in a matrix plot
|
||||
set_exec_pars(line_plots = (det1, det2))
|
||||
|
||||
scan.start()
|
||||
pos1.setSpeed(10.0)
|
||||
for setpoint1 in frange(MOTOR_RANGE[0], MOTOR_RANGE[1], 1.0, True):
|
||||
pos1.move(setpoint1)
|
||||
for setpoint2 in OUTPUT_SETPOINTS:
|
||||
pos2.write(setpoint2)
|
||||
scan.append ([setpoint1, setpoint2], [pos1.read(), pos2.read()], [det1.read(), det2.read()])
|
||||
|
||||
|
||||
scan.end()
|
||||
@@ -0,0 +1,14 @@
|
||||
import signal
|
||||
|
||||
def is_main_thread():
|
||||
try:
|
||||
# Backup the current signal handler
|
||||
back_up = signal.signal(signal.SIGINT, signal.SIG_DFL)
|
||||
except ValueError:
|
||||
# Only Main Thread can handle signals
|
||||
return False
|
||||
# Restore signal handler
|
||||
signal.signal(signal.SIGINT, back_up)
|
||||
return True
|
||||
print (is_main_thread())
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
from functools import partial
|
||||
import threading
|
||||
import traceback
|
||||
import socket
|
||||
|
||||
CTRL_CMD_PORT = 9587
|
||||
msg=None
|
||||
if ("ctrl_cmd_socket" in globals()) and (ctrl_cmd_socket is not None):
|
||||
ctrl_cmd_socket.close()
|
||||
ctrl_cmd_task_thread.join(5.0)
|
||||
if ctrl_cmd_task_thread.is_alive():
|
||||
raise Exception("Cannot stop ctrl_cmd_task_thread")
|
||||
|
||||
def on_ctrl_cmd(cmd):
|
||||
global RE
|
||||
print ("Control command: ", cmd)
|
||||
if cmd=="abort":
|
||||
if "RE" in globals():
|
||||
if RE.state not in ['idle','paused', 'pausing']:
|
||||
print ("Run Engine pause request")
|
||||
RE.request_pause()
|
||||
|
||||
def ctlm_cmd_task(port,parent_thread, rc):
|
||||
try:
|
||||
global ctrl_cmd_socket
|
||||
print ("Starting control command task")
|
||||
quit=False
|
||||
with socket.socket(family=socket.AF_INET, type=socket.SOCK_DGRAM) as ctrl_cmd_socket:
|
||||
ctrl_cmd_socket.bind(("127.0.0.1", port))
|
||||
ctrl_cmd_socket.settimeout(2.0)
|
||||
while(quit==False) and (run_count==rc) and parent_thread.is_alive() and not ctrl_cmd_socket._closed:
|
||||
try:
|
||||
msg,add = ctrl_cmd_socket.recvfrom(100)
|
||||
except socket.timeout:
|
||||
continue
|
||||
cmd =msg.decode('UTF-8')
|
||||
on_ctrl_cmd(cmd)
|
||||
if cmd=="exit":
|
||||
quit=True
|
||||
ctrl_cmd_socket.sendto("ack".encode('UTF-8'), add)
|
||||
finally:
|
||||
print("Quitting control command task")
|
||||
|
||||
ctrl_cmd_task_thread = threading.Thread(target=partial(ctlm_cmd_task, CTRL_CMD_PORT, threading.currentThread(), run_count))
|
||||
ctrl_cmd_task_thread.setDaemon(True)
|
||||
ctrl_cmd_task_thread.start()
|
||||
|
||||
#RE(rel_scan(dets, motor, -1, 1, 10))
|
||||
@@ -0,0 +1,75 @@
|
||||
from jep import jproxy
|
||||
import random
|
||||
|
||||
|
||||
class MyWritable(Writable):
|
||||
def write(self, value):
|
||||
print ("Write: ",value)
|
||||
|
||||
class MyReadable(Readable):
|
||||
def read(self):
|
||||
return random.random()
|
||||
|
||||
class MyReadableArray(ReadableArray):
|
||||
def read(self):
|
||||
ret = []
|
||||
for i in range (self.getSize()):
|
||||
ret.append(random.random())
|
||||
return ret
|
||||
|
||||
def getSize(self):
|
||||
return 20
|
||||
|
||||
class MyReadableCalibratedArray(ReadableCalibratedArray):
|
||||
def read(self):
|
||||
return rw1.read()
|
||||
|
||||
def getSize(self):
|
||||
return rw1.getSize()
|
||||
|
||||
def getCalibration(self):
|
||||
return ArrayCalibration(5,1000)
|
||||
|
||||
class MyReadableMatrix(ReadableMatrix):
|
||||
def read(self):
|
||||
ret = []
|
||||
for i in range (self.getHeight()):
|
||||
ret.append([random.random()] * self.getWidth())
|
||||
return to_array(ret, 'd')
|
||||
|
||||
def getWidth(self):
|
||||
return 80
|
||||
|
||||
def getHeight(self):
|
||||
return 40
|
||||
|
||||
|
||||
class MyReadableCalibratedMatrix(ReadableCalibratedMatrix):
|
||||
def read(self):
|
||||
return ri1.read()
|
||||
|
||||
def getWidth(self):
|
||||
return ri1.getWidth()
|
||||
|
||||
def getHeight(self):
|
||||
return ri1.getHeight()
|
||||
|
||||
def getCalibration(self):
|
||||
return MatrixCalibration(2,4,100,200)
|
||||
|
||||
|
||||
#plot([1,2,3])
|
||||
|
||||
ws1 = MyWritable("ws1")
|
||||
rs1 = MyReadable("rs1")
|
||||
rw1 = MyReadableArray("rw1")
|
||||
ri1 = MyReadableMatrix("ri1")
|
||||
ac1 = MyReadableCalibratedArray("ac1")
|
||||
mc1 = MyReadableCalibratedMatrix("mc1")
|
||||
|
||||
|
||||
|
||||
t=lscan(ws1, (rs1, rw1, ri1, ac1, mc1), 0, 5, 5)
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
from jep import jproxy
|
||||
import random
|
||||
|
||||
|
||||
"""
|
||||
class proxy():
|
||||
def __init__(self,cls):
|
||||
self.cls=cls
|
||||
def __call__(self, name):
|
||||
return jproxy(self, self.cls)
|
||||
|
||||
@proxy(['ch.psi.pshell.device.Readable'])
|
||||
"""
|
||||
class Readable():
|
||||
def __init__(self, name=None):
|
||||
self.name=name
|
||||
self.proxy=jproxy(self, ['ch.psi.pshell.device.Readable'])
|
||||
|
||||
def __call__(self):
|
||||
return self.read()
|
||||
|
||||
def __getattribute__(self, name):
|
||||
if name in ('proxy',):
|
||||
return object.__getattribute__(self, name)
|
||||
print(name)
|
||||
return self.proxy.__getattribute__(name)
|
||||
|
||||
def getName(self):
|
||||
if self.name :
|
||||
return self.name
|
||||
|
||||
return str(self.__class__.__name__)
|
||||
def read(self):
|
||||
raise Exception ("Not implemented")
|
||||
|
||||
|
||||
|
||||
class ReadableScalar(Readable):
|
||||
def read(self):
|
||||
ret =random.random()
|
||||
print (ret)
|
||||
return ret
|
||||
|
||||
class ReadableWaveform(Readable):
|
||||
|
||||
def __call__(self):
|
||||
return self.read()
|
||||
def getSize(self):
|
||||
return 20
|
||||
def read(self):
|
||||
ret = []
|
||||
for i in range (self.getSize()):
|
||||
ret.append(random.random())
|
||||
return ret
|
||||
def getName(self):
|
||||
return "rw1"
|
||||
|
||||
|
||||
|
||||
#rs1 = jproxy(ReadableScalar(), ['ch.psi.pshell.device.Readable'])
|
||||
rs1 = ReadableScalar()
|
||||
#rw1 = jproxy(ReadableWaveform(), ['ch.psi.pshell.device.Readable$ReadableArray'])
|
||||
#ri1 = jproxy(ReadableImage(), ['ch.psi.pshell.device.Readable$ReadableMatrix'])
|
||||
#rw1=ReadableWaveform()
|
||||
rs1.read()
|
||||
#rw1.read()
|
||||
#rs1 = jproxy(rs1 , ['ch.psi.pshell.device.Readable'])#
|
||||
#tscan([rs1],10,0.1, save=False)
|
||||
@@ -0,0 +1,97 @@
|
||||
###################################################################################################
|
||||
#Data Manipulation: Using the data access API to generate and retrieve data
|
||||
###################################################################################################
|
||||
|
||||
|
||||
#Creating a 1D dataset from an array
|
||||
path="group/data1"
|
||||
data1d = [1.0, 2.0, 3.0, 4.0, 5.0]
|
||||
save_dataset(path, data1d)
|
||||
#Reading ii back
|
||||
read =load_data(path)
|
||||
print (list(read))
|
||||
assert data1d==list(read)
|
||||
plot(read)
|
||||
|
||||
#Creating a 2D dataset from an array with some attributes
|
||||
data2d = [ [1.0, 2.0, 3.0, 4.0, 5.0], [2.0, 3.0, 4.0, 5.0, 6.0, ], [3.0, 4.0, 5.0, 6.0, 7.0]]
|
||||
path="group/data2"
|
||||
save_dataset(path, data2d)
|
||||
set_attribute(path, "AttrString", "Value")
|
||||
set_attribute(path, "AttrInteger", 1)
|
||||
set_attribute(path, "AttrDouble", 2.0)
|
||||
set_attribute(path, "AttrBoolean", True)
|
||||
#Reading it back
|
||||
read =load_data(path)
|
||||
print (list(read))
|
||||
plot(read)
|
||||
|
||||
#Creating a 3D dataset from an array
|
||||
data3d = [ [ [1,2,3,4,5], [2,3,4,5,6], [3,4,5,6,7]], [ [3,2,3,4,5], [4,3,4,5,6], [5,4,5,6,7]]]
|
||||
path="group/data3"
|
||||
save_dataset(path, data3d)
|
||||
#Reading it back
|
||||
read =load_data(path,0)
|
||||
print (list(read))
|
||||
read =load_data(path,1)
|
||||
print (list(read))
|
||||
|
||||
#Creating a INT dataset adding elements one by one
|
||||
path = "group/data4"
|
||||
create_dataset(path, 'i')
|
||||
for i in range(10):
|
||||
append_dataset(path,i)
|
||||
|
||||
|
||||
#Creating a 2D data FLOAT dataset adding lines one by one
|
||||
path = "group/data5"
|
||||
create_dataset(path, 'd', False, (0,0))
|
||||
for row in data2d:
|
||||
append_dataset(path, row)
|
||||
|
||||
|
||||
#Creating a Table (compund type)
|
||||
path = "group/data6"
|
||||
names = ["a", "b", "c", "d"]
|
||||
types = ["d", "d", "d", "[d"]
|
||||
lenghts = [0,0,0,5]
|
||||
table = [ [1,2,3,[0,1,2,3,4]],
|
||||
[2,3,4,[3,4,5,6,7]],
|
||||
[3,4,5,[6,7,8,9,4]] ]
|
||||
create_table(path, names, types, lenghts)
|
||||
for row in table:
|
||||
append_table(path, row)
|
||||
flush_data()
|
||||
#Read it back
|
||||
read =load_data(path)
|
||||
print (read)
|
||||
|
||||
|
||||
#Writing scalars (datasets with rank 0)
|
||||
save_dataset("group/val1", 1)
|
||||
save_dataset("group/val2", 3.14)
|
||||
save_dataset("group/val3", "test")
|
||||
print (load_data("group/val1"))
|
||||
print (load_data("group/val2"))
|
||||
print (load_data("group/val3"))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
time.sleep(1.0)
|
||||
|
||||
|
||||
code="""def is_java_instance(obj, cls):
|
||||
print(1)
|
||||
###################################################################################################
|
||||
#Access to context singleton
|
||||
###################################################################################################
|
||||
def get_context():
|
||||
return core.Context.getInstance()
|
||||
"""
|
||||
|
||||
comp=compile(code, '<string>', 'exec')
|
||||
|
||||
set_return(2)
|
||||
@@ -0,0 +1,178 @@
|
||||
import signal
|
||||
signal.signal = lambda *args: None
|
||||
###################################################################################################
|
||||
#import matplotlib
|
||||
#matplotlib.use('Qt5Agg')
|
||||
import traceback
|
||||
|
||||
|
||||
from bluesky import RunEngine
|
||||
from bluesky.callbacks.best_effort import BestEffortCallback
|
||||
from bluesky.utils import install_kicker
|
||||
|
||||
from bluesky.utils import ProgressBarManager
|
||||
from ophyd.sim import det1, det2, det3, det4, det, motor, motor1, motor2, motor3,img, sig, direct_img, pseudo1x3
|
||||
from ophyd import Signal
|
||||
from ophyd.signal import EpicsSignal
|
||||
from bluesky.plans import count, scan, rel_scan, list_scan, grid_scan, list_grid_scan
|
||||
from bluesky.simulators import summarize_plan
|
||||
import bluesky.plan_stubs as bps
|
||||
from bluesky.plan_stubs import mv
|
||||
import bluesky.preprocessors as bpp
|
||||
from bluesky.preprocessors import SupplementalData
|
||||
import databroker
|
||||
#import suitcase
|
||||
#import suitcase.csv
|
||||
#from databroker import Broker
|
||||
|
||||
|
||||
RE = RunEngine({})
|
||||
bec = BestEffortCallback()
|
||||
bec.disable_plots()
|
||||
RE.subscribe(bec)
|
||||
#db = Broker.named('temp')
|
||||
#RE.subscribe(db.insert)
|
||||
#RE.waiting_hook = ProgressBarManager()
|
||||
dets = [det1, det2]
|
||||
|
||||
|
||||
RE(count(dets, num=5))
|
||||
RE(scan(dets, motor, -1, 1, 10))
|
||||
dir (motor)
|
||||
|
||||
vel=motor.velocity.get()
|
||||
motor.velocity.set(vel+1)
|
||||
RE(scan(dets, motor, -1, 1, 10))
|
||||
det.read()
|
||||
det.get()
|
||||
dets=[det]
|
||||
|
||||
RE(rel_scan(dets, motor, -1, 1, 10))
|
||||
|
||||
points = [1, 1, 2, 3, 5, 8, 13]
|
||||
RE(list_scan(dets, motor, points))
|
||||
|
||||
dets=[det4]
|
||||
RE(scan(dets,motor1, -1.5, 1.5, motor2, -0.1, 0.1, 11))
|
||||
RE(list_scan(dets, motor1, [1, 1, 3, 5, 8], motor2, [25, 16, 9, 4, 1]))
|
||||
RE(grid_scan(dets, motor1, -1.5, 1.5, 3, motor2, -0.1, 0.1, 5, motor3, 10, -10, 5))
|
||||
|
||||
RE(grid_scan(dets, motor1, -1.5, 1.5, 3, motor2, -0.1, 0.1, 5))
|
||||
RE(grid_scan(dets, motor1, -1.5, 1.5, 3, motor2, -0.1, 0.1, 5, motor3, 10, -10, 5))
|
||||
|
||||
RE(list_grid_scan(dets, motor1, [1, 1, 2, 3, 5], motor2, [25, 16, 9]))
|
||||
|
||||
|
||||
db[-1].table()
|
||||
|
||||
|
||||
|
||||
def coarse_and_fine(detectors, motor, start, stop):
|
||||
yield from scan(detectors, motor, start, stop, 10)
|
||||
yield from scan(detectors, motor, start, stop, 100)
|
||||
RE(coarse_and_fine(dets, motor, -1, 1))
|
||||
|
||||
# Move motor1 to 1 and motor2 to 10, simultaneously. Wait for both to arrive.
|
||||
RE(mv(motor1, 1, motor2, 10))
|
||||
print (motor1.get().readback, motor2.get().readback)
|
||||
|
||||
# Move motor1 to 1 and motor2 to 10, simultaneously. Wait for both to arrive.
|
||||
print (motor1.get(), motor2.get())
|
||||
def move_then_count():
|
||||
yield from mv(motor1, 1, motor2, 10)
|
||||
yield from count(dets)
|
||||
RE(move_then_count())
|
||||
|
||||
|
||||
sd = SupplementalData()
|
||||
RE.preprocessors.append(sd)
|
||||
sd.baseline = [det1, det2, det3, motor1, motor2]
|
||||
RE(scan([det], motor, -1, 1, 5))
|
||||
print(db[-1].table("baseline"))
|
||||
print(db[-1].table("primary"))
|
||||
|
||||
|
||||
"""
|
||||
docs = db[-1].documents(fill=True)
|
||||
try:
|
||||
suitcase.csv.export(docs, "~/data/bluesky")
|
||||
except:
|
||||
print (sys.exc_info()[1])
|
||||
"""
|
||||
|
||||
motor.delay = 1.1 # simulate slow motor movement
|
||||
sd.monitors=[motor]
|
||||
RE(scan(dets, motor, -1, 1, 10))
|
||||
print(db[-1].table("baseline"))
|
||||
print(db[-1].table("monitor"))
|
||||
|
||||
|
||||
#RE.resume()
|
||||
#RE.abort()
|
||||
#RE.stop()
|
||||
|
||||
|
||||
RE(scan([det], motor, 1, 10, 10), user="alex")
|
||||
for x in db(user="alex"):
|
||||
print (x.table())
|
||||
|
||||
|
||||
summarize_plan(count([det], 3))
|
||||
summarize_plan(scan(dets, motor, -1, 1, 10))
|
||||
summarize_plan(grid_scan(dets, motor1, -1.5, 1.5, 3, motor2, -0.1, 0.1, 5))
|
||||
|
||||
|
||||
def one_run_one_event(detectors):
|
||||
|
||||
md = {
|
||||
# Human-friendly names of detector Devices (useful for searching)
|
||||
'detectors': [det.name for det in detectors],
|
||||
|
||||
# The Python 'repr's each argument to the plan
|
||||
'plan_args': {'detectors': list(map(repr, detectors))},
|
||||
|
||||
# The name of this plan
|
||||
'plan_name': 'one_run_one_event',
|
||||
}
|
||||
@bpp.stage_decorator(detectors)
|
||||
@bpp.run_decorator(md=md)
|
||||
def inner():
|
||||
yield from bps.trigger_and_read(detectors)
|
||||
|
||||
return (yield from inner())
|
||||
|
||||
dets = [det1,det2]
|
||||
RE(one_run_one_event(dets))
|
||||
|
||||
|
||||
def conditional_break(threshold):
|
||||
"""Set, trigger, read until the detector reads intensity < threshold"""
|
||||
|
||||
@bpp.stage_decorator([det, motor])
|
||||
@bpp.run_decorator()
|
||||
def inner():
|
||||
i = 0
|
||||
while True:
|
||||
yield from bps.mv(motor, i)
|
||||
readings = yield from bps.trigger_and_read([det])
|
||||
if readings['det']['value'] < threshold:
|
||||
break
|
||||
i += 1
|
||||
return (yield from inner())
|
||||
|
||||
RE(conditional_break(0.2))
|
||||
|
||||
#catalog = databroker.catalog()
|
||||
|
||||
dets=[pseudo1x3]
|
||||
RE(scan(dets, motor, -1, 1, 10))
|
||||
|
||||
es = EpicsSignal("TESTIOC:TESTSINUS:SinCalc")
|
||||
print (es.read())
|
||||
|
||||
|
||||
try:
|
||||
plot(direct_img.read()['img']['value'].data)
|
||||
|
||||
except:
|
||||
traceback.print_exc()
|
||||
@@ -0,0 +1,30 @@
|
||||
"""
|
||||
RE = RunEngine({}, during_task=EventProcessingTask())
|
||||
bec = BestEffortCallback()
|
||||
bec.disable_plots()
|
||||
RE.subscribe(bec)
|
||||
RE.subscribe(handler)
|
||||
|
||||
motor.delay = 1.1 # simulate slow motor movement
|
||||
|
||||
|
||||
ch1 = EpicsSignal("TESTIOC:TESTSINUS:SinCalc")
|
||||
#TODO: DEmonstrate use of waveform and areadetector (Manual scan setup with the indexes in name)
|
||||
#ch2 = EpicsSignal("TESTIOC:TESTWF2:MyWF", name="arr[10]")
|
||||
#ch3 = EpicsSignal("TESTIOC:TESTWF2:MyWF", name="img[3][2]")det3=ReaderWrapper(sin)
|
||||
"""
|
||||
dets = [det1, det2]
|
||||
|
||||
RE(count(dets, num=5, delay=0.5))
|
||||
RE(scan(dets, motor, 0, 1, 5))
|
||||
RE(rel_scan(dets, motor, -1, 1, 10))
|
||||
RE(list_scan(dets, motor, [1, 1, 2, 3, 5, 8, 13]))
|
||||
RE(grid_scan(dets, motor1, -1.5, 1.5, 3, motor2, -0.1, 0.1, 5))
|
||||
RE(list_grid_scan(dets, motor1, [1, 1, 2, 3, 5], motor2, [25, 16, 9]))
|
||||
|
||||
|
||||
det4=ReaderWrapper(arr)
|
||||
det5=ReaderWrapper(get_device("det").getDataMatrix() )
|
||||
m1=MoverWrapper(get_device("motor"))
|
||||
dets = [det1, det2, ch1, det3, det4, det5]
|
||||
RE(scan(dets, m1, 0, 1, 5))
|
||||
@@ -0,0 +1,487 @@
|
||||
###################################################################################################
|
||||
# Deployment specific global definitions - executed after startup.py
|
||||
###################################################################################################
|
||||
|
||||
###################################################################################################
|
||||
#Devices for PShell standard scans
|
||||
###################################################################################################
|
||||
|
||||
import random
|
||||
|
||||
####################################################################################################
|
||||
# Simulated devices
|
||||
####################################################################################################
|
||||
|
||||
add_device(DummyMotor("m1"), True)
|
||||
add_device(DummyMotor("m2"), True)
|
||||
add_device(DummyRegister("reg1",3), True)
|
||||
add_device(DummyPositioner("p1"),True)
|
||||
add_device(MotorGroupBase("mg1", m1, m2), True)
|
||||
add_device(MotorGroupDiscretePositioner("dp1", mg1), True)
|
||||
|
||||
|
||||
#Initial Configuration
|
||||
if p1.getConfig().unit is None:
|
||||
p1.getConfig().minValue = 0.0 #Not persisted
|
||||
p1.getConfig().maxValue = 1000.0
|
||||
p1.getConfig().unit = "mm"
|
||||
p1.getConfig().save()
|
||||
p1.initialize()
|
||||
|
||||
if dp1.getConfig().positions is None:
|
||||
dp1.getConfig().positions = ["Park","Ready","Out","Clear"]
|
||||
dp1.getConfig().motor1 = ["0.0","4.0","8.0" ,"0.0"]
|
||||
dp1.getConfig().motor2 = ["0.0","5.0","3.0" ,"NaN"]
|
||||
dp1.getConfig().save()
|
||||
dp1.initialize()
|
||||
|
||||
|
||||
|
||||
#Update
|
||||
m1.setMonitored(True)
|
||||
m2.setMonitored(True)
|
||||
|
||||
####################################################################################################
|
||||
# Readable / Writable objects can be created and used in scans
|
||||
####################################################################################################
|
||||
|
||||
class MyWritable(Writable):
|
||||
def write(self, value):
|
||||
#print ("Write: ",value)
|
||||
pass
|
||||
|
||||
class MyReadable(Readable):
|
||||
def read(self):
|
||||
return random.random()
|
||||
|
||||
class MyReadableArray(ReadableArray):
|
||||
def read(self):
|
||||
ret = []
|
||||
for i in range (self.getSize()):
|
||||
ret.append(random.random())
|
||||
return to_array(ret,'d')
|
||||
|
||||
def getSize(self):
|
||||
return 20
|
||||
|
||||
class MyReadableArrayNumpy(ReadableArray):
|
||||
def read(self):
|
||||
ret = numpy.ones(self.getSize(),'d')
|
||||
return ret
|
||||
|
||||
def getSize(self):
|
||||
return 20
|
||||
|
||||
class MyReadableMatrix(ReadableMatrix):
|
||||
def read(self):
|
||||
ret = []
|
||||
for i in range (self.getHeight()):
|
||||
ret.append([random.random()] * self.getWidth())
|
||||
return to_array(ret, 'd')
|
||||
|
||||
def getWidth(self):
|
||||
return 80
|
||||
|
||||
def getHeight(self):
|
||||
return 40
|
||||
|
||||
class MyReadableMatrixNumpy(ReadableMatrix):
|
||||
def read(self):
|
||||
ret = numpy.ones((self.getHeight(), self.getWidth()),'d')
|
||||
for i in range(self.getHeight()):
|
||||
ret[i]=i
|
||||
return to_array(ret, 'd')
|
||||
|
||||
def getWidth(self):
|
||||
return 80
|
||||
|
||||
def getHeight(self):
|
||||
return 40
|
||||
|
||||
|
||||
ao1 = MyWritable("ao1")
|
||||
ao2 = MyWritable("ao2")
|
||||
ai1 = MyReadable("ai1")
|
||||
ai2 = MyReadable("ai2")
|
||||
wf1 = MyReadableArray("wf1")
|
||||
wf2 = MyReadableArrayNumpy("wf2")
|
||||
im1 = MyReadableMatrix("im1")
|
||||
im2 = MyReadableMatrixNumpy("im2")
|
||||
|
||||
|
||||
####################################################################################################
|
||||
# Imaging
|
||||
####################################################################################################
|
||||
|
||||
configured = os.path.exists(GenericDevice.getConfigFileName("src1"))
|
||||
|
||||
add_device(RegisterMatrixSource("src1", im1.proxy), True)
|
||||
add_device(RegisterMatrixSource("src2", im2.proxy), True)
|
||||
|
||||
#src1.setPolling(100)
|
||||
#src2.setPolling(100)
|
||||
|
||||
#Some configuration for so the imaging will work out of the box
|
||||
if not configured:
|
||||
src1.getConfig().colormapAutomatic = True
|
||||
src1.getConfig().colormap = Colormap.Temperature
|
||||
src1.getConfig().save()
|
||||
src2.getConfig().colormapAutomatic = True
|
||||
src2.getConfig().save()
|
||||
|
||||
|
||||
|
||||
|
||||
###################################################################################################
|
||||
#Embedding Bluesky
|
||||
###################################################################################################
|
||||
|
||||
|
||||
import signal
|
||||
signal.signal = lambda *args: None
|
||||
from bluesky import RunEngine
|
||||
from bluesky.callbacks import CallbackBase
|
||||
from bluesky.callbacks.best_effort import BestEffortCallback
|
||||
from bluesky.utils import install_kicker, DuringTask
|
||||
#from bluesky.utils import ProgressBarManager
|
||||
from ophyd.sim import det1, det2, det3, det4, det, motor, motor1, motor2, motor3,img, sig, direct_img, pseudo1x3
|
||||
from ophyd import Signal
|
||||
from ophyd.signal import EpicsSignal
|
||||
from bluesky.plans import count, scan, rel_scan, list_scan, grid_scan, list_grid_scan
|
||||
from bluesky.simulators import summarize_plan
|
||||
import bluesky.plan_stubs as bps
|
||||
from bluesky.plan_stubs import mv
|
||||
import bluesky.preprocessors as bpp
|
||||
from bluesky.preprocessors import SupplementalData
|
||||
#import databroker
|
||||
from databroker import Broker
|
||||
#import suitcase
|
||||
#import suitcase.csv
|
||||
|
||||
CAN_PAUSE=True
|
||||
|
||||
|
||||
|
||||
#def on_ctrl_cmd(cmd):
|
||||
def on_abort(parent_thread):
|
||||
global RE
|
||||
# print ("Control command: ", cmd)
|
||||
# if cmd=="abort":
|
||||
if "RE" in globals():
|
||||
if RE.state not in ['idle','paused', 'pausing']:
|
||||
if CAN_PAUSE:
|
||||
print ("Abort command: Run Engine aborted")
|
||||
sys.stderr=None
|
||||
RE.abort("User abort")
|
||||
return
|
||||
else:
|
||||
print ("Abort command: Run Engine pause request")
|
||||
RE.request_pause()
|
||||
return
|
||||
tid=parent_thread.ident
|
||||
exception = KeyboardInterrupt
|
||||
ctypes.pythonapi.PyThreadState_SetAsyncExc(ctypes.c_long(tid), ctypes.py_object(exception))
|
||||
|
||||
def on_close(parent_thread):
|
||||
on_abort(parent_thread)
|
||||
|
||||
|
||||
|
||||
|
||||
from collections import deque
|
||||
|
||||
is_scan_paused = False
|
||||
class MyHandler(CallbackBase):
|
||||
|
||||
def __init__(self):
|
||||
self.queue= deque(maxlen=1000)
|
||||
|
||||
def clear(self):
|
||||
self.queue.append(("clear",None))
|
||||
|
||||
def start(self, doc):
|
||||
self.queue.append(("start",doc))
|
||||
|
||||
def stop(self, doc):
|
||||
self.queue.append(("stop",doc))
|
||||
|
||||
def descriptor(self, doc):
|
||||
self.queue.append(("descriptor",doc))
|
||||
|
||||
def resource(self, doc):
|
||||
self.queue.append(("resource",doc))
|
||||
|
||||
def event(self, doc):
|
||||
self.queue.append(("event",doc))
|
||||
while is_scan_paused:
|
||||
time.sleep(0.1)
|
||||
|
||||
def datum(self, doc):
|
||||
self.queue.append(("datum",doc))
|
||||
|
||||
def event_page(self, doc):
|
||||
self.queue.append(("event_page",doc))
|
||||
|
||||
def datum_page(self, doc):
|
||||
self.queue.append(("datum_page",doc))
|
||||
|
||||
handler= MyHandler()
|
||||
re_scan=re_res=None
|
||||
|
||||
|
||||
class EventProcessingTask(DuringTask):
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def block(self, blocking_event):
|
||||
global start_doc,descriptor_coc, stop_doc, event_doc, re_scan, re_res, __return__,__exception__
|
||||
re_scan=None
|
||||
while True:
|
||||
done = blocking_event.wait(.1)
|
||||
if done:
|
||||
return
|
||||
try:
|
||||
check_pause()
|
||||
while len(handler.queue):
|
||||
(msg, doc) = handler.queue.popleft()
|
||||
#print("-> " ,msg)
|
||||
if msg=="start":
|
||||
global start_doc
|
||||
start_doc=doc
|
||||
writables=doc.get('motors',[])
|
||||
|
||||
readables=doc.get('detectors',[])
|
||||
start,stop, steps=-1,-1,doc.get('num_intervals',-1)
|
||||
try:
|
||||
if doc.get("plan_name","")=="grid_scan":
|
||||
steps=[x-1 for x in doc['shape']]
|
||||
start=[x[0] for x in doc['extents']]
|
||||
stop=[x[1] for x in doc['extents']]
|
||||
elif doc.get("plan_name","")=="list_grid_scan":
|
||||
steps=[-1 for x in doc['shape']]
|
||||
start=[x[0] for x in doc['extents']]
|
||||
stop=[x[1] for x in doc['extents']]
|
||||
elif doc.get("plan_name","")=="scan":
|
||||
_,start,stop = doc['plan_args']['args']
|
||||
elif doc.get("plan_name","")=="list_scan":
|
||||
_,positions=doc['plan_args']['args']
|
||||
start = min(positions)
|
||||
stop = max(positions)
|
||||
except:
|
||||
pass
|
||||
|
||||
diags=None
|
||||
monitors=None
|
||||
meta={}
|
||||
for k in start_doc.keys():
|
||||
o=start_doc[k]
|
||||
if o is not None:
|
||||
if k=="extents":
|
||||
o = str(o)
|
||||
elif type(o) in (list, tuple):
|
||||
o=to_array(o,'s')
|
||||
elif type(o) == dict:
|
||||
o=str(o)
|
||||
meta[k]=o
|
||||
re_res = None
|
||||
re_scan = ManualScan(writables, readables ,start, stop, steps, diags=diags, monitors=monitors, meta=meta)
|
||||
re_scan.scan.setCanPause(CAN_PAUSE)
|
||||
re_scan.start()
|
||||
|
||||
elif msg=="stop":
|
||||
global stop_doc
|
||||
stop_doc=doc
|
||||
if re_scan is not None:
|
||||
if not re_scan.scan.isCompleted():
|
||||
re_scan.end()
|
||||
re_res = re_scan.scan.getResult()
|
||||
sys.stderr=jep_stderr
|
||||
elif msg=="descriptor":
|
||||
global descriptor_doc
|
||||
descriptor_doc=doc
|
||||
elif msg=="event":
|
||||
global event_doc
|
||||
event_doc=doc
|
||||
if (re_scan is not None) and not (re_scan.scan.isCompleted()):
|
||||
setpoints=[]
|
||||
readbacks=[]
|
||||
detectors=[]
|
||||
data=doc['data']
|
||||
for dev in start_doc.get("motors",[]):
|
||||
readbacks.append(data[dev])
|
||||
try:
|
||||
setpoints.append(data[dev+"_setpoint"])
|
||||
except:
|
||||
setpoints.append(data[dev])
|
||||
for dev in start_doc.get("detectors",[]):
|
||||
v=data[dev]
|
||||
if str(type(v))=="<class 'jep.PyJArray'>":
|
||||
v=numpy.array(v)
|
||||
detectors.append(v)
|
||||
re_scan.append (setpoints, readbacks, detectors)
|
||||
elif msg=="resource":
|
||||
pass
|
||||
elif msg=="datum":
|
||||
pass
|
||||
elif msg=="event_page":
|
||||
pass
|
||||
elif msg=="datum_page":
|
||||
pass
|
||||
elif msg=="clear":
|
||||
pass
|
||||
elif msg=="check_pause":
|
||||
pass
|
||||
elif msg=="read":
|
||||
try:
|
||||
(dev)=doc
|
||||
__return__ = dev.read()
|
||||
except Exception as e:
|
||||
__exception__ = e
|
||||
elif msg=="write":
|
||||
try:
|
||||
(dev, value)=doc
|
||||
dev.write(value)
|
||||
__return__ = True
|
||||
except Exception as e:
|
||||
__exception__ = e
|
||||
except Exception as e:
|
||||
#print (e)
|
||||
pass
|
||||
|
||||
|
||||
def check_pause():
|
||||
try:
|
||||
global RE, re_scan, is_scan_paused
|
||||
if CAN_PAUSE:
|
||||
if ("RE" in globals()) and (re_scan is not None) and not (re_scan.scan.isCompleted()):
|
||||
is_scan_paused =re_scan.scan.isPaused() and not re_scan.scan.isAborted()
|
||||
else:
|
||||
is_scan_paused = False
|
||||
#if re_scan.scan.isAborted():
|
||||
# if RE.state not in ['idle','paused', 'pausing']:
|
||||
# print ("Scan abort")
|
||||
# RE.abort("Scan abort")
|
||||
"""
|
||||
if re_scan.scan.isPaused():
|
||||
if RE.state not in ['idle','paused', 'pausing']:
|
||||
print ("Scan paused: Run Engine pause request")
|
||||
RE.request_pause()
|
||||
is_scan_paused = True
|
||||
else:
|
||||
if RE.state in ['paused', 'pausing']:
|
||||
print ("Scan resumed: Run Engine resuming")
|
||||
#RE.resume()
|
||||
"""
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
class ReaderWrapper():
|
||||
def __init__(self, dev):
|
||||
self.dev=dev
|
||||
self.name=dev.getName()
|
||||
self.parent = None
|
||||
try:
|
||||
self.source = self.dev.getChannelName()
|
||||
except:
|
||||
self.source = "Unknown"
|
||||
try:
|
||||
try:
|
||||
self.shape = [self.dev.getHeight(), self.dev.getWidth()]
|
||||
self.shape_str = "["+str(self.shape[0])+"]"+"["+str(self.shape[1])+"]"
|
||||
except:
|
||||
self.shape = [self.dev.getSize()]
|
||||
self.shape_str = "["+str(self.shape[0])+"]"
|
||||
except:
|
||||
self.shape = []
|
||||
self.shape_str=""
|
||||
try:
|
||||
self.precision = self.dev.getPrecision()
|
||||
except:
|
||||
self.precision = None
|
||||
self.description = {self.name: { \
|
||||
'dtype':'number', \
|
||||
'shape': self.shape, \
|
||||
'source': self.source, \
|
||||
'precision': self.precision \
|
||||
}}
|
||||
|
||||
self.cfg_description = {"shape_str":{"dtype":"string", 'shape':(len(self.shape_str),), "source":""}, }
|
||||
self.configuration = {"shape_str":{"value":self.shape_str, "timestamp":time.time()}}
|
||||
self.name = self.name+self.shape_str
|
||||
|
||||
def read(self):
|
||||
if is_main_thread():
|
||||
return {self.name:{"value":self.dev.read(), "timestamp":time.time()}}
|
||||
global __return__,__exception__
|
||||
__return__ = __exception__ = None
|
||||
handler.queue.append(("read", (self.dev)))
|
||||
while (__return__ is None) and (__exception__ is None):
|
||||
time.sleep(0.01)
|
||||
if __exception__ is not None:
|
||||
raise __exception__
|
||||
return {self.name:{"value":__return__, "timestamp":time.time()}}
|
||||
|
||||
def describe(self):
|
||||
return self.description
|
||||
|
||||
def describe_configuration(self):
|
||||
return self.cfg_description
|
||||
|
||||
def read_configuration(self):
|
||||
return self.configuration
|
||||
|
||||
class NullStatus:
|
||||
"a simple Status object that is always immediately done"
|
||||
def __init__(self):
|
||||
self._cb = None
|
||||
self.done = True
|
||||
self.success = True
|
||||
|
||||
@property
|
||||
def finished_cb(self):
|
||||
return self._cb
|
||||
|
||||
@finished_cb.setter
|
||||
def finished_cb(self, cb):
|
||||
cb()
|
||||
self._cb = cb
|
||||
|
||||
class MoverWrapper(ReaderWrapper):
|
||||
def set(self, value):
|
||||
if is_main_thread():
|
||||
self.dev.write(value)
|
||||
else:
|
||||
global __return__,__exception__
|
||||
__return__ = __exception__ = None
|
||||
handler.queue.append(("write", (self.dev, value)))
|
||||
while (__return__ is None) and (__exception__ is None):
|
||||
time.sleep(0.01)
|
||||
if __exception__ is not None:
|
||||
raise __exception__
|
||||
self.dev.waitReady(-1)
|
||||
return NullStatus()
|
||||
|
||||
@property
|
||||
def position(self):
|
||||
return self.dev.getPosition()
|
||||
|
||||
def stop(self, *, success=False):
|
||||
self.dev.stop()
|
||||
|
||||
|
||||
|
||||
RE = RunEngine({}, during_task=EventProcessingTask())
|
||||
if CAN_PAUSE:
|
||||
RE.pause_msg="User abort"
|
||||
bec = BestEffortCallback()
|
||||
bec.disable_plots()
|
||||
RE.subscribe(bec)
|
||||
RE.subscribe(handler)
|
||||
|
||||
motor.delay = 1.1 # simulate slow motor movement
|
||||
ch1 = EpicsSignal("TESTIOC:TESTSINUS:SinCalc")
|
||||
#TODO: DEmonstrate use of waveform and areadetector (Manual scan setup with the indexes in name)
|
||||
#ch2 = EpicsSignal("TESTIOC:TESTWF2:MyWF", name="arr[10]")
|
||||
#ch3 = EpicsSignal("TESTIOC:TESTWF2:MyWF", name="img[3][2]")det3=ReaderWrapper(sin)
|
||||
dets = [det1, det2]
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,30 @@
|
||||
|
||||
|
||||
#r = tscan((sin,out), 100, 0.01)
|
||||
#vector = [ 1, 3, 5, 10, 25, 40, 45, 47, 49]
|
||||
#r = vscan(pv,(sin,out),vector,False, 0.5, title = "1D Vector")
|
||||
#r = mscan(sin,(sin,out),-1, 3,0)
|
||||
#r = rscan(pv,(sin,out) , [(0.0,5.0,1.0), (10.0,15.0,0.1), (20.0,25.0,1.0)] , 0.01)
|
||||
#r = cscan(motor, (sin,out), 0.0, 2.0 , steps=10.0, time=4.)
|
||||
|
||||
print (get_exec_pars().getPath())
|
||||
|
||||
def before_pass(pass_num):
|
||||
print ("Starting pass: " , pass_num)
|
||||
def after_pass(pass_num):
|
||||
print ("Finished pass: " , pass_num)
|
||||
|
||||
#set_exec_pars(layout="sf")
|
||||
|
||||
ret= lscan(inp, (sin,out), 0, 40, 50, 0.2, passes = 1, before_pass = before_pass, after_pass=after_pass,title = "Test")
|
||||
#ret= lscan(inp, (sin,out), 0, 40, 50, 0.2)
|
||||
|
||||
#set_exec_pars(then="run('test/test3.py)")
|
||||
#set_return([1.0, 3, [1,2,3,4]])
|
||||
#1/0
|
||||
#set_return("T\"es\"t")
|
||||
#set_return([3.0,2])
|
||||
set_return(ret)
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
###################################################################################################
|
||||
# This moddule is called by demo scripts to execute and embed CPython.
|
||||
# Must be put in the scripts folder, or else in the python path.
|
||||
###################################################################################################
|
||||
import matplotlib
|
||||
"""
|
||||
['GTK3Agg', 'GTK3Cairo', 'MacOSX', 'nbAgg', 'Qt4Agg', 'Qt4Cairo', 'Qt5Agg', 'Qt5Cairo', 'TkAgg', 'TkCairo',
|
||||
'WebAgg', 'WX', 'WXAgg', 'WXCairo', 'agg', 'cairo', 'pdf', 'pgf', 'ps', 'svg', 'template']
|
||||
"""
|
||||
matplotlib.use('Qt5Agg')
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
try:
|
||||
import tkinter as tk
|
||||
except:
|
||||
import Tkinter as tk
|
||||
|
||||
|
||||
def calc(array):
|
||||
return np.transpose(array + array)
|
||||
|
||||
|
||||
def test_pandas():
|
||||
s = pd.Series([1,3,5,np.nan,6,8])
|
||||
print (s)
|
||||
dates = pd.date_range('20130101', periods=6)
|
||||
print (dates)
|
||||
df = pd.DataFrame(np.random.randn(6,4), index=dates, columns=list('ABCD'))
|
||||
print (df)
|
||||
df2 = pd.DataFrame({ 'A' : 1.,
|
||||
'B' : pd.Timestamp('20130102'),
|
||||
'C' : pd.Series(1,index=list(range(4)),dtype='float32'),
|
||||
'D' : np.array([3] * 4,dtype='int32'),
|
||||
'E' : pd.Categorical(["test","train","test","train"]),
|
||||
'F' : 'foo' })
|
||||
print (df2)
|
||||
print (df2.dtypes)
|
||||
print (df.head())
|
||||
print (df.tail(3))
|
||||
print (df.values)
|
||||
print (df.describe())
|
||||
print (df.T)
|
||||
print (df.sort_index(axis=1, ascending=False))
|
||||
#print (df.sort_values(by='B'))
|
||||
print (df['A'])
|
||||
print (df[0:3])
|
||||
print (df.mean())
|
||||
return str(df.mean())
|
||||
|
||||
|
||||
def test_tkinter():
|
||||
root = tk.Tk()
|
||||
listb = tk.Listbox(root)
|
||||
for item in ["Hello", "World"]:
|
||||
listb.insert(0,item)
|
||||
listb.pack()
|
||||
root.mainloop()
|
||||
|
||||
print ("OK")
|
||||
|
||||
def test_matplotlib(start,stop,step):
|
||||
import threading
|
||||
x = np.arange(start,stop,step)
|
||||
y = np.exp(-x)
|
||||
|
||||
# example variable error bar values
|
||||
yerr = 0.1 + 0.2*np.sqrt(x)
|
||||
xerr = 0.1 + yerr
|
||||
|
||||
# First illustrate basic pyplot interface, using defaults where possible.
|
||||
plt.figure()
|
||||
plt.errorbar(x, y, xerr=0.2, yerr=0.4)
|
||||
plt.title("Simplest errorbars, 0.2 in x, 0.4 in y")
|
||||
|
||||
# Now switch to a more OO interface to exercise more features.
|
||||
fig, axs = plt.subplots(nrows=2, ncols=2, sharex=True)
|
||||
ax = axs[0,0]
|
||||
ax.errorbar(x, y, yerr=yerr, fmt='o')
|
||||
ax.set_title('Vert. symmetric')
|
||||
|
||||
# With 4 subplots, reduce the number of axis ticks to avoid crowding.
|
||||
ax.locator_params(nbins=4)
|
||||
|
||||
ax = axs[0,1]
|
||||
ax.errorbar(x, y, xerr=xerr, fmt='o')
|
||||
ax.set_title('Hor. symmetric')
|
||||
|
||||
ax = axs[1,0]
|
||||
ax.errorbar(x, y, yerr=[yerr, 2*yerr], xerr=[xerr, 2*xerr], fmt='--o')
|
||||
ax.set_title('H, V asymmetric')
|
||||
|
||||
ax = axs[1,1]
|
||||
ax.set_yscale('log')
|
||||
# Here we have to be careful to keep all y values positive:
|
||||
ylower = np.maximum(1e-2, y - yerr)
|
||||
yerr_lower = y - ylower
|
||||
|
||||
ax.errorbar(x, y, yerr=[yerr_lower, 2*yerr], xerr=xerr,
|
||||
fmt='o', ecolor='g', capthick=2)
|
||||
ax.set_title('Mixed sym., log y')
|
||||
|
||||
fig.suptitle('Variable errorbars')
|
||||
|
||||
plt.show()
|
||||
return [start,stop,step]
|
||||
|
||||
|
||||
test_pandas()
|
||||
test_matplotlib(0,100,100)
|
||||
Reference in New Issue
Block a user