Документ взят из кэша поисковой машины. Адрес оригинального документа : http://www.apo.nmsu.edu/35m_operations/TUI/Scripts/ScriptingTutorial/Refinements.html
Дата изменения: Sat Sep 6 02:16:02 2014
Дата индексирования: Sun Apr 10 07:48:05 2016
Кодировка:
TUI:Scripts:Scripting Tutorial:Refinements

Refinements

Adding a few refinements to the DISCals script makes a script worth adapting for your own uses.

The improvements are as follows:

Better feedback
The original DISCals script opened the DIS Expose window to give feedback, which is clumsy. Fortunately this easy to fix by borrowing the ExposeStatusWdg, the feedback widget used by exposure windows. ExposeStatusWdg updates its own displays, so it is very easy to use!
The original DISCals script also gave misleading feedback, because there was no hint that multiple sequences were going to occur. This version takes advantage of the "startNum" and "totNum" arguments to disExpose to report how many exposures truly remain in the script. Doing this requires computing the total number of exposures in advance, which requires looping through the data twice: first to count the number of exposures, then to execute the exposures.
Proper file numbering
File numbering should obey the "Seq by File" preference. You could fix this by reading the sequence number preference manually, but the formatExpCmd function in the instrument exposure model takes care of this for you and also handles the details of formatting. formatExpCmd is the recommended way to generate exposure commands for any instrument.
Support for debug mode
Adding sr.debug = False to the initialization lets you easily toggle this value when you want to debug your script. In debug mode, the script only pretends to operate, it doesn't actually talk to the hub or any instruments. Your script can also read this value, which is useful for providing fake data (as you'll see later in the the "Get Info" lesson).
Define your script as a class
If your script needs initialization or cleanup, write it as a class. This allows you to easily pass data between the various functions. Fortunately, conversion is very easy:

The resulting script still has no provision for user input, but often that is fine. We'll deal with user input in the next lesson.

NiceDISCals script

As always, get permission to use DIS before commanding it.


from TUI.Inst.ExposeStatusWdg import ExposeStatusWdg
import TUI.Inst.ExposeModel

class ScriptClass(object):
    """Sample script to take a series of DIS calibration images
    and demonstrate looping through data in Python.
    The exposure times and  # of iterations are short so the demo runs quickly.
    """
    def __init__(self, sr):
        """Display the exposure status panel.
        """
        # if True, run in debug-only mode (which doesn't DO anything, it just pretends)
        sr.debug = False
        
        expStatusWdg = ExposeStatusWdg(
            master = sr.master,
            instName = "DIS",
        )
        expStatusWdg.grid(row=0, column=0)
        
        # get the exposure model
        self.expModel = TUI.Inst.ExposeModel.getModel("DIS")
    
    def run(self, sr):
        """Run the script"""
        # typeTimeNumList is a list of calibration info
        # each element of the list is a list of:
        # - exposure type
        # - exposure time (sec)
        # - number of exposures
        typeTimeNumList = [
            ["flat", 1, 2],
            ["flat", 5, 2],
            ["bias", 0, 2],
            ["dark", 1, 2],
            ["dark", 5, 2],
        ]
        
        # compute the total number of exposures
        totNum = 0
        for expType, expTime, numExp in typeTimeNumList:
            totNum += numExp
        
        # take the exposures
        startNum = 1
        for expType, expTime, numExp in typeTimeNumList:
            fileName = "dis_" + expType
            cmdStr = self.expModel.formatExpCmd(
                expType = expType,
                expTime = expTime,
                fileName = fileName,
                numExp = numExp,
                startNum = startNum,
                totNum = totNum,
            )
            startNum += numExp
    
            yield sr.waitCmd(
                actor = self.expModel.actor,
                cmdStr = cmdStr,
                abortCmdStr = "abort",
            )

Comments: