Ignore:
Timestamp:
Dec 3, 2026, 9:10:39 AM (75 minutes ago)
Author:
stuerze
Message:

clock combination improvement

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/src/combination/bnccomb.cpp

    r11221 r11240  
    16391639// the reference signals
    16401640//   u = clock - AC offset - combined clock
    1641 // (rejected corrections included) is compared with the median of the ACs.
     1641// (rejected corrections included) is compared with the median of the ACs
     1642// whose offsets are in the datum. Offsets leave one at a time, the largest
     1643// deviation first, and the median is computed again after each departure.
    16421644// An offset rejected as outlier for DATUM_OUT_SEC leaves the zero-sum
    16431645// conditions (satellite and AC) and is re-initialized: it then absorbs the
    … …  
    16491651// DATUM_OUT_SEC leaves as well, as long as a majority of the ACs stays in.
    16501652// An offset rejoins the datum after a deviation below DATUM_IN_DEV (at most
    1651 // half of the maximum residual) without rejection for DATUM_IN_SEC. ACs not
     1653// half of the maximum residual) from the median of the offsets in the datum
     1654// without rejection for DATUM_IN_SEC. ACs not
    16521655// referred to the reference signals are excluded from the datum anyway and
    16531656// not judged.
    … …  
    16921695    const QVector<const t_datumObs*>& obs = itSat.value();
    16931696    const bool robust = (obs.size() >= DATUM_MIN_AC); // median meaningful
    1694     QVector<double> uSat;
     1697    const int  nn     = obs.size();
     1698    // a majority of the ACs stays in the datum (e.g. two groups of ACs with
     1699    // a clock difference: the median is not meaningful)
     1700    const int  minIn  = std::max(2, (nn + 1) / 2);
     1701
     1702    auto medianOf = [&uu](const QVector<const t_datumObs*>& set) {
     1703      QVector<double> vv;
     1704      for (const t_datumObs* dObs : set) {
     1705        vv.push_back(uu[dObs->ac + ' ' + dObs->prn]);
     1706      }
     1707      std::sort(vv.begin(), vv.end());
     1708      int mm = vv.size();
     1709      return (mm % 2) ? vv[mm/2] : 0.5 * (vv[mm/2-1] + vv[mm/2]);
     1710    };
     1711    auto report = [&](const QString& msg) {
     1712      out << epoTime.datestr().c_str() << " " << epoTime.timestr().c_str() << " " << msg << "\n";
     1713      emit newLogRecord(t_logRecord::message(t_logRecord::info, "bncComb: " + msg.toLatin1()), true);
     1714    };
     1715
     1716    QVector<const t_datumObs*> inSet, outSet;
    16951717    for (const t_datumObs* dObs : obs) {
    1696       uSat.push_back(uu[dObs->ac + ' ' + dObs->prn]);
    1697     }
    1698     std::sort(uSat.begin(), uSat.end());
    1699     int    nn     = uSat.size();
    1700     double median = (nn % 2) ? uSat[nn/2] : 0.5 * (uSat[nn/2-1] + uSat[nn/2]);
    1701 
    1702     // a majority of the ACs stays in the datum (e.g. two groups of ACs with
    1703     // a clock difference: the median is not meaningful); the offsets with the
    1704     // largest deviations leave first
    1705     const int minIn  = std::max(2, (nn + 1) / 2);
    1706     int       numIn  = 0;
    1707     QVector<const t_datumObs*> order = obs;
     1718      (states[dObs->ac + ' ' + dObs->prn].out ? outSet : inSet).push_back(dObs);
     1719    }
     1720
     1721    // Leaving: one offset at a time, the one with the largest deviation from
     1722    // the median of the offsets still in the datum first; the median is
     1723    // computed again after each departure. Otherwise one extreme offset
     1724    // shifts the median of all ACs so much that good offsets leave together
     1725    // with it (29 Nov 2026, G13: BKG00 +5 m took CHC00 out, only GMV00 stayed).
     1726    // ------------------------------------------------------------------------
     1727    if (inSet.size() == 1) {
     1728      t_datumState& state = states[inSet[0]->ac + ' ' + inSet[0]->prn];
     1729      state.dev = 0.0;
     1730      state.since.reset();
     1731    }
     1732    while (inSet.size() > 1) {
     1733      double median = medianOf(inSet);
     1734      QVector<const t_datumObs*> cand;
     1735      for (const t_datumObs* dObs : inSet) {
     1736        t_datumState& state = states[dObs->ac + ' ' + dObs->prn];
     1737        state.dev = uu[dObs->ac + ' ' + dObs->prn] - median;
     1738        if (dObs->rejected || (robust && fabs(state.dev) > DATUM_OUT_DEV)) {
     1739          if (!state.since.valid()) {
     1740            state.since = epoTime;
     1741          }
     1742          cand.push_back(dObs);
     1743        }
     1744        else {
     1745          state.since.reset();
     1746        }
     1747      }
     1748      std::stable_sort(cand.begin(), cand.end(),
     1749                       [&states](const t_datumObs* aa, const t_datumObs* bb) {
     1750                         return fabs(states[aa->ac + ' ' + aa->prn].dev) >
     1751                                fabs(states[bb->ac + ' ' + bb->prn].dev);
     1752                       });
     1753      const t_datumObs* leaving = 0;
     1754      for (const t_datumObs* dObs : cand) {
     1755        t_datumState& state = states[dObs->ac + ' ' + dObs->prn];
     1756        // the largest deviation leaves first: until it may leave, no other does
     1757        if (epoTime - state.since < DATUM_OUT_SEC) {
     1758          break;
     1759        }
     1760        // a rejected offset leaves as long as another one stays in, a
     1761        // deviating (accepted) one only as long as a majority stays in
     1762        if (inSet.size() - 1 >= (dObs->rejected ? 1 : minIn)) {
     1763          leaving = dObs;
     1764          break;
     1765        }
     1766      }
     1767      if (!leaving) {
     1768        break;
     1769      }
     1770      t_datumState& state = states[leaving->ac + ' ' + leaving->prn];
     1771      double duration = epoTime - state.since;
     1772      state.out      = true;
     1773      state.outSince = epoTime;
     1774      state.since.reset();
     1775      // re-initialize the offset: it absorbs the difference from now on
     1776      for (int iPar = 1; iPar <= _params[sys].size(); iPar++) {
     1777        cmbParam* pp = _params[sys][iPar-1];
     1778        if (pp->type == cmbParam::offACSat && pp->AC == leaving->ac && pp->prn == leaving->prn) {
     1779          _QQ[sys].Row(iPar)    = 0.0;
     1780          _QQ[sys].Column(iPar) = 0.0;
     1781          _QQ[sys](iPar,iPar)   = pp->sig0 * pp->sig0;
     1782        }
     1783      }
     1784      report(QString("%1 %2 out of the clock datum: deviation %3 m from the median of %4 ACs%5")
     1785             .arg(leaving->ac).arg(leaving->prn.mid(0,3))
     1786             .arg(state.dev, 0, 'f', 2).arg(inSet.size())
     1787             .arg(leaving->rejected ? QString(", rejected as outlier for %1 s").arg(duration, 0, 'f', 0) : QString()));
     1788      inSet.removeOne(leaving);
     1789    }
     1790
     1791    // Rejoining: deviation from the median of the offsets in the datum (not
     1792    // of all ACs: offsets out of the datum, e.g. a single extreme one, would
     1793    // keep a good offset out for good). If fewer than a majority of the
     1794    // offsets are in the datum, the median of all offsets not rejected as
     1795    // outliers is used instead: one or two remaining offsets would otherwise
     1796    // keep the others out for good (29 Nov 2026, GLONASS: datum of R14
     1797    // alternating between CHC00 and SHA01 for hours).
     1798    // ------------------------------------------------------------------------
     1799    QVector<const t_datumObs*> accepted;
    17081800    for (const t_datumObs* dObs : obs) {
    1709       QString key = dObs->ac + ' ' + dObs->prn;
    1710       states[key].dev = uu[key] - median;
    1711       if (!states[key].out) {
    1712         ++numIn;
    1713       }
    1714     }
    1715     std::stable_sort(order.begin(), order.end(),
    1716                      [&states](const t_datumObs* aa, const t_datumObs* bb) {
    1717                        return fabs(states[aa->ac + ' ' + aa->prn].dev) >
    1718                               fabs(states[bb->ac + ' ' + bb->prn].dev);
    1719                      });
    1720 
    1721     for (const t_datumObs* dObs : order) {
    1722       QString       key   = dObs->ac + ' ' + dObs->prn;
    1723       t_datumState& state = states[key];
    1724       bool change = state.out ? (fabs(state.dev) < DATUM_IN_DEV && !dObs->rejected)
    1725                               : (dObs->rejected || (robust && fabs(state.dev) > DATUM_OUT_DEV));
    1726       if (!change) {
     1801      if (!dObs->rejected) {
     1802        accepted.push_back(dObs);
     1803      }
     1804    }
     1805    const QVector<const t_datumObs*>& refSet =
     1806      (inSet.size() >= minIn) ? inSet : (accepted.isEmpty() ? obs : accepted);
     1807    double medianIn = medianOf(refSet);
     1808    for (const t_datumObs* dObs : outSet) {
     1809      t_datumState& state = states[dObs->ac + ' ' + dObs->prn];
     1810      state.dev = uu[dObs->ac + ' ' + dObs->prn] - medianIn;
     1811      if (fabs(state.dev) >= DATUM_IN_DEV || dObs->rejected) {
    17271812        state.since.reset();
    17281813        continue;
    … …  
    17321817      }
    17331818      double duration = epoTime - state.since;
    1734       if (duration < (state.out ? DATUM_IN_SEC : DATUM_OUT_SEC)) {
     1819      if (duration < DATUM_IN_SEC) {
    17351820        continue;
    17361821      }
    1737       // a rejected offset leaves as long as another one stays in, a deviating
    1738       // (accepted) one only as long as a majority stays in
    1739       if (!state.out && numIn - 1 < (dObs->rejected ? 1 : minIn)) {
    1740         continue;
    1741       }
    1742       QString msg;
    1743       if (!state.out) {
    1744         --numIn;
    1745         state.out      = true;
    1746         state.outSince = epoTime;
    1747         msg = QString("%1 %2 out of the clock datum: deviation %3 m from the median of %4 ACs%5")
    1748               .arg(dObs->ac).arg(dObs->prn.mid(0,3))
    1749               .arg(state.dev, 0, 'f', 2).arg(nn)
    1750               .arg(dObs->rejected ? QString(", rejected as outlier for %1 s").arg(duration, 0, 'f', 0) : QString());
    1751         // re-initialize the offset: it absorbs the difference from now on
    1752         for (int iPar = 1; iPar <= _params[sys].size(); iPar++) {
    1753           cmbParam* pp = _params[sys][iPar-1];
    1754           if (pp->type == cmbParam::offACSat && pp->AC == dObs->ac && pp->prn == dObs->prn) {
    1755             _QQ[sys].Row(iPar)    = 0.0;
    1756             _QQ[sys].Column(iPar) = 0.0;
    1757             _QQ[sys](iPar,iPar)   = pp->sig0 * pp->sig0;
    1758           }
    1759         }
    1760       }
    1761       else {
    1762         ++numIn;
    1763         state.out = false;
    1764         msg = QString("%1 %2 back in the clock datum: deviation %3 m from the median of %4 ACs "
    1765                       "(below %5 m for %6 s)")
    1766               .arg(dObs->ac).arg(dObs->prn.mid(0,3))
    1767               .arg(state.dev, 0, 'f', 2).arg(nn)
    1768               .arg(DATUM_IN_DEV, 0, 'f', 2).arg(duration, 0, 'f', 0);
    1769       }
     1822      state.out = false;
    17701823      state.since.reset();
    1771       out << epoTime.datestr().c_str() << " " << epoTime.timestr().c_str() << " " << msg << "\n";
    1772       emit newLogRecord(t_logRecord::message(t_logRecord::info, "bncComb: " + msg.toLatin1()), true);
     1824      report(QString("%1 %2 back in the clock datum: deviation %3 m from the median of %4 ACs "
     1825                     "(below %5 m for %6 s)")
     1826             .arg(dObs->ac).arg(dObs->prn.mid(0,3))
     1827             .arg(state.dev, 0, 'f', 2).arg(refSet.size())
     1828             .arg(DATUM_IN_DEV, 0, 'f', 2).arg(duration, 0, 'f', 0));
    17731829    }
    17741830  }
Note: See TracChangeset for help on using the changeset viewer.