def normalize_magseries(times,<EOL>mags,<EOL>mingap=<NUM_LIT>,<EOL>normto='<STR_LIT>',<EOL>magsarefluxes=False,<EOL>debugmode=False):
ngroups, timegroups = find_lc_timegroups(times,<EOL>mingap=mingap)<EOL>finite_ind = np.isfinite(mags)<EOL>if any(finite_ind):<EOL><INDENT>global_mag_median = np.median(mags[finite_ind])<EOL>for tgind, tg in enumerate(timegroups):<EOL><INDENT>finite_ind = np.isfinite(mags[tg])<EOL>group_median = np.median((mags[tg])[finite_ind])<EOL>if magsarefluxes:<EOL><INDENT>mags[tg] = mags[tg]/group_median<EOL><DEDENT>else:<EOL><INDENT>mags[tg] = mags[tg] - group_median<EOL><DEDENT>if debugmode:<EOL><INDENT>LOGDEBUG('<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>(tgind,<EOL>len(mags[tg]),<EOL>len(finite_ind),<EOL>group_median))<EOL><DEDENT><DEDENT>if isinstance(normto, str) and normto == '<STR_LIT>':<EOL><INDENT>if magsarefluxes:<EOL><INDENT>mags = mags * global_mag_median<EOL><DEDENT>else:<EOL><INDENT>mags = mags + global_mag_median<EOL><DEDENT><DEDENT>elif isinstance(normto, float):<EOL><INDENT>if magsarefluxes:<EOL><INDENT>mags = mags * normto<EOL><DEDENT>else:<EOL><INDENT>mags = mags + normto<EOL><DEDENT><DEDENT>return times, mags<EOL><DEDENT>else:<EOL><INDENT>LOGERROR('<STR_LIT>')<EOL>return None, None<EOL><DEDENT>
This normalizes the magnitude time-series to a specified value.

    This is used to normalize time series measurements that may have large time
    gaps and vertical offsets in mag/flux measurement between these
    'timegroups', either due to instrument changes or different filters.

    NOTE: this works in-place! The mags array will be replaced with normalized
    mags when this function finishes.

    Parameters
    ----------

    times,mags : array-like
        The times (assumed to be some form of JD) and mags (or flux)
        measurements to be normalized.

    mingap : float
        This defines how much the difference between consecutive measurements is
        allowed to be to consider them as parts of different timegroups. By
        default it is set to 4.0 days.

    normto : {'globalmedian', 'zero'} or a float
        Specifies the normalization type::

          'globalmedian' -> norms each mag to the global median of the LC column
          'zero'         -> norms each mag to zero
          a float        -> norms each mag to this specified float value.

    magsarefluxes : bool
        Indicates if the input `mags` array is actually an array of flux
        measurements instead of magnitude measurements. If this is set to True,
        then:

        - if `normto` is 'zero', then the median flux is divided from each
          observation's flux value to yield normalized fluxes with 1.0 as the
          global median.

        - if `normto` is 'globalmedian', then the global median flux value
          across the entire time series is multiplied with each measurement.

        - if `norm` is set to a `float`, then this number is multiplied with the
          flux value for each measurement.

    debugmode : bool
        If this is True, will print out verbose info on each timegroup found.

    Returns
    -------

    times,normalized_mags : np.arrays
        Normalized magnitude values after normalization. If normalization fails
        for some reason, `times` and `normalized_mags` will both be None.