Skip to content

Commit 6a32f7d

Browse files
committed
add tests for lobes, list, multi-component shapelets
1 parent 0c9a8e3 commit 6a32f7d

File tree

4 files changed

+152
-47
lines changed

4 files changed

+152
-47
lines changed

src/srclist/general_tests.rs

Lines changed: 73 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ use super::{fits::parse_source_list, *};
1919
use crate::constants::DEFAULT_SPEC_INDEX;
2020

2121
fn test_two_sources_lists_are_the_same(sl1: &SourceList, sl2: &SourceList) {
22-
assert_eq!(sl1.len(), sl2.len());
22+
assert_eq!(
23+
sl1.len(),
24+
sl2.len(),
25+
"length mismatch \n {:?}\n != {:?}",
26+
sl1.iter().collect_vec(),
27+
sl2.iter().collect_vec()
28+
);
2329
for ((sl1_name, s1), (sl2_name, s2)) in sl1.iter().zip(sl2.iter()) {
2430
assert_eq!(sl1_name, sl2_name);
2531
assert_eq!(s1.components.len(), s2.components.len());
@@ -891,9 +897,11 @@ fn get_fits_expected_srclist(
891897
pa: 75.0_f64.to_radians(),
892898
};
893899
#[rustfmt::skip]
894-
let flux_type_list = FluxDensityType::List(vec1![FluxDensity {
895-
freq: ref_freq, i: 1.0, q: 0.0, u: 0.0, v: 0.0,
896-
},]);
900+
let flux_type_list = FluxDensityType::List(vec1![
901+
FluxDensity { freq: 100e6, i: 3.0, q: 0.0, u: 0.0, v: 0.0,},
902+
FluxDensity { freq: 150e6, i: 2.0, q: 0.0, u: 0.0, v: 0.0,},
903+
FluxDensity { freq: 200e6, i: 1.0, q: 0.0, u: 0.0, v: 0.0,},
904+
]);
897905
#[rustfmt::skip]
898906
let flux_type_pl = FluxDensityType::PowerLaw {
899907
si: -0.8,
@@ -989,21 +997,36 @@ fn get_fits_expected_srclist(
989997
expected_srclist.insert(
990998
"shape-pl".into(),
991999
Source {
992-
components: vec![SourceComponent {
993-
radec: RADec::from_degrees(1.0, 2.0),
994-
comp_type: ComponentType::Shapelet {
995-
maj: 20.0_f64.to_radians(),
996-
min: 10.0_f64.to_radians(),
997-
pa: 75.0_f64.to_radians(),
998-
coeffs: vec![
999-
ShapeletCoeff { n1: 0, n2: 0, value: 0.9, },
1000-
ShapeletCoeff { n1: 0, n2: 1, value: 0.2, },
1001-
ShapeletCoeff { n1: 1, n2: 0, value: -0.2, },
1002-
]
1003-
.into(),
1000+
components: vec![
1001+
SourceComponent {
1002+
radec: RADec::from_degrees(1.0, 2.0),
1003+
comp_type: ComponentType::Shapelet {
1004+
maj: 20.0_f64.to_radians(),
1005+
min: 10.0_f64.to_radians(),
1006+
pa: 75.0_f64.to_radians(),
1007+
coeffs: vec![
1008+
ShapeletCoeff { n1: 0, n2: 0, value: 0.9, },
1009+
ShapeletCoeff { n1: 0, n2: 1, value: 0.2, },
1010+
ShapeletCoeff { n1: 1, n2: 0, value: -0.2, },
1011+
]
1012+
.into(),
1013+
},
1014+
flux_type: flux_type_pl.clone(),
10041015
},
1005-
flux_type: flux_type_pl,
1006-
}]
1016+
SourceComponent {
1017+
radec: RADec::from_degrees(1.0, 2.0),
1018+
comp_type: ComponentType::Shapelet {
1019+
maj: 20.0_f64.to_radians(),
1020+
min: 10.0_f64.to_radians(),
1021+
pa: 75.0_f64.to_radians(),
1022+
coeffs: vec![
1023+
ShapeletCoeff { n1: 0, n2: 0, value: 0.8, },
1024+
]
1025+
.into(),
1026+
},
1027+
flux_type: flux_type_pl.clone(),
1028+
},
1029+
]
10071030
.into(),
10081031
},
10091032
);
@@ -1031,23 +1054,48 @@ fn test_parse_gleam_fits() {
10311054
#[test]
10321055
fn test_parse_jack_fits() {
10331056
// python -c 'from astropy.io import fits; import sys; from tabulate import tabulate; [print(tabulate(hdu.data, headers=[c.name for c in hdu.columns], tablefmt="plain")) for hdu in fits.open(sys.argv[-1])[1:]]' test_files/jack.fits
1034-
// UNQ_SOURCE_ID NAME RA DEC INT_FLX150 MAJOR_DC MINOR_DC PA_DC MOD_TYPE COMP_TYPE NORM_COMP_PL ALPHA_PL NORM_COMP_CPL ALPHA_CPL CURVE_CPL
1035-
// point-pl point-pl_C0 1 2 2 0 0 0 pl P 2 -0.8 0 0 0
1036-
// point-cpl point-cpl_C0 3 4 3 0 0 0 cpl P 0 0 3 -0.9 0.2
1037-
// gauss-pl gauss-pl_C0 1 2 2 20 10 75 pl G 2 -0.8 0 0 0
1038-
// gauss-cpl gauss-cpl_C0 3 4 3 20 10 75 cpl G 0 0 3 -0.9 0.2
1039-
// shape-pl shape-pl_C0 1 2 2 20 10 75 pl S 2 -0.8 0 0 0
1057+
// UNQ_SOURCE_ID NAME RA DEC INT_FLX100 INT_FLX150 INT_FLX200 MAJOR_DC MINOR_DC PA_DC MOD_TYPE COMP_TYPE NORM_COMP_PL ALPHA_PL NORM_COMP_CPL ALPHA_CPL CURVE_CPL
1058+
// point-list point-list_C0 0 1 3 2 1 0 0 0 nan P 1 0 0 0 0
1059+
// point-pl point-pl_C0 1 2 3.5 2.5 2 0 0 0 pl P 2 -0.8 0 0 0
1060+
// point-cpl point-cpl_C0 3 4 5.6 3.8 3 0 0 0 cpl P 0 0 3 -0.9 0.2
1061+
// gauss-list gauss-list_C0 0 1 3 2 1 20 10 75 nan G 1 0 0 0 0
1062+
// gauss-pl gauss-pl_C0 1 2 3.5 2.5 2 20 10 75 pl G 2 -0.8 0 0 0
1063+
// gauss-cpl gauss-cpl_C0 3 4 5.6 3.8 3 20 10 75 cpl G 0 0 3 -0.9 0.2
1064+
// shape-pl shape-pl_C0 1 2 3.5 2.5 2 20 10 75 pl S 2 -0.8 0 0 0
1065+
// shape-pl shape-pl_C1 1 2 3.5 2.5 2 20 10 75 pl S 2 -0.8 0 0 0
10401066
// NAME N1 N2 COEFF
10411067
// shape-pl_C0 0 0 0.9
10421068
// shape-pl_C0 0 1 0.2
10431069
// shape-pl_C0 1 0 -0.2
1070+
// shape-pl_C1 0 0 0.8
10441071

10451072
// setup logging
10461073
// use crate::cli::setup_logging;
10471074
// setup_logging(3).expect("Failed to setup logging");
10481075

10491076
let res_srclist = parse_source_list(&PathBuf::from("test_files/jack.fits")).unwrap();
1050-
let expected_srclist = get_fits_expected_srclist(200e6, false, true, true);
1077+
let expected_srclist = get_fits_expected_srclist(200e6, true, true, true);
1078+
// dbg!(&res_srclist, &expected_srclist);
1079+
test_two_sources_lists_are_the_same(&res_srclist, &expected_srclist);
1080+
}
1081+
1082+
#[test]
1083+
fn test_parse_lobes_fits() {
1084+
// python -c 'from astropy.io import fits; import sys; from tabulate import tabulate; [print(tabulate(hdu.data, headers=[c.name for c in hdu.columns], tablefmt="plain")) for hdu in fits.open(sys.argv[-1])[1:]]' test_files/lobes.fits
1085+
// UNQ_SOURCE_ID NAME RA DEC INT_FLX100 INT_FLX150 INT_FLX200 MAJOR_DC MINOR_DC PA_DC MOD_TYPE COMP_TYPE NORM_COMP_PL ALPHA_PL NORM_COMP_CPL ALPHA_CPL CURVE_CPL
1086+
// point-list point-list_GID0 0 1 3 2 1 0 0 0 nan P 1 0 0 0 0
1087+
// point-pl point-pl_GID0 1 2 3.5 2.5 2 0 0 0 pl P 2 -0.8 0 0 0
1088+
// point-cpl point-cpl_GID0 3 4 5.6 3.8 3 0 0 0 cpl P 0 0 3 -0.9 0.2
1089+
// gauss-list gauss-list_GID0 0 1 3 2 1 20 10 75 nan G 1 0 0 0 0
1090+
// gauss-pl gauss-pl_GID0 1 2 3.5 2.5 2 20 10 75 pl G 2 -0.8 0 0 0
1091+
// gauss-cpl gauss-cpl_GID0 3 4 5.6 3.8 3 20 10 75 cpl G 0 0 3 -0.9 0.2
1092+
1093+
// setup logging
1094+
// use crate::cli::setup_logging;
1095+
// setup_logging(3).expect("Failed to setup logging");
1096+
1097+
let res_srclist = parse_source_list(&PathBuf::from("test_files/lobes.fits")).unwrap();
1098+
let expected_srclist = get_fits_expected_srclist(200e6, true, true, false);
10511099
// dbg!(&res_srclist, &expected_srclist);
10521100
test_two_sources_lists_are_the_same(&res_srclist, &expected_srclist);
10531101
}

test_files/gen_fits_srclists.py

Lines changed: 77 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
"NAME": [],
1515
"RA": [],
1616
"DEC": [],
17+
"INT_FLX100": [],
1718
"INT_FLX150": [],
19+
"INT_FLX200": [],
1820
"MAJOR_DC": [],
1921
"MINOR_DC": [],
2022
"PA_DC": [],
@@ -32,6 +34,25 @@
3234
"N2": [],
3335
"COEFF": [],
3436
}
37+
arrays_lobes = {
38+
"UNQ_SOURCE_ID": [],
39+
"NAME": [],
40+
"RA": [],
41+
"DEC": [],
42+
"INT_FLX100": [],
43+
"INT_FLX150": [],
44+
"INT_FLX200": [],
45+
"MAJOR_DC": [],
46+
"MINOR_DC": [],
47+
"PA_DC": [],
48+
"MOD_TYPE": [],
49+
"COMP_TYPE": [],
50+
"NORM_COMP_PL": [],
51+
"ALPHA_PL": [],
52+
"NORM_COMP_CPL": [],
53+
"ALPHA_CPL": [],
54+
"CURVE_CPL": [],
55+
}
3556
arrays_gleam = {
3657
"Name": [],
3758
"RAJ2000": [],
@@ -43,25 +64,25 @@
4364
"b": [],
4465
"pa": [],
4566
}
46-
for (i,(name, cmp, ra, de, fd, maj, min, pa, mtyp, ctyp, alpha, q, )) in enumerate([
47-
["point-list", 0, 0., 1., 1., 0., 0., 0., "nan", "P", 0.0, 0.0 ],
48-
["point-pl", 0, 1., 2., 2., 0., 0., 0., "pl", "P", -0.8, 0.0 ],
49-
["point-cpl", 0, 3., 4., 3., 0., 0., 0., "cpl", "P", -0.9, 0.2 ],
50-
["gauss-list", 0, 0., 1., 1., 20., 10., 75., "nan", "G", 0.0, 0.0 ],
51-
["gauss-pl", 0, 1., 2., 2., 20., 10., 75., "pl", "G", -0.8, 0.0 ],
52-
["gauss-cpl", 0, 3., 4., 3., 20., 10., 75., "cpl", "G", -0.9, 0.2 ],
53-
["shape-pl", 0, 1., 2., 2., 20., 10., 75., "pl", "S", -0.8, 0.0 ],
54-
# todo: shapelets
67+
for (i,(name, cmp, ra, de, fd100, fd150, fd200, maj, min, pa, mtyp, ctyp, alpha, q, )) in enumerate([
68+
["point-list", 0, 0., 1., 3.0, 2.0, 1., 0., 0., 0., "nan", "P", 0.0, 0.0 ],
69+
["point-pl", 0, 1., 2., 3.5, 2.5, 2., 0., 0., 0., "pl", "P", -0.8, 0.0 ],
70+
["point-cpl", 0, 3., 4., 5.6, 3.8, 3., 0., 0., 0., "cpl", "P", -0.9, 0.2 ],
71+
["gauss-list", 0, 0., 1., 3., 2., 1., 20., 10., 75., "nan", "G", 0.0, 0.0 ],
72+
["gauss-pl", 0, 1., 2., 3.5, 2.5, 2., 20., 10., 75., "pl", "G", -0.8, 0.0 ],
73+
["gauss-cpl", 0, 3., 4., 5.6, 3.8, 3., 20., 10., 75., "cpl", "G", -0.9, 0.2 ],
74+
["shape-pl", 0, 1., 2., 3.5, 2.5, 2., 20., 10., 75., "pl", "S", -0.8, 0.0 ],
75+
["shape-pl", 1, 1., 2., 3.5, 2.5, 2., 20., 10., 75., "pl", "S", -0.8, 0.0 ],
5576
]):
56-
if mtyp == "nan":
57-
continue
5877

5978
# i_ = f"{i:04d}"
6079
arrays_jack["UNQ_SOURCE_ID"].append(f"{name}")
6180
arrays_jack["NAME"].append(f"{name}_C{cmp}")
6281
arrays_jack["RA"].append(ra)
6382
arrays_jack["DEC"].append(de)
64-
arrays_jack["INT_FLX150"].append(fd)
83+
arrays_jack["INT_FLX100"].append(fd100)
84+
arrays_jack["INT_FLX150"].append(fd150)
85+
arrays_jack["INT_FLX200"].append(fd200)
6586
arrays_jack["MAJOR_DC"].append(maj)
6687
arrays_jack["MINOR_DC"].append(min)
6788
arrays_jack["PA_DC"].append(pa)
@@ -71,37 +92,67 @@
7192
if mtyp == "cpl":
7293
arrays_jack["NORM_COMP_PL"].append(0.0)
7394
arrays_jack["ALPHA_PL"].append(0.0)
74-
arrays_jack["NORM_COMP_CPL"].append(fd)
95+
arrays_jack["NORM_COMP_CPL"].append(fd200)
7596
arrays_jack["ALPHA_CPL"].append(alpha)
7697
arrays_jack["CURVE_CPL"].append(q)
7798
else:
78-
arrays_jack["NORM_COMP_PL"].append(fd)
99+
arrays_jack["NORM_COMP_PL"].append(fd200)
79100
arrays_jack["ALPHA_PL"].append(alpha)
80101
arrays_jack["NORM_COMP_CPL"].append(0.0)
81102
arrays_jack["ALPHA_CPL"].append(0.0)
82103
arrays_jack["CURVE_CPL"].append(0.0)
83104

105+
if ctyp == "S": # no shapelet support in gleam or lobes
106+
continue
107+
108+
arrays_lobes["UNQ_SOURCE_ID"].append(f"{name}")
109+
arrays_lobes["NAME"].append(f"{name}_GID{cmp}")
110+
arrays_lobes["RA"].append(ra)
111+
arrays_lobes["DEC"].append(de)
112+
arrays_lobes["INT_FLX100"].append(fd100)
113+
arrays_lobes["INT_FLX150"].append(fd150)
114+
arrays_lobes["INT_FLX200"].append(fd200)
115+
arrays_lobes["MAJOR_DC"].append(maj)
116+
arrays_lobes["MINOR_DC"].append(min)
117+
arrays_lobes["PA_DC"].append(pa)
118+
arrays_lobes["MOD_TYPE"].append(mtyp)
119+
arrays_lobes["COMP_TYPE"].append(ctyp)
120+
121+
if mtyp == "cpl":
122+
arrays_lobes["NORM_COMP_PL"].append(0.0)
123+
arrays_lobes["ALPHA_PL"].append(0.0)
124+
arrays_lobes["NORM_COMP_CPL"].append(fd200)
125+
arrays_lobes["ALPHA_CPL"].append(alpha)
126+
arrays_lobes["CURVE_CPL"].append(q)
127+
else:
128+
arrays_lobes["NORM_COMP_PL"].append(fd200)
129+
arrays_lobes["ALPHA_PL"].append(alpha)
130+
arrays_lobes["NORM_COMP_CPL"].append(0.0)
131+
arrays_lobes["ALPHA_CPL"].append(0.0)
132+
arrays_lobes["CURVE_CPL"].append(0.0)
133+
84134
if mtyp == "cpl": # no cpl support in gleam
85135
continue
86-
if ctyp == "S": # no shapelet support in gleam
136+
if mtyp == "nan": # no list support in gleam
87137
continue
88138

89139
arrays_gleam['Name'].append(f"{name}")
90140
arrays_gleam['RAJ2000'].append(ra)
91141
arrays_gleam['DEJ2000'].append(de)
92-
arrays_gleam['S_200'].append(fd)
142+
arrays_gleam['S_200'].append(fd200)
93143
arrays_gleam['alpha'].append(alpha)
94144
arrays_gleam['beta'].append(q)
95145
arrays_gleam['a'].append(maj * 3600)
96146
arrays_gleam['b'].append(min * 3600)
97147
arrays_gleam['pa'].append(pa)
98148

99-
for (i, (name, n1, n2, coeff)) in enumerate([
100-
["shape-pl", 0, 0, 0.9],
101-
["shape-pl", 0, 1, 0.2],
102-
["shape-pl", 1, 0, -0.2],
149+
for (i, (name, cmp, n1, n2, coeff)) in enumerate([
150+
["shape-pl", 0, 0, 0, 0.9],
151+
["shape-pl", 0, 0, 1, 0.2],
152+
["shape-pl", 0, 1, 0, -0.2],
153+
["shape-pl", 1, 0, 0, 0.8],
103154
]):
104-
arrays_jack_2["NAME"].append(f"{name}_C0")
155+
arrays_jack_2["NAME"].append(f"{name}_C{cmp}")
105156
arrays_jack_2["N1"].append(n1)
106157
arrays_jack_2["N2"].append(n2)
107158
arrays_jack_2["COEFF"].append(coeff)
@@ -117,6 +168,11 @@
117168
df = table2.to_pandas()
118169
print("\njack2\n", df[[df.columns[0], *df.columns[1:]]].to_string(index=False))
119170

171+
table = Table(arrays_lobes)
172+
table.write('test_files/lobes.fits', overwrite=True)
173+
df = table.to_pandas()
174+
print("\nlobes\n", df.to_string(index=False))
175+
120176
table = Table(arrays_gleam, )
121177
table.write('test_files/gleam.fits', overwrite=True)
122178
df = table.to_pandas()

0 commit comments

Comments
 (0)