default="logL", choices=params, help='Choose column for yaxis \ Must be one of: "{}"'.format('", "'.join(params)), ) parser.add_argument( "--chi2min", type=float, default=20.0, help="chi2min threshold for splitting plots", ) args = parser.parse_args() if args.tex: plt.rc({"usetex": True}) basename = args.filename.replace(".fits", "_diagnostics") set_params(lw=2, fontsize=16, usetex=False) stats = Table.read(args.filename) fig = make_good_bad_plots( stats, suffix=args.suffix, xparam=args.xparam, yparam=args.yparam, chi2min=args.chi2min, ) if args.savefig: fig.savefig("{}.{}".format(basename, args.savefig)) else: plt.show()
def plot_toothpick_details(asts_filename, seds_filename, savefig=False): """ Plot the details of the toothpick noisemodel creation for each filter. These plots show the individual AST results as points as (flux_in - flux_out)/flux_in. In addition, the binned values of these points are plotted giving the bias term in the observation model. Error bars around the binned bias values give the binned sigma term of the observation model. Finally, as a separate column of plots the binned completeness in each filter is plotted. Parameters ---------- asts_filename : str filename with the AST results seds_filename : str filename with the SED grid (used just for the filter information) savefig : str (default=False) to save the figure, set this to the file extension (e.g., 'png', 'pdf') """ sedgrid = SEDGrid(seds_filename, backend="cache") # read in AST results model = toothpick.MultiFilterASTs(asts_filename, sedgrid.filters) # set the column mappings as the external file is BAND_VEGA or BAND_IN model.set_data_mappings(upcase=True, in_pair=("in", "in"), out_pair=("out", "rate")) # compute binned biases, uncertainties, and completeness as a function of band flux model.fit_bins(nbins=50, completeness_mag_cut=-10) nfilters = len(sedgrid.filters) fig, ax = plt.subplots(nrows=nfilters, ncols=2, figsize=(14, 10), sharex=True) set_params() for i, cfilter in enumerate(sedgrid.filters): mag_in = model.data[model.filter_aliases[cfilter + "_in"]] flux_out = model.data[model.filter_aliases[cfilter + "_out"]] flux_in = (10**(-0.4 * mag_in)) * model.vega_flux[i] flux_out *= model.vega_flux[i] gvals = flux_out != 0.0 ax[i, 0].plot( flux_in[gvals], (flux_in[gvals] - flux_out[gvals]) / flux_in[gvals], "ko", alpha=0.1, markersize=2, ) # not all bins are filled with good data ngbins = model._nasts[i] ax[i, 0].plot( model._fluxes[0:ngbins, i], model._biases[0:ngbins, i] / model._fluxes[0:ngbins, i], "b-", ) ax[i, 0].errorbar( model._fluxes[0:ngbins, i], model._biases[0:ngbins, i] / model._fluxes[0:ngbins, i], yerr=model._sigmas[0:ngbins, i] / model._fluxes[0:ngbins, i], fmt="bo", markersize=2, alpha=0.5, ) ax[i, 0].set_ylim(-5e0, 5e0) ax[i, 0].set_xscale("log") ax[i, 0].set_ylabel(r"$(F_i - F_o)/F_i$") ax[i, 1].plot( model._fluxes[0:ngbins, i], model._compls[0:ngbins, i], "b-", ) ax[i, 1].yaxis.tick_right() ax[i, 1].yaxis.set_label_position("right") ax[i, 1].set_ylim(0, 1) ax[i, 1].set_xscale("log") sfilt = cfilter.split("_")[-1] ax[i, 1].set_ylabel(f"C({sfilt})") ax[nfilters - 1, 0].set_xlabel(r"$F_i$") ax[nfilters - 1, 1].set_xlabel(r"$F_i$") # add in the zero line # do after all the data has been plotted to get the full x range pxrange = ax[0, 0].get_xlim() for i, cfilter in enumerate(sedgrid.filters): ax[i, 0].plot(pxrange, [0.0, 0.0], "k--", alpha=0.5) # figname basename = asts_filename.replace(".fits", "_plot") fig.tight_layout() # save or show fig if savefig: fig.savefig("{}.{}".format(basename, savefig)) else: plt.show()
def plot_cmd( fitsfile, mag1_filter="F475W", mag2_filter="F814W", mag3_filter="F475W", savefig=False, show_plot=True, ): """ Read in flux from real or simulated data in fitsfile and plot a color-magnitude diagram based on specified filters. Parameters ---------- fitsfile : str input fitsfile (includes full path to file); format = .fits mag1_filter : str (default='F475W') 1st color filter mag2_filter : str (default='F814W') 2nd color filter mag3_filter : str (default='F475W') magnitude savefig : str (default=False) to save the figure, set this to the file extension (e.g., 'png', 'pdf') show_plot : boolean True, show the plot (to screen or a file) False, return the fig """ fits_data = fits.open(fitsfile) table = fits_data[1].data fits_data.close() # Read in band_rate mag1_flux = table["%s" % (mag1_filter + "_rate")] mag2_flux = table["%s" % (mag2_filter + "_rate")] mag_flux = table["%s" % (mag3_filter + "_rate")] # Exclude negative or 0 fluxes m1_pos_inds = np.where(mag1_flux > 0.0) m2_pos_inds = np.where(mag2_flux > 0.0) m_pos_inds = np.where(mag_flux > 0.0) pos_inds = reduce(np.intersect1d, (m1_pos_inds, m2_pos_inds, m_pos_inds)) mag1_flux_pos = mag1_flux[pos_inds] mag2_flux_pos = mag2_flux[pos_inds] mag_flux_pos = mag_flux[pos_inds] # Convert from flux to mags mag1 = (-2.5) * np.log10(mag1_flux_pos) mag2 = (-2.5) * np.log10(mag2_flux_pos) mag = (-2.5) * np.log10(mag_flux_pos) col = mag1 - mag2 fig = plt.figure(figsize=(9, 9)) # sets up plots to have larger fonts, wider lines, etc. set_params() plt.plot(col, mag, "k.", ms=0.1) plt.gca().invert_yaxis() plt.xlabel("%s - %s" % (mag1_filter, mag2_filter)) plt.ylabel(mag3_filter) plt.title(fitsfile) fig.tight_layout() # figname basename = fitsfile.replace(".fits", "_plot") # save or show fig if show_plot: if savefig: fig.savefig("{}.{}".format(basename, savefig)) else: plt.show() else: return fig