def lnlike(p, visibilities, parameters, plot): # Set up the params dictionary. keys = [] for key in sorted(parameters.keys()): if not parameters[key]["fixed"]: keys.append(key) params = dict(zip(keys, p)) # Run the model. m = modeling.run_flared_model(visibilities, params, parameters, plot, \ ncpus=ncpus, source=source, plot_vis=args.plot_vis, nice=nice) # A list to put all of the chisq into. chisq = [] # Calculate the chisq for the visibilities. for j in range(len(visibilities["file"])): chisq.append(-0.5*(numpy.sum((visibilities["data"][j].real - \ m.visibilities[visibilities["lam"][j]].real)**2 * \ visibilities["data"][j].weights)) + \ -0.5*(numpy.sum((visibilities["data"][j].imag - \ m.visibilities[visibilities["lam"][j]].imag)**2 * \ visibilities["data"][j].weights))) # Return the sum of the chisq. return numpy.array(chisq).sum()
def lnlike(params, visibilities, parameters, plot): m = modeling.run_flared_model(visibilities, params, parameters, plot, \ ncpus=ncpus, source=source, plot_vis=args.plot_vis, nice=nice) # A list to put all of the chisq into. chisq = [] # Calculate the chisq for the visibilities. for j in range(len(visibilities["file"])): chisq.append(-0.5*(numpy.sum((visibilities["data"][j].real - \ m.visibilities[visibilities["lam"][j]].real)**2 * \ visibilities["data"][j].weights)) + \ -0.5*(numpy.sum((visibilities["data"][j].imag - \ m.visibilities[visibilities["lam"][j]].imag)**2 * \ visibilities["data"][j].weights))) # Return the sum of the chisq. return numpy.array(chisq).sum()
plt.savefig("fit.pdf") # Make a dictionary of the best fit parameters. params = dict(zip(keys, params)) ############################################################################ # # Plot the results. # ############################################################################ # Create a high resolution model for averaging. m = modeling.run_flared_model(visibilities, params, config.parameters, \ plot=True, ncpus=ncpus, source=source, plot_vis=args.plot_vis, \ nice=nice) # Open up a pdf file to plot into. pdf = PdfPages("model.pdf") # Loop through the visibilities and plot. for j in range(len(visibilities["file"])): # Plot the best fit model over the data. fig, ax = plt.subplots(nrows=visibilities["nrows"][j], \ ncols=visibilities["ncols"][j], sharex=True, sharey=True) # Make a plot of the channel maps.