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
689 stars 393 forks source link

Vizier.query_region() returns incorrect index for some catalog #3049

Open Chisen-Lupus opened 1 month ago

Chisen-Lupus commented 1 month ago

Hi,

I recently tried to use Vizier.query_region function to batch query items in a data table. It seems like for some catalog, the first keyword of the returned table, _q, does not show the arrray index of the queried item in the original table as expected. Here is how it behaviors and how to reproduce it:

import astroquery
print(astroquery.__version__) 
# output: 0.4.7

from astroquery.vizier import Vizier
# get 10 items that are definitely in the catalog 'II/335'
t = Vizier(catalog="II/335", columns=['*', '_RAJ2000', '_DEJ2000']).query_constraints()[0][:10]
# query them in the catalog 'II/335'
result = Vizier.query_region(t, width="5s", catalog=["II/335"])[0]
print([item['_q'] for item in result]) 
# output: [1, 6, 11, 16, 21, 26, 31, 36, 41, 46]
# expected: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

It seems like each index stored by _q is multiplied by 5 and then subtracted by 4. This behavior is not the same for every dataset, so I also want to report that when repeating the above code to the catalog II/312 (the Galex UV catalog), the output would be [1, 3, 5, 7, 9, 11, 13, 15, 17, 19].

ManonMarchand commented 1 month ago

These correspond to the number of tables in the catalog. Here II/335 has 5 tables whereas II/312 has 2. It looks like you only get matches from the first table of the catalog each time.

[Edit]

I looked into these two catalogs:

ManonMarchand commented 1 month ago

So, the results of the investigation (I got lots of explanations from @glandais). Actually, if the results matched in all tables, we'd expect [1,1,1,1,1,2,2,2,2,2...] for a catalog with 5 tables and [1,1,2,2,3,3...] for a catalog with 2 tables. So this is indeed a bug, likely a counter that does not increment in the right place) that @glandais will try to fix upstream.

Possible workarounds while waiting for the fix upstream

from astroquery.vizier import Vizier
t = Vizier(catalog="II/335", columns=['*', '_RAJ2000', '_DEJ2000']).query_constraints()[0][:10]
# query them in the catalog 'II/335'
result = Vizier(columns=["_1"]).query_region(t, width="5s", catalog=["II/335/galex_ais"])[0]
<Table length=10>
  _q            _1            RAJ2000    DEJ2000            Name            r.fov     b    FUVmag ... e_NUVmag  Fafl  Nafl  Fexf  Nexf     Fr        Nr   
                                deg        deg                               deg            mag   ...   mag                               deg       deg   
int32         str24           float64    float64           str22           float64  uint8 float64 ... float32  int16 int16 int16 int16  float64   float64 
----- ---------------------- ---------- ---------- ---------------------- --------- ----- ------- ... -------- ----- ----- ----- ----- --------- ---------
    1 45.39319700+0.83199900  45.393197   0.831999 GALEX J030134.3+004955  0.462940     1      -- ...   0.1268   256     0     0     0        --  0.002794
    2 45.37659800+0.83901900  45.376598   0.839019 GALEX J030130.3+005020  0.465953     1      -- ...   0.4780   256     1     0     0        --  0.002680
    3 45.38394100+0.84482200  45.383941   0.844822 GALEX J030132.1+005041  0.529154     1      -- ...   0.4722     0     0     0     0        --  0.001294
    4 45.40180000+0.84974100  45.401800   0.849741 GALEX J030136.4+005059  0.482279     3 22.1674 ...   0.3064     0     0     0     0  0.002074  0.004597
    5 45.31170800+0.79905800  45.311708   0.799058 GALEX J030114.8+004756  0.416818     3 20.2951 ...   0.0783     0     0     0     0  0.004551  0.002193
    6 45.30472100+0.80272300  45.304721   0.802723 GALEX J030113.1+004809  0.419970     1      -- ...   0.4482     0     0     0     0        --  0.002482
    7 45.32065300+0.81063500  45.320653   0.810635 GALEX J030116.9+004838  0.429153     1      -- ...   0.4141     0     1     0     0        --  0.002241
    8 45.32989800+0.81712200  45.329898   0.817122 GALEX J030119.1+004901  0.436609     3 21.5729 ...   0.4035     0     1     0     0  0.003513  0.004100
    9 45.33925000+0.81810400  45.339250   0.818104 GALEX J030121.4+004905  0.438789     1      -- ...   0.3703     0     0     0     0        --  0.004177
   10 45.32492500+0.83517700  45.324925   0.835177 GALEX J030117.9+005006  0.454001     1      -- ...   0.3431     0     1     0     0        --  0.002732
Chisen-Lupus commented 1 month ago

Many thanks for explaining this!