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

Поисковые слова: п п п п п п п п п п п п п п п п п
TUI:Scripts:Scripting Tutorial:Get Info

Get Info

It is easy to incorporate information from an instrument or the telescope into your scripts. Most information you might want is available in various "models" within TUI. These include a model for each instrument (TUI.Inst.DIS.DISModel, etc.), a telescope model (TUI.TCC.TCCModel) and the exposure models you have already seen (TUI.Inst.ExposeModel).

Most models primarily consist of a set of "keyword variables", one per keyword that instrument outputs. Keyword variables may be read using sr.getKeyVar or sr.waitKeyVar. Models often also include a few constants, preferences and/or convenience functions (such as formatExpCmd). To obtain a model, import the appropriate code and call getModel() as per the example here. To find out what is in a model, I suggest you read its code. (There are also good ways to get help from within Python; see the Programming manual for details.)

Note that the telescope model contains some important of information about the current instrument, including its name, image scale and size—all information that is not available from the instrument model.

The following example shows a good use of querying information. DIS always does something when you ask its motors to move, even if they are already in the right place. In particular, the gratings are always homed, which is very slow, and the turret detent is temporarily retracted. In the following example, current DIS status is queried and only items that need to be changed are moved.

Note that whenever you read input, you need to think about debug mode (because in that mode you only get None back). In this case, if we're in debug mode then we don't check that the current instrument is DIS. In this example we don't have to mess with the getKeyVar statements because getKeyVar returns None in debug mode, making the commands run, which is perfect.

DISConfig script

Be sure you have permission to use DIS before running this example!!!


import TUI.TCC.TCCModel
import TUI.Inst.DIS.DISModel
from TUI.Inst.DIS.StatusConfigInputWdg import StatusConfigInputWdg

InstName = "DIS"

class ScriptClass(object):
    """Simple script to configure DIS.
    """
    def __init__(self, sr):
        """Display DIS configuration."""
        # if True, run in debug-only mode (which doesn't DO anything, it just pretends)
        sr.debug = False

        statusWdg = StatusConfigInputWdg(sr.master)
        statusWdg.grid(row=0, column=0)
    
    def run(self, sr):
        """Configure DIS
        
        It is inefficient to tell DIS to move something that is already
        in the right location, so check each item before moving.
        """
        disModel = TUI.Inst.DIS.DISModel.getModel()
        tccModel = TUI.TCC.TCCModel.getModel()
    
        # settings
        turretPos = 1  # grating set 1 is typically high blue/high red
        maskID = 1
        filterID = 1  # 1 is clear
        rlambda = 7300  # in Angstroms
        blambda = 4400  # in Angstroms

        # Make sure the current instrument is DIS
        if not sr.debug:
            currInstName = sr.getKeyVar(self.tccModel.instName)
            if not currInstName.lower().startswith(InstName.lower()):
                raise sr.ScriptError("%s is not the current instrument!" % InstName)
    
        # notes:
        # - set turret before setting gratings to make sure that
        # disModel.cmdLambdas is for the correct turret.
        # - DIS only moves one motor at a time,
        # so the following code is about as efficient as it gets
        
        if turretPos != sr.getKeyVar(disModel.turretPos):
            yield sr.waitCmd(
                actor = "dis",
                cmdStr = "motors turret=%d" % turretPos,
            )
        
        if maskID != sr.getKeyVar(disModel.maskID):
            yield sr.waitCmd(
                actor = "dis",
                cmdStr = "motors mask=%d" % maskID,
            )
        
        if filterID != sr.getKeyVar(disModel.filterID):
            yield sr.waitCmd(
                actor = "dis",
                cmdStr = "motors filter=%d" % filterID,
            )
        
        # test against disModel.cmdLambdas, not disModel.actLambdas,
        # because the gratings cannot necessarily go *exactly* where requested
        # but do the best they can
        if blambda != sr.getKeyVar(disModel.cmdLambdas, ind=0):
            yield sr.waitCmd(
                actor = "dis",
                cmdStr = "motors b%dlambda=%d" % (turretPos, blambda),
            )
        
        if rlambda != sr.getKeyVar(disModel.cmdLambdas, ind=1):
            yield sr.waitCmd(
                actor = "dis",
                cmdStr = "motors r%dlambda=%d" % (turretPos, rlambda),
            )

Comments: