def test_two_concatenate_decyear_and_jd(): data = DecimalYearData(scan_angle=np.arange(3), epoch=pd.DataFrame(np.arange(1991, 1994)), residuals=np.arange(2, 5)) data2 = DataParser(scan_angle=np.arange(3), epoch=pd.DataFrame(np.arange(2456951, 2456954)), residuals=np.arange(2, 5)) data3 = data + data2 assert np.allclose(data3.julian_day_epoch()[:len(data)], data.julian_day_epoch()) assert np.allclose(data3.julian_day_epoch()[len(data):], data2.julian_day_epoch())
def test_write_with_missing_info(): data = DataParser(scan_angle=np.arange(3), epoch=np.arange(1991, 1994), residuals=np.arange(2, 5), inverse_covariance_matrix=None, along_scan_errs=None) with tempfile.TemporaryDirectory() as tmp_dir: data.write(os.path.join(tmp_dir, 'out.csv')) t = Table.read(os.path.join(tmp_dir, 'out.csv')) assert np.allclose(t['residuals'], data.residuals) assert np.allclose(t['julian_day_epoch'], data.julian_day_epoch()) assert np.allclose(t['scan_angle'], data.scan_angle) assert len(t.colnames) == 5
def test_write(): data = DataParser(scan_angle=np.arange(3), epoch=np.arange(1991, 1994), residuals=np.arange(2, 5), inverse_covariance_matrix=np.array([[1, 2], [3, 4]]) * np.ones((3, 2, 2)), along_scan_errs=np.arange(3, 6)) with tempfile.TemporaryDirectory() as tmp_dir: data.write(os.path.join(tmp_dir, 'out.csv')) t = Table.read(os.path.join(tmp_dir, 'out.csv')) assert np.allclose(t['residuals'], data.residuals) assert np.allclose(t['julian_day_epoch'], data.julian_day_epoch()) assert np.allclose(t['scan_angle'], data.scan_angle) assert np.allclose(t['along_scan_errs'], data.along_scan_errs) icovs = [np.array(literal_eval(icov)) for icov in t['icov']] assert np.allclose(icovs, data.inverse_covariance_matrix) assert len(t.colnames) == 5
def refit_hip_fromdata(data: DataParser, fit_degree, cntr_RA=Angle(0, unit='degree'), cntr_Dec=Angle(0, unit='degree'), use_parallax=False): data.calculate_inverse_covariance_matrices() # generate parallax motion jyear_epoch = time.Time(data.julian_day_epoch(), format='jd', scale='tcb').jyear # note that ra_motion and dec_motion are in degrees here. # generate sky path year_epochs = jyear_epoch - time.Time(1991.25, format='decimalyear', scale='tcb').jyear ra_motion, dec_motion = parallactic_motion(jyear_epoch, cntr_RA.degree, cntr_Dec.degree, 'degree', time.Time(1991.25, format='decimalyear', scale='tcb').jyear, ephemeris=earth_ephemeris) # Hipparcos was in a geostationary orbit. ra_resid = Angle(data.residuals.values * np.sin(data.scan_angle.values), unit='mas') dec_resid = Angle(data.residuals.values * np.cos(data.scan_angle.values), unit='mas') # instantiate fitter fitter = AstrometricFitter(data.inverse_covariance_matrix, year_epochs, use_parallax=use_parallax, fit_degree=fit_degree, parallactic_pertubations={'ra_plx': Angle(ra_motion, 'degree').mas, 'dec_plx': Angle(dec_motion, 'degree').mas}) fit_coeffs, errors, chisq, refit_residuals = fitter.fit_line(ra_resid.mas, dec_resid.mas, return_all=True) parallax_factors = ra_motion * np.sin(data.scan_angle.values) + dec_motion * np.cos(data.scan_angle.values) # technically this could be data.parallax_factors.values, but then we have to deal with # getting the RA and Dec components of that. if not use_parallax: fit_coeffs = np.hstack([[0], fit_coeffs]) errors = np.hstack([[0], errors]) parallax_factors = np.zeros_like(parallax_factors) # pad so coeffs and errors are 9 long. errors = np.pad(errors, (0, 9 - len(fit_coeffs))) fit_coeffs = np.pad(fit_coeffs, (0, 9 - len(fit_coeffs))) # calculate the chisquared partials sin_scan = np.sin(data.scan_angle.values) cos_scan = np.cos(data.scan_angle.values) dt = data.epoch - 1991.25 chi2_vector = (2 * data.residuals.values / data.along_scan_errs.values ** 2 * np.array( [parallax_factors, sin_scan, cos_scan, dt * sin_scan, dt * cos_scan])).T chi2_partials = np.sum(chi2_vector, axis=0) ** 2 return fit_coeffs, errors, chisq, chi2_partials
def test_call_jd_dates_gaia(): parser = DataParser() parser._epoch = pd.DataFrame(data=[2447892.5, 2447893], index=[5, 6]) jd_epochs = parser.julian_day_epoch() assert np.isclose(jd_epochs[0], 2447892.5) assert np.isclose(jd_epochs[1], 2447893)