コード例 #1
0
ファイル: test_loess_2d.py プロジェクト: kadubarbosa/groups
def test_loess_2d():
    """
    Usage example for loess_2d

    """
    n = 200
    x = np.random.uniform(-1,1,n)
    y = np.random.uniform(-1,1,n)
    z = x**2 - y**2
    sigz = 0.2
    zran = np.random.normal(z, sigz)

    zout, wout = loess_2d(x, y, zran)

    plt.clf()
    plt.subplot(131)
    plot_velfield(x, y, z)
    plt.title("Underlying Function")

    plt.subplot(132)
    plot_velfield(x, y, zran)
    plt.title("With Noise Added")

    plt.subplot(133)
    plot_velfield(x, y, zout)
    plt.title("LOESS Recovery")
    plt.pause(1)
コード例 #2
0
def plot_folded_cones(datasets, pas=None, dpa=22.5, use_err_max=True,
                      use_sn_min=False):
    """ Make azimuthal plots in radial sections. """
    # General setting for the plots
    colors = ("k", "w", "g", "w")
    symbols = ("o", "s", "^", None)
    ecolor = ("0.7", "0.7", "0.7", "1.0")
    ylims = [[3200, 5100], [0, 950], [-.3, .3], [-.2,.4]]
    xlims = [0, 360]
    ylabels = [r"$V_{\rm{LOS}}$ (km/s)", r"$\sigma_{\rm{LOS}}$ (km/s)",
               r"$h_3$", r"$h_4$"]
    mec = ("k", "r")
    names = ["rad_folded_vel", "rad_folded_sigma", "rad_folded_h3",
             "rad_folded_h4"]
    sn_min = [10, 10, 15, 15, 0]
    err_max = [100, 80, 0.1, 0.1]
    fs = _large_fig_settings()
    frac_loess = 0.3
    ##########################################################################
    # Set the default radius
    # Set the default position angles
    if pas is None:
        pas = np.linspace(0, 180, 5)[:-1] + pa0
    ##########################################################################
    for mm in range(4):
        fig = plt.figure(2, figsize=(fs["width"], fs["height"]))
        for j,pa in enumerate(pas):
            ###############################################################
            # Initialize axes
            # ax1 = plt.subplot(len(pas), 1, len(pas)-j)
            ax1 = plt.subplot(len(pas), 1, j + 1)
            ax1.minorticks_on()
            ax1.set_xlim(0, 40)
            ax2 = ax1.twiny()
            ax2.set_xlim(0, 40 / re)
            ax2.minorticks_on()
            #################################################################
            for i, d in enumerate(datasets):
                x, y, r, theta = d[:,:4].T
                moment = d[:,np.arange(4,12,2)[mm]].T
                error = np.clip(d[:,np.arange(5,13,2)[mm]].T, 0, 1000)
                sn = d[:,12]
                if i == 3:
                    idx = np.isfinite(moment)
                    x = x[idx]
                    y = y[idx]
                    r = r[idx]
                    theta = theta[idx]
                    moment = moment[idx]
                    error = error[idx]
                    sn = sn[idx]
                    loess = ll.loess_2d(x, y, moment, frac=frac_loess)
                else:
                    loess = moment
                data = np.column_stack((theta, moment, error, loess, r, sn))
                data = data[np.argsort(data[:,0])]
                datam = np.copy(data)
                datam[:,0] -= 360.
                datap = np.copy(data)
                datap[:,0] += 360
                data = np.vstack((datam, data, datap))
                ###############################################################
                # Select conic regions
                idx1 = np.argwhere((data[:,0] > pa - dpa) &
                                    (data[:,0] < pa + dpa)).ravel().tolist()
                idx2 = np.argwhere((data[:,0] > pa - dpa + 180) &
                                    (data[:,0] < pa + dpa + 180)).ravel().tolist()
                #==========================================================
                # Include central points of our dataset in all subplots
                if i in [0,3]:
                    idx1 += np.argwhere((data[:,0] > pa - 90) &
                                        (data[:,0] < pa + 90) &
                                        (data[:,4] < 8)).ravel().tolist()
                    idx2 += np.argwhere((data[:,0] > pa - 90 + 180) &
                                        (data[:,0] < pa + 90 + 180) &
                                        (data[:,4] < 4)).ravel().tolist()
                #==========================================================
                idx1 = np.unique(idx1)
                idx2 = np.unique(idx2)
                #=============================================================
                # S/N cut for our dataset
                if i == 0:
                    if use_sn_min:
                        idxsn = np.where(data[:,5] > sn_min[mm])
                        idx1 = np.intersect1d(idx1, idxsn)
                        idx2 = np.intersect1d(idx2, idxsn)
                    if use_err_max:
                        idx_err = np.where(data[:,2] < err_max[mm])
                        idx1 = np.intersect1d(idx1, idx_err)
                        idx2 = np.intersect1d(idx2, idx_err)
                #=============================================================
                ##############################################################
                for k, idx in enumerate([idx1, idx2]):
                    if not len(idx):
                        continue
                    subset = data[idx]
                    subset = subset[np.argsort(subset[:,4])]
                    ax1.errorbar(subset[:,4], subset[:,1], yerr=subset[:,2],
                                fmt=symbols[i], ecolor=ecolor[i], c=colors[k],
                                mec=mec[k], ms=9, zorder=-i, mew=1.2)
                    ax1.set_ylim(ylims[mm])
                    ax1.set_ylabel(ylabels[mm])
                    if i == 3:
                        ax1.plot(subset[:,4], subset[:,3], "-{0}".format(mec[k]))
                if mm > 1:
                    ax1.axhline(y=0, ls="--", c="k")
                # if j == 0:
                if j == len(pas) - 1:
                    ax1.set_xlabel("$R$ (kpc)")
                else:
                    ax1.xaxis.set_major_formatter(plt.NullFormatter())
                # if j == len(pas) -1:
                if j == 0:
                   ax2.set_xlabel("$ R / R_e$")
                else:
                   ax2.xaxis.set_major_formatter(plt.NullFormatter())
                ax1.annotate("PA={0:.1f}$\pm${1:.1f}$^{{\\rm o}}$".format(pa,
                            dpa), xy=(0.17, 0.8), xycoords='axes fraction',
                            fontsize=12, horizontalalignment='center',
                            verticalalignment='bottom',
                            color="k")
                ax1.annotate("PA={0:.1f}$\pm${1:.1f}$^{{\\rm o}}$".format(
                            pa+180, dpa), xy=(0.17, 0.68),
                            xycoords='axes fraction',
                            fontsize=12, horizontalalignment='center',
                            verticalalignment='bottom',
                            color="r")
        plt.subplots_adjust(left=fs["left"], right=fs["right"],
                        bottom=fs["bottom"], top=fs["top"],
                        hspace=fs["hspace"])
        plt.savefig(os.path.join(figures_dir, "{0}.png".format(names[mm])))
        plt.clf()
    return
