Exemple #1
0
    def getTimings(self):
        """
        Used to get the actual time in seconds the exposure will take.
        """
        # retval, width, height = andor.GetDetector()
        # print retval, width, height
        expTime, accTime, kTime = andor.GetAcquisitionTimings()
        logger.debug(str(expTime) + " " + str(accTime) + " " + str(kTime))

        return "timings"
Exemple #2
0
    def getHeader(self, attributes):
        """
        Pre: Takes in a list of attributes: [imType, binning, itime]
        Post: Returns an AstroPy header object to be used for writing to.
        """
        imType, binning, itime, filter = attributes[0], attributes[
            1], attributes[2], attributes[3]
        # make new fits header object
        header = fits.Header()
        ut_time = time.gmtime()  # get UT time
        dateObs = time.strftime("%Y-%m-%dT%H:%M:%S", ut_time)
        ut_str = time.strftime("%H:%M:%S", ut_time)
        header.append(card=("DATE-OBS", dateObs, "Time at start of exposure"))
        header.append(card=("UT", ut_str, "UT time at start of exposure"))
        header.append(card=("OBSERVAT", "mro", "per the iraf list"))
        header.append(card=("IMAGETYP", imType))
        header.append(card=("FILTER", filter))
        header.append(card=("BINX", binning, "Horizontal Binning"))
        header.append(card=("BINY", binning, "Vertical Binning"))
        header.append(card=("EXPTIME", itime, "Total exposure time"))
        header.append(card=("ACQMODE", "Single Scan", "Acquisition mode"))
        header.append(card=("READMODE", "Image", "Readout mode"))
        header.append(card=("INSTRUME", "evora",
                            "Instrument used for imaging"))
        header.append(card=("LATITUDE", self.config.get(section, 'latitude'),
                            "Decimal degrees of MRO latitude"))
        header.append(card=("LONGITUD", self.config.get(section, 'longitude'),
                            "Decimal degress of MRO longitude"))

        # get readout time and temp
        temp = andor.GetTemperatureStatus()[1]
        readTime = andor.GetAcquisitionTimings()[3] - itime
        header.append(card=("TEMP", temp, "Temperature"))
        header.append(card=("READTIME", readTime, "Pixel readout time"))

        return header
