Beispiel #1
0
def test_Hip1_fit_to_hip70000():
    # Hip 70000 parameters from the intermediate data
    cntr_ra, cntr_dec = Angle(214.85975459, 'degree'), Angle(14.93570946, 'degree')
    plx = 1.26  # mas
    pmRA = 1.01  # mas/year
    pmDec = 7.27  # mas/year
    # generate fitter and parse intermediate data
    astro = Astrometry('Hip1', '70000', 'htof/test/data_for_tests/Hip1', central_epoch_ra=1991.25,
                       central_epoch_dec=1991.25, format='jyear', fit_degree=1, use_parallax=True,
                       central_ra=cntr_ra, central_dec=cntr_dec)
    chisq = np.sum(astro.data.residuals ** 2 / astro.data.along_scan_errs ** 2)
    # generate ra and dec for each observation.
    year_epochs = Time(astro.data.julian_day_epoch(), format='jd', scale='tcb').jyear - \
                  Time(1991.25, format='decimalyear').jyear
    ra_motion = astro.fitter.parallactic_pertubations['ra_plx']
    dec_motion = astro.fitter.parallactic_pertubations['dec_plx']
    ra = Angle(ra_motion * plx + pmRA * year_epochs, unit='mas')
    dec = Angle(dec_motion * plx + pmDec * year_epochs, unit='mas')
    # add residuals
    ra += Angle(astro.data.residuals.values * np.sin(astro.data.scan_angle.values), unit='mas')
    dec += Angle(astro.data.residuals.values * np.cos(astro.data.scan_angle.values), unit='mas')
    #
    coeffs, errors, chisq_found, residuals_found = astro.fit(ra.mas, dec.mas, return_all=True)
    assert np.isclose(chisq, chisq_found, atol=1E-3)
    assert np.allclose([pmRA, pmDec], np.array([coeffs[3], coeffs[4]]).round(2))
    assert np.isclose(plx, coeffs[0].round(2), atol=0.01)
    assert np.allclose(errors.round(2), np.array([1.11, 0.79, 0.62, 0.82, 0.64]))
Beispiel #2
0
def test_Hip2_fit_to_hip27321():
    # Hip 27321 parameters from the Hipparcos 21 IAD
    cntr_ra, cntr_dec = Angle(86.82118073, 'degree'), Angle(-51.06671341, 'degree')
    plx = 51.44  # mas
    pmRA = 4.65  # mas/year
    pmDec = 83.10  # mas/year
    # generate fitter and parse intermediate data
    for datadir in ['Hip2', 'Hip21']:
        # trying fits with a fresh computation of the parallax factors and without
        astro = Astrometry('hip2or21', '27321', f'htof/test/data_for_tests/{datadir}', central_epoch_ra=1991.25,
                           central_epoch_dec=1991.25, format='jyear', fit_degree=1, use_parallax=True,
                           central_ra=cntr_ra, central_dec=cntr_dec,
                           use_catalog_parallax_factors=True)
        chisq = np.sum(astro.data.residuals ** 2 / astro.data.along_scan_errs ** 2)
        # generate ra and dec for each observation.
        year_epochs = Time(astro.data.julian_day_epoch(), format='jd', scale='tcb').jyear - \
                      Time(1991.25, format='decimalyear').jyear
        ra_motion = astro.fitter.parallactic_pertubations['ra_plx']
        dec_motion = astro.fitter.parallactic_pertubations['dec_plx']
        ra = Angle(ra_motion * plx + pmRA * year_epochs, unit='mas')
        dec = Angle(dec_motion * plx + pmDec * year_epochs, unit='mas')
        # add residuals
        ra += Angle(astro.data.residuals.values * np.sin(astro.data.scan_angle.values), unit='mas')
        dec += Angle(astro.data.residuals.values * np.cos(astro.data.scan_angle.values), unit='mas')
        #
        coeffs, errors, chisq_found, residuals = astro.fit(ra.mas, dec.mas, return_all=True)
        residuals = to_along_scan_basis(residuals[:, 0], residuals[:, 1], astro.data.scan_angle.values)
        assert np.isclose(chisq, chisq_found, atol=1E-3)
        assert np.allclose([pmRA, pmDec], np.array([coeffs[3], coeffs[4]]).round(2))
        assert np.isclose(plx, coeffs[0].round(2), atol=0.01)
        assert np.allclose(errors.round(2), np.array([0.12, 0.10, 0.11, 0.11, 0.15]), atol=0.01)
        assert np.allclose(residuals, astro.data.residuals.values, atol=0.02)
