{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import requests\n",
    "import numpy as np\n",
    "from astropy import units as u\n",
    "from astropy import table\n",
    "from glue import core as gcore\n",
    "import io\n",
    "import floatview"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "tabfn = 'M45_gaia.ecsv'\n",
    "if os.path.isfile(tabfn):\n",
    "    tab = table.Table.read(tabfn)\n",
    "else:\n",
    "    from astroquery import gaia    \n",
    "    tab = gaia.Gaia.query_object_async('Messier 45', 90*u.arcmin)\n",
    "    tab.write(tabfn, format='ascii.ecsv')\n",
    "tab = table.QTable(tab);\n",
    "subtab = tab['designation', 'ra', 'dec', 'parallax', 'parallax_error', 'pmra', 'pmra_error', 'pmdec', 'pmdec_error', \n",
    "             'phot_g_mean_mag' ,'bp_rp']\n",
    "subtab['distance'] = u.Quantity(subtab['parallax']).to(u.pc, u.parallax())\n",
    "subtab['distance_error'] = u.Quantity(subtab['parallax_error']).to(u.pc, u.parallax())\n",
    "subtab = subtab[np.isfinite(subtab['distance'])&(u.Quantity(subtab['distance'])<300*u.pc)&(subtab['distance']>0)]\n",
    "gaia_data = gcore.Data('Gaia_Pleiades', **subtab)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "gmw = floatview.GlueManagerWidget(gaia_data, modal=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "gmw.gluemanager.newView(\"scatter\", [\"bp_rp\", \"phot_g_mean_mag\", \"distance\"], \"Scatter 1\");\n",
    "gmw.gluemanager.newView(\"scatter\", [\"bp_rp\", \"distance\"], \"Scatter 2\");\n",
    "gmw.gluemanager.newView(\"contour\", [\"bp_rp\", \"distance\"], \"Contour\");\n",
    "gmw.gluemanager.newView(\"scatter3D\", [\"bp_rp\", \"phot_g_mean_mag\", \"distance\"], \"Scatter 3\");\n",
    "gmw.gluemanager.newView(\"table\", [\"bp_rp\", \"phot_g_mean_mag\", \"distance\"], \"Table\");\n",
    "gmw.gluemanager.newView(\"histogram\", [\"bp_rp\"], \"histogram\");"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
