def test_background_component(): """Create artificial association composed of two stars at opposite vertices of unit 6D rectangle. Then base background density distribution on that.""" background_density = 100 # Since the background double the span of data, by setting the means as # follows, the backbround should extend from 0 to 1 in each dimension, # which greatly simplifies reasoning about densities and starcounts. upper_mean = np.zeros(6) + 0.75 lower_mean = np.zeros(6) + 0.25 narrow_dx = 1e-10 narrow_dv = 1e-10 tiny_age = 1e-10 upper_pars = np.hstack((upper_mean, narrow_dx, narrow_dv, tiny_age)) lower_pars = np.hstack((lower_mean, narrow_dx, narrow_dv, tiny_age)) starcounts = [1,1] synth_data = SynthData(pars=[upper_pars, lower_pars], starcounts=starcounts, background_density=background_density) synth_data.generate_all_init_cartesian() means = tabletool.build_data_dict_from_table( synth_data.table[2:], main_colnames=[el+'0' for el in 'xyzuvw'], only_means=True, ) assert np.allclose(0.5, np.mean(means, axis=0), atol=0.1) assert np.allclose(1.0, np.max(means, axis=0), atol=0.1) assert np.allclose(0.0, np.min(means, axis=0), atol=0.1) assert len(synth_data.table) == background_density + 2
def test_measureXYZUVW(): """Check measurements of xyzuvw_now to astrometry occur properly. Will use extremely dense component as case study as this ensures stars all have more or less the same true values""" compact_comp_pars = np.copy(PARS[0]) compact_comp_pars[6] = 1e-15 compact_comp_pars[7] = 1e-15 compact_comp_pars[8] = 1e-15 starcounts = [1000] sd = SynthData(pars=np.array([compact_comp_pars]), starcounts=starcounts, Components=COMPONENTS) sd.generate_all_init_cartesian() sd.project_stars() sd.measure_astrometry() for colname in SynthData.DEFAULT_ASTR_COLNAMES: assert np.allclose(sd.GERROR[colname + '_error'], sd.table[colname + '_error']) # Check spread of data is similar to Gaia error, we use # a large tolerance so a small number of stars can be used assert np.isclose(sd.GERROR[colname + '_error'], np.std(sd.table[colname]), rtol=1e-1)
def test_generateInitXYZUVW(): """Check that the mean of initial xyzuvw of stars matches that of the initialising component""" starcounts = (int(1e6), ) sd = SynthData(pars=PARS[:1], starcounts=starcounts, Components=COMPONENTS) sd.generate_all_init_cartesian() comp = SphereComponent(PARS[0]) init_xyzuvw = sd.extract_data_as_array([dim + '0' for dim in 'xyzuvw']) assert np.allclose(comp.get_mean(), np.mean(init_xyzuvw, axis=0), atol=0.1)
def test_generateInitXYZUVW(): """Check that the mean of initial xyzuvw of stars matches that of the initialising component""" starcounts = (int(1e6),) sd = SynthData(pars=PARS[:1], starcounts=starcounts, Components=COMPONENTS) sd.generate_all_init_cartesian() comp = SphereComponent(PARS[0]) init_xyzuvw = sd.extract_data_as_array([dim + '0' for dim in 'xyzuvw']) assert np.allclose(comp.get_mean(), np.mean(init_xyzuvw, axis=0), atol=0.1)
def test_projectStars(): """Check that the mean of stars after projection matches the mean of the component after projection""" starcounts = (int(1e3),) sd = SynthData(pars=PARS[:1], starcounts=starcounts, Components=COMPONENTS) sd.generate_all_init_cartesian() sd.project_stars() comp_mean_now, comp_covmatrix_now = \ sd.components[0].get_currentday_projection() final_xyzuvw = sd.extract_data_as_array([dim + '_now' for dim in 'xzyuvw']) assert np.allclose(comp_mean_now, final_xyzuvw.mean(axis=0), atol=1.)
def test_measureXYZUVW(): """Check measurements of xyzuvw_now to astrometry occur properly. Will use extremely dense component as case study as this ensures stars all have more or less the same true values""" compact_comp_pars = np.copy(PARS[0]) compact_comp_pars[6] = 1e-15 compact_comp_pars[7] = 1e-15 compact_comp_pars[8] = 1e-15 starcounts = [1000] sd = SynthData(pars=np.array([compact_comp_pars]), starcounts=starcounts, Components=COMPONENTS) sd.generate_all_init_cartesian() sd.project_stars() sd.measure_astrometry() for colname in SynthData.DEFAULT_ASTR_COLNAMES: assert np.allclose(sd.GERROR[colname + '_error'], sd.table[colname + '_error']) # Check spread of data is similar to Gaia error, we use # a large tolerance so a small number of stars can be used assert np.isclose(sd.GERROR[colname + '_error'], np.std(sd.table[colname]), rtol=1e-1)