Exemplo n.º 1
0
    def calc_vec_strength_threshold_mean(self, input_ln, input_mn):

        hstvls = {}
        #ax_traj.plot(cr_mn,cr_ln)

        threshinds = np.where(np.array(input_ln) > VEC_STRENGTH_THRESHOLD)[0]
        out_dt = calc.make_hist_calculations(
            calc.rad_to_deg(input_mn[threshinds]), self.degbins)
        for key in ['normhst', 'mnrad', 'circvar']:
            hstvls[key] = out_dt[key]

            #hstvls['xrad']=self.xrad
            #hstvls['rad_per_bin']=self.rad_per_bin
        return hstvls
Exemplo n.º 2
0
    def anal_closed_stroke_data(self):

        self.outdict = {}
        self.outdict['exp'] = {}
        self.outdict['ctrl'] = {}

        self.outdict['mot_rad'] = self.crdata[
            'adjusted_raw_motor_position_in_rad']

        self.outdict['mot_deg'] = calc.rad_to_deg(
            self.crdata['adjusted_raw_motor_position_in_rad'])
        self.outdict['exp']['sumdeg'] = self.outdict['mot_deg'].tolist()
        self.outdict['float_time'] = self.crdata['time']
        self.outdict['raw_time'] = self.crdata['net_time']
        self.outdict['period'] = self.crdata['period']

        self.analyze_degree_data()
Exemplo n.º 3
0
    def make_plots(self, OFFSET_TIME):
        MAXDEGPLOT = 358

        PLOTFLAG = 1
        MINDEGPLOT = 2
        hstvls = {}
        CONTROL_LAG_TIME = 30
        if self.anal_type == 'paired':
            crdt = self.datvls[self.pairind]['sumstats']['exp']
        else:
            try:
                crdt = self.datvls['sumstats']['exp']
            except:
                PLOTFLAG = 0
        if PLOTFLAG:
            plot_time = OFFSET_TIME + crdt['time_in_min']
            plotinds1 = np.where(crdt['mot_deg'] < MAXDEGPLOT)
            plotinds2 = np.where(crdt['mot_deg'] > MINDEGPLOT)
            allinds = np.intersect1d(np.array(plotinds1[0]),
                                     np.array(plotinds2[0]))
            lftwng = crdt['lftwng']
            rtwng = crdt['rtwng']
            pol_sensor = crdt['pol_sensor']
            minbnds = np.where(pol_sensor > POL_SENSOR_MINIMUM)
            srtind = np.argsort(crdt['mot_deg'][minbnds])
            wingdiff = np.array(lftwng) - np.array(rtwng)

            MAXTIME = np.max(plot_time)
            self.axhandles[0].plot(plot_time,
                                   np.array(lftwng),
                                   'r',
                                   linewidth=0.4)
            self.axhandles[0].plot(plot_time,
                                   np.array(rtwng),
                                   'c',
                                   linewidth=0.4)
            self.axhandles[2].plot(crdt['vec_time_lst'],
                                   crdt['len_vector_lst'], 'k')
            self.axhandles[3].plot(plot_time, pol_sensor, 'k')

            #should change this to be vec_axh=self.axhandles[4]
            #fig2=pylab.figure()
            self.vecaxh = fig2.add_subplot(2, 1, 1, polar=True)
            self.vecaxh.plot(cr_mn, cr_ln)
            threshinds = np.where(np.array(cr_ln) > THRESHOLD)[0]

            tmphst, mnrad, tmpvar = calc.make_hist_calculations(
                calc.rad_to_deg(cr_mn[threshinds]), self.degbins)
            self.vechist_axh = fig2.add_subplot(2, 1, 2, polar=True)
            hstvls['normhst'] = tmphst
            hstvls['mnrad'] = mnrad
            hstvls['xrad'] = self.xrad
            hstvls['rad_per_bin'] = self.rad_per_bin

            plt.polar_plot(self.vechist_axh, hstvls)
            if self.anal_type == 'paired':
                self.datvls[self.pairind]['sumstats']['exp']['vecmn'] = mnrad
                self.datvls[self.pairind]['sumstats']['exp']['vecvar'] = tmpvar
            else:
                self.datvls['sumstats']['exp']['vecmn'] = mnrad
                self.datvls['sumstats']['exp']['vechst'] = tmphst
                self.datvls['sumstats']['exp']['vecvar'] = tmpvar

            splitinds = np.array_split(
                threshinds,
                np.array(np.where(np.diff(threshinds) != 1))[0] + 1)
            for rotnum, crsplitinds in enumerate(splitinds):
                if np.size(crsplitinds):
                    self.vecaxh.plot(cr_mn[crsplitinds], cr_ln[crsplitinds],
                                     'r')

            self.vecaxh.set_ylim([0, 1.2])

            if PLOT_SCATTER_POL:
                self.axhandles[4].plot(crdt['mot_deg'][minbnds][srtind],
                                       pol_sensor[minbnds][srtind])

                titlestr = 'period=%f/nentropy=%f' % (
                    self.calculated_motor_period, crdt['entropy'])
                self.axhandles[4].set_title(titlestr, fontsize=8)
            splitinds = np.array_split(
                allinds,
                np.array(np.where(np.diff(allinds) != 1))[0] + 1)
            for rotnum, crsplitinds in enumerate(splitinds):
                if np.size(crsplitinds):
                    self.axhandles[1].plot(plot_time[crsplitinds],
                                           crdt['mot_deg'][crsplitinds], 'k')
            self.plot_boundary_lines()
