如何在Python中对恒电位仪循环测试中从0重启的时间序列做连续拼接
解决方法
新增时间偏移量变量记录上一轮测试的最终时间,每轮获取到新的时间列表后,给所有元素叠加该偏移量再存入总列表,即可得到连续的时间序列。
修改后完整代码
# -*- coding: utf-8 -*- """ Created on Sat Sep 18 18:34:59 2021 @author: dallo """ from potentiostat import Potentiostat import sys import matplotlib.pyplot as plt from serial import Serial port = 'COM7' num_pulse = 25 # Number of pulses (max = 25) lo_pulse = (10, -1.0) hi_pulse = (20, -0.1) num_cycles = 3 dev = Potentiostat(port) hw_variant = dev.get_hardware_variant() dev.set_curr_range('1000uA') dev.set_sample_rate(300) step_list = [] curr_list = [] volt_list = [] t_list = [] # 新增时间偏移量,初始值为0 time_offset = 0.0 # Add pulses to step list for i in range(num_pulse): step_list.append(lo_pulse) step_list.append(hi_pulse) # Test name and test parameters test_name = 'multiStep' test_param = { 'quietValue' : 0.0, 'quietTime' : 0, 'step' : step_list, } for i in range(num_cycles): volt = [] curr = [] dev.set_param(test_name,test_param) t,volt,curr = dev.run_test(test_name,display='pbar') # 调整当前轮时间序列,叠加偏移量 adjusted_t = [x + time_offset for x in t] # 更新偏移量为当前轮最后一个时间值,供下一轮使用 time_offset = adjusted_t[-1] curr_list.extend(curr) volt_list.extend(volt) t_list.extend(adjusted_t) volt_ax = plt.subplot(2,1,1) plt.plot(t_list,volt_list) plt.ylabel('potential (V)') plt.grid('on') plt.subplot(2,1,2, sharex=volt_ax) plt.plot(t_list,curr_list) plt.ylabel('current (uA)') plt.xlabel('t (sec)') plt.grid('on') plt.show()
内容的提问来源于stack exchange,提问作者Dallon Penney
相关产品推荐
相关产品推荐

