|
18 | 18 |
|
19 | 19 | from astroquery.query import BaseVOQuery |
20 | 20 | from astroquery.utils import commons |
21 | | -from astroquery.exceptions import LargeQueryWarning, NoResultsWarning |
| 21 | +from astroquery.exceptions import NoResultsWarning |
22 | 22 | from astroquery.simbad.utils import (_catch_deprecated_fields_with_arguments, |
23 | 23 | _wildcard_to_regexp, CriteriaTranslator, |
24 | 24 | query_criteria_fields) |
@@ -698,7 +698,7 @@ def query_objects(self, object_names, *, wildcard=False, criteria=None, |
698 | 698 |
|
699 | 699 | @deprecated_renamed_argument(["equinox", "epoch", "cache"], |
700 | 700 | new_name=[None]*3, |
701 | | - alternative=["astropy.coordinates.SkyCoord"]*3, |
| 701 | + alternative=["astropy.coordinates.SkyCoord"]*2 + [None], |
702 | 702 | since=['0.4.8']*3, relax=True) |
703 | 703 | def query_region(self, coordinates, radius=2*u.arcmin, *, |
704 | 704 | criteria=None, get_query_payload=False, |
@@ -768,42 +768,54 @@ def query_region(self, coordinates, radius=2*u.arcmin, *, |
768 | 768 | center = center.transform_to("icrs") |
769 | 769 |
|
770 | 770 | top, columns, joins, instance_criteria = self._get_query_parameters() |
| 771 | + if criteria: |
| 772 | + instance_criteria.append(f"({criteria})") |
771 | 773 |
|
772 | 774 | if center.isscalar: |
773 | 775 | radius = coord.Angle(radius) |
774 | 776 | instance_criteria.append(f"CONTAINS(POINT('ICRS', basic.ra, basic.dec), " |
775 | 777 | f"CIRCLE('ICRS', {center.ra.deg}, {center.dec.deg}, " |
776 | 778 | f"{radius.to(u.deg).value})) = 1") |
| 779 | + return self._query(top, columns, joins, instance_criteria, |
| 780 | + get_query_payload=get_query_payload) |
777 | 781 |
|
| 782 | + # from uploadLimit in SIMBAD's capabilities |
| 783 | + # http://simbad.cds.unistra.fr/simbad/sim-tap/capabilities |
| 784 | + if len(center) > 200000: |
| 785 | + raise ValueError("'query_region' can process up to 200000 centers. For " |
| 786 | + "larger queries, split your centers list.") |
| 787 | + |
| 788 | + # `radius` as `str` is iterable, but contains only one value. |
| 789 | + if isiterable(radius) and not isinstance(radius, str): |
| 790 | + if len(radius) != len(center): |
| 791 | + raise ValueError(f"Mismatch between radii of length {len(radius)}" |
| 792 | + f" and center coordinates of length {len(center)}.") |
| 793 | + radius = [coord.Angle(item).to(u.deg).value for item in radius] |
778 | 794 | else: |
779 | | - if len(center) > 10000: |
780 | | - warnings.warn( |
781 | | - "For very large queries, you may receive a timeout error. SIMBAD suggests" |
782 | | - " splitting queries with >10000 entries into multiple threads", |
783 | | - LargeQueryWarning, stacklevel=2 |
784 | | - ) |
785 | | - |
786 | | - # `radius` as `str` is iterable, but contains only one value. |
787 | | - if isiterable(radius) and not isinstance(radius, str): |
788 | | - if len(radius) != len(center): |
789 | | - raise ValueError(f"Mismatch between radii of length {len(radius)}" |
790 | | - f" and center coordinates of length {len(center)}.") |
791 | | - radius = [coord.Angle(item) for item in radius] |
792 | | - else: |
793 | | - radius = [coord.Angle(radius)] * len(center) |
| 795 | + radius = [coord.Angle(radius).to(u.deg).value] * len(center) |
794 | 796 |
|
| 797 | + # for small number of centers, not using the upload method is faster |
| 798 | + if len(center) <= 300: |
795 | 799 | cone_criteria = [(f"CONTAINS(POINT('ICRS', basic.ra, basic.dec), CIRCLE('ICRS', " |
796 | | - f"{center.ra.deg}, {center.dec.deg}, {radius.to(u.deg).value})) = 1 ") |
| 800 | + f"{center.ra.deg}, {center.dec.deg}, {radius})) = 1 ") |
797 | 801 | for center, radius in zip(center, radius)] |
798 | 802 |
|
799 | 803 | cone_criteria = f" ({'OR '.join(cone_criteria)})" |
800 | 804 | instance_criteria.append(cone_criteria) |
801 | 805 |
|
802 | | - if criteria: |
803 | | - instance_criteria.append(f"({criteria})") |
| 806 | + return self._query(top, columns, joins, instance_criteria, |
| 807 | + get_query_payload=get_query_payload) |
| 808 | + |
| 809 | + # for longer centers list, we use a TAP upload |
| 810 | + upload_centers = Table({"ra": center.ra.deg, "dec": center.dec.deg, |
| 811 | + "radius": radius}) |
| 812 | + sub_query = "(SELECT ra, dec, radius FROM TAP_UPLOAD.centers) AS centers" |
| 813 | + instance_criteria.append("CONTAINS(POINT('ICRS', basic.ra, basic.dec), CIRCLE" |
| 814 | + "('ICRS', centers.ra, centers.dec, centers.radius)) = 1 ") |
804 | 815 |
|
805 | 816 | return self._query(top, columns, joins, instance_criteria, |
806 | | - get_query_payload=get_query_payload) |
| 817 | + from_table=f"{sub_query}, basic", |
| 818 | + get_query_payload=get_query_payload, centers=upload_centers) |
807 | 819 |
|
808 | 820 | @deprecated_renamed_argument(["verbose", "cache"], new_name=[None, None], |
809 | 821 | since=['0.4.8', '0.4.8'], relax=True) |
|
0 commit comments