def test_cov_dvrpmllbb_to_vxyz(): l,b,d= 90., 0., 2. e_d, e_vr= 0.2, 2. cov_pmllpmbb= numpy.array([[100.,0.],[0.,400.]]) pmll,pmbb= 20.,30. cov_vxvyvz= bovy_coords.cov_dvrpmllbb_to_vxyz(d,e_d,e_vr, pmll,pmbb, cov_pmllpmbb, l,b, degree=True, plx=False) assert numpy.fabs(numpy.sqrt(cov_vxvyvz[0,0]) -d*4.74047*pmll*numpy.sqrt((e_d/d)**2.+(10./pmll)**2.)) < 10.**-10., 'cov_dvrpmllbb_to_vxyz coversion did not work as expected' assert numpy.fabs(numpy.sqrt(cov_vxvyvz[1,1])-e_vr) < 10.**-10., 'cov_dvrpmllbb_to_vxyz coversion did not work as expected' assert numpy.fabs(numpy.sqrt(cov_vxvyvz[2,2]) -d*4.74047*pmbb*numpy.sqrt((e_d/d)**2.+(20./pmbb)**2.)) < 10.**-10., 'cov_dvrpmllbb_to_vxyz coversion did not work as expected' #Another one l,b,d= 180., 0., 1./2. e_d, e_vr= 0.05, 2. cov_pmllpmbb= numpy.array([[100.,0.],[0.,400.]]) pmll,pmbb= 20.,30. cov_vxvyvz= bovy_coords.cov_dvrpmllbb_to_vxyz(d,e_d,e_vr, pmll,pmbb, cov_pmllpmbb, l/180.*numpy.pi, b/180.*numpy.pi, degree=False, plx=True) assert numpy.fabs(numpy.sqrt(cov_vxvyvz[0,0])-e_vr) < 10.**-10., 'cov_dvrpmllbb_to_vxyz coversion did not work as expected' assert numpy.fabs(numpy.sqrt(cov_vxvyvz[1,1]) -1./d*4.74047*pmll*numpy.sqrt((e_d/d)**2.+(10./pmll)**2.)) < 10.**-10., 'cov_dvrpmllbb_to_vxyz coversion did not work as expected' assert numpy.fabs(numpy.sqrt(cov_vxvyvz[2,2]) -1./d*4.74047*pmbb*numpy.sqrt((e_d/d)**2.+(20./pmbb)**2.)) < 10.**-10., 'cov_dvrpmllbb_to_vxyz coversion did not work as expected' #Another one, w/ arrays l,b,d= 90., 90., 2. e_d, e_vr= 0.2, 2. tcov_pmllpmbb= numpy.array([[100.,0.],[0.,400.]]) cov_pmllpmbb= numpy.empty((3,2,2)) for ii in range(3): cov_pmllpmbb[ii,:,:]= tcov_pmllpmbb pmll,pmbb= 20.,30. os= numpy.ones(3) cov_vxvyvz= bovy_coords.cov_dvrpmllbb_to_vxyz(os*d,os*e_d,os*e_vr, os*pmll,os*pmbb, cov_pmllpmbb, os*l,os*b, degree=True, plx=False) for ii in range(3): assert numpy.fabs(numpy.sqrt(cov_vxvyvz[ii,0,0]) -d*4.74047*pmll*numpy.sqrt((e_d/d)**2.+(10./pmll)**2.)) < 10.**-10., 'cov_dvrpmllbb_to_vxyz coversion did not work as expected' assert numpy.fabs(numpy.sqrt(cov_vxvyvz[ii,1,1]) -d*4.74047*pmbb*numpy.sqrt((e_d/d)**2.+(20./pmbb)**2.)) < 10.**-10., 'cov_dvrpmllbb_to_vxyz coversion did not work as expected' assert numpy.fabs(numpy.sqrt(cov_vxvyvz[ii,2,2])-e_vr) < 10.**-10., 'cov_dvrpmllbb_to_vxyz coversion did not work as expected' return None
def uvw_unc(req_dict, opt_dict): cov_radec = np.zeros((2, 2)) cov_radec[0, 0] = opt_dict['epmra']**2 cov_radec[1, 1] = opt_dict['epmdec']**2 covar_pmllbb = b_c.cov_pmrapmdec_to_pmllpmbb(cov_radec, req_dict['ra'], req_dict['dec'], degree=True, epoch=2000.0) cov_vxvyvz = b_c.cov_dvrpmllbb_to_vxyz(req_dict['dist'], opt_dict['edist'], opt_dict['erv'], req_dict['pml'], req_dict['pmb'], covar_pmllbb, req_dict['l'], req_dict['b'], plx=False, degree=True) du = vx_e = m.sqrt(cov_vxvyvz[0, 0]) dv = vy_e = m.sqrt(cov_vxvyvz[1, 1]) dw = vz_e = m.sqrt(cov_vxvyvz[2, 2]) return du, dv, dw
def calc_spacevel_uncer_var_tensor(self): """ Using vscatter for error in RV (km/s) and 2.5% distance errors """ dist_uncer = 0.025 * self.get_col('RC_DIST') uncer_tensor = bcoords.cov_dvrpmllbb_to_vxyz(self.get_col('RC_DIST'), dist_uncer, self.get_col('VSCATTER'), self.pmll_pmbb[:, 0], self.pmll_pmbb[:, 1], self.covar_pmllpmbb, self.get_col('GLON'), self.get_col('GLAT'), degree=self.degree) self.spacevel_uncer_var_tensor = uncer_tensor
def obs_to_galcen(ra, dec, dist, pmra, pmdec, rv, pmra_err, pmdec_err, pmra_pmdec_corr, dist_err, rv_err, return_cov=True, verbose=True, return_rphiz=True, ro=8., vo=220., zo=0.025, parallax=False): vxvv = np.dstack([ra, dec, dist, pmra, pmdec, rv])[0] ra, dec = vxvv[:, 0], vxvv[:, 1] lb = bovy_coords.radec_to_lb(ra, dec, degree=True) pmra, pmdec = vxvv[:, 3], vxvv[:, 4] pmllpmbb = bovy_coords.pmrapmdec_to_pmllpmbb(pmra, pmdec, ra, dec, degree=True) d, vlos = vxvv[:, 2], vxvv[:, 5] if parallax: d = 1. / d rectgal = bovy_coords.sphergal_to_rectgal(lb[:, 0], lb[:, 1], d, vlos, pmllpmbb[:, 0], pmllpmbb[:, 1], degree=True) vsolar = np.array([-10.1, 4.0, 6.7]) vsun = np.array([ 0., 1., 0., ]) + vsolar / vo X = rectgal[:, 0] / ro Y = rectgal[:, 1] / ro Z = rectgal[:, 2] / ro vx = rectgal[:, 3] / vo vy = rectgal[:, 4] / vo vz = rectgal[:, 5] / vo XYZ = np.dstack([X, Y, Z])[0] vxyz = np.dstack([vx, vy, vz])[0] if return_rphiz: Rpz = bovy_coords.XYZ_to_galcencyl(XYZ[:, 0], XYZ[:, 1], XYZ[:, 2], Zsun=zo / ro) vRvTvz = bovy_coords.vxvyvz_to_galcencyl(vxyz[:, 0], vxyz[:, 1], vxyz[:, 2], Rpz[:, 0], Rpz[:, 1], Rpz[:, 2], vsun=vsun, Xsun=1., Zsun=zo / ro, galcen=True) if return_cov == True: cov_pmradec = np.empty([len(pmra_err), 2, 2]) cov_pmradec[:, 0, 0] = pmra_err**2 cov_pmradec[:, 1, 1] = pmdec_err**2 cov_pmradec[:, 0, 1] = pmra_pmdec_corr * pmra_err * pmdec_err cov_pmradec[:, 1, 0] = pmra_pmdec_corr * pmra_err * pmdec_err if verbose: print('propagating covariance in pmra pmdec -> pmll pmbb') cov_pmllbb = bovy_coords.cov_pmrapmdec_to_pmllpmbb(cov_pmradec, vxvv[:, 0], vxvv[:, 1], degree=True, epoch='J2015') if verbose: print('propagating covariance in pmll pmbb -> vx vy vz') cov_vxyz = bovy_coords.cov_dvrpmllbb_to_vxyz(vxvv[:, 2], dist_err, rv_err, pmllpmbb[:, 0], pmllpmbb[:, 1], cov_pmllbb, lb[:, 0], lb[:, 1]) if not return_rphiz: return XYZ, vxyz, cov_vxyz if verbose: print('propagating covariance in vx vy vz -> vR vT vz') cov_galcencyl = bovy_coords.cov_vxyz_to_galcencyl(cov_vxyz, Rpz[:, 1], Xsun=1., Zsun=zo / ro) return XYZ, vxyz, cov_vxyz, Rpz, vRvTvz, cov_galcencyl if not return_rphiz: return XYZ, vxyz return XYZ, vxyz, Rpz, vRvTvz
def dat_to_galcen( dat, return_cov=True, return_rphiz=True, verbose=False, ro=8., vo=220., zo=0.025, keys=['ra', 'dec', 'BPG_meandist', 'pmra', 'pmdec', 'VHELIO_AVG'], cov_keys=[ 'pmra_error', 'pmdec_error', 'pmra_pmdec_corr', 'BPG_diststd', 'VERR' ], parallax=False): vxvv = np.dstack([dat[keys[i]] for i in range(len(keys))])[0] ra, dec = vxvv[:, 0], vxvv[:, 1] lb = bovy_coords.radec_to_lb(ra, dec, degree=True) pmra, pmdec = vxvv[:, 3], vxvv[:, 4] pmllpmbb = bovy_coords.pmrapmdec_to_pmllpmbb(pmra, pmdec, ra, dec, degree=True) d, vlos = vxvv[:, 2], vxvv[:, 5] if parallax: d = 1. / d rectgal = bovy_coords.sphergal_to_rectgal(lb[:, 0], lb[:, 1], d, vlos, pmllpmbb[:, 0], pmllpmbb[:, 1], degree=True) vsolar = np.array([-11.1, 245.6, 7.25]) #use SBD10 vR and vZ and SGR proper motion vT vsun = np.array([ 0., 0., 0., ]) + vsolar / vo X = rectgal[:, 0] / ro Y = rectgal[:, 1] / ro Z = rectgal[:, 2] / ro vx = rectgal[:, 3] / vo vy = rectgal[:, 4] / vo vz = rectgal[:, 5] / vo XYZ = np.dstack([X, Y, Z])[0] vxyz = np.dstack([vx, vy, vz])[0] if return_rphiz: Rpz = bovy_coords.XYZ_to_galcencyl(XYZ[:, 0], XYZ[:, 1], XYZ[:, 2], Zsun=zo / ro) vRvTvz = bovy_coords.vxvyvz_to_galcencyl(vxyz[:, 0], vxyz[:, 1], vxyz[:, 2], Rpz[:, 0], Rpz[:, 1], Rpz[:, 2], vsun=vsun, Xsun=1., Zsun=zo / ro, galcen=True) if return_cov == True: cov_pmradec = np.array([[[ dat[cov_keys[0]][i]**2, dat[cov_keys[2]][i] * dat[cov_keys[0]][i] * dat[cov_keys[1]][i] ], [ dat[cov_keys[2]][i] * dat[cov_keys[0]][i] * dat[cov_keys[1]][i], dat[cov_keys[1]][i]**2 ]] for i in range(len(dat))]) if verbose: print('propagating covariance in pmra pmdec -> pmll pmbb') cov_pmllbb = bovy_coords.cov_pmrapmdec_to_pmllpmbb(cov_pmradec, vxvv[:, 0], vxvv[:, 1], degree=True, epoch='J2015') if verbose: print('propagating covariance in pmll pmbb -> vx vy vz') cov_vxyz = bovy_coords.cov_dvrpmllbb_to_vxyz(vxvv[:, 2], dat[cov_keys[3]], dat[cov_keys[4]], pmllpmbb[:, 0], pmllpmbb[:, 1], cov_pmllbb, lb[:, 0], lb[:, 1]) if not return_rphiz: return XYZ, vxyz, cov_vxyz if verbose: print('propagating covariance in vx vy vz -> vR vT vz') cov_galcencyl = bovy_coords.cov_vxyz_to_galcencyl(cov_vxyz, Rpz[:, 1], Xsun=1., Zsun=zo / ro) return XYZ, vxyz, cov_vxyz, Rpz, vRvTvz, cov_galcencyl if not return_rphiz: return XYZ, vxyz return XYZ, vxyz, Rpz, vRvTvz