diff --git a/doc/data/sdss_colors/fetch_data.py b/doc/data/sdss_colors/fetch_data.py index 8dcfbd9..330ecd9 100644 --- a/doc/data/sdss_colors/fetch_data.py +++ b/doc/data/sdss_colors/fetch_data.py @@ -1,5 +1,12 @@ +from __future__ import print_function + import os -import urllib2 +# Supporting Python 2 and 3 +try: + import urllib.request as urllib2 +except ImportError: + import urllib2 + import numpy as np DTYPE_TRAIN = [('u-g', np.float32), @@ -28,7 +35,7 @@ destination = TRAIN_FILE.rstrip('.dat') + '.npy' if not os.path.exists(destination): url = SDSS_COLORS_URL + TRAIN_FILE - print "downloading data from", url + print("downloading data from", url) fhandle = opener.open(url) np.save(destination, np.loadtxt(opener.open(url), dtype=DTYPE_TRAIN)) @@ -36,7 +43,7 @@ destination = TEST_FILE.rstrip('.dat') + '.npy' if not os.path.exists(destination): url = SDSS_COLORS_URL + TEST_FILE - print "downloading data from", url + print("downloading data from", url) fhandle = opener.open(url) np.save(destination, np.loadtxt(opener.open(url), dtype=DTYPE_TEST)) diff --git a/doc/data/sdss_colors/scatter_colors.py b/doc/data/sdss_colors/scatter_colors.py index 555a94a..78c142e 100644 --- a/doc/data/sdss_colors/scatter_colors.py +++ b/doc/data/sdss_colors/scatter_colors.py @@ -1,3 +1,4 @@ +from __future__ import print_function import numpy as np import pylab as pl @@ -9,8 +10,8 @@ redshift = data['redshift'] -print "%i qsos" % np.sum(redshift > 0) -print "%i stars" % np.sum(redshift == 0) +print("%i qsos" % np.sum(redshift > 0)) +print("%i stars" % np.sum(redshift == 0)) kwargs = dict(s=1, c=(redshift > 0), lw=0) diff --git a/doc/data/sdss_photoz/fetch_data.py b/doc/data/sdss_photoz/fetch_data.py index fe19ea4..1d060d0 100644 --- a/doc/data/sdss_photoz/fetch_data.py +++ b/doc/data/sdss_photoz/fetch_data.py @@ -4,9 +4,15 @@ queries the SDSS database for the information, and thus can take a few minutes to run. """ - +from __future__ import print_function import os -import urllib, urllib2 +import urllib +# Supporting Python 2 and 3 +try: + import urllib.request as urllib2 +except ImportError: + import urllib2 + import numpy as np # Here's how the data can be downloaded directly from the SDSS server. @@ -42,17 +48,17 @@ def sql_query(sql_str, url=URL, format='csv'): if not os.path.exists(archive_file): - print "querying for %i objects" % N - print query_text + print("querying for %i objects" % N) + print(query_text) output = sql_query(query_text) - print "finished. Processing & saving data" + print("finished. Processing & saving data") try: data = np.loadtxt(output, delimiter=',', skiprows=1, dtype=DTYPE) except: raise ValueError(output.read()) np.save(archive_file, data) else: - print "data already on disk" + print("data already on disk") DATA_URL = ('http://www.astro.washington.edu/users/' @@ -67,6 +73,6 @@ def sql_query(sql_str, url=URL, format='csv'): # download training data if not os.path.exists(LOCAL_FILE): - print "downloading data from", DATA_URL + print("downloading data from", DATA_URL) fhandle = opener.open(DATA_URL) open(LOCAL_FILE, 'wb').write(fhandle.read()) diff --git a/doc/data/sdss_spectra/fetch_data.py b/doc/data/sdss_spectra/fetch_data.py index f576019..9c97ca6 100644 --- a/doc/data/sdss_spectra/fetch_data.py +++ b/doc/data/sdss_spectra/fetch_data.py @@ -1,5 +1,12 @@ +from __future__ import print_function import os -import urllib2 + +# Supporting Python 2 and 3 +try: + import urllib.request as urllib2 +except ImportError: + import urllib2 + import numpy as np DATA_URL = ('http://www.astro.washington.edu/users/' @@ -14,6 +21,6 @@ # download training data if not os.path.exists(LOCAL_FILE): - print "downloading data from", DATA_URL + print("downloading data from", DATA_URL) fhandle = opener.open(DATA_URL) open(LOCAL_FILE, 'wb').write(fhandle.read())