for j in range(n_mocks_per_F): # bookkeeping file_suffix = '_F'+str(np.int(np.round(1e3*F_cpd[i]))) + \ 'uJy_'+str(j).zfill(4) # inject a mock CPD into the data vis_cpd = inject_CPD((u, v, vis, wgt), (F_cpd[i], r_cpd[j], az_cpd[j]), incl=incl, PA=PA, offRA=offRA, offDEC=offDEC) # frank modeling of the data + CPD injection sol = FF.fit(u, v, vis_cpd, wgt) # save the frank results save_fit(u, v, vis_cpd, wgt, sol, prefix=target+'_gap'+str(gap_ix)+file_suffix, save_vis_fit=False, save_solution=False) # clean up file outputs os.system('mv '+target+'_gap'+str(gap_ix)+file_suffix + \ '_frank_uv_resid.npz resid_vis/') os.system('mv '+target+'_gap'+str(gap_ix)+file_suffix + \ '_frank_profile_fit.txt mprofiles/') os.system('rm '+target+'_gap'+str(gap_ix)+file_suffix+'_frank*') # record parameter values (F_cpd in uJy, j, r_cpd, az_cpd) with open(target+'_gap'+str(gap_ix)+'_mpars.'+subsuf+'.txt', 'a') as f: f.write('%i %s %.3f %i\n' % \ (np.int(np.round(1e3*F_cpd[i])), str(j).zfill(4), r_cpd[j], az_cpd[j]))
disk.disk[target]['PA'], dRA=disk.disk[target]['dx'], dDec=disk.disk[target]['dy']) # configure the fitting code setup FF = FrankFitter(Rmax=2 * disk.disk[target]['rout'], geometry=geom, N=disk.disk[target]['hyp-Ncoll'], alpha=disk.disk[target]['hyp-alpha'], weights_smooth=disk.disk[target]['hyp-wsmth']) # fit the visibilities sol = FF.fit(u, v, vis, wgt) # save the fit save_fit(u, v, vis, wgt, sol, prefix='fits/' + target) print('....') print('Finished visibility modeling') print('....') if frank_symm: print('....') print('Performing visibility modeling') print('....') # load the visibility data dat = np.load('data/' + target + '_data_symm.vis.npz') u, v, vis, wgt = dat['u'], dat['v'], dat['Vis'], dat['Wgt'] # set the disk viewing geometry geom = FixedGeometry(disk.disk[target]['incl'],
CPD_pars = F_cpd[i], r_cpd, az_cpd[j] dvis_wcpd = inject_CPD(data, CPD_pars, incl=incl, PA=PA, offRA=offRA, offDEC=offDEC) # Frankenstein modeling of the data + CPD injection sol = FF.fit(u, v, dvis_wcpd, wgt) # save the results save_fit(u, v, dvis_wcpd, wgt, sol, prefix=dfile + file_suffix, save_vis_fit=False, save_solution=False) # clean up file outputs os.system('mv ' + dfile + file_suffix + '_frank_uv_resid.npz resid_vis/') os.system('mv ' + dfile + file_suffix + '_frank_profile_fit.txt mprofiles/') #os.system('mv '+dfile+file_suffix+'_frank_uv_fit.npz model_vis/') os.system('rm ' + dfile + file_suffix + '_frank*') # record parameter values (F_cpd in uJy, j, r_cpd, az_cpd) with open(dfile + '_mpars.txt', 'a') as f: f.write('%i %s %.3f %i\n' % \
def output_results(u, v, vis, weights, sol, iteration_diagnostics, model): r""" Save datafiles of fit results; generate and save figures of fit results (see frank.io.save_fit, frank.make_figs.make_full_fig, frank.make_figs.make_quick_fig, frank.make_figs.make_diag_fig) Parameters ---------- u, v : array, unit = :math:`\lambda` u and v coordinates of observations vis : array, unit = Jy Observed visibilities (complex: real + imag * 1j) weights : array, unit = Jy^-2 Weights assigned to observed visibilities, of the form :math:`1 / \sigma^2` sol : _HankelRegressor object Reconstructed profile using Maximum a posteriori power spectrum (see frank.radial_fitters.FrankFitter) iteration_diagnostics : _HankelRegressor object Diagnostics of the fit iteration (see radial_fitters.FrankFitter.fit) model : dict Dictionary containing model parameters the fit uses Returns ------- figs : Matplotlib `.Figure` instance All produced figures, including the GridSpecs axes : Matplotlib `~.axes.Axes` class Axes for each of the produced figures """ logging.info(' Plotting results') figs, axes = [], [] if model['plotting']['quick_plot']: quick_fig, quick_axes = make_figs.make_quick_fig( u, v, vis, weights, sol, model['plotting']['bin_widths'], model['plotting']['dist'], model['plotting']['force_style'], model['input_output']['save_prefix']) figs.append(quick_fig) axes.append(quick_axes) if model['plotting']['full_plot']: full_fig, full_axes = make_figs.make_full_fig( u, v, vis, weights, sol, model['plotting']['bin_widths'], model['plotting']['dist'], model['plotting']['force_style'], model['input_output']['save_prefix']) figs.append(full_fig) axes.append(full_axes) if model['plotting']['diag_plot']: diag_fig, diag_axes, _ = make_figs.make_diag_fig( sol.r, sol.q, iteration_diagnostics, model['plotting']['iter_plot_range'], model['plotting']['force_style'], model['input_output']['save_prefix']) figs.append(diag_fig) axes.append(diag_axes) io.save_fit(u, v, vis, weights, sol, model['input_output']['save_prefix'], model['input_output']['save_solution'], model['input_output']['save_profile_fit'], model['input_output']['save_vis_fit'], model['input_output']['save_uvtables'], model['input_output']['iteration_diag'], iteration_diagnostics, model['input_output']['format']) return figs, axes, model
def output_results(u, v, vis, weights, sol, geom, model, iteration_diagnostics=None): r""" Save datafiles of fit results; generate and save figures of fit results (see frank.io.save_fit, frank.make_figs) Parameters ---------- u, v : array, unit = :math:`\lambda` u and v coordinates of observations vis : array, unit = Jy Observed visibilities (complex: real + imag * 1j) weights : array, unit = Jy^-2 Weights assigned to observed visibilities, of the form :math:`1 / \sigma^2` sol : _HankelRegressor object Reconstructed profile using Maximum a posteriori power spectrum (see frank.radial_fitters.FrankFitter) geom : SourceGeometry object Fitted geometry (see frank.geometry.SourceGeometry) model : dict Dictionary containing model parameters the fit uses iteration_diagnostics : _HankelRegressor object, optional, default=None Diagnostics of the fit iteration (see radial_fitters.FrankFitter.fit) Returns ------- figs : Matplotlib `.Figure` instance All produced figures, including the GridSpecs axes : Matplotlib `~.axes.Axes` class Axes for each of the produced figures """ io.save_fit(u, v, vis, weights, sol, model['input_output']['save_prefix'], model['input_output']['save_solution'], model['input_output']['save_profile_fit'], model['input_output']['save_vis_fit'], model['input_output']['save_uvtables'], model['input_output']['iteration_diag'], iteration_diagnostics, model['input_output']['format'] ) logging.info(' Plotting results') figs, axes = [], [] if model['plotting']['deprojec_plot']: deproj_fig, deproj_axes = make_figs.make_deprojection_fig(u, v, vis, weights, geom, model['plotting']['bin_widths'], model['plotting']['force_style'], model['input_output']['save_prefix'] ) figs.append(deproj_fig) axes.append(deproj_axes) if model['plotting']['quick_plot']: quick_fig, quick_axes = make_figs.make_quick_fig(u, v, vis, weights, sol, model['plotting']['bin_widths'], model['plotting']['distance'], model['plotting']['plot_in_logx'], model['plotting']['force_style'], model['input_output']['save_prefix'], model['plotting']['stretch'], model['plotting']['gamma'], model['plotting']['asinh_a'] ) figs.append(quick_fig) axes.append(quick_axes) if model['plotting']['full_plot']: full_fig, full_axes = make_figs.make_full_fig(u, v, vis, weights, sol, model['plotting']['bin_widths'], model['hyperparameters']['alpha'], model['hyperparameters']['wsmooth'], model['plotting']['distance'], model['plotting']['plot_in_logx'], model['plotting']['force_style'], model['input_output']['save_prefix'], model['plotting']['norm_residuals'], model['plotting']['stretch'], model['plotting']['gamma'], model['plotting']['asinh_a'] ) figs.append(full_fig) axes.append(full_axes) if model['plotting']['diag_plot']: diag_fig, diag_axes, _ = make_figs.make_diag_fig(sol.r, sol.q, iteration_diagnostics, model['plotting']['iter_plot_range'], model['plotting']['force_style'], model['input_output']['save_prefix'] ) figs.append(diag_fig) axes.append(diag_axes) if model['analysis']['compare_profile']: dat = np.genfromtxt(model['analysis']['compare_profile']).T if len(dat) not in [2,3,4]: raise ValueError("The file in your .json's `analysis` --> " "`compare_profile` must have 2, 3 or 4 " "columns: r [arcsec], I [Jy / sr], " "negative uncertainty [Jy / sr] (optional), " "positive uncertainty [Jy / sr] (optional, " "assumed equal to negative uncertainty if not " "provided).") r_clean, I_clean = dat[0], dat[1] if len(dat) == 3: lo_err_clean, hi_err_clean = dat[2], dat[2] elif len(dat) == 4: lo_err_clean, hi_err_clean = dat[2], dat[3] else: lo_err_clean, hi_err_clean = None, None clean_profile = {'r': r_clean, 'I': I_clean, 'lo_err': lo_err_clean, 'hi_err': hi_err_clean} mean_convolved = None if model['analysis']['clean_beam']['bmaj'] is not None: mean_convolved = utilities.convolve_profile(sol.r, sol.mean, geom.inc, geom.PA, model['analysis']['clean_beam']) clean_fig, clean_axes = make_figs.make_clean_comparison_fig(u, v, vis, weights, sol, clean_profile, model['plotting']['bin_widths'], model['plotting']['gamma'], mean_convolved, model['plotting']['distance'], model['plotting']['force_style'], model['input_output']['save_prefix'] ) figs.append(clean_fig) axes.append(clean_axes) return figs, axes, model