def currentStates(self) -> List[CurrentState]:
     intParam = Parameter("IntValue", "IntKey", [42], "arcsec")
     intArrayParam = Parameter("IntArrayValue", "IntArrayKey", [[1, 2, 3, 4], [5, 6, 7, 8]])
     floatArrayParam = Parameter("FloatArrayValue", "FloatArrayKey", [[1.2, 2.3, 3.4], [5.6, 7.8, 9.1]], "marcsec")
     intMatrixParam = Parameter("IntMatrixValue", "IntMatrixKey",
                                [[[1, 2, 3, 4], [5, 6, 7, 8]], [[-1, -2, -3, -4], [-5, -6, -7, -8]]], "meter")
     return [CurrentState(self.prefix, "PyCswState", [intParam, intArrayParam, floatArrayParam, intMatrixParam])]
Beispiel #2
0
 def __init__(self):
     intParam = Parameter("IntValue", "IntKey", [42], "arcsec")
     intArrayParam = Parameter("IntArrayValue", "IntArrayKey", [[1,2,3,4], [5,6,7,8]])
     floatArrayParam = Parameter("FloatArrayValue", "FloatArrayKey", [[1.2, 2.3, 3.4], [5.6, 7.8, 9.1]], "marcsec")
     intMatrixParam = Parameter("IntMatrixValue", "IntMatrixKey", [[[1,2,3,4], [5,6,7,8]],[[-1,-2,-3,-4], [-5,-6,-7,-8]]], "meter")
     event = SystemEvent("CSW.testassembly", "myAssemblyEvent", [intParam, intArrayParam, floatArrayParam, intMatrixParam])
     self.pub.publish(event)
Beispiel #3
0
 def publishEvent4(self):
     keyName = "assemblyEventValue"
     keyType = KeyType.UTCTimeKey
     values = [UTCTime.from_str("2021-09-20T20:43:35.419053077Z")]
     param = Parameter(keyName, keyType, values)
     keyName2 = "assemblyEventValue2"
     keyType2 = KeyType.TAITimeKey
     values2 = [TAITime.from_str("2021-09-20T18:44:12.419084072Z")]
     param2 = Parameter(keyName2, keyType2, values2)
     paramSet = [param, param2]
     event = SystemEvent(self.prefix, EventName("testEvent4"), paramSet)
     self.log.debug(f"Publishing event {event}")
     self.pub.publish(event)
Beispiel #4
0
 def publishEvent2(self):
     intParam = Parameter("IntValue", KeyType.IntKey, [42], Units.arcsec)
     intArrayParam = Parameter("IntArrayValue", KeyType.IntArrayKey,
                               [[1, 2, 3, 4], [5, 6, 7, 8]])
     floatArrayParam = Parameter("FloatArrayValue", KeyType.FloatArrayKey,
                                 [[1.2, 2.3, 3.4], [5.6, 7.8, 9.1]],
                                 Units.marcsec)
     intMatrixParam = Parameter("IntMatrixValue", KeyType.IntMatrixKey,
                                [[[1, 2, 3, 4], [5, 6, 7, 8]],
                                 [[-1, -2, -3, -4], [-5, -6, -7, -8]]],
                                Units.meter)
     paramSet = [intParam, intArrayParam, floatArrayParam, intMatrixParam]
     event = SystemEvent(self.prefix, EventName("testEvent2"), paramSet)
     self.pub.publish(event)
Beispiel #5
0
 def publishEvent2(self):
     intParam = Parameter("IntValue", "IntKey", [42], "arcsec")
     intArrayParam = Parameter("IntArrayValue", "IntArrayKey",
                               [[1, 2, 3, 4], [5, 6, 7, 8]])
     floatArrayParam = Parameter("FloatArrayValue", "FloatArrayKey",
                                 [[1.2, 2.3, 3.4], [5.6, 7.8, 9.1]],
                                 "marcsec")
     intMatrixParam = Parameter("IntMatrixValue", "IntMatrixKey",
                                [[[1, 2, 3, 4], [5, 6, 7, 8]],
                                 [[-1, -2, -3, -4], [-5, -6, -7, -8]]],
                                "meter")
     event = SystemEvent(
         self.prefix, "testEvent2",
         [intParam, intArrayParam, floatArrayParam, intMatrixParam])
     self.pub.publish(event)
