|
6 | 6 | import tarfile
|
7 | 7 | import warnings
|
8 | 8 | import numpy as np
|
9 |
| -from astropy.table import Table, Row |
| 9 | +from astropy.table import Table, Row, vstack |
10 | 10 | from astropy import coordinates
|
11 | 11 | from astropy import units as u
|
12 | 12 | from astropy.utils.decorators import deprecated, deprecated_renamed_argument
|
| 13 | +from pathlib import Path |
13 | 14 |
|
14 | 15 | import pyvo
|
15 | 16 |
|
@@ -517,13 +518,35 @@ def locate_data(self, query_result=None, catalog_name=None):
|
517 | 518 |
|
518 | 519 | # datalink url
|
519 | 520 | dlink_url = f'{self.VO_URL}/datalink/{catalog_name}'
|
| 521 | + def query_func(query_chunk): |
| 522 | + return pyvo.dal.adhoc.DatalinkQuery( |
| 523 | + baseurl=dlink_url, |
| 524 | + id=query_chunk['__row'], |
| 525 | + session=self._session |
| 526 | + ) |
| 527 | + |
| 528 | + # Standard URL limit of ~2000 characters for GET |
| 529 | + # With query formula https://[urlbase]?ID=###, could get 100 16 digit IDs |
| 530 | + URI_MAX = 100 |
| 531 | + if len(query_result) > URI_MAX: |
| 532 | + # execute a set amount at a time |
| 533 | + chunks = len(query_result) % URI_MAX |
| 534 | + for chunk in range(chunks): |
| 535 | + query_chunk = query_result[URI_MAX*chunk: URI_MAX*chunk+URI_MAX] |
| 536 | + query = query_func(query_chunk) |
| 537 | + dl_result_chunk = query.execute().to_table() |
| 538 | + if chunk == 0: |
| 539 | + dl_result = dl_result_chunk |
| 540 | + else: |
| 541 | + dl_result = vstack([dl_result, dl_result_chunk]) |
| 542 | + query_chunk = query_result[URI_MAX*chunk+URI_MAX:] |
| 543 | + query = query_func(query_chunk) |
| 544 | + dl_result_chunk = query.execute().to_table() |
| 545 | + dl_result = vstack([dl_result, dl_result_chunk]) |
| 546 | + else: |
| 547 | + query = query_func(query_result) |
| 548 | + dl_result = query.execute().to_table() |
520 | 549 |
|
521 |
| - query = pyvo.dal.adhoc.DatalinkQuery( |
522 |
| - baseurl=dlink_url, |
523 |
| - id=query_result['__row'], |
524 |
| - session=self._session |
525 |
| - ) |
526 |
| - dl_result = query.execute().to_table() |
527 | 550 | # include rows that have directory links (i.e. data) and those
|
528 | 551 | # that report errors (usually means there are no data products)
|
529 | 552 | dl_result = dl_result[np.ma.mask_or(
|
|
0 commit comments