コード例 #3
0
def plot_folded_rings(datasets, radius=None):
    """ Make azimuthal plots in radial sections. """
    # General setting for the plots
    symbols = ("o", "s", "^")
    ylims = [[3600, 4200], [100, 700], [-.3, .3], [-.3,.3]]
    xlims = [0, 360]
    ylabels = [r"$V_{\rm{LOS}}$ (km/s)", r"$\sigma_{\rm{LOS}}$ (km/s)",
               r"$h_3$", r"$h_4$"]
    mec = "0.7" # Grayscale level for bars and symbol edge colors
    names = ["pa_folded_vel", "pa_folded_sigma", "pa_folded_h3",
             "pa_folded_h4"]
    sn_min = [10, 10, 10, 10]
    sn = np.loadtxt(intable, usecols=(14,))
    sn = np.vstack((sn, sn, sn))
    fs = _large_fig_settings()
    frac_loess = 0.2
    ##########################################################################
    # Set the default radius
    if radius is None:
        radius = np.linspace(0,40,5)
    ##########################################################################
    for mm in range(4):
        fig = plt.figure(2, figsize=(fs["width"], fs["height"]))
        for j in range(len(radius) - 1):
            ###############################################################
            # Initialize axes
            ax = plt.subplot(len(radius)-1, 1, len(radius)-1-j)
            ax.minorticks_on()
            ax.set_xlim(pa0 - 90, pa0 + 90)
            ax2 = ax.twiny()
            ax2.set_xlim(pa0 + 90 + 180, pa0 - 90 + 180)
            ax2.minorticks_on()
            #################################################################
            rmin = radius[j]
            rmax = radius[j+1]
            for i, d in enumerate(datasets):
                x, y, r, theta = d[:,:4].T
                moment = d[:,np.arange(4,12,2)[mm]].T
                error = np.clip(d[:,np.arange(5,13,2)[mm]].T, 0, 1000)
                sn = d[:,12]
                if i == 0:
                    loess = ll.loess_2d(x, y, moment, frac=frac_loess)
                else:
                    loess = moment
                data = np.column_stack((theta, moment, error, loess, r, sn))
                data = data[np.argsort(data[:,0])]
                datam = np.copy(data)
                datam[:,0] -= 360.
                datap = np.copy(data)
                datap[:,0] += 360
                data = np.vstack((datam, data, datap))
                ###############################################################
                # Select regions
                idx = np.argwhere((data[:,4] >= rmin) & (data[:,4] < rmax))
                # S/N cut for our dataset
                if i == 0:
                    idxsn = np.where(data[:,5] > sn_min[mm])
                    idx = np.intersect1d(idx, idxsn)
                ##############################################################
                idx = idx.ravel()
                subset = data[idx]
                ax.errorbar(subset[:,0], subset[:,1], yerr=subset[:,2],
                            fmt=symbols[i], ecolor=mec, c="k",
                            mec="k", ms=9, zorder=-i, mew=1.2)
                ax2.errorbar(subset[:,0], subset[:,1], yerr=subset[:,2],
                        fmt=symbols[i], ecolor=mec, c="w",
                        mec="r", ms=9, zorder=-i, mew=1.2)
                if i == 0:
                    ax.plot(subset[:,0], subset[:,3], "-k")
                    ax2.plot(subset[:,0], subset[:,3], "-r")
            ax.set_ylim(ylims[mm])
            ax.set_ylabel(ylabels[mm])
            ax2.annotate("${0:.1f} \leq R$(kpc)$<{1:.1f}$".format(rmin,
                        rmax), xy=(0.22, 0.15), xycoords='axes fraction',
                        fontsize=14, horizontalalignment='center',
                        verticalalignment='bottom',
                        bbox=dict(boxstyle="round, pad=0.3", fc="w"),
                        alpha=1, zorder=3)
            if mm > 1:
                ax.axhline(y=0, ls="--", c="k")
            if j == 0:
                ax.set_xlabel("PA (degree)")
            else:
                ax.xaxis.set_major_formatter(plt.NullFormatter())
            for tl in ax2.get_xticklabels():
                tl.set_color('r')
            if j == len(radius) - 2:
               ax2.set_xlabel("PA (degree)", color="r")
            else:
               ax2.xaxis.set_major_formatter(plt.NullFormatter())
            ax.axvline(x=63, ls="--", c="k")

        plt.subplots_adjust(left=fs["left"], right=fs["right"],
                        bottom=fs["bottom"], top=fs["top"],
                        hspace=fs["hspace"])
        plt.savefig(os.path.join(figures_dir, "{0}.png".format(names[mm])))
        plt.clf()
    return
