Пример #1
0
    def getParameters(self, vary_par=0, **kwargs):
        '''---------------------------------------------------------------
		returns mass of the lens and the astrometric parameter including variation in the error 
		Input:
			vary_par == 0: return the original values
			vary_par == 1: returns the original values + a pm,px
						from the typical  distribution if pm + px is unknown 
			vary_par == 2: returns the o
			vary_par == 3: returns random mass from the error distrbution + orignal astrometric parameters
			vary_par == 4: returns random mass from the error distrbution + orignal astrometric 
						parameters + random pm,px from the typical distribution if pm + px is unknown 
			vary_par == 5: returns random pics from the error distrbution 
		---------------------------------------------------------------'''

        #vary the mass
        if vary_par > 2 and self.mass_err > 0:
            mass = np.random.normal(self.mass, self.mass_err)
        else:
            mass = self.mass

        #vary all astrometric parameters
        if vary_par % 3 == 2:
            alpha_r = np.random.normal(
                self.alpha,
                self.alpha_err * unitFac(self.unit[3], self.unit[0]))
            delta_r = np.random.normal(
                self.delta,
                self.delta_err * unitFac(self.unit[3], self.unit[0]))
            if self.pmalpha != 0:
                pmalpha_r = np.random.normal(self.pmalpha, self.pmalpha_err)
                pmdelta_r = np.random.normal(self.pmdelta, self.pmdelta_err)
                px_r = np.random.normal(self.px, self.px_err)
            else:
                #pic from a typical distribution
                pmtot = np.random.normal(5, 3)
                pmdir = np.random.uniform(-np.pi, np.pi)
                pmalpha_r = pmtot * np.cos(pmdir)
                pmdelta_r = pmtot * np.sin(pmdir)
                px_r = np.random.normal(2, 1)
                while px_r <= 0:
                    px_r = np.random.normal(2, 1)
        else:
            alpha_r = self.alpha
            delta_r = self.delta
            if self.pmalpha != 0 or vary_par % 3 == 0:
                #orignal astrometric parameters
                pmalpha_r = self.pmalpha
                pmdelta_r = self.pmdelta
                px_r = self.px
            else:
                #pic from a typical distribution
                pmtot = np.random.normal(5, 3)
                pmdir = np.random.uniform(-np.pi, np.pi)
                pmalpha_r = pmtot * np.cos(pmdir)
                pmdelta_r = pmtot * np.sin(pmdir)
                px_r = np.random.normal(2, 1)
                while px_r <= 0:
                    px_r = np.random.normal(2, 1)
        return [mass, alpha_r, delta_r, pmalpha_r, pmdelta_r, px_r]
