Module csw.Parameter

Functions

def stringKey(name: str,
units: Units = Units.NoUnits) ‑> Key[str]
Expand source code
def stringKey(name: str, units: Units = Units.NoUnits) -> Key[str]:
    return StringKey().make(name, units)

Classes

class AltAzCoordKey
Expand source code
class AltAzCoordKey:
    @staticmethod
    def make(name: str, units: Units = Units.NoUnits) -> Key[AltAzCoord]:
        return Key(name, KeyTypes.AltAzCoordKey, units)

Static methods

def make(name: str,
units: Units = Units.NoUnits) ‑> Key[AltAzCoord]
Expand source code
@staticmethod
def make(name: str, units: Units = Units.NoUnits) -> Key[AltAzCoord]:
    return Key(name, KeyTypes.AltAzCoordKey, units)
class BooleanKey
Expand source code
class BooleanKey:
    @staticmethod
    def make(name: str, units: Units = Units.NoUnits) -> Key[bool]:
        return Key(name, KeyTypes.BooleanKey, units)

Static methods

def make(name: str,
units: Units = Units.NoUnits) ‑> Key[bool]
Expand source code
@staticmethod
def make(name: str, units: Units = Units.NoUnits) -> Key[bool]:
    return Key(name, KeyTypes.BooleanKey, units)
class ByteArrayKey
Expand source code
class ByteArrayKey:
    @staticmethod
    def make(name: str, units: Units = Units.NoUnits) -> Key[List[bytes]]:
        return Key(name, KeyTypes.ByteArrayKey, units)

Static methods

def make(name: str,
units: Units = Units.NoUnits) ‑> Key[typing.List[bytes]]
Expand source code
@staticmethod
def make(name: str, units: Units = Units.NoUnits) -> Key[List[bytes]]:
    return Key(name, KeyTypes.ByteArrayKey, units)
class ByteKey
Expand source code
class ByteKey:
    @staticmethod
    def make(name: str, units: Units = Units.NoUnits) -> Key[int]:
        return Key(name, KeyTypes.ByteKey, units)

Static methods

def make(name: str,
units: Units = Units.NoUnits) ‑> Key[int]
Expand source code
@staticmethod
def make(name: str, units: Units = Units.NoUnits) -> Key[int]:
    return Key(name, KeyTypes.ByteKey, units)
class ByteMatrixKey
Expand source code
class ByteMatrixKey:
    @staticmethod
    def make(name: str, units: Units = Units.NoUnits) -> Key[List[List[bytes]]]:
        return Key(name, KeyTypes.ByteMatrixKey, units)

Static methods

def make(name: str,
units: Units = Units.NoUnits) ‑> Key[typing.List[typing.List[bytes]]]
Expand source code
@staticmethod
def make(name: str, units: Units = Units.NoUnits) -> Key[List[List[bytes]]]:
    return Key(name, KeyTypes.ByteMatrixKey, units)
class CharKey
Expand source code
class CharKey:
    @staticmethod
    def make(name: str, units: Units = Units.NoUnits) -> Key[str]:
        return Key(name, KeyTypes.CharKey, units)

Static methods

def make(name: str,
units: Units = Units.NoUnits) ‑> Key[str]
Expand source code
@staticmethod
def make(name: str, units: Units = Units.NoUnits) -> Key[str]:
    return Key(name, KeyTypes.CharKey, units)
class ChoiceKey
Expand source code
@dataclass
class ChoiceKey(KeyType[str]):

    @staticmethod
    def make(name: str, choices: List[str]) -> GChoiceKey[str]:
        return GChoiceKey(name, KeyTypes.ChoiceKey, Units.NoUnits, choices)

ChoiceKey()

Ancestors

Static methods

def make(name: str, choices: List[str]) ‑> GChoiceKey[str]
Expand source code
@staticmethod
def make(name: str, choices: List[str]) -> GChoiceKey[str]:
    return GChoiceKey(name, KeyTypes.ChoiceKey, Units.NoUnits, choices)
class CometCoordKey
Expand source code
class CometCoordKey:
    @staticmethod
    def make(name: str, units: Units = Units.NoUnits) -> Key[CometCoord]:
        return Key(name, KeyTypes.CometCoordKey, units)

Static methods

def make(name: str,
units: Units = Units.NoUnits) ‑> Key[CometCoord]
Expand source code
@staticmethod
def make(name: str, units: Units = Units.NoUnits) -> Key[CometCoord]:
    return Key(name, KeyTypes.CometCoordKey, units)
class CoordKey
Expand source code
class CoordKey:
    @staticmethod
    def make(name: str, units: Units = Units.NoUnits) -> Key[Coord]:
        return Key(name, KeyTypes.CoordKey, units)

Static methods

def make(name: str,
units: Units = Units.NoUnits) ‑> Key[Coord]
Expand source code
@staticmethod
def make(name: str, units: Units = Units.NoUnits) -> Key[Coord]:
    return Key(name, KeyTypes.CoordKey, units)
class DoubleArrayKey
Expand source code
class DoubleArrayKey:
    @staticmethod
    def make(name: str, units: Units = Units.NoUnits) -> Key[List[float]]:
        return Key(name, KeyTypes.DoubleArrayKey, units)

Static methods

def make(name: str,
units: Units = Units.NoUnits) ‑> Key[typing.List[float]]
Expand source code
@staticmethod
def make(name: str, units: Units = Units.NoUnits) -> Key[List[float]]:
    return Key(name, KeyTypes.DoubleArrayKey, units)
class DoubleKey
Expand source code
class DoubleKey:
    @staticmethod
    def make(name: str, units: Units = Units.NoUnits) -> Key[float]:
        return Key(name, KeyTypes.DoubleKey, units)

Static methods

def make(name: str,
units: Units = Units.NoUnits) ‑> Key[float]
Expand source code
@staticmethod
def make(name: str, units: Units = Units.NoUnits) -> Key[float]:
    return Key(name, KeyTypes.DoubleKey, units)
class DoubleMatrixKey
Expand source code
class DoubleMatrixKey:
    @staticmethod
    def make(name: str, units: Units = Units.NoUnits) -> Key[List[List[float]]]:
        return Key(name, KeyTypes.DoubleMatrixKey, units)

Static methods

def make(name: str,
units: Units = Units.NoUnits) ‑> Key[typing.List[typing.List[float]]]
Expand source code
@staticmethod
def make(name: str, units: Units = Units.NoUnits) -> Key[List[List[float]]]:
    return Key(name, KeyTypes.DoubleMatrixKey, units)
class EqCoordKey
Expand source code
class EqCoordKey:
    @staticmethod
    def make(name: str, units: Units = Units.NoUnits) -> Key[EqCoord]:
        return Key(name, KeyTypes.EqCoordKey, units)

Static methods

def make(name: str,
units: Units = Units.NoUnits) ‑> Key[EqCoord]
Expand source code
@staticmethod
def make(name: str, units: Units = Units.NoUnits) -> Key[EqCoord]:
    return Key(name, KeyTypes.EqCoordKey, units)
class FloatArrayKey
Expand source code
class FloatArrayKey:
    @staticmethod
    def make(name: str, units: Units = Units.NoUnits) -> Key[List[float]]:
        return Key(name, KeyTypes.FloatArrayKey, units)

Static methods

def make(name: str,
units: Units = Units.NoUnits) ‑> Key[typing.List[float]]
Expand source code
@staticmethod
def make(name: str, units: Units = Units.NoUnits) -> Key[List[float]]:
    return Key(name, KeyTypes.FloatArrayKey, units)
class FloatKey
Expand source code
class FloatKey:
    @staticmethod
    def make(name: str, units: Units = Units.NoUnits) -> Key[float]:
        return Key(name, KeyTypes.FloatKey, units)

Static methods

