<jupyter_start><jupyter_text>load data<jupyter_code>filepath = 'sampleData.mat'
mat = scipy.io.loadmat(filepath)
ST = mat['ST']; P = mat['P']; HD = mat['hd']<jupyter_output><empty_output><jupyter_text>intialize class instance<jupyter_code>g = glm(ST,P,HD)<jupyter_output><empty_output><jupyter_text>E+P model  1. calculate tuning curves (data)<jupyter_code>HD = (HD + 180) % 360 - 180;
t = P[:,0]; tpf = t[1]-t[0]
x = P[:,1]
y = P[:,2]
boolean_spk = np.logical_and(t[0] <= ST, ST <= t[-1])
spikes = ST[boolean_spk == True]
edgesT = np.linspace(t[0], t[-1], len(t)+1)
binnedSpikes, timeEdges = np.histogram(spikes, edgesT)

# spatial bins
nBins = 10;
H, yedges, xedges = np.histogram2d(x, y, bins=10);
hitx = np.digitize(x, xedges)
hity= np.digitize(y, yedges)

# angular bin centers
num_Z_bins = 10; # 36 deg/bin
Z_bins = np.linspace(0,360,num_Z_bins+1)
Z_edges = np.linspace(-180,180,num_Z_bins+1)
Z_bin_ctrs = (((Z_bins[1]-Z_bins[0])/2) + Z_bins[0:-1])-180

# initialize structures
time_H = np.ones((10,10,10))*np.NaN
count_H = np.ones((10,10,10))*np.NaN
R_xyh = np.ones((10,10,10))*np.NaN
r_xyh = np.ones((10,10,10))*np.NaN
r_xy = np.ones((10,10))*np.NaN

## 3D tuning curve ##
for rr in range(nBins):
    for cc in range(nBins):
        
        # data from bin(rr,cc)
        idx = np.where(np.logical_and(rr == hitx,cc == hity))
        time_in_bin = len(idx)*tpf
        spk = binnedSpikes[idx]
        z_here = HD[idx]

        # HD occupancy
        zhist, _ = np.histogram(z_here, bins=Z_edges)
        z_idx = np.digitize(z_here, Z_edges)
        z_occ_here = zhist*tpf

        # criteria check
        bin_threshold = 0.4 # 400 ms/each
        rate_threshold = 0.5 # Hz
        bin_criteria = np.round(num_Z_bins*.5)
        num_bins_passed = np.sum(z_occ_here>bin_threshold)

        if num_bins_passed >= bin_criteria:
            for H in range(len(Z_bin_ctrs)):
                time_H[H,rr,cc] = z_occ_here[H]
                count_H[H,rr,cc] = zhist[H]
                idx_H = np.where(z_idx == H); idx_H = idx_H[0]

                if time_H[H,rr,cc] > rate_threshold:
                    spk_H = spk[idx_H]
                    r_xyh_here = np.sum(spk_H)/(count_H[H,rr,cc]*tpf)

                    # conditional ratemap
                    if np.isfinite(r_xyh_here):
                        r_xyh[H,rr,cc] = r_xyh_here

            # spatial ratemap
            r_xy[rr,cc] = np.nanmean(r_xyh[:,rr,cc])
            
            # conditional ratemap (zscore normalized)
            R_xyh[:,rr,cc] = stats.zscore(r_xyh[:,rr,cc], nan_policy='omit')<jupyter_output><empty_output><jupyter_text>2. fit cosine to data<jupyter_code>rCutOff = .5<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1558779761904762, 'fraction_numerical': 0.03311011904761905, 'mean_word_length': 2.8858381502890174, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '174009', 'license': 'MIT', 'n_tokens_mistral': 1189, 'n_tokens_neox': 1106, 'n_words': 182, 'path': 'GLM-eb-3D.ipynb', 'repo_name': 'jncarpen/GLM-eb', 'size': '2688'}