def deltac_vs_time(u0, tE, dt_max, t0, t_obs, t_obs_prop=None, title=''): """ u0 : dim'less impact parameter tE : in years t0 : str, in YYYY-MM-DD format t_obs : list of dates in str YYYY-MM-DD format. dt_max : maximum time after photometric peak """ t0_strp = dt.strptime(t0, '%Y-%m-%d') t0_dec = dtUtil.toYearFraction(t0_strp) t_arr = np.linspace(t0_dec - 0.1, t0_dec + dt_max, 200) if title=='MB19284': t_arr = np.linspace(t0_dec - 1, t0_dec + dt_max, 200) # Turn the epoch YYYY-MM-DD into a decimal. t_obs_dec = np.zeros(len(t_obs)) for idx, tt in enumerate(t_obs): t_strp = dt.strptime(tt, '%Y-%m-%d') t_dec = dtUtil.toYearFraction(t_strp) t_obs_dec[idx] = t_dec if t_obs_prop is not None: # Turn the epoch YYYY-MM-DD into a decimal. t_obs_prop_dec = np.zeros(len(t_obs_prop)) for idx, tt in enumerate(t_obs_prop): t_strp = dt.strptime(tt, '%Y-%m-%d') t_dec = dtUtil.toYearFraction(t_strp) t_obs_prop_dec[idx] = t_dec u = np.sqrt(u0**2 + ((t_arr - t0_dec)/tE)**2) deltac = u/(u**2 + 2) fig, ax = plt.subplots() ax.plot(t_arr, deltac) ax.set_xlabel('Time (Year)') ax.set_ylabel(r'$\delta_c$/$\theta_E$') for obs in t_obs_dec: ax.axvline(x = obs, color='black') ax.axvline(x = 0, color='black', label='Completed') if t_obs_prop is not None: for obs in t_obs_prop_dec: ax.axvline(x = obs, color='red', ls=':') ax.axvline(x = 0, color='red', ls=':', label='Proposed') ax.set_xlim(t_arr[0], t_arr[-1]) ax.legend() ax.set_ylim(bottom=0) ax.set_title(title) plt.savefig(title + '_deltac_vs_time.png') plt.show() return
def calc_mean_year(fitsFiles, verbose=False): """ Calculate the average decimal year for a list of HST fits files. An example call is: year = calc_mean_year(glob.glob('*_flt.fits') You can print out the individual years in verbose mode: year = calc_mean_year(glob.glob('*_flt.fits', verbose=True) """ numObs = 0 meanYear = 0.0 nfiles = len(fitsFiles) for ii in range(len(fitsFiles)): hdr = pyfits.getheader(fitsFiles[ii]) date = hdr['DATE-OBS'] time = hdr['TIME-OBS'] dateObj = dt.strptime(date + ' ' + time, '%Y-%m-%d %H:%M:%S') year = dtUtil.toYearFraction(dateObj) meanYear += year if verbose: print('{0:12s} {1:12s} {2:8.3f} {3}'.format( date, time, year, fitsFiles[ii])) meanYear /= nfiles if verbose: print('*** AVERAGE YEAR = {0:8.3f} ***'.format(meanYear)) return meanYear
def calc_mean_year(fitsFiles, verbose=False): """ Calculate the average decimal year for a list of HST fits files. An example call is: year = calc_mean_year(glob.glob('*_flt.fits') You can print out the individual years in verbose mode: year = calc_mean_year(glob.glob('*_flt.fits', verbose=True) """ numObs = 0 meanYear = 0.0 nfiles = len(fitsFiles) for ii in range(len(fitsFiles)): hdr = pyfits.getheader(fitsFiles[ii]) date = hdr['DATE-OBS'] time = hdr['TIME-OBS'] dateObj = dt.strptime(date + ' ' + time, '%Y-%m-%d %H:%M:%S') year = dtUtil.toYearFraction(dateObj) meanYear += year if verbose: print('{0:12s} {1:12s} {2:8.3f} {3}'.format(date, time, year, fitsFiles[ii])) meanYear /= nfiles if verbose: print('*** AVERAGE YEAR = {0:8.3f} ***'.format(meanYear)) return meanYear
def deltac_vs_time_BH15_targets(target, t_obs_prop=None, dtmax=None): """ target : 'ob120169', 'ob140613', 'ob150029', 'ob150211' """ target_name = copy.deepcopy(target) target_name = target_name.replace('OB', 'ob') print(target_name) mod_fit, data = lu_2019_lens.get_data_and_fitter(tdir[target_name]) mod_all = mod_fit.get_best_fit_modes_model(def_best = 'maxL') mod = mod_all[0] # Sample time tmax = np.max(np.append(data['t_phot1'], data['t_phot2'])) + 90.0 if dtmax is not None: tmax += dtmax t_mod_ast = np.arange(data['t_ast'].min() - 180.0, tmax, 2) t_mod_pho = np.arange(data['t_phot1'].min(), tmax, 2) # Get the linear motion curves for the source (includes parallax) p_unlens_mod = mod.get_astrometry_unlensed(t_mod_ast) p_unlens_mod_at_ast = mod.get_astrometry_unlensed(data['t_ast']) # Get the lensed motion curves for the source p_lens_mod = mod.get_astrometry(t_mod_ast) p_lens_mod_at_ast = mod.get_astrometry(data['t_ast']) x = (data['xpos'] - p_unlens_mod_at_ast[:,0]) * -1e3 xe = data['xpos_err'] * 1e3 y = (data['ypos'] - p_unlens_mod_at_ast[:, 1]) * 1e3 ye = data['ypos_err'] * 1e3 r2 = x**2 + y**2 r = np.sqrt(r2) xterm = (x * xe)**2/r2 yterm = (y * ye)**2/r2 re = np.sqrt(xterm + yterm) xmod = (p_lens_mod[:, 0] - p_unlens_mod[:, 0])*-1e3 ymod = (p_lens_mod[:, 1] - p_unlens_mod[:, 1])*1e3 # Convert to decimal dates t_ast_dec = Time(data['t_ast'], format='mjd', scale='utc') t_mod_ast_dec = Time(t_mod_ast, format='mjd', scale='utc') t_ast_dec.format='decimalyear' t_mod_ast_dec.format='decimalyear' t_ast_dec = t_ast_dec.value t_mod_ast_dec = t_mod_ast_dec.value if t_obs_prop is not None: # Turn the epoch YYYY-MM-DD into a decimal. t_obs_prop_dec = np.zeros(len(t_obs_prop)) for idx, tt in enumerate(t_obs_prop): t_strp = dt.strptime(tt, '%Y-%m-%d') t_dec = dtUtil.toYearFraction(t_strp) t_obs_prop_dec[idx] = t_dec plt.figure(1) plt.clf() plt.errorbar(t_ast_dec, x, yerr=xe, fmt='k.', alpha=1, zorder = 1000, label='Data') plt.scatter(t_mod_ast_dec, xmod, s = 1) plt.title(target) plt.xlabel('Time (Year)') plt.ylabel('$\delta$RA (mas)') if t_obs_prop is not None: for obs in t_obs_prop_dec: plt.axvline(x = obs, color='red', ls=':') plt.axvline(x = 0, color='red', ls=':', label='Proposed') plt.xlim(t_mod_ast_dec.min() - 0.1, t_mod_ast_dec.max() + 0.1) plt.axhline(y=0, color='black', alpha=0.5) plt.legend(loc=1) plt.title(target) plt.savefig(target + '_deltac_RA_vs_time.png') plt.show() plt.figure(2) plt.clf() plt.errorbar(t_ast_dec, y, yerr=ye, fmt='k.', alpha=1, zorder = 1000, label='Data') plt.scatter(t_mod_ast_dec, ymod, s = 1) plt.title(target) plt.xlabel('Time (Year)') plt.ylabel('$\delta$Dec (mas)') if t_obs_prop is not None: for obs in t_obs_prop_dec: plt.axvline(x = obs, color='red', ls=':') plt.axvline(x = 0, color='red', ls=':', label='Proposed') plt.xlim(t_mod_ast_dec.min() - 0.1, t_mod_ast_dec.max() + 0.1) plt.axhline(y=0, color='black', alpha=0.5) plt.legend(loc=1) plt.title(target) plt.savefig(target + '_deltac_Dec_vs_time.png') plt.show() plt.figure(3) plt.clf() plt.errorbar(t_ast_dec, r, yerr=re, fmt='k.', alpha=1, zorder = 1000, label='Data') plt.scatter(t_mod_ast_dec, np.sqrt(xmod**2 + ymod**2), s = 1) plt.xlabel('Time (Year)') plt.ylabel('$\delta_c$ (mas)') if t_obs_prop is not None: for obs in t_obs_prop_dec: plt.axvline(x = obs, color='red', ls=':') plt.axvline(x = 0, color='red', ls=':', label='Proposed') plt.xlim(t_mod_ast_dec.min() - 0.1, t_mod_ast_dec.max() + 0.1) plt.gca().set_ylim(bottom=0) plt.axhline(y=0.15, color='gray', ls='--') plt.legend(loc=1) plt.title(target) plt.savefig(target + '_deltac_vs_time.png') plt.show()
def ob110462_ast_v_time(): target = 'OB110462' target_name = 'ob110462' t_obs_prop = ['2021-04-01'] # Get the model mod_fit, data = lu_2019_lens.get_data_and_fitter(tdir[target_name]) mod_all = mod_fit.get_best_fit_modes_model(def_best='maxL') mod = mod_all[0] # Sample N random draws from the posterior ndraw = 100 res = mod_fit.load_mnest_results() # Indices of the posterior we want pdx = np.random.choice(len(res), ndraw, replace=True, p=res['weights']) # Sample time tmax = np.max(np.append(data['t_phot1'], data['t_phot2'])) + 90.0 tmax += 2500 t_mod_ast = np.arange(data['t_ast'].min() - 180.0, tmax, 0.1) t_mod_pho = np.arange(data['t_phot1'].min(), tmax, 5) days_per_year = 365.25 dt_mod_ast = (t_mod_ast - mod.t0) / days_per_year dt_data_ast = (data['t_ast'] - mod.t0) / days_per_year # Get the linear motion curves for the source (NO parallax) p_unlens_mod = mod.xS0 + np.outer(dt_mod_ast, mod.muS) * 1e-3 p_unlens_mod_at_ast = mod.xS0 + np.outer(dt_data_ast, mod.muS) * 1e-3 # Get the lensed motion curves for the source p_lens_mod = mod.get_astrometry(t_mod_ast) p_lens_mod_at_ast = mod.get_astrometry(data['t_ast']) x = (data['xpos'] - p_unlens_mod_at_ast[:, 0]) * -1e3 xe = data['xpos_err'] * 1e3 y = (data['ypos'] - p_unlens_mod_at_ast[:, 1]) * 1e3 ye = data['ypos_err'] * 1e3 xmod = (p_lens_mod[:, 0] - p_unlens_mod[:, 0]) * -1e3 ymod = (p_lens_mod[:, 1] - p_unlens_mod[:, 1]) * 1e3 # Convert to decimal dates t_ast_dec = Time(data['t_ast'], format='mjd', scale='utc') t_mod_ast_dec = Time(t_mod_ast, format='mjd', scale='utc') t_ast_dec.format = 'decimalyear' t_mod_ast_dec.format = 'decimalyear' t_ast_dec = t_ast_dec.value t_mod_ast_dec = t_mod_ast_dec.value if t_obs_prop is not None: # Turn the epoch YYYY-MM-DD into a decimal. t_obs_prop_dec = np.zeros(len(t_obs_prop)) for idx, tt in enumerate(t_obs_prop): t_strp = dt.strptime(tt, '%Y-%m-%d') t_dec = dtUtil.toYearFraction(t_strp) t_obs_prop_dec[idx] = t_dec ### # X VS TIME ### plt.figure(1) plt.clf() plt.errorbar(t_ast_dec, x, yerr=xe, fmt='r.', alpha=1, zorder=1000, label='Data') plt.scatter(t_mod_ast_dec, xmod, s=0.1, color='black') plt.title(target) plt.xlabel('Time (Year)') plt.ylabel(r'$\Delta \alpha^*$ (mas)') for ii in range(len(pdx)): # Plot the posterior draws pdraw = mod_fit.get_model(res[ii]) # Get the lensed motion curves for the source p_lens_pdraw = pdraw.get_astrometry(t_mod_ast) p_lens_pdraw_at_ast = pdraw.get_astrometry(data['t_ast']) xpdraw = (p_lens_pdraw[:, 0] - p_unlens_mod[:, 0]) * -1e3 ypdraw = (p_lens_pdraw[:, 1] - p_unlens_mod[:, 1]) * 1e3 plt.scatter(t_mod_ast_dec, xpdraw, s=0.01, alpha=0.02, color='lightgray') plt.xticks([2010, 2013, 2016, 2019, 2022]) plt.axvline(x=t_obs_prop_dec, color='red', ls=':') plt.legend(loc=1) plt.title(target) plt.savefig(target + '_deltac_RA_vs_time.png') plt.show() ### # Y VS TIME ### plt.figure(2) plt.clf() plt.errorbar(t_ast_dec, y, yerr=ye, fmt='r.', alpha=1, zorder=1000, label='Data') plt.scatter(t_mod_ast_dec, ymod, s=0.1, color='black') plt.title(target) plt.xlabel('Time (Year)') plt.ylabel('$\Delta \delta$ (mas)') for ii in range(len(pdx)): # Plot the posterior draws pdraw = mod_fit.get_model(res[ii]) # Get the lensed motion curves for the source p_lens_pdraw = pdraw.get_astrometry(t_mod_ast) p_lens_pdraw_at_ast = pdraw.get_astrometry(data['t_ast']) xpdraw = (p_lens_pdraw[:, 0] - p_unlens_mod[:, 0]) * -1e3 ypdraw = (p_lens_pdraw[:, 1] - p_unlens_mod[:, 1]) * 1e3 plt.scatter(t_mod_ast_dec, ypdraw, s=0.01, alpha=0.02, color='lightgray') plt.xticks([2010, 2013, 2016, 2019, 2022]) plt.axvline(x=t_obs_prop_dec, color='red', ls=':') plt.legend(loc=1) plt.title(target) plt.savefig(target + '_deltac_Dec_vs_time.png') plt.show()