Пример #2
0
def Fit_Motion(obs,num_vec, time_vec,obs_error = None, sc_scandir = None, loc_vec = None, unit_obs = 'deg', \
 unit_pos = 'deg', unit_pm = 'mas/yr', unit_px = 'mas', exact = False,**kwargs):
    '''------------------------------------------------------------
		Description: 
	---------------------------------------------------------------
		Input:
	---------------------------------------------------------------
		Output:
	------------------------------------------------------------'''
    obs_error = None
    if obs_error is None:
        obs_error = np.ones(len(num_vec))
    # translate units from and to mas
    unit_pos_fac = unitFac('mas', unit_pos)
    unit_pm_fac = unitFac('mas', unit_pm)
    unit_px_fac = unitFac('mas', unit_px)
    unit_obs_fac = unitFac(unit_obs, 'mas')

    # calculate earth vector

    # calculate sin(ra),cos(ra),sin(dec),cos(dec)
    scsc = sindeg(obs[0,0] * unit_obs_fac / 3.6e6) , cosdeg(obs[0,0] * unit_obs_fac / 3.6e6),\
      sindeg(obs[0,1] * unit_obs_fac / 3.6e6) , cosdeg(obs[0,1] * unit_obs_fac / 3.6e6)
    if loc_vec is None:
        earth = getSun(t_0 + time_vec)
        loc_vec = np.stack([(scsc[0] * earth[0] - scsc[1] *  earth[1])/ max(scsc[3], 1e-6),\
         scsc[1] * scsc[2] *  earth[0] + scsc[0] * scsc[2] *  earth[1] - scsc[3] *  earth[2]]).T
    #switch to relative coordinates by subtracting ra0,dec0 (first observation)

    radec_0 = obs[0, :]
    obs_rel = (obs - radec_0.reshape(-1, 2)) * unit_obs_fac

    #reorder numtimeloc_vec
    ntl_vec = [num_vec, time_vec, loc_vec]

    #setup starting value for par and par0
    #par = [0.5, ra1,dec1, 0,0,0]
    par = np.zeros(max(num_vec + 1) * 5)
    par0 = np.zeros(max(num_vec + 1) * 5)
    par0[0::5] = radec_0[0] * unit_obs_fac
    par0[1::5] = radec_0[1] * unit_obs_fac
    q = [np.where(num_vec == i)[0] for i in range(max(num_vec + 1))]
    index_0 = [i[0] if len(i) > 0 else -1 for i in q]
    par[0::5] = obs_rel[index_0, 0]
    par[1::5] = obs_rel[index_0, 1]
    qq = np.array([False if len(i) > 0 else True for i in q])

    #fitting residual function
    if sc_scandir is None:
        par_res = least_squares(FitFunction_Motion,par, xtol = 3e-16 ,jac = Jacobian_Motion, \
           args = (ntl_vec, obs_rel, obs_error, scsc[3]))

    else:
        par_res = least_squares(FitFunction_Motion_Scandir,par, xtol = 3e-16 ,jac = Jacobian_Motion_Scandir, \
           args = (ntl_vec, sc_scandir, obs_rel, obs_error, scsc[3]))

    #return parameter in requested units
    par_res.x[0::5] = (par_res.x[0::5] + par0[0::5]) * unit_pos_fac
    par_res.x[1::5] = (par_res.x[1::5] + par0[1::5]) * unit_pos_fac
    par_res.x[2::5] = (par_res.x[2::5] + par0[2::5]) * unit_pm_fac
    par_res.x[3::5] = (par_res.x[3::5] + par0[3::5]) * unit_pm_fac
    par_res.x[4::5] = (par_res.x[4::5] + par0[4::5]) * unit_px_fac
    if qq.any():
        par_res.x[1 + 5 * np.where(qq)[0]] = None
        par_res.x[2 + 5 * np.where(qq)[0]] = None
        par_res.x[3 + 5 * np.where(qq)[0]] = None
        par_res.x[4 + 5 * np.where(qq)[0]] = None
        par_res.x[5 + 5 * np.where(qq)[0]] = None
    return par_res
