Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2.0 obs source #108

Merged
merged 3 commits into from
Aug 31, 2023
Merged

V2.0 obs source #108

merged 3 commits into from
Aug 31, 2023

Conversation

spenczar
Copy link
Collaborator

@spenczar spenczar commented Aug 30, 2023

(merge base is #107, take care!)

Add ObservationSource which loads observations and filters them to ones that match a test orbit. This is an interface that describes how data can make its way into THOR. We can implement more ObservationSources in the future, but these two are fundamental.

@spenczar spenczar changed the base branch from main to v2.0-jm-test-orbit August 30, 2023 20:05
Comment on lines +97 to +120
def _within_radius(
detections: detections.PointSourceDetections,
ra: float,
dec: float,
radius: float,
) -> detections.PointSourceDetections:
"""
Return the detections within a given radius of a given ra and dec
"""
sdlon = np.sin(detections.ra.to_numpy() - ra)
cdlon = np.cos(detections.ra.to_numpy() - ra)
slat1 = np.sin(dec)
slat2 = np.sin(detections.dec.to_numpy())
clat1 = np.cos(dec)
clat2 = np.cos(detections.dec.to_numpy())

num1 = clat2 * sdlon
num2 = clat1 * slat2 - slat1 * clat2 * cdlon
denominator = slat1 * slat2 + clat1 * clat2 * cdlon

distances = np.arctan2(np.hypot(num1, num2), denominator)

mask = distances <= radius
return detections.apply_mask(mask)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Obviously ought to be in adam_core but this works for now

@spenczar spenczar marked this pull request as ready for review August 30, 2023 20:09
Copy link
Owner

@moeyensj moeyensj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

left_keys=detections.exposure_id,
right_keys=exposures.id,
)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have already discussed this offline, but for the record, a lightweight class that wraps a quivr linkage is an excellent idea.


"""

def __init__(self, radius: float, all_observations: Observations):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've made me a type hinting stickler now. Do __init__s normally have a return type?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch! __init__ always returns None, and is assumed to do so. There is a lengthy and boring thread on this at python/mypy#604, resolved in python/mypy#5677.

There's nothing wrong with explicitly adding -> None there though.

You might be a bit surprised that it returns None and not, say, Self. That's because __new__ is the actual constructor function which returns the new class instance. __init__ is actually a hook that gets called to initialize the new instance, and its return value is discarded.

y=[0],
z=[0],
vx=[0],
vy=[6.14],
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

6.14 au per day is ~3% the speed of light. This test orbit is flying!

You could give it a y-velocity of np.sqrt(c.MU/r) if you wanted to make it a circular orbit instead of an unbound one.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hahahaha, yeah, that's what what I actually wanted! Thanks.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I'm doing 2𝜋/365.24 instead, because that's how my brain works, and they're the same up to 5 digits of precision :))


# Approximately pi/4 (~0.78) of the detections should be in the 0.5 degree
# radius
assert len(have.detections) > 0.75 * len(fixed_observations.detections)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clever!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And also false! Spherical geometry is super weird and I empirically get more like 95% within the circle. I'm not sure what's going on.

@spenczar
Copy link
Collaborator Author

I think this is good to merge, but it would land on your test orbit branch @moeyensj . Let's merge that first into v2.0 rather than stacking too deeply.

@@ -78,8 +78,7 @@ def __init__(
else:
self.orbit_id = uuid.uuid4().hex

if object_id is not None:
self.object_id = object_id
self.object_id = object_id
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I won't touch this in #107 since you address it here.

@moeyensj moeyensj mentioned this pull request Aug 31, 2023
Base automatically changed from v2.0-jm-test-orbit to v2.0 August 31, 2023 05:12
@moeyensj moeyensj merged commit ddcda9f into v2.0 Aug 31, 2023
0 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants