def test_merged_parse_removes_flagged_observations(self): test_data_directory = os.path.join(os.getcwd(), 'htof/test/data_for_tests/Hip1') data = HipparcosOriginalData() data.parse(star_id='999999', intermediate_data_directory=test_data_directory, data_choice='MERGED') assert len(data) == 32
def test_raises_exception_on_bad_data_choice(self): test_data_directory = os.path.join(os.getcwd(), 'htof/test/data_for_tests/Hip1') data = HipparcosOriginalData() with pytest.raises(Exception): data.parse(star_id='027321', intermediate_data_directory=test_data_directory, data_choice='something')
def refit_hip1_object(iad_dir, hip_id, hip_dm_g=None, use_parallax=False): data = HipparcosOriginalData() data.parse(star_id=hip_id, intermediate_data_directory=iad_dir) fname = os.path.join(iad_dir, hip_id + '.txt') plx, cntr_RA, cntr_Dec, pmRA, pmDec, soltype = get_cat_values_hip1(fname) soltype = soltype.strip() accRA, accDec, jerkRA, jerkDec = 0, 0, 0, 0 fit_degree = {'5': 1}.get(soltype, None) if hip_dm_g is not None and (soltype == '7' or soltype == '9'): # do the fit for seven/nine parameter fits if we have the 7th and 9th parameters. idx = np.searchsorted(hip_dm_g['hip_id'].data, int(hip_id)) # int(hip_id) strips leading zeroes. accRA, accDec, jerkRA, jerkDec = hip_dm_g[idx][['accRA', 'accDec', 'jerkRA', 'jerkDec']] fit_degree = {'5': 1, '7': 2, '9': 3}.get(soltype, None) # only refit 5, 7, 9 parameter solutions. if fit_degree is not None: # abscissa residuals are always with respect to 5p solution for hip1. Do not feed accRA, etc.. # when reconstructing the skypath diffs, errors, chisq, chi2_partials = refit_hip_fromdata(data, fit_degree, cntr_RA=cntr_RA, cntr_Dec=cntr_Dec, use_parallax=use_parallax) if soltype == '7' or soltype == '9': # to account for the 0.81 yr and 1.69 yr^2 basis offsets present in 7 and 9 parameter solutions: diffs -= compute_basis_offsets(accRA, accDec, jerkRA, jerkDec) # diffs[-4:] are not differences but actually the accRA, accDec, jerkRA, jerkDec parameters, so we need to subtract those off diffs[-4:] -= np.array([accRA, accDec, jerkRA, jerkDec]) return tuple((diffs, errors, chisq, chi2_partials, soltype)) else: return [None] * 9, [None] * 9, None, [None] * 5, soltype
def test_fetch_from_web_on_invalid_id(self): data = HipparcosOriginalData() with pytest.raises(RuntimeError): data.parse(star_id='-1', intermediate_data_directory='htof/test/data_for_tests') with pytest.raises(RuntimeError): data.parse(star_id='200000', intermediate_data_directory='htof/test/data_for_tests')
def test_concatenation(self, hip_id='027321'): test_data_directory = os.path.join(os.getcwd(), 'htof/test/data_for_tests/Hip1') data = HipparcosOriginalData() data.parse(star_id=hip_id, intermediate_data_directory=test_data_directory, data_choice='FAST') data.calculate_inverse_covariance_matrices() covars = data.inverse_covariance_matrix data += data data.calculate_inverse_covariance_matrices() assert np.allclose(covars, data.inverse_covariance_matrix[:len(covars)]) assert np.allclose(covars, data.inverse_covariance_matrix[len(covars):])
def test_parse_IA3_eq_zero(self, hip_id='004391'): test_data_directory = os.path.join(os.getcwd(), 'htof/test/data_for_tests/Hip1') data = HipparcosOriginalData() data.parse(star_id=hip_id, intermediate_data_directory=test_data_directory, data_choice='NDAC') # IA4 is larger than IA3 -> more precise answer from IA7/IA4 (differs by .0103538462) assert np.isclose(data._epoch[38], 1992.9142, rtol=1e-8) # IA3 is larger than IA4 -> more precise answer from IA6/IA3 (differs by .0001434115) assert np.isclose(data._epoch[5], 1990.4227657727, rtol=1e-8) # IA3 is exactly 0 which would result in NaN. Must use IA7/IA4 to get a valid result. # IA4 is negative. This case thus also checks that the absolute value is correctly used when comparing IA3 and IA4. assert np.isclose(data._epoch[30], 1992.407684232, rtol=1e-8)
def test_parse(self, hip_id='027321'): test_data_directory = os.path.join(os.getcwd(), 'htof/test/data_for_tests/Hip1') data = HipparcosOriginalData() data.parse(star_id=hip_id, intermediate_data_directory=test_data_directory, data_choice='FAST') assert len(data) == 32 assert np.isclose(data._epoch[0], 1990.005772) assert np.isclose(np.sin(data.scan_angle[0]), -0.9053, rtol=.01) assert np.isclose(data._epoch[17], 1990.779865) assert np.isclose(np.sin(data.scan_angle[17]), 0.3633, rtol=.01) assert np.isclose(data.along_scan_errs.values[0], 2.21) data.parse(star_id=hip_id, intermediate_data_directory=test_data_directory, data_choice='NDAC') assert len(data) == 34 assert np.isclose(data._epoch[1], 1990.005386) assert np.isclose(np.sin(data.scan_angle[1]), -0.9051, rtol=.01) assert np.isclose(data._epoch[10], 1990.455515) assert np.isclose(np.sin(data.scan_angle[10]), 0.7362, rtol=.01) data.parse(star_id=hip_id, intermediate_data_directory=test_data_directory, data_choice='MERGED') assert len(data) == 34 assert np.isclose(data._epoch[0], 1990.005386) assert np.isclose(np.sin(data.scan_angle[0]), -0.9053, atol=.001) assert np.isclose(data._epoch[5], 1990.455515) assert np.isclose(np.sin(data.scan_angle[5]), 0.7364, atol=.001) assert np.isclose(data.along_scan_errs[5], 2.0814, atol=.0001) assert np.isclose(data.residuals[5], 1.1021, atol=.0001) data.parse(star_id=hip_id, intermediate_data_directory=test_data_directory, data_choice='BOTH') assert len(data) == 66
def test_fetch_from_web(self, fake_xml_download): comparison_data = HipparcosOriginalData() comparison_data.parse('004391', 'htof/test/data_for_tests/Hip1') # mock out the query to the internet with a pre-downloaded xml reponse. with open('htof/test/data_for_tests/MockServer/004391.html') as f: response = f.read() fake_xml_download.return_value = response # open up a temporary directory with no GOST files. with tempfile.TemporaryDirectory() as tmp_dir: data = HipparcosOriginalData() data.parse('004391', tmp_dir) assert np.allclose(data.julian_day_epoch(), comparison_data.julian_day_epoch(), atol=1/(24*60)) assert np.allclose(data.scan_angle, comparison_data.scan_angle, atol=0.01*np.pi/180) assert np.allclose(data.parallax_factors, comparison_data.parallax_factors, atol=0.0001)