Beispiel #6
0
 def test_command_service_models(self):
     testDir = pathlib.Path(__file__).parent.absolute()
     with open(f"{testDir}/command-models.json") as json_file:
         data = json.load(json_file)
         for p in data['Units']:
             assert (Units[p].name == p)
         for p in data['UTCTime']:
             t1 = UTCTime.from_str(p)
             t2 = UTCTime.from_str(str(t1))
             assert (t1 == t2)
         for p in data['CurrentState']:
             cs = CurrentState._fromDict(p)
             assert (str(cs.prefix) == "CSW.ncc.trombone")
             assert (str(cs.stateName) == "idle")
             assert (len(cs.paramSet) == 25)
             for entry in p['paramSet']:
                 for key in entry:
                     # Round-trip test
                     # (ignore time values since resolution of fractional seconds is different in Typescript!)
                     if key not in ['UTCTimeKey', 'TAITimeKey']:
                         assert (
                             entry == Parameter._fromDict(entry)._asDict())
         for p in data["CommandIssue"]:
             # Check that the CommandIssue subclass exists
             assert (p['_type'] in self.commandIssueSubclasses)
    def onSubmit(self, runId: str, command: ControlCommand) -> (CommandResponse, Task):
        """
        Overrides the base class onSubmit method to handle commands from a CSW component.
        See ./testSupport/test-assembly/src/main/scala/org/tmt/csw/testassembly/TestAssemblyHandlers.scala#makeTestCommand
        for the contents of the command's parameters.

        Args:
            runId (str): unique id for this command
            command (ControlCommand): contains the command

        Returns: (CommandResponse, Task)
            a pair: (subclass of CommandResponse, Task), where the task can be None if the command response is final.
            For long running commands, you can respond with Started(runId, "...") and a task that completes the work in the background.
        """
        self._checkCommand(command)
        n = len(command.paramSet)
        print(f"MyComponentHandlers Received setup {str(command)} with {n} params")
        # filt = command.get("filter").values[0]
        # encoder = command.get("encoder").values[0]
        # print(f"filter = {filt}, encoder = {encoder}")

        if command.commandName == "LongRunningCommand":
            task = asyncio.create_task(self.longRunningCommand(runId, command))
            return Started(runId, "Long running task in progress..."), task
        elif command.commandName == "SimpleCommand":
            return Completed(runId), None
        elif command.commandName == "ResultCommand":
            result = Result([Parameter("myValue", 'DoubleKey', [42.0])])
            return Completed(runId, result), None
        elif command.commandName == "ErrorCommand":
            return Error(runId, "Error command received"), None
        elif command.commandName == "InvalidCommand":
            return Invalid(runId, MissingKeyIssue("Missing required key XXX")), None
        else:
            return Invalid(runId, UnsupportedCommandIssue(f"Unknown command: {command.commandName}")), None
Beispiel #8
0
 def _fromDict(obj):
     """
     Returns a CurrentState for the given dict.
     """
     prefix = Prefix.from_str(obj['prefix'])
     stateName = obj['stateName']
     paramSet = list(map(lambda p: Parameter._fromDict(p), obj['paramSet']))
     return CurrentState(prefix, stateName, paramSet)
Beispiel #9
0
 def publishEvent1(self):
     keyName = "assemblyEventValue"
     keyType = 'DoubleKey'
     values = [42.0]
     param = Parameter(keyName, keyType, values)
     paramSet = [param]
     event = SystemEvent(self.prefix, "testEvent1", paramSet)
     print(f"Publishing event {event}")
     self.pub.publish(event)
Beispiel #10
0
 def publishEvent1(self):
     keyName = "assemblyEventValue"
     keyType = KeyType.DoubleKey
     values = [42.0]
     param = Parameter(keyName, keyType, values)
     paramSet = [param]
     event = SystemEvent(self.prefix, EventName("testEvent1"), paramSet)
     self.log.debug(f"Publishing event {event}")
     self.pub.publish(event)
Beispiel #11
0
 def _fromDict(obj):
     """
     Returns a ControlCommand for the given dict.
     """
     typ = obj["_type"]
     source = Prefix.from_str(obj['source'])
     commandName = CommandName(obj['commandName'])
     maybeObsId = obj['maybeObsId'] if 'maybeObsId' in obj else ""
     paramSet = list(map(lambda p: Parameter._fromDict(p), obj['paramSet']))
     assert (typ in {"Setup", "Observe"})
     if typ == 'Setup':
         return Setup(source, commandName, maybeObsId, paramSet)
     else:
         return Observe(source, commandName, maybeObsId, paramSet)
Beispiel #12
0
 def _fromDict(obj):
     """
     Returns a Event for the given dict.
     """
     typ = obj['_type']
     assert (typ in {"SystemEvent", "ObserveEvent"})
     paramSet = list(map(lambda p: Parameter._fromDict(p), obj['paramSet']))
     eventTime = EventTime._fromDict(obj['eventTime'])
     if typ == 'SystemEvent':
         return SystemEvent(obj['source'], obj['eventName'], paramSet,
                            eventTime, obj['eventId'])
     else:
         return ObserveEvent(obj['source'], obj['eventName'], paramSet,
                             eventTime, obj['eventId'])
