def return_data(whichdata, nc, time, y, x, thin_locs, P=None):
    if whichdata == "wind":
        uwind = 0.5 * (nc.variables["U"][time, :, y, x] + nc.variables["U"][time, :, y, x + 1])
        vwind = 0.5 * (nc.variables["V"][time, :, y, x] + nc.variables["V"][time, :, y + 1, x])
        return uwind[thin_locs], vwind[thin_locs]
    elif whichdata == "temp":
        theta = nc.variables["T"][time, :, y, x] + T_base
        T = theta * (P / P_bot) ** kappa - T_zero
        return T
    elif whichdata == "dwpt":
        w = nc.variables["QVAPOR"][time, :, y, x]
        Td = td(e(w, P))
        return Td
    else:
        print "Use valid variable."
def skewTPlot(nest, timetuple):
    """
     This is the method to use from the outside
     
     nest: The nesting level of the nc-file from WRF 
     time: The time for which to plot
    """
    nc = openWRF(nest)
    time = convert_time(nest, timetuple)
    _Nx, _Ny, _Nz, _longs, _lats, _dx, _dy, x, y = getDimensions(nc)

    plt.figure()
    _isotherms()
    _isobars()
    _dry_adiabats()
    _moist_adiabats()

    P = nc.variables["P"][time, :, y, x] + nc.variables["PB"][time, :, y, x]

    _windbarbs(nc, time, y, x, P)
    _temperature(nc, time, y, x, P)
    _dewpoint(nc, time, y, x, P)

    plt.axis([-40, 50, P_b, P_t])
    plt.xlabel("Temperature ($^{\circ}\! C$) at 1000hPa")
    xticks = np.arange(-40, 51, 5)
    plt.xticks(xticks, ["" if tick % 10 != 0 else str(tick) for tick in xticks])
    plt.ylabel("Pressure (hPa)")
    yticks = np.arange(P_bot, P_t - 1, -10 ** 4)
    plt.yticks(yticks, yticks / 100)

    sfcT = nc.variables["T2"][time, y, x] - T_zero
    sfcP = nc.variables["PSFC"][time, y, x]
    sfcW = nc.variables["Q2"][time, y, x]
    sfcTd = td(e(sfcW, sfcP))
    plt.suptitle(
        "Drybulb: %4.1f$^{\circ}\! C$  Dewpoint: %3.1f$^{\circ}\! C$  Pressure: %5.1f hPa" % (sfcT, sfcTd, 0.01 * sfcP),
        fontsize=10,
        x=0.5,
        y=0.03,
    )

    # plt.show()
    plt.savefig(outdir + naming + str(nest) + "_skewT.png")
    plt.title("Skew-T plot for (location)")
    plt.close()
def _dewpoint(nc, time, y, x, P, linestyle="dashed", color="black"):
    w = nc.variables["QVAPOR"][time, :, y, x]
    plt.semilogy(td(e(w, P)) + _skewnessTerm(P), P, basey=math.e, color=color, linestyle=linestyle, linewidth=1.5)