Example #1
0
        public Replay(Queue <string> originalTrackData, Queue <string> originalInfoData, OriginalType originalType, int originalLength, int frameRate, int pxPERmm, string folder, string name, string fishID) :
            base(folder, name, fishID, originalLength, frameRate, pxPERmm)
        {
            if (FileSaver != null)
            {
                _trackWriter      = FileSaver.GetStreamWriter(".track");
                _imageWriter      = FileSaver.GetTiffWriter("_camImage.tif", true);
                _backgroundWriter = FileSaver.GetTiffWriter("_bgImage.tif", true);
                //Create 10x10 mm region image
                _camRegion = new Image8(Properties.Settings.Default.PixelsPermm * 10, Properties.Settings.Default.PixelsPermm * 10);
            }
            _laser = new SDLPS500Controller(Properties.Settings.Default.DAQ, Properties.Settings.Default.LaserAO);
            string xchannel = Properties.Settings.Default.DAQ + "/" + Properties.Settings.Default.ScannerX;
            string ychannel = Properties.Settings.Default.DAQ + "/" + Properties.Settings.Default.ScannerY;

            //Load scan lookup table from file
            try
            {
                TextReader reader    = File.OpenText("main.calib");
                var        scanTable = BLIScanLookupTable.LoadFromFile(reader);
                _scanner = new RandomAccessScanner(scanTable, xchannel, ychannel, -10, 10);
                reader.Dispose();
            }
            catch (IOException)
            {
                System.Diagnostics.Debug.WriteLine("Could not find calibration data. No targeting available");
            }
            //This is a closed-loop experiment - try to stay fully up-to-date
            SuggestedBufferSeconds = 0;
            _originalType          = originalType;
            _originalTrackData     = originalTrackData;
            _originalInfoData      = originalInfoData;
            _experimentPhase       = ExperimentPhase.Replay;
        }
Example #2
0
    // updates the state of the experiment. returns true until the experiment is finished (should at best not be overwritten)
    public bool update()
    {
        if (pause)
        {
            pauseTime += Time.deltaTime;
        }
        else
        {
            pauseTime = 0;
        }

        ExperimentPhase phase = phaseIterator.Current;

        if (phase == null || Time.time - pauseTime >= startTime + phase.duration)
        {
            if (phaseIterator.MoveNext())
            {
                phase = phaseIterator.Current;
                phase.action.Invoke();
                startTime = Time.time;
                current++;
            }
            else
            {
                isFinished = true;
                writer.writeFooter(name);
                writer.close();
            }
        }

        return(!isFinished);
    }
 /// <summary>
 /// Processes one frame during the gradient
 /// </summary>
 private void RunGradient(BlobWithMoments fish)
 {
     //compute laser power based on distance from dish center
     if (fish != null)
     {
         var radius      = Math.Sqrt((fish.xc - DishCenter.x) * (fish.xc - DishCenter.x) + (fish.yc - DishCenter.y) * (fish.yc - DishCenter.y));
         var radFraction = radius / Radius;
         if (radFraction > 1)
         {
             radFraction = 1;
         }
         _laser.LaserPower = radFraction * (EdgeLaserPower - CenterLaserPower) + CenterLaserPower;
     }
     if (_currentPhaseFrame >= _gradFrames)
     {
         if (_currentTrial < _nTrials)
         {
             SwitchToPrePhase();
         }
         else
         {
             _laser.LaserPower = 0;
             _experimentPhase  = ExperimentPhase.Done;
         }
     }
     else
     {
         _currentPhaseFrame++;
     }
 }
