Skip to content

Commit 211c2c1

Browse files
Added killMS schema specification (#9)
Co-authored-by: Etienne Bonnassieux <etienne.bonnassieux@u-bordeaux.fr> Co-authored-by: Simon Perkins <simon.perkins@gmail.com>
1 parent 49fce14 commit 211c2c1

3 files changed

Lines changed: 222 additions & 0 deletions

File tree

docs/source/changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Changelog
66

77
X.Y.Z (DD-MM-YYYY)
88
------------------
9+
* Add killMS type gains description (:pr:`9`)
910
* Add github actions (:pr:`8`)
1011
* Add github issue and pr templates (:pr:`8`)
1112
* Add pre-commit hooks (:pr:`8`)

saopicc_schemas/antenna_gains.py

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
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"

tests/test_kms_gain.py

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import numpy as np
2+
import xarray
3+
4+
from saopicc_schemas.antenna_gains import AntennaGains
5+
6+
7+
def test_gains_creation():
8+
# times are defined approximately based on nenufar dataset
9+
# 8s dt, 8h observation
10+
time = np.linspace(1.64e9, 1.64e9 + 3600 * 8, 3600)
11+
# assume a dt of 32s for the solve
12+
t0 = time - 16.0
13+
t1 = time + 16.0
14+
# observation from 856 MHz to 1.712 GHz, why not
15+
freqs = np.linspace(0.856e9, 2 * 0.856e9, 64)
16+
# assume 48 MHz bandwidth for the solve
17+
nu0 = freqs - 24 * 1e6
18+
nu1 = freqs + 24 * 1e6
19+
antenna = np.arange(28).astype(str)
20+
direction = np.arange(16)
21+
# nenufar, ska-low etc have linear dipoles
22+
corrs = np.array(["XX", "XY", "YX", "YY"])
23+
ncorrs = len(corrs)
24+
ntime = len(time)
25+
nfreq = len(freqs)
26+
nant = len(antenna)
27+
ndir = len(direction)
28+
gain_flags = np.random.choice([0, 1], (ndir, nant, ntime, nfreq))
29+
gains = np.ones((ndir, nant, ntime, nfreq, ncorrs))
30+
31+
gains = AntennaGains.new(
32+
gains=gains,
33+
gain_flags=gain_flags,
34+
antenna=antenna,
35+
correlation=corrs,
36+
direction=direction,
37+
gain_time=xarray.DataArray(
38+
time,
39+
attrs={
40+
"type": "time",
41+
"units": "s",
42+
"format": "unix",
43+
"scale": "utc",
44+
},
45+
),
46+
gain_t0=xarray.DataArray(
47+
t0,
48+
attrs={
49+
"type": "time",
50+
"units": "s",
51+
"format": "unix",
52+
"scale": "utc",
53+
},
54+
),
55+
gain_t1=xarray.DataArray(
56+
t1,
57+
attrs={
58+
"type": "time",
59+
"units": "s",
60+
"format": "unix",
61+
"scale": "utc",
62+
},
63+
),
64+
gain_freq=xarray.DataArray(
65+
freqs,
66+
attrs={
67+
"type": "spectral_coord",
68+
"units": "Hz",
69+
"observer": "gcrs",
70+
},
71+
),
72+
gain_nu0=xarray.DataArray(
73+
nu0,
74+
attrs={
75+
"type": "spectral_coord",
76+
"units": "Hz",
77+
"observer": "gcrs",
78+
},
79+
),
80+
gain_nu1=xarray.DataArray(
81+
nu1,
82+
attrs={
83+
"type": "spectral_coord",
84+
"units": "Hz",
85+
"observer": "gcrs",
86+
},
87+
),
88+
GAIN_AXES=["direction", "antenna", "gain_time", "gain_freq", "correlation"],
89+
GAIN_SPEC=[[16], [28], [3600], [64], [4]],
90+
NAME="G",
91+
VERSION="0.0.1",
92+
TYPE="complex",
93+
comment="NenuFAR prototype gain",
94+
)
95+
print(gains)

0 commit comments

Comments
 (0)