Module csw.ParameterSetType

Classes

class CommandName (name: str)
Expand source code
@dataclass
class CommandName:
    """
    A wrapper class representing the name of a Command
    """
    name: str

A wrapper class representing the name of a Command

Instance variables

var name : str

The type of the None singleton.

class ControlCommand (source: Prefix,
commandName: CommandName,
maybeObsId: ObsId | None = <factory>,
paramSet: List[Parameter] = <factory>)
Expand source code
@dataclass
class ControlCommand(SequenceCommand):
    pass

ControlCommand(source: csw.Prefix.Prefix, commandName: csw.ParameterSetType.CommandName, maybeObsId: csw.ObsId.ObsId | None = , paramSet: List[csw.Parameter.Parameter] = )

Ancestors

Subclasses

Inherited members

class Observe (source: Prefix,
commandName: CommandName,
maybeObsId: ObsId | None = <factory>,
paramSet: List[Parameter] = <factory>)
Expand source code
@dataclass
class Observe(ControlCommand):
    """
    An Observe is a special command that can be sent to an HCD or Assembly.
    """
    pass

An Observe is a special command that can be sent to an HCD or Assembly.

Ancestors

Inherited members

class SequenceCommand (source: Prefix,
commandName: CommandName,
maybeObsId: ObsId | None = <factory>,
paramSet: List[Parameter] = <factory>)
Expand source code
@dataclass
class SequenceCommand:
    """
    Represents a CSW command.
    """
    source: Prefix
    commandName: CommandName
    maybeObsId: ObsId | None = field(default_factory=lambda: None)
    paramSet: List[Parameter] = field(default_factory=lambda: [])

    # noinspection PyProtectedMember
    @staticmethod
    def _fromDict(obj):
        """
        Returns a ControlCommand for the given dict.
        """
        typ = obj["_type"]
        source = Prefix.from_str(obj['source'])
        commandName = CommandName(obj['commandName'])
        maybeObsId = ObsId.make(obj['maybeObsId']) if 'maybeObsId' in obj else None
        paramSet = list(map(lambda p: Parameter._fromDict(p), obj['paramSet']))
        assert (typ in {"Setup", "Observe", "Wait"})
        match typ:
            case 'Setup':
                return Setup(source, commandName, maybeObsId, paramSet)
            case 'Observe':
                return Observe(source, commandName, maybeObsId, paramSet)
            case 'Wait':
                return Wait(source, commandName, maybeObsId, paramSet)
            case _:
                raise TypeError

    # noinspection PyProtectedMember
    def _asDict(self) -> dict:
        """
        Returns: dict
            a dictionary corresponding to this object
        """
        d = {
            '_type': self.__class__.__name__,
            'source': str(self.source),
            'commandName': self.commandName.name,
            'paramSet': list(map(lambda p: p._asDict(), self.paramSet))
        }
        if self.maybeObsId:
            d['maybeObsId'] = str(self.maybeObsId)

        return d

    # noinspection PyUnusedLocal
    def get(self, keyName: str, keyType: KeyType[T]) -> Parameter[T] | None:
        """
        Gets the parameter with the given name, or else returns None.

        Args:
            keyName (str): parameter name
            keyType (KeyType[T]): parameter key type (used only for type hint: See also gets(keyName))

        Returns: Parameter[T] | None
            the parameter, if found
        """
        for p in self.paramSet:
            if p.keyName == keyName:
                return p

    def gets(self, keyName: str) -> Parameter | None:
        """
        Gets the parameter with the given name, or else returns None.

        Args:
            keyName (str): parameter name

        Returns: Parameter | None
            the parameter, if found
        """
        for p in self.paramSet:
            if p.keyName == keyName:
                return p

    def __call__(self, key: Key[T]) -> Parameter[T] | None:
        """
        This is similar to Scala's apply() method and gets the parameter for the given key, or else returns None.

        Args:
            key (Key[T]): parameter key

        Returns: Parameter[T] | None
            the parameter, if found
        """
        for p in self.paramSet:
            if p.keyName == key.keyName:
                return p

    def exists(self, keyName: str) -> bool:
        """
        Returns true if the parameter with the given name is present

        Args:
            keyName (str): parameter name

        Returns: bool
            true if the parameter is found
        """
        for p in self.paramSet:
            if p.keyName == keyName:
                return True
        return False

Represents a CSW command.

Subclasses

Instance variables

var commandNameCommandName

The type of the None singleton.

var maybeObsIdObsId | None

The type of the None singleton.

var paramSet : List[Parameter]

The type of the None singleton.

var sourcePrefix

The type of the None singleton.

Methods

def exists(self, keyName: str) ‑> bool
Expand source code
def exists(self, keyName: str) -> bool:
    """
    Returns true if the parameter with the given name is present

    Args:
        keyName (str): parameter name

    Returns: bool
        true if the parameter is found
    """
    for p in self.paramSet:
        if p.keyName == keyName:
            return True
    return False

Returns true if the parameter with the given name is present

Args

keyName : str
parameter name

Returns: bool true if the parameter is found

def get(self,
keyName: str,
keyType: KeyType[~T]) ‑> Parameter[~T] | None
Expand source code
def get(self, keyName: str, keyType: KeyType[T]) -> Parameter[T] | None:
    """
    Gets the parameter with the given name, or else returns None.

    Args:
        keyName (str): parameter name
        keyType (KeyType[T]): parameter key type (used only for type hint: See also gets(keyName))

    Returns: Parameter[T] | None
        the parameter, if found
    """
    for p in self.paramSet:
        if p.keyName == keyName:
            return p

Gets the parameter with the given name, or else returns None.

Args

keyName : str
parameter name
keyType : KeyType[T]
parameter key type (used only for type hint: See also gets(keyName))

Returns: Parameter[T] | None the parameter, if found

def gets(self, keyName: str) ‑> Parameter | None
Expand source code
def gets(self, keyName: str) -> Parameter | None:
    """
    Gets the parameter with the given name, or else returns None.

    Args:
        keyName (str): parameter name

    Returns: Parameter | None
        the parameter, if found
    """
    for p in self.paramSet:
        if p.keyName == keyName:
            return p

Gets the parameter with the given name, or else returns None.

Args

keyName : str
parameter name

Returns: Parameter | None the parameter, if found

class Setup (source: Prefix,
commandName: CommandName,
maybeObsId: ObsId | None = <factory>,
paramSet: List[Parameter] = <factory>)
Expand source code
@dataclass
class Setup(ControlCommand):
    """
    A Setup is a command that can be sent to an HCD or Assembly.
    """
    pass

A Setup is a command that can be sent to an HCD or Assembly.

Ancestors

Inherited members

class Wait (source: Prefix,
commandName: CommandName,
maybeObsId: ObsId | None = <factory>,
paramSet: List[Parameter] = <factory>)
Expand source code
@dataclass
class Wait(SequenceCommand):
    """
    A Wait command can only be sent to a sequencer
    """
    pass

A Wait command can only be sent to a sequencer

Ancestors

Inherited members