def test_enum(self): Values = Enum("A_VALUE", "OTHER_VALUE") c = Config({"key_enum": Values.A_VALUE}) # default assert c["key_enum"] == Values.A_VALUE # valid for i in Values: assert c.__setitem__( "key_enum", i) != False, "%s (%s) is a valid enum configuration" % ( i, type(i)) assert type(c.__getitem__( "key_enum")) == EnumValue, "should return EnumValue object" for i in [ "A_VALUE", "OTHER_VALUE", "a_value", "other_value", "a_vAlUe", "oThEr_VaLuE" ]: assert c.__setitem__( "key_enum", i) != False, "%s (%s) is a valid enum configuration" % ( i, type(i)) assert type(c.__getitem__( "key_enum")) == EnumValue, "should return EnumValue object" # invalid assert_raises(KeyError, c.__getitem__, "WHATERVER")
import yaml from sqlalchemy import or_, and_ import datetime from chimera_supervisor.controllers.scheduler.model import ObsBlock, ExtMoniDB, ObservedAM, TimedDB, RecurrentDB, Session from chimera.util.enum import Enum from chimera.core.constants import SYSTEM_CONFIG_DIRECTORY from chimera.core.site import datetimeFromJD from chimera.core.exceptions import ChimeraException from chimera.util.position import Position from chimera.util.coord import Coord from chimera.util.output import blue, green, red import logging from multiprocessing.pool import ThreadPool as Pool ScheduleOptions = Enum("HIG", "STD") class ExtintionMonitorException(ChimeraException): pass class TimedException(ChimeraException): pass fileHandler = logging.handlers.RotatingFileHandler(os.path.join( SYSTEM_CONFIG_DIRECTORY, "scheduler_algorithms.log"), maxBytes=100 * 1024 * 1024, backupCount=10)
from enum import Enum try: from chimera.core.compat import * except ImportError: if sys.version_info[:2] < (2, 5): def any(iterable): for element in iterable: if element: return True return False __all__ = ['Coord', 'CoordUtil'] State = Enum("HMS", "DMS", "D", "H", "R", "AS") class CoordUtil(object): COORD_RE = re.compile( '((?P<dd>(?P<sign>[+-]?)[\s]*\d+)[dh]?[\s:]*)?((?P<mm>\d+)[m]?[\s:]*)?((?P<ss>\d+)(?P<msec>\.\d*)?([\ss]*))?' ) _arcsec2deg = 1.0 / 3600 _min2deg = 1.0 / 60 @staticmethod def epsEqual(a, b, eps=1e-7): return abs(a - b) <= eps
import serial from chimera.core.chimeraobject import ChimeraObject from chimera.interfaces.focuser import InvalidFocusPositionException from chimera.interfaces.focuserdriver import IFocuserDriver from chimera.core.lock import lock from chimera.util.enum import Enum __all__ = ['OptecTCFS'] Mode = Enum("Manual", "Free", "Auto_A", "Auto_B") Direction = Enum("IN", "OUT") class OptecTCFS (ChimeraObject, IFocuserDriver): def __init__ (self): ChimeraObject.__init__ (self) self.tty = None self._directions = {Direction.IN : "FI", Direction.OUT: "FO"} self._modes = {Mode.Manual: "M", Mode.Free : "F",
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301, USA. from chimera.core.interface import Interface from chimera.core.event import event from chimera.util.enum import Enum from chimera.core.exceptions import ChimeraException GuiderStatus = Enum("OK", "GUIDING", "OFF", "ERROR", "ABORTED") class StarNotFoundException (ChimeraException): pass class Autoguider (Interface): __config__ = {"site": '/Site/0', # Telescope Site. "telescope": "/Telescope/0", # Telescope instrument that will be guided by the autoguider. "camera": "/Camera/0", # Guider camera instrument. "filterwheel": None, # Filter wheel instrument, if there is one. "focuser": None, # Guider camera focuser, if there is one. "autofocus": None, # Autofocus controller, if there is one. "scheduler": None, # Scheduler controller, if there is one. "max_acquire_tries": 3, # Number of tries to find a guiding star.
from chimera.core.exceptions import ChimeraException class CantPointScopeException(ChimeraException): pass class CanSetScopeButNotThisField(ChimeraException): pass class CantSetScopeException(ChimeraException): pass Target = Enum("CURRENT", "AUTO") class PointVerify(Interface): __config__ = { "telescope": "/Telescope/0", "camera": "/Camera/0", "filterwheel": "/FilterWheel/0", "tolra": 0.0166666666667, "toldec": 0.0166666666667, "exptime": 10.0, "filter": "R", "max_trials": 5, "max_fields": 5 }
from chimera.util.enum import Enum SchedulerStatus = Enum("OK", "ABORTED", "ERROR", "SKIPPED")
# You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301, USA. from chimera.core.interface import Interface from chimera.core.event import event from chimera.core.exceptions import ChimeraException from chimera.util.enum import Enum from chimera.util.coord import Coord __all__ = ['Mode', 'Type', 'Dome', 'InvalidDomePositionException'] Mode = Enum("Stand", "Track") Style = Enum("Rolloff", "Classic", "Other") DomeStatus = Enum("OK", "ABORTED") class InvalidDomePositionException(ChimeraException): """ Raised when trying to slew to an invalid azimuth angle. """ class Dome(Interface): """ A Roll-off or classic dome. """
from chimera.util.enum import Enum Unit = Enum ("PERCENTUAL", # Humidity "CELSIUS", # Temperature, Dew point "KELVIN", "FAHRENHEIT", "M_PER_S", # Wind "KM_PER_H", "MILES_PER_H", "FT_PER_S", "MS", "KMH", "FTS", "MPH", "M_BAR", # Pressure "MM_HG", "TORR", "ATM", "PA", "PSI", "MM_PER_H", # Rain "CM_PER_H", "FT_PER_H", ) class WeatherStation (Interface):
# of the License, or (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301, USA. from chimera.core.event import event from chimera.core.interface import Interface from chimera.util.enum import Enum SwitchStatus = Enum("ON", "OFF", "UNKNOWN", "ERROR") class Switch(Interface): """ Interface for general switches """ __config__ = { "device": None, "switch_timeout": None, # Maximum number of seconds to wait for state change } def switchOn(self): """
# of the License, or (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. from chimera.core.interface import Interface from chimera.core.event import event from chimera.util.enum import Enum Shutter = Enum('OPEN', 'CLOSE', 'LEAVE_AS_IS') class ICamera(Interface): """Base camera interface. """ # config __config__ = { "driver": "/FakeCamera/0", "camera_model": "Fake camera Inc.", "ccd_model": "KAF XYZ 10", "telescope_focal_length": 4000 # milimeter }
from collections import namedtuple from chimera.util.enum import Enum InstrumentOperationFlag = Enum( "UNSET", # No info about instrument operation condition "READY", # Instrument can open and operate normally "OPERATING", # Instrument was instanciated by manager and should be operating "CLOSE", # Instrument should be closed and must not be operated "LOCK", # Instrument was locked. It will require a key to unlock # (known to the one that locked it). "ERROR" # Instrument in error. Operation condition is uncertain ) OperationStatus = Enum("DAYTIME_IDLE", "NIGHTTIME_IDLE", "DAYTIME_OPERATING", "NIGHTTIME_OPERATING", "WEATHER_CLOSED", "NETWORK_CLOSED", "TECHNICAL_CLOSED", "UNSPECIFIED_CLOSED") FlagStatus = Enum("UNKNOWN", "UNSET", "OK", "WARNING", "ALERT", "ABORTED", "ERROR") ResponseStatus = Enum("OK", "ERROR", "ABORTED")
# but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301, USA. from chimera.core.interface import Interface from chimera.core.event import event from chimera.core.exceptions import ChimeraException from chimera.util.position import Position from chimera.util.enum import Enum AlignMode = Enum("ALT_AZ", "POLAR", "LAND") SlewRate = Enum("GUIDE", "CENTER", "FIND", "MAX") TelescopeStatus = Enum("OK", "ERROR", "ABORTED", "OBJECT_TOO_LOW", "OBJECT_TOO_HIGH") TelescopePierSide = Enum("EAST", "WEST", "UNKNOWN") class PositionOutsideLimitsException(ChimeraException): pass class Telescope(Interface): """ Telescope base interface.
# of the License, or (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. from chimera.core.interface import Interface from chimera.core.exceptions import ChimeraException from chimera.util.enum import Enum FocuserFeature = Enum("TEMPERATURE_COMPENSATION", "ENCODER", "POSITION_FEEDBACK") class InvalidFocusPositionException(ChimeraException): """ Represents an outside of boundaries Focuser error. """ class Focuser(Interface): """Instrument interface for an electromechanical focuser for astronomical telescopes. Two kinds of focusers are supported: - Encoder based: use optical encoder to move to exact
# This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. from chimera.core.interface import Interface from chimera.core.event import event from chimera.util.enum import Enum from chimera.core.exceptions import ChimeraException Shutter = Enum('OPEN', 'CLOSE', 'LEAVE_AS_IS') Bitpix = Enum("char8", "uint16", "int16", "int32", "int64", "float32", "float64") CCD = Enum("IMAGING", "TRACKING") # Special features parameters can be passed as ImageRequest # parameters. The Camera.supports(feature) method can be used # to ask if the current camera support a given feature (useful for # interfaces, to decides when to display options to the user). CameraFeature = Enum("TEMPERATURE_CONTROL", "PROGRAMMABLE_GAIN", "PROGRAMMABLE_OVERSCAN", "PROGRAMMABLE_FAN", "PROGRAMMABLE_LEDS", "PROGRAMMABLE_BIAS_LEVEL")
from chimera.util.enum import Enum ConstraintReturns = Enum('GOOD', 'BAD', 'DONTCARE') __all__ = ['ConstraintReturns'] class Constraints: def __init__(self): self.__constraints = {'MoonDistance': MoonDistanceConstraint()} def checkConstraint(self, constraintName, paramMin, paramMax, exposure=None, observation=None, program=None): return self.__constraints[constraintName].checkConstraint( paramMin, paramMax, exposure=None, observation=None, program=None) class IConstraint: def __init__(self): self.DONTCARE = ConstraintReturns.DONTCARE self.GOOD = ConstraintReturns.GOOD self.BAD = ConstraintReturns.BAD """ Return the name by which this constraint is referenced. """
#! /usr/bin/env python # -*- coding: iso-8859-1 -*- # chimera - observatory automation system # Copyright (C) 2006-2007 P. Henrique Silva <*****@*****.**> # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. from chimera.util.enum import Enum State = Enum('RUNNING', 'STOPPED')
from chimera.core.chimeraobject import ChimeraObject from chimera.core.event import event from chimera.controllers.scheduler.machine import Machine from chimera.controllers.scheduler.sequential import SequentialScheduler from chimera.controllers.scheduler.circular import CircularScheduler from chimera.controllers.scheduler.executor import ProgramExecutor from chimera.controllers.scheduler.states import State from chimera.controllers.scheduler.model import Session from chimera.util.enum import Enum print "controller" SchedulingAlgorithm = Enum("SEQUENTIAL", "CIRCULAR") SchedulingAlgorithms = { SchedulingAlgorithm.SEQUENTIAL: SequentialScheduler(), SchedulingAlgorithm.CIRCULAR: CircularScheduler() } class Scheduler(ChimeraObject): __config__ = { "telescope": "/Telescope/0", "camera": "/Camera/0", "filterwheel": "/FilterWheel/0", "focuser": "******", "dome": "/Dome/0", "autofocus": "/Autofocus/0", "point_verify": "/PointVerify/0",
# but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. from chimera.core.interface import Interface from chimera.core.event import event from chimera.core.exceptions import ChimeraException from chimera.util.position import Position from chimera.util.enum import Enum AlignMode = Enum("ALT_AZ", "POLAR", "LAND") SlewRate = Enum("GUIDE", "CENTER", "FIND", "MAX") TelescopeStatus = Enum("OK", "ABORTED", "OBJECT_TOO_LOW", "OBJECT_TOO_HIGH") class PositionOutsideLimitsException(ChimeraException): pass class Telescope(Interface): """ Telescope base interface. """ __config__ = {
from chimera.interfaces.telescopedriver import SlewRate, AlignMode from chimera.util.coord import Coord from chimera.util.position import Position from chimera.util.enum import Enum from chimera.core.lock import lock from chimera.core.exceptions import ChimeraException, ObjectNotFoundException class MeadeException(ChimeraException): pass Direction = Enum("E", "W", "N", "S") class Meade(ChimeraObject, ITelescopeDriverSlew, ITelescopeDriverSync, ITelescopeDriverPark, ITelescopeDriverTracking): __config__ = {'azimuth180Correct': True} def __init__(self): ChimeraObject.__init__(self) self._tty = None self._slewRate = None self._abort = threading.Event() self._slewing = False
from chimera_supervisor.controllers.scheduler.machine import Machine from chimera_supervisor.controllers.scheduler import algorithms from chimera.core.chimeraobject import ChimeraObject from chimera.core.constants import SYSTEM_CONFIG_DIRECTORY from chimera.core.site import datetimeFromJD from chimera.core.event import event from chimera.controllers.scheduler.states import State as SchedState from chimera.controllers.scheduler.status import SchedulerStatus from chimera.controllers.scheduler import model from chimera.util.position import Position from chimera.util.coord import Coord from chimera.util.enum import Enum from chimera.util.output import blue, green, red RobState = Enum('OFF', 'ON') schedAlgorithms = {} for name, obj in inspect.getmembers(algorithms): if inspect.isclass(obj) and issubclass(obj, algorithms.BaseScheduleAlgorith): schedAlgorithms[obj.id()] = obj class RobObs(ChimeraObject): __config__ = { "site": "/Site/0", "schedulers": "/Scheduler/0", "weatherstations": None, "seeingmonitors": None,
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. from chimera.core.interface import Interface from chimera.core.event import event from chimera.util.enum import Enum from chimera.core.exceptions import ChimeraException Filter = Enum ("U", "B", "V", "R", "I", # Johnson-Cousins "C", "M", "T1", "T2", # Washington "u", "g", "r", "i", "z", # SDSS "J", "H", "K", "Kp", # MKO "Z", "Y", "J", "H", "K", # UKIDSS design "R", "G", "B", "RGB", "RED", "GREEN", "BLUE", "H_ALPHA", "H_BETA", "CLEAR", "LUNAR", ) class InvalidFilterPositionException (ChimeraException): pass class IFilterWheel (Interface): """ An interface for electromechanical filter wheels. Allow simple control and monitor filter changes """
# of the License, or (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. from chimera.core.interface import Interface from chimera.core.event import event from chimera.util.enum import Enum AlignMode = Enum("ALT_AZ", "POLAR", "LAND") SlewRate = Enum("GUIDE", "CENTER", "FIND", "MAX") class ITelescopeDriver(Interface): __config__ = {"device": "/dev/ttyS0", "align_mode": AlignMode.POLAR} class ITelescopeDriverSlew(ITelescopeDriver): __config__ = { "timeout": 30, # s "slew_rate": SlewRate.MAX, "auto_align": True, "slew_idle_time": 0.1, # s
from chimera.util.enum import Enum __all__ = ['State'] State = Enum("OFF", "START", "IDLE", "BUSY", "STOP", "SHUTDOWN")
# You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301, USA. from chimera.core.interface import Interface from chimera.core.exceptions import ChimeraException from chimera.util.enum import Enum FocuserFeature = Enum("TEMPERATURE_COMPENSATION", "ENCODER", "POSITION_FEEDBACK", "CONTROLLABLE_X", "CONTROLLABLE_Y", "CONTROLLABLE_Z", "CONTROLLABLE_U", "CONTROLLABLE_V", "CONTROLLABLE_W") FocuserAxis = Enum("X", "Y", "Z", "U", "V", "W") ControllableAxis = {FocuserFeature.CONTROLLABLE_X: FocuserAxis.X, FocuserFeature.CONTROLLABLE_Y: FocuserAxis.Y, FocuserFeature.CONTROLLABLE_Z: FocuserAxis.Z, FocuserFeature.CONTROLLABLE_U: FocuserAxis.U, FocuserFeature.CONTROLLABLE_V: FocuserAxis.V, FocuserFeature.CONTROLLABLE_W: FocuserAxis.W, }
# You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. from chimera.interfaces.focuser import (InvalidFocusPositionException, FocuserFeature) from chimera.instruments.focuser import FocuserBase from chimera.core.constants import SYSTEM_CONFIG_DIRECTORY from chimera.core.lock import lock from chimera.util.enum import Enum import os Direction = Enum("IN", "OUT") __all__ = ['Direction', 'DCFocuser'] class DCFocuser(FocuserBase): """ DCFocuser uses as standard DC pulse Focuser with a software layer to mimic the behaviour of a Encoder-based Focuser. You have to define two parameter: - 'dt': define the longest pulse possible to go end-to-end through the focuser. - 'pulse_dt': how long would a single unit pulse be. NOTE: For APIs which doesn't provide access to time driven focuser movements, dt and pulse_dt could be in whatever unit you like, for
try: from chimera.util.coord import Coord, CoordUtil except ImportError: from coord import Coord, CoordUtil try: from chimera.util.enum import Enum except ImportError: from enum import Enum import ephem from types import StringType __all__ = ['Position'] Epoch = Enum("J2000", "B1950", "NOW") System = Enum("CELESTIAL", "GALACTIC", "ECLIPTIC", "TOPOCENTRIC") class PositionOutsideLimitsError(Exception): pass class Position(object): """Position represents a coordinate pair in a reference frame. There are five factories available, that can be used to create Position in different frames. Each factory accepts a pair of parameters. The parameters format is tied to the choosen frame. The intent is to accept the most
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. from chimera.core.interface import Interface from chimera.core.event import event from chimera.core.exceptions import ChimeraException from chimera.util.enum import Enum __all__ = ['Mode', 'Type', 'IDome', 'InvalidDomePositionException'] Mode = Enum("Stand", "Track") Type = Enum("Rolloff", "Classic", "Other") class InvalidDomePositionException(ChimeraException): """ Raised when trying to slew to an invalid azimuth angle. """ class IDome(Interface): """A Roll-off or classic dome. """ __config__ = { "driver": "/FakeDome/0",
from chimera.core.managerlocator import ManagerLocator, ManagerNotFoundException from chimera.util.enum import Enum import Pyro.errors import sys import optparse import os.path import threading import socket import time __all__ = ['ChimeraCLI', 'Action', 'Parameter', 'action', 'parameter'] ParameterType = Enum("INSTRUMENT", "CONTROLLER", "BOOLEAN", "CHOICE", "INCLUDE_PATH", "CONSTANT") class Option(object): name = None short = None long = None type = None default = None choices = None actionGroup = None
# This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301, USA. from chimera.core.interface import Interface from chimera.interfaces.switch import Switch, SwitchStatus, SwitchState from chimera.util.enum import Enum FanDirection = Enum("FORWARD", "REVERSE") FanStatus = SwitchStatus class Fan(Interface): """ Basic fan interface. """ __config__ = { "device": None, "model": "Unknown", } class FanControl(Switch):