Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

test_cereconn_sbp.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. '''
  2. description: test spike rates from cereconn
  3. author: Ioannis Vlachos
  4. date: 16.11.18
  5. based on Jonas Zimmermann test scripts
  6. Copyright (c) 2018 Ioannis Vlachos.
  7. All rights reserved.'''
  8. import sys
  9. import time
  10. import cere_conn as cc
  11. import numpy as np
  12. import pylab as plt
  13. import aux
  14. params = aux.load_config(force_reload=True)
  15. # get CereConn object
  16. ck = cc.CereConn(withSRE=False, withSBPE=True)
  17. ck.send_open()
  18. # Wait until connection is established
  19. t = time.time()
  20. while ck.get_state() != cc.ccS_Idle:
  21. time.sleep(0.005)
  22. print("It took {:5.3f}s to open CereConn\n".format(time.time() - t))
  23. ck.set_spike_band_power_estimator_loop_interval_ms(params.daq.spike_band_power.loop_interval)
  24. ck.set_spike_band_power_estimator_integrated_samples(params.daq.spike_band_power.integrated_samples)
  25. ck.set_spike_band_power_estimator_filter_coefficients(np.asarray(params.daq.spike_band_power.filter.b), np.asarray(params.daq.spike_band_power.filter.a))
  26. ck.set_spike_band_power_estimator_use_sample_group(params.daq.spike_band_power.sample_group)
  27. # start recording
  28. ck.send_record()
  29. t = time.time()
  30. while ck.get_state() != cc.ccS_Recording:
  31. time.sleep(0.05)
  32. print("It took {:5.3f}s to start CereConn recording\n".format(time.time() - t))
  33. # at least with NPlayServer, we need to wait for things to settle
  34. time.sleep(.5)
  35. # ck.set_spike_rate_estimator_ch_u_list([(0,1), (1,1), (0, 0), (1, 0) ])
  36. # ck.set_spike_rate_estimator_ch_u_list([(0, 0), (1, 0), (2, 0), (3, 0), (4, 0), (5, 0)])
  37. n_channels = 128
  38. ck.fill_spike_band_power_estimator_ch_list(n_channels) # record channels, pool all units per channel
  39. ch_map = ck.get_spike_band_power_estimator_ch_map()
  40. print("Channel map: {}".format(ch_map))
  41. bin_width = params.daq.spike_rates.bin_width
  42. run_time = int(sys.argv[1]) #sec
  43. # run_time = run_time #+ bin_width / 1000 / 2. #sec
  44. #ck.set_spike_rate_estimator_loop_interval_ms(params.daq.spike_rates.loop_interval)
  45. # ck.set_spike_rate_estimation_method_exponential(params.daq.spike_rates.decay_factor)
  46. #ck.set_spike_rate_estimation_method_boxcar(params.daq.spike_rates.max_bins)
  47. time.sleep(1.5)
  48. cd = ck.get_spike_band_power_data()
  49. print(cd['sbp'].shape)
  50. data = np.empty((0, n_channels))
  51. # keep stats...
  52. lasttime = time.time()
  53. starttime = lasttime
  54. times = []
  55. samples = {}
  56. start_ts = cd['ts']
  57. last_ts = start_ts
  58. print('STARTING LOOP\n')
  59. ii = 0
  60. while (time.time() - starttime <= run_time):
  61. now_time = time.time()
  62. print(f'Time left: {run_time - (now_time - starttime ):.1f}s.')
  63. time.sleep(min(0.5, run_time - (now_time - starttime )))
  64. cd = ck.get_spike_band_power_data()
  65. print(f"Loop {ii}, rates shape: {cd['sbp'].shape}")
  66. if cd['sbp'].shape[0] > 0:
  67. data = np.concatenate((data, cd['sbp']))
  68. print(f'Total data shape: {data.shape}.')
  69. # print(np.sum(data, 1))
  70. # print("\nNSP Time since start {}s. Time since last loop {}s".format((cd['ts'] - start_ts) / 30000.0, (cd['ts'] - last_ts) / 30000.0))
  71. last_ts = cd['ts']
  72. ctime = time.time()
  73. times.append(ctime - lasttime)
  74. lasttime = ctime
  75. # print("System time since last loop: {}s".format(times[-1]))
  76. # print(f'time elapse: {time.time()-starttime}')
  77. ii += 1
  78. # print(data)
  79. # print(np.any(data))
  80. print('\n')
  81. print(f'Total data shape: {data.shape}')
  82. print('\n')
  83. print('\n')
  84. ck.send_close()
  85. # compute percentiles to select channel for audio feedback
  86. pp = np.percentile(data,[10,90],axis=0)
  87. idx = np.argsort(pp[1])
  88. print(idx)
  89. print(pp[0:2, idx])
  90. plt.figure(1, figsize=(18,5))
  91. plt.clf()
  92. plt.bar(range(128), pp[1])
  93. plt.bar(range(128), pp[0]+0.01)
  94. # plt.ylim(bottom=-1)
  95. plt.title('SBP percentiles')
  96. plt.xlabel('Channel #')
  97. plt.ylabel('sp/sec')
  98. # plt.plot(pp.T,'-o')
  99. plt.show()