def trapezoid_transit_func(transitparams, times, mags, errs,<EOL>get_ntransitpoints=False):
(transitperiod,<EOL>transitepoch,<EOL>transitdepth,<EOL>transitduration,<EOL>ingressduration) = transitparams<EOL>iphase = (times - transitepoch)/transitperiod<EOL>iphase = iphase - np.floor(iphase)<EOL>phasesortind = np.argsort(iphase)<EOL>phase = iphase[phasesortind]<EOL>ptimes = times[phasesortind]<EOL>pmags = mags[phasesortind]<EOL>perrs = errs[phasesortind]<EOL>zerolevel = np.median(pmags)<EOL>modelmags = np.full_like(phase, zerolevel)<EOL>halftransitduration = transitduration/<NUM_LIT><EOL>bottomlevel = zerolevel - transitdepth<EOL>slope = transitdepth/ingressduration<EOL>firstcontact = <NUM_LIT:1.0> - halftransitduration<EOL>secondcontact = firstcontact + ingressduration<EOL>thirdcontact = halftransitduration - ingressduration<EOL>fourthcontact = halftransitduration<EOL>ingressind = (phase > firstcontact) & (phase < secondcontact)<EOL>bottomind = (phase > secondcontact) | (phase < thirdcontact)<EOL>egressind = (phase > thirdcontact) & (phase < fourthcontact)<EOL>in_transit_points = ingressind | bottomind | egressind<EOL>n_transit_points = np.sum(in_transit_points)<EOL>modelmags[ingressind] = zerolevel - slope*(phase[ingressind] - firstcontact)<EOL>modelmags[bottomind] = bottomlevel<EOL>modelmags[egressind] = bottomlevel + slope*(phase[egressind] - thirdcontact)<EOL>if get_ntransitpoints:<EOL><INDENT>return modelmags, phase, ptimes, pmags, perrs, n_transit_points<EOL><DEDENT>else:<EOL><INDENT>return modelmags, phase, ptimes, pmags, perrs<EOL><DEDENT>
This returns a trapezoid transit-shaped function.

    Suitable for first order modeling of transit signals.

    Parameters
    ----------

    transitparams : list of float
        This contains the transiting planet trapezoid model::

            transitparams = [transitperiod (time),
                             transitepoch (time),
                             transitdepth (flux or mags),
                             transitduration (phase),
                             ingressduration (phase)]

        All of these will then have fitted values after the fit is done.

        - for magnitudes -> `transitdepth` should be < 0
        - for fluxes     -> `transitdepth` should be > 0

    times,mags,errs : np.array
        The input time-series of measurements and associated errors for which
        the transit model will be generated. The times will be used to generate
        model mags, and the input `times`, `mags`, and `errs` will be resorted
        by model phase and returned.

    Returns
    -------

    (modelmags, phase, ptimes, pmags, perrs) : tuple
        Returns the model mags and phase values. Also returns the input `times`,
        `mags`, and `errs` sorted by the model's phase.