Пример #3
0
def stars_position_micro(par,num_vec,time_vec,loc_vec = None,scsc = None, \
   out_unit = 'mas',unit_pos = 'deg', unit_pm = 'mas/yr' , unit_px = 'mas', \
   ml = True, pml = False, exact = True, **kwargs):
    '''----------------------------------------------------------------
	Calculate the postion of a list of stars at given times. 
	-------------------------------------------------------------------
		Input:
			par: 	  parameter of the lens and surcees [mass, ra,dec,pmra,pmdec,px, ra_source,dec_source,...]
					  or list of parameters [[mass, ra,dec,pmra,pmdec,px, ra_source,dec_source,...],...]
					  (for varying the input parameters)
			num_vec:  identifier does the observation coresponds to the lens or source
			time_vec: list of dates for the observvation
			loc_vec:  precalculate position of Gaia respect to the sun
			scsc: pre calculate sin(ra),cos(ra), sin(dec), cos(dec)
			out_unit: unit of the output
			unit_pos: unit of the position
			unit_pm:  unit of the propermotion
			unit_px:  unit of the parallax
			ml:		  Include microlensing in the calculation
			pml:	  Calculate the photometric magnification
			exact: 	  use aproximation or exact formular for pos_+  	
	-------------------------------------------------------------------
		Output:
			radec_obs:  array or matrix of [ra, dec] for each time  
			A: 			if pml: magnification for each of the observations.
	----------------------------------------------------------------'''

    #----------------------------------------------------------------
    #calculate scalfactors
    unit_pos_fac = unitFac(unit_pos, 'mas')
    unit_pm_fac = unitFac(unit_pm, 'mas')
    unit_px_fac = unitFac(unit_px, 'mas')
    unit_out_fac = unitFac('mas', out_unit)
    #----------------------------------------------------------------

    if isinstance(
            par[0],
        (int, float)):  #check if only one set of parameters is given:
        #----------------------------------------------------------------
        # reorder parameters
        par = np.array(par)
        mass = par[0]

        if len(par
               ) % 5 == 1:  # check if mass is given in the list of parameters
            astrometry = par[1:].reshape((-1, 5))
        else:
            astrometry = par.reshape((-1, 5))

        radec = astrometry[:, 0:2] * unit_pos_fac
        pm_radec = astrometry[:, 2:4] * unit_pm_fac
        px = astrometry[:, 4] * unit_px_fac
        #----------------------------------------------------------------

        #----------------------------------------------------------------
        #calculate scsc and loc_vec, if not given
        if scsc is None:
            scsc = sinmas(radec[0,0]*unit_pos_fac),cosmas(radec[0,0]),sinmas(radec[0,1]),\
             min(cosmas(radec[0,1]),1e-16),
        if loc_vec is None:
            earth = getSun(t_0 + time_vec).T
            loc_vec = np.stack([(scsc[0] * earth[:,0] - scsc[1] *  earth[:,1])\
              / max(scsc[3],1e-6),\
              scsc[1] * scsc[2] *  earth[:,0] + scsc[0] * scsc[2]\
              *  earth[:,1] - scsc[3] *  earth[:,2]]).T.reshape(-1,1,2)
        #----------------------------------------------------------------

        #----------------------------------------------------------------
        # reorder parameters  (cont.)
        radec_vec = radec[num_vec]
        pm_vec = pm_radec[num_vec]
        px_vec = px[num_vec].reshape((-1, 1))
        radec_lens_vec = radec[np.zeros(
            len(num_vec), int)]  # position of lens for all epochs  (cont.)
        pm_lens_vec = pm_radec[np.zeros(
            len(num_vec), int)]  # position of lens for all epochs  (cont.)
        px_lens_vec = px[[np.zeros(len(num_vec), int)]].reshape(
            (-1, 1))  # position of lens for all epochs  (cont.)
        T_vec = time_vec.reshape((-1, 1))
        cd = np.array([scsc[3], 1])
        #----------------------------------------------------------------

        #----------------------------------------------------------------
        # calculate unlensed positon:
        radec_cur = radec_vec + pm_vec / cd * T_vec + px_vec * loc_vec
        radec_lens_cur = radec_lens_vec + pm_lens_vec / cd * T_vec + px_lens_vec * loc_vec
        #----------------------------------------------------------------

        #----------------------------------------------------------------
        # calculate shif and Magnification due to microlensing
        A = 1  # default value for the Magnification
        if ml:
            #calculate Einstein radius squared
            ThetaE2 = const_Einsteinradius * const_Einsteinradius * mass * (
                px_lens_vec - px_vec).reshape((-1, 1))

            if exact:
                radec_obs = radec_cur * unit_out_fac + unit_out_fac * (radec_cur-radec_lens_cur) \
                 *(np.sqrt(1/4. + ThetaE2 / np.maximum(
                 np.sum(np.square((radec_cur-radec_lens_cur)* cd),axis = 1),1e-16).reshape((-1,1))) -1 /2.)
            else:
                radec_obs = radec_cur * unit_out_fac + (radec_cur-radec_lens_cur) * ThetaE2 * unit_out_fac \
                 / np.maximum((np.sum(np.square((radec_cur-radec_lens_cur)* cd),\
                 axis = 1).reshape((-1,1))+ 2 * ThetaE2),1e-16)
            if pml:
                dist2 = np.sum(np.square((radec_cur - radec_lens_cur) * cd),
                               axis=1).reshape((-1, 1))
                A = (dist2 + 2 * ThetaE2) / np.sqrt(
                    np.maximum(dist2 * dist2 + 4 * dist2 * ThetaE2, 1e-16))

        else:
            radec_obs = radec_cur * unit_out_fac  #without lensing
        #----------------------------------------------------------------
        if pml:
            return radec_obs, A
        else:
            return radec_obs

    else:  #If a matrix of parameters is given
        #----------------------------------------------------------------
        # reorder parameters
        par = np.array(par)
        mass = par[:, 0]

        if par.shape[1] % 5 == 1:
            astrometry = par[:, 1:].reshape(len(par), -1, 5)
        else:
            astrometry = par.reshape(len(par), -1, 5)

        radec = astrometry[:, :, 0:2] * unit_pos_fac
        pm_radec = astrometry[:, :, 2:4] * unit_pm_fac
        px = astrometry[:, :, 4] * unit_px_fac
        #----------------------------------------------------------------

        #----------------------------------------------------------------
        #calculate scsc and loc_vec, if not given
        if scsc is None:
            scsc = np.vstack([sinmas(radec[:,0,0]*unit_pos_fac),cosmas(radec[:,0,0]), \
              sinmas(radec[:,0,1]),np.minimum(cosmas(radec[:,0,1]),1e-16)]).T
        if loc_vec is None:
            earth = getSun(t_0 + time_vec).T
            loc = np.stack([(scsc[:,0] * earth[:,:,0] - scsc[:,1] *  earth[:,:,1])\
              / np.maximum(scsc[:,3],1e-6),\
              scsc[:,1] * scsc[:,2] *  earth[:,:,0] + scsc[:,0] * scsc[:,2]\
              *  earth[:,:,1] - scsc[:,3] *  earth[:,:,2]]).reshape(len(par),-1,1,2)
        #----------------------------------------------------------------

        #----------------------------------------------------------------
        # reorder parameters  (cont.)
        radec_vec = radec[:, num_vec]
        pm_vec = pm_radec[:, num_vec]
        px_vec = px[:, num_vec].reshape((len(par), -1, 1))
        radec_lens_vec = radec[:, np.zeros(len(num_vec), int)]
        pm_lens_vec = pm_radec[:, np.zeros(len(num_vec), int)]
        px_lens_vec = px[:, [np.zeros(len(num_vec), int)]].reshape(
            (len(par), -1, 1))
        T_vec = np.repeat(time_vec.reshape((1, -1, 1)), len(par), axis=0)
        cd = np.array([scsc[3], 1])
        #----------------------------------------------------------------

        #----------------------------------------------------------------
        # calculate unlensed positon:
        radec_cur = radec_vec + pm_vec / cd * T_vec + px_vec * loc_vec
        radec_lens_cur = radec_lens_vec + pm_lens_vec / cd * T_vec + px_lens_vec * loc_vec
        #----------------------------------------------------------------

        #----------------------------------------------------------------
        # calculate shif and Magnification due to microlensing
        A = 1  # default value for the Magnification
        if ml:
            #calculate Einstein radius squared
            ThetaE2 = const_Einsteinradius*const_Einsteinradius * mass.reshape(-1,1,1)\
                * (px_lens_vec-px_vec).reshape((len(par),-1,1))
            if exact:
                radec_obs = radec_cur * unit_out_fac + unit_out_fac * (radec_cur-radec_lens_cur) \
                 *(np.sqrt(1/4. + ThetaE2 / np.maximum(
                 np.sum(np.square((radec_cur-radec_lens_cur)* cd),axis = 2),1e-16).reshape((len(par),-1,1))) -1 /2.)
            else:

                radec_obs = radec_cur * unit_out_fac + (radec_cur-radec_lens_cur) * ThetaE2 * unit_out_fac \
                 / np.maximum((np.sum(np.square((radec_cur-radec_lens_cur)* cd),\
                 axis = 2).reshape((len(par),-1,1))+ 2 * ThetaE2),1e-16)
            if pml:
                dist2 = np.sum(np.square((radec_cur - radec_lens_cur) * cd),
                               axis=2).reshape((len(par), -1, 1))
                A = (dist2 + 2 * ThetaE2) / np.sqrt(
                    np.maximum(dist2 * dist2 + 4 * dist2 * ThetaE2, 1e-16))
        else:
            radec_obs = radec_cur * unit_out_fac
        #----------------------------------------------------------------
        if pml:
            return radec_obs, A
        else:
            return radec_obs
