Getting started

On the Welcome page click the "Sign in" button. You will be taken to the login portal, where you can log in with your existing SciServer credentials, or register a new SciServer account.

Once successfully logged in, instead of the Welcome page you will see the empty Dashboard page. Click the "Create container" button to create your first container.

Enter a name for your container and click "Create".

A new container will appear in your dashboard.

Using the dashboard

Using Jupyter notebooks

When you open a Jupyter session from the Dashboard by clicking on the  icon, it will start in a new browser tab.

Create a new notebook by selecting "New" > "Notebooks" > "Python 3" from the menu. You can choose other kernels from the list as well. The available kernels will vary, depending on the container image that you are currently using.

The notebook will open in a new window. Type fragments of Python code in the input cells and execute them one by one by pressing Shift + Enter, or by clicking the "play" button.

You can rename the notebook by selecting "File" > "Rename..." from the notebook menu.

Calling SciServer services from Python scripts

from SciServer import CasJobs
query = "SELECT TOP 10 objid, ra, dec FROM PhotoObj"
result = CasJobs.executeQuery(query, "DR12")
result

Running astroML examples

You can find some astroML examples here:

http://www.astroml.org/book_figures/index.html
http://www.astroml.org/examples/index.html
http://cadence.lsst.org/introAstroML/blog/

K-Neighbors for Photometric Redshifts

This is the code for estimating redshifts from the colors of sdss galaxies and quasars. It uses both astroML and SciServer.CasJobs and is a modified version of the original posted here.

# Author: Jake VanderPlas <vanderplas@astro.washington.edu>
# License: BSD
#   The figure is an example from astroML: see http://astroML.github.com
# Modified by: Dmitry Medvedev <dmedv@jhu.edu>
from io import StringIO
import numpy as np
from matplotlib import pyplot as plt
from sklearn.neighbors import KNeighborsRegressor
from astroML.plotting import scatter_contour
from SciServer import CasJobs
NOBJECTS = 20000
GAL_COLORS_DTYPE = [('u', float),
                    ('g', float),
                    ('r', float),
                    ('i', float),
                    ('z', float),
                    ('redshift', float),
                    ('redshift_err', float)]
# get data from CasJobs
query_text = ('\n'.join(
    ("SELECT TOP %i" % NOBJECTS,
    "   p.u, p.g, p.r, p.i, p.z, s.z, s.zerr",
    "FROM PhotoObj AS p",
    "   JOIN SpecObj AS s ON s.bestobjid = p.objid",
    "WHERE ",
    "   p.u BETWEEN 0 AND 19.6",
    "   AND p.g BETWEEN 0 AND 20",
    "   AND (s.class = 'GALAXY' OR s.class = 'QSO')")))
response = CasJobs.executeQuery(query_text, "DR12", format="csv")
output = StringIO(response)
data = np.loadtxt(output, delimiter=',',skiprows=1, dtype=GAL_COLORS_DTYPE)
n_neighbors = 1
N = len(data)
# shuffle data
np.random.seed(0)
np.random.shuffle(data)
# put colors in a matrix
X = np.zeros((N, 4))
X[:, 0] = data['u'] - data['g']
X[:, 1] = data['g'] - data['r']
X[:, 2] = data['r'] - data['i']
X[:, 3] = data['i'] - data['z']
z = data['redshift']
# divide into training and testing data
Ntrain = N // 2
Xtrain = X[:Ntrain]
ztrain = z[:Ntrain]
Xtest = X[Ntrain:]
ztest = z[Ntrain:]
knn = KNeighborsRegressor(n_neighbors, weights='uniform')
zpred = knn.fit(Xtrain, ztrain).predict(Xtest)
rms = np.sqrt(np.mean((ztest - zpred) ** 2))
print("RMS error = %.2g" % rms)
axis_lim = np.array([-0.1, 2.5])
ax = plt.axes()
plt.scatter(ztest, zpred, c='k', lw=0, s=4)
plt.plot(axis_lim, axis_lim, '--k')
plt.plot(axis_lim, axis_lim + rms, ':k')
plt.plot(axis_lim, axis_lim - rms, ':k')
plt.xlim(axis_lim)
plt.ylim(axis_lim)
plt.text(0.99, 0.02, "RMS error = %.2g" % rms,
         ha='right', va='bottom', transform=ax.transAxes,
         bbox=dict(ec='w', fc='w'), fontsize=16)
plt.title('Photo-z: Nearest Neigbor Regression')
plt.xlabel(r'$\mathrm{z_{spec}}$', fontsize=14)
plt.ylabel(r'$\mathrm{z_{phot}}$', fontsize=14)
plt.show()

SciScript API reference

You can find a detailed SciScript API reference here: http://www.sciserver.org/support/documentation/

RStudio

When you create an RStudio container, you will be asked to sign in to RStudio. Use idies / idies as your username/password.

Troubleshooting

You can restart your container by going to the container info page (the icon on the dashboard page) and choosing "Stop" / "Start" from the actions list.

Occassionally, your SciServer token may become expired (for example, if you keep your Jupyter notebook open in the browser for more than 24 hours). Your access token will also update automatically every time you open the Jupyter notebook app from the dashboard page by clicking on the  icon.

If nothing else helps, delete the container and create a new one.