// This line is not used // // // PKZ_WINDS for zenith only // // A script to manage a night of observations. The script sets up the required directories and log files, calculates // start and stop times for the observations, handles the observations, and then reloads itself for the next night. // // The following code has an OVERLAY of this script file at the end which allows convenient modification of the script. // It also serves to recalculate twilight and night times every day // 24 May 2010 // // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Below are variables that may need to be modified to fit the specific system being used. // Create the directory to save tonights data into d = DateToInteger($CurrentTime) date = ConvertToString("%8d",d) dirImages = "C:\\PKZdata2014_fall\\" + date LOG_DIRECTORY Master,dirImages // Variables specific to this FPI for the log files logDir = "C:\\PKZPrograms\\Logs" logID = "PKZ" logIDD = "PKZ_" logOrder = 321 PHLasAz = 101. //was 103. count range of 0 to 4 seen // These values need to be checked! -178 might work also for Ze angle PHLasZe = 179. // Define the exposure time for the bias image BiasTime = 0.01 // Desired temperature for the CCD DesiredCCDTemperature = -75.0 // The number of exposure in each cycle (this should be the // number of data look directions. // Laser calibrations are not included in this variable. // nExposuresInCycle = 10 // The number of seconds, per exposure, to add into // the cycle time to account for things like moving the // SkyScanner and reading out the image ExposureOverhead = 6 // The number of auxiliary images (laser, dark) taken per cycle nAuxilaryInCycle = 1; // just laser // You shouldn't have to make modifications below this line. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// lastimageFile = logID + "_LastImage.txt" // Create the various log files LOG_DIRECTORY Master,logDir,logID,logOrder LOG_DIRECTORY MasterUser2, logDir,lastimageFile, 3 LOG_DIRECTORY Observatory,logDir,logID,logOrder LOG_DIRECTORY Camera,logDir,logID,logOrder LOG_DIRECTORY Analyze,logDir,logID,logOrder LOG_DIRECTORY Communicate,logDir,logID,logOrder DELAY 25 // Load in automatic start & stop times based upon the sun's position. // Variables set from this function are // startTime, twilightTime, beginNightTime, endNightTime, and endTime CALL "TwilightNightTimes.txt" // Save the dates into variables DateStart = DateToInteger(beginNightTime) DateEnd = DateToInteger(endNightTime) TimeStart = TimeToInteger(beginNightTime)/1000 TimeEnd = TimeToInteger(endNightTime)/1000 DateStart = ConvertToString("%8d",DateStart) TimeStart = ConvertToString("%6d",TimeStart) DateEnd = ConvertToString("%8d",DateEnd) TimeEnd = ConvertToString("%6d",TimeEnd) LOG_DISPLAY 1 "Start: " + TimeStart+ " " + DateStart + " End: "+TimeEnd + " " + DateEnd // Load in exposure times ControlFileRead("XTimes.txt","xTimeLaser","xTime630","xTimeDark") /// Define image-type counters. I.e. in L07302005001.img, 001 is the ImageSeqeuence counter ImageSequenceL = 0 // L refers to laser images ImageSequenceB = 0 // B refers to bias images ImageSequenceX = 0 // X refers to 630 images ImageSequenceD = 0 // D refers to dark count image in sky mode ImageSequenceF = 0 // F refers to flat-field images ImageSequenceK = 0 // K refers to laser dark image // Initialize the iCycle counter which counts the position within the observing cycle. iCycle=-1 // Read in the direction file containing (az,ze) for each direction in the observing cycle. CALL "NextPositionInCycle" if(endNightTime < beginNightTime) { // We are already after local twilight. Set the // start time back one day, as the calculated start time // is for tomorrow's sunset beginNightTime = beginNightTime - 86400 } // Before observations, we need to initialize the // camera and sky scanner. This takes some time, so we will // start some of this housekeeping 20 minutes // before datataking should commence. beginHousekeepingTime = beginNightTime - 1200 WAIT_UNTIL beginHousekeepingTime // Clear quick look graphics in the analyze program SETUP ANALYZE // Initialize the Andor camera and turn on cooling SETUP CAMERA FPI SETUP COOLER FPI // Get the current status of the Andora camera after initialization GET_STATUS CAMERA FPI, TEMPERATURE, temperature GET_STATUS CAMERA FPI, STATE, CurrentState // Allow cooler to cool down, checking status // every 30 seconds. Let it reach the desired // temperature or time out if we are getting // too close (within 12 minutes) to the data collection time CoolingStatus = 0 while(CoolingStatus == 0) { GET_STATUS CAMERA FPI, TEMPERATURE, temperature if(temperature <= DesiredCCDTemperature) { CoolingStatus = 1 } if(beginNightTime - $CurrentTime < 720.) { CoolingStatus = 1 } DELAY 30 } GET_STATUS CAMERA FPI, TEMPERATURE,CurrentTemp GET_STATUS CAMERA FPI, STATE, CurrentState // Take a bias image xTime = BiasTime SET_PARAMETER CAMERA FPI, ShutterMode = CLOSE SET_PARAMETER CAMERA FPI, ExposureTime = xTime datatype = "B" tagtype = "B" ImageSequenceB = ImageSequenceB + 1 seq = ImageSequenceB CALL "AcquireStoreDisplayImageNATION_Alaska" LOG_OUTPUT ANALYZE, OPEN // Take an initial dark count image xTime = xTimeDark SET_PARAMETER CAMERA FPI, ShutterMode = CLOSE SET_PARAMETER CAMERA FPI, ExposureTime = xTime datatype = "D" tagtype = "D" ImageSequenceD = ImageSequenceD + 1 seq = ImageSequenceD CALL "AcquireStoreDisplayImageNATION_Alaska" // Take an initial dark count image for laser exposure xTime = xTimeLaser SET_PARAMETER CAMERA FPI, ShutterMode = CLOSE SET_PARAMETER CAMERA FPI, ExposureTime = xTime datatype = "K" tagtype = "K" ImageSequenceK = ImageSequenceK + 1 seq = ImageSequenceK CALL "AcquireStoreDisplayImageNATION_Alaska" // Take an initial laser calibration MOVE_PH PHLasAz,PHLasZe xTime = xTimeLaser SET_PARAMETER CAMERA FPI, ShutterMode = AUTO SHUTTER Laser, OPEN // Open the USB LASER shutter (not camera //shutter) SET_PARAMETER CAMERA FPI, ExposureTime = xTime datatype = "L" tagtype = "L" ImageSequenceL = ImageSequenceL + 1 seq = ImageSequenceL CALL "AcquireStoreDisplayImageNATION_Alaska" SHUTTER Laser, CLOSE // Close the LASER shutter (not camera shutter) MOVE_PH PHLasAz,0. // move SS back to zenith for zenith images // Now that we have done the initial housekeeping, wait until observation should commence WAIT_UNTIL beginNightTime // Begin night-time operation iseq = 0 while($CurrentTime < endNightTime) { // Within this loop, we will take one complete cycle of exposures (defined in the positions file) // and then one laser image. We will // synchronize so that the sequence will pause after each image to a predefined time //and that the entire cycle will pause until a // predefined time. This will help synchronize FPIs observing from different locations. // Read in the exposure times. This allows for alteration in the midst of running the program. ControlFileRead("XTimes.txt","xTimeLaser","xTime630","xTimeDark") // Initialize the position in the cycle iCycle = 0; // Calculate when we want this cycle to end. This should account //for all of the images (exposure, dark, laser) to be // taken, as well as enough overhead time to make sure we have a pause at the end of the cycle. // Currently, we account for the exposures, one laser exposure, and //then (10 + 1 + 1) overheads for (nExposuresInCycle + laser image + extra buffer) // endCycleTime=$CurrentTime+nExposuresInCycle*xTime630+xTimeLaser+(nExposuresInCycle+nAuxilaryInCycle+1)*ExposureOverhead // We keep track of the time the last image in the cycle ended. //Right now, we are at the beginning of a cycle, which will be used as the initialization value. lastImageStopTime = $CurrentTime // Loop through each position in this cycle and take the requested number of exposures per cycle iExposures = 0 while(iExposures < nExposuresInCycle) { // Figure out when this exposure should end. // Account for the exposure time and then some overhead // as well as reading out the image. // endExposureTime = lastImageStopTime + xTime630 + ExposureOverhead // Log that we are taking another image CycleString=ConvertToString("%3d",iCycle) LOG_DISPLAY 2 " Cycle pos. #: " + CycleString // Read from the next (az,ze) pair from the positions file - need iCycle for this subroutine CALL "NextPositionInCycle" MOVE_PH az, ze // move SkyScanner to next position if($CurrentTime= nExposuresInCycle) { iCycle = 0 } } // END of iExposures WHILE loop // Just ended a sequence through the cycle. Count it and send a message to the log iseq = iseq + 1 TimeCycle = TimeToInteger($CurrentTime)/1000 TimeCycleString = ConvertToString("%9d",TimeCycle) iseqString = ConvertToString("%3d",iseq) LOG_DISPLAY 3 " Cycle " + iseqString + " " + TimeCycleString /// Laser Calibration xTime = xTimeLaser SET_PARAMETER CAMERA FPI, ShutterMode = AUTO MOVE_PH PHLasAz, PHLasZe SHUTTER Laser, OPEN // Open the LASER shutter (not camera shutter) SET_PARAMETER CAMERA FPI, ExposureTime = xTime datatype = "L" tagtype = "L" ImageSequenceL = ImageSequenceL + 1 seq = ImageSequenceL CALL "AcquireStoreDisplayImageNATION_Alaska" SHUTTER Laser, CLOSE // Close the USB LASER shutter (not camera shutter!) MOVE_PH PHLasAz, 0. DELAY 3 // to give SS time to get to destination } // end of 630 night cycle (outermost WHILE loop) // one more dark image xTime = xTimeDark SET_PARAMETER CAMERA FPI, ShutterMode = CLOSE SET_PARAMETER CAMERA FPI, ExposureTime = xTime datatype = "D" tagtype = "D" ImageSequenceD = ImageSequenceD + 1 seq = ImageSequenceD CALL "AcquireStoreDisplayImageNATION_Alaska" // Laser Dark count xTime = xTimeLaser SET_PARAMETER CAMERA FPI, ShutterMode = CLOSE SET_PARAMETER CAMERA FPI, ExposureTime = xTime datatype = "K" tagtype = "K" ImageSequenceK = ImageSequenceK + 1 seq = ImageSequenceK CALL "AcquireStoreDisplayImageNATION_Alaska" // End night-time operations // BEGIN shutdown SHUTDOWN COOLER FPI GET_STATUS CAMERA FPI, TEMPERATURE, temperature GET_STATUS CAMERA FPI, STATE, CurrentState while(temperature<0.) { GET_STATUS CAMERA FPI, TEMPERATURE, temperature DELAY 30 } // ENDWHILE SHUTDOWN CAMERA FPI // be sure, wait for cooler warmup to take place LOG_OUTPUT OBSERVATORY, ClOSE LOG_OUTPUT CAMERA, CLOSE LOG_OUTPUT MASTER, CLOSE LOG_OUTPUT ANALYZE, CLOSE // LOG_OUTPUT COMMUNICATE, CLOSE LOG_OUTPUT OBSERVATORY, OPEN LOG_OUTPUT CAMERA, OPEN LOG_OUTPUT MASTER, OPEN // LOG_OUTPUT COMMUNICATE, OPEN zipDir = "C:\\PKZImagesCompressed\\" zipFilename = "PKZ_"+date + ".zip" //----------- st=FileXferStatus(0) // these should both be -1 (no status, because xfer hasn't taken place) st=FileXferStatus(1) DELAY 2 // command syntax FILE_COMPRESS imageDir, "*.img", zipDir, zipFilename FILE_COMPRESS dirImages, "*.img", zipDir, zipFilename twait = 400 // Check send status periodically for 60 sec for (i=0; i