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

Поисковые слова: каллисто
lsst.tcc: python/tcc/base/loadInst.py Source File
lsst.tcc  1.2.2-3-g89ecb63
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
loadInst.py
Go to the documentation of this file.
1 from __future__ import division, absolute_import
2 
3 import glob
4 import os.path
5 
6 from twistedActor import BaseActor, CommandError
7 
8 import tcc.base
9 
10 __all__ = ["loadInst"]
11 
12 def loadInst(instDir, instName, gcViewName=None, writeToUsers=None, cmd=None):
13  """!Create an instrument block for the specified instrument
14 
15  @param[in] instDir path to instrument dir (typically tcc.base.getInstDir())
16  @param[in] instName name of instrument (e.g. "DIS"); case is ignored; may be an abbreviation if unique
17  @param[in] gcViewName name of guide camera view; unlike instName, this may not be an abbreviation;
18  if "" or None then no guide camera view is loaded
19  @param[in] writeToUsers tccActor.writeToUsers or a similar function; if None, write to stdout
20  @param[in] cmd command (twistedActor.BaseCmd) associated with this request, or None
21  @return an Inst
22 
23  @throw CommandError if instrument not found or name not unique
24 
25  @warning: does not update the AxeLim block (you must do that separately)
26  """
27  if writeToUsers is None:
28  writeToUsers = BaseActor.writeToStdOut
29  gcViewName = gcViewName or "" # convert None to ""
30 
31  # make sure instName is a unique abbreviation and find the associated instrument position
32  instGlobExpr = "i_[a-z][a-z][0-9]_%s*.dat" % (instName.lower(),)
33  instFilePathList = glob.glob(os.path.join(instDir, instGlobExpr))
34  if not instFilePathList:
35  raise CommandError("Could not find instrument %r in %r" % (instName, instDir))
36  if len(instFilePathList) > 1:
37  raise CommandError("Found more than one instrument named %r in %r" % (instName, instDir))
38  instFilePath = instFilePathList[0]
39  instFileName = os.path.basename(instFilePath)
40  instPosName, fullInstName = instFileName.split("_", 2)[1:3]
41  fullInstName = fullInstName[:-4] # strip .dat
42 
43  def fileExists(fileName):
44  return os.path.isfile(os.path.join(instDir, fileName))
45 
46  # generate names of data files to load
47  dataFileNameList = []
48 
49  defFileName = "default.dat"
50  if not fileExists("default.dat"):
51  raise RuntimeError("Could not find default file %r in %r" % (defFileName, instDir))
52  dataFileNameList.append(defFileName)
53 
54  instPosFileName = "ip_%s.dat" % (instPosName,)
55  if fileExists(instPosFileName):
56  dataFileNameList.append(instPosFileName)
57 
58  if gcViewName:
59  gcViewFileName = "v_%s_%s.dat" % (instPosName, gcViewName)
60  if not fileExists(gcViewFileName):
61  raise RuntimeError("Could not find guide camera view file %r in %r" % (gcViewFileName, instDir))
62  dataFileNameList.append(gcViewFileName)
63 
64  dataFileNameList.append(instFileName)
65 
66  # load data files
67  inst = tcc.base.Inst()
68  for fileName in dataFileNameList:
69  filePath = os.path.join(instDir, fileName)
70  inst.loadPath(filePath)
71  writeToUsers("i", "InstFiles=%s" % (", ".join('"%s"' % (fileName,) for fileName in dataFileNameList),), cmd=cmd)
72 
73  # override the few values that are set based on file name (instead of file contents)
74  inst.instName = fullInstName
75  inst.gcViewName = gcViewName
76  inst.instPos.setName(instPosName.upper())
77  return inst
def loadInst
Create an instrument block for the specified instrument.
Definition: loadInst.py:12