示例#1
0
        public void LoadData(IMouseDataExtendedResult data)
        {
            StartFrame = 0;
            KeyValuePair <int, ISingleFrameExtendedResults> kvp = data.Results.FirstOrDefault(x => x.Value.HeadPoints == null);

            if (kvp.Equals(default(KeyValuePair <int, ISingleFrameExtendedResults>)))
            {
                EndFrame = data.Results.Count;
            }
            else
            {
                EndFrame = kvp.Key;
            }

            RepeatSmooths             = 1;
            Data                      = data;
            MaxVelocity               = data.MaxSpeed;
            MaxCentroidVelocity       = data.MaxCentroidSpeed;
            MaxAngularVelocity        = data.MaxAngularVelocty;
            AverageVelocity           = data.AverageVelocity;
            AverageCentroidVelocity   = data.AverageCentroidVelocity;
            AverageAngularVelocity    = data.AverageAngularVelocity;
            DistanceTravelled         = data.DistanceTravelled;
            CentroidDistanceTravelled = data.CentroidDistanceTravelled;
            OriginalFrameRate         = data.FrameRate;
            UnitsToMm                 = data.UnitsToMilimeters;

            StatGenerator stat = new StatGenerator();

            stat.StartFrame        = StartFrame;
            stat.EndFrame          = EndFrame;
            stat.SmoothingFunction = SelectedSmoothingFunction;
            stat.UseDft            = UseDft;
            stat.SmoothRepeats     = RepeatSmooths;

            stat.Generate(data.Results, OriginalFrameRate);

            IWhiskerAverageAngles angles = new WhiskerAverageAngles();

            angles.StartFrame = 0;
            angles.EndFrame   = data.Results.Count - 1;
            var allAngles = angles.GetWhiskerAngles(data.Results);

            LoadData(allAngles[0], allAngles[1]);


            LeftWhiskerAmplitude               = stat.LeftWhiskerAmplitude;
            RightWhiskerAmplitude              = stat.RightWhiskerAmplitude;
            LeftWhiskerAvgAngularVelocity      = stat.LeftAverageAngularVelocity;
            RightWhiskerAvgAngularVelocity     = stat.RightAverageAngularVelocity;
            LeftWhiskerAvgProtractionVelocity  = stat.LeftAverageProtractionVelocity;
            RightWhiskerAvgProtractionVelocity = stat.RightAverageProtractionVelocity;
            LeftWhiskerAvgRetractionVelocity   = stat.LeftAverageRetractionVelocity;
            RightWhiskerAvgRetractionVelocity  = stat.RightAverageRetractionVelocity;
            LeftWhiskerFrequency               = stat.LeftWhiskerFrequency;
            RightWhiskerFrequency              = stat.RightWhiskerFrequnecy;
            LeftWhiskerMeanOffset              = stat.LeftMeanOffset;
            RightWhiskerMeanOffset             = stat.RightMeanOffset;

            UpdateSmoothing();
        }
示例#2
0
        public double[][] Generate(Dictionary <int, ISingleFrameExtendedResults> results, double frameRate, bool onlyForInteracting = false)
        {
            //Get signal
            IWhiskerAverageAngles angles = new WhiskerAverageAngles();

            angles.StartFrame = StartFrame;
            angles.EndFrame   = EndFrame;
            var allAngles = angles.GetWhiskerAngles(results, onlyForInteracting);

            if (allAngles == null || !allAngles.Any() || (allAngles[0].Count == 0 && allAngles[1].Count == 0))
            {
                return(null);
            }

            LeftSignal  = allAngles[0].Select(x => x.Value).ToArray();
            RightSignal = allAngles[1].Select(x => x.Value).ToArray();

            double[] leftSignal  = LeftSignal;
            double[] rightSignal = RightSignal;
            if (SmoothingFunction != null)
            {
                for (int i = 0; i < SmoothRepeats; i++)
                {
                    leftSignal  = SmoothingFunction.Smooth(leftSignal);
                    rightSignal = SmoothingFunction.Smooth(rightSignal);
                }
            }

            LeftSignal  = leftSignal;
            RightSignal = rightSignal;

            IFrequency frequency = new Frequency();

            frequency.UseDft    = false;
            frequency.Signal    = LeftSignal;
            frequency.FrameRate = frameRate;
            frequency.UseDft    = UseDft;
            double[] leftZeroed, rightZeroed;
            double   lefFequency = frequency.GetFrequency(out leftZeroed);

            frequency.Signal = RightSignal;
            double rightFrequency = frequency.GetFrequency(out rightZeroed);

            Console.WriteLine($"Left Freq: {lefFequency}, Right freq: {rightFrequency}");
            LeftWhiskerFrequency  = lefFequency;
            RightWhiskerFrequnecy = rightFrequency;

            //Get amplitude
            Amplitude amp = new Amplitude();

            LeftWhiskerAmplitude  = amp.GetMaxAmpitude(LeftSignal);
            RightWhiskerAmplitude = amp.GetMaxAmpitude(RightSignal);

            //Get mean offset
            MeanOffset offSet = new MeanOffset();

            LeftMeanOffset  = offSet.GetMeanOffset(LeftSignal);
            RightMeanOffset = offSet.GetMeanOffset(RightSignal);

            SingleWhiskerProtractionRetraction proRetLeft  = new SingleWhiskerProtractionRetraction();
            SingleWhiskerProtractionRetraction proRetRight = new SingleWhiskerProtractionRetraction();

            proRetLeft.FrameRate    = 500;
            proRetRight.FrameRate   = 500;
            proRetLeft.AngleSignal  = LeftSignal;
            proRetRight.AngleSignal = RightSignal;

            LeftAverageAngularVelocity     = proRetLeft.MeanAngularVelocity;
            LeftAverageProtractionVelocity = proRetLeft.MeanProtractionVelocity;
            LeftAverageRetractionVelocity  = proRetLeft.MeanRetractionVelocity;

            RightAverageAngularVelocity     = proRetRight.MeanAngularVelocity;
            RightAverageProtractionVelocity = proRetRight.MeanProtractionVelocity;
            RightAverageRetractionVelocity  = proRetRight.MeanRetractionVelocity;


            return(new double[][] { leftZeroed, rightZeroed });
        }