Beispiel #3
0
def test_Gaia_fit_to_hip27321():
    # Hip 27321 central ra and dec from the gost data file.
    cntr_ra, cntr_dec = Angle(1.5153157780177544, 'radian'), Angle(-0.8912787619608181, 'radian')
    #
    plx = 51.87  # mas
    pmRA = 4.65  # mas/year
    pmDec = 81.96  # mas/year
    # generate fitter and parse intermediate data
    for use_catalog_parallax_factors in [False, True]:
        print('not '* (not use_catalog_parallax_factors) + 'using catalog parallax factors.')
        # trying fits with a fresh computation of the parallax factors and without
        astro = Astrometry('GaiaEDR3', '27321', 'htof/test/data_for_tests/GaiaeDR3',
                           central_epoch_ra=2016, central_epoch_dec=2016,
                           format='jyear', fit_degree=1, use_parallax=True,
                           central_ra=cntr_ra, central_dec=cntr_dec,
                           use_catalog_parallax_factors=use_catalog_parallax_factors)
        chisq = np.sum(astro.data.residuals ** 2 / astro.data.along_scan_errs ** 2)
        # generate ra and dec for each observation.
        year_epochs = Time(astro.data.julian_day_epoch(), format='jd', scale='tcb').jyear - \
                      Time(2016, format='decimalyear').jyear
        ra_motion = astro.fitter.parallactic_pertubations['ra_plx']
        dec_motion = astro.fitter.parallactic_pertubations['dec_plx']
        ra = Angle(ra_motion * plx + pmRA * year_epochs, unit='mas')
        dec = Angle(dec_motion * plx + pmDec * year_epochs, unit='mas')
        #
        coeffs, errors, chisq_found, residuals = astro.fit(ra.mas, dec.mas, return_all=True)
        residuals = to_along_scan_basis(residuals[:, 0], residuals[:, 1], astro.data.scan_angle.values)
        assert np.isclose(chisq, chisq_found, atol=1E-3)
        assert np.allclose([pmRA, pmDec], np.array([coeffs[3], coeffs[4]]).round(2))
        assert np.isclose(plx, coeffs[0].round(2), atol=0.01)
