figure2_analysis.py 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import pandas as pd
  2. import numpy as np
  3. from IPython import embed
  4. def get_feature_values(df, features):
  5. """Get the values of different
  6. Parameters
  7. ----------
  8. df : [type]
  9. [description]
  10. features : [type]
  11. [description]
  12. Returns
  13. -------
  14. [type]
  15. [description]
  16. """
  17. datasets = df.dataset.unique()
  18. df = df.dropna()
  19. feature_dict = {}
  20. for f in features:
  21. feature_dict[f] = []
  22. for d in datasets:
  23. contrasts = df.contrast[(df.dataset == d) & (df.pop_size == 1)].unique()
  24. for c in contrasts:
  25. trials = df[(df.dataset == d) & (df.pop_size == 1) & (df.contrast == c)]
  26. for f in feature_dict.keys():
  27. feature_dict[f].append(np.mean(trials[f].values))
  28. for f in feature_dict.keys():
  29. feature_dict[f] = np.array(feature_dict[f])
  30. return feature_dict, datasets
  31. def export_baseline_data(baseline_df, phase_df):
  32. selection = baseline_df[["FiringRate", "CvISI", "BurstFraction", "VectorStrengthGlobalEOD", "EodPeriod"]]
  33. selection = selection.rename(columns={"FiringRate": "firing_rate",
  34. "CvISI": "cv",
  35. "VectorStrengthGlobalEOD": "vector_strength",
  36. "BurstFraction": "burst_fraction",
  37. "EodPeriod": "eod_period"}
  38. )
  39. ids = [id.split("_")[0] for id in selection.index]
  40. selection.insert(0, "dataset_id", ids)
  41. joined = pd.merge(phase_df, selection)
  42. joined.to_csv("../../data/Figure2_baseline_properties.csv", sep=";")
  43. return joined
  44. def export_driven_data(driven_df, mi_df):
  45. selection = driven_df[["datasetId", "responseModulation", "responseVariability", "normPrsLowerCutoffFreq","normPrsUpperCutoffFreq", "cutoffDiff", "normPrsPeakPower", "AutoRelRfPos"]]
  46. selection = selection.rename(columns={
  47. "datasetId": "dataset_id",
  48. "responseModulation": "response_modulation",
  49. "responseVariability": "response_variability",
  50. "normPrsLowerCutoffFreq": "gain_cutoff_lower",
  51. "normPrsUpperCutoffFreq": "gain_cutoff_upper",
  52. "BurstFraction": "burst_fraction",
  53. "cutoffDiff": "gain_pass_band",
  54. "normPrsPeakPower": "gain_maximum",
  55. "AutoRelRfPos": "receptor_pos_relative"}
  56. )
  57. features, mi_datasets = get_feature_values(mi_df, ["mi"])
  58. mutual_infos = []
  59. for d in driven_df.datasetId:
  60. index = np.argwhere(mi_datasets == d + "-invivo-1")[0]
  61. if len(index) == 1:
  62. mutual_infos.append(features["mi"][index][0])
  63. else:
  64. embed()
  65. mutual_infos.extend(features["mi"][index])
  66. mutual_infos = np.array(mutual_infos)
  67. datasets = driven_df.datasetId.values
  68. df = pd.DataFrame({"dataset_id": datasets, "mi": mutual_infos})
  69. joined = pd.merge(selection, df)
  70. joined.to_csv("../../data/Figure2_driven_properties.csv", sep=";")
  71. return joined
  72. if __name__ == "__main__":
  73. data_frame = "../../data/Fig6_7.hdf5"
  74. phase_data_frame = "../../data/Figure2_phase_analysis.csv"
  75. driven_df = pd.read_hdf(data_frame, key='/dynamic_coding_5pc')
  76. driven_df['cutoffDiff'] = (driven_df.normPrsUpperCutoffFreq - driven_df.normPrsLowerCutoffFreq).values
  77. mi_df = pd.read_csv("../../data/PopulationCodingHomogeneous.csv", index_col=0)
  78. baseline_df = pd.read_hdf(data_frame, key='/baseline')
  79. baseline_df['EodPeriod'] = baseline_df.GlobalEODPeakTimes.apply(lambda x: np.mean(np.diff(x)))
  80. phase_df = pd.read_csv(phase_data_frame, sep=";", index_col=0)
  81. baseline_df = export_baseline_data(baseline_df, phase_df)
  82. export_driven_data(driven_df, mi_df)
  83. embed()