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

The graph only plot after the scan finishing and spex750m scan is slow. #3

Open
arenal opened this issue Jan 16, 2016 · 0 comments
Open

Comments

@arenal
Copy link

arenal commented Jan 16, 2016

Thanks for this python library that we can make our system working again after an unfortunate dying of the old computer and hence the old program did not work on the newer Windows system. However, during the implementation of the library, we found two issues:

  1. When using plotgen(), the graph did not show the plot each point, but only showed once the scan finished. The issue has been resolved by inserting
  ax[0].figure.canvas.flush_events()

after

  ax[0].figure.canvas.draw()

plotgen() function in live_plot.py

  1. The scan is slow. Probably this is caused by the plotgen() function. So write my own plot and scan function. The original plotgen() function gives about 1.5 sec/point, and the modified scan function gives 1.2 sec/point. The improvement is significant when doing fine scan in a large wavelength range (e.g. save about 3 min. for a scan from 330 to 700, step wavelength = 0.2 nm).

Here is the code:

def fastscan(w_start,w_stop,dw):
if w_start>=300 and w_start<=1200 and w_stop>=300 and w_stop<=1200 and w_stop > w_start:
cal_flg = 0
while not cal_flg:
cur_wl = input("Please calibrate the current wavelength!\n")
if cur_wl>=300 and cur_wl<=1200:
cal_flg = 1

    spex.calibrate(cur_wl)

    fig, ax = plt.subplots()
    line, = ax.plot(np.arange(w_start,w_stop,dw))
    plt.show(block=False)
    fig.canvas.draw()

    i = 0
    xwl = np.arange(w_start,w_stop,dw)
    ydata = deque([0]*len(xwl))
    plt.ylim([0,10])
    spex.set_wl(w_start)
    ymin = 0;
    ymax = 1e-8;

    for i in range(len(xwl)):
        data = li.get_x()
        if data < ymin:
            ymin = data;
            plt.ylim([ymin,ymax])
        if data > ymax:
            ymax = data;
            plt.ylim([ymin,ymax])
        ydata.append(data)
        plt.xlim([w_start,xwl[i]])
        del ydata[0]
        line.set_ydata(ydata)
        line.set_xdata(xwl)
        ax.draw_artist(ax.patch)
        ax.draw_artist(line)
        fig.canvas.update()
        fig.canvas.flush_events()
        spex.rel_move(dw)
        print xwl[i], ":", data
        i = i + 1

    result = np.array([xwl,ydata])
    result = result.T
    np.savetxt("D:\\data_temp.txt",result,fmt=['%f','%f'])
else:
    print "wavelength must be 300 ~ 1200 nm!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant