|
| 1 | +from dataclasses import dataclass |
| 2 | +from typing import List, Literal |
| 3 | + |
| 4 | +import numpy as np |
| 5 | +from xarray_dataclasses import AsDataset, Attr, Coord, Coordof, Data |
| 6 | + |
| 7 | +# Define our dimensions here |
| 8 | +Direction = Literal["direction"] |
| 9 | +Antenna = Literal["antenna"] |
| 10 | +GainTime = Literal["gain_time"] |
| 11 | +GainFreq = Literal["gain_freq"] |
| 12 | +Correlation = Literal["correlation"] |
| 13 | +Jones = Literal["jones"] |
| 14 | +# Define properties for gain combinations |
| 15 | +Gain_T0 = Literal["gain_T0"] |
| 16 | +Gain_T1 = Literal["gain_T1"] |
| 17 | +Gain_nu0 = Literal["gain_nu0"] |
| 18 | +Gain_nu1 = Literal["gain_nu1"] |
| 19 | +# Add a comments functionality |
| 20 | +Comments = Literal["comments"] |
| 21 | + |
| 22 | +# Define time axes |
| 23 | + |
| 24 | + |
| 25 | +@dataclass |
| 26 | +class GainTimeAxis: |
| 27 | + """Define the gain_time coordinate. |
| 28 | + This structure matches the MSv4 time coordinate axis |
| 29 | + by included astropy time scale attributes""" |
| 30 | + |
| 31 | + data: Data[GainTime, np.float64] |
| 32 | + type: Attr[str] = "time" |
| 33 | + units: Attr[str] = "s" |
| 34 | + format: Attr[str] = "unix" |
| 35 | + scale: Attr[str] = "utc" |
| 36 | + |
| 37 | + |
| 38 | +@dataclass |
| 39 | +class GainT0Axis: |
| 40 | + """Define the gain_time coordinate. |
| 41 | + This structure matches the MSv4 time coordinate axis |
| 42 | + by included astropy time scale attributes""" |
| 43 | + |
| 44 | + data: Data[GainTime, np.float64] |
| 45 | + type: Attr[str] = "time" |
| 46 | + units: Attr[str] = "s" |
| 47 | + format: Attr[str] = "unix" |
| 48 | + scale: Attr[str] = "utc" |
| 49 | + |
| 50 | + |
| 51 | +@dataclass |
| 52 | +class GainT1Axis: |
| 53 | + """Define the gain_time coordinate. |
| 54 | + This structure matches the MSv4 time coordinate axis |
| 55 | + by included astropy time scale attributes""" |
| 56 | + |
| 57 | + data: Data[GainTime, np.float64] |
| 58 | + type: Attr[str] = "time" |
| 59 | + units: Attr[str] = "s" |
| 60 | + format: Attr[str] = "unix" |
| 61 | + scale: Attr[str] = "utc" |
| 62 | + |
| 63 | + |
| 64 | +# Define frequency axes |
| 65 | + |
| 66 | + |
| 67 | +@dataclass |
| 68 | +class GainFreqAxis: |
| 69 | + """Define the gain_freq coordinate. |
| 70 | + This structure matches the MSv4 frequency coordinate axis |
| 71 | + by included astropy frequency scale attributes""" |
| 72 | + |
| 73 | + data: Data[GainFreq, np.float64] |
| 74 | + type: Attr[str] = "spectral_coord" |
| 75 | + units: Attr[str] = "Hz" |
| 76 | + observer: Attr[str] = "gcrs" |
| 77 | + |
| 78 | + |
| 79 | +@dataclass |
| 80 | +class GainNu0Axis: |
| 81 | + """Define the gain_freq coordinate. |
| 82 | + This structure matches the MSv4 frequency coordinate axis |
| 83 | + by included astropy frequency scale attributes""" |
| 84 | + |
| 85 | + data: Data[GainFreq, np.float64] |
| 86 | + type: Attr[str] = "spectral_coord" |
| 87 | + units: Attr[str] = "Hz" |
| 88 | + observer: Attr[str] = "gcrs" |
| 89 | + |
| 90 | + |
| 91 | +@dataclass |
| 92 | +class GainNu1Axis: |
| 93 | + """Define the gain_freq coordinate. |
| 94 | + This structure matches the MSv4 frequency coordinate axis |
| 95 | + by included astropy frequency scale attributes""" |
| 96 | + |
| 97 | + data: Data[GainFreq, np.float64] |
| 98 | + type: Attr[str] = "spectral_coord" |
| 99 | + units: Attr[str] = "Hz" |
| 100 | + observer: Attr[str] = "gcrs" |
| 101 | + |
| 102 | + |
| 103 | +@dataclass |
| 104 | +class AntennaGains(AsDataset): |
| 105 | + # Data Variables |
| 106 | + gain_flags: Data[tuple[Direction, Antenna, GainTime, GainFreq], np.int8] |
| 107 | + gains: Data[tuple[Direction, Antenna, GainTime, GainFreq, Jones], np.complex64] |
| 108 | + # Coordinates |
| 109 | + antenna: Coord[Antenna, str] |
| 110 | + correlation: Coord[Correlation, str] |
| 111 | + direction: Coord[Direction, int] |
| 112 | + gain_time: Coordof[GainTimeAxis] |
| 113 | + gain_t0: Coordof[GainT0Axis] |
| 114 | + gain_t1: Coordof[GainT1Axis] |
| 115 | + gain_freq: Coordof[GainFreqAxis] |
| 116 | + gain_nu0: Coordof[GainNu0Axis] |
| 117 | + gain_nu1: Coordof[GainNu1Axis] |
| 118 | + # Attributes |
| 119 | + GAIN_AXES: Attr[List[str]] |
| 120 | + GAIN_SPEC: Attr[List[List[int]]] |
| 121 | + NAME: Attr[str] |
| 122 | + TYPE: Attr[str] |
| 123 | + # comments field, empty by default |
| 124 | + comment: Attr[str] = "" |
| 125 | + # Version of the schema |
| 126 | + VERSION: Attr[str] = "0.0.1" |
0 commit comments