コード例 #4
0
ファイル: maps_losvd.py プロジェクト: kadubarbosa/hydra1
def make_kinematics():
    """ Make maps for kinematics individually. """
    # Read data values for vel, sigma, h3, h4
    data = np.loadtxt(outtable, usecols=(5,7,9,11)).T
    xall, yall, sn = np.loadtxt(outtable, usecols=(1,2,14,)).T
    ###############################################
    # Details of the maps
    names = [r"vel", r"sigma", r"h3", r"h4"]
    cb_label = [r"V$_{\rm LOS}$ (km/s)", r"$\sigma_{\rm LOS}$ (km/s)",
                r"$h_3$", r"$h_4$"]
    ##########################################################################
    # Limits of the maps
    lims = [[3750,4000], [150,500], [-0.08, 0.08], [-0.15, 0.15] ]
    ##########################################################################
    xcb = [0.068, 0.385, 0.705] # Position of colorbars
    ###############################################
    # Set the threshold S/N for smoothing
    # Higher values than this values are not smoothed
    sn_thres = [25., 25., 1000, 1000]
    ###############################################
    # Read values of other authors
    tab1a, tab1b = get_richtler()
    tab2 = get_ventimiglia()
    ###############################################
    # Loop for figures
    for i, vector in enumerate(data):
        print "Producing figure for {0}...".format(names[i])
        good = np.where(((~np.isnan(vector)) & (sn>sn_cut)))[0]
        sn_high = np.where(((~np.isnan(vector)) & (sn>=sn_thres[i])))[0]
        sn_low = np.delete(good, sn_high)
        vector_low = ll.loess_2d(xall[sn_low], yall[sn_low], vector[sn_low],
                                 frac=frac_loess)
        vector_high = vector[sn_high]
        good = np.hstack((sn_high, sn_low ))
        v_loess = np.hstack((vector_high, vector_low))
        v = vector[good]
        vmin = lims[i][0] if lims[i][0] else v_loess.min()
        vmax = lims[i][1] if lims[i][1] else v_loess.max()
        fig = plt.figure(figsize=(15, 5.1))
        gs = gridspec.GridSpec(1,3)
        gs.update(left=0.051, right=0.985, bottom=0.11, top=0.975, hspace=0.06,
                  wspace=0.06)
        vs = [v, v_loess, v_loess]
        ylabels = [1,0,0]
        contours = ["vband", "vband", "residual"]
        cb_fmts=["%i","%i", "%.2f", "%.2f"]
        ####################################################
        # Produces pannels
        ####################################################
        for j in range(3):
            ax = plt.subplot(gs[j])
            norm = Normalize(vmin=vmin, vmax=vmax)
            coll = PolyCollection(polygons_bins[good], array=vs[j],
                                  cmap="cubelaw",
                                  edgecolors='w', norm=norm, linewidths=0.4)
            draw_map(fig, ax, coll)
            draw_contours(contours[j], fig, ax)
            plt.gca().add_patch(Rectangle((18,-36),20,10, alpha=1, zorder=10000,
                                color="w"))
            draw_colorbar(fig, ax, coll, cblabel=cb_label[i],
                      cbar_pos=[xcb[j], 0.18, 0.08, 0.04],
                      ticks=np.linspace(vmin, vmax, 4), cb_fmt=cb_fmts[i])
            xylabels(ax, y=ylabels[j])
            if j > 0:
                ax.set_yticklabels([])
            #####################################################
            # Draw long slits of other papers
            #####################################################
            if i > 1:
                continue
            bc = ["g", "g", "b", "b"]
            for k, tab in enumerate([tab1a, tab1b, tab2[4:], tab2[:4]]):
                norm = Normalize(vmin=vmin, vmax=vmax)
                idx = np.argsort(tab[:,0])
                points = np.array([tab[:,0][idx], tab[:,1][idx]]).T.reshape(-1, 1, 2)
                segments = np.concatenate([points[:-1], points[1:]],
                                          axis=1)
                lc = LineCollection(segments, array=tab[:,i+2],
                                cmap="cubelaw", norm=norm, lw=5)
                ax.add_collection(lc)
                add_borders(ax, points, c=bc[k])
        # plt.savefig("figs/{0}.pdf".format(names[i]))
        plt.savefig("figs/{0}.png".format(names[i]))
