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

Add ability to ingest Solar System targets via the MPC Explorer interface #1139

Merged
merged 19 commits into from
Jan 31, 2025

Conversation

talister
Copy link
Contributor

The Minor Planet Center's MPC Explorer API interface (used elsewhere in LCO for resolving designations I believe) has recently added support for downloading orbital elements (but sadly not for comets yet... sad snowball...) as well as designations and observations. This PR adds a new Harvester which supports querying the MPC Explorer to produce Targets.
This interface doesn't import the H,G (or the (unpopulated) newer H,G1, G2 or cometary M1, M2, K1, K2) magnitude values but neither does the existing MPCHarvester and there's nowhere to put in the base Target anyway; possibly this is meant to go into TargetExtra custom fields?

Anyhoo, over to the developers for initial review...

@jchate6 jchate6 self-requested a review December 11, 2024 01:39
@jchate6 jchate6 added User Issue Raised by a user Data Services Data Services labels Dec 11, 2024
@jchate6
Copy link
Contributor

jchate6 commented Dec 16, 2024

If you would like this to show up in the list of Harvesters by default, you should add it to the DEFAULT_HARVESTER_CLASSES list in tom_catalogs.apps.py .

Copy link
Contributor

@jchate6 jchate6 left a comment

Choose a reason for hiding this comment

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

Thanks for this! Let me know if you would like me to implement these changes!


target.type = 'NON_SIDEREAL'
target.scheme = 'MPC_COMET'
target.name = result['designation_data']['iau_designation']
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we probably want to handle this more carefully.
I think it might make sense to check the permid, unpacked_primary_provisional_designation, the name, and the unpacked_secondary_provisional_designations.

The issue with the current strategy is that 'iau_designation' results in numbers that are in parentheses (99942) when there is a primary designation and the name isn't captured for named objects.

Other objects can have multiple provisional designations that should also be included as aliases (such as Elyna).

Copy link
Contributor

Choose a reason for hiding this comment

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

Note, for reasons I cannot understand, if the object is un-named, "name" isn't in the dictionary at all and will throw a key error instead of just being blank like permid

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should be addressed now in 2a4b73f

tom_catalogs/tests/harvesters/data/test_65803_mpc_orb.json Outdated Show resolved Hide resolved
mock_response.content = [None, 200]
mock_get.return_value = mock_response

result = self.broker.query('123456P')
Copy link
Contributor

Choose a reason for hiding this comment

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

self.broker.query doesn't have a return.
This should really be testing that self.catalog_data isn't updated with anything since the return of query will always be None.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had trouble with the Mock and the canary actual query making it fail in a useful way and was unsure what the general policy was on incorporating and simulating tests on unreachable or 500 error-returning sites. If you could take a look at potential "predictably failable" queries @jchate6 or point me at other examples (the Simbad Harvester mocks a InconsistentTableError which isn't applicable), I can look at implementing something in addition as I agree that it would be good

@talister
Copy link
Contributor Author

If you would like this to show up in the list of Harvesters by default, you should add it to the DEFAULT_HARVESTER_CLASSES list in tom_catalogs.apps.py .

I figured that since 1) the MPC Explorer end point doesn't contain comets yet (despite only returning elements in comet form...) and 2) the majority of TOM users would not be using this endpoint, it didn't seem to make a sensible default for the whole project (and I've verified that adding it to FOMO's settings.py does work

@talister talister requested a review from jchate6 January 24, 2025 22:03
Copy link
Contributor

@jchate6 jchate6 left a comment

Choose a reason for hiding this comment

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

Can you please add instructions on how to include the MPCExplorerHarvester via settings.py in the harvester doc string, and add the Harvester to the list (similar to JPL Horizons harvester) in docs.api.tom_catelog.harvesters.rst?

I'll take care of the form stuff. That might be more complicated.


# Save Target, adding in additional names
# target.save(names=extra_desigs)
target.save()
Copy link
Contributor

Choose a reason for hiding this comment

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

This bypasses the form.
Basically this submits the target during the search phase and populates the form with already saved information.
I understand why this is done like this, but what we actually want is to populate the alias fields in the form and save them after the form is submitted.

I'll work on figuring out how to pipe this through correcty.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was the way I could get it work and make the tests pass without getting duplication (in the case of provisional id only) or missing ids. I'm sure it's not the only way though...

Copy link
Contributor

Choose a reason for hiding this comment

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

This was much easier than I thought.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It breaks the tests for me:

======================================================================
ERROR: test_to_target (tom_catalogs.tests.harvesters.test_mpc.TestMPCExplorerHarvester.test_to_target)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/eng/git/tom_base/tom_catalogs/tests/harvesters/test_mpc.py", line 34, in test_to_target
    self.assertEqual(target.names, ['65803', 'Didymos', '1996 GT'])
                     ^^^^^^^^^^^^
  File "/home/eng/git/tom_base/tom_targets/base_models.py", line 491, in names
    return [self.name] + [alias.name for alias in self.aliases.all()]
                                                  ^^^^^^^^^^^^^^^^^^
  File "/home/eng/venv/tombase311_venv/lib64/python3.11/site-packages/django/db/models/manager.py", line 164, in all
    return self.get_queryset()
           ^^^^^^^^^^^^^^^^^^^
  File "/home/eng/venv/tombase311_venv/lib64/python3.11/site-packages/django/db/models/fields/related_descriptors.py", line 718, in get_queryset
    raise ValueError(
ValueError: 'BaseTarget' instance needs to have a primary key value before this relationship can be used.

Copy link
Contributor

Choose a reason for hiding this comment

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

yes. working on that.

@jchate6 jchate6 merged commit 2f63bcb into TOMToolkit:dev Jan 31, 2025
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Data Services Data Services User Issue Raised by a user
Projects
Status: Merged (to dev)
Development

Successfully merging this pull request may close these issues.

2 participants