{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Source Detection and Fit" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "A lot of efforts have been put to create robust and fast methods for finding and fitting sources in the datacubes.\n", "\n", "Starting from a 2D map where sources should shine over the background (namely a **detection frame**), we show here how to use the methods to find the positions and fit both spectrally and spatially the source candidates.\n", "\n", "Details on the methods implementation can be found in `sitelle.fit` and `sitelle.source`.\n", "\n", ".. note::\n", " A lot of these methods are parallelizable in order to be used in scripts. See `here ` how to do that.\n", " \n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/usr/local/lib/python2.7/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.\n", " from ._conv import register_converters as _register_converters\n", "\u001b[0mINFO| Data shape : (2048, 2064, 556)\u001b[0m\n", "\u001b[33mWARNING| /Users/Barth/Documents/M31/orcs/orcs/core.py:1596: UserWarning: Malformed spectral cube. The number of steps in the header (900) does not correspond to the real size of the data cube (556)\n", " warnings.warn('Malformed spectral cube. The number of steps in the header ({}) does not correspond to the real size of the data cube ({})'.format(step_nb, self.dimz))\n", "\u001b[0m\n", "\u001b[0mINFO| Cube is in WAVENUMBER (cm-1)\u001b[0m\n", "\u001b[0mINFO| Cube is CALIBRATED in wavenumber\u001b[0m\n", "\u001b[33mWARNING| /Users/Barth/Documents/M31/orb/orb/core.py:416: UserWarning: Parameter already defined\n", " warnings.warn('Parameter already defined')\n", "\u001b[0m\n", "\u001b[0mINFO| Cube is in WAVENUMBER (cm-1)\u001b[0m\n", "\u001b[0mINFO| Cube is CALIBRATED in wavenumber\u001b[0m\n", "\u001b[33mWARNING| /Users/Barth/Documents/M31/orcs/orcs/core.py:1450: UserWarning: dxmap reshaped from (200, 200) to (2048, 2064)\n", " format(dxmap.shape, self.dimx, self.dimy))\n", "\u001b[0m\n", "\u001b[33mWARNING| /Users/Barth/Documents/M31/orcs/orcs/core.py:1457: UserWarning: dymap reshaped from (200, 200) to (2048, 2064)\n", " format(dymap.shape, self.dimx, self.dimy))\n", "\u001b[0m\n" ] } ], "source": [ "%load_ext autoreload\n", "%autoreload 2\n", "\n", "%matplotlib notebook \n", "import numpy as np\n", "import pandas as pd\n", "\n", "from sitelle.constants import FITS_DIR\n", "from sitelle.process import SpectralCubePatch as SpectralCube\n", "\n", "from orb.utils import io\n", "\n", "from sitelle.fit import fit_SN2\n", "from sitelle.plot import plot_map, plot_scatter, plot_spectra\n", "from sitelle.source import extract_point_source, get_sources\n", "\n", "SN2_ORCS = SpectralCube(FITS_DIR/'orig/M31_SN2.merged.cm1.1.0.hdf5')\n", "SN2_ORCS.set_wcs(FITS_DIR/'M31_SN2.1.0.ORCS/M31_SN2.1.0.wcs.deep_frame.fits')\n", "SN2_ORCS.set_dxdymaps(FITS_DIR/'M31_SN2.1.0.ORCS/M31_SN2.1.0.wcs.dxmap.fits',\n", " FITS_DIR/'M31_SN2.1.0.ORCS/M31_SN2.1.0.wcs.dymap.fits')\n", "SN2_ORCS.correct_wavelength(FITS_DIR/'M31_SN2.1.0.ORCS/M31_SN2.1.0.skymap.fits')" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "(see `here `_ for details on the notebook header)\n", "\n", "Detection\n", "---------\n", "\n", "We assume that a **detection frame** has already been built. We go over it to detect positions of the source candidates, using `sitelle.source.get_sources`. See `sitelle.source` for more details." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "# We load and look at the detection frame\n", "SN2_detection_frame = io.read_fits(FITS_DIR/'SN2/detection_frame.fits')" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "scrolled": true }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "\u001b[0mINFO| Detecting\u001b[0m\n", "\u001b[33mWARNING| /usr/local/lib/python2.7/site-packages/photutils/segmentation/detect.py:123: RuntimeWarning: invalid value encountered in greater\n", " check_normalization=True) > threshold)\n", "\u001b[0m\n", "\u001b[0mINFO| Deblending\u001b[0m\n", "\u001b[0mINFO| Retieving properties\u001b[0m\n", "\u001b[0mINFO| Filtering Quantity columns\u001b[0m\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
idxcentroidycentroidsky_centroidsky_centroid_icrssource_sumsource_sum_errbackground_sumbackground_meanbackground_at_centroid...eccentricityorientationellipticityelongationcovar_sigx2covar_sigxycovar_sigy2cxxcxycyy
011799.01592955.714739NoneNone71.180574NoneNoneNoneNone...0.792046-1.1550190.3895391.6381060.475824-0.2321950.8992082.4046181.2418491.272426
121993.03904463.526273NoneNone1125.244804NoneNoneNoneNone...0.779919-0.8164300.3741191.5977483.966933-1.7786814.1879970.3113800.2644920.294944
231523.54493264.680744NoneNone207.789919NoneNoneNoneNone...0.784809-1.1863720.3802621.6135860.891429-0.4055251.7297771.2557150.5887730.647124
341128.34458874.832441NoneNone182.670688NoneNoneNoneNone...0.6631031.4745730.2514721.3359560.8404200.0626191.4831311.193637-0.1007920.676377
45380.65697996.441849NoneNone1505.593478NoneNoneNoneNone...0.8100001.0061580.4135701.7052333.2708721.8243054.9953440.383931-0.2804240.251392
561725.319049137.258052NoneNone533.696530NoneNoneNoneNone...0.713386-1.0234780.2992291.4269991.845152-0.6635172.5295580.5984060.3139300.436499
671728.159251183.295429NoneNone68.944996NoneNoneNoneNone...0.719897-0.5196870.3059191.4407540.651145-0.1667740.4550751.6948401.2422382.425064
78973.679613199.060425NoneNone1606.124847NoneNoneNoneNone...0.7122911.4049450.2981161.4247362.2458690.3663294.3730400.451430-0.0756330.231842
89881.669442203.291408NoneNone198.724241NoneNoneNoneNone...0.7538541.2472430.3429581.5219730.8109440.2840041.5626281.316956-0.4787070.683450
9101505.959018205.014543NoneNone468.669756NoneNoneNoneNone...0.744913-1.2050790.3328391.4988881.308970-0.4700442.3564160.8229040.3282960.457117
10111746.763690208.003640NoneNone773.474223NoneNoneNoneNone...0.691606-1.0085480.2777251.3845142.320459-0.7612423.0489650.4693960.2343900.357240
1112597.085607214.813913NoneNone265.430982NoneNoneNoneNone...0.5593450.8657760.1710651.2063671.2046090.2272511.2783090.858952-0.3054000.809430
1213463.268744218.559349NoneNone77.706591NoneNoneNoneNone...0.7007211.2291020.2865651.4016680.4506180.1238280.7547572.323947-0.7625461.387482
1314926.868065254.273642NoneNone148.410118NoneNoneNoneNone...0.665099-1.4579840.2532451.3391270.569972-0.0500721.0062641.7621750.1753710.998138
1415956.568499255.670040NoneNone74.877226NoneNoneNoneNone...0.867288-1.4563290.5021942.0088130.245308-0.0812710.9428504.1963450.7234251.091793
1516346.295450259.514618NoneNone146.303972NoneNoneNoneNone...0.6488090.6497150.2390491.3141450.9070080.2174120.7860271.180816-0.6532191.362560
16171624.377497264.910053NoneNone1088.191316NoneNoneNoneNone...0.733938-1.0686080.3207831.4722842.380641-0.9230703.5546570.4670850.2425840.312818
17181485.591063292.288122NoneNone863.582306NoneNoneNoneNone...0.672237-1.2301410.2596641.3507381.826939-0.4343662.8983460.5675880.1701250.357772
1819858.487701292.747787NoneNone329.848964NoneNoneNoneNone...0.6974461.3603080.2833621.3954050.9584100.1781151.7540211.063464-0.2159820.581085
19201805.641201300.530231NoneNone109.346757NoneNoneNoneNone...0.855054-0.7281890.4814611.9284961.038436-0.5577350.9102461.4353491.7589621.637488
20211754.809356302.778597NoneNone535.540122NoneNoneNoneNone...0.581543-0.9200140.1864841.2292331.751503-0.3632701.9519770.5938600.2210390.532869
21221457.107482314.458123NoneNone357.555907NoneNoneNoneNone...0.669662-1.0970120.2573341.3465001.163532-0.3284871.6357600.9111060.3659300.648079
22231605.143219314.640817NoneNone461.419309NoneNoneNoneNone...0.661483-1.0391600.2500391.3334041.399873-0.3965971.8409770.7607830.3277870.578497
232443.725146316.604942NoneNone1656.579232NoneNoneNoneNone...0.7496690.7007790.3381871.5110014.2495781.5360003.7246590.276537-0.2280810.315510
24251411.918205326.043996NoneNone181.876904NoneNoneNoneNone...0.759465-1.5542330.3494521.5371660.565909-0.0127681.3364631.7674500.0337700.748405
25261644.461975332.235644NoneNone190.637693NoneNoneNoneNone...0.611188-1.0276210.2085141.2634470.973379-0.2215291.2065501.0721500.3937060.864953
26271470.304241337.345915NoneNone193.180665NoneNoneNoneNone...0.560127-1.3627230.1715931.2071370.840690-0.0761971.1855061.1964690.1538040.848465
27281301.394119345.526065NoneNone434.407504NoneNoneNoneNone...0.722568-1.2699710.3087001.4465511.076584-0.3037271.9613590.9712980.3008210.533143
28291770.531013365.323643NoneNone104.171702NoneNoneNoneNone...0.568166-1.1333530.1770861.2151940.597070-0.1006120.7651571.7127980.4504391.336537
2930759.853129375.135418NoneNone154.626239NoneNoneNoneNone...0.2581350.6407250.0338911.0350800.7630710.0249610.7482101.311925-0.0875331.337984
..................................................................
2622631240.7984811771.740614NoneNone110.350568NoneNoneNoneNone...0.4644600.9138620.1144061.1291850.8015330.0966970.8523441.264922-0.2870061.189515
263264764.9115561772.462578NoneNone219.895532NoneNoneNoneNone...0.551196-1.3767550.1656241.1985010.705766-0.0573450.9863101.4236250.1655431.018692
2642651794.9852561773.832564NoneNone816.964128NoneNoneNoneNone...0.6698230.7506420.2574791.3467632.3543560.6658832.2616320.463327-0.2728310.482323
265266304.0180331784.224528NoneNone708.398924NoneNoneNoneNone...0.656510-0.6867950.2456831.3257022.001495-0.5116201.7970480.5388410.3068160.600143
26626739.5446271784.183048NoneNone94.053607NoneNoneNoneNone...0.842093-0.4410390.4606681.8541471.057070-0.3323060.5099731.1897191.5504762.466046
2672681075.0050761790.272941NoneNone40.952773NoneNoneNoneNone...0.735696-0.0059180.3226881.4764240.432548-0.0013850.1984442.3119350.0322815.039316
2682691252.4491521792.283980NoneNone60.673446NoneNoneNoneNone...0.7437921.2684150.3315891.4960860.2474150.0784770.4745064.265567-1.4109402.224132
269270802.3346581796.206982NoneNone68.155110NoneNoneNoneNone...0.427861-0.4150400.0961551.1063850.489190-0.0340580.4269042.0556150.3279932.355533
2702711489.9239741820.615449NoneNone474.607814NoneNoneNoneNone...0.4349061.1296480.0995241.1105241.3468630.1163551.5383400.747349-0.1130540.654327
271272573.2964751821.237799NoneNone395.789768NoneNoneNoneNone...0.590216-0.8694290.1927551.2387811.206272-0.2600081.2944990.8665160.3480900.807458
272273383.1319141826.290120NoneNone107.846309NoneNoneNoneNone...0.726492-1.2436390.3128251.4552340.451794-0.1377660.8110112.3343120.7930571.300388
273274929.1048411827.577246NoneNone643.263681NoneNoneNoneNone...0.445952-1.3476710.1049431.1172471.303512-0.0689891.5919050.7689220.0666460.629622
2742751089.5320511830.495321NoneNone40.864115NoneNoneNoneNone...0.1962640.8367910.0194491.0198350.2489730.0048730.2499784.018037-0.1566644.001877
275276450.8123241840.295728NoneNone109.663206NoneNoneNoneNone...0.767995-0.5074980.3595441.5613870.821824-0.2392050.5246771.4029811.2792622.197550
2762771029.4090561842.112202NoneNone1210.795727NoneNoneNoneNone...0.218697-0.5616400.0242071.0248082.079917-0.0454582.0362780.4810230.0214770.491332
2772781575.5445361855.967439NoneNone60.739555NoneNoneNoneNone...0.770802-1.5620280.3629251.5696730.248017-0.0031830.6109854.0322590.0420101.636811
278279463.3721371862.210632NoneNone53.053791NoneNoneNoneNone...0.7737941.2453810.3665631.5786890.2336510.0916420.4743344.630795-1.7893562.281070
279280678.8689291867.289480NoneNone1230.612734NoneNoneNoneNone...0.538046-0.8664910.1570851.1863592.188163-0.3757432.3111230.4701290.1528680.445117
280281158.7545941872.333563NoneNone999.239968NoneNoneNoneNone...0.737969-0.7597900.3251651.4818442.664631-0.9770562.5644610.4362290.3324050.453268
2812821009.4431031888.507987NoneNone42.009249NoneNoneNoneNone...0.287295-0.8598870.0421581.0440130.246763-0.0105720.2499364.0598330.3434514.008285
2822831182.7604051896.044937NoneNone1130.890674NoneNoneNoneNone...0.3573091.1700910.0660141.0706791.9250240.0989872.1167570.520726-0.0487020.473560
2832841336.2605321895.544638NoneNone182.206861NoneNoneNoneNone...0.2944251.3759110.0443261.0463810.8502070.0152770.9245861.176534-0.0388801.081887
284285635.3604381896.123060NoneNone104.264509NoneNoneNoneNone...0.626063-0.4340150.2202281.2824260.732641-0.1177200.5332161.4151260.6248441.944386
285286398.1011221924.588694NoneNone164.168910NoneNoneNoneNone...0.536544-1.3188960.1561271.1850130.790535-0.0752501.0635511.2735430.1802150.946622
286287936.8914431925.494030NoneNone270.677859NoneNoneNoneNone...0.337355-0.6422850.0586231.0622730.968963-0.0551470.9365031.0355010.1219541.071393
287288655.0329651968.495371NoneNone407.097320NoneNoneNoneNone...0.699799-0.9977790.2856611.3998951.268982-0.4327371.6604330.8649000.4508150.660997
2882891020.3748681974.576975NoneNone186.977612NoneNoneNoneNone...0.482543-0.9538250.1241281.1417190.840719-0.1093120.9172811.2081790.2879551.107337
289290820.7846211978.316132NoneNone1234.485713NoneNoneNoneNone...0.565465-1.2205760.1752281.2124561.834287-0.2633002.4589290.5536810.1185750.413030
290291327.9858871978.494752NoneNone42.813448NoneNoneNoneNone...0.916559-0.5649680.6001002.5006250.473593-0.2369700.2499724.0168907.6158997.610318
2912921335.5095541984.502901NoneNone40.828840NoneNoneNoneNone...0.198388-0.7895270.0198761.0202790.249909-0.0050170.2499924.0030740.1606824.001747
\n", "

292 rows × 35 columns

\n", "
" ], "text/plain": [ " id xcentroid ycentroid sky_centroid sky_centroid_icrs \\\n", "0 1 1799.015929 55.714739 None None \n", "1 2 1993.039044 63.526273 None None \n", "2 3 1523.544932 64.680744 None None \n", "3 4 1128.344588 74.832441 None None \n", "4 5 380.656979 96.441849 None None \n", "5 6 1725.319049 137.258052 None None \n", "6 7 1728.159251 183.295429 None None \n", "7 8 973.679613 199.060425 None None \n", "8 9 881.669442 203.291408 None None \n", "9 10 1505.959018 205.014543 None None \n", "10 11 1746.763690 208.003640 None None \n", "11 12 597.085607 214.813913 None None \n", "12 13 463.268744 218.559349 None None \n", "13 14 926.868065 254.273642 None None \n", "14 15 956.568499 255.670040 None None \n", "15 16 346.295450 259.514618 None None \n", "16 17 1624.377497 264.910053 None None \n", "17 18 1485.591063 292.288122 None None \n", "18 19 858.487701 292.747787 None None \n", "19 20 1805.641201 300.530231 None None \n", "20 21 1754.809356 302.778597 None None \n", "21 22 1457.107482 314.458123 None None \n", "22 23 1605.143219 314.640817 None None \n", "23 24 43.725146 316.604942 None None \n", "24 25 1411.918205 326.043996 None None \n", "25 26 1644.461975 332.235644 None None \n", "26 27 1470.304241 337.345915 None None \n", "27 28 1301.394119 345.526065 None None \n", "28 29 1770.531013 365.323643 None None \n", "29 30 759.853129 375.135418 None None \n", ".. ... ... ... ... ... \n", "262 263 1240.798481 1771.740614 None None \n", "263 264 764.911556 1772.462578 None None \n", "264 265 1794.985256 1773.832564 None None \n", "265 266 304.018033 1784.224528 None None \n", "266 267 39.544627 1784.183048 None None \n", "267 268 1075.005076 1790.272941 None None \n", "268 269 1252.449152 1792.283980 None None \n", "269 270 802.334658 1796.206982 None None \n", "270 271 1489.923974 1820.615449 None None \n", "271 272 573.296475 1821.237799 None None \n", "272 273 383.131914 1826.290120 None None \n", "273 274 929.104841 1827.577246 None None \n", "274 275 1089.532051 1830.495321 None None \n", "275 276 450.812324 1840.295728 None None \n", "276 277 1029.409056 1842.112202 None None \n", "277 278 1575.544536 1855.967439 None None \n", "278 279 463.372137 1862.210632 None None \n", "279 280 678.868929 1867.289480 None None \n", "280 281 158.754594 1872.333563 None None \n", "281 282 1009.443103 1888.507987 None None \n", "282 283 1182.760405 1896.044937 None None \n", "283 284 1336.260532 1895.544638 None None \n", "284 285 635.360438 1896.123060 None None \n", "285 286 398.101122 1924.588694 None None \n", "286 287 936.891443 1925.494030 None None \n", "287 288 655.032965 1968.495371 None None \n", "288 289 1020.374868 1974.576975 None None \n", "289 290 820.784621 1978.316132 None None \n", "290 291 327.985887 1978.494752 None None \n", "291 292 1335.509554 1984.502901 None None \n", "\n", " source_sum source_sum_err background_sum background_mean \\\n", "0 71.180574 None None None \n", "1 1125.244804 None None None \n", "2 207.789919 None None None \n", "3 182.670688 None None None \n", "4 1505.593478 None None None \n", "5 533.696530 None None None \n", "6 68.944996 None None None \n", "7 1606.124847 None None None \n", "8 198.724241 None None None \n", "9 468.669756 None None None \n", "10 773.474223 None None None \n", "11 265.430982 None None None \n", "12 77.706591 None None None \n", "13 148.410118 None None None \n", "14 74.877226 None None None \n", "15 146.303972 None None None \n", "16 1088.191316 None None None \n", "17 863.582306 None None None \n", "18 329.848964 None None None \n", "19 109.346757 None None None \n", "20 535.540122 None None None \n", "21 357.555907 None None None \n", "22 461.419309 None None None \n", "23 1656.579232 None None None \n", "24 181.876904 None None None \n", "25 190.637693 None None None \n", "26 193.180665 None None None \n", "27 434.407504 None None None \n", "28 104.171702 None None None \n", "29 154.626239 None None None \n", ".. ... ... ... ... \n", "262 110.350568 None None None \n", "263 219.895532 None None None \n", "264 816.964128 None None None \n", "265 708.398924 None None None \n", "266 94.053607 None None None \n", "267 40.952773 None None None \n", "268 60.673446 None None None \n", "269 68.155110 None None None \n", "270 474.607814 None None None \n", "271 395.789768 None None None \n", "272 107.846309 None None None \n", "273 643.263681 None None None \n", "274 40.864115 None None None \n", "275 109.663206 None None None \n", "276 1210.795727 None None None \n", "277 60.739555 None None None \n", "278 53.053791 None None None \n", "279 1230.612734 None None None \n", "280 999.239968 None None None \n", "281 42.009249 None None None \n", "282 1130.890674 None None None \n", "283 182.206861 None None None \n", "284 104.264509 None None None \n", "285 164.168910 None None None \n", "286 270.677859 None None None \n", "287 407.097320 None None None \n", "288 186.977612 None None None \n", "289 1234.485713 None None None \n", "290 42.813448 None None None \n", "291 40.828840 None None None \n", "\n", " background_at_centroid ... eccentricity orientation ellipticity \\\n", "0 None ... 0.792046 -1.155019 0.389539 \n", "1 None ... 0.779919 -0.816430 0.374119 \n", "2 None ... 0.784809 -1.186372 0.380262 \n", "3 None ... 0.663103 1.474573 0.251472 \n", "4 None ... 0.810000 1.006158 0.413570 \n", "5 None ... 0.713386 -1.023478 0.299229 \n", "6 None ... 0.719897 -0.519687 0.305919 \n", "7 None ... 0.712291 1.404945 0.298116 \n", "8 None ... 0.753854 1.247243 0.342958 \n", "9 None ... 0.744913 -1.205079 0.332839 \n", "10 None ... 0.691606 -1.008548 0.277725 \n", "11 None ... 0.559345 0.865776 0.171065 \n", "12 None ... 0.700721 1.229102 0.286565 \n", "13 None ... 0.665099 -1.457984 0.253245 \n", "14 None ... 0.867288 -1.456329 0.502194 \n", "15 None ... 0.648809 0.649715 0.239049 \n", "16 None ... 0.733938 -1.068608 0.320783 \n", "17 None ... 0.672237 -1.230141 0.259664 \n", "18 None ... 0.697446 1.360308 0.283362 \n", "19 None ... 0.855054 -0.728189 0.481461 \n", "20 None ... 0.581543 -0.920014 0.186484 \n", "21 None ... 0.669662 -1.097012 0.257334 \n", "22 None ... 0.661483 -1.039160 0.250039 \n", "23 None ... 0.749669 0.700779 0.338187 \n", "24 None ... 0.759465 -1.554233 0.349452 \n", "25 None ... 0.611188 -1.027621 0.208514 \n", "26 None ... 0.560127 -1.362723 0.171593 \n", "27 None ... 0.722568 -1.269971 0.308700 \n", "28 None ... 0.568166 -1.133353 0.177086 \n", "29 None ... 0.258135 0.640725 0.033891 \n", ".. ... ... ... ... ... \n", "262 None ... 0.464460 0.913862 0.114406 \n", "263 None ... 0.551196 -1.376755 0.165624 \n", "264 None ... 0.669823 0.750642 0.257479 \n", "265 None ... 0.656510 -0.686795 0.245683 \n", "266 None ... 0.842093 -0.441039 0.460668 \n", "267 None ... 0.735696 -0.005918 0.322688 \n", "268 None ... 0.743792 1.268415 0.331589 \n", "269 None ... 0.427861 -0.415040 0.096155 \n", "270 None ... 0.434906 1.129648 0.099524 \n", "271 None ... 0.590216 -0.869429 0.192755 \n", "272 None ... 0.726492 -1.243639 0.312825 \n", "273 None ... 0.445952 -1.347671 0.104943 \n", "274 None ... 0.196264 0.836791 0.019449 \n", "275 None ... 0.767995 -0.507498 0.359544 \n", "276 None ... 0.218697 -0.561640 0.024207 \n", "277 None ... 0.770802 -1.562028 0.362925 \n", "278 None ... 0.773794 1.245381 0.366563 \n", "279 None ... 0.538046 -0.866491 0.157085 \n", "280 None ... 0.737969 -0.759790 0.325165 \n", "281 None ... 0.287295 -0.859887 0.042158 \n", "282 None ... 0.357309 1.170091 0.066014 \n", "283 None ... 0.294425 1.375911 0.044326 \n", "284 None ... 0.626063 -0.434015 0.220228 \n", "285 None ... 0.536544 -1.318896 0.156127 \n", "286 None ... 0.337355 -0.642285 0.058623 \n", "287 None ... 0.699799 -0.997779 0.285661 \n", "288 None ... 0.482543 -0.953825 0.124128 \n", "289 None ... 0.565465 -1.220576 0.175228 \n", "290 None ... 0.916559 -0.564968 0.600100 \n", "291 None ... 0.198388 -0.789527 0.019876 \n", "\n", " elongation covar_sigx2 covar_sigxy covar_sigy2 cxx cxy \\\n", "0 1.638106 0.475824 -0.232195 0.899208 2.404618 1.241849 \n", "1 1.597748 3.966933 -1.778681 4.187997 0.311380 0.264492 \n", "2 1.613586 0.891429 -0.405525 1.729777 1.255715 0.588773 \n", "3 1.335956 0.840420 0.062619 1.483131 1.193637 -0.100792 \n", "4 1.705233 3.270872 1.824305 4.995344 0.383931 -0.280424 \n", "5 1.426999 1.845152 -0.663517 2.529558 0.598406 0.313930 \n", "6 1.440754 0.651145 -0.166774 0.455075 1.694840 1.242238 \n", "7 1.424736 2.245869 0.366329 4.373040 0.451430 -0.075633 \n", "8 1.521973 0.810944 0.284004 1.562628 1.316956 -0.478707 \n", "9 1.498888 1.308970 -0.470044 2.356416 0.822904 0.328296 \n", "10 1.384514 2.320459 -0.761242 3.048965 0.469396 0.234390 \n", "11 1.206367 1.204609 0.227251 1.278309 0.858952 -0.305400 \n", "12 1.401668 0.450618 0.123828 0.754757 2.323947 -0.762546 \n", "13 1.339127 0.569972 -0.050072 1.006264 1.762175 0.175371 \n", "14 2.008813 0.245308 -0.081271 0.942850 4.196345 0.723425 \n", "15 1.314145 0.907008 0.217412 0.786027 1.180816 -0.653219 \n", "16 1.472284 2.380641 -0.923070 3.554657 0.467085 0.242584 \n", "17 1.350738 1.826939 -0.434366 2.898346 0.567588 0.170125 \n", "18 1.395405 0.958410 0.178115 1.754021 1.063464 -0.215982 \n", "19 1.928496 1.038436 -0.557735 0.910246 1.435349 1.758962 \n", "20 1.229233 1.751503 -0.363270 1.951977 0.593860 0.221039 \n", "21 1.346500 1.163532 -0.328487 1.635760 0.911106 0.365930 \n", "22 1.333404 1.399873 -0.396597 1.840977 0.760783 0.327787 \n", "23 1.511001 4.249578 1.536000 3.724659 0.276537 -0.228081 \n", "24 1.537166 0.565909 -0.012768 1.336463 1.767450 0.033770 \n", "25 1.263447 0.973379 -0.221529 1.206550 1.072150 0.393706 \n", "26 1.207137 0.840690 -0.076197 1.185506 1.196469 0.153804 \n", "27 1.446551 1.076584 -0.303727 1.961359 0.971298 0.300821 \n", "28 1.215194 0.597070 -0.100612 0.765157 1.712798 0.450439 \n", "29 1.035080 0.763071 0.024961 0.748210 1.311925 -0.087533 \n", ".. ... ... ... ... ... ... \n", "262 1.129185 0.801533 0.096697 0.852344 1.264922 -0.287006 \n", "263 1.198501 0.705766 -0.057345 0.986310 1.423625 0.165543 \n", "264 1.346763 2.354356 0.665883 2.261632 0.463327 -0.272831 \n", "265 1.325702 2.001495 -0.511620 1.797048 0.538841 0.306816 \n", "266 1.854147 1.057070 -0.332306 0.509973 1.189719 1.550476 \n", "267 1.476424 0.432548 -0.001385 0.198444 2.311935 0.032281 \n", "268 1.496086 0.247415 0.078477 0.474506 4.265567 -1.410940 \n", "269 1.106385 0.489190 -0.034058 0.426904 2.055615 0.327993 \n", "270 1.110524 1.346863 0.116355 1.538340 0.747349 -0.113054 \n", "271 1.238781 1.206272 -0.260008 1.294499 0.866516 0.348090 \n", "272 1.455234 0.451794 -0.137766 0.811011 2.334312 0.793057 \n", "273 1.117247 1.303512 -0.068989 1.591905 0.768922 0.066646 \n", "274 1.019835 0.248973 0.004873 0.249978 4.018037 -0.156664 \n", "275 1.561387 0.821824 -0.239205 0.524677 1.402981 1.279262 \n", "276 1.024808 2.079917 -0.045458 2.036278 0.481023 0.021477 \n", "277 1.569673 0.248017 -0.003183 0.610985 4.032259 0.042010 \n", "278 1.578689 0.233651 0.091642 0.474334 4.630795 -1.789356 \n", "279 1.186359 2.188163 -0.375743 2.311123 0.470129 0.152868 \n", "280 1.481844 2.664631 -0.977056 2.564461 0.436229 0.332405 \n", "281 1.044013 0.246763 -0.010572 0.249936 4.059833 0.343451 \n", "282 1.070679 1.925024 0.098987 2.116757 0.520726 -0.048702 \n", "283 1.046381 0.850207 0.015277 0.924586 1.176534 -0.038880 \n", "284 1.282426 0.732641 -0.117720 0.533216 1.415126 0.624844 \n", "285 1.185013 0.790535 -0.075250 1.063551 1.273543 0.180215 \n", "286 1.062273 0.968963 -0.055147 0.936503 1.035501 0.121954 \n", "287 1.399895 1.268982 -0.432737 1.660433 0.864900 0.450815 \n", "288 1.141719 0.840719 -0.109312 0.917281 1.208179 0.287955 \n", "289 1.212456 1.834287 -0.263300 2.458929 0.553681 0.118575 \n", "290 2.500625 0.473593 -0.236970 0.249972 4.016890 7.615899 \n", "291 1.020279 0.249909 -0.005017 0.249992 4.003074 0.160682 \n", "\n", " cyy \n", "0 1.272426 \n", "1 0.294944 \n", "2 0.647124 \n", "3 0.676377 \n", "4 0.251392 \n", "5 0.436499 \n", "6 2.425064 \n", "7 0.231842 \n", "8 0.683450 \n", "9 0.457117 \n", "10 0.357240 \n", "11 0.809430 \n", "12 1.387482 \n", "13 0.998138 \n", "14 1.091793 \n", "15 1.362560 \n", "16 0.312818 \n", "17 0.357772 \n", "18 0.581085 \n", "19 1.637488 \n", "20 0.532869 \n", "21 0.648079 \n", "22 0.578497 \n", "23 0.315510 \n", "24 0.748405 \n", "25 0.864953 \n", "26 0.848465 \n", "27 0.533143 \n", "28 1.336537 \n", "29 1.337984 \n", ".. ... \n", "262 1.189515 \n", "263 1.018692 \n", "264 0.482323 \n", "265 0.600143 \n", "266 2.466046 \n", "267 5.039316 \n", "268 2.224132 \n", "269 2.355533 \n", "270 0.654327 \n", "271 0.807458 \n", "272 1.300388 \n", "273 0.629622 \n", "274 4.001877 \n", "275 2.197550 \n", "276 0.491332 \n", "277 1.636811 \n", "278 2.281070 \n", "279 0.445117 \n", "280 0.453268 \n", "281 4.008285 \n", "282 0.473560 \n", "283 1.081887 \n", "284 1.944386 \n", "285 0.946622 \n", "286 1.071393 \n", "287 0.660997 \n", "288 1.107337 \n", "289 0.413030 \n", "290 7.610318 \n", "291 4.001747 \n", "\n", "[292 rows x 35 columns]" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "snr_threshold = 8 # Fixed signal-to-noise ratio threshold\n", "SN2_sources = get_sources(SN2_detection_frame, \n", " threshold=snr_threshold,\n", " mode='SEGM')\n", "\n", "SN2_sources" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "Details about all the outputs can be found in `sitelle.source.get_sources` method.\n", "\n", "We can plot these detections on the detection frame for verification.\n", "\n", ".. warning::\n", " This uses astropy convention, i.e. ycentroid is actually abscisse and xcentroid columns...\n", " To inverse this::\n", " >>> SN2_sources.rename(columns={'ycentroid':'xcentroid', 'xcentroid':'ycentroid'}, inplace=True)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "application/javascript": [ "/* Put everything inside the global mpl namespace */\n", "window.mpl = {};\n", "\n", "\n", "mpl.get_websocket_type = function() {\n", " if (typeof(WebSocket) !== 'undefined') {\n", " return WebSocket;\n", " } else if (typeof(MozWebSocket) !== 'undefined') {\n", " return MozWebSocket;\n", " } else {\n", " alert('Your browser does not have WebSocket support.' +\n", " 'Please try Chrome, Safari or Firefox ≥ 6. ' +\n", " 'Firefox 4 and 5 are also supported but you ' +\n", " 'have to enable WebSockets in about:config.');\n", " };\n", "}\n", "\n", "mpl.figure = function(figure_id, websocket, ondownload, parent_element) {\n", " this.id = figure_id;\n", "\n", " this.ws = websocket;\n", "\n", " this.supports_binary = (this.ws.binaryType != undefined);\n", "\n", " if (!this.supports_binary) {\n", " var warnings = document.getElementById(\"mpl-warnings\");\n", " if (warnings) {\n", " warnings.style.display = 'block';\n", " warnings.textContent = (\n", " \"This browser does not support binary websocket messages. \" +\n", " \"Performance may be slow.\");\n", " }\n", " }\n", "\n", " this.imageObj = new Image();\n", "\n", " this.context = undefined;\n", " this.message = undefined;\n", " this.canvas = undefined;\n", " this.rubberband_canvas = undefined;\n", " this.rubberband_context = undefined;\n", " this.format_dropdown = undefined;\n", "\n", " this.image_mode = 'full';\n", "\n", " this.root = $('
');\n", " this._root_extra_style(this.root)\n", " this.root.attr('style', 'display: inline-block');\n", "\n", " $(parent_element).append(this.root);\n", "\n", " this._init_header(this);\n", " this._init_canvas(this);\n", " this._init_toolbar(this);\n", "\n", " var fig = this;\n", "\n", " this.waiting = false;\n", "\n", " this.ws.onopen = function () {\n", " fig.send_message(\"supports_binary\", {value: fig.supports_binary});\n", " fig.send_message(\"send_image_mode\", {});\n", " if (mpl.ratio != 1) {\n", " fig.send_message(\"set_dpi_ratio\", {'dpi_ratio': mpl.ratio});\n", " }\n", " fig.send_message(\"refresh\", {});\n", " }\n", "\n", " this.imageObj.onload = function() {\n", " if (fig.image_mode == 'full') {\n", " // Full images could contain transparency (where diff images\n", " // almost always do), so we need to clear the canvas so that\n", " // there is no ghosting.\n", " fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n", " }\n", " fig.context.drawImage(fig.imageObj, 0, 0);\n", " };\n", "\n", " this.imageObj.onunload = function() {\n", " fig.ws.close();\n", " }\n", "\n", " this.ws.onmessage = this._make_on_message_function(this);\n", "\n", " this.ondownload = ondownload;\n", "}\n", "\n", "mpl.figure.prototype._init_header = function() {\n", " var titlebar = $(\n", " '
');\n", " var titletext = $(\n", " '
');\n", " titlebar.append(titletext)\n", " this.root.append(titlebar);\n", " this.header = titletext[0];\n", "}\n", "\n", "\n", "\n", "mpl.figure.prototype._canvas_extra_style = function(canvas_div) {\n", "\n", "}\n", "\n", "\n", "mpl.figure.prototype._root_extra_style = function(canvas_div) {\n", "\n", "}\n", "\n", "mpl.figure.prototype._init_canvas = function() {\n", " var fig = this;\n", "\n", " var canvas_div = $('
');\n", "\n", " canvas_div.attr('style', 'position: relative; clear: both; outline: 0');\n", "\n", " function canvas_keyboard_event(event) {\n", " return fig.key_event(event, event['data']);\n", " }\n", "\n", " canvas_div.keydown('key_press', canvas_keyboard_event);\n", " canvas_div.keyup('key_release', canvas_keyboard_event);\n", " this.canvas_div = canvas_div\n", " this._canvas_extra_style(canvas_div)\n", " this.root.append(canvas_div);\n", "\n", " var canvas = $('');\n", " canvas.addClass('mpl-canvas');\n", " canvas.attr('style', \"left: 0; top: 0; z-index: 0; outline: 0\")\n", "\n", " this.canvas = canvas[0];\n", " this.context = canvas[0].getContext(\"2d\");\n", "\n", " var backingStore = this.context.backingStorePixelRatio ||\n", "\tthis.context.webkitBackingStorePixelRatio ||\n", "\tthis.context.mozBackingStorePixelRatio ||\n", "\tthis.context.msBackingStorePixelRatio ||\n", "\tthis.context.oBackingStorePixelRatio ||\n", "\tthis.context.backingStorePixelRatio || 1;\n", "\n", " mpl.ratio = (window.devicePixelRatio || 1) / backingStore;\n", "\n", " var rubberband = $('');\n", " rubberband.attr('style', \"position: absolute; left: 0; top: 0; z-index: 1;\")\n", "\n", " var pass_mouse_events = true;\n", "\n", " canvas_div.resizable({\n", " start: function(event, ui) {\n", " pass_mouse_events = false;\n", " },\n", " resize: function(event, ui) {\n", " fig.request_resize(ui.size.width, ui.size.height);\n", " },\n", " stop: function(event, ui) {\n", " pass_mouse_events = true;\n", " fig.request_resize(ui.size.width, ui.size.height);\n", " },\n", " });\n", "\n", " function mouse_event_fn(event) {\n", " if (pass_mouse_events)\n", " return fig.mouse_event(event, event['data']);\n", " }\n", "\n", " rubberband.mousedown('button_press', mouse_event_fn);\n", " rubberband.mouseup('button_release', mouse_event_fn);\n", " // Throttle sequential mouse events to 1 every 20ms.\n", " rubberband.mousemove('motion_notify', mouse_event_fn);\n", "\n", " rubberband.mouseenter('figure_enter', mouse_event_fn);\n", " rubberband.mouseleave('figure_leave', mouse_event_fn);\n", "\n", " canvas_div.on(\"wheel\", function (event) {\n", " event = event.originalEvent;\n", " event['data'] = 'scroll'\n", " if (event.deltaY < 0) {\n", " event.step = 1;\n", " } else {\n", " event.step = -1;\n", " }\n", " mouse_event_fn(event);\n", " });\n", "\n", " canvas_div.append(canvas);\n", " canvas_div.append(rubberband);\n", "\n", " this.rubberband = rubberband;\n", " this.rubberband_canvas = rubberband[0];\n", " this.rubberband_context = rubberband[0].getContext(\"2d\");\n", " this.rubberband_context.strokeStyle = \"#000000\";\n", "\n", " this._resize_canvas = function(width, height) {\n", " // Keep the size of the canvas, canvas container, and rubber band\n", " // canvas in synch.\n", " canvas_div.css('width', width)\n", " canvas_div.css('height', height)\n", "\n", " canvas.attr('width', width * mpl.ratio);\n", " canvas.attr('height', height * mpl.ratio);\n", " canvas.attr('style', 'width: ' + width + 'px; height: ' + height + 'px;');\n", "\n", " rubberband.attr('width', width);\n", " rubberband.attr('height', height);\n", " }\n", "\n", " // Set the figure to an initial 600x600px, this will subsequently be updated\n", " // upon first draw.\n", " this._resize_canvas(600, 600);\n", "\n", " // Disable right mouse context menu.\n", " $(this.rubberband_canvas).bind(\"contextmenu\",function(e){\n", " return false;\n", " });\n", "\n", " function set_focus () {\n", " canvas.focus();\n", " canvas_div.focus();\n", " }\n", "\n", " window.setTimeout(set_focus, 100);\n", "}\n", "\n", "mpl.figure.prototype._init_toolbar = function() {\n", " var fig = this;\n", "\n", " var nav_element = $('
')\n", " nav_element.attr('style', 'width: 100%');\n", " this.root.append(nav_element);\n", "\n", " // Define a callback function for later on.\n", " function toolbar_event(event) {\n", " return fig.toolbar_button_onclick(event['data']);\n", " }\n", " function toolbar_mouse_event(event) {\n", " return fig.toolbar_button_onmouseover(event['data']);\n", " }\n", "\n", " for(var toolbar_ind in mpl.toolbar_items) {\n", " var name = mpl.toolbar_items[toolbar_ind][0];\n", " var tooltip = mpl.toolbar_items[toolbar_ind][1];\n", " var image = mpl.toolbar_items[toolbar_ind][2];\n", " var method_name = mpl.toolbar_items[toolbar_ind][3];\n", "\n", " if (!name) {\n", " // put a spacer in here.\n", " continue;\n", " }\n", " var button = $('');\n", " button.click(method_name, toolbar_event);\n", " button.mouseover(tooltip, toolbar_mouse_event);\n", " nav_element.append(button);\n", " }\n", "\n", " // Add the status bar.\n", " var status_bar = $('');\n", " nav_element.append(status_bar);\n", " this.message = status_bar[0];\n", "\n", " // Add the close button to the window.\n", " var buttongrp = $('
');\n", " var button = $('');\n", " button.click(function (evt) { fig.handle_close(fig, {}); } );\n", " button.mouseover('Stop Interaction', toolbar_mouse_event);\n", " buttongrp.append(button);\n", " var titlebar = this.root.find($('.ui-dialog-titlebar'));\n", " titlebar.prepend(buttongrp);\n", "}\n", "\n", "mpl.figure.prototype._root_extra_style = function(el){\n", " var fig = this\n", " el.on(\"remove\", function(){\n", "\tfig.close_ws(fig, {});\n", " });\n", "}\n", "\n", "mpl.figure.prototype._canvas_extra_style = function(el){\n", " // this is important to make the div 'focusable\n", " el.attr('tabindex', 0)\n", " // reach out to IPython and tell the keyboard manager to turn it's self\n", " // off when our div gets focus\n", "\n", " // location in version 3\n", " if (IPython.notebook.keyboard_manager) {\n", " IPython.notebook.keyboard_manager.register_events(el);\n", " }\n", " else {\n", " // location in version 2\n", " IPython.keyboard_manager.register_events(el);\n", " }\n", "\n", "}\n", "\n", "mpl.figure.prototype._key_event_extra = function(event, name) {\n", " var manager = IPython.notebook.keyboard_manager;\n", " if (!manager)\n", " manager = IPython.keyboard_manager;\n", "\n", " // Check for shift+enter\n", " if (event.shiftKey && event.which == 13) {\n", " this.canvas_div.blur();\n", " event.shiftKey = false;\n", " // Send a \"J\" for go to next cell\n", " event.which = 74;\n", " event.keyCode = 74;\n", " manager.command_mode();\n", " manager.handle_keydown(event);\n", " }\n", "}\n", "\n", "mpl.figure.prototype.handle_save = function(fig, msg) {\n", " fig.ondownload(fig, null);\n", "}\n", "\n", "\n", "mpl.find_output_cell = function(html_output) {\n", " // Return the cell and output element which can be found *uniquely* in the notebook.\n", " // Note - this is a bit hacky, but it is done because the \"notebook_saving.Notebook\"\n", " // IPython event is triggered only after the cells have been serialised, which for\n", " // our purposes (turning an active figure into a static one), is too late.\n", " var cells = IPython.notebook.get_cells();\n", " var ncells = cells.length;\n", " for (var i=0; i= 3 moved mimebundle to data attribute of output\n", " data = data.data;\n", " }\n", " if (data['text/html'] == html_output) {\n", " return [cell, data, j];\n", " }\n", " }\n", " }\n", " }\n", "}\n", "\n", "// Register the function which deals with the matplotlib target/channel.\n", "// The kernel may be null if the page has been refreshed.\n", "if (IPython.notebook.kernel != null) {\n", " IPython.notebook.kernel.comm_manager.register_target('matplotlib', mpl.mpl_figure_comm);\n", "}\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "(
,\n", " )" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# We display the original spectra and the fit\n", "x,y = source[['xpos', 'ypos']].astype(int)\n", "\n", "axis, spectra = extract_point_source(x,y, SN2_ORCS)\n", "fitted_spectra = fit_params['fitted_vector']\n", "f,ax = plot_spectra(axis,spectra, label='Original')\n", "plot_spectra(axis, fitted_spectra, ax=ax, label='Fit')" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [], "source": [ "## We append the fit result to the original source data\n", "source = source.append(fit_res)\n", "\n", "## We define some threshold to say if a line is detected or not\n", "from sitelle.constants import SN2_LINES\n", "snr_lim = 5\n", "for line_name in SN2_LINES:\n", " line_name = line_name.lower().replace('[', '').replace(']', '')\n", " source['%s_detected'%line_name] = source['snr_%s'%line_name] > snr_lim\n", " source['flux_%s'%line_name] = np.where(source['%s_detected'%line_name],\n", " source['flux_%s'%line_name],\n", " snr_lim*source['flux_%s_err'%line_name])" ] }, { "cell_type": "raw", "metadata": { "raw_mimetype": "text/restructuredtext" }, "source": [ "The `sitelle.fit.fit_SN2` method gathers a lot of different steps and uses a lot of default values to facilitate the fit.\n", "It is largely tunable through the keywords, to modify the LSF to use for the fit, guess values etc..." ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "scrolled": false }, "outputs": [ { "data": { "application/javascript": [ "/* Put everything inside the global mpl namespace */\n", "window.mpl = {};\n", "\n", "\n", "mpl.get_websocket_type = function() {\n", " if (typeof(WebSocket) !== 'undefined') {\n", " return WebSocket;\n", " } else if (typeof(MozWebSocket) !== 'undefined') {\n", " return MozWebSocket;\n", " } else {\n", " alert('Your browser does not have WebSocket support.' +\n", " 'Please try Chrome, Safari or Firefox ≥ 6. ' +\n", " 'Firefox 4 and 5 are also supported but you ' +\n", " 'have to enable WebSockets in about:config.');\n", " };\n", "}\n", "\n", "mpl.figure = function(figure_id, websocket, ondownload, parent_element) {\n", " this.id = figure_id;\n", "\n", " this.ws = websocket;\n", "\n", " this.supports_binary = (this.ws.binaryType != undefined);\n", "\n", " if (!this.supports_binary) {\n", " var warnings = document.getElementById(\"mpl-warnings\");\n", " if (warnings) {\n", " warnings.style.display = 'block';\n", " warnings.textContent = (\n", " \"This browser does not support binary websocket messages. \" +\n", " \"Performance may be slow.\");\n", " }\n", " }\n", "\n", " this.imageObj = new Image();\n", "\n", " this.context = undefined;\n", " this.message = undefined;\n", " this.canvas = undefined;\n", " this.rubberband_canvas = undefined;\n", " this.rubberband_context = undefined;\n", " this.format_dropdown = undefined;\n", "\n", " this.image_mode = 'full';\n", "\n", " this.root = $('
');\n", " this._root_extra_style(this.root)\n", " this.root.attr('style', 'display: inline-block');\n", "\n", " $(parent_element).append(this.root);\n", "\n", " this._init_header(this);\n", " this._init_canvas(this);\n", " this._init_toolbar(this);\n", "\n", " var fig = this;\n", "\n", " this.waiting = false;\n", "\n", " this.ws.onopen = function () {\n", " fig.send_message(\"supports_binary\", {value: fig.supports_binary});\n", " fig.send_message(\"send_image_mode\", {});\n", " if (mpl.ratio != 1) {\n", " fig.send_message(\"set_dpi_ratio\", {'dpi_ratio': mpl.ratio});\n", " }\n", " fig.send_message(\"refresh\", {});\n", " }\n", "\n", " this.imageObj.onload = function() {\n", " if (fig.image_mode == 'full') {\n", " // Full images could contain transparency (where diff images\n", " // almost always do), so we need to clear the canvas so that\n", " // there is no ghosting.\n", " fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n", " }\n", " fig.context.drawImage(fig.imageObj, 0, 0);\n", " };\n", "\n", " this.imageObj.onunload = function() {\n", " fig.ws.close();\n", " }\n", "\n", " this.ws.onmessage = this._make_on_message_function(this);\n", "\n", " this.ondownload = ondownload;\n", "}\n", "\n", "mpl.figure.prototype._init_header = function() {\n", " var titlebar = $(\n", " '
');\n", " var titletext = $(\n", " '
');\n", " titlebar.append(titletext)\n", " this.root.append(titlebar);\n", " this.header = titletext[0];\n", "}\n", "\n", "\n", "\n", "mpl.figure.prototype._canvas_extra_style = function(canvas_div) {\n", "\n", "}\n", "\n", "\n", "mpl.figure.prototype._root_extra_style = function(canvas_div) {\n", "\n", "}\n", "\n", "mpl.figure.prototype._init_canvas = function() {\n", " var fig = this;\n", "\n", " var canvas_div = $('
');\n", "\n", " canvas_div.attr('style', 'position: relative; clear: both; outline: 0');\n", "\n", " function canvas_keyboard_event(event) {\n", " return fig.key_event(event, event['data']);\n", " }\n", "\n", " canvas_div.keydown('key_press', canvas_keyboard_event);\n", " canvas_div.keyup('key_release', canvas_keyboard_event);\n", " this.canvas_div = canvas_div\n", " this._canvas_extra_style(canvas_div)\n", " this.root.append(canvas_div);\n", "\n", " var canvas = $('');\n", " canvas.addClass('mpl-canvas');\n", " canvas.attr('style', \"left: 0; top: 0; z-index: 0; outline: 0\")\n", "\n", " this.canvas = canvas[0];\n", " this.context = canvas[0].getContext(\"2d\");\n", "\n", " var backingStore = this.context.backingStorePixelRatio ||\n", "\tthis.context.webkitBackingStorePixelRatio ||\n", "\tthis.context.mozBackingStorePixelRatio ||\n", "\tthis.context.msBackingStorePixelRatio ||\n", "\tthis.context.oBackingStorePixelRatio ||\n", "\tthis.context.backingStorePixelRatio || 1;\n", "\n", " mpl.ratio = (window.devicePixelRatio || 1) / backingStore;\n", "\n", " var rubberband = $('');\n", " rubberband.attr('style', \"position: absolute; left: 0; top: 0; z-index: 1;\")\n", "\n", " var pass_mouse_events = true;\n", "\n", " canvas_div.resizable({\n", " start: function(event, ui) {\n", " pass_mouse_events = false;\n", " },\n", " resize: function(event, ui) {\n", " fig.request_resize(ui.size.width, ui.size.height);\n", " },\n", " stop: function(event, ui) {\n", " pass_mouse_events = true;\n", " fig.request_resize(ui.size.width, ui.size.height);\n", " },\n", " });\n", "\n", " function mouse_event_fn(event) {\n", " if (pass_mouse_events)\n", " return fig.mouse_event(event, event['data']);\n", " }\n", "\n", " rubberband.mousedown('button_press', mouse_event_fn);\n", " rubberband.mouseup('button_release', mouse_event_fn);\n", " // Throttle sequential mouse events to 1 every 20ms.\n", " rubberband.mousemove('motion_notify', mouse_event_fn);\n", "\n", " rubberband.mouseenter('figure_enter', mouse_event_fn);\n", " rubberband.mouseleave('figure_leave', mouse_event_fn);\n", "\n", " canvas_div.on(\"wheel\", function (event) {\n", " event = event.originalEvent;\n", " event['data'] = 'scroll'\n", " if (event.deltaY < 0) {\n", " event.step = 1;\n", " } else {\n", " event.step = -1;\n", " }\n", " mouse_event_fn(event);\n", " });\n", "\n", " canvas_div.append(canvas);\n", " canvas_div.append(rubberband);\n", "\n", " this.rubberband = rubberband;\n", " this.rubberband_canvas = rubberband[0];\n", " this.rubberband_context = rubberband[0].getContext(\"2d\");\n", " this.rubberband_context.strokeStyle = \"#000000\";\n", "\n", " this._resize_canvas = function(width, height) {\n", " // Keep the size of the canvas, canvas container, and rubber band\n", " // canvas in synch.\n", " canvas_div.css('width', width)\n", " canvas_div.css('height', height)\n", "\n", " canvas.attr('width', width * mpl.ratio);\n", " canvas.attr('height', height * mpl.ratio);\n", " canvas.attr('style', 'width: ' + width + 'px; height: ' + height + 'px;');\n", "\n", " rubberband.attr('width', width);\n", " rubberband.attr('height', height);\n", " }\n", "\n", " // Set the figure to an initial 600x600px, this will subsequently be updated\n", " // upon first draw.\n", " this._resize_canvas(600, 600);\n", "\n", " // Disable right mouse context menu.\n", " $(this.rubberband_canvas).bind(\"contextmenu\",function(e){\n", " return false;\n", " });\n", "\n", " function set_focus () {\n", " canvas.focus();\n", " canvas_div.focus();\n", " }\n", "\n", " window.setTimeout(set_focus, 100);\n", "}\n", "\n", "mpl.figure.prototype._init_toolbar = function() {\n", " var fig = this;\n", "\n", " var nav_element = $('
')\n", " nav_element.attr('style', 'width: 100%');\n", " this.root.append(nav_element);\n", "\n", " // Define a callback function for later on.\n", " function toolbar_event(event) {\n", " return fig.toolbar_button_onclick(event['data']);\n", " }\n", " function toolbar_mouse_event(event) {\n", " return fig.toolbar_button_onmouseover(event['data']);\n", " }\n", "\n", " for(var toolbar_ind in mpl.toolbar_items) {\n", " var name = mpl.toolbar_items[toolbar_ind][0];\n", " var tooltip = mpl.toolbar_items[toolbar_ind][1];\n", " var image = mpl.toolbar_items[toolbar_ind][2];\n", " var method_name = mpl.toolbar_items[toolbar_ind][3];\n", "\n", " if (!name) {\n", " // put a spacer in here.\n", " continue;\n", " }\n", " var button = $('');\n", " button.click(method_name, toolbar_event);\n", " button.mouseover(tooltip, toolbar_mouse_event);\n", " nav_element.append(button);\n", " }\n", "\n", " // Add the status bar.\n", " var status_bar = $('');\n", " nav_element.append(status_bar);\n", " this.message = status_bar[0];\n", "\n", " // Add the close button to the window.\n", " var buttongrp = $('
');\n", " var button = $('');\n", " button.click(function (evt) { fig.handle_close(fig, {}); } );\n", " button.mouseover('Stop Interaction', toolbar_mouse_event);\n", " buttongrp.append(button);\n", " var titlebar = this.root.find($('.ui-dialog-titlebar'));\n", " titlebar.prepend(buttongrp);\n", "}\n", "\n", "mpl.figure.prototype._root_extra_style = function(el){\n", " var fig = this\n", " el.on(\"remove\", function(){\n", "\tfig.close_ws(fig, {});\n", " });\n", "}\n", "\n", "mpl.figure.prototype._canvas_extra_style = function(el){\n", " // this is important to make the div 'focusable\n", " el.attr('tabindex', 0)\n", " // reach out to IPython and tell the keyboard manager to turn it's self\n", " // off when our div gets focus\n", "\n", " // location in version 3\n", " if (IPython.notebook.keyboard_manager) {\n", " IPython.notebook.keyboard_manager.register_events(el);\n", " }\n", " else {\n", " // location in version 2\n", " IPython.keyboard_manager.register_events(el);\n", " }\n", "\n", "}\n", "\n", "mpl.figure.prototype._key_event_extra = function(event, name) {\n", " var manager = IPython.notebook.keyboard_manager;\n", " if (!manager)\n", " manager = IPython.keyboard_manager;\n", "\n", " // Check for shift+enter\n", " if (event.shiftKey && event.which == 13) {\n", " this.canvas_div.blur();\n", " event.shiftKey = false;\n", " // Send a \"J\" for go to next cell\n", " event.which = 74;\n", " event.keyCode = 74;\n", " manager.command_mode();\n", " manager.handle_keydown(event);\n", " }\n", "}\n", "\n", "mpl.figure.prototype.handle_save = function(fig, msg) {\n", " fig.ondownload(fig, null);\n", "}\n", "\n", "\n", "mpl.find_output_cell = function(html_output) {\n", " // Return the cell and output element which can be found *uniquely* in the notebook.\n", " // Note - this is a bit hacky, but it is done because the \"notebook_saving.Notebook\"\n", " // IPython event is triggered only after the cells have been serialised, which for\n", " // our purposes (turning an active figure into a static one), is too late.\n", " var cells = IPython.notebook.get_cells();\n", " var ncells = cells.length;\n", " for (var i=0; i= 3 moved mimebundle to data attribute of output\n", " data = data.data;\n", " }\n", " if (data['text/html'] == html_output) {\n", " return [cell, data, j];\n", " }\n", " }\n", " }\n", " }\n", "}\n", "\n", "// Register the function which deals with the matplotlib target/channel.\n", "// The kernel may be null if the page has been refreshed.\n", "if (IPython.notebook.kernel != null) {\n", " IPython.notebook.kernel.comm_manager.register_target('matplotlib', mpl.mpl_figure_comm);\n", "}\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "/* Put everything inside the global mpl namespace */\n", "window.mpl = {};\n", "\n", "\n", "mpl.get_websocket_type = function() {\n", " if (typeof(WebSocket) !== 'undefined') {\n", " return WebSocket;\n", " } else if (typeof(MozWebSocket) !== 'undefined') {\n", " return MozWebSocket;\n", " } else {\n", " alert('Your browser does not have WebSocket support.' +\n", " 'Please try Chrome, Safari or Firefox ≥ 6. ' +\n", " 'Firefox 4 and 5 are also supported but you ' +\n", " 'have to enable WebSockets in about:config.');\n", " };\n", "}\n", "\n", "mpl.figure = function(figure_id, websocket, ondownload, parent_element) {\n", " this.id = figure_id;\n", "\n", " this.ws = websocket;\n", "\n", " this.supports_binary = (this.ws.binaryType != undefined);\n", "\n", " if (!this.supports_binary) {\n", " var warnings = document.getElementById(\"mpl-warnings\");\n", " if (warnings) {\n", " warnings.style.display = 'block';\n", " warnings.textContent = (\n", " \"This browser does not support binary websocket messages. \" +\n", " \"Performance may be slow.\");\n", " }\n", " }\n", "\n", " this.imageObj = new Image();\n", "\n", " this.context = undefined;\n", " this.message = undefined;\n", " this.canvas = undefined;\n", " this.rubberband_canvas = undefined;\n", " this.rubberband_context = undefined;\n", " this.format_dropdown = undefined;\n", "\n", " this.image_mode = 'full';\n", "\n", " this.root = $('
');\n", " this._root_extra_style(this.root)\n", " this.root.attr('style', 'display: inline-block');\n", "\n", " $(parent_element).append(this.root);\n", "\n", " this._init_header(this);\n", " this._init_canvas(this);\n", " this._init_toolbar(this);\n", "\n", " var fig = this;\n", "\n", " this.waiting = false;\n", "\n", " this.ws.onopen = function () {\n", " fig.send_message(\"supports_binary\", {value: fig.supports_binary});\n", " fig.send_message(\"send_image_mode\", {});\n", " if (mpl.ratio != 1) {\n", " fig.send_message(\"set_dpi_ratio\", {'dpi_ratio': mpl.ratio});\n", " }\n", " fig.send_message(\"refresh\", {});\n", " }\n", "\n", " this.imageObj.onload = function() {\n", " if (fig.image_mode == 'full') {\n", " // Full images could contain transparency (where diff images\n", " // almost always do), so we need to clear the canvas so that\n", " // there is no ghosting.\n", " fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n", " }\n", " fig.context.drawImage(fig.imageObj, 0, 0);\n", " };\n", "\n", " this.imageObj.onunload = function() {\n", " fig.ws.close();\n", " }\n", "\n", " this.ws.onmessage = this._make_on_message_function(this);\n", "\n", " this.ondownload = ondownload;\n", "}\n", "\n", "mpl.figure.prototype._init_header = function() {\n", " var titlebar = $(\n", " '
');\n", " var titletext = $(\n", " '
');\n", " titlebar.append(titletext)\n", " this.root.append(titlebar);\n", " this.header = titletext[0];\n", "}\n", "\n", "\n", "\n", "mpl.figure.prototype._canvas_extra_style = function(canvas_div) {\n", "\n", "}\n", "\n", "\n", "mpl.figure.prototype._root_extra_style = function(canvas_div) {\n", "\n", "}\n", "\n", "mpl.figure.prototype._init_canvas = function() {\n", " var fig = this;\n", "\n", " var canvas_div = $('
');\n", "\n", " canvas_div.attr('style', 'position: relative; clear: both; outline: 0');\n", "\n", " function canvas_keyboard_event(event) {\n", " return fig.key_event(event, event['data']);\n", " }\n", "\n", " canvas_div.keydown('key_press', canvas_keyboard_event);\n", " canvas_div.keyup('key_release', canvas_keyboard_event);\n", " this.canvas_div = canvas_div\n", " this._canvas_extra_style(canvas_div)\n", " this.root.append(canvas_div);\n", "\n", " var canvas = $('');\n", " canvas.addClass('mpl-canvas');\n", " canvas.attr('style', \"left: 0; top: 0; z-index: 0; outline: 0\")\n", "\n", " this.canvas = canvas[0];\n", " this.context = canvas[0].getContext(\"2d\");\n", "\n", " var backingStore = this.context.backingStorePixelRatio ||\n", "\tthis.context.webkitBackingStorePixelRatio ||\n", "\tthis.context.mozBackingStorePixelRatio ||\n", "\tthis.context.msBackingStorePixelRatio ||\n", "\tthis.context.oBackingStorePixelRatio ||\n", "\tthis.context.backingStorePixelRatio || 1;\n", "\n", " mpl.ratio = (window.devicePixelRatio || 1) / backingStore;\n", "\n", " var rubberband = $('');\n", " rubberband.attr('style', \"position: absolute; left: 0; top: 0; z-index: 1;\")\n", "\n", " var pass_mouse_events = true;\n", "\n", " canvas_div.resizable({\n", " start: function(event, ui) {\n", " pass_mouse_events = false;\n", " },\n", " resize: function(event, ui) {\n", " fig.request_resize(ui.size.width, ui.size.height);\n", " },\n", " stop: function(event, ui) {\n", " pass_mouse_events = true;\n", " fig.request_resize(ui.size.width, ui.size.height);\n", " },\n", " });\n", "\n", " function mouse_event_fn(event) {\n", " if (pass_mouse_events)\n", " return fig.mouse_event(event, event['data']);\n", " }\n", "\n", " rubberband.mousedown('button_press', mouse_event_fn);\n", " rubberband.mouseup('button_release', mouse_event_fn);\n", " // Throttle sequential mouse events to 1 every 20ms.\n", " rubberband.mousemove('motion_notify', mouse_event_fn);\n", "\n", " rubberband.mouseenter('figure_enter', mouse_event_fn);\n", " rubberband.mouseleave('figure_leave', mouse_event_fn);\n", "\n", " canvas_div.on(\"wheel\", function (event) {\n", " event = event.originalEvent;\n", " event['data'] = 'scroll'\n", " if (event.deltaY < 0) {\n", " event.step = 1;\n", " } else {\n", " event.step = -1;\n", " }\n", " mouse_event_fn(event);\n", " });\n", "\n", " canvas_div.append(canvas);\n", " canvas_div.append(rubberband);\n", "\n", " this.rubberband = rubberband;\n", " this.rubberband_canvas = rubberband[0];\n", " this.rubberband_context = rubberband[0].getContext(\"2d\");\n", " this.rubberband_context.strokeStyle = \"#000000\";\n", "\n", " this._resize_canvas = function(width, height) {\n", " // Keep the size of the canvas, canvas container, and rubber band\n", " // canvas in synch.\n", " canvas_div.css('width', width)\n", " canvas_div.css('height', height)\n", "\n", " canvas.attr('width', width * mpl.ratio);\n", " canvas.attr('height', height * mpl.ratio);\n", " canvas.attr('style', 'width: ' + width + 'px; height: ' + height + 'px;');\n", "\n", " rubberband.attr('width', width);\n", " rubberband.attr('height', height);\n", " }\n", "\n", " // Set the figure to an initial 600x600px, this will subsequently be updated\n", " // upon first draw.\n", " this._resize_canvas(600, 600);\n", "\n", " // Disable right mouse context menu.\n", " $(this.rubberband_canvas).bind(\"contextmenu\",function(e){\n", " return false;\n", " });\n", "\n", " function set_focus () {\n", " canvas.focus();\n", " canvas_div.focus();\n", " }\n", "\n", " window.setTimeout(set_focus, 100);\n", "}\n", "\n", "mpl.figure.prototype._init_toolbar = function() {\n", " var fig = this;\n", "\n", " var nav_element = $('
')\n", " nav_element.attr('style', 'width: 100%');\n", " this.root.append(nav_element);\n", "\n", " // Define a callback function for later on.\n", " function toolbar_event(event) {\n", " return fig.toolbar_button_onclick(event['data']);\n", " }\n", " function toolbar_mouse_event(event) {\n", " return fig.toolbar_button_onmouseover(event['data']);\n", " }\n", "\n", " for(var toolbar_ind in mpl.toolbar_items) {\n", " var name = mpl.toolbar_items[toolbar_ind][0];\n", " var tooltip = mpl.toolbar_items[toolbar_ind][1];\n", " var image = mpl.toolbar_items[toolbar_ind][2];\n", " var method_name = mpl.toolbar_items[toolbar_ind][3];\n", "\n", " if (!name) {\n", " // put a spacer in here.\n", " continue;\n", " }\n", " var button = $('