def do_visibilities(bestfit_pars, headers, models_filename, uvmaps_filename, **kwargs): from fit_main import setup obs, model, prob, fitter, imagers = setup(headers) ref_coords = prob.get_parameters(bestfit_pars) analysis.compute_visibilities(obs, imagers, ref_coords, models_filename, uvmaps_filename, **kwargs)
def do_models(flatchain, headers, models_filename, **kwargs): from fit_main import setup # how to select the models to be computed? E.g. solved using NUM_STEPS/10 obs, model, prob, fitter, imagers = setup(headers) analysis.compute_models(flatchain, headers, model, prob, models_filename, **kwargs)
def do_bestfit_disk_structure(bestfit_pars, headers, bestfit_structure_filename): from fit_main import setup from py2layer.utils import print_model_structure obs, model, prob, fitter, imagers = setup(headers) res = model.compute(*prob.get_parameters(bestfit_pars)['model'], return_opacity=True) print_model_structure(res, model, bestfit_structure_filename)
def do_plot_uv_density(bestfit_pars, uvmaps_filename, uvlim, plots_dir, plot_uv_density_basename, **kwargs): from fit_main import setup loaded = util.load_models(uvmaps_filename) uvmaps = loaded['models'] headers = loaded['headers'] obs, model, prob, fitter, imagers, = setup(headers) ref_coords = prob.get_parameters(bestfit_pars) util_plot.plot_visibilities(uvmaps, headers, obs, headers['analysis']['uvbinsize'], headers['analysis']['uvdist_bin'], plots_dir, plot_uv_density_basename, ref_coords, uvlim, export_ascii=False, **kwargs)
def do_plot_uv_bestfit(bestfit_pars, headers, uvbinsize, uvlim, Jylims, uvdata_dir, bestfit_dir, plot_filename, **kwargs): # TODO: generalize for nwle>1 from fit_main import setup obs, model, prob, fitter, imagers, = setup(headers) ref_coords = prob.get_parameters(bestfit_pars) inc = np.array([ref_coords['inc'], ref_coords['inc']]) PA = np.array([ref_coords['PA'], ref_coords['PA']]) uvtables = [os.path.join(uvdata_dir, headers['obs']['data_filenames'][0]), os.path.join(bestfit_dir, headers['obs']['data_filenames'][0][:-4] + "_mod.txt")] unit_multiplier = 1. wavelength = [headers['obs']['wle_mm'], headers['obs']['wle_mm']] ismodel = [False, True] colors = ['k', 'b'] linestyle = ['.', '-'] apply_shift = dict(delta_alpha=[ref_coords['delta_alpha'][0], ref_coords['delta_alpha'][0]], delta_delta=[ref_coords['delta_delta'][0], ref_coords['delta_delta'][0]]) from pyvfit.utils.util_plot import plot_uvplot fig = plot_uvplot(uvtables, [uvbinsize[0], uvbinsize[0]], wavelength, inc, PA, np.array(Jylims[0]) * unit_multiplier, np.array(Jylims[0][1]) * unit_multiplier, linestyle, colors, uvlim=uvlim[0], ismodel=ismodel, fontsize=30, fontsize_ticklabels=20, unit_multiplier=unit_multiplier, apply_shift=apply_shift) ax = fig.get_axes() plot_label = kwargs.get("inset_caption", "") ax[0].text(uvlim[0][1] * 0.85, ax[0].get_ylim()[1] * unit_multiplier * 0.85, plot_label, fontsize=30, fontweight='bold', ha='right') for tick in ax[1].xaxis.get_major_ticks(): tick.label.set_fontsize(25) for tick in ax[1].yaxis.get_major_ticks(): tick.label.set_fontsize(25) for tick in ax[0].yaxis.get_major_ticks(): tick.label.set_fontsize(25) fig.tight_layout() fig.savefig(plot_filename)
def do_bestfit_model(bestfit_pars, headers, bestfit_dir, bestfit_model_filename, bestfit_uvmaps_filename, **kwargs): from fit_main import setup print("Bestfit parameters:\n{0} \n".format(repr(bestfit_pars))) obs, model, prob, fitter, imagers, = setup(headers) ref_coords = prob.get_parameters(bestfit_pars) # to compute the bestfit model (and residuals) we must shift the model in the disk center ref_coords['delta_delta'] = [0.] ref_coords['delta_alpha'] = [0.] analysis.compute_models(None, headers, model, prob, bestfit_model_filename, ncpus=1, single_model_pars=bestfit_pars) analysis.compute_visibilities(obs, imagers, ref_coords, bestfit_model_filename, bestfit_uvmaps_filename, working_dir=bestfit_dir, ncpus=1, **kwargs)
t = Table(names=('field', 'info', 'bestfit', '16th', '50th', '84th'), dtype=('S15', 'S15', 'float64', 'float64', 'float64', 'float64')) t.add_row(('starname', STARNAME, np.nan, np.nan, np.nan, np.nan)) for i in xrange(npars): t.add_row(('par{0}'.format(i), labels[i], bestfit_pars_real[i], percentiles[i, 0], percentiles[i, 1], percentiles[i, 2])) print(t) t.write(os.path.join(analysis_dir, "results_{0}.txt".format(STARNAME)), format='ascii.fixed_width_two_line') if do_bestfit_disk_structure: from scipy.integrate import cumtrapz from fit_main import setup obs, model, prob, fitter, imagers = setup(headers) res = model.compute(*prob.get_parameters(bestfit_pars)['model'], return_opacity=True) # determine location of 0.88, 1.3, 3.0 mm in gridwle iw_0_88mm = np.where(res['gridwle'] >= 0.880 / 10.)[0][-1] iw_1_3mm = np.where(res['gridwle'] >= 1.3 / 10.)[0][-1] iw_3mm = np.where(res['gridwle'] >= 3. / 10.)[0][-1] cos_inc = np.cos(res['inc']) dist2 = model.star.dist.cm**2. mJy = 1.e-26 # erg/s/cm2/Hz/sr from astropy.table import Table col_names = ('R', 'Sigma', 'T_mid', 'T_sur', 'H_sur', 'I')
percentiles = util_chain.compute_percentiles(flatchain_real) from astropy.table import Table t = Table(names=('field', 'info', 'bestfit', '16th', '50th', '84th'), dtype=('S15', 'S15', 'float64', 'float64', 'float64', 'float64')) t.add_row(('starname', STARNAME, np.nan, np.nan, np.nan, np.nan)) for i in xrange(npars): t.add_row(('par{0}'.format(i), labels[i], bestfit_pars_real[i], percentiles[i, 0], percentiles[i, 1], percentiles[i, 2])) print(t) t.write(os.path.join(analysis_dir ,"results_{0}.txt".format(STARNAME)), format='ascii.fixed_width_two_line') if do_bestfit_disk_structure: from scipy.integrate import cumtrapz from fit_main import setup obs, model, prob, fitter, imagers = setup(headers) res = model.compute(*prob.get_parameters(bestfit_pars)['model'], return_opacity=True) # determine location of 0.88, 1.3, 3.0 mm in gridwle iw_0_88mm = np.where(res['gridwle']>=0.880/10.)[0][-1] iw_1_3mm = np.where(res['gridwle']>=1.3/10.)[0][-1] iw_3mm = np.where(res['gridwle']>=3./10.)[0][-1] cos_inc = np.cos(res['inc']) dist2 = model.star.dist.cm**2. mJy = 1.e-26 # erg/s/cm2/Hz/sr from astropy.table import Table col_names = ('R', 'Sigma', 'T_mid', 'T_sur', 'H_sur', 'I') # t = Table(names=col_names, dtype=('float64', 'float64', 'float64', 'float64', 'float64', 'float64'))