def __call__(self, params, vector): def _getpar(key): return synth_params[vector.indices['{}{}'.format(key, self.planet_num)]][0] synth_params = vector.params.basis.v_to_synth(vector) tp = synth_params[-4+(5*self.planet_num)][0] per = synth_params[-5+(5*self.planet_num)][0] ecc = synth_params[-3+(5*self.planet_num)][0] omega = synth_params[-2+(5*self.planet_num)][0] ts = orbit.timeperi_to_timetrans(tp, per, ecc, omega, secondary=True) ts_phase = utils.t_to_phase_vector(vector, ts, self.planet_num) pts = utils.t_to_phase_vector(vector, self.ts, self.planet_num) epts = self.ts_err / per penalty = -0.5 * ((ts_phase - pts) / epts)**2 - 0.5*np.log((epts**2)*2.*np.pi) return penalty
def __call__(self, params): def _getpar(key): return synth_params['{}{}'.format(key, self.planet_num)].value synth_params = params.basis.to_synth(params) tp = _getpar('tp') per = _getpar('per') ecc = _getpar('e') omega = _getpar('w') ts = orbit.timeperi_to_timetrans(tp, per, ecc, omega, secondary=True) ts_phase = utils.t_to_phase(synth_params, ts, self.planet_num) pts = utils.t_to_phase(synth_params, self.ts, self.planet_num) epts = self.ts_err / per penalty = -0.5 * ((ts_phase - pts) / epts)**2 return penalty
def from_synth(self, params_in, newbasis, **kwargs): """Convert from synth basis into another basis Convert instance of Parameters with parameters of a given basis into the synth basis Args: params_in (radvel.Parameters or pandas.DataFrame): radvel.Parameters object or pandas.Dataframe containing orbital parameters expressed in current basis newbasis (string): string corresponding to basis to switch into keep (Optional[bool]): keep the parameters expressed in the old basis, else remove them from the output dictionary/DataFrame Returns: dict or dataframe with the parameters converted into the new basis """ if newbasis not in BASIS_NAMES: print("{} not valid basis".format(newbasis)) _print_valid_basis() return None if isinstance(params_in, pd.core.frame.DataFrame): # Output by emcee params_out = params_in.copy() else: params_out = _copy_params(params_in) for num_planet in range(1, 1 + self.num_planets): def _getpar(key): if isinstance(params_in, pd.core.frame.DataFrame): return params_in['{}{}'.format(key, num_planet)] else: return params_in['{}{}'.format(key, num_planet)].value def _setpar(key, new_value): key_name = '{}{}'.format(key, num_planet) if isinstance(params_in, pd.core.frame.DataFrame): params_out[key_name] = new_value else: if key_name in params_in: local_vary = params_in[key_name].vary local_mcmcscale = params_in[key_name].mcmcscale else: local_vary = True local_mcmcscale = None params_out[key_name] = radvel.model.Parameter( value=new_value, vary=local_vary, mcmcscale=local_mcmcscale) def _delpar(key): if isinstance(params_in, OrderedDict): del params_out['{}{}'.format(key, num_planet)] elif isinstance(params_in, pd.core.frame.DataFrame): params_out.drop('{}{}'.format(key, num_planet)) if newbasis == 'per tc e w k': per = _getpar('per') e = _getpar('e') w = _getpar('w') tp = _getpar('tp') _setpar('tc', timeperi_to_timetrans(tp, per, e, w)) _setpar('w', w) if not kwargs.get('keep', True): _delpar('tp') if newbasis == 'per tc secosw sesinw logk': per = _getpar('per') e = _getpar('e') w = _getpar('w') k = _getpar('k') try: tp = _getpar('tp') except KeyError: tc = _getpar('tc') tp = timetrans_to_timeperi(tc, per, e, w) _setpar('tp', tp) _setpar('secosw', np.sqrt(e) * np.cos(w)) _setpar('sesinw', np.sqrt(e) * np.sin(w)) _setpar('logk', np.log(k)) _setpar('tc', timeperi_to_timetrans(tp, per, e, w)) if not kwargs.get('keep', True): _delpar('tp') _delpar('e') _delpar('w') _delpar('k') # basis_name = newbasis self.params = newbasis.split() if newbasis == 'per tc secosw sesinw k': per = _getpar('per') e = _getpar('e') w = _getpar('w') k = _getpar('k') try: tp = _getpar('tp') except KeyError: tp = timetrans_to_timeperi(_getpar('tc'), per, e, w) _setpar('tp', tp) _setpar('secosw', np.sqrt(e) * np.cos(w)) _setpar('sesinw', np.sqrt(e) * np.sin(w)) _setpar('k', k) _setpar('tc', timeperi_to_timetrans(tp, per, e, w)) if not kwargs.get('keep', True): _delpar('tp') _delpar('e') _delpar('w') self.name = newbasis self.params = newbasis.split() if newbasis == 'logper tc secosw sesinw k': per = _getpar('per') e = _getpar('e') w = _getpar('w') k = _getpar('k') try: tp = _getpar('tp') except KeyError: tp = timetrans_to_timeperi(_getpar('tc'), per, e, w) _setpar('tp', tp) _setpar('logper', np.log(per)) _setpar('secosw', np.sqrt(e) * np.cos(w)) _setpar('sesinw', np.sqrt(e) * np.sin(w)) _setpar('k', k) _setpar('tc', timeperi_to_timetrans(tp, per, e, w)) if not kwargs.get('keep', True): _delpar('per') _delpar('tp') _delpar('e') _delpar('w') self.name = newbasis self.params = newbasis.split() if newbasis == 'logper tc secosw sesinw logk': per = _getpar('per') e = _getpar('e') w = _getpar('w') k = _getpar('k') try: tp = _getpar('tp') except KeyError: tp = timetrans_to_timeperi(_getpar('tc'), per, e, w) _setpar('tp', tp) _setpar('logper', np.log(per)) _setpar('secosw', np.sqrt(e) * np.cos(w)) _setpar('sesinw', np.sqrt(e) * np.sin(w)) _setpar('logk', np.log(k)) _setpar('tc', timeperi_to_timetrans(tp, per, e, w)) if not kwargs.get('keep', True): _delpar('per') _delpar('tp') _delpar('e') _delpar('w') _delpar('k') self.name = newbasis self.params = newbasis.split() if newbasis == 'per tc ecosw esinw k': per = _getpar('per') e = _getpar('e') w = _getpar('w') k = _getpar('k') try: tp = _getpar('tp') except KeyError: tp = timetrans_to_timeperi(_getpar('tc'), per, e, w) _setpar('tp', tp) _setpar('ecosw', e * np.cos(w)) _setpar('esinw', e * np.sin(w)) _setpar('k', k) _setpar('tc', timeperi_to_timetrans(tp, per, e, w)) if not kwargs.get('keep', True): _delpar('tp') _delpar('e') _delpar('w') self.name = newbasis self.params = newbasis.split() params_out.basis = Basis(newbasis, self.num_planets) return params_out
def v_from_synth(self, params_in, newbasis): if isinstance(params_in, radvel.Vector): vector = params_in.vector else: vector = params_in vector2 = vector.copy() def setvary(indices): for i in indices: vector2[i][1] = True vector2[i][2] = None for num_planet in range(self.num_planets): if newbasis == 'per tc e w k': vector2[1+(5*num_planet)][0] = timeperi_to_timetrans(vector[1+(5*num_planet)][0], vector[(5*num_planet)][0], vector[2+(5*num_planet)][0], vector[3+(5*num_planet)][0]) setvary([3+(5*num_planet)]) if newbasis == 'per tc se w k': vector2[1 + (5 * num_planet)][0] = timeperi_to_timetrans(vector[1 + (5 * num_planet)][0], vector[(5 * num_planet)][0], vector[2 + (5 * num_planet)][0], vector[3 + (5 * num_planet)][0]) vector2[2+(5*num_planet)][0] = np.sqrt(vector[2+(5*num_planet)][0]) setvary([1 + (5 * num_planet),2+(5*num_planet)]) if newbasis == 'per tc secosw sesinw logk': vector2[1 + (5 * num_planet)][0] = timeperi_to_timetrans(vector[1 + (5 * num_planet)][0], vector[(5 * num_planet)][0], vector[2 + (5 * num_planet)][0], vector[3 + (5 * num_planet)][0]) vector2[2+(5*num_planet)][0] = np.sqrt(vector[2+(5*num_planet)][0])*np.cos(vector[3+(5*num_planet)][0]) vector2[3+(5 * num_planet)][0] = np.sqrt(vector[2+(5 * num_planet)][0]) * np.sin(vector[3 + (5 * num_planet)][0]) vector2[4+(5*num_planet)][0] = np.log(vector[4+(5*num_planet)][0]) setvary([1 + (5 * num_planet),2+(5*num_planet),3+(5 * num_planet),4+(5*num_planet)]) if newbasis == 'per tc secosw sesinw k': vector2[1 + (5 * num_planet)][0] = timeperi_to_timetrans(vector[1 + (5 * num_planet)][0], vector[(5 * num_planet)][0], vector[2 + (5 * num_planet)][0], vector[3 + (5 * num_planet)][0]) vector2[2 + (5 * num_planet)][0] = np.sqrt(vector[2 + (5 * num_planet)][0]) * np.cos(vector[3 + (5 * num_planet)][0]) vector2[3 + (5 * num_planet)][0] = np.sqrt(vector[2 + (5 * num_planet)][0]) * np.sin(vector[3 + (5 * num_planet)][0]) setvary([1 + (5 * num_planet), 2+(5 * num_planet), 3 + (5 * num_planet)]) if newbasis == 'logper tc secosw sesinw k': vector2[1 + (5 * num_planet)][0] = timeperi_to_timetrans(vector[1 + (5 * num_planet)][0], vector[(5 * num_planet)][0], vector[2 + (5 * num_planet)][0], vector[3 + (5 * num_planet)][0]) vector2[2 + (5 * num_planet)][0] = np.sqrt(vector[2 + (5 * num_planet)][0]) * np.cos(vector[3 + (5 * num_planet)][0]) vector2[3 + (5 * num_planet)][0] = np.sqrt(vector[2 + (5 * num_planet)][0]) * np.sin(vector[3 + (5 * num_planet)][0]) vector2[(5*num_planet)][0] = np.log(vector[(5*num_planet)][0]) setvary([1 + (5 * num_planet), 2+(5 * num_planet),3 + (5 * num_planet),(5*num_planet)]) if newbasis == 'logper tc secosw sesinw logk': vector2[1 + (5 * num_planet)][0] = timeperi_to_timetrans(vector[1 + (5 * num_planet)][0], vector[(5 * num_planet)][0], vector[2 + (5 * num_planet)][0], vector[3 + (5 * num_planet)][0]) vector2[2 + (5 * num_planet)][0] = np.sqrt(vector[2 + (5 * num_planet)][0]) * np.cos(vector[3 + (5 * num_planet)][0]) vector2[3 + (5 * num_planet)][0] = np.sqrt(vector[2 + (5 * num_planet)][0]) * np.sin(vector[3 + (5 * num_planet)][0]) vector2[(5 * num_planet)][0] = np.log(vector[(5 * num_planet)][0]) vector2[4+(5*num_planet)][0] = np.log(vector[4+(5*num_planet)][0]) setvary([1 + (5 * num_planet), 2+(5 * num_planet), 3+ (5 * num_planet), (5 * num_planet),4+(5*num_planet)]) if newbasis == 'per tc ecosw esinw k': vector2[1 + (5 * num_planet)][0] = timeperi_to_timetrans(vector[1 + (5 * num_planet)][0], vector[(5 * num_planet)][0], vector[2 + (5 * num_planet)][0], vector[3 + (5 * num_planet)][0]) vector2[2+(5*num_planet)][0] = vector[2+(5*num_planet)][0]*np.cos(vector[3+(5*num_planet)][0]) vector2[3+(5 * num_planet)][0] = vector[2+(5 * num_planet)][0] * np.sin(vector[3 + (5 * num_planet)][0]) setvary([1 + (5 * num_planet),2+(5*num_planet),3+(5 * num_planet)]) if newbasis == 'logper tp e w logk': vector2[(5 * num_planet)][0] = np.log(vector[(5 * num_planet)][0]) vector2[4 + (5 * num_planet)][0] = np.log(vector[4 + (5 * num_planet)][0]) setvary([(5 * num_planet),4 + (5 * num_planet)]) return vector2