Beispiel #4
0
def initialize_data(config):
    # load in items from the ConfigParser object
    HipID = config.getint('data_paths', 'HipID', fallback=0)
    RVFile = config.get('data_paths', 'RVFile')
    AstrometryFile = config.get('data_paths', 'AstrometryFile')
    GaiaDataDir = config.get('data_paths', 'GaiaDataDir', fallback=None)
    Hip2DataDir = config.get('data_paths', 'Hip2DataDir', fallback=None)
    Hip1DataDir = config.get('data_paths', 'Hip1DataDir', fallback=None)
    use_epoch_astrometry = config.getboolean('mcmc_settings',
                                             'use_epoch_astrometry',
                                             fallback=False)
    #

    data = orbit.Data(HipID, RVFile, AstrometryFile)
    if use_epoch_astrometry:
        Gaia_fitter = Astrometry('GaiaDR2',
                                 '%06d' % (HipID),
                                 GaiaDataDir,
                                 central_epoch_ra=data.epRA_G,
                                 central_epoch_dec=data.epDec_G,
                                 central_epoch_fmt='frac_year')
        Hip2_fitter = Astrometry('Hip2',
                                 '%06d' % (HipID),
                                 Hip2DataDir,
                                 central_epoch_ra=data.epRA_H,
                                 central_epoch_dec=data.epDec_H,
                                 central_epoch_fmt='frac_year')
        Hip1_fitter = Astrometry('Hip1',
                                 '%06d' % (HipID),
                                 Hip1DataDir,
                                 central_epoch_ra=data.epRA_H,
                                 central_epoch_dec=data.epDec_H,
                                 central_epoch_fmt='frac_year')
        # instantiate C versions of the astrometric fitter which are must faster than HTOF's Astrometry
        hip1_fast_fitter = orbit.AstrometricFitter(Hip1_fitter)
        hip2_fast_fitter = orbit.AstrometricFitter(Hip2_fitter)
        gaia_fast_fitter = orbit.AstrometricFitter(Gaia_fitter)

        data = orbit.Data(HipID,
                          RVFile,
                          AstrometryFile,
                          use_epoch_astrometry,
                          epochs_Hip1=Hip1_fitter.data.julian_day_epoch(),
                          epochs_Hip2=Hip2_fitter.data.julian_day_epoch(),
                          epochs_Gaia=Gaia_fitter.data.julian_day_epoch())
    else:
        hip1_fast_fitter, hip2_fast_fitter, gaia_fast_fitter = None, None, None

    return data, hip1_fast_fitter, hip2_fast_fitter, gaia_fast_fitter
Beispiel #5
0
 def test_parallax_factors_independent_of_reference_epoch(self):
     astron = Astrometry('Hip1', '27321', 'htof/test/data_for_tests/Hip1', central_epoch_ra=2000,
                        central_epoch_dec=2000, format='jyear', fit_degree=1, use_parallax=True,
                        central_ra=self.cntr_ra, central_dec=self.cntr_dec)
     ra_motionn = astron.fitter.parallactic_pertubations['ra_plx']
     dec_motionn = astron.fitter.parallactic_pertubations['dec_plx']
     assert np.allclose(to_along_scan_basis(self.ra_motion, self.dec_motion, self.scan_angle),
                        to_along_scan_basis(ra_motionn, dec_motionn, self.scan_angle))
Beispiel #6
0
def test_optimal_central_epochs_forHip1_hip27321_no_parallax():
    astro = Astrometry('Hip1', '27321', 'htof/test/data_for_tests/Hip1', central_epoch_ra=1991.25,
                       central_epoch_dec=1991.25, format='jyear', fit_degree=1,
                       use_parallax=False)
    central_epoch = astro.optimal_central_epochs()
    central_epoch_ra, central_epoch_dec = central_epoch['ra'], central_epoch['dec']
    #print(central_epoch_ra, central_epoch_dec)
    fitter = astro.fitter
    cov_matrix = fitter.evaluate_cov_matrix(central_epoch_ra, central_epoch_dec)
    ra_mura_cov, dec_mudec_cov = cov_matrix[0, 2], cov_matrix[1, 3]
    # do a brute force evaluation of all reasonable central epochs
    epoch_t = np.linspace(1991, 1992, 200)
    ra_vals, dec_vals = [], []
    for t in epoch_t:
        cov = fitter.evaluate_cov_matrix(t, t)
        ra_vals.append(cov[0, 2])
        dec_vals.append(cov[1, 3])
    # assert that the optimal central epochs give better covariances than all of those.
    assert np.all(np.abs(dec_vals) >= dec_mudec_cov)
    assert np.all(np.abs(ra_vals) >= ra_mura_cov)
    assert np.allclose([dec_mudec_cov, ra_mura_cov], 0, atol=1e-9)