Exemplo n.º 4
0
    def assign_sumstats_crux(self, deg_per_bin, timevls):

        self.analinds = np.intersect1d(
            np.where(timevls > self.bndtimes[self.crkey][0])[0],
            np.where(timevls < self.bndtimes[self.crkey][1])[0])
        #self.analinds=nonaninds[tmpanalinds]

        crdeg = np.array(self.outdict['exp']['sumdeg'])[self.analinds]

        hstout_dt = calc.make_hist_calculations(crdeg, self.degbins)
        hstout_dt['start_rad'] = calc.rad_to_deg(
            circ.circmean(calc.deg_to_rad(crdeg[0:2])))

        self.make_sumstats_values(hstout_dt)

        self.sumstats[
            self.crkey]['steps_per_rotation'] = self.outdict['period']
        #TKTK save something here indicating index where experiment switched
        self.sumstats[self.crkey]['mean_deg'] = calc.rad_to_deg(
            self.sumstats[self.crkey]['mnrad'])
        self.sumstats[self.crkey]['fname'] = self.fname
        self.rad_per_bin = deg_per_bin * np.pi / 180
        self.sumstats[self.crkey]['rad_per_bin'] = deg_per_bin * np.pi / 180
        self.xrad = calc.deg_to_rad(self.degbins)
        self.sumstats[self.crkey]['xrad'] = calc.deg_to_rad(self.degbins)
        self.sumstats[self.crkey]['raw_time'] = np.array(
            self.crdata['time'])[self.analinds]
        try:
            self.sumstats[self.crkey]['time_in_min'] = np.array(
                self.crdata['net_time'])[self.analinds] / 60.0
        except:
            print('time error')

        self.sumstats[self.crkey]['lftwng'] = np.array(
            self.crdata['lftwng'])[self.analinds]
        self.sumstats[self.crkey]['rtwng'] = np.array(
            self.crdata['rtwng'])[self.analinds]

        self.sumstats[self.crkey]['mot_position_in_rad'] = np.array(
            self.crdata['adjusted_raw_motor_position_in_rad'])[self.analinds]

        if 'gain_coefficient' in self.crdata.keys():

            self.sumstats[self.crkey]['gain_coefficient'] = np.array(
                self.crdata['gain_coefficient'])[self.analinds]

        self.sumstats[self.crkey]['mot_deg'] = self.outdict['mot_deg'][
            self.analinds]

        self.sumstats[self.crkey]['mot_rad'] = np.array(
            self.outdict['mot_rad'])[self.analinds]
        try:

            self.sumstats[self.crkey]['cloop_duration_in_min'] = np.ceil(
                self.sumstats[self.skey]['time_in_min'][-1] -
                self.sumstats[self.skey]['time_in_min'][0])

            self.calculate_continuous_heading()
            self.sumstats[self.crkey][
                'displacement_traj'] = self.calc_displacement_trajectory()

            if 'len_vector_lst' in self.sumstats[self.crkey].keys():
                cr_ln = np.array(self.sumstats[self.crkey]['len_vector_lst'])

                cr_mn = np.array(self.sumstats[self.crkey]['mn_vector_lst'])

                threshinds = np.where(
                    np.array(cr_ln) > VEC_STRENGTH_THRESHOLD)[0]

                out_dt = calc.make_hist_calculations(
                    calc.rad_to_deg(cr_mn[threshinds]), self.degbins)

                self.sumstats[self.crkey]['vecmn'] = out_dt['mnrad']
                self.sumstats[self.crkey]['vechst'] = out_dt['normhst']
                self.sumstats[sef.crkey]['vecvar'] = out_dt['circvar']
        except:
            tst = 1
