Skip to content

Instantly share code, notes, and snippets.

@ntessore
Last active December 7, 2019 08:19
Show Gist options
  • Save ntessore/640649a60ef7f3008e7583ad5d449862 to your computer and use it in GitHub Desktop.
Save ntessore/640649a60ef7f3008e7583ad5d449862 to your computer and use it in GitHub Desktop.
download a file if not already downloaded
# download file if not already downloaded
def dl(url, file=None):
from urllib.request import urlretrieve
from urllib.parse import urlparse
import os.path
if file is None:
file = os.path.basename(urlparse(url).path)
if not os.path.exists(file):
urlretrieve(url, file)
return file
# get SED templates
sed_fits = fits.open(dl('https://github.com/blanton144/kcorrect/raw/master/data/templates/k_nmf_derived.default.fits'))
# can specify name of downloaded file as well
sed_fits = fits.open(dl('https://github.com/blanton144/kcorrect/raw/master/data/templates/k_nmf_derived.default.fits', 'templates.fits'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment