Beispiel #1
0
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())
Beispiel #2
0
def test_add_to_empty():
    data = DataParser(scan_angle=np.arange(3), epoch=pd.DataFrame(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))
    new_data = DataParser()
    new_data += data
    assert np.allclose(new_data.scan_angle, data.scan_angle)
    assert len(new_data) == len(data)
Beispiel #3
0
 def test_read_on_many_filepaths(self, fake_glob, fake_load):
     test_data_directory = os.path.join(os.getcwd(), 'path/')
     fake_glob.return_value = ['/fake/path/1232.dat', '/fake/path/23211.dat', '/fake/path/232.dat']
     DataParser().read_intermediate_data_file('232', test_data_directory, None, None, None)
     fake_load.assert_called_with('/fake/path/232.dat', sep=None, skiprows=None, header=None, engine='python')
     # Test hip2 style names
     fake_glob.return_value = ['H075/HIP075290.d', 'H075/HIP075293.d', 'H107/HIP107529.d', 'H007/HIP007529.d', 'H117/HIP117529.d']
     DataParser().read_intermediate_data_file('7529', test_data_directory, None, None, None)
     fake_load.assert_called_with('H007/HIP007529.d', sep=None, skiprows=None, header=None, engine='python')
Beispiel #4
0
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
Beispiel #5
0
def test_concatenating_data():
    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))
    new_data = sum([data, data])
    assert np.allclose(new_data.scan_angle, [*data.scan_angle, *data.scan_angle])
    assert np.allclose(new_data.residuals, [*data.residuals, *data.residuals])
    assert len(new_data.inverse_covariance_matrix) == 2*len(data.inverse_covariance_matrix)
    data += data
    assert np.allclose(new_data.scan_angle, data.scan_angle)
    assert np.allclose(new_data.residuals, data.residuals)
    data.calculate_inverse_covariance_matrices()
Beispiel #6
0
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
Beispiel #7
0
 def parse_and_instantiate(cls, star_id: str,
                           intermediate_data_directory: str, **kwargs):
     filepath = DataParser.get_intermediate_data_file_path(
         star_id, intermediate_data_directory)
     CorrectDataParser = cls.get_appropriate_parser(filepath)
     return CorrectDataParser.parse_and_instantiate(
         star_id, intermediate_data_directory, **kwargs)
Beispiel #8
0
def test_concatenating_data_with_missing():
    data = DataParser(scan_angle=np.arange(3), epoch=pd.DataFrame(np.arange(1991, 1994)),
                      residuals=np.arange(2, 5))
    new_data = sum([data, data])
    assert np.allclose(new_data.scan_angle, [*data.scan_angle, *data.scan_angle])
    assert np.allclose(new_data.residuals, [*data.residuals, *data.residuals])
    data += data
    assert np.allclose(new_data.scan_angle, data.scan_angle)
    assert np.allclose(new_data.residuals, data.residuals)
Beispiel #9
0
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
Beispiel #10
0
def test_calculate_inverse_covariances(mock_cov_matrix):
    parser = DataParser()
    parser.calculate_inverse_covariance_matrices()
    assert np.allclose(parser.inverse_covariance_matrix[0], np.ones((2, 2)))
Beispiel #11
0
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)
Beispiel #12
0
 def test_len(self):
     assert len(DataParser()) == 0
     assert len(DataParser(epoch=pd.DataFrame(np.arange(4)))) == 4
Beispiel #13
0
 def test_read_on_irregular_paths(self, fake_glob, fake_load):
     test_data_directory = os.path.join(os.getcwd(), 'path/')
     fake_glob.return_value = ['/fake/path/SSADSx1232.dat', '/fake/path/WDASxs23211.dat', '/fake/path/OMGH232.dat']
     DataParser().read_intermediate_data_file('232', test_data_directory, None, None, None)
     fake_load.assert_called_with('/fake/path/OMGH232.dat', sep=None, skiprows=None, header=None, engine='python')
Beispiel #14
0
 def test_read_on_couple_similar_filepaths(self, fake_glob, fake_load):
     test_data_directory = os.path.join(os.getcwd(), 'path/')
     DataParser().read_intermediate_data_file('27321', test_data_directory, None, None, None)
     fake_load.assert_called_with('path/27321.dat', sep=None, skiprows=None, header=None, engine='python')
Beispiel #15
0
 def test_scale_along_scan_errors_raises_on_empty(self):
     parser = DataParser()
     with pytest.raises(ValueError):
         parser.scale_along_scan_errs(1)
Beispiel #16
0
 def test_file_exists(self):
     path = "htof/test/data_for_tests/Hip1/IntermediateData"
     file_doesnt_exist = not DataParser.file_exists(star_id="1800001", intermediate_data_directory=path)
     assert file_doesnt_exist
     assert DataParser.file_exists(star_id="004391", intermediate_data_directory=path)