Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for Python 3 #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 10 additions & 3 deletions doc/data/sdss_colors/fetch_data.py
Original file line number Diff line number Diff line change
@@ -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),
Expand Down Expand Up @@ -28,15 +35,15 @@
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))

# download test data
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))

5 changes: 3 additions & 2 deletions doc/data/sdss_colors/scatter_colors.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import numpy as np
import pylab as pl

Expand All @@ -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)

Expand Down
20 changes: 13 additions & 7 deletions doc/data/sdss_photoz/fetch_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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/'
Expand All @@ -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())
11 changes: 9 additions & 2 deletions doc/data/sdss_spectra/fetch_data.py
Original file line number Diff line number Diff line change
@@ -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/'
Expand All @@ -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())