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

Поисковые слова: m 5
lsst.tcc: python/tcc/base/loadOldObjData.py Source File
lsst.tcc  1.2.2-3-g89ecb63
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
loadOldObjData.py
Go to the documentation of this file.
1 from __future__ import division, absolute_import
2 
3 import collections
4 from StringIO import StringIO
5 
6 import coordConv
7 
8 from tcc.base import Obj, ChebyshevPolynomial, PxPMRadVel
9 from .fieldWrapper import boolFromStr, tokenize
10 
11 __all__ = ["loadOldObjData"]
12 
13 def _getPVTCoord(meanSysName, posName, dataDict):
14  """!Retrieve PVTCoord data from a data dict from an old Obj data file
15  """
16  pvtX = coordConv.PVT(*(float(val) for val in dataDict[posName + "1"]))
17  pvtY = coordConv.PVT(*(float(val) for val in dataDict[posName + "2"]))
18  taiDate = pvtX.t
19  if meanSysName is not None:
20  pm1, pm2, px, rv = (float(val) for val in dataDict[meanSysName])
21  distPVT = coordConv.PVT(coordConv.distanceFromParallax(px), 0, taiDate)
22  meanArgs = (distPVT, pm1, pm2, rv)
23  else:
24  meanArgs = ()
25  return coordConv.PVTCoord(pvtX, pvtY, *meanArgs)
26 
27 def loadOldObjData(filePath):
28  """!Read old format Obj data file into a new Obj
29 
30  @param[in] filePath path to data file
31  @return obj: an Obj block with most fields filled in
32  """
33 
34  # read what lines we can directly (renaming fields in a few cases that obj.i cannot handle)
35  # put other data into dataDict: key: tokenized data from rest of line
36  dataDict = collections.OrderedDict()
37  strFile = StringIO()
38  # names that can be processed "as is"
39  validNames = set(val.lower() for val in (
40  "name",
41  "useCheby",
42  "rotUser",
43  "userArcOff1", "userArcOff2",
44  "guideoff1", "guideoff2", "guideoff3",
45  "caliboff1", "caliboff2", "caliboff3",
46  ))
47  # dict of old name: new name
48  # start with items that have been renamed, then add valid names mapped to themselves, to simplify the code
49  oldNewNameDict = dict((val[0].lower(), val[1].lower()) for val in (
50  ("rot_type", "rotType"),
51  ("az_wrapPref", "azWrapPref"),
52  ("rot_wrapPref", "rotWrapPref"),
53  ("pvtEndTime", "updateTime"),
54  ("obj_inst_xy1", "objInstXY1"),
55  ("obj_inst_xy2", "objInstXY2"),
56  ("arcuser_noarcuser_ang", "arcUserNoArcUserAng"),
57  ("objuser_objaz_ang", "objUserObjAzAng"),
58  ("spider_inst_ang", "spiderInstAng"),
59  ("objaz_inst_ang", "objAzInstAng"),
60  ("objuser_inst_ang", "objUserInstAng"),
61  ("rotaz_rot_ang", "rotAzRotAng"),
62  ("spider_inst_ang", "spiderInstAng"),
63  ("rot_phys", "rotPhys"),
64  ("azalt_mt1", "targetMount1"),
65  ("azalt_mt2", "targetMount2"),
66  ("rot_mt", "targetMount3"),
67  ("mountCmdState", "axisCmdState"),
68  ("mountErrCode", "axisErrCode"),
69  ))
70  oldNewNameDict.update(dict((name, name) for name in validNames))
71 
72  # set of names to ignore
73  obsoletes = set(val.lower() for val in (
74  "doArcOffTDICorr",
75  "offsetEndTime",
76 # "NumChebyCoeffs",
77 # "ChebyBegEndTime",
78  "arcVelCorr",
79  "prevArcVelCorr",
80  "Mech_Obj_xy1",
81  "Mech_Obj_xy2",
82  "Mech_Inst_ang",
83  "RotAz_Mech_ang",
84  "Mech_Inst_ang",
85  "AzAlt_Phys1",
86  "AzAlt_Phys2",
87  "SlewMsgTag",
88  "timestamp",
89  ))
90  # old names that are PVTs; if t = 0 then convert to nan
91  pvtNames = set(val.lower() for val in (
92  "userPos1",
93  "userPos2",
94  "userOff1",
95  "userOff2",
96  "userArcOff1",
97  "userArcOff2",
98  "obj_inst_xy1",
99  "obj_inst_xy2",
100  "rotuser",
101  "guideoff1",
102  "guideoff2",
103  "guideoff3",
104  "caliboff1",
105  "caliboff2",
106  "caliboff3",
107  "zpmUser1",
108  "zpmUser2",
109  "arcVelCorr",
110  "prevArcVelCorr",
111  "netUserPos1",
112  "netUserPos2",
113  "obs1",
114  "obs2",
115  "objUser_objAz_ang",
116  "objAz_inst_ang",
117  "objUser_Inst_ang",
118  "mech_obj_xy1",
119  "mech_obj_xy2",
120  "mech_inst_ang",
121  "rotaz_mech_ang",
122  "rotAz_Rot_ang",
123  "Spider_inst_ang",
124  "azalt_phys1",
125  "azalt_phys2",
126  "rot_phys",
127  "azAlt_mt1",
128  "azAlt_mt2",
129  ))
130  usedNames = set() # valid names that were processed
131  with file(filePath, "rU") as f:
132  for line in f:
133  line = line.strip()
134  if not line:
135  continue
136  if line[0] in ("#", "!"):
137  continue
138  dataList = tokenize(line)
139  key = dataList[0].lower()
140  if key in obsoletes:
141  continue
142 
143  if key in pvtNames:
144  # PVT: if time <= 0 then set time = NaN
145  if len(dataList) != 4:
146  raise RuntimeError("Expected 3 values for %s but got %s" % (key, line))
147  if float(dataList[3]) <= 0:
148  dataList[3] = "NaN"
149  if key in oldNewNameDict:
150  dataList[0] = oldNewNameDict[key]
151  usedNames.add(key)
152  newLine = " ".join(repr(val) for val in dataList)
153  strFile.writelines((newLine, "\n"))
154  else:
155  dataDict[key] = dataList[1:]
156  strFile.pos = 0
157  obj = Obj()
158  obj.load(s