Beispiel #7
0
def test_Hip1_fit_to_hip27321_no_parallax():
    # WARNING including the parallax component is important if you want to recover the catalog errors.
    # Hip 27321 parameters from the Hipparcos 1 catalogue via Vizier
    pmRA = 4.65  # mas/year
    pmDec = 81.96  # mas/year
    # generate fitter and parse intermediate data
    astro = Astrometry('Hip1', '27321', 'htof/test/data_for_tests/Hip1', central_epoch_ra=1991.25,
                       central_epoch_dec=1991.25, format='jyear', fit_degree=1,
                       use_parallax=False)
    chisq = np.sum(astro.data.residuals ** 2 / astro.data.along_scan_errs ** 2)
    # generate ra and dec for each observation.
    year_epochs = Time(astro.data.julian_day_epoch(), format='jd', scale='tcb').jyear - \
                  Time(1991.25, format='decimalyear').jyear
    ra = Angle(pmRA * year_epochs, unit='mas')
    dec = Angle(pmDec * year_epochs, unit='mas')
    # add residuals
    ra += Angle(astro.data.residuals.values * np.sin(astro.data.scan_angle.values), unit='mas')
    dec += Angle(astro.data.residuals.values * np.cos(astro.data.scan_angle.values), unit='mas')
    #
    coeffs, errors, chisq_found, residuals_found = astro.fit(ra.mas, dec.mas, return_all=True)
    assert np.isclose(chisq, chisq_found, atol=1E-3)
    assert np.allclose([pmRA, pmDec], np.array([coeffs[2], coeffs[3]]).round(2))
    assert np.allclose(errors.round(2), np.array([0.45, 0.46, 0.53, 0.61]), atol=0.01)
Beispiel #8
0
def test_optimal_central_epochs_forHip1_hip27321():
    # Hip 27321 parameters from the Hipparcos 1 catalogue via Vizier
    cntr_ra, cntr_dec = Angle(86.82118054, 'degree'), Angle(-51.06671341, 'degree')
    # generate fitter and parse intermediate data
    astro = Astrometry('Hip1', '27321', 'htof/test/data_for_tests/Hip1', central_epoch_ra=1991.25,
                       central_epoch_dec=1991.25, format='jyear', fit_degree=1, use_parallax=True,
                       central_ra=cntr_ra, central_dec=cntr_dec)
    central_epoch = astro.optimal_central_epochs()
    central_epoch_ra, central_epoch_dec = central_epoch['ra'], central_epoch['dec']
    #print(central_epoch_ra, central_epoch_dec)
    fitter = astro.fitter
    cov_matrix = fitter.evaluate_cov_matrix(central_epoch_ra, central_epoch_dec)
    ra_mura_cov, dec_mudec_cov = cov_matrix[1, 3], cov_matrix[2, 4]
    # do a brute force evaluation of all reasonable central epochs
    epoch_t = np.linspace(1991, 1992, 200)
    ra_vals, dec_vals = [], []
    for t in epoch_t:
        cov = fitter.evaluate_cov_matrix(t, t)
        ra_vals.append(cov[1, 3])
        dec_vals.append(cov[2, 4])
    # assert that the optimal central epochs give better covariances than all of those.
    assert np.all(np.abs(dec_vals) >= dec_mudec_cov)
    assert np.all(np.abs(ra_vals) >= ra_mura_cov)
    assert np.allclose([dec_mudec_cov, ra_mura_cov], 0, atol=1e-8)
Beispiel #9
0
class TestParallaxFactorsGaia:
    """
    Tests the computation of the parallax factors anew, as well as tests the basis transformations from along-scan
    to ra and dec.
    """
    # Hip 27321 parameters from the Gaia EDR3 archive.
    cntr_ra, cntr_dec = Angle(86.82123452009108, 'degree'), Angle(-51.066136257823345, 'degree')
    # generate fitter and parse intermediate data
    astro = Astrometry('Gaiaedr3', '27321', 'htof/test/data_for_tests/GaiaeDR3', central_epoch_ra=2016,
                       central_epoch_dec=2016, format='jyear', fit_degree=1, use_parallax=True,
                       central_ra=cntr_ra, central_dec=cntr_dec)
    ra_motion = astro.fitter.parallactic_pertubations['ra_plx']
    dec_motion = astro.fitter.parallactic_pertubations['dec_plx']
    along_scan_parallax_factors = astro.data.parallax_factors.values
    scan_angle = astro.data.scan_angle.values

    def test_new_computed_parallax_factors_agree_with_scanninglaw(self):
        # test that the newly computed parallax factors agree with
        # parallaxFactorAlongScan from the GOST data.
        assert np.allclose(self.along_scan_parallax_factors,
                           to_along_scan_basis(self.ra_motion, self.dec_motion, self.scan_angle), atol=0.03)
