fornax-navo / fornax-demo-notebooks

Demo notebooks for the Fornax project
https://fornax-navo.github.io/fornax-demo-notebooks/
BSD 3-Clause "New" or "Revised" License
7 stars 19 forks source link

BUG: Gaia call throwing `KeyError` #265

Closed troyraen closed 2 months ago

troyraen commented 3 months ago

Using astroquery v0.4.7, the Gaia call is throwing a new error. Pasted below. I have not looked into it and don't know whether our code needs to change or if there is a bug in somewhere else in the chain.

KeyError                                  Traceback (most recent call last)
Cell In[3], line 4
      1 gaiastarttime = time.time()
      3 # get Gaia light curves
----> 4 df_lc_gaia = gaia_get_lightcurves(sample_table, search_radius=1/3600, verbose=0)
      6 # add the resulting dataframe to all other archives
      7 df_lc.append(df_lc_gaia)

File ~/raen/fdn-tmp/light_curves/code_src/gaia_functions.py:45, in gaia_get_lightcurves(sample_table, search_radius, verbose)
     40     return MultiIndexDFObject()
     42 # Extract Light curves ===============
     43 # request the EPOCH_PHOTOMETRY from the Gaia DataLink Service
---> 45 gaia_df = Gaia_retrieve_epoch_photometry(gaia_table)
     47 #if the epochal photometry is empty, return an empty dataframe
     48 if len(gaia_df) == 0:

File ~/raen/fdn-tmp/light_curves/code_src/gaia_functions.py:138, in Gaia_retrieve_epoch_photometry(gaia_table)
    118 """
    119 Function to retrieve EPOCH_PHOTOMETRY catalog product for Gaia
    120 entries using the DataLink. Note that the IDs need to be DR3 source_id and needs to be a list.
   (...)
    132     
    133 """
    135 # gaia datalink server has a threshold of max 5000 requests,
    136 # so we break the input datasets into chunks of size <=5000 sources
    137 # and then send each chunk into the datalink server
--> 138 ids = list(gaia_table["source_id"])
    139 dl_threshold = 5000  # Datalink server threshold
    140 ids_chunks = list(Gaia_chunks(ids, dl_threshold))

File /opt/conda/envs/science_demo/lib/python3.11/site-packages/astropy/table/table.py:2061, in Table.__getitem__(self, item)
   2059 def __getitem__(self, item):
   2060     if isinstance(item, str):
-> 2061         return self.columns[item]
   2062     elif isinstance(item, (int, np.integer)):
   2063         return self.Row(self, item)

File /opt/conda/envs/science_demo/lib/python3.11/site-packages/astropy/table/table.py:264, in TableColumns.__getitem__(self, item)
    253 """Get items from a TableColumns object.
    254 
    255 ::
   (...)
    261   tc[1:3] # <TableColumns names=('b', 'c')>
    262 """
    263 if isinstance(item, str):
--> 264     return OrderedDict.__getitem__(self, item)
    265 elif isinstance(item, (int, np.integer)):
    266     return list(self.values())[item]

KeyError: 'source_id'

Originally posted by @troyraen in https://github.com/fornax-navo/fornax-demo-notebooks/issues/207#issuecomment-2009926032

bsipocz commented 2 months ago

There were some server side changes to the TAP tables at ESA that capitalized source_id (if you go into debug mode then you can see a SOURCE_ID column).

I merged a fix for this into astroquery, and pushed a dev release to pypi, so a pip install -U --pre astroquery should do the trick now. I wonder whether we need to update the requirements version to be 0.4.8 dev