Документ взят из кэша поисковой машины. Адрес
оригинального документа
: 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 Кодировка: Поисковые слова: planet |
Adding a few refinements to the DISCals script makes a script worth adapting for your own uses.
The improvements are as follows:
ExposeStatusWdg
, the feedback widget used by exposure windows. ExposeStatusWdg
updates its own displays, so it is very easy to use!
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.
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.
class ScriptClass(object):
to the beginning
def init(sr)
to def __init__(self, sr)
(there are two underscrores on either side of "init"; it may look funny, but it's standard python)
def run(sr)
to def run(self, sr)
and the same for all other functions.
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.
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:
__init__
, run
and end
, use self
, as in self.expModel =...
.
formatExpCmd
function. Simply call TUI.ExposeModel.getModel(instName) to get it.