whitenoise_delay.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import pandas as pd
  2. import numpy as np
  3. import scipy.stats as stats
  4. import matplotlib.pyplot as plt
  5. from IPython import embed
  6. def main():
  7. df = pd.read_csv("../../derived_data/whitenoise_trials.csv", index_col=0, sep=";")
  8. pos_df = pd.read_csv("../../derived_data/receptivefield_positions.csv", sep=";", index_col=0)
  9. baseline_df = pd.read_csv("../../derived_data/figure2_baseline_properties.csv", sep=";", index_col=0)
  10. datasets = pos_df.dataset_id.unique()
  11. positions = []
  12. delays = []
  13. phases = []
  14. for dataset in datasets:
  15. pos = pos_df.receptor_pos_relative[pos_df.dataset_id == dataset].values[0]
  16. trials = df[df.dataset_id == dataset]
  17. if len(trials) < 1:
  18. continue
  19. delay = np.mean(trials.delay)
  20. phase = baseline_df[baseline_df.dataset_id == dataset].phase_shifted.values[0]
  21. positions.append(pos)
  22. delays.append(delay)
  23. phases.append(phase)
  24. delays = np.array(delays)
  25. positions = np.array(positions)
  26. phases = np.array(phases)
  27. slope, intercept, *params = stats.linregress(positions, delays * 1000)
  28. xRange = np.arange(0., 1.1, 0.1)
  29. yfit = intercept + slope * xRange
  30. fig = plt.figure(figsize=(6, 3), constrained_layout=True)
  31. ax = fig.add_subplot(121)
  32. ax.scatter(positions, delays * 1000, label="data")
  33. ax.plot(xRange, yfit, color="tab:orange", label=f"r:{params[0]:.2f}, p:{params[1]:.3f}", ls="-")
  34. ax.set_xlabel("receptor position [rel.]")
  35. ax.set_xlim([0, 1.0])
  36. ax.set_xticks(np.arange(0, 1.1, 0.2))
  37. ax.set_xticks(np.arange(0, 1.1, 0.1), minor=True)
  38. ax.set_ylabel("delay [ms]")
  39. ax.set_yticks(np.arange(0.0, 6.1, 1.0))
  40. ax.set_yticks(np.arange(0.0, 6.1, 0.5), minor=True)
  41. ax.spines["top"].set_visible(False)
  42. ax.spines["right"].set_visible(False)
  43. ax.legend(fontsize=7)
  44. pslope, pintercept, *pparams = stats.linregress(phases, delays * 1000)
  45. xRange = np.arange(0., 4 * np.pi + 0.1, 0.1)
  46. pyfit = pintercept + pslope * xRange
  47. ax = fig.add_subplot(122)
  48. ax.scatter(phases, delays * 1000, label="data")
  49. ax.plot(xRange, pyfit, color="tab:orange", label=f"r:{pparams[0]:.2f}, p:{pparams[1]:.3f}", ls="-")
  50. ax.set_xlabel("phase [rad]")
  51. ax.set_xlim([0, 4 * np.pi])
  52. ax.set_xticks(np.arange(0, 4 * np.pi + 0.1, np.pi))
  53. ax.set_xticks(np.arange(0, 4 * np.pi + 0.1, 0.5 * np.pi), minor=True)
  54. ax.set_xticklabels([f"{i}$\pi$" for i in range(5)])
  55. ax.set_ylabel("delay [ms]")
  56. ax.set_yticks(np.arange(0.0, 6.1, 1.0))
  57. ax.set_yticks(np.arange(0.0, 6.1, 0.5), minor=True)
  58. ax.spines["top"].set_visible(False)
  59. ax.spines["right"].set_visible(False)
  60. ax.legend(fontsize=7)
  61. fig.savefig("whitenoise_delays.pdf")
  62. if __name__ == "__main__":
  63. main()