Skip to content

Commit 550f2a3

Browse files
authored
Merge pull request #734 from evertrol/progress-bar-toggle
Make the download progress bar optional
2 parents e3dd3de + e2358ce commit 550f2a3

File tree

10 files changed

+91
-56
lines changed

10 files changed

+91
-56
lines changed

CHANGES

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
0.3.3.dev
22
---------
33

4-
- none yet
4+
- Option to toggle the display of the download bar (#734)
55

66
0.3.2 (2016-06-10)
77
------------------

astroquery/alfalfa/core.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def query_region(self, coordinates, radius=3. * u.arcmin,
160160
else:
161161
return None
162162

163-
def get_spectrum_async(self, agc):
163+
def get_spectrum_async(self, agc, show_progress=True):
164164
"""
165165
Download spectrum from ALFALFA catalogue.
166166
@@ -186,11 +186,11 @@ def get_spectrum_async(self, agc):
186186
agc = str(agc).zfill(6)
187187

188188
link = "%s/A%s.fits" % (self.FITS_PREFIX, agc)
189-
result = commons.FileContainer(link)
189+
result = commons.FileContainer(link, show_progress=show_progress)
190190
return result
191191

192192
@prepend_docstr_noreturns(get_spectrum_async.__doc__)
193-
def get_spectrum(self, agc):
193+
def get_spectrum(self, agc, show_progress=True):
194194
"""
195195
Returns
196196
-------
@@ -199,7 +199,7 @@ def get_spectrum(self, agc):
199199
200200
"""
201201

202-
result = self.get_spectrum_async(agc)
202+
result = self.get_spectrum_async(agc, show_progress=show_progress)
203203
hdulist = result.get_fits()
204204
return hdulist
205205

astroquery/irsa_dust/core.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ class IrsaDustClass(BaseQuery):
4747
}
4848

4949
def get_images(self, coordinate, radius=None,
50-
image_type=None, timeout=TIMEOUT, get_query_payload=False):
50+
image_type=None, timeout=TIMEOUT, get_query_payload=False,
51+
show_progress=True):
5152
"""
5253
A query function that performs a coordinate-based query to acquire
5354
Irsa-Dust images.
@@ -85,11 +86,12 @@ def get_images(self, coordinate, radius=None,
8586
return self._args_to_payload(coordinate, radius=radius)
8687
readable_objs = self.get_images_async(
8788
coordinate, radius=radius, image_type=image_type, timeout=timeout,
88-
get_query_payload=get_query_payload)
89+
get_query_payload=get_query_payload, show_progress=show_progress)
8990
return [obj.get_fits() for obj in readable_objs]
9091

9192
def get_images_async(self, coordinate, radius=None, image_type=None,
92-
timeout=TIMEOUT, get_query_payload=False):
93+
timeout=TIMEOUT, get_query_payload=False,
94+
show_progress=True):
9395
"""
9496
A query function similar to
9597
`astroquery.irsa_dust.IrsaDustClass.get_images` but returns
@@ -133,7 +135,8 @@ def get_images_async(self, coordinate, radius=None, image_type=None,
133135

134136
# Images are assumed to be FITS files
135137
# they MUST be read as binary for python3 to parse them
136-
return [commons.FileContainer(U, encoding='binary')
138+
return [commons.FileContainer(U, encoding='binary',
139+
show_progress=show_progress)
137140
for U in image_urls]
138141

139142
def get_image_list(self, coordinate, radius=None, image_type=None,
@@ -176,7 +179,8 @@ def get_image_list(self, coordinate, radius=None, image_type=None,
176179
response = commons.send_request(url, request_payload, timeout)
177180
return self.extract_image_urls(response.text, image_type=image_type)
178181

179-
def get_extinction_table(self, coordinate, radius=None, timeout=TIMEOUT):
182+
def get_extinction_table(self, coordinate, radius=None, timeout=TIMEOUT,
183+
show_progress=True):
180184
"""
181185
Query function that fetches the extinction table from the query
182186
result.
@@ -201,16 +205,16 @@ def get_extinction_table(self, coordinate, radius=None, timeout=TIMEOUT):
201205
--------
202206
table : `~astropy.table.Table`
203207
"""
204-
readable_obj = self.get_extinction_table_async(coordinate,
205-
radius=radius,
206-
timeout=timeout)
208+
readable_obj = self.get_extinction_table_async(
209+
coordinate, radius=radius, timeout=timeout,
210+
show_progress=show_progress)
207211
# guess=False to suppress error messages related to bad guesses
208212
table = Table.read(readable_obj.get_string(), format='ipac',
209213
guess=False)
210214
return table
211215

212216
def get_extinction_table_async(self, coordinate, radius=None,
213-
timeout=TIMEOUT):
217+
timeout=TIMEOUT, show_progress=True):
214218
"""
215219
A query function similar to
216220
`astroquery.irsa_dust.IrsaDustClass.get_extinction_table` but
@@ -242,7 +246,8 @@ def get_extinction_table_async(self, coordinate, radius=None,
242246
response = commons.send_request(url, request_payload, timeout)
243247
xml_tree = utils.xml(response.text)
244248
result = SingleDustResult(xml_tree, coordinate)
245-
return commons.FileContainer(result.ext_detail_table())
249+
return commons.FileContainer(result.ext_detail_table(),
250+
show_progress=show_progress)
246251

247252
def get_query_table(self, coordinate, radius=None,
248253
section=None, timeout=TIMEOUT, url=DUST_SERVICE_URL):

astroquery/irsa_dust/tests/test_irsa_dust.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,10 @@ class MockResponse:
331331
return MockResponse
332332

333333
def get_ext_table_async_mockreturn(self, coordinate, radius=None,
334-
timeout=IrsaDust.TIMEOUT):
335-
return(commons.FileContainer(self.data(EXT_TBL)))
334+
timeout=IrsaDust.TIMEOUT,
335+
show_progress=True):
336+
return(commons.FileContainer(self.data(EXT_TBL),
337+
show_progress=show_progress))
336338

337339
def get_image_list_mockreturn(
338340
self, coordinate, radius=None, image_type=None,
@@ -341,9 +343,11 @@ def get_image_list_mockreturn(
341343

342344
def get_images_async_mockreturn(self, coordinate, radius=None,
343345
image_type=None, timeout=IrsaDust.TIMEOUT,
344-
get_query_payload=False):
346+
get_query_payload=False,
347+
show_progress=True):
345348
readable_obj = commons.FileContainer(self.data(IMG_FITS),
346-
encoding='binary')
349+
encoding='binary',
350+
show_progress=show_progress)
347351
return [readable_obj]
348352

349353
def set_ext_table_text(self, text, xml_tree):

astroquery/ned/core.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,8 @@ def query_refcode_async(self, refcode, get_query_payload=False):
343343
Ned.TIMEOUT, request_type='GET')
344344
return response
345345

