1+ import os
12import shutil
23
34from toolviper .utils import data
45
6+ from astrohack import AstrohackLocitFile , extract_locit , open_locit
7+ from astrohack .utils .validation import (
8+ capture_prints_from_function ,
9+ are_png_files_equal ,
10+ are_lists_equal ,
11+ )
12+
513
614class TestLocitMDS :
715 data_folder = "locit_data"
816 destination_folder = "locit_exports"
917 ref_products_folder = f"{ data_folder } /ref_locit_products"
1018
11- silly_name = "Anything "
12- remote_locit_name = "kband_locit_small .locit.zarr"
19+ phase_cal_table_name = "locit-input-pha.cal "
20+ locit_name = "ant-pos .locit.zarr"
1321
1422 @classmethod
1523 def setup_class (cls ):
1624 """setup any state specific to the execution of the given test class
1725 such as fetching test data"""
18- data .download (file = cls .remote_locit_name , folder = cls .data_folder )
26+ data .download (file = cls .phase_cal_table_name , folder = cls .data_folder )
1927 data .download (file = "ref_locit_products" , folder = cls .data_folder )
2028
2129 # Add datafolder to names for execution
@@ -24,10 +32,105 @@ def setup_class(cls):
2432 if varname .split ("_" )[- 1 ] == "name" :
2533 setattr (cls , varname , f"{ cls .data_folder } /{ varvalue } " )
2634
35+ extract_locit (cls .phase_cal_table_name , cls .locit_name , overwrite = True )
36+
2737 @classmethod
2838 def teardown_class (cls ):
2939 """teardown any state that was previously setup with a call to setup_class
3040 such as deleting test data"""
3141 shutil .rmtree (cls .data_folder , ignore_errors = True )
3242 shutil .rmtree (cls .destination_folder , ignore_errors = True )
3343 return
44+
45+ def test_locit_mds_init (self ):
46+ locit_mds = AstrohackLocitFile (self .locit_name )
47+ assert isinstance (locit_mds , AstrohackLocitFile )
48+
49+ def test_locit_mds_summary (self ):
50+ locit_mds = open_locit (self .locit_name )
51+ summary_reference_name = f"{ self .ref_products_folder } /summary_reference.txt"
52+
53+ captured_output = capture_prints_from_function (locit_mds .summary )
54+
55+ with open (summary_reference_name , "r" ) as ref_file :
56+ ref_content = ref_file .read ()
57+
58+ assert (
59+ captured_output == ref_content
60+ ), "Summary should be exactly equal to reference summary"
61+
62+ def test_locit_mds_text_exports (self ):
63+ locit_mds = open_locit (self .locit_name )
64+ src_tab_reference_name = f"{ self .ref_products_folder } /src_tab_reference.txt"
65+ array_cfg_reference_name = f"{ self .ref_products_folder } /array_cfg_reference.txt"
66+
67+ current_src_tab = capture_prints_from_function (locit_mds .print_source_table )
68+ with open (src_tab_reference_name , "r" ) as ref_src_tab_file :
69+ ref_src_tab_content = ref_src_tab_file .read ()
70+ assert (
71+ current_src_tab == ref_src_tab_content
72+ ), "Source table should be exactly equal to reference source table"
73+
74+ current_array_cfg = capture_prints_from_function (locit_mds .print_source_table )
75+ with open (array_cfg_reference_name , "r" ) as ref_array_cfg_file :
76+ ref_array_cfg_content = ref_array_cfg_file .read ()
77+ assert (
78+ current_array_cfg == ref_array_cfg_content
79+ ), "Array configuration should be exactly equal to reference array confguration"
80+
81+ def test_locit_mds_plot_exports (self ):
82+ locit_mds = open_locit (self .locit_name )
83+
84+ src_fk5_plot_name = "locit_source_table_fk5.png"
85+ locit_mds .plot_source_positions (self .destination_folder , precessed = False )
86+ assert are_png_files_equal (
87+ f"{ self .destination_folder } /{ src_fk5_plot_name } " ,
88+ f"{ self .ref_products_folder } /{ src_fk5_plot_name } " ,
89+ ), "FK5 source position plot should be exactly equal to reference FK5 source position plot"
90+
91+ src_prece_plot_name = "locit_source_table_precessed.png"
92+ locit_mds .plot_source_positions (self .destination_folder , precessed = True )
93+ assert are_png_files_equal (
94+ f"{ self .destination_folder } /{ src_prece_plot_name } " ,
95+ f"{ self .ref_products_folder } /{ src_prece_plot_name } " ,
96+ ), "Precessed source position plot should be exactly equal to reference precessed source position plot"
97+
98+ array_cfg_plot_name = "locit_antenna_positions.png"
99+ locit_mds .plot_array_configuration (self .destination_folder )
100+ assert are_png_files_equal (
101+ f"{ self .destination_folder } /{ array_cfg_plot_name } " ,
102+ f"{ self .ref_products_folder } /{ array_cfg_plot_name } " ,
103+ ), "Array configuration plot should be exactly equal to reference array configuration plot"
104+
105+ def test_locit_mds_metadata_style (self ):
106+ locit_mds = open_locit (self .locit_name )
107+
108+ assert "source_dict" in list (
109+ locit_mds .root .attrs .keys ()
110+ ), "Root attributes should contain 'source_dict'"
111+
112+ expected_src_keys = ["fk5" , "id" , "name" , "precessed" ]
113+ src_table = locit_mds .root .attrs ["source_dict" ]
114+ for key , value in src_table .items ():
115+ assert key .isdigit (), "Source key should be a digit referencing field Ids"
116+ assert are_lists_equal (
117+ list (value .keys ()), expected_src_keys
118+ ), "Source position keys should be the same as expected keys"
119+
120+ expected_ant_keys = [
121+ "geocentric_position" ,
122+ "id" ,
123+ "latitude" ,
124+ "longitude" ,
125+ "name" ,
126+ "offset" ,
127+ "radius" ,
128+ "reference" ,
129+ "station" ,
130+ ]
131+ for ant_xdtree in locit_mds .values ():
132+ assert "antenna_info" in list (
133+ ant_xdtree .attrs .keys ()
134+ ), "Each antenna xarray DataTree needs to contain antenna info"
135+ antenna_info = ant_xdtree .attrs ["antenna_info" ]
136+ assert are_lists_equal (list (antenna_info .keys ()), expected_ant_keys )
0 commit comments