Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
import time
import sys
import numpy as np
import pvaccess as pva
import matplotlib.pyplot as plt
from matplotlib.pyplot import figure, draw, pause
from epics import caget, caput, camonitor, cainfo
data = np.empty((0, 4))
chunk_counter = -1
stop = False
def handle_close(evt):
global stop
stop = True
def reset_pv(pv):
pv["value.column0"] = []
pv["value.column1"] = []
pv["value.column2"] = []
pv["value.column3"] = []
return pv
def callback(x):
"""Collect data."""
global data
global chunk_counter
chunk_data = np.dstack(
(x["value.column0"], x["value.column1"], x["value.column2"], x["value.column3"])
).squeeze()
data = np.vstack((data, chunk_data))
chunk_counter += 1
# print(f"chunk {chunk_counter} received.")
return chunk_counter
def get_new_data():
channel = pva.Channel("CRYVISIL:STM:FASTSCAN:IMAGE_CHUNK")
pv = channel.get("field(value)")
pv = reset_pv(pv)
channel.put(pv, "")
channel.subscribe("callback", callback)
# print("Starting monitor!")
channel.startMonitor("field(value)")
while data.shape[0] < 1:
time.sleep(0.001)
# print("Stopping monitor!")
channel.stopMonitor()
# print(f"{chunk_counter} chunks counted!")
channel.unsubscribe("callback")
x, y, z, zz = np.squeeze(np.hsplit(data,4))
H, xedges, yedges = np.histogram2d(-y, x, bins=100, weights=z, normed=False)
H_notweighted, xedges, yedges = np.histogram2d(-y, x, bins=100)
H_scale = H / H_notweighted
# plt.imshow(H_scale)
# plt.show()
return H_scale
fg = figure()
fg.canvas.mpl_connect("close_event", handle_close)
ax = fg.gca()
h = ax.imshow(get_new_data())
# for i in range(100):
# data = np.empty((0, 4))
# h.set_data(get_new_data())
# draw(), pause(1e-3)
while not stop:
if caget("CRYVISIL:AWG0:HoldDDS") == 13:
data = np.empty((0, 4))
h.set_data(get_new_data())
draw(), pause(1e-3)
elif caget("CRYVISIL:AWG0:HoldDDS") == 15:
plt.close()
break
elif caget("CRYVISIL:AWG0:SmoothHoldDDS") == 1:
data = np.empty((0, 4))
h.set_data(get_new_data())
draw(), pause(1e-3)