def make(name: str,
units: Units = Units.NoUnits) ‑> Key[float]
Expand source code
@staticmethod
def make(name: str, units: Units = Units.NoUnits) -> Key[float]:
    return Key(name, KeyTypes.FloatKey, units)
class FloatMatrixKey
Expand source code
class FloatMatrixKey:
    @staticmethod
    def make(name: str, units: Units = Units.NoUnits) -> Key[List[List[float]]]:
        return Key(name, KeyTypes.FloatMatrixKey, units)

Static methods

def make(name: str,
units: Units = Units.NoUnits) ‑> Key[typing.List[typing.List[float]]]
Expand source code
@staticmethod
def make(name: str, units: Units = Units.NoUnits) -> Key[List[List[float]]]:
    return Key(name, KeyTypes.FloatMatrixKey, units)
class GChoiceKey (keyName: str,
keyType: KeyTypes,
units: Units,
choices: List[str])
Expand source code
@dataclass
class GChoiceKey(Key[T]):
    """
    A key for a choice item similar to an enumeration

    Args:
        keyName: the name of the key
        keyType: reference to an object of type KeyType[S]
        units: applicable units
        choices: the available choices, the values set must be in the choices
    """
    choices: List[str]

    def validate(self, *values: str):
        """
        validates the input list of choices

        Args:
            *values:  one or more values
        """
        assert all(i in self.choices for i in values), \
            f"Bad choice for key: {self.keyName} which must be one of: {self.choices}"

    def set(self, *values: str) -> Parameter[str]:
        self.validate(*values)
        return Parameter(self.keyName, self.keyType, [*values], self.units)

    def setAll(self, values: List[str]) -> Parameter[str]:
        self.validate(*values)
        return Parameter(self.keyName, self.keyType, values, self.units)

A key for a choice item similar to an enumeration

Args

keyName
the name of the key
keyType
reference to an object of type KeyType[S]
units
applicable units
choices
the available choices, the values set must be in the choices

Ancestors

  • Key
  • typing.Generic

Instance variables

var choices : List[str]

The type of the None singleton.

Methods

def validate(self, *values: str)
Expand source code
def validate(self, *values: str):
    """
    validates the input list of choices

    Args:
        *values:  one or more values
    """
    assert all(i in self.choices for i in values), \
        f"Bad choice for key: {self.keyName} which must be one of: {self.choices}"

validates the input list of choices

Args

*values
one or more values

Inherited members

class IntArrayKey
Expand source code
class IntArrayKey:
    @staticmethod
    def make(name: str, units: Units = Units.NoUnits) -> Key[List[int]]:
        return Key(name, KeyTypes.IntArrayKey, units)

Static methods

def make(name: str,
units: Units = Units.NoUnits) ‑> Key[typing.List[int]]
Expand source code
@staticmethod
def make(name: str, units: Units = Units.NoUnits) -> Key[List[int]]:
    return Key(name, KeyTypes.IntArrayKey, units)
class IntKey
Expand source code
class IntKey:
    @staticmethod
    def make(name: str, units: Units = Units.NoUnits) -> Key[int]:
        return Key(name, KeyTypes.IntKey, units)

Static methods

def make(name: str,
units: Units = Units.NoUnits) ‑> Key[int]
Expand source code
@staticmethod
def make(name: str, units: Units = Units.NoUnits) -> Key[int]:
    return Key(name, KeyTypes.IntKey, units)
class IntMatrixKey
Expand source code
class IntMatrixKey:
    @staticmethod
    def make(name: str, units: Units = Units.NoUnits) -> Key[List[List[int]]]:
        return Key(name, KeyTypes.IntMatrixKey, units)

Static methods

def make(name: str,
units: Units = Units.NoUnits) ‑> Key[typing.List[typing.List[int]]]
Expand source code
@staticmethod
def make(name: str, units: Units = Units.NoUnits) -> Key[List[List[int]]]:
    return Key(name, KeyTypes.IntMatrixKey, units)
class Key (keyName: str,
keyType: KeyTypes,
units: Units)
Expand source code
@dataclass
class Key(Generic[T]):
    """
    A generic Key class. Never meant to be instantiated directly. [[csw.params.core.generics.KeyType]] exposes
    allowed types of Keys and make method to create instances of Key.

    Args:
        keyName: the name of the key
        keyType: reference to an object of type KeyType[S]
        units: applicable units
    """
    keyName: str
    keyType: KeyTypes
    units: Units

    def set(self, *values: T) -> Parameter[T]:
        """
        Set values for this key using variable number of arguments
        Args:
            *values: an Array of values

        Returns:
            an instance of Parameter[T] containing the key name and values

        """
        return Parameter(self.keyName, self.keyType, [*values], self.units)

    def setAll(self, values: List[T]) -> Parameter[T]:
        """
        Set values for this key using a list
        Args:
            *values: an Array of values

        Returns:
            an instance of Parameter[T] containing the key name and values

        """
        return Parameter(self.keyName, self.keyType, values, self.units)

A generic Key class. Never meant to be instantiated directly. [[csw.params.core.generics.KeyType]] exposes allowed types of Keys and make method to create instances of Key.

Args

keyName
the name of the key
keyType
reference to an object of type KeyType[S]
units
applicable units

Ancestors

  • typing.Generic

Subclasses

Instance variables

var keyName : str

The type of the None singleton.

var keyTypeKeyTypes

The type of the None singleton.

var unitsUnits

The type of the None singleton.

Methods

def set(self, *values: ~T) ‑> Parameter[~T]
Expand source code
def set(self, *values: T) -> Parameter[T]:
    """
    Set values for this key using variable number of arguments
    Args:
        *values: an Array of values

    Returns:
        an instance of Parameter[T] containing the key name and values

    """
    return Parameter(self.keyName, self.keyType, [*values], self.units)

Set values for this key using variable number of arguments

Args

*values
an Array of values

Returns

an instance of Parameter[T] containing the key name and values

def setAll(self, values: List[~T]) ‑> Parameter[~T]
Expand source code
def setAll(self, values: List[T]) -> Parameter[T]:
    """
    Set values for this key using a list
    Args:
        *values: an Array of values

    Returns:
        an instance of Parameter[T] containing the key name and values

    """
    return Parameter(self.keyName, self.keyType, values, self.units)

Set values for this key using a list

Args

*values
an Array of values

Returns

an instance of Parameter[T] containing the key name and values

class KeyType
Expand source code
@dataclass
class KeyType(Generic[T]):
    pass

KeyType()

Ancestors

  • typing.Generic

Subclasses

class LongArrayKey
Expand source code
class LongArrayKey:
    @staticmethod
    def make(name: str, units: Units = Units.NoUnits) -> Key[List[int]]:
        return Key(name, KeyTypes.LongArrayKey, units)

Static methods

def make(name: str,
units: Units = Units.NoUnits) ‑> Key[typing.List[int]]
Expand source code
@staticmethod
def make(name: str, units: Units = Units.NoUnits) -> Key[List[int]]:
    return Key(name, KeyTypes.LongArrayKey, units)
class LongKey
Expand source code
class LongKey:
    @staticmethod
    def make(name: str, units: Units = Units.NoUnits) -> Key[int]:
        return Key(name, KeyTypes.LongKey, units)

Static methods

def make(name: str,
units: Units = Units.NoUnits) ‑> Key[int]
Expand source code
@staticmethod
def make(name: str, units: Units = Units.NoUnits) -> Key[int]:
    return Key(name, KeyTypes.LongKey, units)
class LongMatrixKey
Expand source code
class LongMatrixKey:
    @staticmethod
    def make(name: str, units: Units = Units.NoUnits) -> Key[List[List[int]]]:
        return Key(name, KeyTypes.LongMatrixKey, units)

Static methods

def make(name: str,
units: Units = Units.NoUnits) ‑> Key[typing.List[typing.List[int]]]
Expand source code
@staticmethod
def make(name: str, units: Units = Units.NoUnits) -> Key[List[List[int]]]:
    return Key(name, KeyTypes.LongMatrixKey, units)
