astropy / astroquery

Functions and classes to access online data resources. Maintainers: @keflavich and @bsipocz and @ceb8
http://astroquery.readthedocs.org/en/latest/
BSD 3-Clause "New" or "Revised" License
706 stars 400 forks source link

Error in astroquery.mpc #1732

Open martinBanda opened 4 years ago

martinBanda commented 4 years ago

Hello, I am trying to use MPC library from astroquery.mpc to get all reported observations (in Minor Planet Center) for the asteroid 137295 (1999 RB216). The result is different when the asteroid's name (result=38 lines) is used instead of the number (result=333 lines). Could anyone please check if this problem is really happening? if yes, what would be the solution?

bsipocz commented 4 years ago

Could you please include a complete example of code that would reproduce the issue? Also, please report your astropy and astroquery versions. Is the main MPC webpage works as you expect for these two cases?

martinBanda commented 4 years ago

astropy: 4.0 astroquery: 0.4.1.dev0

Below an example:

from astroquery.mpc import MPC

number, name = 137295, '1999 RB216'

obs = MPC.get_observations(number, get_mpcformat=True)
obs2 = MPC.get_observations(name, get_mpcformat=True)

print(len(obs))   #output: 333
print(len(obs2))  #output: 38

There are 333 observations, according the main MPC webpage: https://minorplanetcenter.net/db_search/show_object?object_id=137295

but, in the download version (click in download link) there are 341 observations.

The "obs" variable (in example) actually has 341 observations stored in 333 lines, which means that 2 observations are being stored by line for 8 of the 333 lines (lines 121 to 128).

I used the next code to write, in a ascii file, the content of the "obs" variable:

import numpy as np

obs_data = obs['obs'].data
np.savetxt('test.txt', obs_data, fmt='%s')

The version of my numpy is: 1.18.1

bsipocz commented 2 months ago

cc @mkelley - this still seems to be an issue

mkelley commented 2 months ago

I think this is an issue with the service and not with astroquery. The raw responses have the same problem:

>>> from astroquery.mpc import MPC
>>> 
>>> number, name = 137295, '1999 RB216'
>>> 
>>> obs = MPC.get_observations_async(number, get_mpcformat=True)
>>> obs2 = MPC.get_observations_async(name, get_mpcformat=True)
>>> 
>>> print(len(obs2.json()))
38
>>> print(len(obs.json()))
363

There is a new API for getting observational data and it does not have this issue:

>>> import requests
>>> from xml.etree import ElementTree as ET
>>> 
>>> response = requests.get("https://data.minorplanetcenter.net/api/get-obs", json={"desigs": ["137295"]})
>>> obs = ET.fromstring(response.json()[0]["XML"])
>>> response = requests.get("https://data.minorplanetcenter.net/api/get-obs", json={"desigs": ["1999 RB216"]})
>>> obs2 = ET.fromstring(response.json()[0]["XML"])
>>> 
>>> print(len(obs.findall("optical")))
363
>>> print(len(obs2.findall("optical")))
363

Since the old API is or is going to be deprecated, the solution is to switch to the new API. Otherwise, open a help desk ticket at the MPC with the problem (but their answer might be to use the new API).

bsipocz commented 2 months ago

Since the old API is or is going to be deprecated

Do we have a roadmap/timeline to switch the astroquery module to use the new API?

mkelley commented 2 months ago

At the moment I can only say that I will not have time before November.