def fom_maps(plt, ifu, image_file, snr, color, rms, frms, rchi2, chi_grw, extent=None, fit='sc', ofile=None): color_lim = numpy.exp(growth_lim(numpy.ma.log(color), 0.95, fac=1.1)) \ if fit != 'sc' else growth_lim(color, 0.95, fac=1.10) snr_lim = numpy.power(10., growth_lim(numpy.ma.log10(snr), 0.90, fac=1.05)) rms_lim = numpy.power(10., growth_lim(numpy.ma.log10(rms), 0.90, fac=1.05)) frm_lim = numpy.power(10., growth_lim(numpy.ma.log10(frms), 0.90, fac=1.05)) chi_lim = [1 / 4, 4] c68_lim = [1 / 4, 4] c99_lim = [2.6 / 4, 2.6 * 4] crt_lim = [0.8, 2] left = 0.035 bott = 0.08 imwd = 0.24 hbuf = 0.08 cbuf = 0.005 cbwd = 0.01 vbuf = 0.03 font = {'size': 6} rc('font', **font) w, h = pyplot.figaspect(1) fig = pyplot.figure(figsize=(1.5 * w, 1.5 * h)) i, j = 0, 2 ax = init_image_ax( fig, [left + i * (imwd + hbuf), bott + j * (imwd + vbuf), imwd, imwd]) if os.path.isfile(image_file): img = image.imread(image_file) ax.imshow(img) ax.text(0.95, 0.95, r'SDSS', color='white', ha='right', va='center', transform=ax.transAxes) else: ax.text(0.5, 0.5, 'No Image', horizontalalignment='center', verticalalignment='center', transform=ax.transAxes, fontsize=20) ax.axes.get_xaxis().set_visible(False) ax.axes.get_yaxis().set_visible(False) i, j = 1, 2 ax = init_image_ax( fig, [left + i * (imwd + hbuf), bott + j * (imwd + vbuf), imwd, imwd]) cax = fig.add_axes([ left + i * (imwd + hbuf) + imwd + cbuf, bott + j * (imwd + vbuf), cbwd, imwd ]) masked_imshow(fig, ax, cax, snr, extent=extent, norm=colors.LogNorm(vmin=snr_lim[0], vmax=snr_lim[1]), cmap='viridis', zorder=3) ax.set_xlim(extent[:2]) ax.set_ylim(extent[2:]) ax.add_patch( map_beam_patch(extent, ax, facecolor='0.7', edgecolor='k', zorder=4)) ax.text(0.95, 0.95, r'S/N$_g$' if fit == 'sc' else r'H$\alpha$ A/N', ha='right', va='center', transform=ax.transAxes, zorder=4) label = '{0}-{1}'.format(plt, ifu) label += (' STELLAR' if fit == 'sc' else ' EMLINE') ax.text(0.5, 1.1, label, horizontalalignment='center', verticalalignment='bottom', transform=ax.transAxes, fontsize=26) i, j = 2, 2 ax = init_image_ax( fig, [left + i * (imwd + hbuf), bott + j * (imwd + vbuf), imwd, imwd]) cax = fig.add_axes([ left + i * (imwd + hbuf) + imwd + cbuf, bott + j * (imwd + vbuf), cbwd, imwd ]) kwargs = {} if fit == 'sc': # Plotting the g-r color kwargs['vmin'] = color_lim[0] kwargs['vmax'] = color_lim[1] else: # Plotting H-alpha/H-beta flux ratio kwargs['norm'] = colors.LogNorm(vmin=color_lim[0], vmax=color_lim[1]) masked_imshow(fig, ax, cax, color, extent=extent, cmap='RdBu_r', zorder=3, **kwargs) ax.set_xlim(extent[:2]) ax.set_ylim(extent[2:]) ax.add_patch( map_beam_patch(extent, ax, facecolor='0.7', edgecolor='k', zorder=4)) ax.text(0.95, 0.95, r'$g-r$' if fit == 'sc' else r'H$\alpha$/H$\beta$', ha='right', va='center', transform=ax.transAxes, zorder=4) i, j = 0, 1 ax = init_image_ax( fig, [left + i * (imwd + hbuf), bott + j * (imwd + vbuf), imwd, imwd]) cax = fig.add_axes([ left + i * (imwd + hbuf) + imwd + cbuf, bott + j * (imwd + vbuf), cbwd, imwd ]) masked_imshow(fig, ax, cax, rms, extent=extent, norm=colors.LogNorm(vmin=rms_lim[0], vmax=rms_lim[1]), cmap='viridis', zorder=3) ax.set_xlim(extent[:2]) ax.set_ylim(extent[2:]) ax.add_patch( map_beam_patch(extent, ax, facecolor='0.7', edgecolor='k', zorder=4)) ax.text(0.95, 0.95, r'RMS', ha='right', va='center', transform=ax.transAxes, zorder=4) i, j = 1, 1 ax = init_image_ax( fig, [left + i * (imwd + hbuf), bott + j * (imwd + vbuf), imwd, imwd]) cax = fig.add_axes([ left + i * (imwd + hbuf) + imwd + cbuf, bott + j * (imwd + vbuf), cbwd, imwd ]) masked_imshow(fig, ax, cax, frms, extent=extent, norm=colors.LogNorm(vmin=frm_lim[0], vmax=frm_lim[1]), cmap='viridis', zorder=3) ax.set_xlim(extent[:2]) ax.set_ylim(extent[2:]) ax.add_patch( map_beam_patch(extent, ax, facecolor='0.7', edgecolor='k', zorder=4)) ax.text(0.95, 0.95, r'fRMS', ha='right', va='center', transform=ax.transAxes, zorder=4) i, j = 2, 1 ax = init_image_ax( fig, [left + i * (imwd + hbuf), bott + j * (imwd + vbuf), imwd, imwd]) cax = fig.add_axes([ left + i * (imwd + hbuf) + imwd + cbuf, bott + j * (imwd + vbuf), cbwd, imwd ]) masked_imshow(fig, ax, cax, rchi2, extent=extent, norm=colors.LogNorm(vmin=chi_lim[0], vmax=chi_lim[1]), cmap='RdBu_r', zorder=3) ax.set_xlim(extent[:2]) ax.set_ylim(extent[2:]) ax.add_patch( map_beam_patch(extent, ax, facecolor='0.7', edgecolor='k', zorder=4)) ax.text(0.95, 0.95, r'$\chi^2$', ha='right', va='center', transform=ax.transAxes, zorder=4) i, j = 0, 0 ax = init_image_ax( fig, [left + i * (imwd + hbuf), bott + j * (imwd + vbuf), imwd, imwd]) cax = fig.add_axes([ left + i * (imwd + hbuf) + imwd + cbuf, bott + j * (imwd + vbuf), cbwd, imwd ]) masked_imshow(fig, ax, cax, chi_grw[0], extent=extent, norm=colors.LogNorm(vmin=c68_lim[0], vmax=c68_lim[1]), cmap='viridis', zorder=3) ax.set_xlim(extent[:2]) ax.set_ylim(extent[2:]) ax.add_patch( map_beam_patch(extent, ax, facecolor='0.7', edgecolor='k', zorder=4)) ax.text(0.95, 0.95, r'68% Growth $|\Delta|/\epsilon$', ha='right', va='center', transform=ax.transAxes, zorder=4) i, j = 1, 0 ax = init_image_ax( fig, [left + i * (imwd + hbuf), bott + j * (imwd + vbuf), imwd, imwd]) cax = fig.add_axes([ left + i * (imwd + hbuf) + imwd + cbuf, bott + j * (imwd + vbuf), cbwd, imwd ]) masked_imshow(fig, ax, cax, chi_grw[1], extent=extent, norm=colors.LogNorm(vmin=c99_lim[0], vmax=c99_lim[1]), cmap='viridis', zorder=3) ax.set_xlim(extent[:2]) ax.set_ylim(extent[2:]) ax.add_patch( map_beam_patch(extent, ax, facecolor='0.7', edgecolor='k', zorder=4)) ax.text(0.95, 0.95, r'99% Growth $|\Delta|/\epsilon$', ha='right', va='center', transform=ax.transAxes, zorder=4) x = numpy.linspace(0, 5, 100) g = (erf(x / numpy.sqrt(2)) - erf(-x / numpy.sqrt(2))) / 2. interp = interpolate.interp1d(g, x) m = interp([0.68, 0.99]) i, j = 2, 0 ax = init_image_ax( fig, [left + i * (imwd + hbuf), bott + j * (imwd + vbuf), imwd, imwd]) cax = fig.add_axes([ left + i * (imwd + hbuf) + imwd + cbuf, bott + j * (imwd + vbuf), cbwd, imwd ]) masked_imshow(fig, ax, cax, numpy.ma.divide(chi_grw[1], chi_grw[0]) * m[0] / m[1], extent=extent, vmin=crt_lim[0], vmax=crt_lim[1], cmap='RdBu_r', zorder=3) ax.set_xlim(extent[:2]) ax.set_ylim(extent[2:]) ax.add_patch( map_beam_patch(extent, ax, facecolor='0.7', edgecolor='k', zorder=4)) ax.text(0.95, 0.95, r'99%/68% wrt Gaussian', ha='right', va='center', transform=ax.transAxes, zorder=4) if ofile is None: pyplot.show() else: print('Writing: {0}'.format(ofile)) fig.canvas.print_figure(ofile, bbox_inches='tight', dpi=100) fig.clear() pyplot.close(fig)
def radial_coverage_histogram(dapall, daptype, ofile=None): # Must have finished, be of the correct daptype, and *not* be # critical indx = (dapall['DAPDONE'] == 1) & (dapall['DAPTYPE'] == daptype) \ & numpy.invert(DAPQualityBitMask().flagged(dapall['DAPQUAL'], 'CRITICAL')) # Get the range arcsec_rng = growth_lim(dapall['RCOV90'][indx], 0.99, fac=1.1) rore = numpy.ma.divide(dapall['RCOV90'][indx], dapall['NSA_ELPETRO_TH50_R'][indx]) rore[dapall['NSA_ELPETRO_TH50_R'][indx] < 0] = numpy.ma.masked rore_rng = growth_lim(rore, 0.99, fac=1.1) # Determine the sample sdssMaskbits = defaults.sdss_maskbits_file() targ1bm = BitMask.from_par_file(sdssMaskbits, 'MANGA_TARGET1') ancillary = dapall['MNGTARG3'][indx] > 0 primaryplus = targ1bm.flagged( dapall['MNGTARG1'][indx], flag=['PRIMARY_v1_2_0', 'COLOR_ENHANCED_v1_2_0']) secondary = targ1bm.flagged(dapall['MNGTARG1'][indx], flag='SECONDARY_v1_2_0') other = numpy.invert(ancillary) & numpy.invert(primaryplus) & numpy.invert( secondary) print('Num. of observations with 90% coverage <1 arcsec: {0}'.format( numpy.sum(dapall['RCOV90'][indx] < 1))) font = {'size': 10} rc('font', **font) # Instantiate the figure w, h = pyplot.figaspect(1) fig = pyplot.figure(figsize=(1.5 * w, 1.5 * h)) nlim = [0.8, 1000] # Show RCOV90 in terms of arcseconds for each IFU ax = init_ax(fig, [0.1, 0.58, 0.8, 0.4]) ax.set_ylim(nlim) ax.set_yscale('log', nonpositive='clip') ifu = [19, 37, 61, 91, 127] for i, f in enumerate(ifu): _indx = indx & ((dapall['IFUDESIGN'] / 100).astype(int) == f) if not numpy.any(_indx): continue ax.hist(dapall['RCOV90'][_indx], bins=50, range=arcsec_rng, alpha=0.5, histtype='stepfilled', color='C{0}'.format(i), zorder=2) ax.hist(dapall['RCOV90'][_indx], bins=50, range=arcsec_rng, histtype='step', color='C{0}'.format(i), zorder=3) medp = numpy.median(dapall['RCOV90'][_indx]) ax.plot([medp, medp], nlim, color='C{0}'.format(i), zorder=4, linestyle='--') ax.text(-0.1, 0.5, 'N', ha='center', va='center', transform=ax.transAxes, rotation='vertical') ax.text(0.5, -0.13, r'$R_{90}$ (arcsec)', ha='center', va='center', transform=ax.transAxes) ax.text(0.05, 0.95, '19-fiber', color='C0', ha='left', va='center', transform=ax.transAxes) ax.text(0.05, 0.90, '37-fiber', color='C1', ha='left', va='center', transform=ax.transAxes) ax.text(0.05, 0.85, '61-fiber', color='C2', ha='left', va='center', transform=ax.transAxes) ax.text(0.05, 0.80, '91-fiber', color='C3', ha='left', va='center', transform=ax.transAxes) ax.text(0.05, 0.75, '127-fiber', color='C4', ha='left', va='center', transform=ax.transAxes) # Show RCOV90 in terms of Re for each sample ax = init_ax(fig, [0.1, 0.08, 0.8, 0.4]) ax.set_ylim(nlim) ax.set_yscale('log', nonpositive='clip') if numpy.any(primaryplus): _rore = (rore[primaryplus]).compressed() ax.hist(_rore, bins=50, range=rore_rng, alpha=0.5, histtype='stepfilled', color='C0', zorder=2) ax.hist(_rore, bins=50, range=rore_rng, histtype='step', color='C0', zorder=3) medp = numpy.median(_rore) ax.plot([medp, medp], nlim, color='C0', zorder=4, linestyle='--') if numpy.any(secondary): _rore = (rore[secondary]).compressed() ax.hist(_rore, bins=50, range=rore_rng, alpha=0.5, histtype='stepfilled', color='C1', zorder=2) ax.hist(_rore, bins=50, range=rore_rng, histtype='step', color='C1', zorder=3) medp = numpy.median(_rore) ax.plot([medp, medp], nlim, color='C1', zorder=4, linestyle='--') if numpy.any(other): _rore = (rore[other]).compressed() ax.hist(_rore, bins=50, range=rore_rng, alpha=0.5, histtype='stepfilled', color='C2', zorder=2) ax.hist(_rore, bins=50, range=rore_rng, histtype='step', color='C2', zorder=3) if numpy.any(ancillary): _rore = (rore[ancillary]).compressed() ax.hist(_rore, bins=50, range=rore_rng, alpha=0.5, histtype='stepfilled', color='C3', zorder=2) ax.hist(_rore, bins=50, range=rore_rng, histtype='step', color='C3', zorder=3) ax.text(-0.1, 0.5, 'N', ha='center', va='center', transform=ax.transAxes, rotation='vertical') ax.text(0.5, -0.12, r'$R_{90}/R_{eff}$', ha='center', va='center', transform=ax.transAxes) ax.text(0.05, 0.95, 'Primary+', color='C0', ha='left', va='center', transform=ax.transAxes) ax.text(0.05, 0.90, 'Secondary', color='C1', ha='left', va='center', transform=ax.transAxes) ax.text(0.05, 0.85, 'Other', color='C2', ha='left', va='center', transform=ax.transAxes) ax.text(0.05, 0.80, 'Ancillary', color='C3', ha='left', va='center', transform=ax.transAxes) if ofile is None: pyplot.show() else: print('Writing: {0}'.format(ofile)) fig.canvas.print_figure(ofile, bbox_inches='tight') fig.clear() pyplot.close(fig)
def fom_lambda(plt, ifu, wave, flux, error, model, fit='sc', wave_limits=None, ofile=None): if wave_limits is not None: indx = (wave < wave_limits[0]) | (wave > wave_limits[1]) flux[indx, :] = numpy.ma.masked error[indx, :] = numpy.ma.masked model[indx, :] = numpy.ma.masked else: indx = numpy.arange(len(wave))[numpy.any(numpy.invert(model.mask), axis=1)] wave_limits = [wave[indx[0]], wave[indx[-1]]] nspec = flux.shape[1] resid = numpy.ma.absolute(flux - model) fresid = numpy.ma.absolute(numpy.ma.divide(resid, model)) chi = numpy.ma.absolute(numpy.ma.divide(resid, error)) snr = numpy.ma.divide(flux, error) mean_flux = numpy.ma.mean(flux, axis=1) mean_snr = numpy.ma.mean(snr, axis=1) mean_resid = numpy.ma.mean(resid, axis=1) mean_fresid = numpy.ma.mean(fresid, axis=1) mean_chi = numpy.ma.mean(chi, axis=1) bc = BoxcarFilter(100) resid_sm = bc.smooth(resid) fresid_sm = bc.smooth(fresid) chi_sm = bc.smooth(chi) spec_lim = [-10, nspec + 10] flux_lim = numpy.exp( growth_lim(numpy.ma.log(mean_flux).compressed(), 0.99, fac=2.0)) snr_lim = numpy.exp( growth_lim(numpy.ma.log(mean_snr).compressed(), 0.99, fac=2.0)) resid_lim = numpy.exp( growth_lim(numpy.ma.log(mean_resid).compressed(), 0.99, fac=2.0)) fresid_lim = numpy.exp( growth_lim(numpy.ma.log(mean_fresid).compressed(), 0.99, fac=2.0)) chi_lim = numpy.exp( growth_lim(numpy.ma.log(mean_chi).compressed(), 0.99, fac=2.0, midpoint=0)) l0 = numpy.log10(wave[0]) dl = spectral_coordinate_step(wave, log=True) wave_bins = numpy.power(10, l0 - dl / 2 + dl * numpy.arange(len(wave) + 1)) spec_bins = 0.5 + numpy.arange(nspec + 1) font = {'size': 10} rc('font', **font) w, h = pyplot.figaspect(1) fig = pyplot.figure(figsize=(1.5 * w, 1.5 * h)) ax = init_ax(fig, [0.2, 0.87, 0.60, 0.12], facecolor='0.95', grid=True) ax.set_xlim(wave_limits) ax.set_ylim(flux_lim) ax.set_yscale('log') ax.xaxis.set_major_formatter(ticker.NullFormatter()) ax.plot(wave, numpy.ma.mean(flux, axis=1), color='k', lw=0.5) ax.text(-0.15, 0.5, r'Flux', horizontalalignment='center', verticalalignment='center', rotation='vertical', transform=ax.transAxes) axt = ax.twinx() axt.set_xlim(wave_limits) axt.set_ylim(snr_lim) axt.set_yscale('log') axt.tick_params(axis='y', colors='0.5') axt.xaxis.set_major_formatter(ticker.NullFormatter()) axt.plot(wave, numpy.ma.mean(snr, axis=1), color='0.5', lw=0.5) axt.text(1.1, 0.5, r'S/N', horizontalalignment='center', verticalalignment='center', rotation='vertical', transform=axt.transAxes, color='0.5') ax = init_ax(fig, [0.2, 0.75, 0.60, 0.12], facecolor='0.95', grid=True) ax.set_xlim(wave_limits) ax.set_ylim(resid_lim) ax.set_yscale('log') ax.xaxis.set_major_formatter(ticker.NullFormatter()) # ax.plot(wave, numpy.ma.mean(resid_sm, axis=0), color='C3') ax.plot(wave, numpy.ma.mean(resid, axis=1), color='k', lw=0.5) ax.text(-0.15, 0.5, r'$|\Delta|$', horizontalalignment='center', verticalalignment='center', rotation='vertical', transform=ax.transAxes) ax = init_ax(fig, [0.2, 0.63, 0.60, 0.12], facecolor='0.95', grid=True) ax.set_xlim(wave_limits) ax.set_ylim(fresid_lim) ax.set_yscale('log') ax.xaxis.set_major_formatter(ticker.NullFormatter()) ax.plot(wave, numpy.ma.mean(fresid, axis=1), color='k', lw=0.5) ax.text(-0.15, 0.5, r'$|\Delta|/m$', horizontalalignment='center', verticalalignment='center', rotation='vertical', transform=ax.transAxes) ax = init_ax(fig, [0.2, 0.51, 0.60, 0.12], facecolor='0.95', grid=True) ax.set_xlim(wave_limits) ax.set_ylim(chi_lim) ax.set_yscale('log') ax.plot(wave, numpy.ma.mean(chi, axis=1), color='k', lw=0.5) ax.text(0.5, -0.41, r'Wavelength ($\AA$)', horizontalalignment='center', verticalalignment='center', transform=ax.transAxes) ax.text(-0.15, 0.5, r'$|\Delta|/\epsilon$', horizontalalignment='center', verticalalignment='center', rotation='vertical', transform=ax.transAxes) label = '{0}-{1}'.format(plt, ifu) label += (' STELLAR' if fit == 'sc' else ' EMLINE') ax.text(1.23, -0.3, label, horizontalalignment='center', verticalalignment='bottom', rotation='vertical', transform=ax.transAxes, fontsize=22) ax = init_ax(fig, [0.07, 0.23, 0.30, 0.16], facecolor='0.95') ax.set_xlim(wave_limits) ax.set_ylim(spec_lim) ax.xaxis.set_major_formatter(ticker.NullFormatter()) im = ax.pcolormesh(wave_bins, spec_bins, resid.T, norm=colors.LogNorm(vmin=resid_lim[0], vmax=resid_lim[1]), cmap='viridis', zorder=4, lw=0, rasterized=True) ax = init_ax(fig, [0.07, 0.07, 0.30, 0.16], facecolor='0.95') ax.set_xlim(wave_limits) ax.set_ylim(spec_lim) ax.pcolormesh(wave_bins, spec_bins, resid_sm.T, norm=colors.LogNorm(vmin=resid_lim[0], vmax=resid_lim[1]), cmap='viridis', zorder=4, lw=0, rasterized=True) cax = fig.add_axes([0.07, 0.395, 0.20, 0.01]) cb = pyplot.colorbar( im, cax=cax, orientation='horizontal') #, format=FormatStrFormatter('%d')) cb.ax.tick_params(axis='x', which='both', bottom=False, top=True, labelbottom=False, labeltop=True) cax.text(1.05, 0.7, r'$|\Delta|$', horizontalalignment='left', verticalalignment='center', transform=cax.transAxes, fontsize=10) ax = init_ax(fig, [0.37, 0.23, 0.30, 0.16], facecolor='0.95') ax.set_xlim(wave_limits) ax.set_ylim(spec_lim) ax.xaxis.set_major_formatter(ticker.NullFormatter()) ax.yaxis.set_major_formatter(ticker.NullFormatter()) im = ax.pcolormesh(wave_bins, spec_bins, fresid.T, norm=colors.LogNorm(vmin=fresid_lim[0], vmax=fresid_lim[1]), cmap='viridis', zorder=4, lw=0, rasterized=True) ax = init_ax(fig, [0.37, 0.07, 0.30, 0.16], facecolor='0.95') ax.set_xlim(wave_limits) ax.set_ylim(spec_lim) ax.yaxis.set_major_formatter(ticker.NullFormatter()) ax.pcolormesh(wave_bins, spec_bins, fresid_sm.T, norm=colors.LogNorm(vmin=fresid_lim[0], vmax=fresid_lim[1]), cmap='viridis', zorder=4, lw=0, rasterized=True) ax.text(0.5, -0.30, r'Wavelength ($\AA$)', horizontalalignment='center', verticalalignment='center', transform=ax.transAxes) cax = fig.add_axes([0.37, 0.395, 0.20, 0.01]) cb = pyplot.colorbar( im, cax=cax, orientation='horizontal') #, format=FormatStrFormatter('%d')) cb.ax.tick_params(axis='x', which='both', bottom=False, top=True, labelbottom=False, labeltop=True) cax.text(1.05, 0.7, r'$|\Delta|/m$', horizontalalignment='left', verticalalignment='center', transform=cax.transAxes, fontsize=10) ax = init_ax(fig, [0.67, 0.23, 0.30, 0.16], facecolor='0.95') ax.set_xlim(wave_limits) ax.set_ylim(spec_lim) ax.xaxis.set_major_formatter(ticker.NullFormatter()) ax.yaxis.set_major_formatter(ticker.NullFormatter()) im = ax.pcolormesh(wave_bins, spec_bins, chi.T, norm=colors.LogNorm(vmin=chi_lim[0], vmax=chi_lim[1]), cmap='RdBu_r', zorder=4, lw=0, rasterized=True) ax = init_ax(fig, [0.67, 0.07, 0.30, 0.16], facecolor='0.95') ax.set_xlim(wave_limits) ax.set_ylim(spec_lim) ax.yaxis.set_major_formatter(ticker.NullFormatter()) ax.pcolormesh(wave_bins, spec_bins, chi_sm.T, norm=colors.LogNorm(vmin=chi_lim[0], vmax=chi_lim[1]), cmap='RdBu_r', zorder=4, lw=0, rasterized=True) cax = fig.add_axes([0.67, 0.395, 0.20, 0.01]) cb = pyplot.colorbar( im, cax=cax, orientation='horizontal') #, format=FormatStrFormatter('%d')) cb.ax.tick_params(axis='x', which='both', bottom=False, top=True, labelbottom=False, labeltop=True) cax.text(1.05, 0.7, r'$|\Delta|/\epsilon$', horizontalalignment='left', verticalalignment='center', transform=cax.transAxes, fontsize=10) if ofile is None: pyplot.show() else: print('Writing: {0}'.format(ofile)) fig.canvas.print_figure(ofile, bbox_inches='tight', dpi=100) fig.clear() pyplot.close(fig)
def fom_growth(plt, ifu, flux, error, model, snrg, rms, frms, rchi2, fit='sc', ofile=None): nspec = flux.shape[1] resid = numpy.ma.absolute(flux - model) fresid = numpy.ma.divide(resid, model) chi = numpy.ma.divide(resid, error) snr_lim = numpy.exp( growth_lim(numpy.ma.log(snrg).compressed(), 0.95, fac=1.3)) chi_lim = numpy.exp( growth_lim(numpy.ma.log(chi).compressed(), 0.8, fac=1.1)) chi_lim[1] = numpy.ma.amax(chi) * 2 resid_lim = numpy.exp( growth_lim(numpy.ma.log(resid).compressed(), 0.9, fac=1.1)) resid_lim[1] = numpy.ma.amax(resid) * 2 fresid_lim = numpy.exp( growth_lim(numpy.ma.log(fresid).compressed(), 0.9, fac=1.1)) fresid_lim[1] = numpy.ma.amax(fresid) * 2 w, h = pyplot.figaspect(1) fig = pyplot.figure(figsize=(1.5 * w, 1.5 * h)) rax = init_ax(fig, [0.07, 0.50, 0.30, 0.35], facecolor='0.9', grid=True) rax.set_xlim(resid_lim) rax.set_ylim([1e-4, 2]) rax.set_yscale('log') rax.set_xscale('log') rax.text(0.5, -0.17, r'$|\Delta|$', ha='center', va='center', transform=rax.transAxes) rax.text(0.1, 0.5, r'1-Growth', horizontalalignment='center', verticalalignment='center', transform=rax.transAxes, rotation='vertical') fax = init_ax(fig, [0.37, 0.50, 0.30, 0.35], facecolor='0.9', grid=True) fax.set_xlim(fresid_lim) fax.set_ylim([1e-4, 2]) fax.set_yscale('log') fax.set_xscale('log') fax.yaxis.set_major_formatter(ticker.NullFormatter()) label = '{0}-{1}'.format(plt, ifu) label += (' STELLAR' if fit == 'sc' else ' EMLINE') fax.text(0.5, 1.3, label, horizontalalignment='center', verticalalignment='center', transform=fax.transAxes, fontsize=22) fax.text(0.5, -0.17, r'$|\Delta|/m$', ha='center', va='center', transform=fax.transAxes) cax = init_ax(fig, [0.67, 0.50, 0.30, 0.35], facecolor='0.9', grid=True) cax.set_xlim(chi_lim) cax.set_ylim([1e-4, 2]) cax.set_yscale('log') cax.set_xscale('log') cax.yaxis.set_major_formatter(ticker.NullFormatter()) cax.text(0.5, -0.17, r'$|\Delta|/\epsilon$', ha='center', va='center', transform=cax.transAxes) cmap = cm.get_cmap('viridis') cnorm = colors.LogNorm(vmin=snr_lim[0], vmax=snr_lim[1]) cbax = fig.add_axes([0.69, 0.86, 0.2, 0.01]) cb = colorbar.ColorbarBase(cbax, norm=cnorm, cmap=cmap, orientation='horizontal') cb.ax.tick_params(axis='x', which='both', bottom=False, top=True, labelbottom=False, labeltop=True) cbax.text(1.05, 0.5, r'S/N$_g$', ha='left', va='center', transform=cbax.transAxes) snr_srt = numpy.argsort(snrg) for i in range(nspec): j = snr_srt[i] if numpy.all(chi.mask[:, j]): continue t = resid[:, j].compressed() s = numpy.argsort(t) rax.step(t[s], 1 - numpy.arange(len(t)).astype(float) / len(t), where='pre', color=cmap(cnorm(snrg[j])), lw=0.7) t = fresid[:, j].compressed() s = numpy.argsort(t) fax.step(t[s], 1 - numpy.arange(len(t)).astype(float) / len(t), where='pre', color=cmap(cnorm(snrg[j])), lw=0.7) t = chi[:, j].compressed() s = numpy.argsort(t) cax.step(t[s], 1 - numpy.arange(len(t)).astype(float) / len(t), where='pre', color=cmap(cnorm(snrg[j])), lw=0.7) x = numpy.linspace(0, 5, 100) g = (erf(x / numpy.sqrt(2)) - erf(-x / numpy.sqrt(2))) / 2. interp = interpolate.interp1d(g, x) cax.plot(x, 1 - g, color='k') chi2_lim = numpy.exp( growth_lim(numpy.ma.log(rchi2).compressed(), 1.0, fac=2.0)) rms_lim = numpy.exp( growth_lim(numpy.ma.log(rms).compressed(), 1.0, fac=2.0)) frms_lim = numpy.exp( growth_lim(numpy.ma.log(frms).compressed(), 1.0, fac=2.0)) snr_lim = numpy.exp( growth_lim(numpy.ma.log(snrg).compressed(), 1.0, fac=2.0)) rax = init_ax(fig, [0.07, 0.15, 0.30, 0.25], facecolor='0.9', grid=True) rax.set_xlim(rms_lim) rax.set_ylim(snr_lim) rax.set_yscale('log') rax.set_xscale('log') rax.scatter(rms, snrg, marker='.', s=20, color='k', lw=0, alpha=0.5) rax.text(0.5, -0.25, r'$RMS$', ha='center', va='center', transform=rax.transAxes) rax.text(0.1, 0.5, r'S/N$_g$', horizontalalignment='center', verticalalignment='center', transform=rax.transAxes, rotation='vertical') fax = init_ax(fig, [0.37, 0.15, 0.30, 0.25], facecolor='0.9', grid=True) fax.set_xlim(frms_lim) fax.set_ylim(snr_lim) fax.set_yscale('log') fax.set_xscale('log') fax.yaxis.set_major_formatter(ticker.NullFormatter()) fax.scatter(frms, snrg, marker='.', s=20, color='k', lw=0, alpha=0.5) fax.text(0.5, -0.25, r'$fRMS$', ha='center', va='center', transform=fax.transAxes) cax = init_ax(fig, [0.67, 0.15, 0.30, 0.25], facecolor='0.9', grid=True) cax.set_xlim(chi2_lim) cax.set_ylim(snr_lim) cax.set_yscale('log') cax.set_xscale('log') cax.yaxis.set_major_formatter(ticker.NullFormatter()) cax.scatter(rchi2, snrg, marker='.', s=20, color='k', lw=0, alpha=0.5) cax.text(0.5, -0.25, r'$\chi^2_\nu$', ha='center', va='center', transform=cax.transAxes) if ofile is None: pyplot.show() else: print('Writing: {0}'.format(ofile)) fig.canvas.print_figure(ofile, bbox_inches='tight', dpi=100) fig.clear() pyplot.close(fig)
def spotcheck_images(cube, plan, method_dir, ref_dir, qa_dir, fwhm=None): """ Construct a QA plot for the PPXFFit results. Args: cube (:class:`~mangadap.datacube.datacube.DataCube`): Analyzed data cube plan (:obj:`dict`, :class:`~mangadap.par.parset.ParSet`): Object with analysis plan keywords. method_dir (`Path`_): Top-level "method" directory with all the DAP files. ref_dir (`Path`_): Directory with all the DAP reference files. qa_dir (`Path`_): Directory for the QA figures fwhm (:obj:`float`, optional): The FWHM in arcsec of the beam. If None, no beam included in the plot. """ # Check that the paths exists if not method_dir.exists(): raise NotADirectoryError( f'{method_dir} does not exist; run the DAP first!') if not ref_dir.exists(): raise NotADirectoryError( f'{ref_dir} does not exist; run the DAP first!') if not qa_dir.exists(): qa_dir.mkdir(parents=True) # Get the name of the output file ofile = qa_dir / f'{cube.output_root}-MAPS-{plan["key"]}-spotcheck.png' bm = dapfits.DAPMapsBitMask() _, directory, file = dapfits.default_paths(cube, method=plan['key'], output_path=method_dir) ifile = directory / file if not ifile.exists(): raise FileNotFoundError(f'No file: {ifile}') print(f'Reading: {ifile}') hdu = fits.open(str(ifile)) # Check everything is finite num_ext = len(hdu) for i in range(num_ext): if hdu[i].data is None: continue if not numpy.all(numpy.isfinite(hdu[i].data)): raise ValueError(f'HDU {hdu[i].name} contains infs or NaNs!') # Build the column dictionaries emline = channel_dictionary(hdu, 'EMLINE_GFLUX') specindex = channel_dictionary(hdu, 'SPECINDEX') extent = map_extent(hdu, 'SPX_MFLUX') # Get the data to plot spxflx = numpy.ma.MaskedArray(hdu['SPX_MFLUX'].data.copy()) spxsnr = numpy.ma.MaskedArray(hdu['SPX_SNR'].data.copy()) binid = numpy.ma.MaskedArray(hdu['BINID'].data.copy(), mask=hdu['BINID'].data < 0) binsnr = numpy.ma.MaskedArray(hdu['BIN_SNR'].data.copy(), mask=hdu['BIN_MFLUX_MASK'].data > 0) # 68% growth of the absolute value of the fractional residuals scfres = numpy.ma.MaskedArray( hdu['STELLAR_FOM'].data.copy()[3, :, :], mask=numpy.invert(hdu['STELLAR_FOM'].data[3, :, :] > 0)) # Reduced chi-square scrchi = numpy.ma.MaskedArray( hdu['STELLAR_FOM'].data.copy()[2, :, :], mask=numpy.invert(hdu['STELLAR_FOM'].data[2, :, :] > 0)) strvel = numpy.ma.MaskedArray(hdu['STELLAR_VEL'].data.copy(), mask=bm.flagged(hdu['STELLAR_VEL_MASK'].data, 'DONOTUSE')) ustrvel = numpy.ma.MaskedArray(hdu['STELLAR_VEL'].data.copy(), mask=numpy.invert( bm.flagged(hdu['STELLAR_VEL_MASK'].data, 'UNRELIABLE'))) ustrvel[numpy.invert(numpy.ma.getmaskarray(ustrvel))] = 0.0 strsig = numpy.ma.MaskedArray(hdu['STELLAR_SIGMA'].data.copy(), mask=bm.flagged( hdu['STELLAR_SIGMA_MASK'].data, 'DONOTUSE')) ustrsig = numpy.ma.MaskedArray(hdu['STELLAR_SIGMA'].data.copy(), mask=numpy.invert( bm.flagged( hdu['STELLAR_SIGMA_MASK'].data, 'UNRELIABLE'))) ustrsig[numpy.invert(numpy.ma.getmaskarray(ustrsig))] = 0.0 hasflx = numpy.ma.MaskedArray( hdu['EMLINE_SFLUX'].data.copy()[emline['Ha-6564'], :, :], mask=bm.flagged(hdu['EMLINE_SFLUX_MASK'].data[emline['Ha-6564'], :, :], 'DONOTUSE')) uhasflx = numpy.ma.MaskedArray( hdu['EMLINE_SFLUX'].data.copy()[emline['Ha-6564'], :, :], mask=numpy.invert( bm.flagged(hdu['EMLINE_SFLUX_MASK'].data[emline['Ha-6564'], :, :], 'UNRELIABLE'))) uhasflx[numpy.invert(numpy.ma.getmaskarray(uhasflx))] = 0.0 hagflx = numpy.ma.MaskedArray( hdu['EMLINE_GFLUX'].data.copy()[emline['Ha-6564'], :, :], mask=bm.flagged(hdu['EMLINE_GFLUX_MASK'].data[emline['Ha-6564'], :, :], 'DONOTUSE')) uhagflx = numpy.ma.MaskedArray( hdu['EMLINE_GFLUX'].data.copy()[emline['Ha-6564'], :, :], mask=numpy.invert( bm.flagged(hdu['EMLINE_GFLUX_MASK'].data[emline['Ha-6564'], :, :], 'UNRELIABLE'))) uhagflx[numpy.invert(numpy.ma.getmaskarray(uhagflx))] = 0.0 hagvel = numpy.ma.MaskedArray( hdu['EMLINE_GVEL'].data.copy()[emline['Ha-6564'], :, :], mask=bm.flagged(hdu['EMLINE_GVEL_MASK'].data[emline['Ha-6564'], :, :], 'DONOTUSE')) uhagvel = numpy.ma.MaskedArray( hdu['EMLINE_GVEL'].data.copy()[emline['Ha-6564'], :, :], mask=numpy.invert( bm.flagged(hdu['EMLINE_GVEL_MASK'].data[emline['Ha-6564'], :, :], 'UNRELIABLE'))) uhagvel[numpy.invert(numpy.ma.getmaskarray(uhagvel))] = 0.0 hagsig = numpy.ma.MaskedArray( hdu['EMLINE_GSIGMA'].data.copy()[emline['Ha-6564'], :, :], mask=bm.flagged( hdu['EMLINE_GSIGMA_MASK'].data[emline['Ha-6564'], :, :], 'DONOTUSE')) uhagsig = numpy.ma.MaskedArray( hdu['EMLINE_GSIGMA'].data.copy()[emline['Ha-6564'], :, :], mask=numpy.invert( bm.flagged(hdu['EMLINE_GSIGMA_MASK'].data[emline['Ha-6564'], :, :], 'UNRELIABLE'))) uhagsig[numpy.invert(numpy.ma.getmaskarray(uhagsig))] = 0.0 hbsflx = numpy.ma.MaskedArray( hdu['EMLINE_SFLUX'].data.copy()[emline['Hb-4862'], :, :], mask=bm.flagged(hdu['EMLINE_SFLUX_MASK'].data[emline['Hb-4862'], :, :], 'DONOTUSE')) uhbsflx = numpy.ma.MaskedArray( hdu['EMLINE_SFLUX'].data.copy()[emline['Hb-4862'], :, :], mask=numpy.invert( bm.flagged(hdu['EMLINE_SFLUX_MASK'].data[emline['Hb-4862'], :, :], 'UNRELIABLE'))) uhbsflx[numpy.invert(numpy.ma.getmaskarray(uhbsflx))] = 0.0 hbgflx = numpy.ma.MaskedArray( hdu['EMLINE_GFLUX'].data.copy()[emline['Hb-4862'], :, :], mask=bm.flagged(hdu['EMLINE_GFLUX_MASK'].data[emline['Hb-4862'], :, :], 'DONOTUSE')) uhbgflx = numpy.ma.MaskedArray( hdu['EMLINE_GFLUX'].data.copy()[emline['Hb-4862'], :, :], mask=numpy.invert( bm.flagged(hdu['EMLINE_GFLUX_MASK'].data[emline['Hb-4862'], :, :], 'UNRELIABLE'))) uhbgflx[numpy.invert(numpy.ma.getmaskarray(uhbgflx))] = 0.0 specindex_available = True try: if hdu['SPECINDEX'].data is None: pass except: warnings.warn('No spectral indices in maps file.') specindex_available = False if specindex_available: d4000 = numpy.ma.MaskedArray( hdu['SPECINDEX'].data.copy()[specindex['D4000'], :, :], mask=bm.flagged( hdu['SPECINDEX_MASK'].data[specindex['D4000'], :, :], 'DONOTUSE')) ud4000 = numpy.ma.MaskedArray( hdu['SPECINDEX'].data.copy()[specindex['D4000'], :, :], mask=numpy.invert( bm.flagged( hdu['SPECINDEX_MASK'].data[specindex['D4000'], :, :], 'UNRELIABLE'))) ud4000[numpy.invert(numpy.ma.getmaskarray(ud4000))] = 0.0 dn4000 = numpy.ma.MaskedArray( hdu['SPECINDEX'].data.copy()[specindex['Dn4000'], :, :], mask=bm.flagged( hdu['SPECINDEX_MASK'].data[specindex['Dn4000'], :, :], 'DONOTUSE')) udn4000 = numpy.ma.MaskedArray( hdu['SPECINDEX'].data.copy()[specindex['Dn4000'], :, :], mask=numpy.invert( bm.flagged( hdu['SPECINDEX_MASK'].data[specindex['Dn4000'], :, :], 'UNRELIABLE'))) udn4000[numpy.invert(numpy.ma.getmaskarray(udn4000))] = 0.0 else: output_shape = spxflx.shape d4000 = numpy.ma.masked_all(output_shape) ud4000 = numpy.ma.masked_all(output_shape) dn4000 = numpy.ma.masked_all(output_shape) udn4000 = numpy.ma.masked_all(output_shape) # Get the limits to apply x_order = 1 if extent[0] < extent[1] else -1 Dx = x_order * (extent[1] - extent[0]) y_order = 1 if extent[2] < extent[3] else -1 Dy = y_order * (extent[3] - extent[2]) # Force the image panels to be square; assumes extent has the same units in # both dimensions. D = max(Dx, Dy) x_lim = (extent[0] + extent[1]) / 2 + D * x_order * numpy.array([-1, 1 ]) / 2 y_lim = (extent[2] + extent[3]) / 2 + D * y_order * numpy.array([-1, 1 ]) / 2 flux_lim = numpy.power(10, growth_lim(numpy.ma.log10(spxflx), 0.90, fac=1.05)) t = numpy.ma.append(numpy.ma.log10(spxsnr), numpy.ma.log10(binsnr)) snr_lim = numpy.power(10, growth_lim(t, 0.90, fac=1.05)) bin_lim = [numpy.ma.amin(binid), numpy.ma.amax(binid)] res_lim = numpy.power(10, growth_lim(numpy.ma.log10(scfres), 0.90, fac=1.05)) chi_lim = growth_lim(scrchi, 0.90, fac=1.05) t = numpy.ma.append(strvel, hagvel) vel_lim = growth_lim(t, 0.85, fac=1.10, midpoint=0.0) if vel_lim[0] < -350: vel_lim[0] = -350 if vel_lim[1] > 350: vel_lim[1] = 350 t = numpy.ma.append(numpy.ma.log10(strsig), numpy.ma.log10(hagsig)) sig_lim = numpy.power(10, growth_lim(t, 0.90, fac=1.05)) t = numpy.ma.append( numpy.ma.append(numpy.ma.log10(hasflx), numpy.ma.log10(hagflx)), numpy.ma.append(numpy.ma.log10(hbsflx), numpy.ma.log10(hbgflx))) # t = numpy.ma.log10(t) hflx_lim = numpy.power(10, growth_lim(t, 0.95, fac=1.10)) # hflx_lim = [ -0.3, 2.2 ] t = numpy.ma.append(d4000, dn4000) # d4000_lim = growth_lim(t, 0.90, 1.05) d4000_lim = [1.0, 2.5] font = {'size': 6} rc('font', **font) w, h = pyplot.figaspect(1) fig = pyplot.figure(figsize=(1.5 * w, 1.5 * h)) dx = 0.22 left = 0.05 top = 0.94 dw = 0.005 snr_levels = [0.5, 1.0, 1.5, 2.0] ax = init_ax(fig, [left, top - dx, dx, dx]) ax.set_xlim(x_lim) ax.set_ylim(y_lim) ax.xaxis.set_major_formatter(ticker.NullFormatter()) cax = fig.add_axes([left + dx * 0.65, top - 0.07 * dx, 0.27 * dx, 0.01]) cbticks = [flux_lim[0] * 1.1, flux_lim[1] / 1.1] masked_imshow(fig, ax, cax, spxflx, extent=extent, norm=colors.LogNorm(vmin=flux_lim[0], vmax=flux_lim[1]), cmap='YlGnBu_r', zorder=4, orientation='horizontal', contour_data=numpy.ma.log10(spxsnr), levels=snr_levels, cbticks=cbticks, cbformat=ticker.ScalarFormatter()) if fwhm is not None: ax.add_patch( map_beam_patch(extent, ax, fwhm=fwhm, facecolor='0.7', edgecolor='k', zorder=4)) ax.text(0.99, 0.05, r'g-band S (spx)', horizontalalignment='right', verticalalignment='center', transform=ax.transAxes) ax = init_ax(fig, [left + dx + dw, top - dx, dx, dx]) ax.set_xlim(x_lim) ax.set_ylim(y_lim) ax.xaxis.set_major_formatter(ticker.NullFormatter()) ax.yaxis.set_major_formatter(ticker.NullFormatter()) cax = fig.add_axes( [left + dx + dw + dx * 0.65, top - 0.07 * dx, 0.27 * dx, 0.01]) cbticks = [snr_lim[0] * 1.1, snr_lim[1] / 1.1] masked_imshow(fig, ax, cax, spxsnr, extent=extent, norm=colors.LogNorm(vmin=snr_lim[0], vmax=snr_lim[1]), cmap='YlGnBu_r', zorder=4, orientation='horizontal', contour_data=numpy.ma.log10(spxsnr), levels=snr_levels, cbticks=cbticks, cbformat=ticker.ScalarFormatter()) #'%.0f') if fwhm is not None: ax.add_patch( map_beam_patch(extent, ax, fwhm=fwhm, facecolor='0.7', edgecolor='k', zorder=4)) ax.text(0.99, 0.05, r'g-band S/N (spx)', horizontalalignment='right', verticalalignment='center', transform=ax.transAxes) # ax.text(1.0, 1.1, r'{0}-{1}; {2}'.format(plate,ifudesign, hdu['PRIMARY'].header['MANGAID']), # horizontalalignment='center', verticalalignment='center', transform=ax.transAxes, # fontsize=20) ax.text(1.0, 1.1, f'{cube.name}; {plan["key"]}', ha='center', va='center', transform=ax.transAxes, fontsize=20) ax = init_ax(fig, [left + 2 * dx + 2 * dw, top - dx, dx, dx]) ax.set_xlim(x_lim) ax.set_ylim(y_lim) ax.xaxis.set_major_formatter(ticker.NullFormatter()) ax.yaxis.set_major_formatter(ticker.NullFormatter()) cax = fig.add_axes( [left + 2 * dx + 2 * dw + dx * 0.65, top - 0.07 * dx, 0.27 * dx, 0.01]) masked_imshow(fig, ax, cax, binid[0, :, :], extent=extent, vmin=bin_lim[0], vmax=bin_lim[1], cmap='CMRmap', zorder=4, orientation='horizontal', contour_data=numpy.ma.log10(spxsnr), levels=snr_levels, cbformat=ticker.ScalarFormatter(), cbticks=bin_lim) if fwhm is not None: ax.add_patch( map_beam_patch(extent, ax, fwhm=fwhm, facecolor='0.7', edgecolor='k', zorder=4)) ax.text(0.99, 0.05, r'bin ID', horizontalalignment='right', verticalalignment='center', transform=ax.transAxes) ax = init_ax(fig, [left + 3 * dx + 3 * dw, top - dx, dx, dx]) ax.set_xlim(x_lim) ax.set_ylim(y_lim) ax.xaxis.set_major_formatter(ticker.NullFormatter()) ax.yaxis.set_major_formatter(ticker.NullFormatter()) cax = fig.add_axes( [left + 3 * dx + 3 * dw + dx * 0.65, top - 0.07 * dx, 0.27 * dx, 0.01]) cbticks = [snr_lim[0] * 1.1, snr_lim[1] / 1.1] masked_imshow(fig, ax, cax, binsnr, extent=extent, norm=colors.LogNorm(vmin=snr_lim[0], vmax=snr_lim[1]), cmap='YlGnBu_r', zorder=4, orientation='horizontal', contour_data=numpy.ma.log10(spxsnr), levels=snr_levels, cbticks=cbticks, cbformat=ticker.ScalarFormatter()) #'%.0f') if fwhm is not None: ax.add_patch( map_beam_patch(extent, ax, fwhm=fwhm, facecolor='0.7', edgecolor='k', zorder=4)) ax.text(0.99, 0.05, r'g-band S/N (bin)', horizontalalignment='right', verticalalignment='center', transform=ax.transAxes) ax = init_ax(fig, [left, top - 2 * dx - dw, dx, dx]) ax.set_xlim(x_lim) ax.set_ylim(y_lim) ax.xaxis.set_major_formatter(ticker.NullFormatter()) cax = fig.add_axes( [left + dx * 0.65, top - dx - dw - 0.07 * dx, 0.27 * dx, 0.01]) cbticks = [res_lim[0] * 1.1, res_lim[1] / 1.1] masked_imshow(fig, ax, cax, scfres, extent=extent, norm=colors.LogNorm(vmin=res_lim[0], vmax=res_lim[1]), cmap='inferno', zorder=4, orientation='horizontal', contour_data=numpy.ma.log10(spxsnr), levels=snr_levels, cbticks=cbticks, cbformat=ticker.ScalarFormatter()) #'%.0f') if fwhm is not None: ax.add_patch( map_beam_patch(extent, ax, fwhm=fwhm, facecolor='0.7', edgecolor='k', zorder=4)) ax.text(0.99, 0.05, r'pPXF Frac. Resid.', horizontalalignment='right', verticalalignment='center', transform=ax.transAxes) ax = init_ax(fig, [left + dx + dw, top - 2 * dx - dw, dx, dx]) ax.set_xlim(x_lim) ax.set_ylim(y_lim) ax.xaxis.set_major_formatter(ticker.NullFormatter()) ax.yaxis.set_major_formatter(ticker.NullFormatter()) cax = fig.add_axes([ left + dx + dw + dx * 0.65, top - dx - dw - 0.07 * dx, 0.27 * dx, 0.01 ]) cbticks = [ numpy.round(chi_lim[0] + 0.01, decimals=2), numpy.round(chi_lim[1] - 0.01, decimals=2) ] masked_imshow(fig, ax, cax, scrchi, extent=extent, vmin=chi_lim[0], vmax=chi_lim[1], cmap='inferno', zorder=4, orientation='horizontal', contour_data=numpy.ma.log10(spxsnr), levels=snr_levels, cbticks=cbticks, cbformat=ticker.ScalarFormatter()) #'%.0f') if fwhm is not None: ax.add_patch( map_beam_patch(extent, ax, fwhm=fwhm, facecolor='0.7', edgecolor='k', zorder=4)) ax.text(0.99, 0.05, r'${\rm pPXF}\ \chi^2_\nu$', horizontalalignment='right', verticalalignment='center', transform=ax.transAxes) ax = init_ax(fig, [left + 2 * dx + 2 * dw, top - 2 * dx - dw, dx, dx]) ax.set_xlim(x_lim) ax.set_ylim(y_lim) ax.xaxis.set_major_formatter(ticker.NullFormatter()) ax.yaxis.set_major_formatter(ticker.NullFormatter()) cax = fig.add_axes([ left + 2 * dx + 2 * dw + dx * 0.65, top - dx - dw - 0.07 * dx, 0.27 * dx, 0.01 ]) cbticks = [vel_lim[0] / 1.1, 0.0, vel_lim[1] / 1.1] masked_imshow(fig, ax, cax, strvel, extent=extent, vmin=vel_lim[0], vmax=vel_lim[1], cmap='RdBu_r', zorder=4, orientation='horizontal', contour_data=numpy.ma.log10(spxsnr), levels=snr_levels, cbticks=cbticks, cbformat=ticker.ScalarFormatter()) #'%.0f') if fwhm is not None: ax.add_patch( map_beam_patch(extent, ax, fwhm=fwhm, facecolor='0.7', edgecolor='k', zorder=4)) ax.text(0.99, 0.05, r'$V_\ast$', horizontalalignment='right', verticalalignment='center', transform=ax.transAxes) ax = init_ax(fig, [left + 3 * dx + 3 * dw, top - 2 * dx - dw, dx, dx]) ax.set_xlim(x_lim) ax.set_ylim(y_lim) ax.xaxis.set_major_formatter(ticker.NullFormatter()) ax.yaxis.set_major_formatter(ticker.NullFormatter()) cax = fig.add_axes([ left + 3 * dx + 3 * dw + dx * 0.65, top - dx - dw - 0.07 * dx, 0.27 * dx, 0.01 ]) cbticks = [ sig_lim[0] * 1.1, numpy.power(10, numpy.mean(numpy.log10(sig_lim))), sig_lim[1] / 1.1 ] masked_imshow(fig, ax, cax, strsig, extent=extent, norm=colors.LogNorm(vmin=sig_lim[0], vmax=sig_lim[1]), cmap='viridis', zorder=4, orientation='horizontal', contour_data=numpy.ma.log10(spxsnr), levels=snr_levels, cbticks=cbticks, cbformat=ticker.ScalarFormatter()) #'%.0f') if fwhm is not None: ax.add_patch( map_beam_patch(extent, ax, fwhm=fwhm, facecolor='0.7', edgecolor='k', zorder=4)) ax.text(0.99, 0.05, r'$\sigma_\ast$', horizontalalignment='right', verticalalignment='center', transform=ax.transAxes) ax = init_ax(fig, [left, top - 3 * dx - 2 * dw, dx, dx]) ax.set_xlim(x_lim) ax.set_ylim(y_lim) ax.xaxis.set_major_formatter(ticker.NullFormatter()) cax = fig.add_axes( [left + dx * 0.65, top - 2 * dx - 2 * dw - 0.07 * dx, 0.27 * dx, 0.01]) cbticks = [hflx_lim[0] * 1.1, hflx_lim[1] / 1.1] masked_imshow(fig, ax, cax, hasflx, extent=extent, norm=colors.LogNorm(vmin=hflx_lim[0], vmax=hflx_lim[1]), cmap='inferno', zorder=4, orientation='horizontal', contour_data=numpy.ma.log10(spxsnr), levels=snr_levels, cbticks=cbticks, cbformat=ticker.ScalarFormatter()) #'%.0f') if fwhm is not None: ax.add_patch( map_beam_patch(extent, ax, fwhm=fwhm, facecolor='0.7', edgecolor='k', zorder=4)) ax.text(0.99, 0.05, r'${\rm H}\alpha\ {\rm flux}$ (sum)', horizontalalignment='right', verticalalignment='center', transform=ax.transAxes) ax = init_ax(fig, [left + dx + dw, top - 3 * dx - 2 * dw, dx, dx]) ax.set_xlim(x_lim) ax.set_ylim(y_lim) ax.xaxis.set_major_formatter(ticker.NullFormatter()) ax.yaxis.set_major_formatter(ticker.NullFormatter()) cax = fig.add_axes([ left + dx + dw + dx * 0.65, top - 2 * dx - 2 * dw - 0.07 * dx, 0.27 * dx, 0.01 ]) cbticks = [hflx_lim[0] * 1.1, hflx_lim[1] / 1.1] masked_imshow(fig, ax, cax, hagflx, extent=extent, norm=colors.LogNorm(vmin=hflx_lim[0], vmax=hflx_lim[1]), cmap='inferno', zorder=4, orientation='horizontal', contour_data=numpy.ma.log10(spxsnr), levels=snr_levels, cbticks=cbticks, cbformat=ticker.ScalarFormatter()) #'%.0f') if fwhm is not None: ax.add_patch( map_beam_patch(extent, ax, fwhm=fwhm, facecolor='0.7', edgecolor='k', zorder=4)) ax.text(0.99, 0.05, r'${\rm H}\alpha\ {\rm flux}$ (Gauss)', horizontalalignment='right', verticalalignment='center', transform=ax.transAxes) ax = init_ax(fig, [left + 2 * dx + 2 * dw, top - 3 * dx - 2 * dw, dx, dx]) ax.set_xlim(x_lim) ax.set_ylim(y_lim) ax.xaxis.set_major_formatter(ticker.NullFormatter()) ax.yaxis.set_major_formatter(ticker.NullFormatter()) cax = fig.add_axes([ left + 2 * dx + 2 * dw + dx * 0.65, top - 2 * dx - 2 * dw - 0.07 * dx, 0.27 * dx, 0.01 ]) cbticks = [vel_lim[0] / 1.1, 0.0, vel_lim[1] / 1.1] masked_imshow(fig, ax, cax, hagvel, extent=extent, vmin=vel_lim[0], vmax=vel_lim[1], cmap='RdBu_r', zorder=4, orientation='horizontal', contour_data=numpy.ma.log10(spxsnr), levels=snr_levels, cbticks=cbticks, cbformat=ticker.ScalarFormatter()) #'%.0f') if fwhm is not None: ax.add_patch( map_beam_patch(extent, ax, fwhm=fwhm, facecolor='0.7', edgecolor='k', zorder=4)) ax.text(0.99, 0.05, r'$V_{{\rm H}\alpha}$', horizontalalignment='right', verticalalignment='center', transform=ax.transAxes) ax = init_ax(fig, [left + 3 * dx + 3 * dw, top - 3 * dx - 2 * dw, dx, dx]) ax.set_xlim(x_lim) ax.set_ylim(y_lim) ax.xaxis.set_major_formatter(ticker.NullFormatter()) ax.yaxis.set_major_formatter(ticker.NullFormatter()) cax = fig.add_axes([ left + 3 * dx + 3 * dw + dx * 0.65, top - 2 * dx - 2 * dw - 0.07 * dx, 0.27 * dx, 0.01 ]) cbticks = [ sig_lim[0] * 1.1, numpy.power(10, numpy.mean(numpy.log10(sig_lim))), sig_lim[1] / 1.1 ] masked_imshow(fig, ax, cax, hagsig, extent=extent, norm=colors.LogNorm(vmin=sig_lim[0], vmax=sig_lim[1]), cmap='viridis', zorder=4, orientation='horizontal', contour_data=numpy.ma.log10(spxsnr), levels=snr_levels, cbticks=cbticks, cbformat=ticker.ScalarFormatter()) #'%.0f') if fwhm is not None: ax.add_patch( map_beam_patch(extent, ax, fwhm=fwhm, facecolor='0.7', edgecolor='k', zorder=4)) ax.text(0.99, 0.05, r'$\sigma_{{\rm H}\alpha}$', horizontalalignment='right', verticalalignment='center', transform=ax.transAxes) ax = init_ax(fig, [left, top - 4 * dx - 3 * dw, dx, dx]) ax.set_xlim(x_lim) ax.set_ylim(y_lim) cax = fig.add_axes( [left + dx * 0.65, top - 3 * dx - 3 * dw - 0.07 * dx, 0.27 * dx, 0.01]) cbticks = [hflx_lim[0] * 1.1, hflx_lim[1] / 1.1] masked_imshow(fig, ax, cax, hbsflx, extent=extent, norm=colors.LogNorm(vmin=hflx_lim[0], vmax=hflx_lim[1]), cmap='inferno', zorder=4, orientation='horizontal', contour_data=numpy.ma.log10(spxsnr), levels=snr_levels, cbticks=cbticks, cbformat=ticker.ScalarFormatter()) #'%.0f') if fwhm is not None: ax.add_patch( map_beam_patch(extent, ax, fwhm=fwhm, facecolor='0.7', edgecolor='k', zorder=4)) ax.text(0.99, 0.05, r'${\rm H}\beta\ {\rm flux}$ (sum)', horizontalalignment='right', verticalalignment='center', transform=ax.transAxes) ax = init_ax(fig, [left + dx + dw, top - 4 * dx - 3 * dw, dx, dx]) ax.set_xlim(x_lim) ax.set_ylim(y_lim) ax.yaxis.set_major_formatter(ticker.NullFormatter()) cax = fig.add_axes([ left + dx + dw + dx * 0.65, top - 3 * dx - 3 * dw - 0.07 * dx, 0.27 * dx, 0.01 ]) cbticks = [hflx_lim[0] * 1.1, hflx_lim[1] / 1.1] masked_imshow(fig, ax, cax, hbgflx, extent=extent, norm=colors.LogNorm(vmin=hflx_lim[0], vmax=hflx_lim[1]), cmap='inferno', zorder=4, orientation='horizontal', contour_data=numpy.ma.log10(spxsnr), levels=snr_levels, cbticks=cbticks, cbformat=ticker.ScalarFormatter()) #'%.0f') if fwhm is not None: ax.add_patch( map_beam_patch(extent, ax, fwhm=fwhm, facecolor='0.7', edgecolor='k', zorder=4)) ax.text(0.99, 0.05, r'${\rm H}\beta\ {\rm flux}$ (Gauss)', horizontalalignment='right', verticalalignment='center', transform=ax.transAxes) ax = init_ax(fig, [left + 2 * dx + 2 * dw, top - 4 * dx - 3 * dw, dx, dx]) ax.set_xlim(x_lim) ax.set_ylim(y_lim) ax.yaxis.set_major_formatter(ticker.NullFormatter()) cax = fig.add_axes([ left + 2 * dx + 2 * dw + dx * 0.65, top - 3 * dx - 3 * dw - 0.07 * dx, 0.27 * dx, 0.01 ]) masked_imshow(fig, ax, cax, d4000, extent=extent, vmin=d4000_lim[0], vmax=d4000_lim[1], cmap='RdBu_r', zorder=4, orientation='horizontal', contour_data=numpy.ma.log10(spxsnr), levels=snr_levels, cbticks=d4000_lim, cbformat=ticker.ScalarFormatter()) if fwhm is not None: ax.add_patch( map_beam_patch(extent, ax, fwhm=fwhm, facecolor='0.7', edgecolor='k', zorder=4)) ax.text(0.99, 0.05, r'D4000', horizontalalignment='right', verticalalignment='center', transform=ax.transAxes) ax = init_ax(fig, [left + 3 * dx + 3 * dw, top - 4 * dx - 3 * dw, dx, dx]) ax.set_xlim(x_lim) ax.set_ylim(y_lim) ax.yaxis.set_major_formatter(ticker.NullFormatter()) cax = fig.add_axes([ left + 3 * dx + 3 * dw + dx * 0.65, top - 3 * dx - 3 * dw - 0.07 * dx, 0.27 * dx, 0.01 ]) masked_imshow(fig, ax, cax, dn4000, extent=extent, vmin=d4000_lim[0], vmax=d4000_lim[1], cmap='RdBu_r', zorder=4, orientation='horizontal', contour_data=numpy.ma.log10(spxsnr), levels=snr_levels, cbticks=d4000_lim, cbformat=ticker.ScalarFormatter()) if fwhm is not None: ax.add_patch( map_beam_patch(extent, ax, fwhm=fwhm, facecolor='0.7', edgecolor='k', zorder=4)) ax.text(0.99, 0.05, r'Dn4000', horizontalalignment='right', verticalalignment='center', transform=ax.transAxes) if ofile is not None: fig.canvas.print_figure(ofile, bbox_inches='tight') print('Writing: {0}'.format(ofile)) else: pyplot.show() fig.clear() pyplot.close(fig)
def stellar_continuum_scatter(plt, ifu, daptype, binid, snr, r68, r99, rchi2, signal, a, da, an, dan, gmr, t, dt, tn, dtn, svel, ssigo, ssigcor, ssigc, extent=None, ofile=None): snr_lim = numpy.power(10., growth_lim(numpy.ma.log10(snr), 1.00, fac=1.05)) snr_lim[0] = max(0.1, snr_lim[0]) r68_lim = numpy.power(10., growth_lim(numpy.ma.log10(r68), 0.90, fac=1.05)) r99_lim = numpy.power(10., growth_lim(numpy.ma.log10(r99), 0.90, fac=1.05)) chi_lim = growth_lim(rchi2, 0.90, fac=1.05) s_lim = numpy.power(10., growth_lim(numpy.ma.log10(signal), 1.00, fac=1.10)) a_lim = growth_lim(numpy.ma.log10(a), 0.99, fac=1.10) da_lim = growth_lim(numpy.ma.log10(da), 0.99, fac=1.10) an_lim = growth_lim(numpy.ma.log10(an), 1.00, fac=1.10) dan_lim = growth_lim(numpy.ma.log10(dan), 1.00, fac=1.10) an_lim = numpy.power(10, an_lim) dan_lim = numpy.power(10, dan_lim) gmr_lim = None if gmr is None else growth_lim(gmr, 0.95, fac=1.10) t_lim = growth_lim(numpy.ma.log10(t), 0.99, fac=1.10) dt_lim = growth_lim(numpy.ma.log10(dt), 0.99, fac=1.10) tn_lim = growth_lim(numpy.ma.log10(tn), 1.00, fac=1.10) dtn_lim = growth_lim(numpy.ma.log10(dtn), 1.00, fac=1.10) dtn_lim = numpy.power(10, dtn_lim) tn_lim = numpy.power(10, tn_lim) sv_lim = growth_lim(svel, 0.90, fac=1.2, midpoint=0) so_lim = numpy.power(10., growth_lim(numpy.ma.log10(ssigo), 1.00, fac=1.05)) sc_lim = growth_lim(ssigcor, 0.90, fac=1.05) ss_lim = numpy.power(10., growth_lim(numpy.ma.log10(ssigc), 0.90, fac=1.05)) # so_lim = [ min(so_lim[0],ss_lim[0]), max(so_lim[1],ss_lim[1]) ] # ss_lim = so_lim.copy() uniq, indx = numpy.unique(binid, return_index=True) if uniq[0] == -1: indx = indx[1:] # fig = pyplot.figure() # ax = fig.add_subplot(111, projection='3d') # # ax.scatter(numpy.ma.log10(dtn[indx]), numpy.ma.log10(dan[indx]), numpy.ma.log10(ssigo[indx]), # c=snr[indx], cmap='viridis', norm=colors.LogNorm(vmin=snr_lim[0], vmax=snr_lim[1])) # # ax.set_xlim(numpy.log10(dtn_lim)) # ax.set_ylim(numpy.log10(dan_lim)) # ax.set_zlim(numpy.log10(so_lim)) # sc = pyplot.scatter(dan[indx], ssigo[indx], marker='.', s=20, c=rchi2[indx], # cmap='viridis', vmin=chi_lim[0], vmax=chi_lim[1]) # sc = pyplot.scatter(snr[indx], ssigo[indx], marker='.', s=20, c=dan[indx], # cmap='viridis', norm=colors.LogNorm(vmin=numpy.amin(dan[indx]), vmax=numpy.amax(dan[indx]))) # sc = pyplot.scatter(signal[indx], dan[indx], marker='.', s=20, c=snr[indx], # cmap='viridis', norm=colors.LogNorm(vmin=snr_lim[0], vmax=snr_lim[1])) sc = pyplot.scatter(snr[indx], dan[indx], marker='.', s=20, c=ssigo[indx], cmap='viridis', norm=colors.LogNorm(vmin=so_lim[0], vmax=so_lim[1])) # sc = pyplot.scatter(dan[indx], ssigo[indx], marker='.', s=20, c=snr[indx], # cmap='viridis', norm=colors.LogNorm(vmin=snr_lim[0], vmax=snr_lim[1])) # sc = pyplot.scatter(dtn[indx], dan[indx], marker='.', s=20, c=snr[indx], # cmap='viridis', norm=colors.LogNorm(vmin=snr_lim[0], vmax=snr_lim[1])) cb = pyplot.colorbar(sc) ## pyplot.xlim(s_lim) pyplot.ylim(dan_lim) pyplot.xlim(snr_lim) pyplot.xscale('log') pyplot.yscale('log') pyplot.show() exit()
def stellar_continuum_maps(plt, ifu, daptype, snr, r68, r99, rchi2, signal, a, da, an, dan, gmr, t, dt, tn, dtn, svel, ssigo, ssigcor, ssigc, extent=None, ofile=None): font = {'size': 6} rc('font', **font) w, h = pyplot.figaspect(1) fig = pyplot.figure(figsize=(2 * w, 2 * h)) # Dx = (extent[0]-extent[1])*1.1 # x_lim = (extent[0]+extent[1])/2 + Dx*numpy.array([1,-1])/2 # Dy = (extent[2]-extent[3])*1.1 # y_lim = (extent[2]+extent[3])/2 + Dy*numpy.array([-1,1])/2 # ax.set_xlim(x_lim) # ax.set_ylim(y_lim) snr_lim = numpy.power(10., growth_lim(numpy.ma.log10(snr), 0.90, fac=1.05)) snr_lim[0] = max(0.1, snr_lim[0]) r68_lim = numpy.power(10., growth_lim(numpy.ma.log10(r68), 0.90, fac=1.05)) r99_lim = numpy.power(10., growth_lim(numpy.ma.log10(r99), 0.90, fac=1.05)) chi_lim = growth_lim(rchi2, 0.90, fac=1.05) s_lim = numpy.power(10., growth_lim(numpy.ma.log10(signal), 0.99, fac=1.05)) a_lim = growth_lim(numpy.ma.log10(a), 0.99, fac=1.05) da_lim = growth_lim(numpy.ma.log10(da), 0.99, fac=1.05) an_lim = growth_lim(numpy.ma.log10(an), 0.99, fac=1.05) dan_lim = growth_lim(numpy.ma.log10(dan), 0.99, fac=1.05) gmr_lim = None if gmr is None else growth_lim(gmr, 0.95, fac=1.10) t_lim = growth_lim(numpy.ma.log10(t), 0.99, fac=1.05) dt_lim = growth_lim(numpy.ma.log10(dt), 0.99, fac=1.05) tn_lim = growth_lim(numpy.ma.log10(tn), 0.99, fac=1.05) dtn_lim = growth_lim(numpy.ma.log10(dtn), 0.99, fac=1.05) sv_lim = growth_lim(svel, 0.90, fac=1.2, midpoint=0) so_lim = numpy.power(10., growth_lim(numpy.ma.log10(ssigo), 0.90, fac=1.10)) sc_lim = growth_lim(ssigcor, 0.90, fac=1.10) ss_lim = numpy.power(10., growth_lim(numpy.ma.log10(ssigc), 0.90, fac=1.10)) so_lim = [min(so_lim[0], ss_lim[0]), max(so_lim[1], ss_lim[1])] ss_lim = so_lim.copy() # so_lim = [10,400] # ss_lim = [10,400] # ------------------------------------------------------------------ # Layout left = 0.035 bott = 0.08 imwd = 0.18 hbuf = 0.06 cbuf = 0.005 cbwd = 0.01 vbuf = 0.03 # ------------------------------------------------------------------ # ------------------------------------------------------------------ # S/N i, j = 0, 3 ax = init_image_ax( fig, [left + i * (imwd + hbuf), bott + j * (imwd + vbuf), imwd, imwd]) cax = fig.add_axes([ left + i * (imwd + hbuf) + imwd + cbuf, bott + j * (imwd + vbuf), cbwd, imwd ]) # print(numpy.sum(snr.mask), numpy.prod(snr.shape), numpy.sum(snr.mask)/numpy.prod(snr.shape)) masked_imshow(fig, ax, cax, snr, extent=extent, norm=colors.LogNorm(vmin=snr_lim[0], vmax=snr_lim[1]), cmap='viridis', zorder=3, cbformat='%.1f', subs=(1., 2., 4.)) ax.set_xlim(extent[:2]) ax.set_ylim(extent[2:]) ax.add_patch( map_beam_patch(extent, ax, facecolor='0.7', edgecolor='k', zorder=4)) ax.text(0.1, 0.95, r'S/N', horizontalalignment='left', verticalalignment='center', transform=ax.transAxes) # ------------------------------------------------------------------ # 68th percentile of fractional residuals i, j = 1, 3 ax = init_image_ax( fig, [left + i * (imwd + hbuf), bott + j * (imwd + vbuf), imwd, imwd]) cax = fig.add_axes([ left + i * (imwd + hbuf) + imwd + cbuf, bott + j * (imwd + vbuf), cbwd, imwd ]) ax.yaxis.set_major_formatter(ticker.NullFormatter()) # print(numpy.sum(r68.mask), numpy.prod(r68.shape), numpy.sum(r68.mask)/numpy.prod(r68.shape)) masked_imshow(fig, ax, cax, r68, extent=extent, norm=colors.LogNorm(vmin=r68_lim[0], vmax=r68_lim[1]), cmap='viridis_r', zorder=3, cbformat='%.2f', subs=(1., 2., 4.)) ax.set_xlim(extent[:2]) ax.set_ylim(extent[2:]) ax.add_patch( map_beam_patch(extent, ax, facecolor='0.7', edgecolor='k', zorder=4)) ax.text(0.1, 0.95, r'68% Frac. Resid', horizontalalignment='left', verticalalignment='center', transform=ax.transAxes) # ax.text(0.5, 1.2, '{0}-{1}'.format(plt, ifu), horizontalalignment='center', # verticalalignment='center', transform=ax.transAxes, fontsize=12) # ax.text(0.5, 1.08, daptype, horizontalalignment='center', # verticalalignment='center', transform=ax.transAxes, fontsize=12) # ------------------------------------------------------------------ # 99th percentile of fractional residuals i, j = 2, 3 ax = init_image_ax( fig, [left + i * (imwd + hbuf), bott + j * (imwd + vbuf), imwd, imwd]) cax = fig.add_axes([ left + i * (imwd + hbuf) + imwd + cbuf, bott + j * (imwd + vbuf), cbwd, imwd ]) ax.yaxis.set_major_formatter(ticker.NullFormatter()) # print(numpy.sum(r99.mask), numpy.prod(r99.shape), numpy.sum(r99.mask)/numpy.prod(r99.shape)) masked_imshow(fig, ax, cax, r99, extent=extent, norm=colors.LogNorm(vmin=r99_lim[0], vmax=r99_lim[1]), cmap='viridis_r', zorder=3, cbformat='%.2f', subs=(1., 2., 4.)) ax.set_xlim(extent[:2]) ax.set_ylim(extent[2:]) ax.add_patch( map_beam_patch(extent, ax, facecolor='0.7', edgecolor='k', zorder=4)) ax.text(0.1, 0.95, r'99% Frac. Resid', horizontalalignment='left', verticalalignment='center', transform=ax.transAxes) # ------------------------------------------------------------------ # Reduced chi-square i, j = 3, 3 ax = init_image_ax( fig, [left + i * (imwd + hbuf), bott + j * (imwd + vbuf), imwd, imwd]) cax = fig.add_axes([ left + i * (imwd + hbuf) + imwd + cbuf, bott + j * (imwd + vbuf), cbwd, imwd ]) ax.yaxis.set_major_formatter(ticker.NullFormatter()) # print(numpy.sum(rchi2.mask), numpy.prod(rchi2.shape), # numpy.sum(rchi2.mask)/numpy.prod(rchi2.shape)) masked_imshow(fig, ax, cax, rchi2, extent=extent, vmin=chi_lim[0], vmax=chi_lim[1], cmap='viridis_r', zorder=3, cbformat='%.2f') ax.set_xlim(extent[:2]) ax.set_ylim(extent[2:]) ax.add_patch( map_beam_patch(extent, ax, facecolor='0.7', edgecolor='k', zorder=4)) ax.text(0.1, 0.95, r'$\chi^2_\nu$', horizontalalignment='left', verticalalignment='center', transform=ax.transAxes) # ------------------------------------------------------------------ # Signal i, j = 0, 2 ax = init_image_ax( fig, [left + i * (imwd + hbuf), bott + j * (imwd + vbuf), imwd, imwd]) cax = fig.add_axes([ left + i * (imwd + hbuf) + imwd + cbuf, bott + j * (imwd + vbuf), cbwd, imwd ]) # print(numpy.sum(signal.mask), numpy.prod(signal.shape), # numpy.sum(signal.mask)/numpy.prod(signal.shape)) masked_imshow(fig, ax, cax, signal, extent=extent, norm=colors.LogNorm(vmin=s_lim[0], vmax=s_lim[1]), cmap='viridis', zorder=3, cbformat='%.1f', subs=(1., 2., 4.)) ax.set_xlim(extent[:2]) ax.set_ylim(extent[2:]) ax.add_patch( map_beam_patch(extent, ax, facecolor='0.7', edgecolor='k', zorder=4)) ax.text(0.1, 0.95, r'$I_g$', horizontalalignment='left', verticalalignment='center', transform=ax.transAxes) # ------------------------------------------------------------------ # A i, j = 1, 2 ax = init_image_ax( fig, [left + i * (imwd + hbuf), bott + j * (imwd + vbuf), imwd, imwd]) cax = fig.add_axes([ left + i * (imwd + hbuf) + imwd + cbuf, bott + j * (imwd + vbuf), cbwd, imwd ]) ax.yaxis.set_major_formatter(ticker.NullFormatter()) lga = numpy.ma.log10(a) # print(numpy.sum(lga.mask), numpy.prod(lga.shape), numpy.sum(lga.mask)/numpy.prod(lga.shape)) masked_imshow(fig, ax, cax, lga, extent=extent, vmin=a_lim[0], vmax=a_lim[1], cmap='viridis', zorder=3, cbformat='%.1f') ax.set_xlim(extent[:2]) ax.set_ylim(extent[2:]) ax.add_patch( map_beam_patch(extent, ax, facecolor='0.7', edgecolor='k', zorder=4)) ax.text(0.1, 0.95, r'$\log A$', horizontalalignment='left', verticalalignment='center', transform=ax.transAxes) # ------------------------------------------------------------------ # Delta A i, j = 2, 2 ax = init_image_ax( fig, [left + i * (imwd + hbuf), bott + j * (imwd + vbuf), imwd, imwd]) cax = fig.add_axes([ left + i * (imwd + hbuf) + imwd + cbuf, bott + j * (imwd + vbuf), cbwd, imwd ]) ax.yaxis.set_major_formatter(ticker.NullFormatter()) lgan = numpy.ma.log10(an) # print(numpy.sum(lgan.mask), numpy.prod(lgan.shape), numpy.sum(lgan.mask)/numpy.prod(lgan.shape)) masked_imshow(fig, ax, cax, lgan, extent=extent, vmin=an_lim[0], vmax=an_lim[1], cmap='viridis_r', zorder=3, cbformat='%.1f') ax.set_xlim(extent[:2]) ax.set_ylim(extent[2:]) ax.add_patch( map_beam_patch(extent, ax, facecolor='0.7', edgecolor='k', zorder=4)) ax.text(0.1, 0.95, r'$\log A_n$', horizontalalignment='left', verticalalignment='center', transform=ax.transAxes) # ------------------------------------------------------------------ # Delta A/Ig i, j = 3, 2 ax = init_image_ax( fig, [left + i * (imwd + hbuf), bott + j * (imwd + vbuf), imwd, imwd]) cax = fig.add_axes([ left + i * (imwd + hbuf) + imwd + cbuf, bott + j * (imwd + vbuf), cbwd, imwd ]) ax.yaxis.set_major_formatter(ticker.NullFormatter()) lgdan = numpy.ma.log10(dan) # print(numpy.sum(lgdan.mask), numpy.prod(lgdan.shape), # numpy.sum(lgdan.mask)/numpy.prod(lgdan.shape)) masked_imshow(fig, ax, cax, lgdan, extent=extent, vmin=dan_lim[0], vmax=dan_lim[1], cmap='viridis_r', zorder=3, cbformat='%.1f') ax.set_xlim(extent[:2]) ax.set_ylim(extent[2:]) ax.add_patch( map_beam_patch(extent, ax, facecolor='0.7', edgecolor='k', zorder=4)) ax.text(0.1, 0.95, r'$\log(\delta A_n)$', horizontalalignment='left', verticalalignment='center', transform=ax.transAxes) # ------------------------------------------------------------------ # g-r Color i, j = 0, 1 ax = init_image_ax( fig, [left + i * (imwd + hbuf), bott + j * (imwd + vbuf), imwd, imwd]) cax = fig.add_axes([ left + i * (imwd + hbuf) + imwd + cbuf, bott + j * (imwd + vbuf), cbwd, imwd ]) # print(numpy.sum(gmr.mask), numpy.prod(gmr.shape), numpy.sum(gmr.mask)/numpy.prod(gmr.shape)) masked_imshow(fig, ax, cax, gmr, extent=extent, vmin=gmr_lim[0], vmax=gmr_lim[1], cmap='RdBu_r', zorder=3, cbformat='%.1f') ax.set_xlim(extent[:2]) ax.set_ylim(extent[2:]) ax.add_patch( map_beam_patch(extent, ax, facecolor='0.7', edgecolor='k', zorder=4)) ax.text(0.1, 0.95, r'$g-r$', horizontalalignment='left', verticalalignment='center', transform=ax.transAxes) # ------------------------------------------------------------------ # T i, j = 1, 1 ax = init_image_ax( fig, [left + i * (imwd + hbuf), bott + j * (imwd + vbuf), imwd, imwd]) cax = fig.add_axes([ left + i * (imwd + hbuf) + imwd + cbuf, bott + j * (imwd + vbuf), cbwd, imwd ]) ax.yaxis.set_major_formatter(ticker.NullFormatter()) lgt = numpy.ma.log10(t) # print(numpy.sum(lgt.mask), numpy.prod(lgt.shape), numpy.sum(lgt.mask)/numpy.prod(lgt.shape)) masked_imshow(fig, ax, cax, lgt, extent=extent, vmin=t_lim[0], vmax=t_lim[1], cmap='viridis', zorder=3, cbformat='%.1f') ax.set_xlim(extent[:2]) ax.set_ylim(extent[2:]) ax.add_patch( map_beam_patch(extent, ax, facecolor='0.7', edgecolor='k', zorder=4)) ax.text(0.1, 0.95, r'$\log T$', horizontalalignment='left', verticalalignment='center', transform=ax.transAxes) # ------------------------------------------------------------------ # Delta T i, j = 2, 1 ax = init_image_ax( fig, [left + i * (imwd + hbuf), bott + j * (imwd + vbuf), imwd, imwd]) cax = fig.add_axes([ left + i * (imwd + hbuf) + imwd + cbuf, bott + j * (imwd + vbuf), cbwd, imwd ]) ax.yaxis.set_major_formatter(ticker.NullFormatter()) lgtn = numpy.ma.log10(tn) # print(numpy.sum(lgtn.mask), numpy.prod(lgtn.shape), numpy.sum(lgtn.mask)/numpy.prod(lgtn.shape)) masked_imshow(fig, ax, cax, lgtn, extent=extent, vmin=tn_lim[0], vmax=tn_lim[1], cmap='viridis_r', zorder=3, cbformat='%.1f') ax.set_xlim(extent[:2]) ax.set_ylim(extent[2:]) ax.add_patch( map_beam_patch(extent, ax, facecolor='0.7', edgecolor='k', zorder=4)) ax.text(0.1, 0.95, r'$\log T_n$', horizontalalignment='left', verticalalignment='center', transform=ax.transAxes) # ------------------------------------------------------------------ # Delta T/Ig i, j = 3, 1 ax = init_image_ax( fig, [left + i * (imwd + hbuf), bott + j * (imwd + vbuf), imwd, imwd]) cax = fig.add_axes([ left + i * (imwd + hbuf) + imwd + cbuf, bott + j * (imwd + vbuf), cbwd, imwd ]) ax.yaxis.set_major_formatter(ticker.NullFormatter()) lgdtn = numpy.ma.log10(dtn) # print(numpy.sum(lgdtn.mask), numpy.prod(lgdtn.shape), # numpy.sum(lgdtn.mask)/numpy.prod(lgdtn.shape)) masked_imshow(fig, ax, cax, lgdtn, extent=extent, vmin=dtn_lim[0], vmax=dtn_lim[1], cmap='viridis_r', zorder=3, cbformat='%.1f') ax.set_xlim(extent[:2]) ax.set_ylim(extent[2:]) ax.add_patch( map_beam_patch(extent, ax, facecolor='0.7', edgecolor='k', zorder=4)) ax.text(0.1, 0.95, r'$\log \delta T_n$', horizontalalignment='left', verticalalignment='center', transform=ax.transAxes) # ------------------------------------------------------------------ # Stellar velocity i, j = 0, 0 ax = init_image_ax( fig, [left + i * (imwd + hbuf), bott + j * (imwd + vbuf), imwd, imwd]) cax = fig.add_axes([ left + i * (imwd + hbuf) + imwd + cbuf, bott + j * (imwd + vbuf), cbwd, imwd ]) # print(numpy.sum(svel.mask), numpy.prod(svel.shape), numpy.sum(svel.mask)/numpy.prod(svel.shape)) masked_imshow(fig, ax, cax, svel, extent=extent, vmin=sv_lim[0], vmax=sv_lim[1], cmap='RdBu_r', zorder=3, cbformat='%.0f') ax.set_xlim(extent[:2]) ax.set_ylim(extent[2:]) ax.add_patch( map_beam_patch(extent, ax, facecolor='0.7', edgecolor='k', zorder=4)) ax.text(0.1, 0.95, r'$V_\ast$ (km/s)', horizontalalignment='left', verticalalignment='center', transform=ax.transAxes) # ------------------------------------------------------------------ # Stellar sigma i, j = 1, 0 ax = init_image_ax( fig, [left + i * (imwd + hbuf), bott + j * (imwd + vbuf), imwd, imwd]) cax = fig.add_axes([ left + i * (imwd + hbuf) + imwd + cbuf, bott + j * (imwd + vbuf), cbwd, imwd ]) ax.yaxis.set_major_formatter(ticker.NullFormatter()) # print(numpy.sum(ssigo.mask), numpy.prod(ssigo.shape), # numpy.sum(ssigo.mask)/numpy.prod(ssigo.shape)) masked_imshow(fig, ax, cax, ssigo, extent=extent, norm=colors.LogNorm(vmin=so_lim[0], vmax=so_lim[1]), cmap='viridis', zorder=3, cbformat='%.0f', subs=(1., 2., 4.)) ax.set_xlim(extent[:2]) ax.set_ylim(extent[2:]) ax.add_patch( map_beam_patch(extent, ax, facecolor='0.7', edgecolor='k', zorder=4)) ax.text(0.1, 0.95, r'$\sigma_{\rm obs}$ (km/s)', horizontalalignment='left', verticalalignment='center', transform=ax.transAxes) # ------------------------------------------------------------------ # Sigma correction i, j = 2, 0 ax = init_image_ax( fig, [left + i * (imwd + hbuf), bott + j * (imwd + vbuf), imwd, imwd]) cax = fig.add_axes([ left + i * (imwd + hbuf) + imwd + cbuf, bott + j * (imwd + vbuf), cbwd, imwd ]) ax.yaxis.set_major_formatter(ticker.NullFormatter()) # print(numpy.sum(ssigcor.mask), numpy.prod(ssigcor.shape), # numpy.sum(ssigcor.mask)/numpy.prod(ssigcor.shape)) masked_imshow(fig, ax, cax, ssigcor, extent=extent, vmin=sc_lim[0], vmax=sc_lim[1], cmap='viridis', zorder=3, cbformat='%.0f') ax.set_xlim(extent[:2]) ax.set_ylim(extent[2:]) ax.add_patch( map_beam_patch(extent, ax, facecolor='0.7', edgecolor='k', zorder=4)) ax.text(0.1, 0.95, r'$\sigma_{\rm corr}$ (km/s)', horizontalalignment='left', verticalalignment='center', transform=ax.transAxes) # ------------------------------------------------------------------ # Corrected stellar sigma i, j = 3, 0 ax = init_image_ax( fig, [left + i * (imwd + hbuf), bott + j * (imwd + vbuf), imwd, imwd]) cax = fig.add_axes([ left + i * (imwd + hbuf) + imwd + cbuf, bott + j * (imwd + vbuf), cbwd, imwd ]) ax.yaxis.set_major_formatter(ticker.NullFormatter()) # print(numpy.sum(ssigc.mask), numpy.prod(ssigc.shape), # numpy.sum(ssigc.mask)/numpy.prod(ssigc.shape)) masked_imshow(fig, ax, cax, ssigo, extent=extent, norm=colors.LogNorm(vmin=ss_lim[0], vmax=ss_lim[1]), cmap='viridis', zorder=3, cbformat='%.0f', subs=(1., 2., 4.)) ax.set_xlim(extent[:2]) ax.set_ylim(extent[2:]) ax.add_patch( map_beam_patch(extent, ax, facecolor='0.7', edgecolor='k', zorder=4)) ax.text(0.1, 0.95, r'$\sigma_\ast$ (km/s)', horizontalalignment='left', verticalalignment='center', transform=ax.transAxes) if ofile is None: pyplot.show() else: print('Writing: {0}'.format(ofile)) fig.canvas.print_figure(ofile, bbox_inches='tight') fig.clear() pyplot.close(fig)
def radial_coverage_histogram(dapall, plot_file=None): # Get the range arcsec_rng = growth_lim(dapall['RCOV90'], 0.99, fac=1.1) rore = numpy.ma.divide(dapall['RCOV90'], dapall['NSA_ELPETRO_TH50_R']) rore[dapall['NSA_ELPETRO_TH50_R'] < 0] = numpy.ma.masked rore_rng = growth_lim(rore, 0.99, fac=1.1) # Determine the sample sdssMaskbits = sdss_maskbits_file() targ1bm = BitMask.from_par_file(sdssMaskbits, 'MANGA_TARGET1') ancillary = dapall['MNGTARG3'] > 0 primaryplus = targ1bm.flagged(dapall['MNGTARG1'], flag=['PRIMARY_v1_2_0', 'COLOR_ENHANCED_v1_2_0']) secondary = targ1bm.flagged(dapall['MNGTARG1'], flag='SECONDARY_v1_2_0') other = numpy.invert(ancillary) & numpy.invert(primaryplus) & numpy.invert(secondary) indx = dapall['RCOV90'] < 1 print('Num. of observations with 90% coverage <1 arcsec: {0}'.format(numpy.sum(indx))) print(dapall['PLATEIFU'][indx]) # Instantiate the figure w,h = pyplot.figaspect(1) fig = pyplot.figure(figsize=(1.5*w,1.5*h)) nlim = [0.8, 1000] # Show RCOV90 in terms of arcseconds for each IFU ax = init_ax(fig, [0.1, 0.58, 0.8, 0.4]) ax.set_ylim(nlim) ax.set_yscale('log', nonposy='clip') ifu = [ 19, 37, 61, 91, 127 ] for i,f in enumerate(ifu): indx = (dapall['IFUDESIGN']/100).astype(int) == f ax.hist(dapall['RCOV90'][indx], bins=50, range=arcsec_rng, alpha=0.5, histtype='stepfilled', color='C{0}'.format(i), zorder=2) ax.hist(dapall['RCOV90'][indx], bins=50, range=arcsec_rng, histtype='step', color='C{0}'.format(i), zorder=3) medp = numpy.median(dapall['RCOV90'][indx]) ax.plot([medp, medp], nlim, color='C{0}'.format(i), zorder=4, linestyle='--') ax.text(-0.1, 0.5, 'N', ha='center', va='center', transform=ax.transAxes, rotation='vertical') ax.text(0.5, -0.13, r'$R_{90}$ (arcsec)', ha='center', va='center', transform=ax.transAxes) ax.text(0.05, 0.95, '19-fiber', color='C0', ha='left', va='center', transform=ax.transAxes) ax.text(0.05, 0.90, '37-fiber', color='C1', ha='left', va='center', transform=ax.transAxes) ax.text(0.05, 0.85, '61-fiber', color='C2', ha='left', va='center', transform=ax.transAxes) ax.text(0.05, 0.80, '91-fiber', color='C3', ha='left', va='center', transform=ax.transAxes) ax.text(0.05, 0.75, '127-fiber', color='C4', ha='left', va='center', transform=ax.transAxes) # Show RCOV90 in terms of Re for each sample ax = init_ax(fig, [0.1, 0.08, 0.8, 0.4]) ax.set_ylim(nlim) ax.set_yscale('log', nonposy='clip') ax.hist(rore[primaryplus], bins=50, range=rore_rng, alpha=0.5, histtype='stepfilled', color='C0', zorder=2) ax.hist(rore[primaryplus], bins=50, range=rore_rng, histtype='step', color='C0', zorder=3) medp = numpy.median(rore[primaryplus]) ax.plot([medp, medp], nlim, color='C0', zorder=4, linestyle='--') ax.hist(rore[secondary], bins=50, range=rore_rng, alpha=0.5, histtype='stepfilled', color='C1', zorder=2) ax.hist(rore[secondary], bins=50, range=rore_rng, histtype='step', color='C1', zorder=3) medp = numpy.median(rore[secondary]) ax.plot([medp, medp], nlim, color='C1', zorder=4, linestyle='--') ax.hist(rore[other], bins=50, range=rore_rng, alpha=0.5, histtype='stepfilled', color='C2', zorder=2) ax.hist(rore[other], bins=50, range=rore_rng, histtype='step', color='C2', zorder=3) ax.hist(rore[ancillary], bins=50, range=rore_rng, alpha=0.5, histtype='stepfilled', color='C3', zorder=2) ax.hist(rore[ancillary], bins=50, range=rore_rng, histtype='step', color='C3', zorder=3) ax.text(-0.1, 0.5, 'N', ha='center', va='center', transform=ax.transAxes, rotation='vertical') ax.text(0.5, -0.12, r'$R_{90}/R_{eff}$', ha='center', va='center', transform=ax.transAxes) ax.text(0.05, 0.95, 'Primary+', color='C0', ha='left', va='center', transform=ax.transAxes) ax.text(0.05, 0.90, 'Secondary', color='C1', ha='left', va='center', transform=ax.transAxes) ax.text(0.05, 0.85, 'Other', color='C2', ha='left', va='center', transform=ax.transAxes) ax.text(0.05, 0.80, 'Ancillary', color='C3', ha='left', va='center', transform=ax.transAxes) if plot_file is None: pyplot.show() else: fig.canvas.print_figure(plot_file, bbox_inches='tight') fig.clear() pyplot.close(fig)
def spotcheck_images(analysis_path, daptype, plate, ifudesign, ofile=None, drpver=None, dapver=None): bm = DAPMapsBitMask() plan_dir = defaults.dap_method_path(daptype, plate=plate, ifudesign=ifudesign, drpver=drpver, dapver=dapver, analysis_path=analysis_path) ifile = os.path.join( plan_dir, 'manga-{0}-{1}-MAPS-{2}.fits.gz'.format(plate, ifudesign, daptype)) if not os.path.isfile(ifile): raise FileNotFoundError('No file: {0}'.format(ifile)) print('Reading: {0}'.format(ifile)) hdu = fits.open(ifile) # Check everything is finite num_ext = len(hdu) for i in range(num_ext): if hdu[i].data is None: continue if not numpy.all(numpy.isfinite(hdu[i].data)): raise ValueError('HDU {0} contains infs or NaNs!'.format( hdu[i].name)) # Build the column dictionaries emline = channel_dictionary(hdu, 'EMLINE_GFLUX') specindex = channel_dictionary(hdu, 'SPECINDEX') extent = map_extent(hdu, 'SPX_MFLUX') # Get the data to plot spxflx = numpy.ma.MaskedArray(hdu['SPX_MFLUX'].data.copy()) spxsnr = numpy.ma.MaskedArray(hdu['SPX_SNR'].data.copy()) binid = numpy.ma.MaskedArray(hdu['BINID'].data.copy(), mask=hdu['BINID'].data < 0) binsnr = numpy.ma.MaskedArray(hdu['BIN_SNR'].data.copy(), mask=hdu['BIN_MFLUX_MASK'].data > 0) # scfres = numpy.ma.MaskedArray(hdu['STELLAR_CONT_FRESID'].data.copy()[0,:,:], # mask=numpy.invert(hdu['STELLAR_CONT_FRESID'].data[0,:,:] > 0)) # #bm.flagged(hdu['STELLAR_VEL_MASK'].data, 'DONOTUSE')) # scrchi = numpy.ma.MaskedArray(hdu['STELLAR_CONT_RCHI2'].data.copy(), # mask=numpy.invert(hdu['STELLAR_CONT_RCHI2'].data > 0)) # #mask=bm.flagged(hdu['STELLAR_VEL_MASK'].data, 'DONOTUSE')) # 68% growth of the absolute value of the fractional residuals scfres = numpy.ma.MaskedArray( hdu['STELLAR_FOM'].data.copy()[3, :, :], mask=numpy.invert(hdu['STELLAR_FOM'].data[3, :, :] > 0)) # Reduced chi-square scrchi = numpy.ma.MaskedArray( hdu['STELLAR_FOM'].data.copy()[2, :, :], mask=numpy.invert(hdu['STELLAR_FOM'].data[2, :, :] > 0)) strvel = numpy.ma.MaskedArray(hdu['STELLAR_VEL'].data.copy(), mask=bm.flagged(hdu['STELLAR_VEL_MASK'].data, 'DONOTUSE')) ustrvel = numpy.ma.MaskedArray(hdu['STELLAR_VEL'].data.copy(), mask=numpy.invert( bm.flagged(hdu['STELLAR_VEL_MASK'].data, 'UNRELIABLE'))) ustrvel[numpy.invert(numpy.ma.getmaskarray(ustrvel))] = 0.0 strsig = numpy.ma.MaskedArray(hdu['STELLAR_SIGMA'].data.copy(), mask=bm.flagged( hdu['STELLAR_SIGMA_MASK'].data, 'DONOTUSE')) ustrsig = numpy.ma.MaskedArray(hdu['STELLAR_SIGMA'].data.copy(), mask=numpy.invert( bm.flagged( hdu['STELLAR_SIGMA_MASK'].data, 'UNRELIABLE'))) ustrsig[numpy.invert(numpy.ma.getmaskarray(ustrsig))] = 0.0 hasflx = numpy.ma.MaskedArray( hdu['EMLINE_SFLUX'].data.copy()[emline['Ha-6564'], :, :], mask=bm.flagged(hdu['EMLINE_SFLUX_MASK'].data[emline['Ha-6564'], :, :], 'DONOTUSE')) uhasflx = numpy.ma.MaskedArray( hdu['EMLINE_SFLUX'].data.copy()[emline['Ha-6564'], :, :], mask=numpy.invert( bm.flagged(hdu['EMLINE_SFLUX_MASK'].data[emline['Ha-6564'], :, :], 'UNRELIABLE'))) uhasflx[numpy.invert(numpy.ma.getmaskarray(uhasflx))] = 0.0 hagflx = numpy.ma.MaskedArray( hdu['EMLINE_GFLUX'].data.copy()[emline['Ha-6564'], :, :], mask=bm.flagged(hdu['EMLINE_GFLUX_MASK'].data[emline['Ha-6564'], :, :], 'DONOTUSE')) uhagflx = numpy.ma.MaskedArray( hdu['EMLINE_GFLUX'].data.copy()[emline['Ha-6564'], :, :], mask=numpy.invert( bm.flagged(hdu['EMLINE_GFLUX_MASK'].data[emline['Ha-6564'], :, :], 'UNRELIABLE'))) uhagflx[numpy.invert(numpy.ma.getmaskarray(uhagflx))] = 0.0 hagvel = numpy.ma.MaskedArray( hdu['EMLINE_GVEL'].data.copy()[emline['Ha-6564'], :, :], mask=bm.flagged(hdu['EMLINE_GVEL_MASK'].data[emline['Ha-6564'], :, :], 'DONOTUSE')) uhagvel = numpy.ma.MaskedArray( hdu['EMLINE_GVEL'].data.copy()[emline['Ha-6564'], :, :], mask=numpy.invert( bm.flagged(hdu['EMLINE_GVEL_MASK'].data[emline['Ha-6564'], :, :], 'UNRELIABLE'))) uhagvel[numpy.invert(numpy.ma.getmaskarray(uhagvel))] = 0.0 hagsig = numpy.ma.MaskedArray( hdu['EMLINE_GSIGMA'].data.copy()[emline['Ha-6564'], :, :], mask=bm.flagged( hdu['EMLINE_GSIGMA_MASK'].data[emline['Ha-6564'], :, :], 'DONOTUSE')) uhagsig = numpy.ma.MaskedArray( hdu['EMLINE_GSIGMA'].data.copy()[emline['Ha-6564'], :, :], mask=numpy.invert( bm.flagged(hdu['EMLINE_GSIGMA_MASK'].data[emline['Ha-6564'], :, :], 'UNRELIABLE'))) uhagsig[numpy.invert(numpy.ma.getmaskarray(uhagsig))] = 0.0 hbsflx = numpy.ma.MaskedArray( hdu['EMLINE_SFLUX'].data.copy()[emline['Hb-4862'], :, :], mask=bm.flagged(hdu['EMLINE_SFLUX_MASK'].data[emline['Hb-4862'], :, :], 'DONOTUSE')) uhbsflx = numpy.ma.MaskedArray( hdu['EMLINE_SFLUX'].data.copy()[emline['Hb-4862'], :, :], mask=numpy.invert( bm.flagged(hdu['EMLINE_SFLUX_MASK'].data[emline['Hb-4862'], :, :], 'UNRELIABLE'))) uhbsflx[numpy.invert(numpy.ma.getmaskarray(uhbsflx))] = 0.0 hbgflx = numpy.ma.MaskedArray( hdu['EMLINE_GFLUX'].data.copy()[emline['Hb-4862'], :, :], mask=bm.flagged(hdu['EMLINE_GFLUX_MASK'].data[emline['Hb-4862'], :, :], 'DONOTUSE')) uhbgflx = numpy.ma.MaskedArray( hdu['EMLINE_GFLUX'].data.copy()[emline['Hb-4862'], :, :], mask=numpy.invert( bm.flagged(hdu['EMLINE_GFLUX_MASK'].data[emline['Hb-4862'], :, :], 'UNRELIABLE'))) uhbgflx[numpy.invert(numpy.ma.getmaskarray(uhbgflx))] = 0.0 specindex_available = True try: if hdu['SPECINDEX'].data is None: pass except: warnings.warn('No spectral indices in maps file.') specindex_available = False if specindex_available: d4000 = numpy.ma.MaskedArray( hdu['SPECINDEX'].data.copy()[specindex['D4000'], :, :], mask=bm.flagged( hdu['SPECINDEX_MASK'].data[specindex['D4000'], :, :], 'DONOTUSE')) ud4000 = numpy.ma.MaskedArray( hdu['SPECINDEX'].data.copy()[specindex['D4000'], :, :], mask=numpy.invert( bm.flagged( hdu['SPECINDEX_MASK'].data[specindex['D4000'], :, :], 'UNRELIABLE'))) ud4000[numpy.invert(numpy.ma.getmaskarray(ud4000))] = 0.0 dn4000 = numpy.ma.MaskedArray( hdu['SPECINDEX'].data.copy()[specindex['Dn4000'], :, :], mask=bm.flagged( hdu['SPECINDEX_MASK'].data[specindex['Dn4000'], :, :], 'DONOTUSE')) udn4000 = numpy.ma.MaskedArray( hdu['SPECINDEX'].data.copy()[specindex['Dn4000'], :, :], mask=numpy.invert( bm.flagged( hdu['SPECINDEX_MASK'].data[specindex['Dn4000'], :, :], 'UNRELIABLE'))) udn4000[numpy.invert(numpy.ma.getmaskarray(udn4000))] = 0.0 else: output_shape = spxflx.shape d4000 = numpy.ma.masked_all(output_shape) ud4000 = numpy.ma.masked_all(output_shape) dn4000 = numpy.ma.masked_all(output_shape) udn4000 = numpy.ma.masked_all(output_shape) # Get the limits to apply flux_lim = numpy.power(10, growth_lim(numpy.ma.log10(spxflx), 0.90, fac=1.05)) t = numpy.ma.append(numpy.ma.log10(spxsnr), numpy.ma.log10(binsnr)) snr_lim = numpy.power(10, growth_lim(t, 0.90, fac=1.05)) bin_lim = [numpy.ma.amin(binid), numpy.ma.amax(binid)] res_lim = numpy.power(10, growth_lim(numpy.ma.log10(scfres), 0.90, fac=1.05)) chi_lim = growth_lim(scrchi, 0.90, fac=1.05) t = numpy.ma.append(strvel, hagvel) vel_lim = growth_lim(t, 0.85, fac=1.10, midpoint=0.0) if vel_lim[0] < -350: vel_lim[0] = -350 if vel_lim[1] > 350: vel_lim[1] = 350 t = numpy.ma.append(numpy.ma.log10(strsig), numpy.ma.log10(hagsig)) sig_lim = numpy.power(10, growth_lim(t, 0.90, fac=1.05)) t = numpy.ma.append( numpy.ma.append(numpy.ma.log10(hasflx), numpy.ma.log10(hagflx)), numpy.ma.append(numpy.ma.log10(hbsflx), numpy.ma.log10(hbgflx))) # t = numpy.ma.log10(t) hflx_lim = numpy.power(10, growth_lim(t, 0.95, fac=1.10)) # hflx_lim = [ -0.3, 2.2 ] t = numpy.ma.append(d4000, dn4000) # d4000_lim = growth_lim(t, 0.90, 1.05) d4000_lim = [1.0, 2.5] font = {'size': 6} rc('font', **font) w, h = pyplot.figaspect(1) fig = pyplot.figure(figsize=(1.5 * w, 1.5 * h)) dx = 0.22 left = 0.05 top = 0.94 dw = 0.005 snr_levels = [0.5, 1.0, 1.5, 2.0] ax = init_ax(fig, [left, top - dx, dx, dx]) ax.xaxis.set_major_formatter(ticker.NullFormatter()) cax = fig.add_axes([left + dx * 0.65, top - 0.07 * dx, 0.27 * dx, 0.01]) cbticks = [flux_lim[0] * 1.1, flux_lim[1] / 1.1] masked_imshow(fig, ax, cax, spxflx, extent=extent, norm=colors.LogNorm(vmin=flux_lim[0], vmax=flux_lim[1]), cmap='YlGnBu_r', zorder=4, orientation='horizontal', contour_data=numpy.ma.log10(spxsnr), levels=snr_levels, cbticks=cbticks, cbformat=ticker.ScalarFormatter()) ax.add_patch( map_beam_patch(extent, ax, facecolor='0.7', edgecolor='k', zorder=4)) ax.text(0.99, 0.05, r'g-band S (spx)', horizontalalignment='right', verticalalignment='center', transform=ax.transAxes) ax = init_ax(fig, [left + dx + dw, top - dx, dx, dx]) ax.xaxis.set_major_formatter(ticker.NullFormatter()) ax.yaxis.set_major_formatter(ticker.NullFormatter()) cax = fig.add_axes( [left + dx + dw + dx * 0.65, top - 0.07 * dx, 0.27 * dx, 0.01]) cbticks = [snr_lim[0] * 1.1, snr_lim[1] / 1.1] masked_imshow(fig, ax, cax, spxsnr, extent=extent, norm=colors.LogNorm(vmin=snr_lim[0], vmax=snr_lim[1]), cmap='YlGnBu_r', zorder=4, orientation='horizontal', contour_data=numpy.ma.log10(spxsnr), levels=snr_levels, cbticks=cbticks, cbformat=ticker.ScalarFormatter()) #'%.0f') ax.add_patch( map_beam_patch(extent, ax, facecolor='0.7', edgecolor='k', zorder=4)) ax.text(0.99, 0.05, r'g-band S/N (spx)', horizontalalignment='right', verticalalignment='center', transform=ax.transAxes) ax.text(1.0, 1.1, r'{0}-{1}; {2}'.format(plate, ifudesign, hdu['PRIMARY'].header['MANGAID']), horizontalalignment='center', verticalalignment='center', transform=ax.transAxes, fontsize=20) ax = init_ax(fig, [left + 2 * dx + 2 * dw, top - dx, dx, dx]) ax.xaxis.set_major_formatter(ticker.NullFormatter()) ax.yaxis.set_major_formatter(ticker.NullFormatter()) cax = fig.add_axes( [left + 2 * dx + 2 * dw + dx * 0.65, top - 0.07 * dx, 0.27 * dx, 0.01]) masked_imshow(fig, ax, cax, binid[0, :, :], extent=extent, vmin=bin_lim[0], vmax=bin_lim[1], cmap='CMRmap', zorder=4, orientation='horizontal', contour_data=numpy.ma.log10(spxsnr), levels=snr_levels, cbformat=ticker.ScalarFormatter(), cbticks=bin_lim) ax.add_patch( map_beam_patch(extent, ax, facecolor='0.7', edgecolor='k', zorder=4)) ax.text(0.99, 0.05, r'bin ID', horizontalalignment='right', verticalalignment='center', transform=ax.transAxes) ax = init_ax(fig, [left + 3 * dx + 3 * dw, top - dx, dx, dx]) ax.xaxis.set_major_formatter(ticker.NullFormatter()) ax.yaxis.set_major_formatter(ticker.NullFormatter()) cax = fig.add_axes( [left + 3 * dx + 3 * dw + dx * 0.65, top - 0.07 * dx, 0.27 * dx, 0.01]) cbticks = [snr_lim[0] * 1.1, snr_lim[1] / 1.1] masked_imshow(fig, ax, cax, binsnr, extent=extent, norm=colors.LogNorm(vmin=snr_lim[0], vmax=snr_lim[1]), cmap='YlGnBu_r', zorder=4, orientation='horizontal', contour_data=numpy.ma.log10(spxsnr), levels=snr_levels, cbticks=cbticks, cbformat=ticker.ScalarFormatter()) #'%.0f') ax.add_patch( map_beam_patch(extent, ax, facecolor='0.7', edgecolor='k', zorder=4)) ax.text(0.99, 0.05, r'g-band S/N (bin)', horizontalalignment='right', verticalalignment='center', transform=ax.transAxes) ax = init_ax(fig, [left, top - 2 * dx - dw, dx, dx]) ax.xaxis.set_major_formatter(ticker.NullFormatter()) cax = fig.add_axes( [left + dx * 0.65, top - dx - dw - 0.07 * dx, 0.27 * dx, 0.01]) cbticks = [res_lim[0] * 1.1, res_lim[1] / 1.1] masked_imshow(fig, ax, cax, scfres, extent=extent, norm=colors.LogNorm(vmin=res_lim[0], vmax=res_lim[1]), cmap='inferno', zorder=4, orientation='horizontal', contour_data=numpy.ma.log10(spxsnr), levels=snr_levels, cbticks=cbticks, cbformat=ticker.ScalarFormatter()) #'%.0f') ax.add_patch( map_beam_patch(extent, ax, facecolor='0.7', edgecolor='k', zorder=4)) ax.text(0.99, 0.05, r'pPXF Frac. Resid.', horizontalalignment='right', verticalalignment='center', transform=ax.transAxes) ax = init_ax(fig, [left + dx + dw, top - 2 * dx - dw, dx, dx]) ax.xaxis.set_major_formatter(ticker.NullFormatter()) ax.yaxis.set_major_formatter(ticker.NullFormatter()) cax = fig.add_axes([ left + dx + dw + dx * 0.65, top - dx - dw - 0.07 * dx, 0.27 * dx, 0.01 ]) cbticks = [ numpy.round(chi_lim[0] + 0.01, decimals=2), numpy.round(chi_lim[1] - 0.01, decimals=2) ] masked_imshow(fig, ax, cax, scrchi, extent=extent, vmin=chi_lim[0], vmax=chi_lim[1], cmap='inferno', zorder=4, orientation='horizontal', contour_data=numpy.ma.log10(spxsnr), levels=snr_levels, cbticks=cbticks, cbformat=ticker.ScalarFormatter()) #'%.0f') ax.add_patch( map_beam_patch(extent, ax, facecolor='0.7', edgecolor='k', zorder=4)) ax.text(0.99, 0.05, r'${\rm pPXF}\ \chi^2_\nu$', horizontalalignment='right', verticalalignment='center', transform=ax.transAxes) ax = init_ax(fig, [left + 2 * dx + 2 * dw, top - 2 * dx - dw, dx, dx]) ax.xaxis.set_major_formatter(ticker.NullFormatter()) ax.yaxis.set_major_formatter(ticker.NullFormatter()) cax = fig.add_axes([ left + 2 * dx + 2 * dw + dx * 0.65, top - dx - dw - 0.07 * dx, 0.27 * dx, 0.01 ]) cbticks = [vel_lim[0] / 1.1, 0.0, vel_lim[1] / 1.1] masked_imshow(fig, ax, cax, strvel, extent=extent, vmin=vel_lim[0], vmax=vel_lim[1], cmap='RdBu_r', zorder=4, orientation='horizontal', contour_data=numpy.ma.log10(spxsnr), levels=snr_levels, cbticks=cbticks, cbformat=ticker.ScalarFormatter()) #'%.0f') # im = ax.imshow(strvel, origin='lower', interpolation='nearest', cmap='RdBu_r', # zorder=4, extent=extent, vmin=vel_lim[0], vmax=vel_lim[1]) # im2 = ax.imshow(ustrvel, origin='lower', interpolation='nearest', cmap='Greens_r', # vmin=0, vmax=1, zorder=5, alpha=0.3, extent=extent) # cnt = ax.contour(numpy.ma.log10(spxsnr), origin='lower', extent=im.get_extent(), # colors='0.5', levels=snr_levels, linewidths=1.5, zorder=6) # pyplot.colorbar(im, cax=cax, orientation='horizontal', # ticks=[numpy.round(vel_lim[0]+1), numpy.round(vel_lim[1]-1)], format='%.0f') ax.add_patch( map_beam_patch(extent, ax, facecolor='0.7', edgecolor='k', zorder=4)) ax.text(0.99, 0.05, r'$V_\ast$', horizontalalignment='right', verticalalignment='center', transform=ax.transAxes) ax = init_ax(fig, [left + 3 * dx + 3 * dw, top - 2 * dx - dw, dx, dx]) ax.xaxis.set_major_formatter(ticker.NullFormatter()) ax.yaxis.set_major_formatter(ticker.NullFormatter()) cax = fig.add_axes([ left + 3 * dx + 3 * dw + dx * 0.65, top - dx - dw - 0.07 * dx, 0.27 * dx, 0.01 ]) cbticks = [ sig_lim[0] * 1.1, numpy.power(10, numpy.mean(numpy.log10(sig_lim))), sig_lim[1] / 1.1 ] masked_imshow(fig, ax, cax, strsig, extent=extent, norm=colors.LogNorm(vmin=sig_lim[0], vmax=sig_lim[1]), cmap='viridis', zorder=4, orientation='horizontal', contour_data=numpy.ma.log10(spxsnr), levels=snr_levels, cbticks=cbticks, cbformat=ticker.ScalarFormatter()) #'%.0f') # im = ax.imshow(numpy.ma.log10(strsig), origin='lower', interpolation='nearest', # cmap='viridis', zorder=4, extent=extent, vmin=sig_lim[0], vmax=sig_lim[1]) # im2 = ax.imshow(ustrsig, origin='lower', interpolation='nearest', cmap='Reds_r', # vmin=0, vmax=1, zorder=5, alpha=0.3, extent=extent) # cnt = ax.contour(numpy.ma.log10(spxsnr), origin='lower', extent=im.get_extent(), # colors='0.5', levels=snr_levels, linewidths=1.5, zorder=6) # pyplot.colorbar(im, cax=cax, orientation='horizontal', # ticks=[numpy.round(sig_lim[0]+0.1, decimals=1), # numpy.round(sig_lim[1]-0.1, decimals=1)], format='%.1f') ax.add_patch( map_beam_patch(extent, ax, facecolor='0.7', edgecolor='k', zorder=4)) ax.text(0.99, 0.05, r'$\sigma_\ast$', horizontalalignment='right', verticalalignment='center', transform=ax.transAxes) ax = init_ax(fig, [left, top - 3 * dx - 2 * dw, dx, dx]) ax.xaxis.set_major_formatter(ticker.NullFormatter()) cax = fig.add_axes( [left + dx * 0.65, top - 2 * dx - 2 * dw - 0.07 * dx, 0.27 * dx, 0.01]) cbticks = [hflx_lim[0] * 1.1, hflx_lim[1] / 1.1] masked_imshow(fig, ax, cax, hasflx, extent=extent, norm=colors.LogNorm(vmin=hflx_lim[0], vmax=hflx_lim[1]), cmap='inferno', zorder=4, orientation='horizontal', contour_data=numpy.ma.log10(spxsnr), levels=snr_levels, cbticks=cbticks, cbformat=ticker.ScalarFormatter()) #'%.0f') # im = ax.imshow(hasflx, origin='lower', interpolation='nearest', cmap='inferno', # zorder=4, extent=extent, vmin=hflx_lim[0], vmax=hflx_lim[1]) # im2 = ax.imshow(uhasflx, origin='lower', interpolation='nearest', cmap='Greens_r', # vmin=0, vmax=1, zorder=5, alpha=0.3, extent=extent) # cnt = ax.contour(numpy.ma.log10(spxsnr), origin='lower', extent=im.get_extent(), # colors='0.5', levels=snr_levels, linewidths=1.5, zorder=6) # pyplot.colorbar(im, cax=cax, orientation='horizontal', # ticks=[numpy.round(hflx_lim[0]+0.1, decimals=1), # numpy.round(hflx_lim[1]-0.1, decimals=1)], format='%.1f') ax.add_patch( map_beam_patch(extent, ax, facecolor='0.7', edgecolor='k', zorder=4)) ax.text(0.99, 0.05, r'${\rm H}\alpha\ {\rm flux}$ (sum)', horizontalalignment='right', verticalalignment='center', transform=ax.transAxes) ax = init_ax(fig, [left + dx + dw, top - 3 * dx - 2 * dw, dx, dx]) ax.xaxis.set_major_formatter(ticker.NullFormatter()) ax.yaxis.set_major_formatter(ticker.NullFormatter()) cax = fig.add_axes([ left + dx + dw + dx * 0.65, top - 2 * dx - 2 * dw - 0.07 * dx, 0.27 * dx, 0.01 ]) cbticks = [hflx_lim[0] * 1.1, hflx_lim[1] / 1.1] masked_imshow(fig, ax, cax, hagflx, extent=extent, norm=colors.LogNorm(vmin=hflx_lim[0], vmax=hflx_lim[1]), cmap='inferno', zorder=4, orientation='horizontal', contour_data=numpy.ma.log10(spxsnr), levels=snr_levels, cbticks=cbticks, cbformat=ticker.ScalarFormatter()) #'%.0f') # im = ax.imshow(hagflx, origin='lower', interpolation='nearest', cmap='inferno', # zorder=4, extent=extent, vmin=hflx_lim[0], vmax=hflx_lim[1]) # im2 = ax.imshow(uhagflx, origin='lower', interpolation='nearest', cmap='Greens_r', # vmin=0, vmax=1, zorder=5, alpha=0.3, extent=extent) # cnt = ax.contour(numpy.ma.log10(spxsnr), origin='lower', extent=im.get_extent(), # colors='0.5', levels=snr_levels, linewidths=1.5, zorder=6) # pyplot.colorbar(im, cax=cax, orientation='horizontal', # ticks=[numpy.round(hflx_lim[0]+0.1, decimals=1), # numpy.round(hflx_lim[1]-0.1, decimals=1)], format='%.1f') ax.add_patch( map_beam_patch(extent, ax, facecolor='0.7', edgecolor='k', zorder=4)) ax.text(0.99, 0.05, r'${\rm H}\alpha\ {\rm flux}$ (Gauss)', horizontalalignment='right', verticalalignment='center', transform=ax.transAxes) ax = init_ax(fig, [left + 2 * dx + 2 * dw, top - 3 * dx - 2 * dw, dx, dx]) ax.xaxis.set_major_formatter(ticker.NullFormatter()) ax.yaxis.set_major_formatter(ticker.NullFormatter()) cax = fig.add_axes([ left + 2 * dx + 2 * dw + dx * 0.65, top - 2 * dx - 2 * dw - 0.07 * dx, 0.27 * dx, 0.01 ]) cbticks = [vel_lim[0] / 1.1, 0.0, vel_lim[1] / 1.1] masked_imshow(fig, ax, cax, hagvel, extent=extent, vmin=vel_lim[0], vmax=vel_lim[1], cmap='RdBu_r', zorder=4, orientation='horizontal', contour_data=numpy.ma.log10(spxsnr), levels=snr_levels, cbticks=cbticks, cbformat=ticker.ScalarFormatter()) #'%.0f') # im = ax.imshow(hagvel, origin='lower', interpolation='nearest', cmap='RdBu_r', # zorder=4, extent=extent, vmin=vel_lim[0], vmax=vel_lim[1]) # im2 = ax.imshow(uhagvel, origin='lower', interpolation='nearest', cmap='Greens_r', # vmin=0, vmax=1, zorder=5, alpha=0.3, extent=extent) # cnt = ax.contour(numpy.ma.log10(spxsnr), origin='lower', extent=im.get_extent(), # colors='0.5', levels=snr_levels, linewidths=1.5, zorder=6) # pyplot.colorbar(im, cax=cax, orientation='horizontal', # ticks=[numpy.round(vel_lim[0]+1), numpy.round(vel_lim[1]-1)], format='%.0f') ax.add_patch( map_beam_patch(extent, ax, facecolor='0.7', edgecolor='k', zorder=4)) ax.text(0.99, 0.05, r'$V_{{\rm H}\alpha}$', horizontalalignment='right', verticalalignment='center', transform=ax.transAxes) ax = init_ax(fig, [left + 3 * dx + 3 * dw, top - 3 * dx - 2 * dw, dx, dx]) ax.xaxis.set_major_formatter(ticker.NullFormatter()) ax.yaxis.set_major_formatter(ticker.NullFormatter()) cax = fig.add_axes([ left + 3 * dx + 3 * dw + dx * 0.65, top - 2 * dx - 2 * dw - 0.07 * dx, 0.27 * dx, 0.01 ]) cbticks = [ sig_lim[0] * 1.1, numpy.power(10, numpy.mean(numpy.log10(sig_lim))), sig_lim[1] / 1.1 ] masked_imshow(fig, ax, cax, hagsig, extent=extent, norm=colors.LogNorm(vmin=sig_lim[0], vmax=sig_lim[1]), cmap='viridis', zorder=4, orientation='horizontal', contour_data=numpy.ma.log10(spxsnr), levels=snr_levels, cbticks=cbticks, cbformat=ticker.ScalarFormatter()) #'%.0f') # im = ax.imshow(numpy.ma.log10(hagsig), origin='lower', interpolation='nearest', # cmap='viridis', zorder=4, extent=extent, vmin=sig_lim[0], vmax=sig_lim[1]) # im2 = ax.imshow(uhagsig, origin='lower', interpolation='nearest', cmap='Reds_r', # vmin=0, vmax=1, zorder=5, alpha=0.3, extent=extent) # cnt = ax.contour(numpy.ma.log10(spxsnr), origin='lower', extent=im.get_extent(), # colors='0.5', levels=snr_levels, linewidths=1.5, zorder=6) # pyplot.colorbar(im, cax=cax, orientation='horizontal', # ticks=[numpy.round(sig_lim[0]+0.1, decimals=1), # numpy.round(sig_lim[1]-0.1, decimals=1)], format='%.1f') ax.add_patch( map_beam_patch(extent, ax, facecolor='0.7', edgecolor='k', zorder=4)) ax.text(0.99, 0.05, r'$\sigma_{{\rm H}\alpha}$', horizontalalignment='right', verticalalignment='center', transform=ax.transAxes) ax = init_ax(fig, [left, top - 4 * dx - 3 * dw, dx, dx]) cax = fig.add_axes( [left + dx * 0.65, top - 3 * dx - 3 * dw - 0.07 * dx, 0.27 * dx, 0.01]) cbticks = [hflx_lim[0] * 1.1, hflx_lim[1] / 1.1] masked_imshow(fig, ax, cax, hbsflx, extent=extent, norm=colors.LogNorm(vmin=hflx_lim[0], vmax=hflx_lim[1]), cmap='inferno', zorder=4, orientation='horizontal', contour_data=numpy.ma.log10(spxsnr), levels=snr_levels, cbticks=cbticks, cbformat=ticker.ScalarFormatter()) #'%.0f') # im = ax.imshow(hbsflx, origin='lower', interpolation='nearest', cmap='inferno', # zorder=4, extent=extent, vmin=hflx_lim[0], vmax=hflx_lim[1]) # im2 = ax.imshow(uhbsflx, origin='lower', interpolation='nearest', cmap='Greens_r', # vmin=0, vmax=1, zorder=5, alpha=0.3, extent=extent) # cnt = ax.contour(numpy.ma.log10(spxsnr), origin='lower', extent=im.get_extent(), # colors='0.5', levels=snr_levels, linewidths=1.5, zorder=6) # pyplot.colorbar(im, cax=cax, orientation='horizontal', # ticks=[numpy.round(hflx_lim[0]+0.1, decimals=1), # numpy.round(hflx_lim[1]-0.1, decimals=1)], format='%.1f') ax.add_patch( map_beam_patch(extent, ax, facecolor='0.7', edgecolor='k', zorder=4)) ax.text(0.99, 0.05, r'${\rm H}\beta\ {\rm flux}$ (sum)', horizontalalignment='right', verticalalignment='center', transform=ax.transAxes) ax = init_ax(fig, [left + dx + dw, top - 4 * dx - 3 * dw, dx, dx]) ax.yaxis.set_major_formatter(ticker.NullFormatter()) cax = fig.add_axes([ left + dx + dw + dx * 0.65, top - 3 * dx - 3 * dw - 0.07 * dx, 0.27 * dx, 0.01 ]) cbticks = [hflx_lim[0] * 1.1, hflx_lim[1] / 1.1] masked_imshow(fig, ax, cax, hbgflx, extent=extent, norm=colors.LogNorm(vmin=hflx_lim[0], vmax=hflx_lim[1]), cmap='inferno', zorder=4, orientation='horizontal', contour_data=numpy.ma.log10(spxsnr), levels=snr_levels, cbticks=cbticks, cbformat=ticker.ScalarFormatter()) #'%.0f') # im = ax.imshow(hbgflx, origin='lower', interpolation='nearest', cmap='inferno', # zorder=4, extent=extent, vmin=hflx_lim[0], vmax=hflx_lim[1]) # im2 = ax.imshow(uhbgflx, origin='lower', interpolation='nearest', cmap='Greens_r', # vmin=0, vmax=1, zorder=5, alpha=0.3, extent=extent) # cnt = ax.contour(numpy.ma.log10(spxsnr), origin='lower', extent=im.get_extent(), # colors='0.5', levels=snr_levels, linewidths=1.5, zorder=6) # pyplot.colorbar(im, cax=cax, orientation='horizontal', # ticks=[numpy.round(hflx_lim[0]+0.1, decimals=1), # numpy.round(hflx_lim[1]-0.1, decimals=1)], format='%.1f') ax.add_patch( map_beam_patch(extent, ax, facecolor='0.7', edgecolor='k', zorder=4)) ax.text(0.99, 0.05, r'${\rm H}\beta\ {\rm flux}$ (Gauss)', horizontalalignment='right', verticalalignment='center', transform=ax.transAxes) ax = init_ax(fig, [left + 2 * dx + 2 * dw, top - 4 * dx - 3 * dw, dx, dx]) ax.yaxis.set_major_formatter(ticker.NullFormatter()) cax = fig.add_axes([ left + 2 * dx + 2 * dw + dx * 0.65, top - 3 * dx - 3 * dw - 0.07 * dx, 0.27 * dx, 0.01 ]) masked_imshow(fig, ax, cax, d4000, extent=extent, vmin=d4000_lim[0], vmax=d4000_lim[1], cmap='RdBu_r', zorder=4, orientation='horizontal', contour_data=numpy.ma.log10(spxsnr), levels=snr_levels, cbticks=d4000_lim, cbformat=ticker.ScalarFormatter()) # im = ax.imshow(d4000, origin='lower', interpolation='nearest', cmap='RdBu_r', # zorder=4, extent=extent, vmin=d4000_lim[0], vmax=d4000_lim[1]) # im2 = ax.imshow(ud4000, origin='lower', interpolation='nearest', cmap='Greens_r', # vmin=0, vmax=1, zorder=5, alpha=0.3, extent=extent) # cnt = ax.contour(numpy.ma.log10(spxsnr), origin='lower', extent=im.get_extent(), # colors='0.5', levels=snr_levels, linewidths=1.5, zorder=6) # pyplot.colorbar(im, cax=cax, orientation='horizontal', ticks=d4000_lim, format='%.1f') ax.add_patch( map_beam_patch(extent, ax, facecolor='0.7', edgecolor='k', zorder=4)) ax.text(0.99, 0.05, r'D4000', horizontalalignment='right', verticalalignment='center', transform=ax.transAxes) ax = init_ax(fig, [left + 3 * dx + 3 * dw, top - 4 * dx - 3 * dw, dx, dx]) ax.yaxis.set_major_formatter(ticker.NullFormatter()) cax = fig.add_axes([ left + 3 * dx + 3 * dw + dx * 0.65, top - 3 * dx - 3 * dw - 0.07 * dx, 0.27 * dx, 0.01 ]) masked_imshow(fig, ax, cax, dn4000, extent=extent, vmin=d4000_lim[0], vmax=d4000_lim[1], cmap='RdBu_r', zorder=4, orientation='horizontal', contour_data=numpy.ma.log10(spxsnr), levels=snr_levels, cbticks=d4000_lim, cbformat=ticker.ScalarFormatter()) # im = ax.imshow(dn4000, origin='lower', interpolation='nearest', cmap='RdBu_r', # zorder=4, extent=extent, vmin=d4000_lim[0], vmax=d4000_lim[1]) # im2 = ax.imshow(udn4000, origin='lower', interpolation='nearest', cmap='Greens_r', # vmin=0, vmax=1, zorder=5, alpha=0.3, extent=extent) # cnt = ax.contour(numpy.ma.log10(spxsnr), origin='lower', extent=im.get_extent(), # colors='0.5', levels=snr_levels, linewidths=1.5, zorder=6) # pyplot.colorbar(im, cax=cax, orientation='horizontal', ticks=d4000_lim, format='%.1f') ax.add_patch( map_beam_patch(extent, ax, facecolor='0.7', edgecolor='k', zorder=4)) ax.text(0.99, 0.05, r'Dn4000', horizontalalignment='right', verticalalignment='center', transform=ax.transAxes) if ofile is not None: fig.canvas.print_figure(ofile, bbox_inches='tight') print('Writing: {0}'.format(ofile)) else: pyplot.show() fig.clear() pyplot.close(fig)