class MinorPlanetCoordKey
Expand source code
class MinorPlanetCoordKey:
    @staticmethod
    def make(name: str, units: Units = Units.NoUnits) -> Key[MinorPlanetCoord]:
        return Key(name, KeyTypes.MinorPlanetCoordKey, units)

Static methods

def make(name: str,
units: Units = Units.NoUnits) ‑> Key[MinorPlanetCoord]
Expand source code
@staticmethod
def make(name: str, units: Units = Units.NoUnits) -> Key[MinorPlanetCoord]:
    return Key(name, KeyTypes.MinorPlanetCoordKey, units)
class Parameter (keyName: str,
keyType: KeyTypes,
values: List[~T],
units: Units = <factory>)
Expand source code
@dataclass
class Parameter(Generic[T]):
    # noinspection PyUnresolvedReferences
    """
        Creates a Parameter (keys with values, units).

        Args:

            keyName (str): name of the key
            keyType (KeyTypes): type of the key
            values (List[T]): an array of values, or a nested array for array and matrix types.
            units (Units): units of the values.
        """
    keyName: str
    keyType: KeyTypes
    values: List[T]
    units: Units = field(default_factory=lambda: Units.NoUnits)

    @staticmethod
    def _paramValueOrDict(keyType: KeyTypes, param: T, forEvent: bool):
        """
        Internal method that also handles coord and time types

        Args:
            keyType (KeyTypes): parameter's key type
            param (T): parameter value
            forEvent (bool): needed since time values are encoded differently in CBOR and JSON

        Returns:
            param value
        """
        # keyTypes = coordTypes.union(timeKeyTypes) if forEvent else coordTypes
        if keyType in coordTypes:
            return param._asDict()
        if keyType in timeKeyTypes:
            if forEvent:
                return param._asDict()
            return str(param)
        return param

    @staticmethod
    def _paramValueFromDict(keyType: KeyTypes, obj: T, forEvent: bool) -> T:
        """
        Internal recursive method that also handles Coord types

        Args:

            keyType (KeyTypes): parameter's key type
            obj: T
            forEvent (bool): needed since time values are encoded differently in CBOR and JSON

        Returns: object
            param value
        """
        if keyType in coordTypes:
            return Coord._fromDict(obj)
        elif not forEvent and keyType in timeKeyTypes:
            if keyType == KeyTypes.UTCTimeKey:
                return UTCTime.from_str(obj)
            else:
                return TAITime.from_str(obj)
        else:
            return obj

    # noinspection PyTypeChecker
    # forEvent flag is needed since time and byte values are encoded differently in CBOR and JSON
    def _asDict(self, forEvent: bool = False):
        # Note that bytes are stored in a byte string (b'...') instead of a list or array.
        if forEvent and self.keyType == KeyTypes.ByteKey:
            values = bytes(self.values)
        else:
            values = list(map(lambda p: Parameter._paramValueOrDict(self.keyType, p, forEvent), self.values))

        return {
            self.keyType.name: {
                'keyName': self.keyName,
                'values': values,
                'units': self.units.name
            }
        }

    @staticmethod
    # forEvent flag is needed since time values are encoded differently in CBOR and JSON
    def _fromDict(obj: dict, forEvent: bool = False):
        """
        Returns a Parameter for the given dict.
        """
        k = next(iter(obj))
        keyType = KeyTypes[k]
        obj = obj[k]

        if forEvent and keyType == KeyTypes.ByteKey:
            values = list(obj['values'])
        else:
            values = list(map(lambda p: Parameter._paramValueFromDict(keyType, p, forEvent), obj['values']))
        return Parameter(obj['keyName'], keyType, values, Units[obj['units']])

Creates a Parameter (keys with values, units).

Args

keyName : str
name of the key
keyType : KeyTypes
type of the key
values : List[T]
an array of values, or a nested array for array and matrix types.
units : Units
units of the values.