346-
def get_images(self, object_name, get_query_payload=False):
346+
def get_images(self, object_name, get_query_payload=False,
347+
show_progress=True):
347348
"""
348349
Query function to fetch FITS images for a given identifier.
349350
@@ -361,13 +362,15 @@ def get_images(self, object_name, get_query_payload=False):
361362
362363
"""
363364
readable_objs = self.get_images_async(
364-
object_name, get_query_payload=get_query_payload)
365+
object_name, get_query_payload=get_query_payload,
366+
show_progress=show_progress)
365367

366368
if get_query_payload:
367369
return readable_objs
368370
return [obj.get_fits() for obj in readable_objs]
369371

370-
def get_images_async(self, object_name, get_query_payload=False):
372+
def get_images_async(self, object_name, get_query_payload=False,
373+
show_progress=True):
371374
"""
372375
Serves the same purpose as `~NedClass.get_images` but returns
373376
file-handlers to the remote files rather than downloading them.
@@ -389,10 +392,12 @@ def get_images_async(self, object_name, get_query_payload=False):
389392
get_query_payload=get_query_payload)
390393
if get_query_payload:
391394
return image_urls
392-
return [commons.FileContainer(U, encoding='binary')
395+
return [commons.FileContainer(U, encoding='binary',
396+
show_progress=show_progress)
393397
for U in image_urls]
394398

395-
def get_spectra(self, object_name, get_query_payload=False):
399+
def get_spectra(self, object_name, get_query_payload=False,
400+
show_progress=True):
396401
"""
397402
Query function to fetch FITS files of spectra for a given identifier.
398403
@@ -410,13 +415,15 @@ def get_spectra(self, object_name, get_query_payload=False):
410415
411416
"""
412417
readable_objs = self.get_spectra_async(
413-
object_name, get_query_payload=get_query_payload)
418+
object_name, get_query_payload=get_query_payload,
419+
show_progress=show_progress)
414420

415421
if get_query_payload:
416422
return readable_objs
417423
return [obj.get_fits() for obj in readable_objs]
418424

419-
def get_spectra_async(self, object_name, get_query_payload=False):
425+
def get_spectra_async(self, object_name, get_query_payload=False,
426+
show_progress=True):
420427
"""
421428
Serves the same purpose as `~NedClass.get_spectra` but returns
422429
file-handlers to the remote files rather than downloading them.
@@ -438,7 +445,8 @@ def get_spectra_async(self, object_name, get_query_payload=False):
438445
get_query_payload=get_query_payload)
439446
if get_query_payload:
440447
return image_urls
441-
return [commons.FileContainer(U, encoding='binary')
448+
return [commons.FileContainer(U, encoding='binary',
449+
show_progress=show_progress)
442450
for U in image_urls]
443451

444452
def get_image_list(self, object_name, item='image',

astroquery/ned/tests/test_ned.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ def patch_get(request):
4848

4949
@pytest.fixture
5050
def patch_get_readable_fileobj(request):
51-
def get_readable_fileobj_mockreturn(filename, cache=True, encoding=None):
51+
def get_readable_fileobj_mockreturn(filename, cache=True, encoding=None,
52+
show_progress=True):
5253
# Need to read FITS files with binary encoding: should raise error
5354
# otherwise
5455
assert encoding == 'binary'

astroquery/nvas/core.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class NvasClass(BaseQuery):
3636

3737
def get_images(self, coordinates, radius=0.25 * u.arcmin, max_rms=10000,
3838
band="all", get_uvfits=False, verbose=True,
39-
get_query_payload=False):
39+
get_query_payload=False, show_progress=True):
4040
"""
4141
Get an image around a target/ coordinates from the NVAS image archive.
4242
@@ -74,7 +74,7 @@ def get_images(self, coordinates, radius=0.25 * u.arcmin, max_rms=10000,
7474
readable_objs = self.get_images_async(
7575
coordinates, radius=radius, max_rms=max_rms,
7676
band=band, get_uvfits=get_uvfits, verbose=verbose,
77-
get_query_payload=get_query_payload)
77+
get_query_payload=get_query_payload, show_progress=show_progress)
7878
if get_query_payload:
7979
return readable_objs
8080

@@ -84,7 +84,8 @@ def get_images(self, coordinates, radius=0.25 * u.arcmin, max_rms=10000,
8484

8585
def get_images_async(self, coordinates, radius=0.25 * u.arcmin,
8686
max_rms=10000, band="all", get_uvfits=False,
87-
verbose=True, get_query_payload=False):
87+
verbose=True, get_query_payload=False,
88+
show_progress=True):
8889
"""
8990
Serves the same purpose as `get_images` but
9091
returns a list of file handlers to remote files.
@@ -131,7 +132,8 @@ def get_images_async(self, coordinates, radius=0.25 * u.arcmin,
131132
if verbose:
132133
print("{num} images found.".format(num=len(image_urls)))
133134

134-
return [commons.FileContainer(U, encoding='binary')
135+
return [commons.FileContainer(U, encoding='binary',
136+
show_progress=show_progress)
135137
for U in image_urls]
136138

137139
def get_image_list(self, coordinates, radius=0.25 * u.arcmin,

astroquery/sdss/core.py

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ class = 'galaxy' \
478478
def get_spectra_async(self, coordinates=None, radius=2. * u.arcsec,
479479
matches=None, plate=None, fiberID=None, mjd=None,
480480
timeout=TIMEOUT, get_query_payload=False,
481-
data_release=12, cache=True):
481+
data_release=12, cache=True, show_progress=True):
482482
"""
483483
Download spectrum from SDSS.
484484
@@ -590,14 +590,16 @@ def get_spectra_async(self, coordinates=None, radius=2. * u.arcsec,
590590

591591
results.append(commons.FileContainer(link,
592592
encoding='binary',
593-
remote_timeout=timeout))
593+
remote_timeout=timeout,
594+
show_progress=show_progress))
594595

595596
return results
596597

597598
@prepend_docstr_noreturns(get_spectra_async.__doc__)
598599
def get_spectra(self, coordinates=None, radius=2. * u.arcsec,
599600
matches=None, plate=None, fiberID=None, mjd=None,
600-
timeout=TIMEOUT, cache=True, data_release=12):
601+
timeout=TIMEOUT, cache=True, data_release=12,
602+
show_progress=True):
601603
"""
602604
Returns
603605
-------
@@ -609,7 +611,8 @@ def get_spectra(self, coordinates=None, radius=2. * u.arcsec,
609611
radius=radius, matches=matches,
610612
plate=plate, fiberID=fiberID,
611613
mjd=mjd, timeout=timeout,
612-
data_release=data_release)
614+
data_release=data_release,
615+
show_progress=show_progress)
613616

614617
if readable_objs is not None:
615618
if isinstance(readable_objs, dict):
@@ -620,7 +623,8 @@ def get_spectra(self, coordinates=None, radius=2. * u.arcsec,
620623
def get_images_async(self, coordinates=None, radius=2. * u.arcsec,
621624
matches=None, run=None, rerun=301, camcol=None,
622625
field=None, band='g', timeout=TIMEOUT,
623-
get_query_payload=False, cache=True, data_release=12):
626+
get_query_payload=False, cache=True, data_release=12,
627+
show_progress=True):
624628
"""
625629
Download an image from SDSS.
626630
@@ -730,18 +734,18 @@ def get_images_async(self, coordinates=None, radius=2. * u.arcsec,
730734
rerun=row['rerun'], camcol=row['camcol'],
731735
field=row['field'], band=b)
732736

733-
results.append(commons.FileContainer(link,
734-
encoding='binary',
735-
remote_timeout=timeout,
736-
cache=cache))
737+
results.append(commons.FileContainer(
738+
link, encoding='binary', remote_timeout=timeout,
739+
cache=cache, show_progress=show_progress))
737740

738741
return results
739742

740743
@prepend_docstr_noreturns(get_images_async.__doc__)
741744
def get_images(self, coordinates=None, radius=2. * u.arcsec,
742745
matches=None, run=None, rerun=301, camcol=None, field=None,
743746
band='g', timeout=TIMEOUT, cache=True,
744-
get_query_payload=False, data_release=12):
747+
get_query_payload=False, data_release=12,
748+
show_progress=True):
745749
"""
746750
Returns
747751
-------
@@ -752,15 +756,17 @@ def get_images(self, coordinates=None, radius=2. * u.arcsec,
752756
readable_objs = self.get_images_async(
753757
coordinates=coordinates, radius=radius, matches=matches, run=run,
754758
rerun=rerun, data_release=data_release, camcol=camcol, field=field,
755-
band=band, timeout=timeout, get_query_payload=get_query_payload)
759+
band=band, timeout=timeout, get_query_payload=get_query_payload,
760+
show_progress=show_progress)
756761

757762
if readable_objs is not None:
758763
if isinstance(readable_objs, dict):
759764
return readable_objs
760765
else:
761766
return [obj.get_fits() for obj in readable_objs]
762767

763-
def get_spectral_template_async(self, kind='qso', timeout=TIMEOUT):
768+
def get_spectral_template_async(self, kind='qso', timeout=TIMEOUT,
769+
show_progress=True):
764770
"""
765771
Download spectral templates from SDSS DR-2.
766772
@@ -806,21 +812,23 @@ def get_spectral_template_async(self, kind='qso', timeout=TIMEOUT):
806812
link = '%s-%s.fit' % (self.TEMPLATES_URL, name)
807813
results.append(commons.FileContainer(link,
808814
remote_timeout=timeout,
809-
encoding='binary'))
815+
encoding='binary',
816+
show_progress=show_progress))
810817

811818
return results
812819

813820
@prepend_docstr_noreturns(get_spectral_template_async.__doc__)
814-
def get_spectral_template(self, kind='qso', timeout=TIMEOUT):
821+
def get_spectral_template(self, kind='qso', timeout=TIMEOUT,
822+
show_progress=True):
815823
"""
816824
Returns
817825
-------
818826
list : List of `~astropy.io.fits.HDUList` objects.
819827
820828
"""
821829

822-
readable_objs = self.get_spectral_template_async(kind=kind,
823-
timeout=timeout)
830+
readable_objs = self.get_spectral_template_async(
831+
kind=kind, timeout=timeout, show_progress=show_progress)
824832

825833
if readable_objs is not None:
826834
return [obj.get_fits() for obj in readable_objs]

0 commit comments

Comments
 (0)