"""
Contains very basic building blocks used elsewhere in the PDM.
Enums, constants, type definitions, etc.
Don't put any fancy models or classes in here.
"""
from enum import Enum
from typing import Annotated, TypeVar
from pydantic import WrapSerializer
# If we upgrade to Py>3.10, could we use StrEnum?
[docs]
class TerseStrEnum(str, Enum):
"""Subclass to give enums a terse repr()"""
def __str__(self):
return self.value
def __repr__(self):
return f"{self.__class__.__name__}.{self.name}"
T = TypeVar("T")
# Frozenset that serialises to a sorted list in JSON
# to avoid test failures from unstable ordering.
# https://github.com/pydantic/pydantic/discussions/8794#discussioncomment-8453370
StableSet = Annotated[
frozenset[T],
WrapSerializer(lambda v, next_: sorted(next_(v)), when_used="json-unless-none"),
]
[docs]
class TelescopeType(TerseStrEnum):
SKA_MID = "ska_mid"
SKA_LOW = "ska_low"
MEERKAT = "MeerKAT"
[docs]
class SubArrayLOW(TerseStrEnum):
AA05_ALL = "AA0.5"
AA1_ALL = "AA1"
AA2_ALL = "AA2"
AA2_CORE_ONLY = "AA2 (core only)"
AASTAR_ALL = "AA*"
AASTAR_CORE_ONLY = "AA* (core only)"
AA4_ALL = "AA4"
AA4_CORE_ONLY = "AA4 (core only)"
LOW_ITF = "Low ITF"
CUSTOM = "Custom"
[docs]
class SubArrayMID(TerseStrEnum):
AA05_ALL = "AA0.5"
AA1_ALL = "AA1"
AA2_ALL = "AA2"
AASTAR_ALL = "AA*"
AASTAR_SKA_ONLY = "AA* (15m antennas only)"
AA4_ALL = "AA4"
AA4_MEERKAT_ONLY = "AA*/AA4 (13.5m antennas only)"
AA4_SKA_ONLY = "AA4 (15m antennas only)"