Ancestors

  • typing.Generic

Instance variables

var keyName : str

The type of the None singleton.

var keyTypeKeyTypes

The type of the None singleton.

var unitsUnits

The type of the None singleton.

var values : List[~T]

The type of the None singleton.

class ShortArrayKey
Expand source code
class ShortArrayKey:
    @staticmethod
    def make(name: str, units: Units = Units.NoUnits) -> Key[List[int]]:
        return Key(name, KeyTypes.ShortArrayKey, units)

Static methods

def make(name: str,
units: Units = Units.NoUnits) ‑> Key[typing.List[int]]
Expand source code
@staticmethod
def make(name: str, units: Units = Units.NoUnits) -> Key[List[int]]:
    return Key(name, KeyTypes.ShortArrayKey, units)
class ShortKey
Expand source code
class ShortKey:
    @staticmethod
    def make(name: str, units: Units = Units.NoUnits) -> Key[int]:
        return Key(name, KeyTypes.ShortKey, units)

Static methods

def make(name: str,
units: Units = Units.NoUnits) ‑> Key[int]
Expand source code
@staticmethod
def make(name: str, units: Units = Units.NoUnits) -> Key[int]:
    return Key(name, KeyTypes.ShortKey, units)
class ShortMatrixKey
Expand source code
class ShortMatrixKey:
    @staticmethod
    def make(name: str, units: Units = Units.NoUnits) -> Key[List[List[int]]]:
        return Key(name, KeyTypes.ShortMatrixKey, units)

Static methods

def make(name: str,
units: Units = Units.NoUnits) ‑> Key[typing.List[typing.List[int]]]
Expand source code
@staticmethod
def make(name: str, units: Units = Units.NoUnits) -> Key[List[List[int]]]:
    return Key(name, KeyTypes.ShortMatrixKey, units)
class SolarSystemCoordKey
Expand source code
class SolarSystemCoordKey:
    @staticmethod
    def make(name: str, units: Units = Units.NoUnits) -> Key[SolarSystemCoord]:
        return Key(name, KeyTypes.SolarSystemCoordKey, units)

Static methods

def make(name: str,
units: Units = Units.NoUnits) ‑> Key[SolarSystemCoord]
Expand source code
@staticmethod
def make(name: str, units: Units = Units.NoUnits) -> Key[SolarSystemCoord]:
    return Key(name, KeyTypes.SolarSystemCoordKey, units)
class StringKey
Expand source code
class StringKey:
    @staticmethod
    def make(name: str, units: Units = Units.NoUnits) -> Key[str]:
        return Key(name, KeyTypes.StringKey, units)

Static methods

def make(name: str,
units: Units = Units.NoUnits) ‑> Key[str]
Expand source code
@staticmethod
def make(name: str, units: Units = Units.NoUnits) -> Key[str]:
    return Key(name, KeyTypes.StringKey, units)
class TAITimeKey
Expand source code
class TAITimeKey:
    @staticmethod
    def make(name: str, units: Units = Units.NoUnits) -> Key[TAITime]:
        return Key(name, KeyTypes.TAITimeKey, units)

Static methods

def make(name: str,
units: Units = Units.NoUnits) ‑> Key[TAITime]
Expand source code
@staticmethod
def make(name: str, units: Units = Units.NoUnits) -> Key[TAITime]:
    return Key(name, KeyTypes.TAITimeKey, units)
class UTCTimeKey
Expand source code
class UTCTimeKey:
    @staticmethod
    def make(name: str, units: Units = Units.NoUnits) -> Key[UTCTime]:
        return Key(name, KeyTypes.UTCTimeKey, units)

Static methods

def make(name: str,
units: Units = Units.NoUnits) ‑> Key[UTCTime]
Expand source code
@staticmethod
def make(name: str, units: Units = Units.NoUnits) -> Key[UTCTime]:
    return Key(name, KeyTypes.UTCTimeKey, units)