Документ взят из кэша поисковой машины. Адрес оригинального документа : http://www.apo.nmsu.edu/Telescopes/TCC/html/set_instrument_8py_source.html
Дата изменения: Tue Sep 15 02:25:37 2015
Дата индексирования: Sun Apr 10 03:02:25 2016
Кодировка:

Поисковые слова: annular solar eclipse
lsst.tcc: python/tcc/cmd/setInstrument.py Source File
lsst.tcc  1.2.2-3-g89ecb63
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
setInstrument.py
Go to the documentation of this file.
1 from __future__ import division, absolute_import
2 
3 import functools
4 
5 from twistedActor import CommandError
6 
7 import tcc.base
8 from tcc.axis import computeObj
9 from .showInstrument import showInstrument
10 from .showObject import showObjectFields
11 from .startSlew import startSlew
12 
13 __all__ = ["setInstrument"]
14 
15 def setInstrument(tccActor, userCmd):
16  """Implement the "set instrument" command
17 
18  @param[in,out] tccActor tcc actor
19  writes to tccActor.inst, and tccActor.obj
20  @param[in,out] userCmd user command
21  """
22  currSecUserFocus = tccActor.inst.secUserFocus
23  try:
24  instName = userCmd.parsedCmd.paramDict["instrument"].valueList[0].valueList[0]
25  except Exception:
26  # no name specified, re-use from current inst
27  instName = tccActor.inst.instName
28  if not instName:
29  raise CommandError('No name avalable in current instrument block!')
30 
31  gcview = userCmd.parsedCmd.qualDict["gcview"].valueList[0] if userCmd.parsedCmd.qualDict["gcview"].boolValue else None
32  newInst = tcc.base.loadInst(
33  instDir = tcc.base.getInstDir(),
34  instName = instName,
35  gcViewName = gcview,
36  writeToUsers = tccActor.writeToUsers,
37  cmd = userCmd,
38  )
39  newInst.secUserFocus = currSecUserFocus
40 
41  if userCmd.parsedCmd.qualDict["keep"].boolValue:
42  # keep certain values, note: no scaleFactor range checking...
43  # could add it.
44  for attr in userCmd.parsedCmd.qualDict["keep"].valueList:
45  if attr.endswith('Focus'):
46  # add 'User' before 'Focus' to match block attribute
47  attr = attr.replace('Focus', 'UserFocus')
48  setattr(newInst, attr, getattr(tccActor.inst, attr))
49 
50  # if rotator changes, then update tccActor.axisDevSet and initialize the old and new rotator
51  if tccActor.inst.rotID != newInst.rotID:
52  RotSwapper(tccActor=tccActor, userCmd=userCmd, newInst=newInst)
53  else:
54  isNewInst = newInst.instName != tccActor.inst.instName
55  tccActor.inst = newInst
56  finishSetInst(tccActor=tccActor, userCmd=userCmd, isNewInst=isNewInst)
57 
58 
59 class RotSwapper(object):
60  """Swap instrument rotators.
61 
62  On success, update tccActor.inst and call finishSetInst
63  """
64  def __init__(self, tccActor, userCmd, newInst):
65  """Construct a RotSwapper
66 
67  @param[in,out] tccActor tcc actor
68  writes to tccActor.inst, and tccActor.obj
69  @param[in,out] userCmd user command
70  @param[in] newInst new instrument data (a tcc.base.Inst)
71  """
72  self.userCmd = userCmd
73  self.tccActor = tccActor
74  self.newInst = newInst
75  self.isNewInst = newInst.instName != tccActor.inst.instName
76  if newInst.rotID <= 0:
77  newDev = None
78  else:
79  newRotName = "rot%i" % (newInst.rotID,)
80  try:
81  newDev = self.tccActor.axisDict[newRotName]
82  except Exception:
83  raise CommandError("Unknown rotator ID %d" % (newInst.rotID,))
84  swapCmd = self.tccActor.axisDevSet.replaceDev(
85  "rot",
86  newDev,
87  )
88  swapCmd.addCallback(functools.partial(self._swapCallback, newDev=newDev))
89 
90  def _swapCallback(self, cmd, newDev):
91  if not cmd.isDone:
92  return
93  if cmd.didFail:
94  self.userCmd.setState(self.userCmd.Failed,
95  textMsg = "Failed to change to rotator %d: %s" % (self.newInst.rotID, cmd.getMsg()))
96  else:
97  self.tccActor.inst = self.newInst
98  if self.tccActor.inst.rotID <= 0:
99  # there is no rotator, update rotator axis state to not available
100  self.tccActor.obj.axisCmdState[2] = tcc.base.AxisState_NotAvailable
101  else:
102  # there is a rotator
103  self.tccActor.obj.axisCmdState[2] = tcc.base.AxisState_Halted
104  finishSetInst(self.tccActor, self.userCmd, isNewInst=self.isNewInst)
105 
106 
107 def finishSetInst(tccActor, userCmd, isNewInst):
108  """Finish the set instrument command by updating tccActor.axeLim and slewing to the updated target
109 
110  Halted axes are left halted. If the new instrument has no rotator than the old rotType is ditched.
111 
112  @param[in,out] tccActor tcc actor
113  reads and updates obj, setting azWrapPref and rotWrapPref and slewing
114  @param[in,out] userCmd set instrument command
115  reads azwrap and rotwrap preferences from userCmd.parsedCmd.qualDict
116  @param[in] isNewInst set True if "set inst" changed to a new instrument,
117  in which case set rotType to None
118  """
119  tccActor.axeLim.setRotLim(tccActor.inst)
120  showInstrument(tccActor, userCmd, setDone=False, showFull=True)
121  if isNewInst or not tccActor.inst.hasRotator():
122  tccActor.obj.rotType = tcc.base.RotType_None
123  tccActor.obj.rotUser.invalidate()
124  showObjectFields(tccActor, userCmd, showFull=None)
125 
126  if tccActor.obj.isMoving():
127  # apply wrap preference
128  newObj = tcc.base.Obj(tccActor.obj)
129  newObj.azWrapPref = tcc.base.WrapTypeNameDict[userCmd.parsedCmd.qualDict["azwrap"].valueList[0].lower()]
130  newObj.rotWrapPref = tcc.base.WrapTypeNameDict[userCmd.parsedCmd.qualDict["rotwrap"].valueList[0].lower()]
131 
132  computeObj(
133  obj = newObj,
134  doWrap = True,
135  doRestart = [False]*tcc.base.NAxes,
136  reportLim = True,
137  earth = tccActor.earth,
138  inst = tccActor.inst,
139  telMod = tccActor.telMod,
140  axeLim = tccActor.axeLim,
141  tai = tcc.base.tai(),
142  )
143 
144  startSlew(
145  tccActor = tccActor,
146  obj = newObj,
147  slewCmd = userCmd,
148  doAbsRefCorr = True,
149  doCollimate = True,
150  )
151  else:
152  userCmd.setState(userCmd.Done)
def computeObj
Compute all computed obj fields from user-specified fields except path generator outputs.
Definition: computeObj.py:22
def showObjectFields
Write fields from the object block.
Definition: showObject.py:22