def test_lnprior(): dim = 6 mean = np.zeros(dim) covmatrix = np.identity(dim) age = 10. sphere_comp = SphereComponent(attributes={ 'mean':mean, 'covmatrix':covmatrix, 'age':age, }) memb_probs = np.ones(10) assert np.isfinite(likelihood.lnprior(sphere_comp, memb_probs)) # Now increase age to something ridiculous sphere_comp.update_attribute(attributes={ 'age':1e10, }) assert np.isinf(likelihood.lnprior(sphere_comp, memb_probs)) # Try an EllipComponent with a non-symmetrical covariance matrix covmatrix[0,1] = 1.01 # covmatrix[1,0] = 100 ellip_comp = EllipComponent(attributes={ 'mean':mean, 'covmatrix':covmatrix, 'age':age, }) assert np.isinf(likelihood.lnprior(ellip_comp, memb_probs)) # Try an EllipComponent with a very broken correlation value covmatrix[0,1] = 1.01 covmatrix[1,0] = 1.01 ellip_comp = EllipComponent(attributes={ 'mean':mean, 'covmatrix':covmatrix, 'age':age, }) assert np.isinf(likelihood.lnprior(ellip_comp, memb_probs))
def test_lnprior(): dim = 6 mean = np.zeros(dim) covmatrix = np.identity(dim) age = 10. sphere_comp = SphereComponent(attributes={ 'mean': mean, 'covmatrix': covmatrix, 'age': age, }) memb_probs = np.ones(10) assert np.isfinite(likelihood.lnprior(sphere_comp, memb_probs)) # Now increase age to something ridiculous sphere_comp.update_attribute(attributes={ 'age': 1e10, }) assert np.isinf(likelihood.lnprior(sphere_comp, memb_probs)) # Try an EllipComponent with a non-symmetrical covariance matrix covmatrix[0, 1] = 1.01 # covmatrix[1,0] = 100 ellip_comp = EllipComponent(attributes={ 'mean': mean, 'covmatrix': covmatrix, 'age': age, }) assert np.isinf(likelihood.lnprior(ellip_comp, memb_probs)) # Try an EllipComponent with a very broken correlation value covmatrix[0, 1] = 1.01 covmatrix[1, 0] = 1.01 ellip_comp = EllipComponent(attributes={ 'mean': mean, 'covmatrix': covmatrix, 'age': age, }) assert np.isinf(likelihood.lnprior(ellip_comp, memb_probs))
lims = 6*[None] for time_ix, time in enumerate(times[::-1]): print('plot {:3}: time {:4.2f}'.format(time_ix, time)) plt.clf() for c in all_comps: # only plot component if it exists # print('plotting {}'.format(c)) if c.get_age() > time: # print('{} is greater than {}'.format(c.get_age(), time)) c_copy = SphereComponent(c.get_pars()) # modify age so that 'comp_now' is plotted at time `time` # time is how long ago, we want copy.age to be time since # birth, that is c.get_age - time c_copy.update_attribute({'age':c.get_age()-time}) # print('pars updated to: {}'.format(c_copy.get_pars())) c_copy.plot(dim1=dim1, dim2=dim2, comp_now=True, comp_then=True, comp_orbit=True) # There was a prior issue ( # if c_copy.get_mean_now()[1] < -200: # import pdb; pdb.set_trace() plt.xlim() plt.xlabel('{} [{}]'.format(labels[dim1], units[dim1])) plt.ylabel('{} [{}]'.format(labels[dim2], units[dim2])) lims[dim1] = update_1D_lims(lims[dim1], plt.xlim()) lims[dim2] = update_1D_lims(lims[dim2], plt.ylim())