def reco_energy_plot(config, out=False, batch=False): # Load median file information simBase = getSimBase(config) inFile = '%s_median.npy' % simBase d = np.load(inFile) d = d.item() xbins, ybins, ebins = d['xbins'], d['ybins'], d['ebins'] # Calculate median energy value from bin energies = d['medians'] energies = energies.T # Trim down the top of the grid ycts = energies.sum(axis=1) yidx = np.where(ycts==0)[0][0] + 2 ybins = ybins[:yidx] energies = energies[:yidx] emin, emax = energies[energies!=0].min(), energies[energies!=0].max() emin, emax = 3.75, 8 ebins = [emin] + getEbins() + [emax] fig = plt.figure(figsize=(8,6)) ax = fig.add_subplot(111) X, Y = np.meshgrid(xbins, ybins) cmap = plt.cm.jet cmap = cmap_discretize(cmap, ebins) cmap.set_under('white') tPars = {'fontsize':16} p = ax.pcolor(X, Y, energies, cmap=cmap, vmin=emin, vmax=emax) cb = fig.colorbar(p, ax=ax, ticks=ebins) cb.ax.set_yticklabels(['%.2f' % ebin for ebin in ebins]) cb.set_label(r'$\mathrm{log}_{10}(E/\mathrm{GeV})$', rotation=270, labelpad=20, **tPars) #ax.set_title('Median Energy vs Zenith and Nchannel') ax.set_xlabel(r'$\mathrm{cos}(\theta_\mathrm{reco})$', **tPars) ax.set_ylabel(r'$\mathrm{log}_{10}(N_\mathrm{channel})$', **tPars) ax.set_xlim(xbins.min(), xbins.max()) ax.set_ylim(ybins.min(), ybins.max()) if out != False: #outFile = '%s/%s_Median_Energy' % (outPrefix, config) plt.savefig(out, dpi=300, bbox_inches='tight') if not batch: plt.show()
def spline(config, inFile, outFile, plot=False): # Load input median file d = np.load(inFile) d = d.item() xbins, ybins = d['xbins'], d['ybins'] energies = d['medians'] vars = d['var'] vars[vars<1e-15] = np.inf # Variances sufficiently close to 0 aren't real w = 1/vars emin, emax = energies[energies!=0].min(), energies.max() ebins = [emin] + getEbins() + [emax] axes, knots = [],[] binList = [xbins, ybins] nknots = 30 step_scale = 2/5. for bins in binList: mids = (bins[1:]+bins[:-1])/2. axes += [mids] step = (bins.max() - bins.min()) * step_scale knots += [np.linspace(bins.min()-step, bins.max()+step, nknots)] tab = glam.fit(energies, w, axes, knots, order=(4), \ penalties={2:1e-3}) if plot: # Look at spline fit with finer binning fitaxes = [[],[]] fitaxes[0] = np.linspace(xbins.min(),xbins.max(),len(xbins)*3) fitaxes[1] = np.linspace(ybins.min(),ybins.max(),len(ybins)*3) fit = glam.grideval(tab, fitaxes) #err_fit = 10**glam.grideval(err_tab,axes) fig = plt.figure(figsize=(17,6)) mpl.rc("font", family="serif") X, Y = np.meshgrid(axes[0], axes[1]) fitX, fitY = np.meshgrid(fitaxes[0], fitaxes[1]) # Setup custom colormap cmap = plt.cm.jet cmap = cmap_discretize(cmap, ebins) cmap.set_under('white') ax = fig.add_subplot(121) p = ax.pcolor(fitX, fitY, fit.T, cmap=cmap, vmin=emin, vmax=emax) cb = fig.colorbar(p, ax=ax) ax.set_title('Median Energy') ax.set_xlabel('cos(zenith)') ax.set_ylabel('log10(Nchannel)') ax.set_xlim(xbins.min(), xbins.max()) ax.set_ylim(ybins.min(), ybins.max()) ax = fig.add_subplot(122) p = ax.pcolor(X, Y, energies.T, cmap=cmap, vmin=emin, vmax=emax) ax.set_title('Median Energy') ax.set_xlabel('cos(zenith)') ax.set_ylabel('log10(Nchannel)') ax.set_xlim(xbins.min(), xbins.max()) ax.set_ylim(ybins.min(), ybins.max()) plt.show() if outFile: if os.path.exists(outFile): os.remove(outFile) splinefitstable.write(tab, outFile)