Beispiel #10
0
class TestParallaxFactors:
    """
    Tests the computation of the parallax factors anew, as well as tests the basis transformations from along-scan
    to ra and dec.
    """
    # Hip 27321 parameters from the Hipparcos 1 catalogue via Vizier
    cntr_ra, cntr_dec = Angle(86.82118054, 'degree'), Angle(-51.06671341, 'degree')
    # generate fitter and parse intermediate data
    astro = Astrometry('Hip1', '27321', 'htof/test/data_for_tests/Hip1', central_epoch_ra=1991.25,
                       central_epoch_dec=1991.25, format='jyear', fit_degree=1, use_parallax=True,
                       central_ra=cntr_ra, central_dec=cntr_dec)
    ra_motion = astro.fitter.parallactic_pertubations['ra_plx']
    dec_motion = astro.fitter.parallactic_pertubations['dec_plx']
    along_scan_parallax_factors = astro.data.parallax_factors.values
    scan_angle = astro.data.scan_angle.values

    def test_new_computed_parallax_factors_agree_with_catalog(self):
        assert np.allclose(self.along_scan_parallax_factors,
                           to_along_scan_basis(self.ra_motion, self.dec_motion, self.scan_angle), atol=0.03)

    def test_parallax_factors_backward_transform(self):
        # note that this is redundant with test_basis_change_consistency()
        ra_motion, dec_motion = to_ra_dec_basis(self.along_scan_parallax_factors, self.scan_angle)
        # convert the calculated parallax factors to the along-scan basis and back to null out the AC component.
        al_parallax_factor = to_along_scan_basis(self.ra_motion, self.dec_motion, self.scan_angle)
        ra_motion_acnull, dec_motion_acnull = to_ra_dec_basis(al_parallax_factor, self.scan_angle)
        assert np.allclose(ra_motion, ra_motion_acnull, atol=0.03)
        assert np.allclose(dec_motion, dec_motion_acnull, atol=0.03)

    def test_parallax_factors_independent_of_reference_epoch(self):
        astron = Astrometry('Hip1', '27321', 'htof/test/data_for_tests/Hip1', central_epoch_ra=2000,
                           central_epoch_dec=2000, format='jyear', fit_degree=1, use_parallax=True,
                           central_ra=self.cntr_ra, central_dec=self.cntr_dec)
        ra_motionn = astron.fitter.parallactic_pertubations['ra_plx']
        dec_motionn = astron.fitter.parallactic_pertubations['dec_plx']
        assert np.allclose(to_along_scan_basis(self.ra_motion, self.dec_motion, self.scan_angle),
                           to_along_scan_basis(ra_motionn, dec_motionn, self.scan_angle))
