def simplemax_distance(params, dt=1): t = np.arange(params['t0'] - 200, params['t0'] + 200, dt) return np.max( np.abs( np.max( np.abs( microlens_simple(t, **params) - microlens_parallax(t, **params)))))
def update_plot(xk, convergence): convergence=0 u0, t0, tE = xk global curr_max global i i+=1 axs[1].set_title(str(i)) pdif1.set_ydata(np.abs((microlens_parallax(t, 19, 0, p1['u0'], p1['t0'], p1['tE'], p1['delta_u'],p1['theta']) - microlens_simple(t, 19., 0., u0, t0, tE, 0., 0.)))) ppar1.set_ydata(-(microlens_parallax(t, 19, 0, p1['u0'], p1['t0'], p1['tE'], p1['delta_u'], p1['theta']))) pnop1.set_ydata(-(microlens_simple(t, 19, 0, u0, t0, tE, p1['delta_u'], p1['theta']))) l1.set_xdata(t0 - 6*tE) l2.set_xdata(t0 + 6*tE) plt.pause(0.000001) hl2.set_ydata(-convergence) if convergence>curr_max: curr_max = convergence hl.set_ydata(-convergence) axs[1].relim() axs[1].autoscale_view() fig.canvas.draw()
def fastfit_simplemax_distance(params, init_dt=0.5): t = np.arange(params['t0'] - 200, params['t0'] + 200, init_dt) init_t = t[(-np.abs( microlens_parallax(t, **params) - microlens_simple(t, **params)) ).argmin()] m = Minuit(absdiff2, t=init_t, t0=params['t0'], u0=params['u0'], tE=params['tE'], delta_u=params['delta_u'], theta=params['theta'], fix_t0=True, fix_u0=True, fix_tE=True, fix_delta_u=True, fix_theta=True, error_t=10, errordef=1, print_level=0) m.migrad() return [m.get_fmin().fval, dict(m.values)]
def curvefit_func(t, u0, t0, tE, pu0, pt0, ptE, pdu, ptheta): return (microlens_parallax(t, 19, 0, pu0, pt0, ptE, pdu, ptheta) - microlens_simple(t, 19., 0., u0, t0, tE, 0., 0.))**2
def max_fitter(t, u0, t0, tE, pu0, pt0, ptE, pdu, ptheta): return -np.abs((microlens_parallax(t, 19, 0, pu0, pt0, ptE, pdu, ptheta) - microlens_simple(t, 19., 0., u0, t0, tE, 0., 0.)))
def drydiff(t, u0, t0, tE, pu0, pt0, ptE, pdu, ptheta): return microlens_parallax(t, 19, 0, pu0, pt0, ptE, pdu, ptheta) - microlens_simple(t, 19., 0., u0, t0, tE, 0., 0.)
def max_fitter(t): t = np.array([t]) return -np.abs((microlens_parallax(t, 19, 0, p1['u0'], p1['t0'], p1['tE'], p1['delta_u'], p1['theta']) - microlens_simple(t, 19., 0., u0, t0, tE, 0., 0.)))
print(len(df)) print(df.idx.nunique()) tmin = 48928 tmax = 52697 # df = df[(df.mass == 30) & (df.fitted_u0<2.0)] p2 = df.sort_values(by='distance', ascending=False).iloc[1000].to_dict() # p1 = df.iloc[np.random.randint(0, len(df))].to_dict() print(p2) p2['blend']=0. p2['mag']=19. p1 = {key: p2[key] for key in ['mag', 'blend', 'u0', 'tE', 't0', 'theta', 'delta_u']} t = np.arange(tmin, tmax, 0.5) cnopa = microlens_simple(t, **p1) cpara = microlens_parallax(t, **p1) fig, axs = plt.subplots(ncols=1, nrows=2, sharex='col') pdif1, = axs[1].plot(t, np.abs((microlens_parallax(t, 19, 0, p1['u0'], p1['t0'], p1['tE'], p1['delta_u'],p1['theta']) - microlens_simple(t, 19., 0., p1['u0'], p1['t0'], p1['tE'], 0., 0.)))) ppar1, = axs[0].plot(t, -(microlens_parallax(t, 19, 0, p1['u0'], p1['t0'], p1['tE'], p1['delta_u'], p1['theta']))) pnop1, = axs[0].plot(t, -(microlens_simple(t, 19, 0, p1['u0'], p1['t0'], p1['tE'], p1['delta_u'], p1['theta']))) axs[0].plot(t, -(microlens_simple(t, 19, 0, p1['u0'], p1['t0'], p1['tE'], p1['delta_u'], p1['theta'])), ls='--') hl = axs[1].axhline(0, color='black', linewidth=0.5) hl2 = axs[1].axhline(0, color='red', linewidth=0.5) l1 = axs[1].axvline(tmin, color='red', linewidth=0.5) l2 = axs[1].axvline(tmax, color='red', linewidth=0.5) pts, = axs[1].plot([], [], ls='', marker='+') # plt.xlim(51500, 52500) curr_max=-np.inf i=0
def absdiff2(t, u0, t0, tE, delta_u, theta): t = np.array([t]) return -np.abs((microlens_parallax(t, 19, 0, u0, t0, tE, delta_u, theta) - microlens_simple(t, 19., 0., u0, t0, tE, 0., 0.)))
def absdiff_dict(t, params): return -np.abs( (microlens_parallax(t, 19, 0, params['u0'], params['t0'], params['tE'], params['delta_u'], params['theta']) - microlens_simple(t, 19., 0., params['u0'], params['t0'], params['tE'], 0., 0.)))
def fitter_func(params): u0, t0, tE = params return np.max( np.abs( (cpara - microlens_simple(time_range, 19., 0., u0, t0, tE, 0., 0.))))
def distance1(t, params): return np.max( np.abs( microlens_simple(t, **params) - microlens_parallax(t, **params)))