コード例 #5
0
ファイル: maps_losvd.py プロジェクト: kadubarbosa/hydra1
def make_kin_summary(loess=False, contours="vband", format="png",
                     sn_lims=None, sn_loess=None, sn_sig=True):
    """ Make maps for the Lick indices in a single panel. """
    ##########################################################################
    # Set the limits for the S/N in case it is not defined by the user
    # sn_cut is defined in the setup_n3311 file
    if sn_lims == None:
        sn_lims = [sn_cut] * 4
    ##########################################################################
    # In case of LOESS smoothing, set the smoothing region (S/N < sn_loess)
    if sn_loess == None:
        sn_loess = [25,25,25,25]
    ##########################################################################
    # Read data values for Lick indices
    data = np.loadtxt(outtable, usecols=(5,7,9,11)).T
    # Read spectra name
    s = np.genfromtxt(outtable, usecols=(0,), dtype=None).tolist()
    ########################################################
    # Read coords and S/N
    xall, yall, sn = np.loadtxt(outtable, usecols=(1,2, 14)).T
    ##########################################################
    # If using S/N / sigma instead of S/N
    if sn_sig == True:
        sn /= data[1] / 100.
    ########################################################
    # Read values of other authors
    tab1a, tab1b = get_richtler()
    tab2 = get_ventimiglia()
    ###############################################
    # Details of the maps
    # Name to be displayed during processing
    titles = [r"velocity", r"sigma", r"h3", r"h4"]
    # Tex strings to be used in labels
    cb_label = [r"V$_{\rm LOS}$ [km/s]", r"$\sigma_{\rm LOS}$ [km/s]",
                r"$h_3$", r"$h_4$"]
    # Ranges of the plots
    lims = [[3750, 4000], [200, 500], [None, None], [None, None]]
    # Position of the colorbars
    xcb = [0.075, 0.555]
    xcb = xcb + xcb
    yc1 = 0.56
    yc2 = 0.085
    ycb = [yc1, yc1, yc2, yc2]
    # Colormap
    cmap = "cubelaw"
    ylabels = [1,0,1,0]
    xlabels = [0,0,1,1]
    cb_fmts = ["%d", "%d", "%.2f", "%.2f"]
    ###############################################
    # Initialize figure and subplots
    fig = plt.figure(figsize=(12.5, 12))
    gs = gridspec.GridSpec(2,2)
    gs.update(left=0.045, right=0.988, bottom=0.05, top=0.99, hspace=0.03,
              wspace=0.03)
    # Loop for figures
    for i, vector in enumerate(data):
        print "Producing figure for {0}...".format(titles[i])
        good = np.where(((~np.isnan(vector)) & (sn>sn_lims[i])))[0]
        if loess:
            sn_high = np.where(((~np.isnan(vector)) & (sn>=sn_loess[i])))[0]
            sn_low = np.delete(good, sn_high)
            vector_low = ll.loess_2d(xall[sn_low], yall[sn_low],
                                     vector[sn_low], frac=frac_loess)
            vector_high = vector[sn_high]
            good = np.hstack((sn_high, sn_low ))
            v = np.hstack((vector_high, vector_low))
        else:
            v = vector[good]
        mad =  1.4826 * np.median(np.abs(v - np.median(v)))
        ######################################################################
        # Set limits according to median deviation if not defined in lims
        vmin = np.median(v) - 1.5 * mad if lims[i][0] == None else lims[i][0]
        vmax = np.median(v) + 1.5 * mad if lims[i][0] == None else lims[i][1]
        norm = Normalize(vmin=vmin, vmax=vmax)
        ######################################################################
        ax = plt.subplot(gs[i])
        coll = PolyCollection(polygons_bins[good], array=v, cmap=cmap,
                              edgecolors='w', norm=norm)
        draw_map(fig, ax, coll)
        draw_contours(contours, fig, ax)
        plt.gca().add_patch(Rectangle((18,-36),20,10, alpha=1, zorder=1000,
                            color="w"))
        draw_colorbar(fig, ax, coll, cblabel=cb_label[i],
                  cbar_pos=[xcb[i], ycb[i], 0.09, 0.02],
                  ticks=np.linspace(vmin, vmax, 4), cb_fmt=cb_fmts[i],
                  labelsize=12)
        xylabels(ax, y=ylabels[i], x=xlabels[i])
        if i not in [0,2]:
            ax.set_yticklabels([])
        if i < 2:
           ax.set_xticklabels([])
        #####################################################
        # Draw long slits of other papers
        #####################################################
        if i > 1:
            continue
        for tab in [tab1a, tab1b, tab2]:
            norm = Normalize(vmin=lims[i][0], vmax=lims[i][1])
            points = np.array([tab[:,0], tab[:,1]]).T.reshape(-1, 1, 2)
            segments = np.concatenate([points[:-1], points[1:]],
                                      axis=1)
            lc = LineCollection(segments, array=tab[:,i+2],
                            cmap=cmap, norm=norm, linewidth=10, zorder=800,
                            edgecolor="w")
            ax.add_collection(lc)
    nloess = "_loess" if loess else ""
    plt.savefig("figs/kinmaps{0}_{1}.{2}".format(nloess, contours, format),
                dpi=100)
    return
