@@ -43,13 +43,20 @@ def unmask_track(track):
4343 comp_y = ma .compressed (ma .masked_where (x_mask , track ['Y' ]))
4444 comp_msd = ma .compressed (ma .masked_where (msd_mask , track ['MSDs' ]))
4545 comp_gauss = ma .compressed (ma .masked_where (msd_mask , track ['Gauss' ]))
46+ comp_qual = ma .compressed (ma .masked_where (x_mask , track ['Quality' ]))
47+ comp_snr = ma .compressed (ma .masked_where (x_mask , track ['SN_Ratio' ]))
48+ comp_meani = ma .compressed (ma .masked_where (x_mask ,
49+ track ['Mean_Intensity' ]))
4650
4751 data1 = {'Frame' : comp_frame ,
4852 'Track_ID' : compid ,
4953 'X' : comp_x ,
5054 'Y' : comp_y ,
5155 'MSDs' : comp_msd ,
52- 'Gauss' : comp_gauss
56+ 'Gauss' : comp_gauss ,
57+ 'Quality' : comp_qual ,
58+ 'SN_Ratio' : comp_snr ,
59+ 'Mean_Intensity' : comp_meani
5360 }
5461 comp_track = pd .DataFrame (data = data1 )
5562 return comp_track
@@ -712,7 +719,7 @@ def msd_ratio(track, fram1=3, fram2=100):
712719 return ratio
713720
714721
715- def calculate_features (dframe , framerate = 1 ):
722+ def calculate_features (dframe , framerate = 1 , frame = ( 10 , 100 ) ):
716723 """Calculates multiple features from input MSD dataset and stores in pandas
717724 dataframe.
718725
@@ -727,6 +734,8 @@ def calculate_features(dframe, framerate=1):
727734 Required for accurate calculation of some features. Default is 1.
728735 Possibly not required. Ignore if performing all calcuations without
729736 units.
737+ frame : int
738+ Frame at which to calculate Deff
730739
731740 Returns
732741 -------
@@ -763,7 +772,12 @@ def calculate_features(dframe, framerate=1):
763772 'MSD_ratio' : holder ,
764773 'frames' : holder ,
765774 'X' : holder ,
766- 'Y' : holder }
775+ 'Y' : holder ,
776+ 'Quality' : holder ,
777+ 'Mean_Intensity' : holder ,
778+ 'SN_Ratio' : holder ,
779+ 'Deff1' : holder ,
780+ 'Deff2' : holder }
767781
768782 datai = pd .DataFrame (data = die )
769783
@@ -799,14 +813,31 @@ def calculate_features(dframe, framerate=1):
799813 else :
800814 datai ['MSD_ratio' ][particle ] = np .nan
801815
816+ try :
817+ datai ['Deff1' ][particle ] = single_track ['MSDs' ][frame [0 ]] / (4 * frame [0 ])
818+ except :
819+ datai ['Deff1' ][particle ] = np .nan
820+
821+ try :
822+ datai ['Deff2' ][particle ] = single_track ['MSDs' ][frame [1 ]] / (4 * frame [1 ])
823+ except :
824+ datai ['Deff2' ][particle ] = np .nan
825+
826+ datai ['Mean_Intensity' ][particle ] = np .nanmean (single_track [
827+ 'Mean_Intensity' ].replace ([np .inf , - np .inf ], np .nan ).dropna (how = "all" ).values )
828+ datai ['Quality' ][particle ] = np .nanmean (single_track [
829+ 'Quality' ].replace ([np .inf , - np .inf ], np .nan ).dropna (how = "all" ).values )
830+ datai ['SN_Ratio' ][particle ] = np .nanmean (single_track [
831+ 'SN_Ratio' ].replace ([np .inf , - np .inf ], np .nan ).dropna (how = "all" ).values )
832+
802833 return datai
803834
804835
805836def feature_violin (tgroups , feature = 'boundedness' ,
806837 labels = ['sample 1' , 'sample 2' , 'sample 3' ],
807- points = 40 , ylim = [0 , 1 ]):
838+ points = 40 , ylim = [0 , 1 ], nticks = 11 ):
808839 '''Plots violin plots of features in comparison groups
809-
840+
810841 Parameters
811842 ----------
812843 tgroups : dict of pandas.core.frames.DataFrame
@@ -820,33 +851,33 @@ def feature_violin(tgroups, feature='boundedness',
820851 Determines resolution of violin plot
821852 ylim : list of int
822853 Y range of output plot
823-
854+
824855 '''
825856
826- majorticks = np .linspace (0 , ylim [1 ], 11 )
857+ majorticks = np .linspace (ylim [ 0 ] , ylim [1 ], nticks )
827858 to_graph = []
828859 pos = []
829860 counter = 1
830861 for key in tgroups :
831- to_graph .append (tgroups [key ][feature ]. dropna (). tolist () )
862+ to_graph .append (tgroups [key ][feature ][ tgroups [ key ][ feature ] < 10000 ]. replace ([ np . inf , - np . inf ], np . nan ). dropna (). values )
832863 pos .append (counter )
833864 counter = counter + 1
834-
865+
835866 def set_axis_style (ax , labels ):
836867 ax .get_xaxis ().set_tick_params (direction = 'out' )
837868 ax .xaxis .set_ticks_position ('bottom' )
838869 ax .set_xticks (np .arange (1 , len (labels ) + 1 ))
839870 ax .set_xticklabels (labels )
840871 ax .set_xlim (0.25 , len (labels ) + 0.75 )
841-
872+
842873 fig , axes = plt .subplots (nrows = 1 , ncols = 1 , figsize = (6 , 6 ))
843874
844875 axes .violinplot (to_graph , pos , points = points , widths = 0.9 ,
845876 showmeans = True , showextrema = False )
846877 set_axis_style (axes , labels )
847- axes .tick_params (axis = 'both' , which = 'major' ,
848- labelsize = 16 )
878+ axes .tick_params (axis = 'both' , which = 'major' ,
879+ labelsize = 16 )
849880 axes .set_ylim (ylim )
850881 axes .set_yticks (majorticks )
851-
852- plt .show ()
882+
883+ plt .show ()
0 commit comments