|
4 | 4 | import pytest |
5 | 5 | from numpy.testing import assert_equal |
6 | 6 |
|
7 | | -from layup.predict import predict, predict_cli |
| 7 | +from layup.predict import predict, predict_cli, _convert_to_sg |
8 | 8 | from layup.utilities.data_utilities_for_tests import get_test_filepath |
9 | 9 | from layup.utilities.file_io.CSVReader import CSVDataReader |
10 | 10 |
|
@@ -39,6 +39,7 @@ def __init__(self, g=None): |
39 | 39 | self.n = 1 |
40 | 40 | self.chunk = chunk_size |
41 | 41 | self.station = "X05" |
| 42 | + self.sexagesimal = False |
42 | 43 |
|
43 | 44 | # The naming scheme for the test files indicates its orbit format |
44 | 45 | test_filename = f"predict_chunk_{input_format}.csv" |
@@ -151,3 +152,52 @@ def test_predict_output(tmpdir): |
151 | 152 | # assert np.allclose(output_data["obs_cov1"], known_data["obs_cov1"]) |
152 | 153 | # assert np.allclose(output_data["obs_cov2"], known_data["obs_cov2"]) |
153 | 154 | # assert np.allclose(output_data["obs_cov3"], known_data["obs_cov3"]) |
| 155 | + |
| 156 | + # Testing the output of the sexagesimal conversion separately |
| 157 | + |
| 158 | + result = subprocess.run( |
| 159 | + [ |
| 160 | + "layup", |
| 161 | + "predict", |
| 162 | + str(input_file), |
| 163 | + "-f", |
| 164 | + "-o", |
| 165 | + str(temp_out_file), |
| 166 | + "-s", |
| 167 | + start, |
| 168 | + "-sg", |
| 169 | + ] |
| 170 | + ) |
| 171 | + |
| 172 | + assert result.returncode == 0 |
| 173 | + |
| 174 | + result_file = Path(f"{tmpdir}/{temp_out_file}.csv") |
| 175 | + assert result_file.exists |
| 176 | + |
| 177 | + # Create a new CSV reader to read in our output file |
| 178 | + output_csv_reader = CSVDataReader(str(result_file), "csv", primary_id_column_name="provID") |
| 179 | + output_data = output_csv_reader.read_rows() |
| 180 | + |
| 181 | + # Read in the known output |
| 182 | + known_output_file = get_test_filepath("holman_expected_predict_sg.csv") |
| 183 | + known_output_csv_reader = CSVDataReader(known_output_file, "csv", primary_id_column_name="provID") |
| 184 | + known_data = known_output_csv_reader.read_rows() |
| 185 | + |
| 186 | + assert (output_data["ra_str_hms"] == known_data["ra_str_hms"]).all() == True |
| 187 | + assert (output_data["dec_str_dms"] == known_data["dec_str_dms"]).all() == True |
| 188 | + |
| 189 | + # Check the columns have been swapped too |
| 190 | + assert (known_data.dtype.names == output_data.dtype.names) == True |
| 191 | + |
| 192 | + |
| 193 | +def test_convert_to_sg(tmpdir): |
| 194 | + """Compare the output given by _convert_to_sg() with an expected output, seeing how it handles edge cases.""" |
| 195 | + |
| 196 | + data = CSVDataReader( |
| 197 | + get_test_filepath("known_sexagesimal.csv"), "csv", primary_id_column_name="provID" |
| 198 | + ).read_rows() |
| 199 | + |
| 200 | + data = _convert_to_sg(data) |
| 201 | + |
| 202 | + assert (data["ra_str_hms"] == data["ra_str_hms_CHECK"]).all() == True |
| 203 | + assert (data["dec_str_dms"] == data["dec_str_dms_CHECK"]).all() == True |
0 commit comments