Пример #4
0
def Fit_Micro(obs, num_vec, time_vec, obs_error = None, sc_scandir = None, loc_vec = None, unit_obs = 'deg', \
 unit_pos = 'deg', unit_pm = 'mas/yr', unit_px = 'mas', plot = False, exact = False, bounds = False, prefit_motion = False,**kwargs):
    '''------------------------------------------------------------
		Description: Fited the stelar motion to de data 
	---------------------------------------------------------------
		Input:
			obs: list of observations
			numvec: identifier of the coresponding star
			time_vec: epoch of the observations
			obs_error: measurement errors for weigting. If none use uniform weights)
			sc_scandir: sin,cos of the position angle of the scan direction. for each observation
				If None 2D residuals are used.
			loc_vec: Location of Gaia. respect to the sun. If None, calculate the position from the epoch
			unit_**: Units of the observation, position, propermotion and parallax
			exact: If False, use the center of light as aproximation
			bounds: Use bounds for the fitting process. 
			prefit_motion: Determine a priors from a fit without microlensing.
	---------------------------------------------------------------
		Output:
			par_res:	leastsquare fit results
						par_res.x = [mass, ra0_Lens, dec0_Lens, pmra_Lens,pmdec_Lens,px_Lens, ra0_Source1,.... ]
	------------------------------------------------------------'''
    if obs_error is None:
        obs_error = np.ones(len(obs))
    # translate units from and to mas
    unit_pos_fac = unitFac('mas', unit_pos)
    unit_pm_fac = unitFac('mas', unit_pm)
    unit_px_fac = unitFac('mas', unit_px)
    unit_obs_fac = unitFac(unit_obs, 'mas')

    # calculate sin(ra),cos(ra),sin(dec),cos(dec)
    scsc = sindeg(obs[0,0] * unit_obs_fac / 3.6e6) , cosdeg(obs[0,0] * unit_obs_fac / 3.6e6),\
      sindeg(obs[0,1] * unit_obs_fac / 3.6e6) , cosdeg(obs[0,1] * unit_obs_fac / 3.6e6)
    # calculate earth vector
    if loc_vec is None:
        earth = getSun(t_0 + time_vec)
        loc_vec = np.stack([(scsc[0] * earth[0] - scsc[1] *  earth[1])/ max(scsc[3], 1e-20),\
         scsc[1] * scsc[2] *  earth[0] + scsc[0] * scsc[2] *  earth[1] - scsc[3] *  earth[2]]).T
    #switch to relative coordinates by subtracting ra0,dec0 (first observation)

    radec_0 = obs[0, :]
    obs_rel = (obs - radec_0.reshape(-1, 2)) * unit_obs_fac

    #reorder numtimeloc_vec
    ntl_vec = [num_vec, time_vec, loc_vec]

    #setup starting value for par and par0
    #par = [0.5, ra1,dec1, 0,0,0]
    if len(np.where(num_vec == 0)[0]) == 0:
        #test source only
        par = np.zeros(max(num_vec + 1) * 5 + 1)
        par0 = np.zeros(max(num_vec + 1) * 5 + 1)
        par0[1::5] = radec_0[0] * unit_obs_fac
        par0[2::5] = radec_0[1] * unit_obs_fac
        par[0] = 0.5
        q = [np.where(num_vec == i)[0] for i in range(max(num_vec + 1))]
        index_0 = [i[0] if len(i) > 0 else -1 for i in q]
        par[1::5] = obs_rel[index_0, 0]
        par[2::5] = obs_rel[index_0, 1]
        par[2] = par[7]
        par[1] = par[6]
        #calculat preset parameters
        if sc_scandir is None:
            par_1 = least_squares(fm.FitFunction_Motion,par[1:], xtol = 3e-8 ,jac = fm.Jacobian_Motion, \
              args = (ntl_vec, obs_rel, obs_error, scsc[3]))
        else:
            par_1 = least_squares(fm.FitFunction_Motion_Scandir,par[1:], xtol = 3e-8 ,jac = fm.Jacobian_Motion_Scandir, \
              args = (ntl_vec, sc_scandir, obs_rel, obs_error, scsc[3]))
        nn = np.where(np.abs(par_1.fun) == max(np.abs(par_1.fun)))[0]
        mm = par_1.fun[nn] * obs_error[nn]
        ThetaE2 = const_Einsteinradius * const_Einsteinradius * 0.5 * 100
        deltaphi = -(ThetaE2 / mm +
                     np.sqrt(max(ThetaE2**2 / mm**2 - 8 * ThetaE2, 0))) / 2
        par[1:3] = obs_rel[nn] + deltaphi * sc_scandir[nn]
        par[5] = 100
        par[6:] = par_1.x[5:]
        qq = np.array([False, False])
    else:
        par = np.zeros(max(num_vec + 1) * 5 + 1)
        par0 = np.zeros(max(num_vec + 1) * 5 + 1)
        par0[1::5] = radec_0[0] * unit_obs_fac
        par0[2::5] = radec_0[1] * unit_obs_fac
        par[0] = 0.5
        if prefit_motion:
            if sc_scandir is None:
                par_res = least_squares(fm.FitFunction_Motion,par[1:], xtol = 3e-8 ,jac = fm.Jacobian_Motion, \
                 args = (ntl_vec, obs_rel, obs_error, scsc[3]))
            else:
                par_res = least_squares(fm.FitFunction_Motion_Scandir,par[1:], xtol = 3e-8 ,jac = fm.Jacobian_Motion_Scandir, \
                 args = (ntl_vec, sc_scandir, obs_rel, obs_error, scsc[3]))
            par0[1:] = par_res.x

        q = [np.where(num_vec == i)[0] for i in range(max(num_vec + 1))]
        index_0 = [i[0] if len(i) > 0 else -1 for i in q]
        par[1::5] = obs_rel[index_0, 0]
        par[2::5] = obs_rel[index_0, 1]
        qq = np.array([False if len(i) > 0 else True for i in q])

    if bounds: bounds = (-np.inf, [1000, *(np.inf * np.ones(len(par) - 1))])
    else: bounds = (-np.inf, np.inf)
    #fitting residual function
    if sc_scandir is None:
        par_res = least_squares(FitFunction_Micro,par, xtol = 3e-16 ,jac = Jacobian_Micro, bounds = bounds, \
           args = (ntl_vec, obs_rel, obs_error, scsc[3], exact))

    else:
        par_res = least_squares(FitFunction_Micro_Scandir,par, xtol = 3e-16 ,jac = Jacobian_Micro_Scandir, \
           bounds = bounds, args = (ntl_vec, sc_scandir, obs_rel, obs_error, scsc[3], exact))
        r = np.random.uniform()
        if False:
            cost = lambda x, i: np.sum(
                FitFunction_Micro_Scandir([
                    *par_res.x[0:i], x, *par_res.x[i + 1:]
                ], ntl_vec, sc_scandir, obs_rel, obs_error, scsc[3], exact)**2)

            xx = np.linspace(-1, 1, 1000)
            sfactor = [1, 1, 1, 0.1, 0.1, 1, 1, 1, 0.1, 0.1, 1]

            y = [
                np.array([cost(x * sfactor[i] + par_res.x[i], i) for x in xx])
                for i in range(11)
            ]
            par_name = [
                'mass, M_sun', 'ra1, mas', 'dec1, mas', 'pmra1, 0.1mas/yr',
                'pmdec1, 0.1mas/yr', 'px1, mas', 'ra2', 'dec2', 'pmra2',
                'pmdec2', 'px2'
            ]
            fig = plt.figure(figsize=(11, 10))
            for i in range(11):
                plt.plot(xx, y[i], label=par_name[i])
            plt.xlabel('delta_par')
            plt.ylim([0, 5 * par_res.cost])
            plt.legend(fontsize=20)
            fig.savefig(imagepath + 'Cost_function_' + str(int(r * 10000)) +
                        '.png')
            plt.close(fig)

            fig = plt.figure(figsize=(11, 10))
            xx = np.linspace(-1000, 1000, 10000)
            xx2 = np.linspace(-999.999, 1000.001, 10000)
            y = [
                np.array([cost(x * sfactor[i] + par_res.x[i], i) for x in xx])
                for i in range(1)
            ]
            y2 = [
                np.array([cost(x * sfactor[i] + par_res.x[i], i) for x in xx2])
                for i in range(1)
            ]
            for i in range(1):
                plt.plot(xx, y[i] - y2[i], label=par_name[i])
            fig.savefig(imagepath + 'Cost_function_' + str(int(r * 10000)) +
                        '_2.png')
            plt.close(fig)

    if plot:
        plotMicro(obs_rel, par_res.x, scsc, styl = '-', linewidth=2, out_unit = 'mas', \
           unit_pos = 'mas', unit_pm = 'mas/yr', unit_px = 'mas')
    #return parameter in requested units

    par_res.x[1::5] = (par_res.x[1::5] + par0[1::5]) * unit_pos_fac
    par_res.x[2::5] = (par_res.x[2::5] + par0[2::5]) * unit_pos_fac
    par_res.x[3::5] = (par_res.x[3::5] + par0[3::5]) * unit_pm_fac
    par_res.x[4::5] = (par_res.x[4::5] + par0[4::5]) * unit_pm_fac
    par_res.x[5::5] = (par_res.x[5::5] + par0[5::5]) * unit_px_fac
    if qq.any():
        par_res.x[1 + 5 * np.where(qq)[0]] = None
        par_res.x[2 + 5 * np.where(qq)[0]] = None
        par_res.x[3 + 5 * np.where(qq)[0]] = None
        par_res.x[4 + 5 * np.where(qq)[0]] = None
        par_res.x[5 + 5 * np.where(qq)[0]] = None
    return par_res
