<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def modelshift_weaksec(koi):
 """ Max secondary depth based on model-shift secondary test from Jeff Coughlin secondary metric: mod_depth_sec_dv * (1 + 3*mod_fred_dv / mod_sig_sec_dv) """

    num = KOIDATA.ix[ku.koiname(koi), 'koi_tce_plnt_num']
    if np.isnan(num):
        num = 1
    kid = KOIDATA.ix[ku.koiname(koi), 'kepid']
    tce = '{:09.0f}-{:02.0f}'.format(kid,num)

    #return largest depth between DV detrending and alternate detrending
    try:
        r = ROBOVETDATA.ix[tce]
    except KeyError:
        raise NoWeakSecondaryError(koi)

    depth_dv = r['mod_depth_sec_dv'] * (1 + 3*r['mod_fred_dv'] / r['mod_sig_sec_dv'])
    depth_alt = r['mod_depth_sec_alt'] * (1 + 3*r['mod_fred_alt'] / r['mod_sig_sec_alt'])

    logging.debug(r[['mod_depth_sec_dv','mod_fred_dv','mod_sig_sec_dv']])
    logging.debug(r[['mod_depth_sec_alt','mod_fred_alt','mod_sig_sec_alt']])

    if np.isnan(depth_dv) and np.isnan(depth_alt):
        #return weaksec_vv2(koi)
        raise NoWeakSecondaryError(koi)
    elif np.isnan(depth_dv):
        return depth_alt
    elif np.isnan(depth_alt):
        return depth_dv
    else:
        return max(depth_dv, depth_alt)