Exemple #3
0
    def kseriesExposure(self,
                        protocol,
                        imType,
                        itime,
                        filter="",
                        readTime=3,
                        numexp=1,
                        binning=1,
                        numAccum=1,
                        accumCycleTime=0,
                        kCycleTime=0):
        """
        This handles multiple image acquisition using the camera kinetic series capability.  The basic arguements are
        the passed in protocol, the image type, integration time, filter type, readout index, number of exposures, and binning type.

        In the future this function could be modified to include accumulations or add time the kinetic cycle time.  Accumulations
        are how many images should be readout as one, and kCycleTime can add time between each exposure that is taken.
        """
        global isAborted
        isAborted = False
        retval, width, height = andor.GetDetector()
        logger.debug('GetDetector: ' + str(retval) + " " + str(width) + " " + str(height))

        logger.debug("SetAcquisitionMode: " + str(andor.SetAcquisitionMode(3)))
        logger.debug('SetReadMode: ' + str(andor.SetReadMode(4)))

        logger.debug(
            'SetImage: ' + str(andor.SetImage(binning, binning, 1, width, 1, height)))
        logger.debug('GetDetector (again): ' + str(andor.GetDetector()))

        if imType == "bias":
            itime = 0
            andor.SetShutter(
                1, 2, 0, 0
            )  # TLL mode high, shutter mode Permanently Closed, 0 millisec open/close
            logger.debug('SetExposureTime: ' + str(andor.SetExposureTime(0)))
        else:
            if imType in ['flat', 'object']:
                andor.SetShutter(1, 0, 5, 5)
            else:
                andor.SetShutter(1, 2, 0, 0)
            logger.debug(
                'SetExposureTime: ' + str(andor.SetExposureTime(itime))
            )  # TLL mode high, shutter mode Fully Auto, 5 millisec open/close

        logger.debug("SetNumberOfAccumulations: " + str(andor.SetNumberAccumulations(numAccum)))  # number of exposures to be combined
        logger.debug("SetAccumulationTime: " + str(andor.SetAccumulationCycleTime(accumCycleTime)))
        logger.debug("SetNumberOfKinetics: " + str(andor.SetNumberKinetics(numexp)))  # this is the number of exposures the user wants
        logger.debug('SetKineticTime: ' + str(andor.SetKineticCycleTime(accumCycleTime)))
        logger.debug("SetTriggerMode: " + str(andor.SetTriggerMode(0)))
        logger.debug("Timings: " + str(andor.GetAcquisitionTimings()))
        logger.debug("SetHSSpeed: " + str(andor.SetHSSpeed(0, readTime)))  # default readTime is index 3 which is 0.5 MHz or ~6 sec

        # write headers
        attributes = [imType, binning, itime, filter]
        # header = self.getHeader(attributes)
        header = self.getHeader_2(attributes, 'heimdall')

        logger.debug('StartAcquisition: ' + str(andor.StartAcquisition()))

        status = andor.GetStatus()
        logger.debug(str(status))

        imageAcquired = False

        counter = 1
        while status[1] == andor.DRV_ACQUIRING:
            status = andor.GetStatus()
            progress = andor.GetAcquisitionProgress()

            runtime = 0
            if progress[2] == counter or (not isAborted and progress[2] == 0 and imageAcquired):
                runtime -= time.clock()
                data = np.zeros(width // binning * height // binning,
                                dtype='uint16')  # reserve room for image
                results = andor.GetMostRecentImage16(data)  # store image data
                logger.debug(
                    str(results) + " " + 'success={}'.format(results == 20002)
                )  # print if the results were successful
                logger.debug('image number: ' + str(progress[2]))

                if results == andor.DRV_SUCCESS:  # if the array filled store successfully
                    data = data.reshape(width // binning, height // binning)  # reshape into image
                    logger.debug(str(data.shape) + " " + str(data.dtype))

                    hdu = fits.PrimaryHDU(data,
                                          do_not_scale_image_data=True,
                                          uint=True,
                                          header=header)
                    # filename = time.strftime('/data/forTCC/image_%Y%m%d_%H%M%S.fits')
                    filename = fits_utils.get_image_path('series')
                    hdu.writeto(filename, clobber=True)

                    logger.debug("wrote: {}".format(filename))

                    protocol.sendData("seriesSent" + str(counter) + " " + str(counter) + "," + str(itime) + "," + filename)
                    # make a new header and write time to it for new exposure.
                    # header = self.getHeader(attributes)
                    header = self.getHeader_2(attributes, 'heimdall')

                    if counter == numexp:
                        logger.info("entered abort")
                        isAborted = True

                    imageAcquired = True
                    counter += 1
                runtime += time.clock()
                logger.debug("Took %f seconds to write." % runtime)
        return "series 1," + str(counter)  # exits with 1 for success
Exemple #4
0
    def expose(self,
               imType=None,
               expnum=None,
               itime=2,
               binning=1,
               filter="",
               readTime=3):
        """
        expNum is deprecated and should be removed.
        This handles a single exposure and no more.  Inputs are the image type integration time, binning type
        filter type, as a string, and the index for the specified horizontal readout time.
        """
        elapse_time = 0 - time.clock()
        if expnum is None:
            self.num += 1
            expnum = self.num
        else:
            self.num = expnum

        if imType is None:  # if the image type is not specified it defaults to object
            imType = "object"

        retval, width, height = andor.GetDetector()
        logger.debug('GetDetector: ' + str(retval) + " " + str(width) + " " + str(height))
        # print 'SetImage:', andor.SetImage(1,1,1,width,1,height)
        logger.debug('SetReadMode: ' + str(andor.SetReadMode(4)))
        logger.debug('SetAcquisitionMode: ' + str(andor.SetAcquisitionMode(1)))
        logger.debug(
            'SetImage: ' + str(andor.SetImage(binning, binning, 1, width, 1, height)))
        logger.debug('GetDetector (again): ' + str(andor.GetDetector()))

        if imType == "bias":
            andor.SetShutter(
                1, 2, 0, 0
            )  # TLL mode high, shutter mode Permanently Closed, 0 millisec open/close
            logger.debug('SetExposureTime: ' + str(andor.SetExposureTime(0)))
        else:
            if imType in ['flat', 'object']:
                andor.SetShutter(1, 0, 5, 5)
            else:
                andor.SetShutter(1, 2, 0, 0)
            logger.debug(
                'SetExposureTime: ' + str(andor.SetExposureTime(itime))
            )  # TLL mode high, shutter mode Fully Auto, 5 millisec open/close

        # set Readout speeds 0, 1, 2, or 3
        # print("SetVSSpeed:", andor.SetVSSpeed(3))
        logger.debug(
            "SetHSSpeed: " + str(andor.SetHSSpeed(0, readTime))
        )  # default readTime is index 3 which is 0.5 MHz or ~6 sec

        results, expTime, accTime, kTime = andor.GetAcquisitionTimings()
        logger.debug("Adjusted Exposure Time: " + str([results, expTime, accTime, kTime]))

        attributes = [imType, binning, itime, filter]
        # header = self.getHeader(attributes)
        header = self.getHeader_2(attributes, 'heimdall')

        logger.debug('StartAcquisition: ' + str(andor.StartAcquisition()))

        status = andor.GetStatus()
        logger.debug(str(status))
        while status[1] == andor.DRV_ACQUIRING:
            status = andor.GetStatus()

        data = np.zeros(width // binning * height // binning, dtype='uint16')
        logger.debug(str(data.shape))
        result = andor.GetAcquiredData16(data)

        success = None
        if result == 20002:
            success = 1  # for true
        else:
            success = 0  # for false

        logger.debug(str(result) + 'success={}'.format(result == 20002))
        filename = None
        if success == 1:
            data = data.reshape(width // binning, height // binning)
            #data = np.fliplr(data)
            logger.debug(str(data.shape) + " " + str(data.dtype))
            hdu = fits.PrimaryHDU(data,
                                  do_not_scale_image_data=True,
                                  uint=True,
                                  header=header)
            # filename = time.strftime('/data/forTCC/image_%Y%m%d_%H%M%S.fits')
            filename = fits_utils.get_image_path('expose')
            hdu.writeto(filename, clobber=True)
            logger.debug("wrote: {}".format(filename))
        elapse_time += time.clock()
        print("Took %.3f seconds." % elapse_time)
        return "expose " + str(success) + "," + str(filename) + "," + str(
            itime)
Exemple #5
0
    def getHeader_2(self, attributes, tcc):
        """
        Pre: Takes in a list of attributes: [imType, binning, itime], tcc is ether 'gtcc' or 'heimdall'
        Post: Returns an AstroPy header object to be used for writing to.
        """
        imType, binning, itime, filter = attributes[0], attributes[
            1], attributes[2], attributes[3]
        # make new fits header object
        header = fits.Header()
        ut_time = time.gmtime()  # get UT time
        dateObs = time.strftime("%Y-%m-%dT%H:%M:%S", ut_time)
        ut_str = time.strftime("%H:%M:%S", ut_time)
        header.append(card=("DATE-OBS", dateObs, "Time at start of exposure"))
        header.append(card=("UT", ut_str, "UT time at start of exposure"))
        header.append(card=("OBSERVAT", "mro", "per the iraf list"))
        header.append(card=("IMAGETYP", imType))
        header.append(card=("FILTER", filter))
        header.append(card=("BINX", binning, "Horizontal Binning"))
        header.append(card=("BINY", binning, "Vertical Binning"))
        header.append(card=("EXPTIME", itime, "Total exposure time"))
        header.append(card=("ACQMODE", "Single Scan", "Acquisition mode"))
        header.append(card=("READMODE", "Image", "Readout mode"))
        header.append(card=("INSTRUME", "evora",
                            "Instrument used for imaging"))
        header.append(card=("LONGITUD", self.config.get(section, 'longitude'),
                            "Decimal degrees of MRO latitude"))
        header.append(card=("LATITUDE", self.config.get(section, 'latitude'),
                            "Decimal degress of MRO longitude"))

        # get readout time and temp
        temp = andor.GetTemperatureStatus()[1]
        readTime = andor.GetAcquisitionTimings()[3] - itime
        header.append(card=("TEMP", temp, "Temperature"))
        header.append(card=("READTIME", readTime, "Pixel readout time"))

        # NEEDED header keywords
        # Done RA / Right Ascension
        # Done DEC / Declination
        # Done EPOCH / Epoch for RA and Dec (years)
        # Done ST / local sidereal time (hours)
        # Done HA / Hour Angle
        # Done ZD / Zenith Angle
        # AIRMASS
        # UTMIDDLE
        # JD
        # HJD
        # LJD
        if tcc == "heimdall":
            obsTime = time.strptime(dateObs + " UTC", "%Y-%m-%dT%H:%M:%S %Z")
            logFileList = glob.glob(
                "/home/mro/storage/tcc_data/positionlogs/*.txt")
            file = self.heimdallChooseLogFile(logFileList, obsTime)
            if file is not None:
                results = self.heimdallParseLogFile(file, obsTime)
                if results is not None:
                    ra, dec, epoch, lst, ha, za = results

                    airmass = 1.0 / np.cos(np.radians(za))
                    # airmass = 1.0 / np.sin(np.radians((90-za) + 244/(165+47*(90-za)**1.1)))

                    astroTime = Time(dateObs, scale='utc')
                    print("FROM HEIMDALL LOGS:", results)

                    header.append(card=("RA", ra, "Right Ascension"))
                    header.append(card=("DEC", dec, "Declination"))
                    header.append(card=("EPOCH", epoch,
                                        "Epoch for RA and Dec (years)"))
                    header.append(card=("ST", lst,
                                        "local sidereal time (hours)"))
                    header.append(card=("HA", ha, "Hour Angle"))
                    header.append(card=("ZD", za, "Zenith Angle"))
                    header.append(card=("AIRMASS", airmass,
                                        "Airmass (X = sec z)"))
                    header.append(card=("JD", str(astroTime.jd),
                                        "Julian Date"))
                    header.append(card=("MJD", str(astroTime.mjd),
                                        "Modified Julian Date"))

        else:  # gtcc
            print("ACCESSING LOG FILES")
            LogfileList = glob.glob("/home/mro/mnt/gtcc" + '/????-??-??T??:??:??')
            print("FOUND %d LOGS" % len(LogfileList))
            ObsTime = time.strptime(dateObs + ' UTC', "%Y-%m-%dT%H:%M:%S %Z")
            LogfileName = self.ChooseLogfile(LogfileList, ObsTime)
            if LogfileName is not None:
                print("LOG FILE NAME:", LogfileName)
                ra, dec, epoch, lst, ha, za = self.ParseLogfile(
                    LogfileName, ObsTime)
                print(ra, dec, epoch, lst, ha, za)

                header.append(card=("RA", ra, "Right Ascension"))
                header.append(card=("DEC", dec, "Declination"))
                header.append(card=("EPOCH", epoch,
                                    "Epoch for RA and Dec (years)"))
                header.append(card=("ST", lst, "local sidereal time (hours)"))
                header.append(card=("HA", ha, "Hour Angle"))
                header.append(card=("ZD", za, "Zenith Angle"))

        return header