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_rates1.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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()
  15. # get CereConn object
  16. ck = cc.CereConn(withSRE=True, withSBPE=False)
  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. # start recording
  24. ck.send_record()
  25. t = time.time()
  26. while ck.get_state() != cc.ccS_Recording:
  27. time.sleep(0.05)
  28. print("It took {:5.3f}s to start CereConn recording\n".format(time.time() - t))
  29. # at least with NPlayServer, we need to wait for things to settle
  30. time.sleep(.5)
  31. # ck.set_spike_rate_estimator_ch_u_list([(0,1), (1,1), (0, 0), (1, 0) ])
  32. # ck.set_spike_rate_estimator_ch_u_list([(0, 0), (1, 0), (2, 0), (3, 0), (4, 0), (5, 0)])
  33. n_channels = 128
  34. ck.fill_spike_rate_estimator_ch_u_list(n_channels, 1) # record channels, pool all units per channel
  35. ch_map = ck.get_spike_rate_estimator_ch_u_map()
  36. print("Channel map: {}".format(ch_map))
  37. bin_width = params.daq.spike_rates.bin_width
  38. run_time = int(sys.argv[1]) #sec
  39. # run_time = run_time #+ bin_width / 1000 / 2. #sec
  40. ck.set_spike_rate_estimator_loop_interval_ms(params.daq.spike_rates.loop_interval)
  41. # ck.set_spike_rate_estimation_method_exponential(params.daq.spike_rates.decay_factor)
  42. ck.set_spike_rate_estimation_method_boxcar(params.daq.spike_rates.max_bins)
  43. time.sleep(.5)
  44. cd = ck.get_spike_rate_data()
  45. print(cd['rates'].shape)
  46. data = np.empty((0, n_channels))
  47. # keep stats...
  48. lasttime = time.time()
  49. starttime = lasttime
  50. times = []
  51. samples = {}
  52. start_ts = cd['ts']
  53. last_ts = start_ts
  54. print('STARTING LOOP\n')
  55. ii = 0
  56. while (time.time() - starttime <= run_time):
  57. now_time = time.time()
  58. print(f'Time left: {run_time - (now_time - starttime ):.1f}s.')
  59. time.sleep(min(0.5, run_time - (now_time - starttime )))
  60. cd = ck.get_spike_rate_data()
  61. print(f"Loop {ii}, rates shape: {cd['rates'].shape}")
  62. data = np.concatenate((data, cd['rates']))
  63. print(f'Total data shape: {data.shape}.')
  64. # print(np.sum(data, 1))
  65. # print("\nNSP Time since start {}s. Time since last loop {}s".format((cd['ts'] - start_ts) / 30000.0, (cd['ts'] - last_ts) / 30000.0))
  66. last_ts = cd['ts']
  67. ctime = time.time()
  68. times.append(ctime - lasttime)
  69. lasttime = ctime
  70. # print("System time since last loop: {}s".format(times[-1]))
  71. # print(f'time elapse: {time.time()-starttime}')
  72. ii += 1
  73. # print(data)
  74. # print(np.any(data))
  75. print('\n')
  76. print(f'Total data shape: {data.shape}')
  77. print('\n')
  78. print('\n')
  79. ck.send_close()
  80. # compute percentiles to select channel for audio feedback
  81. pp = np.percentile(data,[5,95],axis=0)
  82. idx = np.argsort(pp[1])
  83. print(idx)
  84. print(pp[0:2, idx])
  85. plt.figure(1, figsize=(18,5))
  86. plt.clf()
  87. plt.bar(range(128), pp[1])
  88. plt.bar(range(128), pp[0]+0.01)
  89. # plt.ylim(bottom=-1)
  90. plt.title('Firing rates percentiles')
  91. plt.xlabel('Channel #')
  92. plt.ylabel('sp/sec')
  93. # plt.plot(pp.T,'-o')
  94. plt.show()