1 from __future__
import division, absolute_import
4 from StringIO
import StringIO
8 from tcc.base import Obj, ChebyshevPolynomial, PxPMRadVel
9 from .fieldWrapper
import boolFromStr, tokenize
11 __all__ = [
"loadOldObjData"]
13 def _getPVTCoord(meanSysName, posName, dataDict):
14 """!Retrieve PVTCoord data from a data dict from an old Obj data file
16 pvtX = coordConv.PVT(*(float(val)
for val
in dataDict[posName +
"1"]))
17 pvtY = coordConv.PVT(*(float(val)
for val
in dataDict[posName +
"2"]))
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)
25 return coordConv.PVTCoord(pvtX, pvtY, *meanArgs)
28 """!Read old format Obj data file into a new Obj
30 @param[in] filePath path to data file
31 @return obj: an Obj block with most fields filled in
36 dataDict = collections.OrderedDict()
39 validNames = set(val.lower()
for val
in (
43 "userArcOff1",
"userArcOff2",
44 "guideoff1",
"guideoff2",
"guideoff3",
45 "caliboff1",
"caliboff2",
"caliboff3",
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"),
70 oldNewNameDict.update(dict((name, name)
for name
in validNames))
73 obsoletes = set(val.lower()
for val
in (
91 pvtNames = set(val.lower()
for val
in (
131 with file(filePath,
"rU")
as f:
136 if line[0]
in (
"#",
"!"):
139 key = dataList[0].lower()
145 if len(dataList) != 4:
146 raise RuntimeError(
"Expected 3 values for %s but got %s" % (key, line))
147 if float(dataList[3]) <= 0:
149 if key
in oldNewNameDict:
150 dataList[0] = oldNewNameDict[key]
152 newLine =
" ".join(repr(val)
for val
in dataList)
153 strFile.writelines((newLine,
"\n"))
155 dataDict[key] = dataList[1:]
160 missingKeys = sorted(set(oldNewNameDict.keys()) - usedNames)
162 print "Warning: did not see the following keys:", sorted(missingKeys)
164 sysNum, date = dataDict[
"coordsys"]
176 }.get(sysNum,
"none")
177 if userSysName
in (
"obs",
"apptopo",
"appgeo"):
181 obj.userSys = coordConv.makeCoordSys(userSysName, date)
183 for axis
in range(2):
184 obj.userPos[axis] = coordConv.PVT(*[float(val)
for val
in dataDict[
"userpos" + str(axis + 1)]])
186 pm1, pm2, px, rv = (float(val)
for val
in dataDict[
"meansys"])
187 obj.userPxPMRadVel = PxPMRadVel(px, pm1, pm2, rv)
188 obj.zpmUserPos = _getPVTCoord(
"zpmmeansys",
"zpmuser", dataDict)
189 obj.netUserPos = _getPVTCoord(
"zpmmeansys",
"netuserpos", dataDict)
190 obj.obsPos = _getPVTCoord(
None,
"obs", dataDict)
192 mag, magIsValid = dataDict[
"mag"]
193 obj.mag = float(mag)
if boolFromStr(magIsValid)
else float(
"nan")
195 obj.site.wavelen = float(dataDict[
"wavelen"][0])
196 obj.site.refCoA, obj.site.refCoB = tuple(float(val)
for val
in dataDict[
"refco"])
199 numChebyCoeffsList = tuple(int(val)
for val
in dataDict[
"numchebycoeffs"])
200 chebyBegTime, chebyEndTime = tuple(float(val)
for val
in dataDict[
"chebybegendtime"])
201 for i, suffix
in enumerate((
"User1",
"User2",
"Dist")):
202 oldName =
"chebycoeffs" + suffix.lower()
203 newName =
"cheby" + suffix.title()
204 numChebyCoeffs = numChebyCoeffsList[i]
205 if numChebyCoeffs > 0:
206 chebyCoeffs = tuple(float(val)
for val
in dataDict[oldName])
209 setattr(obj, newName, ChebyshevPolynomial(chebyCoeffs, chebyBegTime, chebyEndTime))
211 obj.obsSysPtr.setDate(0)
def tokenize
Break a line of whitespace-separated data into individual tokens.
def loadOldObjData
Read old format Obj data file into a new Obj.