chunk_ctv_funcs_from_fidor.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import numpy as np
  2. def ctv_for_FIDOR_chunks(curve):
  3. """
  4. input: a time trace (curve)
  5. output: one value, based on a number
  6. """
  7. base_ind, peak_ind = ctv_for_FIDOR_chunks_frames(curve)
  8. output = curve[peak_ind] - curve[base_ind]
  9. return output
  10. def ctv_for_FIDOR_chunks_with_minmax_indices(curve):
  11. """
  12. input: a time trace (curve)
  13. output: ctv, ind1, ind2
  14. ctv: one value, based on a number; ind1 and ind2, so that CTV = curve[ind2] - curve[ind1]
  15. """
  16. base_ind, peak_ind = ctv_for_FIDOR_chunks_frames(curve)
  17. output = curve[peak_ind] - curve[base_ind]
  18. return output, base_ind, peak_ind
  19. def ctv_for_FIDOR_chunks_frames(curve):
  20. """
  21. input: a time trace (curve)
  22. output: two indices ind1 and ind2, so that CTV = curve[ind2] - curve[ind1]
  23. """
  24. middle = len(curve)//2
  25. leftminpos = np.argmin(curve[:middle])
  26. leftmaxpos = np.argmax(curve[:middle])
  27. argminval = np.argmin(curve[leftminpos:])
  28. argmaxval = np.argmax(curve[leftminpos:])
  29. # assuming responses ride only on a flat or falling baseline;
  30. if argminval == 0: # positive response, or an early negative response, which is really rare
  31. pos_resp = True
  32. elif argmaxval == 0: # positive response in first half, maybe weak negative response, hard to quantify reliably
  33. base_ind = leftminpos + argminval
  34. peak_ind = leftmaxpos
  35. return base_ind, peak_ind
  36. elif argminval < argmaxval: # negative response
  37. pos_resp = False
  38. else: # argminval > argmaxval; positive response
  39. pos_resp = True
  40. if pos_resp:
  41. base_ind = leftminpos + argminval
  42. peak_ind = leftminpos + argmaxval
  43. else:
  44. base_ind = leftminpos + argmaxval
  45. peak_ind = leftminpos + argminval
  46. return base_ind, peak_ind