Estimate a UCD's bolometric luminosity given some basic parameters.

    sptnum: the spectral type as a number; 8 -> M8; 10 -> L0 ; 20 -> T0
      Valid values range between 0 and 30, ie M0 to Y0.
    dist_pc: distance to the object in parsecs
    jmag: object's J-band magnitude or NaN (*not* None) if unavailable
    kmag: same with K-band magnitude
    format: either 'cgs', 'logcgs', or 'logsun', defining the form of the
      outputs. Logarithmic quantities are base 10.

    This routine can be used with vectors of measurements. The result will be
    NaN if a value cannot be computed. This routine implements the method
    documented in the Appendix of Williams et al., 2014ApJ...785....9W
    (doi:10.1088/0004-637X/785/1/9).

def lbol_from_spt_dist_mag (sptnum, dist_pc, jmag, kmag, format='cgs'):
    """Estimate a UCD's bolometric luminosity given some basic parameters.

    sptnum: the spectral type as a number; 8 -> M8; 10 -> L0 ; 20 -> T0
      Valid values range between 0 and 30, ie M0 to Y0.
    dist_pc: distance to the object in parsecs
    jmag: object's J-band magnitude or NaN (*not* None) if unavailable
    kmag: same with K-band magnitude
    format: either 'cgs', 'logcgs', or 'logsun', defining the form of the
      outputs. Logarithmic quantities are base 10.

    This routine can be used with vectors of measurements. The result will be
    NaN if a value cannot be computed. This routine implements the method
    documented in the Appendix of Williams et al., 2014ApJ...785....9W
    (doi:10.1088/0004-637X/785/1/9).

    """
    bcj = bcj_from_spt (sptnum)
    bck = bck_from_spt (sptnum)

    n = np.zeros (sptnum.shape, dtype=np.int)
    app_mbol = np.zeros (sptnum.shape)

    w = np.isfinite (bcj) & np.isfinite (jmag)
    app_mbol[w] += jmag[w] + bcj[w]
    n[w] += 1

    w = np.isfinite (bck) & np.isfinite (kmag)
    app_mbol[w] += kmag[w] + bck[w]
    n[w] += 1

    w = (n != 0)
    abs_mbol = (app_mbol[w] / n[w]) - 5 * (np.log10 (dist_pc[w]) - 1)
    # note: abs_mbol is filtered by `w`

    lbol = np.empty (sptnum.shape)
    lbol.fill (np.nan)
    lbol[w] = lbol_from_mbol (abs_mbol, format=format)
    return lbol