コード例 #6
0
def make_kinematics():
    """ Make maps for kinematics individually. """
    # Read data values for vel, sigma, h3, h4
    data = np.loadtxt(outtable, usecols=(5, 7, 9, 11)).T
    xall, yall, sn = np.loadtxt(outtable, usecols=(
        1,
        2,
        14,
    )).T
    ###############################################
    # Details of the maps
    names = [r"vel", r"sigma", r"h3", r"h4"]
    cb_label = [
        r"V$_{\rm LOS}$ (km/s)", r"$\sigma_{\rm LOS}$ (km/s)", r"$h_3$",
        r"$h_4$"
    ]
    ##########################################################################
    # Limits of the maps
    lims = [[3750, 4000], [150, 500], [-0.08, 0.08], [-0.15, 0.15]]
    ##########################################################################
    xcb = [0.068, 0.385, 0.705]  # Position of colorbars
    ###############################################
    # Set the threshold S/N for smoothing
    # Higher values than this values are not smoothed
    sn_thres = [25., 25., 1000, 1000]
    ###############################################
    # Read values of other authors
    tab1a, tab1b = get_richtler()
    tab2 = get_ventimiglia()
    ###############################################
    # Loop for figures
    for i, vector in enumerate(data):
        print "Producing figure for {0}...".format(names[i])
        good = np.where(((~np.isnan(vector)) & (sn > sn_cut)))[0]
        sn_high = np.where(((~np.isnan(vector)) & (sn >= sn_thres[i])))[0]
        sn_low = np.delete(good, sn_high)
        vector_low = ll.loess_2d(xall[sn_low],
                                 yall[sn_low],
                                 vector[sn_low],
                                 frac=frac_loess)
        vector_high = vector[sn_high]
        good = np.hstack((sn_high, sn_low))
        v_loess = np.hstack((vector_high, vector_low))
        v = vector[good]
        vmin = lims[i][0] if lims[i][0] else v_loess.min()
        vmax = lims[i][1] if lims[i][1] else v_loess.max()
        fig = plt.figure(figsize=(15, 5.1))
        gs = gridspec.GridSpec(1, 3)
        gs.update(left=0.051,
                  right=0.985,
                  bottom=0.11,
                  top=0.975,
                  hspace=0.06,
                  wspace=0.06)
        vs = [v, v_loess, v_loess]
        ylabels = [1, 0, 0]
        contours = ["vband", "vband", "residual"]
        cb_fmts = ["%i", "%i", "%.2f", "%.2f"]
        ####################################################
        # Produces pannels
        ####################################################
        for j in range(3):
            ax = plt.subplot(gs[j])
            norm = Normalize(vmin=vmin, vmax=vmax)
            coll = PolyCollection(polygons_bins[good],
                                  array=vs[j],
                                  cmap="cubelaw",
                                  edgecolors='w',
                                  norm=norm,
                                  linewidths=0.4)
            draw_map(fig, ax, coll)
            draw_contours(contours[j], fig, ax)
            plt.gca().add_patch(
                Rectangle((18, -36), 20, 10, alpha=1, zorder=10000, color="w"))
            draw_colorbar(fig,
                          ax,
                          coll,
                          cblabel=cb_label[i],
                          cbar_pos=[xcb[j], 0.18, 0.08, 0.04],
                          ticks=np.linspace(vmin, vmax, 4),
                          cb_fmt=cb_fmts[i])
            xylabels(ax, y=ylabels[j])
            if j > 0:
                ax.set_yticklabels([])
            #####################################################
            # Draw long slits of other papers
            #####################################################
            if i > 1:
                continue
            bc = ["g", "g", "b", "b"]
            for k, tab in enumerate([tab1a, tab1b, tab2[4:], tab2[:4]]):
                norm = Normalize(vmin=vmin, vmax=vmax)
                idx = np.argsort(tab[:, 0])
                points = np.array([tab[:, 0][idx],
                                   tab[:, 1][idx]]).T.reshape(-1, 1, 2)
                segments = np.concatenate([points[:-1], points[1:]], axis=1)
                lc = LineCollection(segments,
                                    array=tab[:, i + 2],
                                    cmap="cubelaw",
                                    norm=norm,
                                    lw=5)
                ax.add_collection(lc)
                add_borders(ax, points, c=bc[k])
        # plt.savefig("figs/{0}.pdf".format(names[i]))
        plt.savefig("figs/{0}.png".format(names[i]))
