core.locator_twice

core.locator_twice(
    fovs,
    orb,
    simstates=None,
    drop_major_asteroids=True,
    jd0=None,
    include_asteroids=(False, True),
    dt_limit=None,
    suppress_errors=True,
    add_obsid=True,
    drop_obsindex=True,
    add_jds=True,
    non_gravs=[True, True],
    calc_ephems_crude=False,
    use_spice_for_loaded=(True, True),
    *,
    jd0_tol=1e-05,
    lunar_elong=True,
    vmag_max=None,
    keep_comets=True,
)

Find the objects in FOVs in 2 stages, and compute their ephemerides.

Each stage has its own settings: jd0, include_asteroids, dt_limit, non_gravs, and use_spice_for_loaded. See Notes for details.

Parameters

fovs : FOVCollection, or iterable of kete.fov.FOV

Field of View(s) to check the propagated states against.

orb : pandas.DataFrame

Orbit file with columns of orbital elements. See query.fetch_orb().

simstates : ~kete.SimultaneousStates, path-like, default = None

States to reuse for faster computation by bypassing recomputation if jd0 is None or within jd0_tol days. Then the locator will use simstates without new propagation. Otherwise, orb is used (propagated to properjd0), and simstates are ignored. A path is read with ~skyloc.keteutils.load_simstates (not the default loader in kete). Default is None.

drop_major_asteroids : bool, default = True

If True, drop the major asteroids from the orb. The major asteroids are the 5 asteroids whose masses kete uses with include_asteroids: 1 Ceres, 2 Pallas, 4 Vesta, 10 Hygiea, and 704 Interamnia. Default is True.

jd0 : 2-tuple of {float, callable, None}, or None, default = None

The epochs (TDB JD) to which the stages to use (i.e., propagate the objects to). A callable (e.g., np.mean) takes 1 argument as the list of all FOV epochs of the stage and returns the output. None (default) lets skyloc pick it:

  • If the stage already has states (simstates, or in the 2nd stage, the reused 1st-stage states), we use them at their own epoch.
  • Otherwise, np.min(FOV epochs) for kete (>=3.3), and the (min + max) / 2 for kete_ipac (v1.x). See Notes.

jd0=None is the same as (None, None).

include_asteroids : 2-tuple of bool, default = (False, True)

If True, the N-body motion of that stage includes the masses of the 5 major asteroids. Default is (False, True).

dt_limit : float, 2-tuple of float, or None, default = None

Longest time span in days of 2-body motion, one value per stage. A float sets dt_limit[0] only. None, for the whole value or one item, means (5.0a, 0.5). See Notes. Default is None.

suppress_errors : bool, default = True

If True, suppress errors during propagation. Default is True.

add_obsid : bool, default = True

If True, add “obsid” column to the result. Default is True.

drop_obsindex : bool, default = True

If True, drop “obsindex” column from the result. Default is True.

add_jds : bool, default = True

If True, add “jd_tdb” and “jd_utc” columns to the result. Default is True.

non_gravs : 2-tuple of 2 settings, default = [True, True]

Non-gravitational models of each stage. True builds the models from orb, and False disables them. A sequence for the 2nd stage must contain one model or None per row of the original orb, including rows that the 1st stage excludes. Default is [True, True].

calc_ephems_crude : bool, default = False

If True, calculate ephemerides after the 1st stage. Default is False.

use_spice_for_loaded : tuple of bool, default = (True, True)

If True, that stage also finds the major asteroids in the FOVs, with their SPICE states. Default is (True, True).

jd0_tol : float, default = 1e-05

Finite, non-negative epoch tolerance in days for both stages. Reuse requires an epoch difference strictly less than this value; 0 disables reuse. Default is 1e-5 days (0.864 sec). Reused states retain their epoch. This is not a positional accuracy guarantee.

lunar_elong : bool, default = True

If True, add the "lunar_elong" column (Target-Observer-Moon angle in degrees) to the ephemerides. Default is True.

vmag_max : float or None, default = None

If given, the 1st stage drops the objects whose V is larger than this in every FOV where it found them (SSOLocator.drop_faint). V is from the 1st-stage states, at the epoch and from the observer of each FOV. Objects without any magnitude parameter are kept. None (default) keeps all objects.

keep_comets : bool, default = True

If True, vmag_max does not drop comets. Default is True.

Returns

: SSOLocator

The locators of the 1st and 2nd stages. sl2 is identical to sl1 if the 2nd stage is skipped.

Notes

.. note:: TL;DR: the 1st stage quickly drops the objects that have no hope of being in any FOV (For any reasonably large FoVs, >90% of them). Then the 2nd stage computes the ephemerides of the remaining candidates precisely (<< 1 arcsec offset).

1st stage (quick approximation) finds the candidates. All objects are propagated with N-body to jd0[0] (not to each FOV epoch), and then checked against the FOVs with kete.fov.fov_state_check:

  • kete_ipac (v1.x): FOVs are grouped so that each group spans < 2 * dt_limit[0] days by kete. The states are propagated with N-body to the middle epoch of a group only if it is >= dt_limit[0] days away from the current state epoch. Then each FOV <= dt_limit[0] days from the state epoch uses the quick 2-body approximation, and the other FOVs use N-body. So I recommend chunks of FOVs that span < 2 * dt_limit[0] days. The default jd0[0] is the middle of the FOV epochs, because it makes the longest 2-body step as short as possible.
  • kete (>=3.3): the FOV check is always N-body to each FOV epoch, and it has no dt_limit. It is exact, but it can be much slower than 2-body when we have > 1M of objects and the FOV epochs are close to jd0[0]. kete first propagates every object to the earliest FOV epoch, so the default jd0[0] is that epoch, and this first N-body run is not repeated. A dt_limit value other than None is not used, and gives a UserWarning.

2nd stage (precise) checks only the candidates, with kete.fov.fov_state_check, and computes their precise ephemerides. They are propagated with N-body to jd0[1], again from the orbital elements. Two shortcuts avoid repeating the same work:

  • If both stages have the same include_asteroids and non_gravs, and jd0[1] is None or within jd0_tol days of the 1st-stage epoch, the 2nd stage reuses the states of the 1st stage.
  • With kete (>=3.3), if both stages have the same jd0, include_asteroids, non_gravs, and use_spice_for_loaded, the 2nd stage would only repeat the 1st stage. So it is skipped: the ephemerides are computed from the 1st stage, and sl2 is sl1. With the same callable jd0 (e.g., np.mean), the two start epochs can differ because the 2nd stage has fewer FOVs, but this changes only the integration path, not the forces.

The 2nd stage looks only at the FOVs that contain candidates. If only the 2nd stage uses SPICE (use_spice_for_loaded), it checks the major asteroids in all FOVs.

Forces. Each stage can include the masses of the major asteroids (include_asteroids) and non-gravitational forces (non_gravs). Non-gravitational forces are on in both stages by default, because they barely add computation time: only 977 of 1,573,014 orbits (0.06%) in the SBDB table of 2026-09-29 have A1, A2, A3, or DT. Of course, both are tunable. kete_ipac (v1.x) applies non-gravitational forces only when it propagates to jd0, and its FOV check ignores them.

Cached states. For repeated full-catalog runs, prepare the states with CachedOrbPropagator and pass them as simstates, together with the same orb. A stage that uses them (see jd0) does not propagate them again, so they must have been made with force settings that suit that stage. Missing objects are simply omitted, and this function does not check where the states came from.