def test_auto_host_port(self): s = """ site: name: site1 #host: 200.131.64.200 # default=None #port: 10000 # default=None """ system = SystemConfig(s, loadGlobal=False) assert system.sites[0].host == MANAGER_DEFAULT_HOST assert system.sites[0].port == MANAGER_DEFAULT_PORT system.dump()
def test_simple_driver(self): s = """ telescope: name: tel1 driver: DriverType """ system = SystemConfig(s, loadGlobal=False) assert system.drivers[0].cls == 'DriverType' assert "device" not in system.drivers[0].config assert system.telescopes[0].config['driver'] == system.drivers[0] system.dump()
def __start__(self): self.sysconfig = SystemConfig.fromFile(self['chimera_config']) self.localManager = Manager(self.sysconfig.chimera["host"], 9090) self.offsets = dict( zip(self["focus_filters"].split(), [int(x) for x in self["focus_difference"].split()])) @callback(self.localManager) def filterChange(newFilter, oldFilter): self.log.debug("Moved from %s to %s" % (oldFilter, newFilter)) diff = self.offsets[newFilter] - self.offsets[oldFilter] if diff < 0: diff = int(ceil(abs(diff))) self.log.debug("Moving focuser %i steps IN due filter change" % diff) self.focuser.moveIn(diff) elif diff > 0: diff = int(ceil(abs(diff))) self.log.debug( "Moving focuser %i steps OUT due filter change" % diff) self.focuser.moveOut(diff) self.filterwheel = self.getManager().getProxy(self["filterwheel"]) self.filterwheel.filterChange += filterChange self.focuser = self.getManager().getProxy(self["focuser"])
def setupChimera (self): try: self.sysconfig = SystemConfig.fromFile(SYSTEM_CONFIG_DEFAULT_FILENAME) except IOError, e: logging.exception(e) logging.error("There was a problem reading your configuration file. (%s)" % e) return False
def startup(self): if self.options.daemon: # detach log.info("FIXME: Daemon...") # system config self.config = SystemConfig.fromFile(self.options.config_file, self.options.use_global) # manager if not self.options.dry: log.info("Starting system.") log.info("Chimera version: %s" % find_dev_version() or _chimera_version_) log.info("Chimera prefix: %s" % ChimeraPath.root()) try: self.manager = Manager(**self.config.chimera) except ChimeraException, e: log.error( "Chimera is already running on this machine. Use chimera-admin to manage it." ) sys.exit(1) log.info("Chimera: running on " + self.manager.getHostname() + ":" + str(self.manager.getPort())) if self.options.use_global: log.info("Chimera: reading configuration from %s" % SYSTEM_CONFIG_DEFAULT_GLOBAL) log.info("Chimera: reading configuration from %s" % os.path.realpath(self.options.config_file))
def test_simple_driver_with_device(self): s = """ telescope: name: tel1 driver: DriverType device: /dev/ttyS0 """ system = SystemConfig(s, loadGlobal=False) assert system.drivers[0].cls == 'DriverType' assert system.drivers[0].config["device"] == '/dev/ttyS0' assert system.telescopes[0].config['driver'] == system.drivers[0] system.dump()
def test_auto_type_name(self): s = """ site: name: site1 #type: SiteType # type would be Site (key.capitalize()) host: 200.131.64.200 port: 10000 config0: value0 """ system = SystemConfig(s, loadGlobal=False) assert system.sites[0].name == "site1" assert system.sites[0].cls == "Site" assert system.sites[0].host == "200.131.64.200" assert system.sites[0].port == 10000 assert system.sites[0].config['config0'] == 'value0' system.dump()
def test_controller(self): s = """ controller: name: simple type: ControllerType """ system = SystemConfig(s, loadGlobal=False) assert system.controllers[0].name == 'simple' assert system.controllers[0].cls == 'ControllerType'
def test_instrument(self): s = """ instrument: name: simple type: InstrumentType """ system = SystemConfig(s, loadGlobal=False) assert system.instruments[0].name == 'simple' assert system.instruments[0].cls == 'InstrumentType'
def test_auto_host_port (self): s = """ site: name: site1 #host: 200.131.64.200 # default=None #port: 10000 # default=None """ system = SystemConfig.fromString(s) assert system.sites[0].host == MANAGER_DEFAULT_HOST assert system.sites[0].port == MANAGER_DEFAULT_PORT
def test_driver(self): s = """ driver: name: simple type: DriverType """ system = SystemConfig(s, loadGlobal=False) assert system.drivers[0].name == 'simple' assert system.drivers[0].cls == 'DriverType'
def test_multiple_drivers(self): s = """ driver: - name: simple type: DriverType - name: simple type: DriverType """ system = SystemConfig(s, loadGlobal=False) assert len(system.drivers) == 2
def test_instrument (self): s = """ instrument: name: simple type: InstrumentType """ system = SystemConfig.fromString(s) assert system.instruments[0].name == 'simple' assert system.instruments[0].cls == 'InstrumentType'
def test_instrument(self): s = """ instrument: name: simple type: InstrumentType """ system = SystemConfig.fromString(s) assert system.instruments[0].name == 'simple' assert system.instruments[0].cls == 'InstrumentType'
def test_multiple_instruments (self): s = """ instrument: - name: simple type: InstrumentType - name: simple type: InstrumentType """ system = SystemConfig.fromString(s) assert len(system.instruments) == 2
def test_multiple_controllers(self): s = """ controller: - name: simple type: ControllerType - name: simple type: ControllerType """ system = SystemConfig.fromString(s) assert len(system.controllers) == 2
def test_multiple_controllers(self): s = """ controller: - name: simple type: ControllerType - name: simple type: ControllerType """ system = SystemConfig(s, loadGlobal=False) assert len(system.controllers) == 2
def test_multiple_controllers (self): s = """ controller: - name: simple type: ControllerType - name: simple type: ControllerType """ system = SystemConfig.fromString(s) assert len(system.controllers) == 2
def test_controller (self): s = """ controller: name: simple type: ControllerType """ system = SystemConfig.fromString(s) assert system.controllers[0].name == 'simple' assert system.controllers[0].cls == 'ControllerType'
def test_controller(self): s = """ controller: name: simple type: ControllerType """ system = SystemConfig.fromString(s) assert system.controllers[0].name == 'simple' assert system.controllers[0].cls == 'ControllerType'
def test_auto_host_port(self): s = """ site: name: site1 #host: 200.131.64.200 # default=None #port: 10000 # default=None """ system = SystemConfig.fromString(s) assert system.sites[0].host == MANAGER_DEFAULT_HOST assert system.sites[0].port == MANAGER_DEFAULT_PORT
def test_multiple_instruments(self): s = """ instrument: - name: simple type: InstrumentType - name: simple type: InstrumentType """ system = SystemConfig(s, loadGlobal=False) assert len(system.instruments) == 2
def test_multiple_instruments(self): s = """ instrument: - name: simple type: InstrumentType - name: simple type: InstrumentType """ system = SystemConfig.fromString(s) assert len(system.instruments) == 2
def startup(self): if self.options.daemon: # detach log.info("FIXME: Daemon...") # system config try: self.config = SystemConfig.fromFile(self.options.config_file) except (InvalidLocationException, IOError), e: log.exception(e) log.error("There was a problem reading your configuration file. (%s)" % e) sys.exit(1)
def _startSystem (self, options): try: self.sysconfig = SystemConfig.fromFile(options.config) self.localManager = Manager(self.sysconfig.chimera["host"], getattr(options, 'port', 9000)) self._remoteManager = ManagerLocator.locate(self.sysconfig.chimera["host"], self.sysconfig.chimera["port"]) except ManagerNotFoundException: # FIXME: better way to start Chimera site = SiteController(wait=False) site.startup() self._keepRemoteManager = False self._remoteManager = ManagerLocator.locate(self.sysconfig.chimera["host"], self.sysconfig.chimera["port"])
def test_complex_device(self): s = """ telescope: name: tel1 device: /dev/ttyS0 driver: name: driverName """ # driver must have a type assert_raises(TypeNotFoundException, SystemConfig, s) s = """ telescope: name: tel1 device: /dev/ttyS0 driver: type: DriverType device: /dev/ttyS1 # name: driverName # default=noname """ system = SystemConfig(s, loadGlobal=False) assert system.drivers[0].cls == 'DriverType' assert system.drivers[0].name == 'noname' assert system.drivers[0].config["device"] == '/dev/ttyS1' # device is ignored, just the driver get their own assert not 'device' in system.telescopes[0].config assert system.telescopes[0].config['driver'] == system.drivers[0] system.dump()
def startup(self): if self.options.daemon: # detach log.info("FIXME: Daemon...") # system config try: self.config = SystemConfig.fromFile(self.options.config_file) except (InvalidLocationException, IOError), e: log.exception(e) log.error( "There was a problem reading your configuration file. (%s)" % e) sys.exit(1)
def setJD(self,options): ''' Configure time domain by specifing a julian day. It will use information on exposure time to build time bins that will be filled when selecting targets. ''' sysconfig = SystemConfig.fromFile(options.config) manager = Manager() site = manager.getProxy(sysconfig.sites[0]) jd = options.JD if not jd: jd = np.floor(site.JD())+0.5 lat = np.array([float(tt) / 60.**i for i,tt in enumerate(str(site['latitude']).split(':'))]) lat[1:] *= lat[0]/np.abs(lat[0]) sitelat = np.sum(lat) long = np.array([float(tt) / 60.**i for i,tt in enumerate(str(site['longitude']).split(':'))]) long[1:] *= long[0]/np.abs(long[0]) sitelong = abs(np.sum(long)/360*24.) print site['latitude'],'->',sitelat print site['longitude'],'->',sitelong nightstart = _skysub.jd_sun_alt(self.sunMaxAlt, jd, sitelat, sitelong) nightend = _skysub.jd_sun_alt(self.sunMaxAlt, jd+0.5, sitelat, sitelong) print('Nigh Start @JD= %.3f # Night End @JD = %.3f'%(nightstart,nightend)) # Creating a 1 minute time bin tbin = self.tbin self.obsTimeBins = np.arange(nightstart,nightend+tbin,tbin) self.obsTimeMask = np.zeros(len(self.obsTimeBins)) self.obsTimeMask[-1] = 1.0 # Marking filled bins session = Session() scheduled = session.query(Program) for target in scheduled: tindex = np.abs(self.obsTimeBins - 2400000.5 - target.slewAt).argmin() self.obsTimeMask[tindex] = 1.0 self.isJD = True
def _startSystem(self, options): try: self.sysconfig = SystemConfig.fromFile(options.config) self.localManager = Manager(self.sysconfig.chimera["host"], getattr(options, 'port', 9000)) self._remoteManager = ManagerLocator.locate( self.sysconfig.chimera["host"], self.sysconfig.chimera["port"]) except ManagerNotFoundException: # FIXME: better way to start Chimera site = SiteController(wait=False) site.startup() self._keepRemoteManager = False self._remoteManager = ManagerLocator.locate( self.sysconfig.chimera["host"], self.sysconfig.chimera["port"])
def test_auto_type_name (self): s = """ site: name: site1 #type: SiteType # type would be Site (key.capitalize()) host: 200.131.64.200 port: 10000 config0: value0 """ system = SystemConfig.fromString(s) assert system.sites[0].name == "site1" assert system.sites[0].cls == "Site" assert system.sites[0].host == "200.131.64.200" assert system.sites[0].port == 10000 assert system.sites[0].config['config0'] == 'value0'
def test_specials (self): s = """ site: name: site1 type: SiteType host: 200.131.64.200 port: 10000 config0: value0 telescope: name: tel1 type: TelescopeType host: 200.131.64.201 port: 10001 config1: value1 camera: name: cam1 type: CameraType host: 200.131.64.202 port: 10002 config2: value2 focuser: name: focuser1 type: FocuserType host: 200.131.64.203 port: 10003 config3: value3 dome: name: dome1 type: DomeType host: 200.131.64.204 port: 10004 config4: value4 filterwheel: name: wheel1 type: FilterWheelType host: 200.131.64.205 port: 10005 config5: value5 filters: [R, G, B, RGB, CLEAR] """ system = SystemConfig.fromString(s) assert system.sites[0].name == "site1" assert system.sites[0].cls == "SiteType" assert system.sites[0].host == "200.131.64.200" assert system.sites[0].port == 10000 assert system.sites[0].config['config0'] == 'value0' assert system.instruments[0].name == "tel1" assert system.instruments[0].cls == "TelescopeType" assert system.instruments[0].host == "200.131.64.201" assert system.instruments[0].port == 10001 assert system.instruments[0].config['config1'] == 'value1' assert system.instruments[1].name == "cam1" assert system.instruments[1].cls == "CameraType" assert system.instruments[1].host == "200.131.64.202" assert system.instruments[1].port == 10002 assert system.instruments[1].config['config2'] == 'value2' assert system.instruments[2].name == "focuser1" assert system.instruments[2].cls == "FocuserType" assert system.instruments[2].host == "200.131.64.203" assert system.instruments[2].port == 10003 assert system.instruments[2].config['config3'] == 'value3' assert system.instruments[3].name == "dome1" assert system.instruments[3].cls == "DomeType" assert system.instruments[3].host == "200.131.64.204" assert system.instruments[3].port == 10004 assert system.instruments[3].config['config4'] == 'value4' assert system.instruments[4].name == "wheel1" assert system.instruments[4].cls == "FilterWheelType" assert system.instruments[4].host == "200.131.64.205" assert system.instruments[4].port == 10005 assert system.instruments[4].config['config5'] == 'value5' assert system.instruments[4].config['filters'] == ["R", "G", "B", "RGB", "CLEAR"] assert len(system.instruments) == 5
def test_from_default(self): s = SystemConfig.fromDefault() s.dump()
def startup(self): if self.options.daemon: # detach log.info("FIXME: Daemon...") # system config try: self.config = SystemConfig.fromFile(self.options.config_file) except (InvalidLocationException, IOError) as e: log.exception(e) log.error( "There was a problem reading your configuration file. (%s)" % e) sys.exit(1) # manager if not self.options.dry: log.info("Starting system.") log.info("Chimera: %s" % _chimera_version_) log.info("Chimera prefix: %s" % ChimeraPath().root()) log.info("Python: %s" % platform.python_version()) log.info("System: %s" % ' '.join(platform.uname())) try: self.manager = Manager(**self.config.chimera) except ChimeraException as e: log.error( "Chimera is already running on this machine. Use chimera-admin to manage it." ) sys.exit(1) log.info("Chimera: running on " + self.manager.getHostname() + ":" + str(self.manager.getPort())) log.info("Chimera: reading configuration from %s" % os.path.realpath(self.options.config_file)) # add site object if not self.options.dry: for site in self.config.sites: self.manager.addClass(Site, site.name, site.config, True) # search paths log.info( "Setting objects include path from command line parameters...") for _dir in self.options.inst_dir: self.paths["instruments"].append(_dir) for _dir in self.options.ctrl_dir: self.paths["controllers"].append(_dir) # init from config log.info("Trying to start instruments...") for inst in self.config.instruments + self.options.instruments: if self.options.dry: print(inst) else: self._add(inst, path=self.paths["instruments"], start=True) log.info("Trying to start controllers...") for ctrl in self.config.controllers + self.options.controllers: if self.options.dry: print(ctrl) else: self._add(ctrl, path=self.paths["controllers"], start=True) log.info("System up and running.") # ok, let's wait manager work if self.wait and not self.options.dry: self.manager.wait()
def test_specials(self): s = """ site: name: site1 type: SiteType host: 200.131.64.200 port: 10000 config0: value0 telescope: name: tel1 type: TelescopeType host: 200.131.64.201 port: 10001 config1: value1 camera: name: cam1 type: CameraType host: 200.131.64.202 port: 10002 config2: value2 focuser: name: focuser1 type: FocuserType host: 200.131.64.203 port: 10003 config3: value3 dome: name: dome1 type: DomeType host: 200.131.64.204 port: 10004 config4: value4 filterwheel: name: wheel1 type: FilterWheelType host: 200.131.64.205 port: 10005 config5: value5 filters: [R, G, B, RGB, CLEAR] """ system = SystemConfig.fromString(s) assert system.sites[0].name == "site1" assert system.sites[0].cls == "SiteType" assert system.sites[0].host == "200.131.64.200" assert system.sites[0].port == 10000 assert system.sites[0].config['config0'] == 'value0' assert system.instruments[0].name == "tel1" assert system.instruments[0].cls == "TelescopeType" assert system.instruments[0].host == "200.131.64.201" assert system.instruments[0].port == 10001 assert system.instruments[0].config['config1'] == 'value1' assert system.instruments[1].name == "cam1" assert system.instruments[1].cls == "CameraType" assert system.instruments[1].host == "200.131.64.202" assert system.instruments[1].port == 10002 assert system.instruments[1].config['config2'] == 'value2' assert system.instruments[2].name == "focuser1" assert system.instruments[2].cls == "FocuserType" assert system.instruments[2].host == "200.131.64.203" assert system.instruments[2].port == 10003 assert system.instruments[2].config['config3'] == 'value3' assert system.instruments[3].name == "dome1" assert system.instruments[3].cls == "DomeType" assert system.instruments[3].host == "200.131.64.204" assert system.instruments[3].port == 10004 assert system.instruments[3].config['config4'] == 'value4' assert system.instruments[4].name == "wheel1" assert system.instruments[4].cls == "FilterWheelType" assert system.instruments[4].host == "200.131.64.205" assert system.instruments[4].port == 10005 assert system.instruments[4].config['config5'] == 'value5' assert system.instruments[4].config['filters'] == [ "R", "G", "B", "RGB", "CLEAR" ] assert len(system.instruments) == 5