コード例 #7
0
def make_kin_summary(loess=False,
                     contours="vband",
                     format="png",
                     sn_lims=None,
                     sn_loess=None,
                     sn_sig=True):
    """ Make maps for the Lick indices in a single panel. """
    ##########################################################################
    # Set the limits for the S/N in case it is not defined by the user
    # sn_cut is defined in the setup_n3311 file
    if sn_lims == None:
        sn_lims = [sn_cut] * 4
    ##########################################################################
    # In case of LOESS smoothing, set the smoothing region (S/N < sn_loess)
    if sn_loess == None:
        sn_loess = [25, 25, 25, 25]
    ##########################################################################
    # Read data values for Lick indices
    data = np.loadtxt(outtable, usecols=(5, 7, 9, 11)).T
    # Read spectra name
    s = np.genfromtxt(outtable, usecols=(0, ), dtype=None).tolist()
    ########################################################
    # Read coords and S/N
    xall, yall, sn = np.loadtxt(outtable, usecols=(1, 2, 14)).T
    ##########################################################
    # If using S/N / sigma instead of S/N
    if sn_sig == True:
        sn /= data[1] / 100.
    ########################################################
    # Read values of other authors
    tab1a, tab1b = get_richtler()
    tab2 = get_ventimiglia()
    ###############################################
    # Details of the maps
    # Name to be displayed during processing
    titles = [r"velocity", r"sigma", r"h3", r"h4"]
    # Tex strings to be used in labels
    cb_label = [
        r"V$_{\rm LOS}$ [km/s]", r"$\sigma_{\rm LOS}$ [km/s]", r"$h_3$",
        r"$h_4$"
    ]
    # Ranges of the plots
    lims = [[3750, 4000], [200, 500], [None, None], [None, None]]
    # Position of the colorbars
    xcb = [0.075, 0.555]
    xcb = xcb + xcb
    yc1 = 0.56
    yc2 = 0.085
    ycb = [yc1, yc1, yc2, yc2]
    # Colormap
    cmap = "cubelaw"
    ylabels = [1, 0, 1, 0]
    xlabels = [0, 0, 1, 1]
    cb_fmts = ["%d", "%d", "%.2f", "%.2f"]
    ###############################################
    # Initialize figure and subplots
    fig = plt.figure(figsize=(12.5, 12))
    gs = gridspec.GridSpec(2, 2)
    gs.update(left=0.045,
              right=0.988,
              bottom=0.05,
              top=0.99,
              hspace=0.03,
              wspace=0.03)
    # Loop for figures
    for i, vector in enumerate(data):
        print "Producing figure for {0}...".format(titles[i])
        good = np.where(((~np.isnan(vector)) & (sn > sn_lims[i])))[0]
        if loess:
            sn_high = np.where(((~np.isnan(vector)) & (sn >= sn_loess[i])))[0]
            sn_low = np.delete(good, sn_high)
            vector_low = ll.loess_2d(xall[sn_low],
                                     yall[sn_low],
                                     vector[sn_low],
                                     frac=frac_loess)
            vector_high = vector[sn_high]
            good = np.hstack((sn_high, sn_low))
            v = np.hstack((vector_high, vector_low))
        else:
            v = vector[good]
        mad = 1.4826 * np.median(np.abs(v - np.median(v)))
        ######################################################################
        # Set limits according to median deviation if not defined in lims
        vmin = np.median(v) - 1.5 * mad if lims[i][0] == None else lims[i][0]
        vmax = np.median(v) + 1.5 * mad if lims[i][0] == None else lims[i][1]
        norm = Normalize(vmin=vmin, vmax=vmax)
        ######################################################################
        ax = plt.subplot(gs[i])
        coll = PolyCollection(polygons_bins[good],
                              array=v,
                              cmap=cmap,
                              edgecolors='w',
                              norm=norm)
        draw_map(fig, ax, coll)
        draw_contours(contours, fig, ax)
        plt.gca().add_patch(
            Rectangle((18, -36), 20, 10, alpha=1, zorder=1000, color="w"))
        draw_colorbar(fig,
                      ax,
                      coll,
                      cblabel=cb_label[i],
                      cbar_pos=[xcb[i], ycb[i], 0.09, 0.02],
                      ticks=np.linspace(vmin, vmax, 4),
                      cb_fmt=cb_fmts[i],
                      labelsize=12)
        xylabels(ax, y=ylabels[i], x=xlabels[i])
        if i not in [0, 2]:
            ax.set_yticklabels([])
        if i < 2:
            ax.set_xticklabels([])
        #####################################################
        # Draw long slits of other papers
        #####################################################
        if i > 1:
            continue
        for tab in [tab1a, tab1b, tab2]:
            norm = Normalize(vmin=lims[i][0], vmax=lims[i][1])
            points = np.array([tab[:, 0], tab[:, 1]]).T.reshape(-1, 1, 2)
            segments = np.concatenate([points[:-1], points[1:]], axis=1)
            lc = LineCollection(segments,
                                array=tab[:, i + 2],
                                cmap=cmap,
                                norm=norm,
                                linewidth=10,
                                zorder=800,
                                edgecolor="w")
            ax.add_collection(lc)
    nloess = "_loess" if loess else ""
    plt.savefig("figs/kinmaps{0}_{1}.{2}".format(nloess, contours, format),
                dpi=100)
    return