Exemplo n.º 5
0
    def make_raw_plot(self,flyindnum,exp_type_to_plot):
        ADD_VEC_TEXT=True
        #COLNUM=-1

        if self.crdt:


            for cr_fltnum in self.crdt.keys():

                if self.crdt[cr_fltnum]:




                    mnvl_in_rad=self.crdt[cr_fltnum]['mnrad_360']
                    if mnvl_in_rad>np.pi:
                        mnvl_in_rad=-(2*np.pi-mnvl_in_rad)
                    halt_flag=False

                    offset_time=0
                    if cr_fltnum==1:
                        offset_time=self.crdt[cr_fltnum-1]['time_in_min'][-1]
                    elif cr_fltnum>1:
                        offset_time=self.crdt[cr_fltnum-1]['time_in_min'][-1]-TIME_GAP
                    if flyindnum<len(self.axraw[exp_type_to_plot]['tmdt']):
                        try:
                            fpb.plot_motor(self.crdt[cr_fltnum],self.axraw[exp_type_to_plot]['tmdt'][self.crplotnum],plot_vector=False,plot_split=1,plot_start_angle=0,subtract_zero_time=True,offset_time=offset_time,plot_vert_line_at_end=True, halt_flag=halt_flag,center_on_zero_flag=True,withhold_bottom_axis=True)
                        except:
                            print('plot_motor error')
                        self.axraw[exp_type_to_plot]['tmdt'][self.crplotnum].set_xlim([0,15.5])


                        if ADD_VEC_TEXT:
                            crvec=1-self.crdt[cr_fltnum]['circvar_mod360']

                            self.axraw[exp_type_to_plot]['tmdt'][self.crplotnum].text(1.5*5*cr_fltnum,30,str(crvec))
                        #if COLNUM:

                         #   axmotor[crkey][flyindnum][COLNUM].axis('off')
                          #  axhist[crkey][flyindnum][COLNUM].axis('off')
                        mot_deg=calc.center_deg_on_zero(calc.rad_to_deg(self.crdt[cr_fltnum]['mot_rad']))
                        degbins=np.arange(-180,190,10)
                        tst=calc.make_hist_calculations(mot_deg,degbins)
                        deg_per_bin=10

                        tst['rad_per_bin']=deg_per_bin*np.pi/180

                        tst['xrad']=calc.deg_to_rad(degbins)
                        try:
                            crax=self.axraw[exp_type_to_plot]['hst'][self.crplotnum][cr_fltnum]
                        except:
                            print('ax assignment error')

                        crax.step(tst['normhst'],tst['xrad'][0:-1]+tst['rad_per_bin']/2,color='k',linewidth=0.5)
                        if PLOT_EX_TEXT_STR:
                            textax=self.axraw[exp_type_to_plot]['txt'][self.crplotnum]
                            txtfile=self.crdt[cr_fltnum]['fname'].split('/')[-1]
                            textax.text(0,0,txtfile,fontsize=4, rotation='vertical')
                            textax.set_ylim([-12,2])

                        #crax.step(self.crdt[cr_fltnum]['normhst'],self.crdt[cr_fltnum]['xrad'][0:-1]+self.crdt[cr_fltnum]['rad_per_bin']/2,'k',linewidth=0.5)
                        #self.col_num[crkey]=self.col_num[crkey]+1
                        fpl.adjust_spines(crax,[])
                        crax.set_ylim([-calc.deg_to_rad(180.),calc.deg_to_rad(180.0)])
                        crax.plot(0.21,mnvl_in_rad,'r<',clip_on=False)
                        crax.set_xlim([0,0.24])
            self.crplotnum=self.crplotnum+1