Skip to content

Commit

Permalink
Read sorcha's object_linked column
Browse files Browse the repository at this point in the history
  • Loading branch information
moeyensj committed Jan 23, 2025
1 parent 00af25a commit a911c07
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 31 deletions.
34 changes: 11 additions & 23 deletions src/adam_impact_study/conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,52 +95,40 @@ def sorcha_output_to_od_observations(sorcha_output_file: str) -> Observations:
sorcha_observations_table = sorcha_observations_table.take(sort_indices)
observations = Observations.empty()

object_ids = pc.unique(sorcha_observations_table["ObjID"]).to_numpy(
zero_copy_only=False
)
object_ids = pc.unique(sorcha_observations_table["ObjID"])

for obj in object_ids:
object_obs = sorcha_observations_table.filter(
pc.equal(sorcha_observations_table["ObjID"], obj)
)
times = Timestamp.from_mjd(
object_obs["fieldMJD_TAI"].to_numpy(zero_copy_only=False), scale="tai"
)
times = Timestamp.from_mjd(object_obs["fieldMJD_TAI"], scale="tai")
times = times.rescale("utc")
sigmas = np.full((len(object_obs), 6), np.nan)
sigmas[:, 1] = object_obs["astrometricSigma_deg"].to_numpy(zero_copy_only=False)
sigmas[:, 2] = object_obs["astrometricSigma_deg"].to_numpy(zero_copy_only=False)
photometry = Photometry.from_kwargs(
mag=object_obs["trailedSourceMag"].to_numpy(zero_copy_only=False),
mag_sigma=object_obs["trailedSourceMagSigma"].to_numpy(
zero_copy_only=False
),
filter=object_obs["optFilter"].to_numpy(),
mag=object_obs["trailedSourceMag"],
mag_sigma=object_obs["trailedSourceMagSigma"],
filter=object_obs["optFilter"],
)
coordinates = SphericalCoordinates.from_kwargs(
lon=object_obs["RA_deg"].to_numpy(zero_copy_only=False),
lat=object_obs["Dec_deg"].to_numpy(zero_copy_only=False),
lon=object_obs["RA_deg"],
lat=object_obs["Dec_deg"],
origin=Origin.from_kwargs(
code=np.full(len(object_obs), "X05", dtype="object")
code=pa.repeat("X05", len(object_obs)),
),
time=times,
frame="equatorial",
covariance=CoordinateCovariances.from_sigmas(sigmas),
)
coordinates_sorted = coordinates.sort_by(
[
("time.days", "ascending"),
("time.nanos", "ascending"),
("origin.code", "ascending"),
]
)

object_observation = Observations.from_kwargs(
obs_id=[f"{obj}_{i}" for i in range(len(object_obs))],
orbit_id=pa.repeat(obj, len(object_obs)),
coordinates=coordinates_sorted,
observers=Observers.from_code("X05", coordinates_sorted.time),
coordinates=coordinates,
observers=Observers.from_codes(coordinates.origin.code, coordinates.time),
photometry=photometry,
linked=object_obs["object_linked"],
)

observations = qv.concatenate([observations, object_observation])
Expand Down
2 changes: 0 additions & 2 deletions src/adam_impact_study/sorcha_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ def write_config_file_timeframe(
SSP_number_tracklets = 3
SSP_track_window = 15
SSP_night_start_utc = 16.0
[LINKING]
drop_unlinked = False
[OUTPUT]
Expand Down
14 changes: 8 additions & 6 deletions src/adam_impact_study/tests/test_conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ def test_impactor_file_to_adam_orbit(mock_impactor_file):
@pytest.fixture
def mock_sorcha_output_file(tmpdir):
file_path = tmpdir.join("sorcha_output.csv")
sorcha_data = """ObjID,fieldMJD_TAI,fieldRA_deg,fieldDec_deg,RA_deg,Dec_deg,astrometricSigma_deg,optFilter,trailedSourceMag,trailedSourceMagSigma,fiveSigmaDepth_mag,phase_deg
Test_1001,60001.12345678912,340.1234567,-7.1234567,341.1234567,-8.1234567,1.12e-05,i,21.123,0.123,22.123,18.12345678912345
Test_1001,60002.12345678912,341.1234567,-6.1234567,342.1234567,-7.1234567,2.12e-05,r,21.123,0.123,23.123,19.12345678912345
Test_1001,60003.12345678912,342.1234567,-5.1234567,343.1234567,-6.1234567,3.12e-05,z,21.123,0.123,24.123,20.12345678912345
Test_1002,60005.12345678912,344.1234567,-4.1234567,345.1234567,-5.1234567,8.12e-06,r,22.123,0.123,24.123,20.12345678912345
Test_1002,60006.12345678912,345.1234567,-3.1234567,346.1234567,-4.1234567,9.12e-06,i,23.123,0.123,25.123,21.12345678912345
sorcha_data = """ObjID,fieldMJD_TAI,fieldRA_deg,fieldDec_deg,RA_deg,Dec_deg,astrometricSigma_deg,optFilter,trailedSourceMag,trailedSourceMagSigma,fiveSigmaDepth_mag,phase_deg,object_linked
Test_1001,60001.12345678912,340.1234567,-7.1234567,341.1234567,-8.1234567,1.12e-05,i,21.123,0.123,22.123,18.12345678912345,True
Test_1001,60002.12345678912,341.1234567,-6.1234567,342.1234567,-7.1234567,2.12e-05,r,21.123,0.123,23.123,19.12345678912345,True
Test_1001,60003.12345678912,342.1234567,-5.1234567,343.1234567,-6.1234567,3.12e-05,z,21.123,0.123,24.123,20.12345678912345,False
Test_1002,60005.12345678912,344.1234567,-4.1234567,345.1234567,-5.1234567,8.12e-06,r,22.123,0.123,24.123,20.12345678912345,True
Test_1002,60006.12345678912,345.1234567,-3.1234567,346.1234567,-4.1234567,9.12e-06,i,23.123,0.123,25.123,21.12345678912345,True
"""
file_path.write(sorcha_data)
return str(file_path)
Expand Down Expand Up @@ -98,6 +98,8 @@ def test_sorcha_output_to_od_observations(mock_sorcha_output_file):
60006.12345678912,
]

assert observations.linked.to_pylist() == [True, True, False, True, True]


@pytest.fixture
def mock_observations():
Expand Down
2 changes: 2 additions & 0 deletions src/adam_impact_study/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class Observations(qv.Table):
observers = Observers.as_column()
photometry = Photometry.as_column(nullable=True)
observing_night = qv.Int64Column(nullable=True)
#: Was this observation linked by Rubin's SSP
linked = qv.BooleanColumn(nullable=True)


class PhotometricProperties(qv.Table):
Expand Down

0 comments on commit a911c07

Please sign in to comment.