Skip to content

Commit

Permalink
add some debug statements
Browse files Browse the repository at this point in the history
  • Loading branch information
akoumjian committed Dec 2, 2024
1 parent e7713f0 commit 0c4c532
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
4 changes: 4 additions & 0 deletions precovery/frame_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ def propagation_targets(
A table of healpixels and times.
"""
print(f"Selecting propagation targets for {window.obscode[0].as_py()} at {window.time.mjd()[0].as_py()}")
assert len(window) == 1
obscode = window.obscode[0].as_py()
start_mjd = window.window_start().mjd()[0].as_py()
Expand Down Expand Up @@ -285,10 +286,13 @@ def propagation_targets(
)

rows = self.dbconn.execute(select_stmt).fetchall()
print(f"Found {len(rows)} rows")
if len(rows) == 0:
return GenericFrame.empty()
# turn rows into columns
print(f"Turning rows into columns")
times, healpixels = zip(*rows)
print(f"Returning")
return GenericFrame.from_kwargs(
time=Timestamp.from_mjd(times, scale="utc"),
healpixel=healpixels,
Expand Down
21 changes: 17 additions & 4 deletions precovery/precovery_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ def find_observation_matches(
Tuple[ObservationsTable, Ephemeris]
Observations and ephemeris that match within the given tolerance
"""
print("Finding observation matches")
assert len(ephems) == len(
observations
), "Ephemeris must be the same length as observations"
Expand All @@ -465,7 +466,7 @@ def find_observation_matches(
mask = pc.less(distances, tolerance_deg)
matching_observations = observations.apply_mask(mask)
matching_ephems = ephems.apply_mask(mask)

print("Done finding matches")
return matching_observations, matching_ephems


Expand Down Expand Up @@ -655,6 +656,7 @@ def _check_windows(
"""
Find all observations that match orbit within a list of windows
"""
print(f"Checking {len(windows)} windows")
# Propagate the orbit with n-body to every window center
assert len(orbit) == 1, "_check_windows only support one orbit for now"
windows = windows.sort_by(["time.days", "time.nanos"])
Expand Down Expand Up @@ -703,6 +705,7 @@ def _check_window(
propagator_class: Type[Propagator],
datasets: Optional[set[str]],
) -> Tuple[PrecoveryCandidates, FrameCandidates]:
print(f"Checking window {window.time.mjd()[0].as_py()}")
assert len(window) == 1, "Use _check_windows for multiple windows"
assert len(orbit) == 1, "_check_window only support one orbit for now"
obscode = window.obscode[0].as_py()
Expand All @@ -718,6 +721,7 @@ def _check_window(

times = propagation_targets.time

print(f"Window 2 body prop and ephemeris start")
# create our observers
observers = Observers.from_code(obscode, times)
## first propagate with 2_body
Expand All @@ -731,9 +735,11 @@ def _check_window(

# generate ephemeris
ephems = generate_ephemeris_2body(propagated_orbits, observers)
print("Finding healpixels")
frames_to_check = find_healpixel_matches(
propagation_targets, ephems, self.frames.healpix_nside
)
print(f"Found {len(frames_to_check)} frames to check")
candidates = PrecoveryCandidates.empty()
frame_candidates = FrameCandidates.empty()
for frame in frames_to_check:
Expand Down Expand Up @@ -764,7 +770,9 @@ def _check_frames(
Deeply inspect all frames that match the given obscode, mjd, and healpix to
see if they contain observations which match the ephemeris.
"""
print(f"Starting check frames with {len(generic_frames)} frames")
frames = HealpixFrame.empty()
print("Getting the actual frames")
for generic_frame in generic_frames:
frames = qv.concatenate(
[
Expand All @@ -777,13 +785,16 @@ def _check_frames(
),
]
)
print(f"Done fetching {len(frames)} frames")
print(f"Generating n-body frame ephemeris")
unique_frame_times = frames.exposure_mid_timestamp().unique()
observers = Observers.from_code(obscode, unique_frame_times)
# Compute the position of the ephem carefully.
propagator = propagator_class()
ephemeris = propagator.generate_ephemeris(orbit, observers)
precovery_candidates = PrecoveryCandidates.empty()
frame_candidates = FrameCandidates.empty()
print("Matching the frames")
for f in frames:
matching_ephem = ephemeris.apply_mask(
ephemeris.coordinates.time.equals(
Expand Down Expand Up @@ -821,19 +832,21 @@ def find_matches_in_frame(
"""
Find all sources in a single frame which match ephem.
"""
print(f"Finding matches in frame {frame.healpixel[0].as_py()}")
logger.debug("checking frame: %s", frame)
assert len(frame_ephem) == 1, "ephem should have only one entry"

print("Getting observations")
# Gather all observations.
observations: ObservationsTable = self.frames.get_observations(frame)

print("Done getting observations")
# Check if the observations have per-observation MJDs.
# If so we use 2 body to generate unique ephemeris for each
if len(observations.time.unique()) > 1:
logger.info(
print(
f"{frame} has {len(observations.time.unique())} unique obs times"
)
logger.info("Using per-observation ephem")
print("Using per-observation ephem")
per_obs_ephem = generate_ephem_for_per_obs_timestamps(
orbit, observations, frame.obscode, propagator
)
Expand Down

0 comments on commit 0c4c532

Please sign in to comment.