Beispiel #13
0
    def onSubmit(self, runId: str,
                 command: ControlCommand) -> (CommandResponse, Task):
        """
        Overrides the base class onSubmit method to handle commands from a CSW component

        Args:
            runId (str): unique id for this command
            command (ControlCommand): contains the ControlCommand from CSW

        Returns: (CommandResponse, Task)
            a subclass of CommandResponse that is serialized and passed back to the CSW component
        """
        n = len(command.paramSet)
        print(
            f"MyComponentHandlers Received setup {str(command)} with {n} params"
        )
        # filt = command.get("filter").values[0]
        # encoder = command.get("encoder").values[0]
        # print(f"filter = {filt}, encoder = {encoder}")

        # --- Example return values ---

        # return Completed(runId), None

        # return Error(runId, "There is a problem ..."), None

        # return Invalid(runId, MissingKeyIssue("Missing required key XXX")), None

        # result = Result("tcs.filter", [Parameter("myValue", 'DoubleKey', [42.0])])
        # return Completed(runId, result), None

        if command.commandName == "LongRunningCommand":
            task = asyncio.create_task(self.longRunningCommand(runId, command))
            return Started(runId, "Long running task in progress..."), task
        elif command.commandName == "SimpleCommand":
            return Completed(runId), None
        elif command.commandName == "ResultCommand":
            result = Result([Parameter("myValue", 'DoubleKey', [42.0])])
            return Completed(runId, result), None
        else:
            return Invalid(
                runId,
                UnsupportedCommandIssue(
                    f"Unknown command: {command.commandName}")), None
    def test_pub_sub(self):
        pub = EventPublisher()
        sub = EventSubscriber()

        prefix = Prefix(Subsystems.CSW, "assembly")
        eventName = EventName("test_event")
        eventKey = EventKey(prefix, eventName)
        keyName = "testEventValue"
        keyType = KeyType.IntKey
        values = [42]
        param = Parameter(keyName, keyType, values)
        paramSet = [param]
        event = SystemEvent(prefix, eventName, paramSet)

        thread = sub.subscribe([eventKey], self.callback)
        pub.publish(event)
        time.sleep(1)
        e = sub.get(eventKey)
        assert (e == event)
        assert (self.count == 1)
        sub.unsubscribe([eventKey])
        thread.stop()
Beispiel #15
0
from csw.Event import SystemEvent, EventName
from csw.EventPublisher import EventPublisher
from csw.Parameter import Parameter
from csw.KeyType import KeyType
from csw.Prefix import Prefix
from csw.Subsystem import Subsystems

# Test publishing events
from csw.TAITime import TAITime

prefix = Prefix(Subsystems.CSW, "testassembly")
eventName = EventName("myAssemblyEvent")

keyName = "assemblyEventValue"
keyType = KeyType.TAITimeKey
param = Parameter(keyName, keyType, [TAITime.fromSystem()])
paramSet = [param]

event = SystemEvent(prefix, eventName, paramSet)
pub = EventPublisher()
pub.publish(event)
Beispiel #16
0
    def __init__(self):
        intParam = Parameter("IntValue", "IntKey", [42], "arcsec")
        floatParam = Parameter("floatValue", "FloatKey", [float(42.1)], "arcsec")
        longParam = Parameter("longValue", "LongKey", [42], "arcsec")
        shortParam = Parameter("shortValue", "ShortKey", [42], "arcsec")
        byteParam = Parameter("byteValue", "ByteKey", b'\xDE\xAD\xBE\xEF')
        booleanParam = Parameter("booleanValue", "BooleanKey", [True, False], "arcsec")

        intArrayParam = Parameter("IntArrayValue", "IntArrayKey", [[1, 2, 3, 4], [5, 6, 7, 8]])
        floatArrayParam = Parameter("FloatArrayValue", "FloatArrayKey", [[1.2, 2.3, 3.4], [5.6, 7.8, 9.1]], "arcsec")
        doubleArrayParam = Parameter("DoubleArrayValue", "DoubleArrayKey", [[1.2, 2.3, 3.4], [5.6, 7.8, 9.1]], "arcsec")

        byteArrayParam = Parameter("ByteArrayValue", "ByteArrayKey", [b'\xDE\xAD\xBE\xEF', bytes([1, 2, 3, 4])])

        intMatrixParam = Parameter("IntMatrixValue", "IntMatrixKey",
                                   [[[1, 2, 3, 4], [5, 6, 7, 8]], [[-1, -2, -3, -4], [-5, -6, -7, -8]]], "meter")

        eqCoord = EqCoord.make(ra="12:13:14.15 hours", dec="-30:31:32.3 deg", frame=EqFrame.FK5, pm=(0.5, 2.33))
        solarSystemCoord = SolarSystemCoord.make("BASE", SolarSystemObject.Venus)
        minorPlanetCoord = MinorPlanetCoord.make("GUIDER1", 2000, "90 deg", "2 deg", "100 deg", 1.4, 0.234,
                                                 "220 deg")
        cometCoord = CometCoord.make("BASE", 2000.0, "90 deg", "2 deg", "100 deg", 1.4, 0.234)
        altAzCoord = AltAzCoord.make("301 deg", "42.5 deg")
        coordsParam = Parameter("CoordParam", "CoordKey",
                                [eqCoord, solarSystemCoord, minorPlanetCoord, cometCoord, altAzCoord])

        structParam = Parameter("MyStruct", "StructKey", [Struct(
            [coordsParam, intParam, floatParam, longParam, shortParam, booleanParam, intArrayParam, floatArrayParam,
             doubleArrayParam, intMatrixParam])])

        paramSet = [coordsParam, byteParam, intParam, floatParam, longParam, shortParam, booleanParam, byteArrayParam,
                    intArrayParam, floatArrayParam, doubleArrayParam, intMatrixParam, structParam]
        event = SystemEvent("CSW.testassembly", "myAssemblyEvent", paramSet)
        self.pub.publish(event)
