Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
6f12bc7
Add the dastcom5 module from poliastro
anhiga Jan 17, 2019
85e6ca0
Add the init file
shreyasbapat Jan 17, 2019
8fd6b0e
Add the core package for querying DASTCOM5
shreyasbapat Jan 17, 2019
dcf2fb5
Create a stack of tables for returning multiple orbits
shreyasbapat Jan 17, 2019
6633d0c
Complete the DASTCOM5 Module, Add tests
shreyasbapat Jan 17, 2019
1f825fd
Fix PEP8 Errors
shreyasbapat Jan 17, 2019
01898ca
Minor changes
shreyasbapat Jan 28, 2019
d3f26ff
Add Python2 Support
shreyasbapat Jan 28, 2019
8064ab6
Work on suggestions
shreyasbapat Jan 29, 2019
c973e3e
Fix download progress issue
amsuhane Feb 5, 2019
8d853fd
Remove vstack
shreyasbapat Feb 5, 2019
d34b2fc
Fix PEP8 issues!
shreyasbapat Feb 5, 2019
b0f3f07
Remove urllib, remove class, add _download_file
shreyasbapat Feb 6, 2019
9d479d6
Add the dastcom5 module from poliastro
anhiga Jan 17, 2019
0388788
Add the init file
shreyasbapat Jan 17, 2019
06c422e
Add the core package for querying DASTCOM5
shreyasbapat Jan 17, 2019
6c8cd85
Create a stack of tables for returning multiple orbits
shreyasbapat Jan 17, 2019
8739e0a
Complete the DASTCOM5 Module, Add tests
shreyasbapat Jan 17, 2019
b61374b
Fix PEP8 Errors
shreyasbapat Jan 17, 2019
d3986f3
Minor changes
shreyasbapat Jan 28, 2019
bc0d1eb
Add Python2 Support
shreyasbapat Jan 28, 2019
614b835
Work on suggestions
shreyasbapat Jan 29, 2019
cf28593
Fix download progress issue
amsuhane Feb 5, 2019
af17efd
Remove vstack
shreyasbapat Feb 5, 2019
e07b55f
Fix PEP8 issues!
shreyasbapat Feb 5, 2019
83c32a0
Remove urllib, remove class, add _download_file
shreyasbapat Feb 6, 2019
9be0535
Add ftp_download method
shreyasbapat Feb 7, 2019
29843a4
Merge branch 'dastcom' of https://github.com/shreyasbapat/astroquery …
shreyasbapat Feb 7, 2019
10d497f
Remove _ from download ftp
shreyasbapat Feb 7, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 2 additions & 14 deletions astroquery/dastcom5/core.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from __future__ import print_function
import re
import os
import urllib.request
import zipfile
import numpy as np
import pandas as pd
from tqdm import tqdm

from astropy.time import Time
from astropy.table import Table
Expand Down Expand Up @@ -39,7 +37,6 @@ def __init__(self, spk_id=None, name=None):
self.com_dtype = conf.COM_DTYPE
self.ast_dtype = conf.AST_DTYPE
self.ftp_url = conf.FTP_DB_URL
self._show_download_progress = self._Show_Download_Progress

def download_dastcom5(self):
"""Downloads DASTCOM5 database.
Expand All @@ -50,6 +47,7 @@ def download_dastcom5(self):

dastcom5_dir = os.path.join(self.local_path, "dastcom5")
dastcom5_zip_path = os.path.join(self.local_path, "dastcom5.zip")
ftp_path = self.ftp_url + "dastcom5.zip"

if os.path.isdir(dastcom5_dir):
raise FileExistsError(
Expand All @@ -61,21 +59,11 @@ def download_dastcom5(self):
os.makedirs(self.local_path)

print("Downloading datscom5.zip")
with self._show_download_progress(unit='B', unit_scale=True, miniters=1, desc="dastcom5.zip") as t:
urllib.request.urlretrieve(
self.ftp_url + "dastcom5.zip", filename=dastcom5_zip_path, reporthook=t.update_to)
self._download_file(url=ftp_path, local_filepath=dastcom5_zip_path)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. You could pass on some of the other optional keyword arguments here like timeout, cache, and continuation if you'd like. But this is fine.

Copy link
Author

@shreyasbapat shreyasbapat Feb 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was hoping it'd work fine, but it isn't on my system. I am unable to understand whether it is my internet connection and system or there is something wrong in the code


with zipfile.ZipFile(dastcom5_zip_path) as myzip:
myzip.extractall(self.local_path)

class _Show_Download_Progress(tqdm):
"""Helper class for displaying download progress bar when using download_dastcom5() function
"""
def update_to(self, b=1, bsize=1, tsize=None):
if tsize is not None:
self.total = tsize
self.update(b * bsize - self.n)

def asteroid_db(self):
"""Return complete DASTCOM5 asteroid database.

Expand Down
12 changes: 5 additions & 7 deletions astroquery/dastcom5/tests/test_dastcom5.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,14 @@ def test_download_dastcom5_creates_folder(mocker):


def test_download_dastcom5_downloads_file(mocker):
mock_request = mocker.patch(
"astroquery.dastcom5.urllib.request.urlretrieve")
mock_download = mocker.patch(
"astroquery.query.BaseQuery._download_file")
mock_isdir = mocker.patch("astroquery.dastcom5.os.path.isdir")
mock_zipfile = mocker.patch("astroquery.dastcom5.zipfile")
mock_isdir.side_effect = lambda x: x == Dastcom5.local_path
mock_zipfile.is_zipfile.return_value = False
Dastcom5.download_dastcom5()
mock_request.assert_called_once_with(
Dastcom5.ftp_url + "dastcom5.zip",
filename=os.path.join(Dastcom5.local_path, "dastcom5.zip"),
reporthook=Dastcom5.self._show_download_progress(
unit='B', unit_scale=True, miniters=1, desc="dastcom5.zip").update_to,
mock_download.assert_called_once_with(
url=Dastcom5.ftp_url + "dastcom5.zip",
local_filepath=os.path.join(Dastcom5.local_path, "dastcom5.zip"),
)