Example #4
0
 /// <summary>
 /// Processes one frame during the replay experiment
 /// </summary>
 private void RunReplay(double originalPower)
 {
     _laser.LaserPower = originalPower;
     //If queue is empty now, change phase to done
     if (_originalTrackData.Count < 1)
     {
         _experimentPhase = ExperimentPhase.Done;
     }
 }
 /// <summary>
 /// Processes one frame during Pre-phase
 /// </summary>
 private void RunPrePhase()
 {
     //flat power corresponding to center power
     _laser.LaserPower = CenterLaserPower;
     if (_currentPhaseFrame >= _preFrames)
     {
         _currentPhaseFrame = 0;
         _experimentPhase   = ExperimentPhase.Gradient;
     }
     else
     {
         _currentPhaseFrame++;
     }
 }
 /// <summary>
 /// Processes one frame during RampDown
 /// </summary>
 private void RunRampDown()
 {
     //compute laser power as linear ramp over phase
     _laser.LaserPower = (1 - (double)_currentPhaseFrame / (double)_rampFrames) * (PeakLaserPower - BaseLaserPower) + BaseLaserPower;
     if (_currentPhaseFrame >= _rampFrames)
     {
         _currentPhaseFrame = 0;
         _experimentPhase   = ExperimentPhase.Rest;
     }
     else
     {
         _currentPhaseFrame++;
     }
 }
 /// <summary>
 /// Processes one frame during Rest
 /// </summary>
 private void RunRest()
 {
     _laser.LaserPower = BaseLaserPower;
     if (_currentPhaseFrame >= _restFrames)
     {
         if (_currentTrial < _nTrials)
         {
             SwitchToRampUp();
         }
         else
         {
             _laser.LaserPower = 0;
             _experimentPhase  = ExperimentPhase.Done;
         }
     }
     else
     {
         _currentPhaseFrame++;
     }
 }
        public CircularGradient(int habitSeconds, int preSeconds, int gradientSeconds, int nTrials, int frameRate, int pxPERmm, string folder, string name, string fishID) :
            base(folder, name, fishID, habitSeconds + (preSeconds + gradientSeconds) * nTrials, frameRate, pxPERmm)
        {
            if (FileSaver != null)
            {
                _trackWriter      = FileSaver.GetStreamWriter(".track");
                _imageWriter      = FileSaver.GetTiffWriter("_camImage.tif", true);
                _backgroundWriter = FileSaver.GetTiffWriter("_bgImage.tif", true);
                //Create 10x10 mm region image
                _camRegion = new Image8(Properties.Settings.Default.PixelsPermm * 10, Properties.Settings.Default.PixelsPermm * 10);
            }
            _laser = new SDLPS500Controller(Properties.Settings.Default.DAQ, Properties.Settings.Default.LaserAO);
            string xchannel = Properties.Settings.Default.DAQ + "/" + Properties.Settings.Default.ScannerX;
            string ychannel = Properties.Settings.Default.DAQ + "/" + Properties.Settings.Default.ScannerY;

            //Load scan lookup table from file
            try
            {
                TextReader reader    = File.OpenText("main.calib");
                var        scanTable = BLIScanLookupTable.LoadFromFile(reader);
                _scanner = new RandomAccessScanner(scanTable, xchannel, ychannel, -10, 10);
                reader.Dispose();
            }
            catch (IOException)
            {
                System.Diagnostics.Debug.WriteLine("Could not find calibration data. No targeting available");
            }
            _preFrames         = preSeconds * FrameRate;
            _gradFrames        = gradientSeconds * FrameRate;
            _habitFrames       = habitSeconds * FrameRate;
            _nTrials           = nTrials;
            _currentPhaseFrame = 0;
            _currentTrial      = 0;//Start at 0 during habituation will be pre-incremented as we enter pre-phase and will be checked for completing at end of gradient phase
            //This is a closed-loop experiment - try to stay fully up-to-date
            SuggestedBufferSeconds = 0;
            //Start in habituation phase
            _experimentPhase = ExperimentPhase.Habituation;
        }
 /// <summary>
 /// Switches phase to pre-gradient marking the begin of a new trial
 /// </summary>
 private void SwitchToPrePhase()
 {
     _experimentPhase   = ExperimentPhase.Pre;
     _currentPhaseFrame = 0;
     _currentTrial++;
 }
 /// <summary>
 /// Switches phase to ramp-up marking the begin of a new trial
 /// </summary>
 private void SwitchToRampUp()
 {
     _experimentPhase   = ExperimentPhase.RampUp;
     _currentPhaseFrame = 0;
     _currentTrial++;
 }