Beispiel #17
0
    def publishEvent3(self):
        intParam = Parameter("IntValue", KeyType.IntKey, [42], Units.arcsec)
        floatParam = Parameter("floatValue", KeyType.FloatKey, [float(42.1)],
                               Units.arcsec)
        longParam = Parameter("longValue", KeyType.LongKey, [42], Units.arcsec)
        shortParam = Parameter("shortValue", KeyType.ShortKey, [42],
                               Units.arcsec)
        byteParam = Parameter("byteValue", KeyType.ByteKey,
                              b'\xDE\xAD\xBE\xEF')
        booleanParam = Parameter("booleanValue", KeyType.BooleanKey,
                                 [True, False], Units.arcsec)

        intArrayParam = Parameter("IntArrayValue", KeyType.IntArrayKey,
                                  [[1, 2, 3, 4], [5, 6, 7, 8]])
        floatArrayParam = Parameter("FloatArrayValue", KeyType.FloatArrayKey,
                                    [[1.2, 2.3, 3.4], [5.6, 7.8, 9.1]],
                                    Units.arcsec)
        doubleArrayParam = Parameter("DoubleArrayValue",
                                     KeyType.DoubleArrayKey,
                                     [[1.2, 2.3, 3.4], [5.6, 7.8, 9.1]],
                                     Units.arcsec)

        byteArrayParam = Parameter(
            "ByteArrayValue", KeyType.ByteArrayKey,
            [b'\xDE\xAD\xBE\xEF', bytes([1, 2, 3, 4])])

        intMatrixParam = Parameter("IntMatrixValue", KeyType.IntMatrixKey,
                                   [[[1, 2, 3, 4], [5, 6, 7, 8]],
                                    [[-1, -2, -3, -4], [-5, -6, -7, -8]]],
                                   Units.meter)

        eqCoord = EqCoord.make(ra="12:13:14.15 hours",
                               dec="-30:31:32.3 deg",
                               frame=EqFrame.FK5,
                               pm=(0.5, 2.33))
        solarSystemCoord = SolarSystemCoord.make("BASE",
                                                 SolarSystemObject.Venus)
        minorPlanetCoord = MinorPlanetCoord.make("GUIDER1", 2000, "90 deg",
                                                 "2 deg", "100 deg", 1.4,
                                                 0.234, "220 deg")
        cometCoord = CometCoord.make("BASE", 2000.0, "90 deg", "2 deg",
                                     "100 deg", 1.4, 0.234)
        altAzCoord = AltAzCoord.make("301 deg", "42.5 deg")
        coordsParam = Parameter("CoordParam", KeyType.CoordKey, [
            eqCoord, solarSystemCoord, minorPlanetCoord, cometCoord, altAzCoord
        ])

        paramSet = [
            coordsParam, byteParam, intParam, floatParam, longParam,
            shortParam, booleanParam, byteArrayParam, intArrayParam,
            floatArrayParam, doubleArrayParam, intMatrixParam
        ]
        event = SystemEvent(self.prefix, EventName("testEvent3"), paramSet)
        self.pub.publish(event)
Beispiel #18
0
from csw.Event import SystemEvent, EventName
from csw.EventPublisher import EventPublisher
from csw.KeyType import KeyType
from csw.Parameter import Parameter
from csw.Prefix import Prefix
from csw.Subsystem import Subsystems

# Test publishing events
source = Prefix(Subsystems.CSW, "testassembly")
eventName = EventName("myAssemblyEvent")

keyName = "assemblyEventValue"
keyType = KeyType.DoubleKey
values = [42.0]
param = Parameter(keyName, keyType, values)
paramSet = [param]

event = SystemEvent(source, eventName, paramSet)
pub = EventPublisher()
pub.publish(event)