Пример #5
0
    def __init__(self,
                 pos,
                 pos_err,
                 pm,
                 pm_err,
                 px,
                 px_err,
                 Gmag,
                 mass=0,
                 mass_err=0,
                 id=-1,
                 unit_pos='deg',
                 unit_pos_err='mas',
                 unit_pm='mas/yr',
                 unit_px='mas',
                 tca=-1,
                 eta=0):
        '''---------------------------------------------------------------
		initialise the Star
		------------------------------------------------------------------

		Input:
			pos: position vector [ra,dec]
			pos_error: error of the position vector [ra_err,dec_err]
			pm: propermotion vector: [pmra,pmdec]
			pm_err: error of the propermotion vector [ra_err,dec_err]
			px: parallax 
			px_err:  error of the parallax
			Gmag: Magnitude of the Star
			mass: Mass of the lens
			mass_err: error of the mass
			id: source_id
			unit_pos: unit of the given position
			unit_pos_err: unit of the given error of the position
			unit_pm: unit of the given propermotion
			unit_px: unit of the given parallax
			tca:  epoach of the closest approach
			eta: value to store eta 
		---------------------------------------------------------------'''
        self.unit = ['deg', 'mas/yr', 'mas', 'mas']
        self.alpha = pos[0] * unitFac(unit_pos, 'deg')
        self.delta = pos[1] * unitFac(unit_pos, 'deg')
        self.alpha_err = pos_err[0] * unitFac(unit_pos_err, 'mas')
        self.delta_err = pos_err[1] * unitFac(unit_pos_err, 'mas')
        self.pmalpha = pm[0] * unitFac(unit_pm, 'mas/yr')
        self.pmdelta = pm[1] * unitFac(unit_pm, 'mas/yr')
        self.pmalpha_err = pm_err[0] * unitFac(unit_pm, 'mas/yr')
        self.pmdelta_err = pm_err[1] * unitFac(unit_pm, 'mas/yr')
        self.px = px * unitFac(unit_pm, 'mas')
        self.px_err = px_err * unitFac(unit_pm, 'mas')
        self.Gmag = Gmag
        if mass < 0:  # use an random value for m
            self.mass = np.random.uniform(0.07, 1.5)
            self.mass_err = 0.1 * self.mass

        else:
            self.mass = mass
            if mass_err == 0: self.mass_err = 0.1 * mass  # use an 10 % error
            else: self.mass_err = mass_err

        self.id = id
        self.tca = tca
        self.eta = eta
Пример #6
0
 def getPx(self, unit='mas'):
     #returns the parallax
     try:
         return self.px * unitFac('mas', unit)
     except:
         return self.parallax * unitFac('mas', unit)  #old variable name
Пример #7
0
 def getPm(self, unit='mas/yr'):
     #returns the propermotion
     return self.pmalpha * unitFac('mas/yr', unit), self.pmdelta * unitFac(
         'mas/yr', unit)
Пример #8
0
 def getPos(self, unit='deg'):
     #returns the 2015.5 position
     return self.alpha * unitFac('deg', unit), self.delta * unitFac(
         'deg', unit)