{
 "metadata": {
  "name": "",
  "signature": "sha256:e5bd7bbcbb2f77cb4950888f893c03f6a26e81270b3d9c3d8e35af9c004f431e"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import pyvo as vo"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "The most common use of the registry is to find archives with \n",
      "`VO data access services`, and the simplest way\n",
      "to do this is to use the \n",
      "`~pyvo.regsearch` function.  For example, to find data\n",
      "collections that contain searchable X-ray images:"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "services = vo.regsearch(servicetype='sia', waveband='x-ray')\n",
      "len(services)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "Aha! Perhaps you didn't realize there were that many.\n",
      "What collections are these?"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "for service in services:\n",
      "    print(service.res_title)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "As you can gather, each record in the registry search results\n",
      "represents a different service (in this case, an image service).\n",
      "Included in the record is the all-important base URL for the service:"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "print(services[0].access_url)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "However, it's not necessary to keep track of that URL because you can\n",
      "now search that collection directly via the registry record:"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "images = services[0].search(pos=(350.85, 58.815), size=0.25)\n",
      "len(images)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "Other types of services via the ``servicetype`` parameter:\n",
      "\n",
      "| set ``servicetype`` to... | ...to find:\n",
      "| ------------------------- | -------------------------------------\n",
      "| sia                       | Simple Image Access (SIA) services\n",
      "| ssa                       | Simple Spectral Access (SSA) services\n",
      "| scs                       | Simple Cone Search (SCS) services\n",
      "| slap                      | Simple Line Access (SLA) services\n",
      "| tap                       | Table Access Protocol (TAP) services\n",
      "\n",
      "For example, to find all known Cone Search services:"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "cats = vo.regsearch(servicetype='conesearch')\n",
      "len(cats)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "Wow, that's a lot of catalogs.  (Most of these are from the\n",
      "`Vizier Catalog Archive <http://vizier.u-strasbg.fr/viz-bin/VizieR>`)\n",
      "every Vizier catalog that includes a position is available as a Cone\n",
      "Search service.)  For just catalogs related to blazars:"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "cats = vo.regsearch(keywords=['blazar'], servicetype='conesearch')\n",
      "len(cats)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "How about blazars observed with Fermi?"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "cats = vo.regsearch(keywords=['blazar', 'Fermi'], servicetype='conesearch')\n",
      "len(cats)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "Sometimes you may be looking for a particular catalog or image collections\n",
      "that you already know exists, and you just need to learn the base URL\n",
      "for the service.  The ``keywords`` parameter can be used to find it.\n",
      "For example, suppose you want to get cutout images from the NRAO VLA\n",
      "Sky Survey (NVSS):"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "colls = vo.regsearch(keywords=[\"NVSS\"], servicetype='sia')\n",
      "for coll in colls:\n",
      "    print coll.res_title"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": []
    }
   ],
   "metadata": {}
  }
 ]
}