if not (args.rn or args.rr) and args.show: pl.show() if __name__=='__main__' and args.rn: # Calculate the <rn> correlation for all the tracks in a given dataset # TODO: fix this to combine multiple datasets (more than one prefix) if not args.nn: # if args.nn, then these have been loaded already data, trackids, odata, omask = helpy.load_data(prefix, True, False) tracksets, otracksets = helpy.load_tracksets(data, trackids, odata, omask, min_length=max(100, args.stub)) corr_args = {'side': 'both', 'ret_dx': True, 'cumulant': (True, False), 'norm': 0 } xcoscorrs = [ corr.crosscorr(tracksets[t]['x']/S, np.cos(otracksets[t]), **corr_args) for t in tracksets ] ysincorrs = [ corr.crosscorr(tracksets[t]['y']/S, np.sin(otracksets[t]), **corr_args) for t in tracksets ] # Align and merge them fmax = int(2*fps/(D_R if args.nn else 12)) fmin = -fmax rncorrs = xcoscorrs + ysincorrs # TODO: align these so that even if a track doesn't reach the fmin edge, # that is, if f.min() > fmin for a track, then it still aligns at zero rncorrs = helpy.pad_uneven([ rn[np.searchsorted(f, fmin):np.searchsorted(f, fmax)] for f, rn in rncorrs if f.min() <= fmin ], np.nan) tcorr = np.arange(fmin, fmax)/fps meancorr = np.nanmean(rncorrs, 0)
save = absprefix+'_nn-corr.pdf' print 'saving <nn> correlation plot to', save plt.savefig(save) if not (args.rn or args.rr) and args.show: plt.show() if __name__=='__main__' and args.rn: # Calculate the <rn> correlation for all the tracks in a given dataset # TODO: fix this to combine multiple datasets (more than one prefix) if not args.nn: D_R = 1/12 corr_args = {'side': 'both', 'ret_dx': True, 'cumulant': (True, False), 'norm': 0 } xcoscorrs = [ corr.crosscorr(trackset['x']/S, np.cos(trackset['o']), **corr_args) for trackset in tracksets.values() ] ysincorrs = [ corr.crosscorr(trackset['y']/S, np.sin(trackset['o']), **corr_args) for trackset in tracksets.values() ] # Align and merge them fmax = int(2*fps/D_R*args.zoom) fmin = -fmax rncorrs = xcoscorrs + ysincorrs # TODO: align these so that even if a track doesn't reach the fmin edge, # that is, if f.min() > fmin for a track, then it still aligns at zero rncorrs = helpy.pad_uneven([ rn[np.searchsorted(f, fmin):np.searchsorted(f, fmax)] for f, rn in rncorrs if f.min() <= fmin ], np.nan) tcorr = np.arange(fmin, fmax)/fps meancorr = np.nanmean(rncorrs, 0)
print 'saving to', save pl.savefig(save) if __name__=='__main__' and args.rn: # Calculate the <rn> correlation for all the tracks in a given dataset # TODO: fix this to combine multiple datasets (more than one prefix) if not args.nn: # if args.nn, then these have been loaded already data, trackids, odata, omask = helpy.load_data(prefix, True, False) tracksets, otracksets = helpy.load_tracksets(data, trackids, odata, omask, min_length=max(100, args.stub)) corr_args = {'side': 'both', 'ret_dx': True, 'cumulant': True} xcoscorrs = [ corr.crosscorr(tracksets[t]['x']/S, np.cos(otracksets[t]), **corr_args) for t in tracksets ] ysincorrs = [ corr.crosscorr(tracksets[t]['y']/S, np.sin(otracksets[t]), **corr_args) for t in tracksets ] # Align and merge them fmin, fmax = -20, 100 rncorrs = xcoscorrs + ysincorrs rncorrs = helpy.pad_uneven([ rn[np.searchsorted(t, fmin):np.searchsorted(t, fmax)] for t, rn in rncorrs ], np.nan) tcorr = np.arange(fmin, fmax)/fps meancorr = np.nanmean(rncorrs, 0) errcorr = np.nanstd(rncorrs, 0)/sqrt(len(rncorrs)) if verbose: print "Merged rn corrs"