def f_observing_log(title="Observing log for each tile, for each band"):
    """
    Makes a graphical observing log.

    """

    tile_tables = filter_by_tile()[0]

    fig = plt.figure()

    for i, tile_table in zip(range(len(tile_tables)), tile_tables):

        # How do we J slice? BAND CUT
        j_tile_table = band_cut(tile_table, 'j')
        h_tile_table = band_cut(tile_table, 'h')
        k_tile_table = band_cut(tile_table, 'k')

        j_dates = list(set(j_tile_table.MEANMJDOBS))
        h_dates = list(set(h_tile_table.MEANMJDOBS))
        k_dates = list(set(k_tile_table.MEANMJDOBS))

        plt.plot(j_dates, 5/4+i*np.ones(len(j_dates)), 'b.')
        plt.plot(h_dates, 1+i*np.ones(len(h_dates)), 'g.')
        plt.plot(k_dates, 3/4+i*np.ones(len(k_dates)), 'r.')

    plt.xlabel("Modified Julian Date")
    plt.ylabel("Tile #", rotation='horizontal')
    plt.title(title)

    plt.ylim(1-1/3, 16+1/3)

    return fig
def f_observing_map():
    """
    Makes a map of observations and how many J, H, K band datapoints
    each tile has.

    """

    max_ra = maxvars.RA.max()
    min_ra = maxvars.RA.min()
    max_dec = maxvars.DEC.max()
    min_dec = maxvars.DEC.min()

    tile_size_ra = (max_ra - min_ra) / 4
    tile_size_dec = (max_dec - min_dec) / 4

    tile_spreadsheets = filter_by_tile()[1]

    fig = plt.figure(figsize=(6,6))

    ij_list = [(x, y) for x in range(4) for y in range(4)]

    text_params = {'horizontalalignment':'center',
                   'verticalalignment':'center'}

    # print the nice text and stuff
    for k, ij, tile_spreadsheet in zip(range(len(tile_spreadsheets)),
                                       ij_list, tile_spreadsheets):

        ra_i, dec_j = ij

        tile_ra = min_ra + tile_size_ra*ra_i + tile_size_ra/2
        tile_dec = min_dec + tile_size_dec*dec_j + tile_size_dec/2

        plt.text(np.degrees(tile_ra), np.degrees(tile_dec+tile_size_dec/4),
                 "Tile #%d" % (k+1), **text_params)
        plt.text(np.degrees(tile_ra), np.degrees(tile_dec+tile_size_dec/12),
                 "J: %3d" % tile_spreadsheet.N_j.max(), color='b',
                 **text_params)
        plt.text(np.degrees(tile_ra), np.degrees(tile_dec-tile_size_dec/12),
                 "H: %3d" % tile_spreadsheet.N_h.max(), color='g',
                 **text_params)
        plt.text(np.degrees(tile_ra), np.degrees(tile_dec-tile_size_dec/4),
                 "K: %3d" % tile_spreadsheet.N_k.max(), color='r', 
                 **text_params)


    physical_tile_size_ra = (max_ra - min_ra) / 3.88
    physical_tile_size_dec = (max_dec - min_dec) / 3.88

    # make the overlapping rectangles
    for k, ij in zip(range(len(ij_list)), ij_list):

        ra_i, dec_j = ij

        southeast_corner_ra = min_ra + 0.94*physical_tile_size_ra*ra_i
        southeast_corner_dec = min_dec + 0.94*physical_tile_size_dec*dec_j

        if ij == (0,0) or ij == (0,2) or ij == (2,0) or ij == (2,2):
            rectangle_params = {'color': '0.85',
                                'zorder':-10}
        else:
            rectangle_params = {'fill': False}
        
        plt.gca().add_patch(
            plt.Rectangle((np.degrees(southeast_corner_ra), 
                           np.degrees(southeast_corner_dec)),
                          np.degrees(physical_tile_size_ra), 
                          np.degrees(physical_tile_size_dec),
                          ec='k', **rectangle_params))

    northeast_corner = (np.degrees(maxvars.RA.max() + 0.001),
                        np.degrees(maxvars.DEC.max() + 0.001))

    southwest_corner = (np.degrees(maxvars.RA.min() - 0.001),
                        np.degrees(maxvars.DEC.min() - 0.001))    

    plt.xlim(northeast_corner[0], southwest_corner[0])
    plt.ylim(southwest_corner[1], northeast_corner[1])

    plt.xlabel("RA (deg)")
    plt.ylabel("Dec (deg)")

    return fig