Beispiel #11
0
def initialize_data(config, companion_gaia):
    # load in items from the ConfigParser object
    HipID = config.getint('data_paths', 'HipID', fallback=0)
    HGCAFile = config.get('data_paths', 'HGCAFile')
    if not os.path.exists(HGCAFile):
        raise FileNotFoundError(f'No HGCA file found at {HGCAFile}')

    try:
        table = fits.open(HGCAFile)[1].data
        epoch_ra_gaia = table[table['hip_id'] == 1]['epoch_ra_gaia']
        if np.isclose(epoch_ra_gaia, 2015.60211565):
            HGCAVersion = 'GaiaDR2'
        elif np.isclose(epoch_ra_gaia, 2015.92749023):
            HGCAVersion = 'GaiaeDR3'
        else:
            raise ValueError(
                "Cannot match %s to either DR2 or eDR3 based on RA epoch of Gaia"
                % (HGCAFile))
    except:
        raise ValueError("Cannot access HIP 1 in HGCA file" + HGCAFile)

    RVFile = config.get('data_paths', 'RVFile', fallback='')
    AstrometryFile = config.get('data_paths', 'AstrometryFile', fallback='')
    GaiaDataDir = config.get('data_paths', 'GaiaDataDir', fallback='')
    Hip2DataDir = config.get('data_paths', 'Hip2DataDir', fallback='')
    Hip1DataDir = config.get('data_paths', 'Hip1DataDir', fallback='')
    use_epoch_astrometry = config.getboolean('mcmc_settings',
                                             'use_epoch_astrometry',
                                             fallback=False)

    data = orbit.Data(HipID,
                      HGCAFile,
                      RVFile,
                      AstrometryFile,
                      companion_gaia=companion_gaia)
    if use_epoch_astrometry and data.use_abs_ast == 1:
        # TODO verify that this half-day should indeed be here. This doesnt matter for ~10 year orbits,
        #  but would matter if we wanted to fit companions with shorter orbital arcs.
        to_jd = lambda x: Time(x, format='decimalyear').jd + 0.5
        Gaia_fitter = Astrometry(HGCAVersion,
                                 '%06d' % (HipID),
                                 GaiaDataDir,
                                 central_epoch_ra=to_jd(data.epRA_G),
                                 central_epoch_dec=to_jd(data.epDec_G),
                                 format='jd')
        Hip2_fitter = Astrometry('Hip2',
                                 '%06d' % (HipID),
                                 Hip2DataDir,
                                 central_epoch_ra=to_jd(data.epRA_H),
                                 central_epoch_dec=to_jd(data.epDec_H),
                                 format='jd')
        Hip1_fitter = Astrometry('Hip1',
                                 '%06d' % (HipID),
                                 Hip1DataDir,
                                 central_epoch_ra=to_jd(data.epRA_H),
                                 central_epoch_dec=to_jd(data.epDec_H),
                                 format='jd')
        # instantiate C versions of the astrometric fitter which are much faster than HTOF's Astrometry
        #print(Gaia_fitter.fitter.astrometric_solution_vector_components['ra'])
        hip1_fast_fitter = orbit.AstrometricFitter(Hip1_fitter)
        hip2_fast_fitter = orbit.AstrometricFitter(Hip2_fitter)
        gaia_fast_fitter = orbit.AstrometricFitter(Gaia_fitter)

        data = orbit.Data(HipID,
                          HGCAFile,
                          RVFile,
                          AstrometryFile,
                          use_epoch_astrometry,
                          epochs_Hip1=Hip1_fitter.data.julian_day_epoch(),
                          epochs_Hip2=Hip2_fitter.data.julian_day_epoch(),
                          epochs_Gaia=Gaia_fitter.data.julian_day_epoch(),
                          companion_gaia=companion_gaia,
                          verbose=False)
    elif data.use_abs_ast == 1:
        hip1_fast_fitter, hip2_fast_fitter, gaia_fast_fitter = None, None, None
    else:
        hip1_fast_fitter, hip2_fast_fitter, gaia_fast_fitter = None, None, None
        try:
            data.plx = 1e-3 * config.getfloat('priors_settings', 'parallax')
            data.plx_err = 1e-3 * config.getfloat('priors_settings',
                                                  'parallax_error')
        except:
            print("Cannot load absolute astrometry.")
            print("Please supply a prior for parallax and parallax_error")
            print("in the priors_settings area of the configuration file.")

    return data, hip1_fast_fitter, hip2_fast_fitter, gaia_fast_fitter