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

Поисковые слова: annular solar eclipse
lsst.tcc: python/tcc/cmd/offset.py Source File
lsst.tcc  1.2.2-3-g89ecb63
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
offset.py
Go to the documentation of this file.
1 from __future__ import division, absolute_import
2 
3 from twistedActor import CommandError
4 
5 import tcc.base
6 from tcc.axis import computeObj
7 from tcc.parse import getPVTList, getRestart
8 from .checkTargetForSlew import checkTargetForSlew
9 from .startSlew import startSlew
10 from .showObject import showObjectFields
11 from tcc.msg import moveItemKW
12 
13 __all__ = ["offset"]
14 
15 # dict of offset name (lowercase): number of axes, obj block attribute name (case-sensitive):
16 OffsetNumAxesAttrDict = dict(
17  arc = (2, "userArcOff"),
18  boresight = (2, "objInstXY"),
19  instplane = (2, "objInstXY"),
20  rotator = (1, "rotUser"),
21  guidecorrection = (3, "guideOff"),
22  gcorrection = (3, "guideOff"),
23  calibration = (3, "calibOff"),
24 )
25 
26 def setObjOffset(obj, parsedCmd, rotExists, tai, writeToUsers=None):
27  """Update user-set attributes of object block based on an offset command
28 
29  @param[in,out] obj object block to update
30  @param[in] parsedCmd parsed offset command
31  @param[in] rotExists True if there is an instrument rotator
32  @param[in] tai TAI date for PVT coordinates
33 
34  @return three flags:
35  - isNewObj: True if new object position requested
36  - isNewRot: True if new rotator position requested
37 
38  @throw twistedActor.CommandError if offset type is rotator and there is no rotator
39  """
40  #print 'offsetType', parsedCmd.paramDict["type"].valueList[0].keyword.lower()
41  offsetType = parsedCmd.paramDict["type"].valueList[0].keyword.lower()
42  if offsetType == "rotator" and not rotExists:
43  raise CommandError("Cannot command rotator offset, current instrument has no rotator")
44  numAxes, attrName = OffsetNumAxesAttrDict[offsetType]
45  coordSetParam = parsedCmd.paramDict["coordset"]
46  pvtList, numValues = getPVTList(coordSetParam, numAxes, defTAI=tai)
47 
48  pAbs = parsedCmd.qualDict["pabsolute"].boolValue
49  vAbs = not parsedCmd.qualDict["vincremental"].boolValue
50 
51  objField = getattr(obj, attrName)
52  if numAxes == 1:
53  objField = [objField]
54 
55  numAxesToSet = numAxes
56  if numAxes == 3:
57  if numValues == 0 and not rotExists:
58  # user did not specify any values; skip rotator
59  numAxesToSet = 2
60  elif numValues == 2:
61  # user specified 2 values, and so explicitly excluded the rotator
62  numAxesToSet = 2
63  rotOmitted = numAxesToSet != numAxes
64 
65  for ind in range(numAxesToSet):
66  pvt = objField[ind]
67  offPVT = pvtList[ind]
68  # get a copy of the current offset(s) at the TAI date of the new offset,
69  # since that is the desired final TAI of the offset and one can simply add .pos
70  newPVT = pvt.copy(tai)
71  if pAbs:
72  newPVT.pos = offPVT.pos
73  else:
74  newPVT.pos += offPVT.pos
75 
76  if vAbs:
77  newPVT.vel = offPVT.vel
78  else:
79  newPVT.vel += offPVT.vel
80 
81  if numAxes == 1:
82  # scalar field; setting objField[ind] will not change obj, so set the field directly
83  setattr(obj, attrName, newPVT)
84  else:
85  objField[ind] = newPVT
86 
87  isNewObj = False
88  isNewRot = False
89  if numAxes == 1: # only the rotator is changed
90  isNewRot = True
91  elif numAxes == 2: # az, alt or user1, user2
92  isNewObj = True
93  else: # az, alt [, rot]
94  isNewObj = True
95  isNewRot = not rotOmitted
96 
97  return isNewObj, isNewRot
98 
99 
100 def offset(tccActor, userCmd):
101  """Implement the offset command
102  """
103  rotExists = tccActor.inst.hasRotator()
104  parsedCmd = userCmd.parsedCmd
105 
106  currTAI = tcc.base.tai()
107  newObj = tcc.base.Obj(tccActor.obj)
108  isNewObj, isNewRot = setObjOffset(obj=newObj, parsedCmd=parsedCmd, rotExists=rotExists, tai=currTAI, writeToUsers=tccActor.writeToUsers)
109  if isNewRot and not rotExists:
110  # rotator offset (with no rotator) as part of offsetting other axes as well (if offset type is "rotator",
111  # then the command was already rejected by setObjOffset); warn but continue
112  tccActor.writeToUsers("w", "Text=\"No instrument rotator: rotator component of offset recorded but not applied\"", cmd=userCmd)
113 
114  if isNewObj and tccActor.obj.userSys.getName().lower() == "mount":
115  tccActor.obj = newObj
116  tccActor.writeToUsers("w", "Text=\"Tracking in mount coordinates; offset recorded but not applied\"", cmd=userCmd)
117  userCmd.setState(userCmd.Done)
118  return
119 
120  qualDict = parsedCmd.qualDict
121  # note: collimate, refCoefficients handled in startSlew()?
122  doRestart = getRestart(qual=qualDict["restart"], rotExists=rotExists)
123  doComputed = qualDict["computed"].boolValue
124  doAbsRefCorr = qualDict["absrefcorrect"].boolValue
125  if any(doRestart):
126  if qualDict["computed"].boolValueDefaulted:
127  doComputed = True # if restart is specified, computed must be the default action
128  elif not doComputed:
129  # user specifically commanded /nocomputed along with /restart, this isn't allowed
130  raise CommandError("May not specify /NoComputed and /Restart simultaneously")
131  perfect = qualDict["perfect"].boolValue
132  if qualDict["refcoefficients"].boolValue:
133  tccActor.weath.updateSite(newObj.site)
134 
136  tccActor=tccActor,
137  userCmd=userCmd,
138  newObj=newObj,
139  isNewObj=isNewObj,
140  isNewRot=isNewRot,
141  doWrap=False,
142  doRestart=doRestart,
143  perfect=perfect,
144  tai=currTAI,
145  )
146  if userCmd.isDone:
147  return
148 
149  doCollimate = qualDict["collimate"].boolValue
150 
151  if doComputed:
152  # computed offset, use a normal slew
153  startSlew(
154  tccActor=tccActor,
155  obj=newObj,
156  slewCmd=userCmd,
157  doAbsRefCorr=doAbsRefCorr,
158  doCollimate=doCollimate,
159  )
160  else:
161  # uncomputed offset; use +MOVE P V
162 
163  # compute delta-mount at currTAI
164  # (note that newObj has already been computed at that date by checkTargetForSlew)
165  oldObj = tcc.base.Obj(tccActor.obj)
166  computeObj(
167  oldObj,
168  doWrap=False,
169  doRestart=doRestart,
170  reportLim=True,
171  earth=tccActor.earth,
172  inst=tccActor.inst,
173  telMod=tccActor.telMod,
174  axeLim=tccActor.axeLim,
175  tai=currTAI,
176  )
177 
178  offsetPVTList = [newObj.targetMount[axis] - oldObj.targetMount[axis] for axis in range(tcc.base.NAxes)]
179  # preserve old MOVE P V T update time to allow testing for calling updateTracking late
180  newObj.updateTime = tccActor.obj.updateTime
181  tccActor.obj = newObj
182  tccActor.axisDevSet.plusMovePV(offsetPVTList, userCmd=userCmd)
183 
184  showObjectFields(tccActor, userCmd)
185  kwString = "Moved; %s"%moveItemKW(tccActor.obj)
186  tccActor.writeToUsers("i", kwString)
187  if doCollimate:
188  tccActor.updateCollimation()
189 
190 
191 
def getRestart
Get a list of axes from the /Restart qualifier.
Definition: getRestart.py:15
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
def getPVTList
Obtain a list of PVTs from a PVT list parameter.
Definition: getPVTList.py:10
def setObjOffset
Definition: offset.py:26