def _calc_weight_reg(x, y, weights): """Apply a linear regression (IDL function) to fit the hole phase and error.""" reg = regress_noc(x, y, weights) sig = cov2cor(reg.cov)[1] hole_ph = reg.coeff hole_ph_err = sig * np.sqrt(reg.MSE) return hole_ph, hole_ph_err
def _normalize_all_obs( bs_quantities, v2_quantities, cvis_arr, cp_cov, bs_v2_cov, fluxes, index_mask, infos, expert_plot=False, save=False, ): """Normalize all observables by the appropriate factor proportional to the averaged fluxes and the number of holes.""" bs_arr = bs_quantities["bs_arr"] v2_arr = v2_quantities["v2_arr"] v2 = v2_quantities["v2"] v2_cov = v2_quantities["v2_cov"] avar = v2_quantities["avar"] err_avar = v2_quantities["err_avar"] bs = bs_quantities["bs"] bs_cov = bs_quantities["bs_cov"] bs_var = bs_quantities["bs_var"] n_holes = index_mask.n_holes bs_arr_norm = bs_arr / np.mean(fluxes ** 3) * n_holes ** 3 v2_arr_norm = v2_arr / np.mean(fluxes ** 2) * n_holes ** 2 cvis_arr_norm = cvis_arr / np.mean(fluxes) * n_holes v2_norm = (v2 / np.mean(fluxes ** 2)) * n_holes ** 2 v2_cov_norm = (v2_cov / np.mean(fluxes ** 4)) * n_holes ** 4 bs_norm = bs / np.mean(fluxes ** 3) * n_holes ** 3 avar_norm = avar / np.mean(fluxes ** 4) * n_holes ** 4 err_avar_norm = err_avar / np.mean(fluxes ** 4) * n_holes ** 4 try: cp_cov_norm = cp_cov / np.mean(fluxes ** 6) * n_holes ** 6 except TypeError: cp_cov_norm = None bs_cov_norm = bs_cov / np.mean(fluxes ** 6) * n_holes ** 6 bs_v2_cov_norm = np.real(bs_v2_cov / np.mean(fluxes ** 5) * n_holes ** 5) bs_var_norm = bs_var / np.mean(fluxes ** 6) * n_holes ** 6 if expert_plot: plt.figure(figsize=(12, 6)) plt.title("DIAGNOSTIC PLOTS - V2 - %s" % infos.target) plt.plot(v2_arr_norm[0], color="grey", alpha=0.2, label="V$^2$ dispersion") plt.plot(v2_arr_norm.T, color="grey", alpha=0.2) plt.plot(v2_norm, color="crimson", label="Raw V$^2$") plt.grid(alpha=0.2) plt.legend() plt.xlabel("# baselines") plt.ylabel("Raw visibilities") plt.tight_layout() # We compute the correlation matrix (to be used lated) v2_cor = cov2cor(v2_cov)[0] norm_quantities = { "bs_arr": bs_arr_norm, "v2_arr": v2_arr_norm, "cvis_arr": cvis_arr_norm, "bs": bs_norm, "v2_cov": v2_cov_norm, "bs_cov": bs_cov_norm, "avar": avar_norm, "err_avar": err_avar_norm, "cp_cov": cp_cov_norm, "bs_var": bs_var_norm, "bs_v2_cov": bs_v2_cov_norm, "v2_cor": v2_cor, } return v2_norm, norm_quantities
def _normalize_all_obs(bs_quantities, v2_quantities, cvis_arr, cp_cov, bs_v2_cov, fluxes, index_mask, infos, expert_plot=False): """ Normalize all observables by the appropriate factor proportional to the averaged fluxes and the number of holes.""" bs_arr = bs_quantities['bs_arr'] v2_arr = v2_quantities['v2_arr'] v2 = v2_quantities['v2'] v2_cov = v2_quantities['v2_cov'] avar = v2_quantities['avar'] err_avar = v2_quantities['err_avar'] bs = bs_quantities['bs'] bs_cov = bs_quantities['bs_cov'] bs_var = bs_quantities['bs_var'] n_holes = index_mask.n_holes bs_arr_norm = bs_arr / np.mean(fluxes ** 3) * n_holes ** 3 v2_arr_norm = v2_arr / np.mean(fluxes ** 2) * n_holes ** 2 cvis_arr_norm = cvis_arr / np.mean(fluxes) * n_holes v2_norm = (v2 / np.mean(fluxes ** 2)) * n_holes ** 2 v2_cov_norm = (v2_cov / np.mean(fluxes ** 4)) * n_holes ** 4 bs_norm = bs / np.mean(fluxes ** 3) * n_holes ** 3 avar_norm = avar / np.mean(fluxes ** 4) * n_holes ** 4 err_avar_norm = err_avar / np.mean(fluxes ** 4) * n_holes ** 4 try: cp_cov_norm = cp_cov / np.mean(fluxes ** 6) * n_holes ** 6 except TypeError: cp_cov_norm = None bs_cov_norm = bs_cov / np.mean(fluxes ** 6) * n_holes ** 6 bs_v2_cov_norm = np.real(bs_v2_cov / np.mean(fluxes ** 5) * n_holes ** 5) bs_var_norm = bs_var / np.mean(fluxes ** 6) * n_holes ** 6 if expert_plot: plt.figure(figsize=(5, 4)) plt.title('DIAGNOSTIC PLOTS - V2 - %s' % infos.target) plt.plot(v2_arr_norm[0], color='grey', alpha=.2, label='V$^2$ dispersion') plt.plot(v2_arr_norm.T, color='grey', alpha=.2) plt.plot(v2_norm, color='crimson', label='Raw V$^2$') plt.grid(alpha=.2) plt.legend() plt.xlabel('# baselines') plt.ylabel('Raw visibilities') plt.tight_layout() # We compute the correlation matrix (to be used lated) v2_cor = cov2cor(v2_cov)[0] norm_quantities = {'bs_arr': bs_arr_norm, 'v2_arr': v2_arr_norm, 'cvis_arr': cvis_arr_norm, 'bs': bs_norm, 'v2_cov': v2_cov_norm, 'bs_cov': bs_cov_norm, 'avar': avar_norm, 'err_avar': err_avar_norm, 'cp_cov': cp_cov_norm, 'bs_var': bs_var_norm, 'bs_v2_cov': bs_v2_cov_norm, 'v2_cor': v2_cor } return v2_norm, norm_quantities