for ii in range(nlocs):
        indx= (data['LOCATION'] == locs[ii])
        #l
        printline= '$%i^\circ$ ' % int(round(numpy.mean(data['GLON'][indx])))
        # # of data
        printline+= '& %i' % numpy.sum(indx)
        # # of data H < 12.2
        printline+= '& %i' % numpy.sum((data['LOCATION'] == locs[ii])*(data['HMAG'] < 12.2))
        # # of data 12.2 <= H < 12.8
        nn= numpy.sum((data['LOCATION'] == locs[ii])*(data['HMAG'] >= 12.2)*(data['HMAG'] < 12.8))
        if nn > 0:
            printline+= '& %i' % nn
        else:
            printline+= '& 0'
        # # of data 12.8 <= H < 13.8
        nn= numpy.sum((data['LOCATION'] == locs[ii])*(data['HMAG'] >= 12.8)*(data['HMAG'] < 13.8))
        if nn > 0: printline+= '& %i' % nn
        else: printline+= '& 0 '
        #median ak
        printline+= '& %.1f ' % numpy.median(data['AK'][indx])
        #median visits
        #printline+= '& %i ' % numpy.median(data['NVISITS'][indx])
        #Write the line
        if not ii == (nlocs-1): printline+= '\\\\\n'
        else: printline+= '\n'
        outfile.write(printline)
    outfile.close()

if __name__ == '__main__':
    fieldsTable(get_options())
        # # of data
        printline += '& %i' % numpy.sum(indx)
        # # of data H < 12.2
        printline += '& %i' % numpy.sum(
            (data['LOCATION'] == locs[ii]) * (data['HMAG'] < 12.2))
        # # of data 12.2 <= H < 12.8
        nn = numpy.sum((data['LOCATION'] == locs[ii]) *
                       (data['HMAG'] >= 12.2) * (data['HMAG'] < 12.8))
        if nn > 0:
            printline += '& %i' % nn
        else:
            printline += '& 0'
        # # of data 12.8 <= H < 13.8
        nn = numpy.sum((data['LOCATION'] == locs[ii]) *
                       (data['HMAG'] >= 12.8) * (data['HMAG'] < 13.8))
        if nn > 0: printline += '& %i' % nn
        else: printline += '& 0 '
        #median ak
        printline += '& %.1f ' % numpy.median(data['AK'][indx])
        #median visits
        #printline+= '& %i ' % numpy.median(data['NVISITS'][indx])
        #Write the line
        if not ii == (nlocs - 1): printline += '\\\\\n'
        else: printline += '\n'
        outfile.write(printline)
    outfile.close()


if __name__ == '__main__':
    fieldsTable(get_options())
    pyplot.ylim(-14.5,14.5)
    pyplot.xlim(0.,360.)
    bovy_plot._add_ticks()
    nullfmt   = NullFormatter()         # no labels
    axTop.xaxis.set_major_formatter(nullfmt)
    #pyplot.xlabel(r'$\mathrm{Galactic\ longitude}\ [\mathrm{deg}]$')
    pyplot.xlim(0.,360.)
    bovy_plot._add_ticks()
    #Plot the chi2
    fig.sca(axChi2)
    bovy_plot.bovy_plot([0.,360.],[0.,0.],'-',color='0.5',overplot=True)
    bovy_plot.bovy_plot(l_plate,
                        logl_plate,
                        'ko',overplot=True)
    pyplot.ylabel(r'$\Delta \chi^2$')
    #pyplot.ylim(numpy.amin(logl_plate),numpy.amax(logl_plate))
    pyplot.ylim(-150.,150.)
    pyplot.xlim(0.,360.)
    bovy_plot._add_ticks()
    pyplot.xlabel(r'$\mathrm{Galactic\ longitude}\ [\mathrm{deg}]$')
    pyplot.xlim(0.,360.)
    bovy_plot._add_ticks()
    #Save
    bovy_plot.bovy_end_print(options.plotfilename)
    return None

if __name__ == '__main__':
    numpy.random.seed(1) #We need to seed to get, e.g., the same permutation when downsampling
    plot_chi2(get_options())

    pyplot.ylim(-14.5, 14.5)
    pyplot.xlim(0., 360.)
    bovy_plot._add_ticks()
    nullfmt = NullFormatter()  # no labels
    axTop.xaxis.set_major_formatter(nullfmt)
    #pyplot.xlabel(r'$\mathrm{Galactic\ longitude}\ [\mathrm{deg}]$')
    pyplot.xlim(0., 360.)
    bovy_plot._add_ticks()
    #Plot the chi2
    fig.sca(axChi2)
    bovy_plot.bovy_plot([0., 360.], [0., 0.], '-', color='0.5', overplot=True)
    bovy_plot.bovy_plot(l_plate, logl_plate, 'ko', overplot=True)
    pyplot.ylabel(r'$\Delta \chi^2$')
    #pyplot.ylim(numpy.amin(logl_plate),numpy.amax(logl_plate))
    pyplot.ylim(-150., 150.)
    pyplot.xlim(0., 360.)
    bovy_plot._add_ticks()
    pyplot.xlabel(r'$\mathrm{Galactic\ longitude}\ [\mathrm{deg}]$')
    pyplot.xlim(0., 360.)
    bovy_plot._add_ticks()
    #Save
    bovy_plot.bovy_end_print(options.plotfilename)
    return None


if __name__ == '__main__':
    numpy.random.seed(
        1
    )  #We need to seed to get, e.g., the same permutation when downsampling
    plot_chi2(get_options())