diff --git a/README.md b/README.md index 58aea35..75c34a0 100644 --- a/README.md +++ b/README.md @@ -60,17 +60,51 @@ properties and calculations. - Check the notebooks under the "notebooks/2_detrending_examples" directory to see how to model your light-curves. -- Check the notebook "2_core_calculations" for higher efficiency +- Check the notebook "3_core_calculations" for higher efficiency (suggested for developers). -## History +# History -### v4.1 +## PyLightcurve v4.1.x + +### Changes in usage compared to Pylightcurve v4.0.x versions: + +- Parameters renamed + +An attempt has been made to use more consistent and self-explainable parameter names in PyLightcurve. +Please pay extra care when accessing the fitting output, almost all parameter names have changed! + +| variable name in | type | description |unit | +|:-------------------------|:----------:|:-----------------------------------------:|:----------------------:| +| ``name`` |``str`` |name of the planet | -- | +| ``ra`` |``float`` |RA of the host star |degrees (ICRS) | +| ``dec`` |``float`` |DEC of the host star |degrees (ICRS) | +| ``stellar_logg`` |``float`` |log(g) of the host star |log(cm/s2) | +| ``stellar_temperature`` |``float`` |effecive temperature of the host star |Kelvin | +| ``stellar_metallicity`` |``float`` |metallicity of the host star |dex(Fe/H) or dex(M/H) | +| ``rp_over_rs`` |``float`` |plant-to-star radius ratio | -- | +| ``period`` |``float`` |orbital period |days | +| ``sma_over_rs`` |``float`` |orbital semi-major axis relatively
to the stellar radius | -- | +| ``eccentricity`` |``float`` |orbital eccentricity | -- | +| ``inclination`` |``float`` |orbital inclination |degrees | +| ``periastron`` |``float`` |orbital argument of periastron |degrees | +| ``mid_time`` |``float`` |the time of conjunction with the planet in front of the star |days (BJDTDB)| +| ``albedo`` |``float`` |planet albedo | -- | +| ``emissivity`` |``float`` |planet emissivity | -- | +| ``filter_name`` |``str`` |filter used for the observation | -- | +| ``wlrange`` |``list`` or ``None`` |2-element list that includes the wavelength range in the filter used for the observation | Angstrom | +| ``ldc_method`` |``str`` |limb-darkening model used to calculate the limb-darkening coefficients | -- | +| ``stellar_model`` |``str`` |stellar model used to calculate the limb-darkening coefficients | -- | +| ``precision`` |``int`` |level of precision used to calculate the light-curve models | -- | + +- New structure for fitting output + +Please check the notebook ```notebooks/2_detrending_examples/0_a_simple_lc_fitting.ipynb``` to see the structure of the fitting output. -#### Changes in usage: - New way of accessing the LDCs and the Fp/Fs in the planet class + ```python # v4.0 limb_darkening_coefficients = planet.filter('COUSINS_R').limb_darkening_coefficients @@ -78,7 +112,7 @@ fp_over_fs = planet.filter('COUSINS_R').fp_over_fs rp_over_rs = planet.filter('COUSINS_R').rp_over_rs # v4.1 -limb_darkening_coefficients = planet.exotethys('COUSINS_R', method='claret', +limb_darkening_coefficients = planet.exotethys('COUSINS_R', ldc_method='claret', wlrange=None, stellar_model='Phoenix_2018') # available methods: claret, power2, quad, linear # available stellar models: Atlas_2000, Phoenix_2012_13, Stagger_2015, Stagger_2018 @@ -87,6 +121,7 @@ fp_over_fs = planet.fp_over_fs('COUSINS_R', wlrange=None) rp_over_rs = planet.rp_over_rs ``` + - Planet eclipse time is not automatically calulated ```python # v4.0 @@ -97,7 +132,6 @@ eclipse_mid_time = planet.eclipse_mid_time() ``` - - New way of adding custom filters or limb darkening coefficients in the planet class ```python # v4.0 @@ -114,7 +148,8 @@ planet.add_custom_limb_darkening_coefficients([ldc1, ldc2, ldc3, ldc4], filter_n - Stellar model is no longer defined when initialising a Planet object (no ```ldc_stellar_model``` argument), it is defined when adding an observation -- New way of defining the iterations in MCMC + +- New definition of iterations in MCMC ```python # v4.0 - total model evaluations = iterations iterations, walkers = 15000, 3 @@ -122,20 +157,38 @@ iterations, walkers = 15000, 3 # v4.1 - total model evaluations = iterations x walkers iterations, walkers = 5000, 3 ``` -- Time conversions are now available through the Planet class + + +- Time conversions are now available through the Planet class directly ```python # v4.0 -time_in_bjd_utc = planet.target.convert_to_bjd_tdb(time_in_hjd_utc, 'HJD_UTC') +time_in_bjd_tdb = planet.target.convert_to_bjd_tdb(time_in_hjd_utc, 'HJD_UTC') # v4.1 -time_in_bjd_utc = planet.convert_to_bjd_tdb(time_in_hjd_utc, 'HJD_UTC') +time_in_bjd_tdb = planet.convert_to_bjd_tdb(time_in_hjd_utc, 'HJD_UTC') # or -time_in_bjd_utc = plc.convert_to_bjd_tdb(ra_in_degrees, dec_in_degrees, time_in_hjd_utc, 'HJD_UTC') +time_in_bjd_tdb = plc.convert_to_bjd_tdb(ra_in_degrees, dec_in_degrees, time_in_hjd_utc, 'HJD_UTC') # where ra, dec in degrees # available formats: JD_UTC, MJD_UTC, HJD_UTC, HJD_TDB, BJD_UTC, BJD_TDB ``` -- PyLightcurve now accepts angles as floats only (degrees). No angle transformation through + + +- When performing core calculations directly or through a ```plc.Planet``` object, + all time arrays must be provided in ```BJD_TDB```, so you need to convert them first +```python +# v4.0 +time_in_jd_utc = np.arange(planet.mid_time - 0.1, planet.mid_time + 0.1, 0.001) +transit_model = planet.transit(time_in_jd_utc, time_format='JD_UTC', filter_name='COUSINS_R') + + +# v4.1 +time_in_jd_utc = np.arange(planet.mid_time - 0.1, planet.mid_time + 0.1, 0.001) +time_in_bjd_tdb = planet.convert_to_bjd_tdb(time_in_hjd_utc, 'JD_UTC') +transit_model = planet.transit(time_array_in_jd_utc, filter_name='COUSINS_R') +``` + +- PyLightcurve now accepts angles as floats only (degrees). No angle transformations through ```pylightcurve``` are available, please use the new ```exoclock``` package. ```python # v4.0 @@ -149,8 +202,6 @@ ra_in_dms_coordinate = ra.dms_coord() # this will give the angle between -90 and ra_in_hms = ra.hms() ra_in_degrees_coordinate = ra.deg_coord() # this will give the angle between -90 and 90 degrees - - # v4.1 import exoclock ra = exoclock.Hours('22:03:10.7729') @@ -164,16 +215,15 @@ ra_in_hms = ra.hms() ra_in_degrees_coordinate = ra.deg_coord() # this will give the angle between -90 and 90 degrees ``` - -#### New features: +### New features: - Custom detrending - Automatic scaling of uncertainties, outliers rejection and initial parameter optimisation -- Wrapper for ExoTETHyS and sub-bandpass LDCs +- Wrapper for ExoTETHyS and LDCs for sub-bandpass - More precise integration -- Airmass detrending is now available -- Flux/Mag conversions are now available through the Planet class +- Airmass detrending +- Flux/Mag conversions available through the Planet class -### v4.0 - [latest (v4.0.3)](https://github.com/ucl-exoplanets/pylightcurve/releases/tag/v4.0.3) +### PyLightcurve v4.1.x - [latest (v4.0.4)](https://github.com/ucl-exoplanets/pylightcurve/releases/tag/v4.0.4) - PyLightcurve 4.0 no longer supports the use of the Open Exoplanet Catalogue (OEC), due to the large number of mistakes in the catalogue and the absence of parameters updates. OEC has been replaced by the @@ -205,13 +255,17 @@ angles (e.g. '+47:12:34.05' to degrees) and of timing systems (e.g. HJD_UTC to B ### 4.0.3 - Fix np.float bug. +### 4.0.4 +- Fixed packaging and test issues. +- Fixed latex strings in plots. +- Fixed matplotlib.cm.get_cmap bug. ## Licence MIT License -Copyright (c) 2016-2023 Angelos Tsiaras, and collaborators +Copyright (c) 2016-present Angelos Tsiaras, and collaborators Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/notebooks/.ipynb_checkpoints/1_the_planet_class-checkpoint.ipynb b/notebooks/.ipynb_checkpoints/1_the_planet_class-checkpoint.ipynb new file mode 100644 index 0000000..c8945cd --- /dev/null +++ b/notebooks/.ipynb_checkpoints/1_the_planet_class-checkpoint.ipynb @@ -0,0 +1,91 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "988b5848", + "metadata": {}, + "outputs": [], + "source": [ + "%matplotlib notebook\n", + "import matplotlib.pyplot as plt\n", + "import pylightcurve as plc\n", + "import numpy as np\n", + "\n", + "\n", + "###############################################################################################\n", + "##### Definitions\n", + "###############################################################################################\n", + "\n", + "# The core culculations are provided to ofer maximum efficiency and they are available to \n", + "# help developers build their own codes on the functionalities of PyLigthcurve.\n", + "# To use the core calculation in PyLightcurve we need to be able to provide the following \n", + "# information to the different functions:\n", + "\n", + "# ra # float, in degrees\n", + "# dec # float, in degrees\n", + "# stellar_logg # float, in log(cm/s^2)\n", + "# stellar_temperature # float, in Kelvin\n", + "# stellar_metallicity # float, in dex(Fe/H) or dex(M/H)\n", + "# rp_over_rs # float, no units\n", + "# period # float, in days\n", + "# sma_over_rs # float, no units\n", + "# eccentricity # float, no units\n", + "# inclination # float, in degrees\n", + "# periastron # float, in degrees\n", + "# mid_time # float, in days (BJD_TDB)\n", + "# time_array # np.array dtype=float, in days (BJD_TDB)\n", + "# albedo # float, no units\n", + "# emissivity # float, no units\n", + "\n", + "# For the examples below we will use the paraeters of the famus HD209458b:\n", + "\n", + "ra = 330.795\n", + "dec = 18.884\n", + "stellar_logg = 4.36 \n", + "stellar_temperature = 6065.0\n", + "stellar_metallicity = 0.0\n", + "rp_over_rs = 0.12086\n", + "period = 3.5247486\n", + "sma_over_rs = 8.76\n", + "eccentricity = 0.0\n", + "inclination = 86.71 \n", + "periastron = 0.0\n", + "mid_time = 2452826.62928\n", + "albedo = 0.15 # assumed\n", + "emissivity = 1.0 # assumed\n", + "\n", + "###############################################################################################" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c960cf47", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "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.11.5" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/notebooks/1_the_planet_class.ipynb b/notebooks/1_the_planet_class.ipynb index 99d1dd7..05d1053 100644 --- a/notebooks/1_the_planet_class.ipynb +++ b/notebooks/1_the_planet_class.ipynb @@ -1,67 +1,893 @@ { "cells": [ + { + "cell_type": "markdown", + "id": "fa06101c", + "metadata": {}, + "source": [ + "# 1. The ```plc.Planet``` class\n", + "\n", + "Since Pylightcurve 4.0.0 we can access many core calculations related to exoplanets through the ```plc.Planet``` object.\n", + "\n", + "## 1.1 Automated definition throught the ExoClock database\n", + "\n", + "We can quickly create a ```plc.Planet``` object based on catalague data as follows:" + ] + }, { "cell_type": "code", - "execution_count": null, - "id": "988b5848", + "execution_count": 1, + "id": "e7365142", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "exoclock: Checking ephemerides database...\n", + "exoclock: Checking catalogues database...\n", + "exoclock: Checking ut database...\n" + ] + }, + { + "ename": "SyntaxError", + "evalue": "invalid syntax (optimisation.py, line 386)", + "output_type": "error", + "traceback": [ + "Traceback \u001b[0;36m(most recent call last)\u001b[0m:\n", + "\u001b[0m File \u001b[1;32m~/anaconda3/lib/python3.11/site-packages/IPython/core/interactiveshell.py:3526\u001b[0m in \u001b[1;35mrun_code\u001b[0m\n exec(code_obj, self.user_global_ns, self.user_ns)\u001b[0m\n", + "\u001b[0m Cell \u001b[1;32mIn[1], line 5\u001b[0m\n import pylightcurve as plc\u001b[0m\n", + "\u001b[0;36m File \u001b[0;32m~/Dropbox/my_macbook/python_packages/pylightcurve-dev/pylightcurve/__init__.py:16\u001b[0;36m\n\u001b[0;31m from .analysis.optimisation import *\u001b[0;36m\n", + "\u001b[0;36m File \u001b[0;32m~/Dropbox/my_macbook/python_packages/pylightcurve-dev/pylightcurve/analysis/optimisation.py:386\u001b[0;36m\u001b[0m\n\u001b[0;31m elif self.optimiser == 'emcee':=\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n" + ] + } + ], "source": [ "%matplotlib notebook\n", + "\n", + "import numpy as np\n", "import matplotlib.pyplot as plt\n", "import pylightcurve as plc\n", - "import numpy as np\n", "\n", + "planet = plc.get_planet('hd209458b')" + ] + }, + { + "cell_type": "markdown", + "id": "489bfd8b", + "metadata": {}, + "source": [ + "\n", + "At the moment the data provided are base on the Exoplanet Characterisation Catalogue (ECC) developed as part of the [```ExoClock Project```](https://www.exoclock.space) ([Kokori et al. 2021](https://link.springer.com/article/10.1007/s10686-020-09696-3)). The catalogue contains about 750 objects and will gradually expand in future releases.\n", + "\n", + "To retrieve a list of all the available planet names we can type:\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c22c10ce", + "metadata": {}, + "outputs": [], + "source": [ + "plc.get_all_planets()" + ] + }, + { + "cell_type": "markdown", + "id": "2b58ef23", + "metadata": {}, + "source": [ + "## 1.2 Manual definition\n", + "\n", + "Alternatively, we can define a ```plc.Planet``` object manually:\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d0be88c4", + "metadata": {}, + "outputs": [], + "source": [ + "planet = plc.Planet(\n", + " name='HD209458b', # str\n", + " ra = 330.795, # float, in degrees\n", + " dec = 18.884, # float, in degrees\n", + " stellar_logg = 4.36, # float, in log(cm/s^2)\n", + " stellar_temperature = 6065.0, # float, in Kelvin\n", + " stellar_metallicity = 0.0, # float, in dex(Fe/H) or dex(M/H)\n", + " rp_over_rs = 0.12086, # float, no units\n", + " period = 3.5247486, # float, in days\n", + " sma_over_rs = 8.76, # float, no units\n", + " eccentricity = 0.0, # float, no units\n", + " inclination = 86.71, # float, in degrees \n", + " periastron = 0.0, # float, in degrees\n", + " mid_time = 2452826.62928, # float, in days (BJD-TDB) \n", + " ldc_method = 'claret', # str, available methods: claret(default), power2, linear, quad\n", + " max_sub_exp_time=10, # float, default = 10 seconds\n", + " precision=2, # int 0 to 10, default = 2\n", + " asc_node=0, # float, default = 0.0 degrees\n", + " albedo = 0.15, # float, default = 0.15, no units \n", + " emissivity = 1.0, # float, default = 1.0, no units\n", + ")" + ] + }, + { + "cell_type": "markdown", + "id": "203974a4", + "metadata": {}, + "source": [ + "**Note**: if we have the ```mid_time``` in a format different from BJDTDB (e.g. HJDUTC) we need to convert it before passing it to the planet object:\n", + "``` python\n", + "mid_time = plc.convert_to_bjd_tdb(ra, dec, mid_time_in_hjd_utc, 'HJD_UTC')\n", + "```" + ] + }, + { + "cell_type": "markdown", + "id": "05f756bf", + "metadata": {}, + "source": [ + "## 1.3 Definition of parameters\n", + "\n", + "\n", + "| variable name | type | decription |unit |\n", + "|:-------------------------|:----------:|:-----------------------------------------:|:----------------------:|\n", + "| ``name`` |``str`` |name of the planet | -- |\n", + "| ``ra`` |``float`` |RA of the host star |degrees (ICRS) |\n", + "| ``dec`` |``float`` |DEC of the host star |degrees (ICRS) |\n", + "| ``stellar_logg`` |``float`` |log(g) of the host star |log(cm/s2) |\n", + "| ``stellar_temperature`` |``float`` |effecive temperature of the host star |Kelvin |\n", + "| ``stellar_metallicity`` |``float`` |metallicity of the host star |dex(Fe/H) or dex(M/H) |\n", + "| ``rp_over_rs`` |``float`` |plant-to-star radius ratio | -- |\n", + "| ``period`` |``float`` |orbital period |days |\n", + "| ``sma_over_rs`` |``float`` |orbital semi-major axis relatively
to the stellar radius | -- |\n", + "| ``eccentricity`` |``float`` |orbital eccentricity | -- |\n", + "| ``inclination`` |``float`` |orbital inclination |degrees |\n", + "| ``periastron`` |``float`` |orbital argument of periastron |degrees |\n", + "| ``mid_time`` |``float`` |the time of conjunction with the planet in front of the star |days (BJDTDB)|\n", + "\n", + "\n", + "\n", + "### ```ldc_method = 'claret'```\n", + "\n", + "This parameter refers to the limb-darkening law that we want to use. The default value is ```claret```, and the other options are: ```power2```, ```linear``` and ```quad```.\n", + "\n", + "\n", + "### ```max_sub_exp_time = 10```\n", + " \n", + "This parameter defines the time-resolution of the integrated transit models (see below for what the intgated model is) that will be calculated for this planet, in seconds. The default value is 10, meaning that the integrated models with exposure times below 10 seconds will be identical. \n", + " \n", + " \n", + "### ```precision = 2```\n", + "\n", + "This parameter is an option for the functions that calculate the relative flux during a transit or an eclipse. It refers to the precision of the numerical calculation of the Gauss–Kronrod quadrature, the default value is 2, and the other options are 3, 4, ... 10, meaning that 20, 30, 40, ... 100 quadrature points will be used.\n", + "\n", + "We can check the balance between precision and speed (to adjust the precision level to our needs), as follows: \n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2058106b", + "metadata": {}, + "outputs": [], + "source": [ + "planet.performance_report(array_size=100)" + ] + }, + { + "cell_type": "markdown", + "id": "8fa5e0f5", + "metadata": {}, + "source": [ + "### ```asc_node = 0```\n", + " \n", + "This is the longitude of the scending node in degrees. This parameter doesn't affect the transit or eclipse depth, and by default is 0.\n", + "\n", + "### ```albedo = 0.15```, ```emissivity = 1.0```\n", + " \n", + "These two parameters have the above dafault values (no units) and they affect the theoretical calculation of the expected eclipse depth, as they are used to calculate the planetary temperature as folows:\n", + " \n", + "```python\n", + "planet_temperature = stellar_temperature * np.sqrt(0.5 / sma_over_rs) * (((1 - albedo) / emissivity) ** 0.25)\n", + "```" + ] + }, + { + "cell_type": "markdown", + "id": "0755ebeb", + "metadata": {}, + "source": [ + "## 1.4 PyLightcurve core calculations though a ```planet``` object\n", + "\n", + "Through a ```plc.Planet``` object we can quickly access the core calculations of Pylightcurve \n", + "These calulations are:\n", + "\n", + "- **```planet.exotethys```**: calculates the limb-darkening coefficients\n", + "- **```planet.fp_over_fs```**: calculates the planet-to-star flux ratio (flux emmitted + reflected by the planet)\n", + "- **```planet.convert_to_bjd_tdb```**: converts a time array from different time formats to BJDTDB\n", + "- **```planet.convert_to_jd_utc```**: converts a time array from different time formats to JDUTC\n", + "- **```planet.convert_to_relflux```**: converts a flux array from magnitude to relative flux\n", + "- **```planet.planet_orbit```**: calculates the (x,y,z) position of the planet in a cartesian frame with the star at (0,0,0), the Earth at (+infinity,0,0) and the periastron located on the −y axis for $\\omega$=0.\n", + "- **```planet.planet_star_projected_distance```**: calculates the distance between the planet and the star relatively to the stellar radius, as projected on the celestial sphere.\n", + "- **```planet.planet_phase```**: calculates the planet phase with respect to the transit mid-time (time of conjunction when the planet is behind the star, no units)\n", + "- **```planet.transit_depth```**: calculates the transit depth (in relative flux)\n", + "- **```planet.transit_duration```**: calculates the transit duration (in days)\n", + "- **```planet.transit_t12```**: calculates the time between transit contact points 1 and 2 (in days)\n", + "- **```planet.eclipse_mid_time```**: calculates the eclipse mid-time (time of conjunction when the planet is behind the star, in days BJDTDB)\n", + "- **```planet.eclipse_depth```**: calculates the eclipse depth (in relative flux)\n", + "- **```planet.eclipse_duration```**: calculates the eclipse duration (in days)\n", + "- **```planet.transit```**: calculates the transit model (in relative flux)\n", + "- **```planet.eclipse```**: calculates the eclipse model (in relative flux)\n", + "- **```planet.transit_integrated```**: calculates the exposure-integtared transit model (in relative flux)\n", + "- **```planet.eclipse_integrated```**: calculates the exposure-integtared eclipse model (in relative flux)\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "id": "41c1d8cf", + "metadata": {}, + "source": [ + "### 1.4.1 ```planet.exotethys``` \n", + "\n", + "*Calculates the limb-darkening coefficients.*\n", + "\n", + "PyLightcurve includes a wrapper for the [```ExoTETHyS```](https://github.com/ucl-exoplanets/ExoTETHyS) package ([Morello et al. 2020](https://iopscience.iop.org/article/10.3847/1538-3881/ab63dc)), to allow for the easy calclation of the limb-darkening coefficients.\n", + "\n", + "Returns a 4-element array. If the limb-darkening law used for the ```plc.Planet``` object is not ```claret```, the extra elements will be zero.\n", + "\n", + "**Example 1**:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "78e05643", + "metadata": {}, + "outputs": [], + "source": [ + "planet.exotethys(filter_name = 'COUSINS_R',)" + ] + }, + { + "cell_type": "markdown", + "id": "889f8017", + "metadata": {}, + "source": [ + "**Example 2**:\n", + "\n", + "We may want to use different stellar models to calculate the limb-darkening coefficients\n", + "There is a range of stellar models availabe throught the [```ExoTETHyS```](https://github.com/ucl-exoplanets/ExoTETHyS) package pachage.\n", + "The default stellar model is the ```Phoenix_2018```. However some stellar parameters and some \n", + "wavelengths, are not covered by all models. For example, ```Phoenix_2018``` are not availble \n", + "for the ```irac4``` filter, or for very cool stars (e.g. 3000 K).\n", + "The other stellar models are: ```Atlas_2000```, ```Phoenix_2012_13```, ```Phoenix_drift_2012```, ```Stagger_2015```, ```Stagger_2018```.\n", + "Please consult the the [```ExoTETHyS```](https://github.com/ucl-exoplanets/ExoTETHyS) package page if an error occurs.\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9ba64b9c", + "metadata": {}, + "outputs": [], + "source": [ + "planet.exotethys(filter_name = 'irac4', stellar_model='Atlas_2000')" + ] + }, + { + "cell_type": "markdown", + "id": "eefeceac", + "metadata": {}, + "source": [ + "**Example 3**:\n", + "\n", + "For the cases where a specroscopic band-pass is needed, we can also specify a part of the filter's bandpass to be used, by defining the ```wlrange``` parameter (by default is ```None```). This is a list with two elements, indicating the limits (in Angstrom) within the filter bandpass that we want to use. The wavelength range needs to be within the limits of the filter bandpass, otherwise the calsulation will fail.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b038c7fe", + "metadata": {}, + "outputs": [], + "source": [ + "planet.exotethys(filter_name = 'hst_wfc3_ir_g141', wlrange = [11000, 12000])" + ] + }, + { + "cell_type": "markdown", + "id": "0d1b1b04", + "metadata": {}, + "source": [ + "### 1.4.2 ```planet.fp_over_fs``` \n", + "\n", + "*Calculates the planet-to-star flux ratio (flux emmitted + reflected by the planet).*\n", + "\n", + "Here, the ```filter_name``` and ```wlrange``` parameters can be used in the same way as in the ```planet.exotethys``` funcion." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "05eeb35e", + "metadata": {}, + "outputs": [], + "source": [ + "planet.fp_over_fs(filter_name='COUSINS_R')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6ed3d283", + "metadata": {}, + "outputs": [], + "source": [ + "planet.fp_over_fs(filter_name = 'hst_wfc3_ir_g141', wlrange = [11000, 12000])" + ] + }, + { + "cell_type": "markdown", + "id": "1c53969d", + "metadata": {}, + "source": [ + "### 1.4.3 ```planet.convert_to_bjd_tdb```\n", + "\n", + "*Converts a time array from different time formats to BJDTDB.*\n", + "\n", + "```time_format``` defines the format of the input time-series, and it can be: \n", + "- ```JD_UTC```\n", + "- ```MJD_UTC```\n", + "- ```BJD_UTC```\n", + "- ```BJD_TDB```\n", + "- ```BJD_TT```\n", + "- ```HJD_UTC```\n", + "- ```HJD_BJD```\n", + "- ```HJD_TT```" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "388b2baa", + "metadata": {}, + "outputs": [], + "source": [ + "time_array_in_jd_utc = np.arange(2460000.0, 2460010.0, 0.1)\n", + "\n", + "time_array_in_bjd_tdb = planet.convert_to_bjd_tdb(time_array_in_jd_utc, time_format='JD_UTC')\n", + "\n", + "plt.figure(figsize=(7, 5))\n", + "plt.plot(\n", + " time_array_in_bjd_tdb, \n", + " (time_array_in_bjd_tdb - time_array_in_jd_utc) * (24 * 60), 'ko')\n", + "plt.ylabel(r'BJD$_\\mathrm{TDB}$ - JD$_\\mathrm{UTC}$ (min)')\n", + "plt.xlabel(r'Time (BJD$_\\mathrm{TDB}$)')" + ] + }, + { + "cell_type": "markdown", + "id": "9b1668be", + "metadata": {}, + "source": [ + "### 1.4.4 ```planet.convert_to_jd_utc```\n", + "\n", + "*Converts a time array from different time formats to JDUTC.*\n", + "\n", + "```time_format``` defines the format of the input time-series, and it can be: \n", + "- ```JD_UTC```\n", + "- ```MJD_UTC```\n", + "- ```BJD_UTC```\n", + "- ```BJD_TDB```\n", + "- ```BJD_TT```\n", + "- ```HJD_UTC```\n", + "- ```HJD_BJD```\n", + "- ```HJD_TT```" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a7c015ba", + "metadata": {}, + "outputs": [], + "source": [ + "time_array_in_bjd_tdb = np.arange(2460000.0, 2460010.0, 0.1)\n", + "\n", + "time_array_in_jd_utc = planet.convert_to_jd_utc(time_array_in_bjd_tdb, time_format='BJD_TDB')\n", + "\n", + "plt.figure(figsize=(7, 5))\n", + "plt.plot(\n", + " time_array_in_bjd_tdb, \n", + " (time_array_in_bjd_tdb - time_array_in_jd_utc) * (24 * 60), 'ko')\n", + "plt.ylabel(r'BJD$_\\mathrm{TDB}$ - JD$_\\mathrm{UTC}$ (min)')\n", + "plt.xlabel(r'Time (BJD$_\\mathrm{TDB}$)')" + ] + }, + { + "cell_type": "markdown", + "id": "7d17d45e", + "metadata": {}, + "source": [ + "### 1.4.5 ```planet.convert_to_relflux```\n", + "\n", + "*Converts a flux array from magnitude to relative flux.*\n", + "\n", + "```flux_format``` defines the format of the input series, and it can be: \n", + "- ```flux```\n", + "- ```mag```" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "27f8568f", + "metadata": {}, + "outputs": [], + "source": [ + "planet.convert_to_relflux(np.array([9, 9.1, 9.2]), np.array([0.01, 0.01, 0.01]), 'mag')" + ] + }, + { + "cell_type": "markdown", + "id": "65000686", + "metadata": {}, + "source": [ + "### 1.4.6 ```planet.planet_orbit```\n", + "\n", + "*Calculates the (x,y,z) position of the planet in a cartesian frame with the star at (0,0,0), the Earth at (+infinity,0,0) and the periastron located on the −y axis for $\\omega$=0.*" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a3841c6a", + "metadata": {}, + "outputs": [], + "source": [ + "time_array = np.arange(planet.mid_time - 1.5 * planet.period, planet.mid_time + 1.5 * planet.period, 0.01)\n", + "\n", + "x, y, z = planet.planet_orbit(time_array)\n", + "\n", + "plt.figure()\n", + "plt.plot(time_array, x, 'ko', ms=2, label='x')\n", + "plt.plot(time_array, y, 'ro', ms=2, label='y')\n", + "plt.plot(time_array, z, 'bo', ms=2, label='z')\n", + "plt.legend()\n", + "plt.ylabel('Planet-star distance / $R_*$')\n", + "plt.xlabel(r'Time (BJD$_\\mathrm{TDB}$)')" + ] + }, + { + "cell_type": "markdown", + "id": "7a34e925", + "metadata": {}, + "source": [ + "### 1.4.7 ```planet.planet_star_projected_distance```\n", + "\n", + "*Calculates the distance between the planet and the star relatively to the stellar radius, as projected on the celestial sphere.*" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "51760465", + "metadata": {}, + "outputs": [], + "source": [ + "time_array = np.arange(planet.mid_time - 1.5 * planet.period, planet.mid_time + 1.5 * planet.period, 0.01)\n", + "\n", + "planet_star_projected_distance = planet.planet_star_projected_distance(time_array)\n", + "\n", + "\n", + "plt.figure()\n", + "plt.plot(time_array, planet_star_projected_distance, 'ko', ms=2)\n", + "plt.ylabel('Planet-star projected distance / $R_*$')\n", + "plt.xlabel(r'Time (BJD$_\\mathrm{TDB}$)')" + ] + }, + { + "cell_type": "markdown", + "id": "627be872", + "metadata": {}, + "source": [ + "### 1.4.8 ```planet.planet_phase```\n", + "\n", + "*Calculates the planet phase with respect to the transit mid-time (time of conjunction when the planet is in front of the star, no units).*" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "53e80ac0", + "metadata": {}, + "outputs": [], + "source": [ + "time_array = np.arange(planet.mid_time - 1.5 * planet.period, planet.mid_time + 1.5 * planet.period, 0.01)\n", + "\n", + "planet_phase = planet.planet_phase(time_array)\n", + "\n", + "\n", + "plt.figure()\n", + "plt.plot(time_array, planet_phase, 'ko', ms=2)\n", + "plt.ylabel('Planet phase')\n", + "plt.xlabel(r'Time (BJD_$\\mathrm{TDB}$)')" + ] + }, + { + "cell_type": "markdown", + "id": "70b7f104", + "metadata": {}, + "source": [ + "### 1.4.9 ```planet.transit_depth```\n", + "\n", + "*Calculates the transit depth (in relative flux).*\n", + "\n", + "Here, the ```filter_name``` and ```wlrange``` parameters can be used in the same way as in the ```planet.exotethys``` funcion." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "abc50f13", + "metadata": {}, + "outputs": [], + "source": [ + "planet.transit_depth(filter_name='COUSINS_R')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a87738cc", + "metadata": {}, + "outputs": [], + "source": [ + "planet.transit_depth(filter_name = 'hst_wfc3_ir_g141', wlrange = [11000, 12000])" + ] + }, + { + "cell_type": "markdown", + "id": "9a27bc85", + "metadata": {}, + "source": [ + "### 1.4.10 ```planet.transit_duration```\n", + "\n", + "*Calculates the transit duration (in days).*" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "63088546", + "metadata": {}, + "outputs": [], + "source": [ + "planet.transit_duration()" + ] + }, + { + "cell_type": "markdown", + "id": "2e4dd6f3", + "metadata": {}, + "source": [ + "### 1.4.11 ```planet.transit_t12```\n", + "\n", + "*Calculates the time between transit contact points 1 and 2 (in days).*" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b5f05192", + "metadata": {}, + "outputs": [], + "source": [ + "planet.transit_t12()" + ] + }, + { + "cell_type": "markdown", + "id": "8008eb8b", + "metadata": {}, + "source": [ + "### 1.4.12 ```planet.eclipse_mid_time```\n", + "\n", + "*Calculates the eclipse mid-time (time of conjunction when the planet is behind the star, in days BJDTDB).*" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "fea4d446", + "metadata": {}, + "outputs": [], + "source": [ + "planet.eclipse_mid_time()" + ] + }, + { + "cell_type": "markdown", + "id": "3ba57fbc", + "metadata": {}, + "source": [ + "### 1.4.13 ```planet.eclipse_depth```\n", + "\n", + "*Calculates the eclipse depth (in relative flux).*\n", + "\n", + "Here, the ```filter_name``` and ```wlrange``` parameters can be used in the same way as in the ```planet.exotethys``` funcion." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6019b1e3", + "metadata": {}, + "outputs": [], + "source": [ + "planet.eclipse_depth(filter_name='COUSINS_R')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "baf21447", + "metadata": {}, + "outputs": [], + "source": [ + "planet.eclipse_depth(filter_name = 'hst_wfc3_ir_g141', wlrange = [11000, 12000])" + ] + }, + { + "cell_type": "markdown", + "id": "7b8a65be", + "metadata": {}, + "source": [ + "### 1.4.14 ```planet.eclipse_duration```\n", + "\n", + "*Calculates the eclipse duration (in days).*" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1dbea83e", + "metadata": {}, + "outputs": [], + "source": [ + "planet.eclipse_duration()" + ] + }, + { + "cell_type": "markdown", + "id": "87a1992d", + "metadata": {}, + "source": [ + "### 1.4.15 ```planet.transit```\n", + "\n", + "*Calculates the transit model (in relative flux).*\n", + "\n", + "Here, the ```filter_name``` and ```wlrange``` parameters can be used in the same way as in the ```planet.exotethys``` funcion." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b0bc2fe9", + "metadata": {}, + "outputs": [], + "source": [ + "time_array = np.arange(planet.mid_time - 1.1 * planet.transit_duration(), \n", + " planet.mid_time + 1.1 * planet.transit_duration(), 0.001)\n", + "\n", + "flux_jonhson_b = planet.transit(time_array, filter_name='JOHNSON_B')\n", + "flux_cousins_r = planet.transit(time_array, filter_name='COUSINS_R')\n", + "\n", + "plt.figure()\n", + "plt.plot(time_array, flux_jonhson_b, 'o', ms=2, label='JOHNSON_B')\n", + "plt.plot(time_array, flux_cousins_r, 'ro', ms=2, label='COUSINS_R')\n", + "plt.ylabel('Flux (relative)')\n", + "plt.xlabel(r'Time (BJD$_\\mathrm{TDB}$)')\n", + "plt.legend()\n" + ] + }, + { + "cell_type": "markdown", + "id": "4ddcebfc", + "metadata": {}, + "source": [ + "### 1.4.16 ```planet.eclipse```\n", + "\n", + "*Calculates the eclipse model (in relative flux).*\n", + "\n", + "Here, the ```filter_name``` and ```wlrange``` parameters can be used in the same way as in the ```planet.exotethys``` funcion." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9b71a26b", + "metadata": {}, + "outputs": [], + "source": [ + "time_array = np.arange(planet.eclipse_mid_time() - 1.1 * planet.eclipse_duration(), \n", + " planet.eclipse_mid_time() + 1.1 * planet.eclipse_duration(), 0.001)\n", + "\n", + "flux_jonhson_b = planet.eclipse(time_array, filter_name='JOHNSON_B')\n", + "flux_cousins_r = planet.eclipse(time_array, filter_name='COUSINS_R')\n", + "\n", + "\n", + "plt.figure()\n", + "plt.plot(time_array, flux_jonhson_b, 'o', ms=2, label='JOHNSON_B')\n", + "plt.plot(time_array, flux_cousins_r, 'ro', ms=2, label='COUSINS_R')\n", + "plt.ylabel('Flux (relative)')\n", + "plt.xlabel(r'Time (BJD$_\\mathrm{TDB}$)')\n", + "plt.legend()" + ] + }, + { + "cell_type": "markdown", + "id": "12120e5b", + "metadata": {}, + "source": [ + "### 1.4.17 ```planet.transit_integrated```\n", + "\n", + "*Calculates the exposure-integtared transit model (in relative flux).*\n", + "\n", + "```exp_time``` defines the exposure time of each dtaapoint in seconds. The time array mush indicate the mid-exposure time. \n", + "\n", + "Here, the ```filter_name``` and ```wlrange``` parameters can be used in the same way as in the ```planet.exotethys``` funcion." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "766174c9", + "metadata": {}, + "outputs": [], + "source": [ + "time_array = np.arange(planet.mid_time - 1.1 * planet.transit_duration(), \n", + " planet.mid_time + 1.1 * planet.transit_duration(), 0.001)\n", + "\n", + "flux_jonhson_b = planet.transit_integrated(time_array, exp_time=100, filter_name='JOHNSON_B')\n", + "flux_cousins_r = planet.transit_integrated(time_array, exp_time=100, filter_name='COUSINS_R')\n", + "\n", + "plt.figure()\n", + "plt.plot(time_array, flux_jonhson_b, 'o', ms=2, label='JOHNSON_B')\n", + "plt.plot(time_array, flux_cousins_r, 'ro', ms=2, label='COUSINS_R')\n", + "plt.ylabel('Flux (relative)')\n", + "plt.xlabel(r'Time (BJD$_\\mathrm{TDB}$)')\n", + "plt.legend()\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4728d82d", + "metadata": {}, + "outputs": [], + "source": [ + "time_array = np.arange(planet.mid_time - 1.1 * planet.transit_duration(), \n", + " planet.mid_time + 1.1 * planet.transit_duration(), 0.001)\n", + "\n", + "flux_cousins_r_10s = planet.transit_integrated(time_array, exp_time=10, filter_name='COUSINS_R')\n", + "flux_cousins_r_100s = planet.transit_integrated(time_array, exp_time=100, filter_name='COUSINS_R')\n", + "\n", + "plt.figure()\n", + "plt.plot(time_array, 1000000*(flux_cousins_r_10s - flux_cousins_r_100s), 'ko', ms=2)\n", + "plt.ylabel('Flux 10s exposure - 100s exposure (ppm)')\n", + "plt.xlabel(r'Time (BJD$_\\mathrm{TDB}$)')\n", + "plt.legend()\n" + ] + }, + { + "cell_type": "markdown", + "id": "ab040917", + "metadata": {}, + "source": [ + "### 1.4.18 ```planet.eclipse_integrated```\n", + "\n", + "*Calculates the exposure-integtared eclipse model (in relative flux).*\n", + "\n", + "```exp_time``` defines the exposure time of each dtaapoint in seconds. The time array mush indicate the mid-exposure time. \n", + "\n", + "Here, the ```filter_name``` and ```wlrange``` parameters can be used in the same way as in the ```planet.exotethys``` funcion." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d224f778", + "metadata": {}, + "outputs": [], + "source": [ + "time_array = np.arange(planet.eclipse_mid_time() - 1.1 * planet.eclipse_duration(), \n", + " planet.eclipse_mid_time() + 1.1 * planet.eclipse_duration(), 0.001)\n", + "\n", + "flux_jonhson_b = planet.eclipse_integrated(time_array, exp_time=100, filter_name='JOHNSON_B')\n", + "flux_cousins_r = planet.eclipse_integrated(time_array, exp_time=100, filter_name='COUSINS_R')\n", + "\n", + "\n", + "plt.figure()\n", + "plt.plot(time_array, flux_jonhson_b, 'o', ms=2, label='JOHNSON_B')\n", + "plt.plot(time_array, flux_cousins_r, 'ro', ms=2, label='COUSINS_R')\n", + "plt.ylabel('Flux (relative)')\n", + "plt.xlabel(r'Time (BJD$_\\mathrm{TDB}$)')\n", + "plt.legend()" + ] + }, + { + "cell_type": "markdown", + "id": "11069b96", + "metadata": {}, + "source": [ + "## 1.5 Creating a simulated light-curve" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1113ff77", + "metadata": {}, + "outputs": [], + "source": [ + "planet = plc.get_planet('WASP-12b')\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "926016dc", + "metadata": {}, + "outputs": [], + "source": [ + "# define the filter\n", + "filter_name = 'COUSINS_R'\n", + "\n", + "# define the out-of-transit observation time in hours\n", + "oot = 2\n", + "\n", + "# define the exposure time in seconds\n", + "exp_time = 60\n", + "\n", + "# define the noise (relatve flux)\n", + "noise = 0.0001\n", + "\n", + "\n", + "\n", + "# calculate the transit duration \n", + "transit_duration = planet.transit_duration()\n", + "\n", + "# define the time array\n", + "time_array = np.arange(planet.mid_time - 0.5 * transit_duration - oot/24, \n", + " planet.mid_time + 0.5 * transit_duration + oot/24, exp_time/60/60/24)\n", "\n", - "###############################################################################################\n", - "##### Definitions\n", - "###############################################################################################\n", + "# calculate model\n", + "flux_array = planet.transit_integrated(time_array, exp_time=exp_time, filter_name=filter_name)\n", "\n", - "# The core culculations are provided to ofer maximum efficiency and they are available to \n", - "# help developers build their own codes on the functionalities of PyLigthcurve.\n", - "# To use the core calculation in PyLightcurve we need to be able to provide the following \n", - "# information to the different functions:\n", + "# add noise\n", + "flux_array += np.random.normal(0, noise, len(flux_array))\n", "\n", - "# ra # float, in degrees\n", - "# dec # float, in degrees\n", - "# stellar_logg # float, in log(cm/s^2)\n", - "# stellar_temperature # float, in Kelvin\n", - "# stellar_metallicity # float, in dex(Fe/H) or dex(M/H)\n", - "# rp_over_rs # float, no units\n", - "# period # float, in days\n", - "# sma_over_rs # float, no units\n", - "# eccentricity # float, no units\n", - "# inclination # float, in degrees\n", - "# periastron # float, in degrees\n", - "# mid_time # float, in days (BJD_TDB)\n", - "# time_array # np.array dtype=float, in days (BJD_TDB)\n", - "# albedo # float, no units\n", - "# emissivity # float, no units\n", + "# calculate phase\n", + "phase_array = planet.planet_phase(time_array)\n", "\n", - "# For the examples below we will use the paraeters of the famus HD209458b:\n", "\n", - "ra = 330.795\n", - "dec = 18.884\n", - "stellar_logg = 4.36 \n", - "stellar_temperature = 6065.0\n", - "stellar_metallicity = 0.0\n", - "rp_over_rs = 0.12086\n", - "period = 3.5247486\n", - "sma_over_rs = 8.76\n", - "eccentricity = 0.0\n", - "inclination = 86.71 \n", - "periastron = 0.0\n", - "mid_time = 2452826.62928\n", - "albedo = 0.15 # assumed\n", - "emissivity = 1.0 # assumed\n", "\n", - "###############################################################################################" + "plt.figure()\n", + "plt.plot(phase_array, flux_array, 'ko', ms=2)\n", + "plt.ylabel('Flux (relative)')\n", + "plt.xlabel('Phase')\n" ] }, { "cell_type": "code", "execution_count": null, - "id": "c960cf47", + "id": "d88f7f9d", "metadata": {}, "outputs": [], "source": [] @@ -83,7 +909,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.5" + "version": "3.11.5" } }, "nbformat": 4, diff --git a/notebooks/2_detrending_examples/.ipynb_checkpoints/1_wasp39b_ground-checkpoint.ipynb b/notebooks/2_detrending_examples/.ipynb_checkpoints/1_wasp39b_ground-checkpoint.ipynb deleted file mode 100644 index 5ec4a1e..0000000 --- a/notebooks/2_detrending_examples/.ipynb_checkpoints/1_wasp39b_ground-checkpoint.ipynb +++ /dev/null @@ -1,2383 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "id": "988b5848", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "exoclock: Checking ephemerides database...\n", - "exoclock: Checking catalogues database...\n", - "exoclock: Checking ut database...\n", - "pylightcurve: Checking exotethys database...\n", - "pylightcurve: Checking photometry database...\n" - ] - } - ], - "source": [ - "%matplotlib notebook\n", - "import matplotlib.pyplot as plt\n", - "import pylightcurve as plc\n", - "import numpy as np\n", - "\n", - "\n", - "###############################################################################################\n", - "##### Create a Planet object\n", - "###############################################################################################\n", - "\n", - "# At first we need to create a Planet object.\n", - "# Planets include in the ExoClock project (https://www.exoclock.space/database/planets)\n", - "# can be loaded automatically. \n", - "# Alteranatively we can difine our custom Planet object (see notebook: The Planet class)\n", - "\n", - "planet = plc.get_planet('WASP-39b')\n", - "\n", - "###############################################################################################\n" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "id": "5f8fe7c5", - "metadata": {}, - "outputs": [ - { - "data": { - "application/javascript": [ - "/* Put everything inside the global mpl namespace */\n", - "/* global mpl */\n", - "window.mpl = {};\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(\n", - " '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", - "\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 = document.createElement('div');\n", - " this.root.setAttribute('style', 'display: inline-block');\n", - " this._root_extra_style(this.root);\n", - "\n", - " parent_element.appendChild(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 (fig.ratio !== 1) {\n", - " fig.send_message('set_device_pixel_ratio', {\n", - " device_pixel_ratio: fig.ratio,\n", - " });\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 = document.createElement('div');\n", - " titlebar.classList =\n", - " 'ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix';\n", - " var titletext = document.createElement('div');\n", - " titletext.classList = 'ui-dialog-title';\n", - " titletext.setAttribute(\n", - " 'style',\n", - " 'width: 100%; text-align: center; padding: 3px;'\n", - " );\n", - " titlebar.appendChild(titletext);\n", - " this.root.appendChild(titlebar);\n", - " this.header = titletext;\n", - "};\n", - "\n", - "mpl.figure.prototype._canvas_extra_style = function (_canvas_div) {};\n", - "\n", - "mpl.figure.prototype._root_extra_style = function (_canvas_div) {};\n", - "\n", - "mpl.figure.prototype._init_canvas = function () {\n", - " var fig = this;\n", - "\n", - " var canvas_div = (this.canvas_div = document.createElement('div'));\n", - " canvas_div.setAttribute('tabindex', '0');\n", - " canvas_div.setAttribute(\n", - " 'style',\n", - " 'border: 1px solid #ddd;' +\n", - " 'box-sizing: content-box;' +\n", - " 'clear: both;' +\n", - " 'min-height: 1px;' +\n", - " 'min-width: 1px;' +\n", - " 'outline: 0;' +\n", - " 'overflow: hidden;' +\n", - " 'position: relative;' +\n", - " 'resize: both;' +\n", - " 'z-index: 2;'\n", - " );\n", - "\n", - " function on_keyboard_event_closure(name) {\n", - " return function (event) {\n", - " return fig.key_event(event, name);\n", - " };\n", - " }\n", - "\n", - " canvas_div.addEventListener(\n", - " 'keydown',\n", - " on_keyboard_event_closure('key_press')\n", - " );\n", - " canvas_div.addEventListener(\n", - " 'keyup',\n", - " on_keyboard_event_closure('key_release')\n", - " );\n", - "\n", - " this._canvas_extra_style(canvas_div);\n", - " this.root.appendChild(canvas_div);\n", - "\n", - " var canvas = (this.canvas = document.createElement('canvas'));\n", - " canvas.classList.add('mpl-canvas');\n", - " canvas.setAttribute(\n", - " 'style',\n", - " 'box-sizing: content-box;' +\n", - " 'pointer-events: none;' +\n", - " 'position: relative;' +\n", - " 'z-index: 0;'\n", - " );\n", - "\n", - " this.context = canvas.getContext('2d');\n", - "\n", - " var backingStore =\n", - " this.context.backingStorePixelRatio ||\n", - " this.context.webkitBackingStorePixelRatio ||\n", - " this.context.mozBackingStorePixelRatio ||\n", - " this.context.msBackingStorePixelRatio ||\n", - " this.context.oBackingStorePixelRatio ||\n", - " this.context.backingStorePixelRatio ||\n", - " 1;\n", - "\n", - " this.ratio = (window.devicePixelRatio || 1) / backingStore;\n", - "\n", - " var rubberband_canvas = (this.rubberband_canvas = document.createElement(\n", - " 'canvas'\n", - " ));\n", - " rubberband_canvas.setAttribute(\n", - " 'style',\n", - " 'box-sizing: content-box;' +\n", - " 'left: 0;' +\n", - " 'pointer-events: none;' +\n", - " 'position: absolute;' +\n", - " 'top: 0;' +\n", - " 'z-index: 1;'\n", - " );\n", - "\n", - " // Apply a ponyfill if ResizeObserver is not implemented by browser.\n", - " if (this.ResizeObserver === undefined) {\n", - " if (window.ResizeObserver !== undefined) {\n", - " this.ResizeObserver = window.ResizeObserver;\n", - " } else {\n", - " var obs = _JSXTOOLS_RESIZE_OBSERVER({});\n", - " this.ResizeObserver = obs.ResizeObserver;\n", - " }\n", - " }\n", - "\n", - " this.resizeObserverInstance = new this.ResizeObserver(function (entries) {\n", - " // There's no need to resize if the WebSocket is not connected:\n", - " // - If it is still connecting, then we will get an initial resize from\n", - " // Python once it connects.\n", - " // - If it has disconnected, then resizing will clear the canvas and\n", - " // never get anything back to refill it, so better to not resize and\n", - " // keep something visible.\n", - " if (fig.ws.readyState != 1) {\n", - " return;\n", - " }\n", - " var nentries = entries.length;\n", - " for (var i = 0; i < nentries; i++) {\n", - " var entry = entries[i];\n", - " var width, height;\n", - " if (entry.contentBoxSize) {\n", - " if (entry.contentBoxSize instanceof Array) {\n", - " // Chrome 84 implements new version of spec.\n", - " width = entry.contentBoxSize[0].inlineSize;\n", - " height = entry.contentBoxSize[0].blockSize;\n", - " } else {\n", - " // Firefox implements old version of spec.\n", - " width = entry.contentBoxSize.inlineSize;\n", - " height = entry.contentBoxSize.blockSize;\n", - " }\n", - " } else {\n", - " // Chrome <84 implements even older version of spec.\n", - " width = entry.contentRect.width;\n", - " height = entry.contentRect.height;\n", - " }\n", - "\n", - " // Keep the size of the canvas and rubber band canvas in sync with\n", - " // the canvas container.\n", - " if (entry.devicePixelContentBoxSize) {\n", - " // Chrome 84 implements new version of spec.\n", - " canvas.setAttribute(\n", - " 'width',\n", - " entry.devicePixelContentBoxSize[0].inlineSize\n", - " );\n", - " canvas.setAttribute(\n", - " 'height',\n", - " entry.devicePixelContentBoxSize[0].blockSize\n", - " );\n", - " } else {\n", - " canvas.setAttribute('width', width * fig.ratio);\n", - " canvas.setAttribute('height', height * fig.ratio);\n", - " }\n", - " /* This rescales the canvas back to display pixels, so that it\n", - " * appears correct on HiDPI screens. */\n", - " canvas.style.width = width + 'px';\n", - " canvas.style.height = height + 'px';\n", - "\n", - " rubberband_canvas.setAttribute('width', width);\n", - " rubberband_canvas.setAttribute('height', height);\n", - "\n", - " // And update the size in Python. We ignore the initial 0/0 size\n", - " // that occurs as the element is placed into the DOM, which should\n", - " // otherwise not happen due to the minimum size styling.\n", - " if (width != 0 && height != 0) {\n", - " fig.request_resize(width, height);\n", - " }\n", - " }\n", - " });\n", - " this.resizeObserverInstance.observe(canvas_div);\n", - "\n", - " function on_mouse_event_closure(name) {\n", - " /* User Agent sniffing is bad, but WebKit is busted:\n", - " * https://bugs.webkit.org/show_bug.cgi?id=144526\n", - " * https://bugs.webkit.org/show_bug.cgi?id=181818\n", - " * The worst that happens here is that they get an extra browser\n", - " * selection when dragging, if this check fails to catch them.\n", - " */\n", - " var UA = navigator.userAgent;\n", - " var isWebKit = /AppleWebKit/.test(UA) && !/Chrome/.test(UA);\n", - " if(isWebKit) {\n", - " return function (event) {\n", - " /* This prevents the web browser from automatically changing to\n", - " * the text insertion cursor when the button is pressed. We\n", - " * want to control all of the cursor setting manually through\n", - " * the 'cursor' event from matplotlib */\n", - " event.preventDefault()\n", - " return fig.mouse_event(event, name);\n", - " };\n", - " } else {\n", - " return function (event) {\n", - " return fig.mouse_event(event, name);\n", - " };\n", - " }\n", - " }\n", - "\n", - " canvas_div.addEventListener(\n", - " 'mousedown',\n", - " on_mouse_event_closure('button_press')\n", - " );\n", - " canvas_div.addEventListener(\n", - " 'mouseup',\n", - " on_mouse_event_closure('button_release')\n", - " );\n", - " canvas_div.addEventListener(\n", - " 'dblclick',\n", - " on_mouse_event_closure('dblclick')\n", - " );\n", - " // Throttle sequential mouse events to 1 every 20ms.\n", - " canvas_div.addEventListener(\n", - " 'mousemove',\n", - " on_mouse_event_closure('motion_notify')\n", - " );\n", - "\n", - " canvas_div.addEventListener(\n", - " 'mouseenter',\n", - " on_mouse_event_closure('figure_enter')\n", - " );\n", - " canvas_div.addEventListener(\n", - " 'mouseleave',\n", - " on_mouse_event_closure('figure_leave')\n", - " );\n", - "\n", - " canvas_div.addEventListener('wheel', function (event) {\n", - " if (event.deltaY < 0) {\n", - " event.step = 1;\n", - " } else {\n", - " event.step = -1;\n", - " }\n", - " on_mouse_event_closure('scroll')(event);\n", - " });\n", - "\n", - " canvas_div.appendChild(canvas);\n", - " canvas_div.appendChild(rubberband_canvas);\n", - "\n", - " this.rubberband_context = rubberband_canvas.getContext('2d');\n", - " this.rubberband_context.strokeStyle = '#000000';\n", - "\n", - " this._resize_canvas = function (width, height, forward) {\n", - " if (forward) {\n", - " canvas_div.style.width = width + 'px';\n", - " canvas_div.style.height = height + 'px';\n", - " }\n", - " };\n", - "\n", - " // Disable right mouse context menu.\n", - " canvas_div.addEventListener('contextmenu', function (_e) {\n", - " event.preventDefault();\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 toolbar = document.createElement('div');\n", - " toolbar.classList = 'mpl-toolbar';\n", - " this.root.appendChild(toolbar);\n", - "\n", - " function on_click_closure(name) {\n", - " return function (_event) {\n", - " return fig.toolbar_button_onclick(name);\n", - " };\n", - " }\n", - "\n", - " function on_mouseover_closure(tooltip) {\n", - " return function (event) {\n", - " if (!event.currentTarget.disabled) {\n", - " return fig.toolbar_button_onmouseover(tooltip);\n", - " }\n", - " };\n", - " }\n", - "\n", - " fig.buttons = {};\n", - " var buttonGroup = document.createElement('div');\n", - " buttonGroup.classList = 'mpl-button-group';\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", - " /* Instead of a spacer, we start a new button group. */\n", - " if (buttonGroup.hasChildNodes()) {\n", - " toolbar.appendChild(buttonGroup);\n", - " }\n", - " buttonGroup = document.createElement('div');\n", - " buttonGroup.classList = 'mpl-button-group';\n", - " continue;\n", - " }\n", - "\n", - " var button = (fig.buttons[name] = document.createElement('button'));\n", - " button.classList = 'mpl-widget';\n", - " button.setAttribute('role', 'button');\n", - " button.setAttribute('aria-disabled', 'false');\n", - " button.addEventListener('click', on_click_closure(method_name));\n", - " button.addEventListener('mouseover', on_mouseover_closure(tooltip));\n", - "\n", - " var icon_img = document.createElement('img');\n", - " icon_img.src = '_images/' + image + '.png';\n", - " icon_img.srcset = '_images/' + image + '_large.png 2x';\n", - " icon_img.alt = tooltip;\n", - " button.appendChild(icon_img);\n", - "\n", - " buttonGroup.appendChild(button);\n", - " }\n", - "\n", - " if (buttonGroup.hasChildNodes()) {\n", - " toolbar.appendChild(buttonGroup);\n", - " }\n", - "\n", - " var fmt_picker = document.createElement('select');\n", - " fmt_picker.classList = 'mpl-widget';\n", - " toolbar.appendChild(fmt_picker);\n", - " this.format_dropdown = fmt_picker;\n", - "\n", - " for (var ind in mpl.extensions) {\n", - " var fmt = mpl.extensions[ind];\n", - " var option = document.createElement('option');\n", - " option.selected = fmt === mpl.default_extension;\n", - " option.innerHTML = fmt;\n", - " fmt_picker.appendChild(option);\n", - " }\n", - "\n", - " var status_bar = document.createElement('span');\n", - " status_bar.classList = 'mpl-message';\n", - " toolbar.appendChild(status_bar);\n", - " this.message = status_bar;\n", - "};\n", - "\n", - "mpl.figure.prototype.request_resize = function (x_pixels, y_pixels) {\n", - " // Request matplotlib to resize the figure. Matplotlib will then trigger a resize in the client,\n", - " // which will in turn request a refresh of the image.\n", - " this.send_message('resize', { width: x_pixels, height: y_pixels });\n", - "};\n", - "\n", - "mpl.figure.prototype.send_message = function (type, properties) {\n", - " properties['type'] = type;\n", - " properties['figure_id'] = this.id;\n", - " this.ws.send(JSON.stringify(properties));\n", - "};\n", - "\n", - "mpl.figure.prototype.send_draw_message = function () {\n", - " if (!this.waiting) {\n", - " this.waiting = true;\n", - " this.ws.send(JSON.stringify({ type: 'draw', figure_id: this.id }));\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_save = function (fig, _msg) {\n", - " var format_dropdown = fig.format_dropdown;\n", - " var format = format_dropdown.options[format_dropdown.selectedIndex].value;\n", - " fig.ondownload(fig, format);\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_resize = function (fig, msg) {\n", - " var size = msg['size'];\n", - " if (size[0] !== fig.canvas.width || size[1] !== fig.canvas.height) {\n", - " fig._resize_canvas(size[0], size[1], msg['forward']);\n", - " fig.send_message('refresh', {});\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_rubberband = function (fig, msg) {\n", - " var x0 = msg['x0'] / fig.ratio;\n", - " var y0 = (fig.canvas.height - msg['y0']) / fig.ratio;\n", - " var x1 = msg['x1'] / fig.ratio;\n", - " var y1 = (fig.canvas.height - msg['y1']) / fig.ratio;\n", - " x0 = Math.floor(x0) + 0.5;\n", - " y0 = Math.floor(y0) + 0.5;\n", - " x1 = Math.floor(x1) + 0.5;\n", - " y1 = Math.floor(y1) + 0.5;\n", - " var min_x = Math.min(x0, x1);\n", - " var min_y = Math.min(y0, y1);\n", - " var width = Math.abs(x1 - x0);\n", - " var height = Math.abs(y1 - y0);\n", - "\n", - " fig.rubberband_context.clearRect(\n", - " 0,\n", - " 0,\n", - " fig.canvas.width / fig.ratio,\n", - " fig.canvas.height / fig.ratio\n", - " );\n", - "\n", - " fig.rubberband_context.strokeRect(min_x, min_y, width, height);\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_figure_label = function (fig, msg) {\n", - " // Updates the figure title.\n", - " fig.header.textContent = msg['label'];\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_cursor = function (fig, msg) {\n", - " fig.canvas_div.style.cursor = msg['cursor'];\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_message = function (fig, msg) {\n", - " fig.message.textContent = msg['message'];\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_draw = function (fig, _msg) {\n", - " // Request the server to send over a new figure.\n", - " fig.send_draw_message();\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_image_mode = function (fig, msg) {\n", - " fig.image_mode = msg['mode'];\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_history_buttons = function (fig, msg) {\n", - " for (var key in msg) {\n", - " if (!(key in fig.buttons)) {\n", - " continue;\n", - " }\n", - " fig.buttons[key].disabled = !msg[key];\n", - " fig.buttons[key].setAttribute('aria-disabled', !msg[key]);\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_navigate_mode = function (fig, msg) {\n", - " if (msg['mode'] === 'PAN') {\n", - " fig.buttons['Pan'].classList.add('active');\n", - " fig.buttons['Zoom'].classList.remove('active');\n", - " } else if (msg['mode'] === 'ZOOM') {\n", - " fig.buttons['Pan'].classList.remove('active');\n", - " fig.buttons['Zoom'].classList.add('active');\n", - " } else {\n", - " fig.buttons['Pan'].classList.remove('active');\n", - " fig.buttons['Zoom'].classList.remove('active');\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.updated_canvas_event = function () {\n", - " // Called whenever the canvas gets updated.\n", - " this.send_message('ack', {});\n", - "};\n", - "\n", - "// A function to construct a web socket function for onmessage handling.\n", - "// Called in the figure constructor.\n", - "mpl.figure.prototype._make_on_message_function = function (fig) {\n", - " return function socket_on_message(evt) {\n", - " if (evt.data instanceof Blob) {\n", - " var img = evt.data;\n", - " if (img.type !== 'image/png') {\n", - " /* FIXME: We get \"Resource interpreted as Image but\n", - " * transferred with MIME type text/plain:\" errors on\n", - " * Chrome. But how to set the MIME type? It doesn't seem\n", - " * to be part of the websocket stream */\n", - " img.type = 'image/png';\n", - " }\n", - "\n", - " /* Free the memory for the previous frames */\n", - " if (fig.imageObj.src) {\n", - " (window.URL || window.webkitURL).revokeObjectURL(\n", - " fig.imageObj.src\n", - " );\n", - " }\n", - "\n", - " fig.imageObj.src = (window.URL || window.webkitURL).createObjectURL(\n", - " img\n", - " );\n", - " fig.updated_canvas_event();\n", - " fig.waiting = false;\n", - " return;\n", - " } else if (\n", - " typeof evt.data === 'string' &&\n", - " evt.data.slice(0, 21) === 'data:image/png;base64'\n", - " ) {\n", - " fig.imageObj.src = evt.data;\n", - " fig.updated_canvas_event();\n", - " fig.waiting = false;\n", - " return;\n", - " }\n", - "\n", - " var msg = JSON.parse(evt.data);\n", - " var msg_type = msg['type'];\n", - "\n", - " // Call the \"handle_{type}\" callback, which takes\n", - " // the figure and JSON message as its only arguments.\n", - " try {\n", - " var callback = fig['handle_' + msg_type];\n", - " } catch (e) {\n", - " console.log(\n", - " \"No handler for the '\" + msg_type + \"' message type: \",\n", - " msg\n", - " );\n", - " return;\n", - " }\n", - "\n", - " if (callback) {\n", - " try {\n", - " // console.log(\"Handling '\" + msg_type + \"' message: \", msg);\n", - " callback(fig, msg);\n", - " } catch (e) {\n", - " console.log(\n", - " \"Exception inside the 'handler_\" + msg_type + \"' callback:\",\n", - " e,\n", - " e.stack,\n", - " msg\n", - " );\n", - " }\n", - " }\n", - " };\n", - "};\n", - "\n", - "function getModifiers(event) {\n", - " var mods = [];\n", - " if (event.ctrlKey) {\n", - " mods.push('ctrl');\n", - " }\n", - " if (event.altKey) {\n", - " mods.push('alt');\n", - " }\n", - " if (event.shiftKey) {\n", - " mods.push('shift');\n", - " }\n", - " if (event.metaKey) {\n", - " mods.push('meta');\n", - " }\n", - " return mods;\n", - "}\n", - "\n", - "/*\n", - " * return a copy of an object with only non-object keys\n", - " * we need this to avoid circular references\n", - " * https://stackoverflow.com/a/24161582/3208463\n", - " */\n", - "function simpleKeys(original) {\n", - " return Object.keys(original).reduce(function (obj, key) {\n", - " if (typeof original[key] !== 'object') {\n", - " obj[key] = original[key];\n", - " }\n", - " return obj;\n", - " }, {});\n", - "}\n", - "\n", - "mpl.figure.prototype.mouse_event = function (event, name) {\n", - " if (name === 'button_press') {\n", - " this.canvas.focus();\n", - " this.canvas_div.focus();\n", - " }\n", - "\n", - " // from https://stackoverflow.com/q/1114465\n", - " var boundingRect = this.canvas.getBoundingClientRect();\n", - " var x = (event.clientX - boundingRect.left) * this.ratio;\n", - " var y = (event.clientY - boundingRect.top) * this.ratio;\n", - "\n", - " this.send_message(name, {\n", - " x: x,\n", - " y: y,\n", - " button: event.button,\n", - " step: event.step,\n", - " modifiers: getModifiers(event),\n", - " guiEvent: simpleKeys(event),\n", - " });\n", - "\n", - " return false;\n", - "};\n", - "\n", - "mpl.figure.prototype._key_event_extra = function (_event, _name) {\n", - " // Handle any extra behaviour associated with a key event\n", - "};\n", - "\n", - "mpl.figure.prototype.key_event = function (event, name) {\n", - " // Prevent repeat events\n", - " if (name === 'key_press') {\n", - " if (event.key === this._key) {\n", - " return;\n", - " } else {\n", - " this._key = event.key;\n", - " }\n", - " }\n", - " if (name === 'key_release') {\n", - " this._key = null;\n", - " }\n", - "\n", - " var value = '';\n", - " if (event.ctrlKey && event.key !== 'Control') {\n", - " value += 'ctrl+';\n", - " }\n", - " else if (event.altKey && event.key !== 'Alt') {\n", - " value += 'alt+';\n", - " }\n", - " else if (event.shiftKey && event.key !== 'Shift') {\n", - " value += 'shift+';\n", - " }\n", - "\n", - " value += 'k' + event.key;\n", - "\n", - " this._key_event_extra(event, name);\n", - "\n", - " this.send_message(name, { key: value, guiEvent: simpleKeys(event) });\n", - " return false;\n", - "};\n", - "\n", - "mpl.figure.prototype.toolbar_button_onclick = function (name) {\n", - " if (name === 'download') {\n", - " this.handle_save(this, null);\n", - " } else {\n", - " this.send_message('toolbar_button', { name: name });\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.toolbar_button_onmouseover = function (tooltip) {\n", - " this.message.textContent = tooltip;\n", - "};\n", - "\n", - "///////////////// REMAINING CONTENT GENERATED BY embed_js.py /////////////////\n", - "// prettier-ignore\n", - "var _JSXTOOLS_RESIZE_OBSERVER=function(A){var t,i=new WeakMap,n=new WeakMap,a=new WeakMap,r=new WeakMap,o=new Set;function s(e){if(!(this instanceof s))throw new TypeError(\"Constructor requires 'new' operator\");i.set(this,e)}function h(){throw new TypeError(\"Function is not a constructor\")}function c(e,t,i,n){e=0 in arguments?Number(arguments[0]):0,t=1 in arguments?Number(arguments[1]):0,i=2 in arguments?Number(arguments[2]):0,n=3 in arguments?Number(arguments[3]):0,this.right=(this.x=this.left=e)+(this.width=i),this.bottom=(this.y=this.top=t)+(this.height=n),Object.freeze(this)}function d(){t=requestAnimationFrame(d);var s=new WeakMap,p=new Set;o.forEach((function(t){r.get(t).forEach((function(i){var r=t instanceof window.SVGElement,o=a.get(t),d=r?0:parseFloat(o.paddingTop),f=r?0:parseFloat(o.paddingRight),l=r?0:parseFloat(o.paddingBottom),u=r?0:parseFloat(o.paddingLeft),g=r?0:parseFloat(o.borderTopWidth),m=r?0:parseFloat(o.borderRightWidth),w=r?0:parseFloat(o.borderBottomWidth),b=u+f,F=d+l,v=(r?0:parseFloat(o.borderLeftWidth))+m,W=g+w,y=r?0:t.offsetHeight-W-t.clientHeight,E=r?0:t.offsetWidth-v-t.clientWidth,R=b+v,z=F+W,M=r?t.width:parseFloat(o.width)-R-E,O=r?t.height:parseFloat(o.height)-z-y;if(n.has(t)){var k=n.get(t);if(k[0]===M&&k[1]===O)return}n.set(t,[M,O]);var S=Object.create(h.prototype);S.target=t,S.contentRect=new c(u,d,M,O),s.has(i)||(s.set(i,[]),p.add(i)),s.get(i).push(S)}))})),p.forEach((function(e){i.get(e).call(e,s.get(e),e)}))}return s.prototype.observe=function(i){if(i instanceof window.Element){r.has(i)||(r.set(i,new Set),o.add(i),a.set(i,window.getComputedStyle(i)));var n=r.get(i);n.has(this)||n.add(this),cancelAnimationFrame(t),t=requestAnimationFrame(d)}},s.prototype.unobserve=function(i){if(i instanceof window.Element&&r.has(i)){var n=r.get(i);n.has(this)&&(n.delete(this),n.size||(r.delete(i),o.delete(i))),n.size||r.delete(i),o.size||cancelAnimationFrame(t)}},A.DOMRectReadOnly=c,A.ResizeObserver=s,A.ResizeObserverEntry=h,A}; // eslint-disable-line\n", - "mpl.toolbar_items = [[\"Home\", \"Reset original view\", \"fa fa-home\", \"home\"], [\"Back\", \"Back to previous view\", \"fa fa-arrow-left\", \"back\"], [\"Forward\", \"Forward to next view\", \"fa fa-arrow-right\", \"forward\"], [\"\", \"\", \"\", \"\"], [\"Pan\", \"Left button pans, Right button zooms\\nx/y fixes axis, CTRL fixes aspect\", \"fa fa-arrows\", \"pan\"], [\"Zoom\", \"Zoom to rectangle\\nx/y fixes axis\", \"fa fa-square-o\", \"zoom\"], [\"\", \"\", \"\", \"\"], [\"Download\", \"Download plot\", \"fa fa-floppy-o\", \"download\"]];\n", - "\n", - "mpl.extensions = [\"eps\", \"jpeg\", \"pgf\", \"pdf\", \"png\", \"ps\", \"raw\", \"svg\", \"tif\", \"webp\"];\n", - "\n", - "mpl.default_extension = \"png\";/* global mpl */\n", - "\n", - "var comm_websocket_adapter = function (comm) {\n", - " // Create a \"websocket\"-like object which calls the given IPython comm\n", - " // object with the appropriate methods. Currently this is a non binary\n", - " // socket, so there is still some room for performance tuning.\n", - " var ws = {};\n", - "\n", - " ws.binaryType = comm.kernel.ws.binaryType;\n", - " ws.readyState = comm.kernel.ws.readyState;\n", - " function updateReadyState(_event) {\n", - " if (comm.kernel.ws) {\n", - " ws.readyState = comm.kernel.ws.readyState;\n", - " } else {\n", - " ws.readyState = 3; // Closed state.\n", - " }\n", - " }\n", - " comm.kernel.ws.addEventListener('open', updateReadyState);\n", - " comm.kernel.ws.addEventListener('close', updateReadyState);\n", - " comm.kernel.ws.addEventListener('error', updateReadyState);\n", - "\n", - " ws.close = function () {\n", - " comm.close();\n", - " };\n", - " ws.send = function (m) {\n", - " //console.log('sending', m);\n", - " comm.send(m);\n", - " };\n", - " // Register the callback with on_msg.\n", - " comm.on_msg(function (msg) {\n", - " //console.log('receiving', msg['content']['data'], msg);\n", - " var data = msg['content']['data'];\n", - " if (data['blob'] !== undefined) {\n", - " data = {\n", - " data: new Blob(msg['buffers'], { type: data['blob'] }),\n", - " };\n", - " }\n", - " // Pass the mpl event to the overridden (by mpl) onmessage function.\n", - " ws.onmessage(data);\n", - " });\n", - " return ws;\n", - "};\n", - "\n", - "mpl.mpl_figure_comm = function (comm, msg) {\n", - " // This is the function which gets called when the mpl process\n", - " // starts-up an IPython Comm through the \"matplotlib\" channel.\n", - "\n", - " var id = msg.content.data.id;\n", - " // Get hold of the div created by the display call when the Comm\n", - " // socket was opened in Python.\n", - " var element = document.getElementById(id);\n", - " var ws_proxy = comm_websocket_adapter(comm);\n", - "\n", - " function ondownload(figure, _format) {\n", - " window.open(figure.canvas.toDataURL());\n", - " }\n", - "\n", - " var fig = new mpl.figure(id, ws_proxy, ondownload, element);\n", - "\n", - " // Call onopen now - mpl needs it, as it is assuming we've passed it a real\n", - " // web socket which is closed, not our websocket->open comm proxy.\n", - " ws_proxy.onopen();\n", - "\n", - " fig.parent_element = element;\n", - " fig.cell_info = mpl.find_output_cell(\"
\");\n", - " if (!fig.cell_info) {\n", - " console.error('Failed to find cell for figure', id, fig);\n", - " return;\n", - " }\n", - " fig.cell_info[0].output_area.element.on(\n", - " 'cleared',\n", - " { fig: fig },\n", - " fig._remove_fig_handler\n", - " );\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_close = function (fig, msg) {\n", - " var width = fig.canvas.width / fig.ratio;\n", - " fig.cell_info[0].output_area.element.off(\n", - " 'cleared',\n", - " fig._remove_fig_handler\n", - " );\n", - " fig.resizeObserverInstance.unobserve(fig.canvas_div);\n", - "\n", - " // Update the output cell to use the data from the current canvas.\n", - " fig.push_to_output();\n", - " var dataURL = fig.canvas.toDataURL();\n", - " // Re-enable the keyboard manager in IPython - without this line, in FF,\n", - " // the notebook keyboard shortcuts fail.\n", - " IPython.keyboard_manager.enable();\n", - " fig.parent_element.innerHTML =\n", - " '';\n", - " fig.close_ws(fig, msg);\n", - "};\n", - "\n", - "mpl.figure.prototype.close_ws = function (fig, msg) {\n", - " fig.send_message('closing', msg);\n", - " // fig.ws.close()\n", - "};\n", - "\n", - "mpl.figure.prototype.push_to_output = function (_remove_interactive) {\n", - " // Turn the data on the canvas into data in the output cell.\n", - " var width = this.canvas.width / this.ratio;\n", - " var dataURL = this.canvas.toDataURL();\n", - " this.cell_info[1]['text/html'] =\n", - " '';\n", - "};\n", - "\n", - "mpl.figure.prototype.updated_canvas_event = function () {\n", - " // Tell IPython that the notebook contents must change.\n", - " IPython.notebook.set_dirty(true);\n", - " this.send_message('ack', {});\n", - " var fig = this;\n", - " // Wait a second, then push the new image to the DOM so\n", - " // that it is saved nicely (might be nice to debounce this).\n", - " setTimeout(function () {\n", - " fig.push_to_output();\n", - " }, 1000);\n", - "};\n", - "\n", - "mpl.figure.prototype._init_toolbar = function () {\n", - " var fig = this;\n", - "\n", - " var toolbar = document.createElement('div');\n", - " toolbar.classList = 'btn-toolbar';\n", - " this.root.appendChild(toolbar);\n", - "\n", - " function on_click_closure(name) {\n", - " return function (_event) {\n", - " return fig.toolbar_button_onclick(name);\n", - " };\n", - " }\n", - "\n", - " function on_mouseover_closure(tooltip) {\n", - " return function (event) {\n", - " if (!event.currentTarget.disabled) {\n", - " return fig.toolbar_button_onmouseover(tooltip);\n", - " }\n", - " };\n", - " }\n", - "\n", - " fig.buttons = {};\n", - " var buttonGroup = document.createElement('div');\n", - " buttonGroup.classList = 'btn-group';\n", - " var button;\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", - " /* Instead of a spacer, we start a new button group. */\n", - " if (buttonGroup.hasChildNodes()) {\n", - " toolbar.appendChild(buttonGroup);\n", - " }\n", - " buttonGroup = document.createElement('div');\n", - " buttonGroup.classList = 'btn-group';\n", - " continue;\n", - " }\n", - "\n", - " button = fig.buttons[name] = document.createElement('button');\n", - " button.classList = 'btn btn-default';\n", - " button.href = '#';\n", - " button.title = name;\n", - " button.innerHTML = '';\n", - " button.addEventListener('click', on_click_closure(method_name));\n", - " button.addEventListener('mouseover', on_mouseover_closure(tooltip));\n", - " buttonGroup.appendChild(button);\n", - " }\n", - "\n", - " if (buttonGroup.hasChildNodes()) {\n", - " toolbar.appendChild(buttonGroup);\n", - " }\n", - "\n", - " // Add the status bar.\n", - " var status_bar = document.createElement('span');\n", - " status_bar.classList = 'mpl-message pull-right';\n", - " toolbar.appendChild(status_bar);\n", - " this.message = status_bar;\n", - "\n", - " // Add the close button to the window.\n", - " var buttongrp = document.createElement('div');\n", - " buttongrp.classList = 'btn-group inline pull-right';\n", - " button = document.createElement('button');\n", - " button.classList = 'btn btn-mini btn-primary';\n", - " button.href = '#';\n", - " button.title = 'Stop Interaction';\n", - " button.innerHTML = '';\n", - " button.addEventListener('click', function (_evt) {\n", - " fig.handle_close(fig, {});\n", - " });\n", - " button.addEventListener(\n", - " 'mouseover',\n", - " on_mouseover_closure('Stop Interaction')\n", - " );\n", - " buttongrp.appendChild(button);\n", - " var titlebar = this.root.querySelector('.ui-dialog-titlebar');\n", - " titlebar.insertBefore(buttongrp, titlebar.firstChild);\n", - "};\n", - "\n", - "mpl.figure.prototype._remove_fig_handler = function (event) {\n", - " var fig = event.data.fig;\n", - " if (event.target !== this) {\n", - " // Ignore bubbled events from children.\n", - " return;\n", - " }\n", - " fig.close_ws(fig, {});\n", - "};\n", - "\n", - "mpl.figure.prototype._root_extra_style = function (el) {\n", - " el.style.boxSizing = 'content-box'; // override notebook setting of border-box.\n", - "};\n", - "\n", - "mpl.figure.prototype._canvas_extra_style = function (el) {\n", - " // this is important to make the div 'focusable\n", - " el.setAttribute('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", - " } else {\n", - " // location in version 2\n", - " IPython.keyboard_manager.register_events(el);\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype._key_event_extra = function (event, _name) {\n", - " // Check for shift+enter\n", - " if (event.shiftKey && event.which === 13) {\n", - " this.canvas_div.blur();\n", - " // select the cell after this one\n", - " var index = IPython.notebook.find_cell_index(this.cell_info[0]);\n", - " IPython.notebook.select(index + 1);\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_save = function (fig, _msg) {\n", - " fig.ondownload(fig, null);\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 < ncells; i++) {\n", - " var cell = cells[i];\n", - " if (cell.cell_type === 'code') {\n", - " for (var j = 0; j < cell.output_area.outputs.length; j++) {\n", - " var data = cell.output_area.outputs[j];\n", - " if (data.data) {\n", - " // IPython >= 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(\n", - " 'matplotlib',\n", - " mpl.mpl_figure_comm\n", - " );\n", - "}\n" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/html": [ - "
" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "time_format: JD_UTC\n", - "time_stamp: start\n", - "exp_time: 60.0\n", - "flux_format: flux\n", - "filter_name: luminance\n", - "observatory_latitude: 37.9394\n", - "observatory_longitude: 14.0206\n" - ] - } - ], - "source": [ - "###############################################################################################\n", - "##### Load data\n", - "###############################################################################################\n", - "\n", - "# This dataset contains one transit observation of WASP-39b, obtained by Carmelo Falco, \n", - "# from the GALHassin observatory in Sicily, Italy.\n", - "\n", - "data = plc.open_dict('wasp39b_ground.pickle')\n", - "\n", - "###############################################################################################\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "###############################################################################################\n", - "##### Inspect data\n", - "###############################################################################################\n", - "\n", - "# The dictionaly contains the necessary keywords:\n", - "# 'time'\n", - "# 'time_format'\n", - "# 'time_stamp'\n", - "# 'exp_time'\n", - "# 'flux'\n", - "# 'flux_unc'\n", - "# 'flux_format'\n", - "# 'filter_name'\n", - "\n", - "# and in additon, the observatory latitude and longitude:\n", - "# 'observatory_latitude'\n", - "# 'observatory_longitude'\n", - "\n", - "plt.figure()\n", - "plt.ylabel('flux')\n", - "plt.xlabel('time')\n", - "plt.errorbar(data['time'], data['flux'], data['flux_unc'], fmt='o')\n", - "\n", - "for i in ['time_format', 'time_stamp', 'exp_time', 'flux_format', 'filter_name', \n", - " 'observatory_latitude', 'observatory_longitude']:\n", - " print('{0}: {1}'.format(i, data[i]))\n", - " \n", - "###############################################################################################\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "###############################################################################################\n", - "##### Define the trend function\n", - "###############################################################################################\n", - "\n", - "# By default, the detrending is done using a second order polynomial with time.\n", - "# Here, since the dataset contains the observatory location, \n", - "# we can use a the airmass as a detrending series.\n", - "# We will try as a trend function a fisrt order polynomial with airmass:\n", - "\n", - "data['detrending_series'] = 'airmass'\n", - "data['detrending_order'] = 1\n", - "\n", - "###############################################################################################\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "###############################################################################################\n", - "##### Define the stellar model\n", - "###############################################################################################\n", - "\n", - "# The default stellar model used to calculate the limb-darkening coefficients \n", - "# is the 'Pheonix_2018'. Here, we will not change this.\n", - "\n", - "###############################################################################################\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "###############################################################################################\n", - "##### Add observation to the Planet object\n", - "###############################################################################################\n", - "\n", - "# Then we are going to add the observation to the Planet object.\n", - "# It is advised to use planet.clear_observations() before, \n", - "# to avoid duplications, in case we forget that we have already added the same observation.\n", - "\n", - "planet.clear_observations()\n", - "planet.add_observation_from_dict(data)\n", - "\n", - "###############################################################################################\n" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "id": "fc4fcb81", - "metadata": { - "scrolled": false - }, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "WARNING:root:\n", - "PHOENIX models are only computed for solar metallicity stars. Setting stellar_metallicity = 0.\n", - "\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "File already here... teff05400_logg4.00_MH0.0.pickle\n", - "File already here... teff05400_logg4.50_MH0.0.pickle\n", - "\n", - "Observation: obs0\n", - "Filter: luminance\n", - "Epoch: 603\n", - "Data-points excluded: 0\n", - "Scaling uncertainties by: 1\n", - "\n", - "Optimising initial parameters...\n", - "Transit fitting...\n" - ] - }, - { - "data": { - "application/javascript": [ - "/* Put everything inside the global mpl namespace */\n", - "/* global mpl */\n", - "window.mpl = {};\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(\n", - " '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", - "\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 = document.createElement('div');\n", - " this.root.setAttribute('style', 'display: inline-block');\n", - " this._root_extra_style(this.root);\n", - "\n", - " parent_element.appendChild(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 (fig.ratio !== 1) {\n", - " fig.send_message('set_device_pixel_ratio', {\n", - " device_pixel_ratio: fig.ratio,\n", - " });\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 = document.createElement('div');\n", - " titlebar.classList =\n", - " 'ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix';\n", - " var titletext = document.createElement('div');\n", - " titletext.classList = 'ui-dialog-title';\n", - " titletext.setAttribute(\n", - " 'style',\n", - " 'width: 100%; text-align: center; padding: 3px;'\n", - " );\n", - " titlebar.appendChild(titletext);\n", - " this.root.appendChild(titlebar);\n", - " this.header = titletext;\n", - "};\n", - "\n", - "mpl.figure.prototype._canvas_extra_style = function (_canvas_div) {};\n", - "\n", - "mpl.figure.prototype._root_extra_style = function (_canvas_div) {};\n", - "\n", - "mpl.figure.prototype._init_canvas = function () {\n", - " var fig = this;\n", - "\n", - " var canvas_div = (this.canvas_div = document.createElement('div'));\n", - " canvas_div.setAttribute('tabindex', '0');\n", - " canvas_div.setAttribute(\n", - " 'style',\n", - " 'border: 1px solid #ddd;' +\n", - " 'box-sizing: content-box;' +\n", - " 'clear: both;' +\n", - " 'min-height: 1px;' +\n", - " 'min-width: 1px;' +\n", - " 'outline: 0;' +\n", - " 'overflow: hidden;' +\n", - " 'position: relative;' +\n", - " 'resize: both;' +\n", - " 'z-index: 2;'\n", - " );\n", - "\n", - " function on_keyboard_event_closure(name) {\n", - " return function (event) {\n", - " return fig.key_event(event, name);\n", - " };\n", - " }\n", - "\n", - " canvas_div.addEventListener(\n", - " 'keydown',\n", - " on_keyboard_event_closure('key_press')\n", - " );\n", - " canvas_div.addEventListener(\n", - " 'keyup',\n", - " on_keyboard_event_closure('key_release')\n", - " );\n", - "\n", - " this._canvas_extra_style(canvas_div);\n", - " this.root.appendChild(canvas_div);\n", - "\n", - " var canvas = (this.canvas = document.createElement('canvas'));\n", - " canvas.classList.add('mpl-canvas');\n", - " canvas.setAttribute(\n", - " 'style',\n", - " 'box-sizing: content-box;' +\n", - " 'pointer-events: none;' +\n", - " 'position: relative;' +\n", - " 'z-index: 0;'\n", - " );\n", - "\n", - " this.context = canvas.getContext('2d');\n", - "\n", - " var backingStore =\n", - " this.context.backingStorePixelRatio ||\n", - " this.context.webkitBackingStorePixelRatio ||\n", - " this.context.mozBackingStorePixelRatio ||\n", - " this.context.msBackingStorePixelRatio ||\n", - " this.context.oBackingStorePixelRatio ||\n", - " this.context.backingStorePixelRatio ||\n", - " 1;\n", - "\n", - " this.ratio = (window.devicePixelRatio || 1) / backingStore;\n", - "\n", - " var rubberband_canvas = (this.rubberband_canvas = document.createElement(\n", - " 'canvas'\n", - " ));\n", - " rubberband_canvas.setAttribute(\n", - " 'style',\n", - " 'box-sizing: content-box;' +\n", - " 'left: 0;' +\n", - " 'pointer-events: none;' +\n", - " 'position: absolute;' +\n", - " 'top: 0;' +\n", - " 'z-index: 1;'\n", - " );\n", - "\n", - " // Apply a ponyfill if ResizeObserver is not implemented by browser.\n", - " if (this.ResizeObserver === undefined) {\n", - " if (window.ResizeObserver !== undefined) {\n", - " this.ResizeObserver = window.ResizeObserver;\n", - " } else {\n", - " var obs = _JSXTOOLS_RESIZE_OBSERVER({});\n", - " this.ResizeObserver = obs.ResizeObserver;\n", - " }\n", - " }\n", - "\n", - " this.resizeObserverInstance = new this.ResizeObserver(function (entries) {\n", - " // There's no need to resize if the WebSocket is not connected:\n", - " // - If it is still connecting, then we will get an initial resize from\n", - " // Python once it connects.\n", - " // - If it has disconnected, then resizing will clear the canvas and\n", - " // never get anything back to refill it, so better to not resize and\n", - " // keep something visible.\n", - " if (fig.ws.readyState != 1) {\n", - " return;\n", - " }\n", - " var nentries = entries.length;\n", - " for (var i = 0; i < nentries; i++) {\n", - " var entry = entries[i];\n", - " var width, height;\n", - " if (entry.contentBoxSize) {\n", - " if (entry.contentBoxSize instanceof Array) {\n", - " // Chrome 84 implements new version of spec.\n", - " width = entry.contentBoxSize[0].inlineSize;\n", - " height = entry.contentBoxSize[0].blockSize;\n", - " } else {\n", - " // Firefox implements old version of spec.\n", - " width = entry.contentBoxSize.inlineSize;\n", - " height = entry.contentBoxSize.blockSize;\n", - " }\n", - " } else {\n", - " // Chrome <84 implements even older version of spec.\n", - " width = entry.contentRect.width;\n", - " height = entry.contentRect.height;\n", - " }\n", - "\n", - " // Keep the size of the canvas and rubber band canvas in sync with\n", - " // the canvas container.\n", - " if (entry.devicePixelContentBoxSize) {\n", - " // Chrome 84 implements new version of spec.\n", - " canvas.setAttribute(\n", - " 'width',\n", - " entry.devicePixelContentBoxSize[0].inlineSize\n", - " );\n", - " canvas.setAttribute(\n", - " 'height',\n", - " entry.devicePixelContentBoxSize[0].blockSize\n", - " );\n", - " } else {\n", - " canvas.setAttribute('width', width * fig.ratio);\n", - " canvas.setAttribute('height', height * fig.ratio);\n", - " }\n", - " /* This rescales the canvas back to display pixels, so that it\n", - " * appears correct on HiDPI screens. */\n", - " canvas.style.width = width + 'px';\n", - " canvas.style.height = height + 'px';\n", - "\n", - " rubberband_canvas.setAttribute('width', width);\n", - " rubberband_canvas.setAttribute('height', height);\n", - "\n", - " // And update the size in Python. We ignore the initial 0/0 size\n", - " // that occurs as the element is placed into the DOM, which should\n", - " // otherwise not happen due to the minimum size styling.\n", - " if (width != 0 && height != 0) {\n", - " fig.request_resize(width, height);\n", - " }\n", - " }\n", - " });\n", - " this.resizeObserverInstance.observe(canvas_div);\n", - "\n", - " function on_mouse_event_closure(name) {\n", - " /* User Agent sniffing is bad, but WebKit is busted:\n", - " * https://bugs.webkit.org/show_bug.cgi?id=144526\n", - " * https://bugs.webkit.org/show_bug.cgi?id=181818\n", - " * The worst that happens here is that they get an extra browser\n", - " * selection when dragging, if this check fails to catch them.\n", - " */\n", - " var UA = navigator.userAgent;\n", - " var isWebKit = /AppleWebKit/.test(UA) && !/Chrome/.test(UA);\n", - " if(isWebKit) {\n", - " return function (event) {\n", - " /* This prevents the web browser from automatically changing to\n", - " * the text insertion cursor when the button is pressed. We\n", - " * want to control all of the cursor setting manually through\n", - " * the 'cursor' event from matplotlib */\n", - " event.preventDefault()\n", - " return fig.mouse_event(event, name);\n", - " };\n", - " } else {\n", - " return function (event) {\n", - " return fig.mouse_event(event, name);\n", - " };\n", - " }\n", - " }\n", - "\n", - " canvas_div.addEventListener(\n", - " 'mousedown',\n", - " on_mouse_event_closure('button_press')\n", - " );\n", - " canvas_div.addEventListener(\n", - " 'mouseup',\n", - " on_mouse_event_closure('button_release')\n", - " );\n", - " canvas_div.addEventListener(\n", - " 'dblclick',\n", - " on_mouse_event_closure('dblclick')\n", - " );\n", - " // Throttle sequential mouse events to 1 every 20ms.\n", - " canvas_div.addEventListener(\n", - " 'mousemove',\n", - " on_mouse_event_closure('motion_notify')\n", - " );\n", - "\n", - " canvas_div.addEventListener(\n", - " 'mouseenter',\n", - " on_mouse_event_closure('figure_enter')\n", - " );\n", - " canvas_div.addEventListener(\n", - " 'mouseleave',\n", - " on_mouse_event_closure('figure_leave')\n", - " );\n", - "\n", - " canvas_div.addEventListener('wheel', function (event) {\n", - " if (event.deltaY < 0) {\n", - " event.step = 1;\n", - " } else {\n", - " event.step = -1;\n", - " }\n", - " on_mouse_event_closure('scroll')(event);\n", - " });\n", - "\n", - " canvas_div.appendChild(canvas);\n", - " canvas_div.appendChild(rubberband_canvas);\n", - "\n", - " this.rubberband_context = rubberband_canvas.getContext('2d');\n", - " this.rubberband_context.strokeStyle = '#000000';\n", - "\n", - " this._resize_canvas = function (width, height, forward) {\n", - " if (forward) {\n", - " canvas_div.style.width = width + 'px';\n", - " canvas_div.style.height = height + 'px';\n", - " }\n", - " };\n", - "\n", - " // Disable right mouse context menu.\n", - " canvas_div.addEventListener('contextmenu', function (_e) {\n", - " event.preventDefault();\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 toolbar = document.createElement('div');\n", - " toolbar.classList = 'mpl-toolbar';\n", - " this.root.appendChild(toolbar);\n", - "\n", - " function on_click_closure(name) {\n", - " return function (_event) {\n", - " return fig.toolbar_button_onclick(name);\n", - " };\n", - " }\n", - "\n", - " function on_mouseover_closure(tooltip) {\n", - " return function (event) {\n", - " if (!event.currentTarget.disabled) {\n", - " return fig.toolbar_button_onmouseover(tooltip);\n", - " }\n", - " };\n", - " }\n", - "\n", - " fig.buttons = {};\n", - " var buttonGroup = document.createElement('div');\n", - " buttonGroup.classList = 'mpl-button-group';\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", - " /* Instead of a spacer, we start a new button group. */\n", - " if (buttonGroup.hasChildNodes()) {\n", - " toolbar.appendChild(buttonGroup);\n", - " }\n", - " buttonGroup = document.createElement('div');\n", - " buttonGroup.classList = 'mpl-button-group';\n", - " continue;\n", - " }\n", - "\n", - " var button = (fig.buttons[name] = document.createElement('button'));\n", - " button.classList = 'mpl-widget';\n", - " button.setAttribute('role', 'button');\n", - " button.setAttribute('aria-disabled', 'false');\n", - " button.addEventListener('click', on_click_closure(method_name));\n", - " button.addEventListener('mouseover', on_mouseover_closure(tooltip));\n", - "\n", - " var icon_img = document.createElement('img');\n", - " icon_img.src = '_images/' + image + '.png';\n", - " icon_img.srcset = '_images/' + image + '_large.png 2x';\n", - " icon_img.alt = tooltip;\n", - " button.appendChild(icon_img);\n", - "\n", - " buttonGroup.appendChild(button);\n", - " }\n", - "\n", - " if (buttonGroup.hasChildNodes()) {\n", - " toolbar.appendChild(buttonGroup);\n", - " }\n", - "\n", - " var fmt_picker = document.createElement('select');\n", - " fmt_picker.classList = 'mpl-widget';\n", - " toolbar.appendChild(fmt_picker);\n", - " this.format_dropdown = fmt_picker;\n", - "\n", - " for (var ind in mpl.extensions) {\n", - " var fmt = mpl.extensions[ind];\n", - " var option = document.createElement('option');\n", - " option.selected = fmt === mpl.default_extension;\n", - " option.innerHTML = fmt;\n", - " fmt_picker.appendChild(option);\n", - " }\n", - "\n", - " var status_bar = document.createElement('span');\n", - " status_bar.classList = 'mpl-message';\n", - " toolbar.appendChild(status_bar);\n", - " this.message = status_bar;\n", - "};\n", - "\n", - "mpl.figure.prototype.request_resize = function (x_pixels, y_pixels) {\n", - " // Request matplotlib to resize the figure. Matplotlib will then trigger a resize in the client,\n", - " // which will in turn request a refresh of the image.\n", - " this.send_message('resize', { width: x_pixels, height: y_pixels });\n", - "};\n", - "\n", - "mpl.figure.prototype.send_message = function (type, properties) {\n", - " properties['type'] = type;\n", - " properties['figure_id'] = this.id;\n", - " this.ws.send(JSON.stringify(properties));\n", - "};\n", - "\n", - "mpl.figure.prototype.send_draw_message = function () {\n", - " if (!this.waiting) {\n", - " this.waiting = true;\n", - " this.ws.send(JSON.stringify({ type: 'draw', figure_id: this.id }));\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_save = function (fig, _msg) {\n", - " var format_dropdown = fig.format_dropdown;\n", - " var format = format_dropdown.options[format_dropdown.selectedIndex].value;\n", - " fig.ondownload(fig, format);\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_resize = function (fig, msg) {\n", - " var size = msg['size'];\n", - " if (size[0] !== fig.canvas.width || size[1] !== fig.canvas.height) {\n", - " fig._resize_canvas(size[0], size[1], msg['forward']);\n", - " fig.send_message('refresh', {});\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_rubberband = function (fig, msg) {\n", - " var x0 = msg['x0'] / fig.ratio;\n", - " var y0 = (fig.canvas.height - msg['y0']) / fig.ratio;\n", - " var x1 = msg['x1'] / fig.ratio;\n", - " var y1 = (fig.canvas.height - msg['y1']) / fig.ratio;\n", - " x0 = Math.floor(x0) + 0.5;\n", - " y0 = Math.floor(y0) + 0.5;\n", - " x1 = Math.floor(x1) + 0.5;\n", - " y1 = Math.floor(y1) + 0.5;\n", - " var min_x = Math.min(x0, x1);\n", - " var min_y = Math.min(y0, y1);\n", - " var width = Math.abs(x1 - x0);\n", - " var height = Math.abs(y1 - y0);\n", - "\n", - " fig.rubberband_context.clearRect(\n", - " 0,\n", - " 0,\n", - " fig.canvas.width / fig.ratio,\n", - " fig.canvas.height / fig.ratio\n", - " );\n", - "\n", - " fig.rubberband_context.strokeRect(min_x, min_y, width, height);\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_figure_label = function (fig, msg) {\n", - " // Updates the figure title.\n", - " fig.header.textContent = msg['label'];\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_cursor = function (fig, msg) {\n", - " fig.canvas_div.style.cursor = msg['cursor'];\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_message = function (fig, msg) {\n", - " fig.message.textContent = msg['message'];\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_draw = function (fig, _msg) {\n", - " // Request the server to send over a new figure.\n", - " fig.send_draw_message();\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_image_mode = function (fig, msg) {\n", - " fig.image_mode = msg['mode'];\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_history_buttons = function (fig, msg) {\n", - " for (var key in msg) {\n", - " if (!(key in fig.buttons)) {\n", - " continue;\n", - " }\n", - " fig.buttons[key].disabled = !msg[key];\n", - " fig.buttons[key].setAttribute('aria-disabled', !msg[key]);\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_navigate_mode = function (fig, msg) {\n", - " if (msg['mode'] === 'PAN') {\n", - " fig.buttons['Pan'].classList.add('active');\n", - " fig.buttons['Zoom'].classList.remove('active');\n", - " } else if (msg['mode'] === 'ZOOM') {\n", - " fig.buttons['Pan'].classList.remove('active');\n", - " fig.buttons['Zoom'].classList.add('active');\n", - " } else {\n", - " fig.buttons['Pan'].classList.remove('active');\n", - " fig.buttons['Zoom'].classList.remove('active');\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.updated_canvas_event = function () {\n", - " // Called whenever the canvas gets updated.\n", - " this.send_message('ack', {});\n", - "};\n", - "\n", - "// A function to construct a web socket function for onmessage handling.\n", - "// Called in the figure constructor.\n", - "mpl.figure.prototype._make_on_message_function = function (fig) {\n", - " return function socket_on_message(evt) {\n", - " if (evt.data instanceof Blob) {\n", - " var img = evt.data;\n", - " if (img.type !== 'image/png') {\n", - " /* FIXME: We get \"Resource interpreted as Image but\n", - " * transferred with MIME type text/plain:\" errors on\n", - " * Chrome. But how to set the MIME type? It doesn't seem\n", - " * to be part of the websocket stream */\n", - " img.type = 'image/png';\n", - " }\n", - "\n", - " /* Free the memory for the previous frames */\n", - " if (fig.imageObj.src) {\n", - " (window.URL || window.webkitURL).revokeObjectURL(\n", - " fig.imageObj.src\n", - " );\n", - " }\n", - "\n", - " fig.imageObj.src = (window.URL || window.webkitURL).createObjectURL(\n", - " img\n", - " );\n", - " fig.updated_canvas_event();\n", - " fig.waiting = false;\n", - " return;\n", - " } else if (\n", - " typeof evt.data === 'string' &&\n", - " evt.data.slice(0, 21) === 'data:image/png;base64'\n", - " ) {\n", - " fig.imageObj.src = evt.data;\n", - " fig.updated_canvas_event();\n", - " fig.waiting = false;\n", - " return;\n", - " }\n", - "\n", - " var msg = JSON.parse(evt.data);\n", - " var msg_type = msg['type'];\n", - "\n", - " // Call the \"handle_{type}\" callback, which takes\n", - " // the figure and JSON message as its only arguments.\n", - " try {\n", - " var callback = fig['handle_' + msg_type];\n", - " } catch (e) {\n", - " console.log(\n", - " \"No handler for the '\" + msg_type + \"' message type: \",\n", - " msg\n", - " );\n", - " return;\n", - " }\n", - "\n", - " if (callback) {\n", - " try {\n", - " // console.log(\"Handling '\" + msg_type + \"' message: \", msg);\n", - " callback(fig, msg);\n", - " } catch (e) {\n", - " console.log(\n", - " \"Exception inside the 'handler_\" + msg_type + \"' callback:\",\n", - " e,\n", - " e.stack,\n", - " msg\n", - " );\n", - " }\n", - " }\n", - " };\n", - "};\n", - "\n", - "function getModifiers(event) {\n", - " var mods = [];\n", - " if (event.ctrlKey) {\n", - " mods.push('ctrl');\n", - " }\n", - " if (event.altKey) {\n", - " mods.push('alt');\n", - " }\n", - " if (event.shiftKey) {\n", - " mods.push('shift');\n", - " }\n", - " if (event.metaKey) {\n", - " mods.push('meta');\n", - " }\n", - " return mods;\n", - "}\n", - "\n", - "/*\n", - " * return a copy of an object with only non-object keys\n", - " * we need this to avoid circular references\n", - " * https://stackoverflow.com/a/24161582/3208463\n", - " */\n", - "function simpleKeys(original) {\n", - " return Object.keys(original).reduce(function (obj, key) {\n", - " if (typeof original[key] !== 'object') {\n", - " obj[key] = original[key];\n", - " }\n", - " return obj;\n", - " }, {});\n", - "}\n", - "\n", - "mpl.figure.prototype.mouse_event = function (event, name) {\n", - " if (name === 'button_press') {\n", - " this.canvas.focus();\n", - " this.canvas_div.focus();\n", - " }\n", - "\n", - " // from https://stackoverflow.com/q/1114465\n", - " var boundingRect = this.canvas.getBoundingClientRect();\n", - " var x = (event.clientX - boundingRect.left) * this.ratio;\n", - " var y = (event.clientY - boundingRect.top) * this.ratio;\n", - "\n", - " this.send_message(name, {\n", - " x: x,\n", - " y: y,\n", - " button: event.button,\n", - " step: event.step,\n", - " modifiers: getModifiers(event),\n", - " guiEvent: simpleKeys(event),\n", - " });\n", - "\n", - " return false;\n", - "};\n", - "\n", - "mpl.figure.prototype._key_event_extra = function (_event, _name) {\n", - " // Handle any extra behaviour associated with a key event\n", - "};\n", - "\n", - "mpl.figure.prototype.key_event = function (event, name) {\n", - " // Prevent repeat events\n", - " if (name === 'key_press') {\n", - " if (event.key === this._key) {\n", - " return;\n", - " } else {\n", - " this._key = event.key;\n", - " }\n", - " }\n", - " if (name === 'key_release') {\n", - " this._key = null;\n", - " }\n", - "\n", - " var value = '';\n", - " if (event.ctrlKey && event.key !== 'Control') {\n", - " value += 'ctrl+';\n", - " }\n", - " else if (event.altKey && event.key !== 'Alt') {\n", - " value += 'alt+';\n", - " }\n", - " else if (event.shiftKey && event.key !== 'Shift') {\n", - " value += 'shift+';\n", - " }\n", - "\n", - " value += 'k' + event.key;\n", - "\n", - " this._key_event_extra(event, name);\n", - "\n", - " this.send_message(name, { key: value, guiEvent: simpleKeys(event) });\n", - " return false;\n", - "};\n", - "\n", - "mpl.figure.prototype.toolbar_button_onclick = function (name) {\n", - " if (name === 'download') {\n", - " this.handle_save(this, null);\n", - " } else {\n", - " this.send_message('toolbar_button', { name: name });\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.toolbar_button_onmouseover = function (tooltip) {\n", - " this.message.textContent = tooltip;\n", - "};\n", - "\n", - "///////////////// REMAINING CONTENT GENERATED BY embed_js.py /////////////////\n", - "// prettier-ignore\n", - "var _JSXTOOLS_RESIZE_OBSERVER=function(A){var t,i=new WeakMap,n=new WeakMap,a=new WeakMap,r=new WeakMap,o=new Set;function s(e){if(!(this instanceof s))throw new TypeError(\"Constructor requires 'new' operator\");i.set(this,e)}function h(){throw new TypeError(\"Function is not a constructor\")}function c(e,t,i,n){e=0 in arguments?Number(arguments[0]):0,t=1 in arguments?Number(arguments[1]):0,i=2 in arguments?Number(arguments[2]):0,n=3 in arguments?Number(arguments[3]):0,this.right=(this.x=this.left=e)+(this.width=i),this.bottom=(this.y=this.top=t)+(this.height=n),Object.freeze(this)}function d(){t=requestAnimationFrame(d);var s=new WeakMap,p=new Set;o.forEach((function(t){r.get(t).forEach((function(i){var r=t instanceof window.SVGElement,o=a.get(t),d=r?0:parseFloat(o.paddingTop),f=r?0:parseFloat(o.paddingRight),l=r?0:parseFloat(o.paddingBottom),u=r?0:parseFloat(o.paddingLeft),g=r?0:parseFloat(o.borderTopWidth),m=r?0:parseFloat(o.borderRightWidth),w=r?0:parseFloat(o.borderBottomWidth),b=u+f,F=d+l,v=(r?0:parseFloat(o.borderLeftWidth))+m,W=g+w,y=r?0:t.offsetHeight-W-t.clientHeight,E=r?0:t.offsetWidth-v-t.clientWidth,R=b+v,z=F+W,M=r?t.width:parseFloat(o.width)-R-E,O=r?t.height:parseFloat(o.height)-z-y;if(n.has(t)){var k=n.get(t);if(k[0]===M&&k[1]===O)return}n.set(t,[M,O]);var S=Object.create(h.prototype);S.target=t,S.contentRect=new c(u,d,M,O),s.has(i)||(s.set(i,[]),p.add(i)),s.get(i).push(S)}))})),p.forEach((function(e){i.get(e).call(e,s.get(e),e)}))}return s.prototype.observe=function(i){if(i instanceof window.Element){r.has(i)||(r.set(i,new Set),o.add(i),a.set(i,window.getComputedStyle(i)));var n=r.get(i);n.has(this)||n.add(this),cancelAnimationFrame(t),t=requestAnimationFrame(d)}},s.prototype.unobserve=function(i){if(i instanceof window.Element&&r.has(i)){var n=r.get(i);n.has(this)&&(n.delete(this),n.size||(r.delete(i),o.delete(i))),n.size||r.delete(i),o.size||cancelAnimationFrame(t)}},A.DOMRectReadOnly=c,A.ResizeObserver=s,A.ResizeObserverEntry=h,A}; // eslint-disable-line\n", - "mpl.toolbar_items = [[\"Home\", \"Reset original view\", \"fa fa-home\", \"home\"], [\"Back\", \"Back to previous view\", \"fa fa-arrow-left\", \"back\"], [\"Forward\", \"Forward to next view\", \"fa fa-arrow-right\", \"forward\"], [\"\", \"\", \"\", \"\"], [\"Pan\", \"Left button pans, Right button zooms\\nx/y fixes axis, CTRL fixes aspect\", \"fa fa-arrows\", \"pan\"], [\"Zoom\", \"Zoom to rectangle\\nx/y fixes axis\", \"fa fa-square-o\", \"zoom\"], [\"\", \"\", \"\", \"\"], [\"Download\", \"Download plot\", \"fa fa-floppy-o\", \"download\"]];\n", - "\n", - "mpl.extensions = [\"eps\", \"jpeg\", \"pgf\", \"pdf\", \"png\", \"ps\", \"raw\", \"svg\", \"tif\", \"webp\"];\n", - "\n", - "mpl.default_extension = \"png\";/* global mpl */\n", - "\n", - "var comm_websocket_adapter = function (comm) {\n", - " // Create a \"websocket\"-like object which calls the given IPython comm\n", - " // object with the appropriate methods. Currently this is a non binary\n", - " // socket, so there is still some room for performance tuning.\n", - " var ws = {};\n", - "\n", - " ws.binaryType = comm.kernel.ws.binaryType;\n", - " ws.readyState = comm.kernel.ws.readyState;\n", - " function updateReadyState(_event) {\n", - " if (comm.kernel.ws) {\n", - " ws.readyState = comm.kernel.ws.readyState;\n", - " } else {\n", - " ws.readyState = 3; // Closed state.\n", - " }\n", - " }\n", - " comm.kernel.ws.addEventListener('open', updateReadyState);\n", - " comm.kernel.ws.addEventListener('close', updateReadyState);\n", - " comm.kernel.ws.addEventListener('error', updateReadyState);\n", - "\n", - " ws.close = function () {\n", - " comm.close();\n", - " };\n", - " ws.send = function (m) {\n", - " //console.log('sending', m);\n", - " comm.send(m);\n", - " };\n", - " // Register the callback with on_msg.\n", - " comm.on_msg(function (msg) {\n", - " //console.log('receiving', msg['content']['data'], msg);\n", - " var data = msg['content']['data'];\n", - " if (data['blob'] !== undefined) {\n", - " data = {\n", - " data: new Blob(msg['buffers'], { type: data['blob'] }),\n", - " };\n", - " }\n", - " // Pass the mpl event to the overridden (by mpl) onmessage function.\n", - " ws.onmessage(data);\n", - " });\n", - " return ws;\n", - "};\n", - "\n", - "mpl.mpl_figure_comm = function (comm, msg) {\n", - " // This is the function which gets called when the mpl process\n", - " // starts-up an IPython Comm through the \"matplotlib\" channel.\n", - "\n", - " var id = msg.content.data.id;\n", - " // Get hold of the div created by the display call when the Comm\n", - " // socket was opened in Python.\n", - " var element = document.getElementById(id);\n", - " var ws_proxy = comm_websocket_adapter(comm);\n", - "\n", - " function ondownload(figure, _format) {\n", - " window.open(figure.canvas.toDataURL());\n", - " }\n", - "\n", - " var fig = new mpl.figure(id, ws_proxy, ondownload, element);\n", - "\n", - " // Call onopen now - mpl needs it, as it is assuming we've passed it a real\n", - " // web socket which is closed, not our websocket->open comm proxy.\n", - " ws_proxy.onopen();\n", - "\n", - " fig.parent_element = element;\n", - " fig.cell_info = mpl.find_output_cell(\"
\");\n", - " if (!fig.cell_info) {\n", - " console.error('Failed to find cell for figure', id, fig);\n", - " return;\n", - " }\n", - " fig.cell_info[0].output_area.element.on(\n", - " 'cleared',\n", - " { fig: fig },\n", - " fig._remove_fig_handler\n", - " );\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_close = function (fig, msg) {\n", - " var width = fig.canvas.width / fig.ratio;\n", - " fig.cell_info[0].output_area.element.off(\n", - " 'cleared',\n", - " fig._remove_fig_handler\n", - " );\n", - " fig.resizeObserverInstance.unobserve(fig.canvas_div);\n", - "\n", - " // Update the output cell to use the data from the current canvas.\n", - " fig.push_to_output();\n", - " var dataURL = fig.canvas.toDataURL();\n", - " // Re-enable the keyboard manager in IPython - without this line, in FF,\n", - " // the notebook keyboard shortcuts fail.\n", - " IPython.keyboard_manager.enable();\n", - " fig.parent_element.innerHTML =\n", - " '';\n", - " fig.close_ws(fig, msg);\n", - "};\n", - "\n", - "mpl.figure.prototype.close_ws = function (fig, msg) {\n", - " fig.send_message('closing', msg);\n", - " // fig.ws.close()\n", - "};\n", - "\n", - "mpl.figure.prototype.push_to_output = function (_remove_interactive) {\n", - " // Turn the data on the canvas into data in the output cell.\n", - " var width = this.canvas.width / this.ratio;\n", - " var dataURL = this.canvas.toDataURL();\n", - " this.cell_info[1]['text/html'] =\n", - " '';\n", - "};\n", - "\n", - "mpl.figure.prototype.updated_canvas_event = function () {\n", - " // Tell IPython that the notebook contents must change.\n", - " IPython.notebook.set_dirty(true);\n", - " this.send_message('ack', {});\n", - " var fig = this;\n", - " // Wait a second, then push the new image to the DOM so\n", - " // that it is saved nicely (might be nice to debounce this).\n", - " setTimeout(function () {\n", - " fig.push_to_output();\n", - " }, 1000);\n", - "};\n", - "\n", - "mpl.figure.prototype._init_toolbar = function () {\n", - " var fig = this;\n", - "\n", - " var toolbar = document.createElement('div');\n", - " toolbar.classList = 'btn-toolbar';\n", - " this.root.appendChild(toolbar);\n", - "\n", - " function on_click_closure(name) {\n", - " return function (_event) {\n", - " return fig.toolbar_button_onclick(name);\n", - " };\n", - " }\n", - "\n", - " function on_mouseover_closure(tooltip) {\n", - " return function (event) {\n", - " if (!event.currentTarget.disabled) {\n", - " return fig.toolbar_button_onmouseover(tooltip);\n", - " }\n", - " };\n", - " }\n", - "\n", - " fig.buttons = {};\n", - " var buttonGroup = document.createElement('div');\n", - " buttonGroup.classList = 'btn-group';\n", - " var button;\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", - " /* Instead of a spacer, we start a new button group. */\n", - " if (buttonGroup.hasChildNodes()) {\n", - " toolbar.appendChild(buttonGroup);\n", - " }\n", - " buttonGroup = document.createElement('div');\n", - " buttonGroup.classList = 'btn-group';\n", - " continue;\n", - " }\n", - "\n", - " button = fig.buttons[name] = document.createElement('button');\n", - " button.classList = 'btn btn-default';\n", - " button.href = '#';\n", - " button.title = name;\n", - " button.innerHTML = '';\n", - " button.addEventListener('click', on_click_closure(method_name));\n", - " button.addEventListener('mouseover', on_mouseover_closure(tooltip));\n", - " buttonGroup.appendChild(button);\n", - " }\n", - "\n", - " if (buttonGroup.hasChildNodes()) {\n", - " toolbar.appendChild(buttonGroup);\n", - " }\n", - "\n", - " // Add the status bar.\n", - " var status_bar = document.createElement('span');\n", - " status_bar.classList = 'mpl-message pull-right';\n", - " toolbar.appendChild(status_bar);\n", - " this.message = status_bar;\n", - "\n", - " // Add the close button to the window.\n", - " var buttongrp = document.createElement('div');\n", - " buttongrp.classList = 'btn-group inline pull-right';\n", - " button = document.createElement('button');\n", - " button.classList = 'btn btn-mini btn-primary';\n", - " button.href = '#';\n", - " button.title = 'Stop Interaction';\n", - " button.innerHTML = '';\n", - " button.addEventListener('click', function (_evt) {\n", - " fig.handle_close(fig, {});\n", - " });\n", - " button.addEventListener(\n", - " 'mouseover',\n", - " on_mouseover_closure('Stop Interaction')\n", - " );\n", - " buttongrp.appendChild(button);\n", - " var titlebar = this.root.querySelector('.ui-dialog-titlebar');\n", - " titlebar.insertBefore(buttongrp, titlebar.firstChild);\n", - "};\n", - "\n", - "mpl.figure.prototype._remove_fig_handler = function (event) {\n", - " var fig = event.data.fig;\n", - " if (event.target !== this) {\n", - " // Ignore bubbled events from children.\n", - " return;\n", - " }\n", - " fig.close_ws(fig, {});\n", - "};\n", - "\n", - "mpl.figure.prototype._root_extra_style = function (el) {\n", - " el.style.boxSizing = 'content-box'; // override notebook setting of border-box.\n", - "};\n", - "\n", - "mpl.figure.prototype._canvas_extra_style = function (el) {\n", - " // this is important to make the div 'focusable\n", - " el.setAttribute('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", - " } else {\n", - " // location in version 2\n", - " IPython.keyboard_manager.register_events(el);\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype._key_event_extra = function (event, _name) {\n", - " // Check for shift+enter\n", - " if (event.shiftKey && event.which === 13) {\n", - " this.canvas_div.blur();\n", - " // select the cell after this one\n", - " var index = IPython.notebook.find_cell_index(this.cell_info[0]);\n", - " IPython.notebook.select(index + 1);\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_save = function (fig, _msg) {\n", - " fig.ondownload(fig, null);\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 < ncells; i++) {\n", - " var cell = cells[i];\n", - " if (cell.cell_type === 'code') {\n", - " for (var j = 0; j < cell.output_area.outputs.length; j++) {\n", - " var data = cell.output_area.outputs[j];\n", - " if (data.data) {\n", - " // IPython >= 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(\n", - " 'matplotlib',\n", - " mpl.mpl_figure_comm\n", - " );\n", - "}\n" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/html": [ - "
" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "Observation: obs0\n", - "Filter: luminance\n", - "Epoch: 603\n", - "Number of outliers removed: 0\n", - "Uncertainties scale factor: 1\n", - "Residuals statistics:\n", - "res_max_autocorr: \t 0.1914507839556266\n", - "res_max_autocorr_flag: \t False\n", - "res_shapiro: \t\t 0.9895082116127014\n", - "res_shapiro_flag: \t False\n", - "res_mean: \t\t 5.0708944461451895e-06\n", - "res_std: \t\t 0.0005407573751613006\n", - "res_rms: \t\t 0.0005407811505237803\n", - "res_chi_sqr: \t\t 258.6627876799993\n", - "res_red_chi_sqr: \t 1.1651476922522492\n" - ] - } - ], - "source": [ - "\n", - "###############################################################################################\n", - "##### Test the performance of the trend function \n", - "###############################################################################################\n", - "\n", - "# We can test the performance of the trend function with quick fit, using: \n", - "# optimiser = 'curve_fit'.\n", - "\n", - "test = planet.transit_fitting(\n", - " optimiser = 'curve_fit',\n", - ")\n", - "\n", - "###############################################################################################\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "###############################################################################################\n", - "##### Evaluate test results\n", - "###############################################################################################\n", - "\n", - "# To evaluate the test results we can plot the raw data, trend function, and residuals like this:\n", - "\n", - "observations = len(test['observations'])\n", - "plt.figure(figsize=(9,6))\n", - "for obs_n, obs_id in enumerate(test['observations']):\n", - " observation = test['observations'][obs_id]\n", - " plt.subplot(2, observations, obs_n + 1)\n", - " plt.errorbar(observation['input_series']['time'], \n", - " observation['input_series']['flux'], \n", - " observation['input_series']['flux_unc'], \n", - " fmt='o', zorder=0, label='raw data')\n", - " plt.plot(observation['input_series']['time'], observation['output_series']['trend'], 'r--', zorder=1, \n", - " label='trend model')\n", - " plt.plot(observation['input_series']['time'], observation['output_series']['model'], 'r-', zorder=1,\n", - " label='trend + transit model'\n", - " )\n", - " plt.legend(fontsize='small')\n", - " plt.ylabel('rel. flux')\n", - " plt.title(obs_id)\n", - "\n", - " plt.subplot(2, observations, observations + 1)\n", - " plt.errorbar(observation['input_series']['time'], \n", - " observation['output_series']['residuals'], \n", - " observation['input_series']['flux_unc'], \n", - " fmt='o', zorder=0)\n", - " plt.xlabel('time (BJD_TDB)')\n", - " plt.ylabel('rel. flux residuals')\n", - "\n", - " \n", - " \n", - "# And also print the residuals diagnostics like this:\n", - "\n", - "for obs_n, obs_id in enumerate(test['observations']):\n", - " observation = test['observations'][obs_id]\n", - " print('')\n", - " print('Observation: ', obs_id)\n", - " print('Filter: ', observation['model_info']['filter_id'])\n", - " print('Epoch: ', observation['model_info']['epoch'])\n", - " print('Number of outliers removed: ', observation['data_conversion_info']['outliers'])\n", - " print('Uncertainties scale factor: ', observation['data_conversion_info']['scale_factor'])\n", - "\n", - " print('Residuals statistics:')\n", - " print('res_max_autocorr:', '\\t', observation['statistics']['res_max_autocorr'])\n", - " print('res_max_autocorr_flag:', '\\t', observation['statistics']['res_max_autocorr_flag'])\n", - " print('res_shapiro:', '\\t\\t', observation['statistics']['res_shapiro'])\n", - " print('res_shapiro_flag:', '\\t', observation['statistics']['res_shapiro_flag'])\n", - " print('res_mean:', '\\t\\t', observation['statistics']['res_mean'])\n", - " print('res_std:', '\\t\\t', observation['statistics']['res_std'])\n", - " print('res_rms:', '\\t\\t', observation['statistics']['res_rms'])\n", - " print('res_chi_sqr:', '\\t\\t', observation['statistics']['res_chi_sqr'])\n", - " print('res_red_chi_sqr:', '\\t', observation['statistics']['res_red_chi_sqr'])\n", - " \n", - "###############################################################################################\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "0a5ae6df", - "metadata": { - "scrolled": true - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "Observation: obs0\n", - "Filter: luminance\n", - "Epoch: 603\n", - "Data-points excluded: 1\n", - "Scaling uncertainties by: 1.0563870819342949\n", - "\n", - "Optimising initial parameters...\n", - "\u001b[KTransit fitting: 2330 / 5000 , time left: 0:01:43, time elapsed: 0:01:30, total time: 0:03:14" - ] - } - ], - "source": [ - "\n", - "###############################################################################################\n", - "##### MCMC fit\n", - "###############################################################################################\n", - "\n", - "# If the residuals diagniostics look ok, we can run the MCMC.\n", - "# Here we will define the 'output_folder', so that all the results and plots are saved.\n", - "# We don't need to defile the optimiser, as the default one is 'mcmc'.\n", - "# It is also better to use filter_outliers=True to clear the outliers and \n", - "# and scale_uncertainties=True to scale the errorbars to match the residuals rms.\n", - "\n", - "final = planet.transit_fitting(\n", - " output_folder = 'wasp39b_ground',\n", - " filter_outliers=True,\n", - " scale_uncertainties=True,\n", - ")\n", - "\n", - "# By default, the number of iterations is 5000 and the burn in is 1000.\n", - "# If the chains do not converge, we can increase these number, for example by setting:\n", - "# iterations = 10000\n", - "# burn_in = 5000\n", - "\n", - "###############################################################################################\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "c960cf47", - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "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.11.5" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/notebooks/2_detrending_examples/.ipynb_checkpoints/2_wasp39b_tess-checkpoint.ipynb b/notebooks/2_detrending_examples/.ipynb_checkpoints/2_wasp39b_tess-checkpoint.ipynb deleted file mode 100644 index a0ed054..0000000 --- a/notebooks/2_detrending_examples/.ipynb_checkpoints/2_wasp39b_tess-checkpoint.ipynb +++ /dev/null @@ -1,2378 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "id": "fcbef1c0", - "metadata": { - "scrolled": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "exoclock: Checking ephemerides database...\n", - "exoclock: Checking catalogues database...\n", - "exoclock: Checking ut database...\n", - "pylightcurve: Checking exotethys database...\n", - "pylightcurve: Checking photometry database...\n" - ] - } - ], - "source": [ - "%matplotlib notebook\n", - "import matplotlib.pyplot as plt\n", - "import pylightcurve as plc\n", - "import numpy as np\n", - "\n", - "\n", - "###############################################################################################\n", - "##### Create a Planet object\n", - "###############################################################################################\n", - "\n", - "# At first we need to create a Planet object.\n", - "# Planets include in the ExoClock project (https://www.exoclock.space/database/planets)\n", - "# can be loaded automatically. \n", - "# Alteranatively we can difine our custom Planet object (see notebook: The Planet class)\n", - "\n", - "planet = plc.get_planet('WASP-39b')\n", - "\n", - "###############################################################################################\n" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "id": "afdc8521", - "metadata": {}, - "outputs": [ - { - "data": { - "application/javascript": [ - "/* Put everything inside the global mpl namespace */\n", - "/* global mpl */\n", - "window.mpl = {};\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(\n", - " '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", - "\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 = document.createElement('div');\n", - " this.root.setAttribute('style', 'display: inline-block');\n", - " this._root_extra_style(this.root);\n", - "\n", - " parent_element.appendChild(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 (fig.ratio !== 1) {\n", - " fig.send_message('set_device_pixel_ratio', {\n", - " device_pixel_ratio: fig.ratio,\n", - " });\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 = document.createElement('div');\n", - " titlebar.classList =\n", - " 'ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix';\n", - " var titletext = document.createElement('div');\n", - " titletext.classList = 'ui-dialog-title';\n", - " titletext.setAttribute(\n", - " 'style',\n", - " 'width: 100%; text-align: center; padding: 3px;'\n", - " );\n", - " titlebar.appendChild(titletext);\n", - " this.root.appendChild(titlebar);\n", - " this.header = titletext;\n", - "};\n", - "\n", - "mpl.figure.prototype._canvas_extra_style = function (_canvas_div) {};\n", - "\n", - "mpl.figure.prototype._root_extra_style = function (_canvas_div) {};\n", - "\n", - "mpl.figure.prototype._init_canvas = function () {\n", - " var fig = this;\n", - "\n", - " var canvas_div = (this.canvas_div = document.createElement('div'));\n", - " canvas_div.setAttribute('tabindex', '0');\n", - " canvas_div.setAttribute(\n", - " 'style',\n", - " 'border: 1px solid #ddd;' +\n", - " 'box-sizing: content-box;' +\n", - " 'clear: both;' +\n", - " 'min-height: 1px;' +\n", - " 'min-width: 1px;' +\n", - " 'outline: 0;' +\n", - " 'overflow: hidden;' +\n", - " 'position: relative;' +\n", - " 'resize: both;' +\n", - " 'z-index: 2;'\n", - " );\n", - "\n", - " function on_keyboard_event_closure(name) {\n", - " return function (event) {\n", - " return fig.key_event(event, name);\n", - " };\n", - " }\n", - "\n", - " canvas_div.addEventListener(\n", - " 'keydown',\n", - " on_keyboard_event_closure('key_press')\n", - " );\n", - " canvas_div.addEventListener(\n", - " 'keyup',\n", - " on_keyboard_event_closure('key_release')\n", - " );\n", - "\n", - " this._canvas_extra_style(canvas_div);\n", - " this.root.appendChild(canvas_div);\n", - "\n", - " var canvas = (this.canvas = document.createElement('canvas'));\n", - " canvas.classList.add('mpl-canvas');\n", - " canvas.setAttribute(\n", - " 'style',\n", - " 'box-sizing: content-box;' +\n", - " 'pointer-events: none;' +\n", - " 'position: relative;' +\n", - " 'z-index: 0;'\n", - " );\n", - "\n", - " this.context = canvas.getContext('2d');\n", - "\n", - " var backingStore =\n", - " this.context.backingStorePixelRatio ||\n", - " this.context.webkitBackingStorePixelRatio ||\n", - " this.context.mozBackingStorePixelRatio ||\n", - " this.context.msBackingStorePixelRatio ||\n", - " this.context.oBackingStorePixelRatio ||\n", - " this.context.backingStorePixelRatio ||\n", - " 1;\n", - "\n", - " this.ratio = (window.devicePixelRatio || 1) / backingStore;\n", - "\n", - " var rubberband_canvas = (this.rubberband_canvas = document.createElement(\n", - " 'canvas'\n", - " ));\n", - " rubberband_canvas.setAttribute(\n", - " 'style',\n", - " 'box-sizing: content-box;' +\n", - " 'left: 0;' +\n", - " 'pointer-events: none;' +\n", - " 'position: absolute;' +\n", - " 'top: 0;' +\n", - " 'z-index: 1;'\n", - " );\n", - "\n", - " // Apply a ponyfill if ResizeObserver is not implemented by browser.\n", - " if (this.ResizeObserver === undefined) {\n", - " if (window.ResizeObserver !== undefined) {\n", - " this.ResizeObserver = window.ResizeObserver;\n", - " } else {\n", - " var obs = _JSXTOOLS_RESIZE_OBSERVER({});\n", - " this.ResizeObserver = obs.ResizeObserver;\n", - " }\n", - " }\n", - "\n", - " this.resizeObserverInstance = new this.ResizeObserver(function (entries) {\n", - " // There's no need to resize if the WebSocket is not connected:\n", - " // - If it is still connecting, then we will get an initial resize from\n", - " // Python once it connects.\n", - " // - If it has disconnected, then resizing will clear the canvas and\n", - " // never get anything back to refill it, so better to not resize and\n", - " // keep something visible.\n", - " if (fig.ws.readyState != 1) {\n", - " return;\n", - " }\n", - " var nentries = entries.length;\n", - " for (var i = 0; i < nentries; i++) {\n", - " var entry = entries[i];\n", - " var width, height;\n", - " if (entry.contentBoxSize) {\n", - " if (entry.contentBoxSize instanceof Array) {\n", - " // Chrome 84 implements new version of spec.\n", - " width = entry.contentBoxSize[0].inlineSize;\n", - " height = entry.contentBoxSize[0].blockSize;\n", - " } else {\n", - " // Firefox implements old version of spec.\n", - " width = entry.contentBoxSize.inlineSize;\n", - " height = entry.contentBoxSize.blockSize;\n", - " }\n", - " } else {\n", - " // Chrome <84 implements even older version of spec.\n", - " width = entry.contentRect.width;\n", - " height = entry.contentRect.height;\n", - " }\n", - "\n", - " // Keep the size of the canvas and rubber band canvas in sync with\n", - " // the canvas container.\n", - " if (entry.devicePixelContentBoxSize) {\n", - " // Chrome 84 implements new version of spec.\n", - " canvas.setAttribute(\n", - " 'width',\n", - " entry.devicePixelContentBoxSize[0].inlineSize\n", - " );\n", - " canvas.setAttribute(\n", - " 'height',\n", - " entry.devicePixelContentBoxSize[0].blockSize\n", - " );\n", - " } else {\n", - " canvas.setAttribute('width', width * fig.ratio);\n", - " canvas.setAttribute('height', height * fig.ratio);\n", - " }\n", - " /* This rescales the canvas back to display pixels, so that it\n", - " * appears correct on HiDPI screens. */\n", - " canvas.style.width = width + 'px';\n", - " canvas.style.height = height + 'px';\n", - "\n", - " rubberband_canvas.setAttribute('width', width);\n", - " rubberband_canvas.setAttribute('height', height);\n", - "\n", - " // And update the size in Python. We ignore the initial 0/0 size\n", - " // that occurs as the element is placed into the DOM, which should\n", - " // otherwise not happen due to the minimum size styling.\n", - " if (width != 0 && height != 0) {\n", - " fig.request_resize(width, height);\n", - " }\n", - " }\n", - " });\n", - " this.resizeObserverInstance.observe(canvas_div);\n", - "\n", - " function on_mouse_event_closure(name) {\n", - " /* User Agent sniffing is bad, but WebKit is busted:\n", - " * https://bugs.webkit.org/show_bug.cgi?id=144526\n", - " * https://bugs.webkit.org/show_bug.cgi?id=181818\n", - " * The worst that happens here is that they get an extra browser\n", - " * selection when dragging, if this check fails to catch them.\n", - " */\n", - " var UA = navigator.userAgent;\n", - " var isWebKit = /AppleWebKit/.test(UA) && !/Chrome/.test(UA);\n", - " if(isWebKit) {\n", - " return function (event) {\n", - " /* This prevents the web browser from automatically changing to\n", - " * the text insertion cursor when the button is pressed. We\n", - " * want to control all of the cursor setting manually through\n", - " * the 'cursor' event from matplotlib */\n", - " event.preventDefault()\n", - " return fig.mouse_event(event, name);\n", - " };\n", - " } else {\n", - " return function (event) {\n", - " return fig.mouse_event(event, name);\n", - " };\n", - " }\n", - " }\n", - "\n", - " canvas_div.addEventListener(\n", - " 'mousedown',\n", - " on_mouse_event_closure('button_press')\n", - " );\n", - " canvas_div.addEventListener(\n", - " 'mouseup',\n", - " on_mouse_event_closure('button_release')\n", - " );\n", - " canvas_div.addEventListener(\n", - " 'dblclick',\n", - " on_mouse_event_closure('dblclick')\n", - " );\n", - " // Throttle sequential mouse events to 1 every 20ms.\n", - " canvas_div.addEventListener(\n", - " 'mousemove',\n", - " on_mouse_event_closure('motion_notify')\n", - " );\n", - "\n", - " canvas_div.addEventListener(\n", - " 'mouseenter',\n", - " on_mouse_event_closure('figure_enter')\n", - " );\n", - " canvas_div.addEventListener(\n", - " 'mouseleave',\n", - " on_mouse_event_closure('figure_leave')\n", - " );\n", - "\n", - " canvas_div.addEventListener('wheel', function (event) {\n", - " if (event.deltaY < 0) {\n", - " event.step = 1;\n", - " } else {\n", - " event.step = -1;\n", - " }\n", - " on_mouse_event_closure('scroll')(event);\n", - " });\n", - "\n", - " canvas_div.appendChild(canvas);\n", - " canvas_div.appendChild(rubberband_canvas);\n", - "\n", - " this.rubberband_context = rubberband_canvas.getContext('2d');\n", - " this.rubberband_context.strokeStyle = '#000000';\n", - "\n", - " this._resize_canvas = function (width, height, forward) {\n", - " if (forward) {\n", - " canvas_div.style.width = width + 'px';\n", - " canvas_div.style.height = height + 'px';\n", - " }\n", - " };\n", - "\n", - " // Disable right mouse context menu.\n", - " canvas_div.addEventListener('contextmenu', function (_e) {\n", - " event.preventDefault();\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 toolbar = document.createElement('div');\n", - " toolbar.classList = 'mpl-toolbar';\n", - " this.root.appendChild(toolbar);\n", - "\n", - " function on_click_closure(name) {\n", - " return function (_event) {\n", - " return fig.toolbar_button_onclick(name);\n", - " };\n", - " }\n", - "\n", - " function on_mouseover_closure(tooltip) {\n", - " return function (event) {\n", - " if (!event.currentTarget.disabled) {\n", - " return fig.toolbar_button_onmouseover(tooltip);\n", - " }\n", - " };\n", - " }\n", - "\n", - " fig.buttons = {};\n", - " var buttonGroup = document.createElement('div');\n", - " buttonGroup.classList = 'mpl-button-group';\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", - " /* Instead of a spacer, we start a new button group. */\n", - " if (buttonGroup.hasChildNodes()) {\n", - " toolbar.appendChild(buttonGroup);\n", - " }\n", - " buttonGroup = document.createElement('div');\n", - " buttonGroup.classList = 'mpl-button-group';\n", - " continue;\n", - " }\n", - "\n", - " var button = (fig.buttons[name] = document.createElement('button'));\n", - " button.classList = 'mpl-widget';\n", - " button.setAttribute('role', 'button');\n", - " button.setAttribute('aria-disabled', 'false');\n", - " button.addEventListener('click', on_click_closure(method_name));\n", - " button.addEventListener('mouseover', on_mouseover_closure(tooltip));\n", - "\n", - " var icon_img = document.createElement('img');\n", - " icon_img.src = '_images/' + image + '.png';\n", - " icon_img.srcset = '_images/' + image + '_large.png 2x';\n", - " icon_img.alt = tooltip;\n", - " button.appendChild(icon_img);\n", - "\n", - " buttonGroup.appendChild(button);\n", - " }\n", - "\n", - " if (buttonGroup.hasChildNodes()) {\n", - " toolbar.appendChild(buttonGroup);\n", - " }\n", - "\n", - " var fmt_picker = document.createElement('select');\n", - " fmt_picker.classList = 'mpl-widget';\n", - " toolbar.appendChild(fmt_picker);\n", - " this.format_dropdown = fmt_picker;\n", - "\n", - " for (var ind in mpl.extensions) {\n", - " var fmt = mpl.extensions[ind];\n", - " var option = document.createElement('option');\n", - " option.selected = fmt === mpl.default_extension;\n", - " option.innerHTML = fmt;\n", - " fmt_picker.appendChild(option);\n", - " }\n", - "\n", - " var status_bar = document.createElement('span');\n", - " status_bar.classList = 'mpl-message';\n", - " toolbar.appendChild(status_bar);\n", - " this.message = status_bar;\n", - "};\n", - "\n", - "mpl.figure.prototype.request_resize = function (x_pixels, y_pixels) {\n", - " // Request matplotlib to resize the figure. Matplotlib will then trigger a resize in the client,\n", - " // which will in turn request a refresh of the image.\n", - " this.send_message('resize', { width: x_pixels, height: y_pixels });\n", - "};\n", - "\n", - "mpl.figure.prototype.send_message = function (type, properties) {\n", - " properties['type'] = type;\n", - " properties['figure_id'] = this.id;\n", - " this.ws.send(JSON.stringify(properties));\n", - "};\n", - "\n", - "mpl.figure.prototype.send_draw_message = function () {\n", - " if (!this.waiting) {\n", - " this.waiting = true;\n", - " this.ws.send(JSON.stringify({ type: 'draw', figure_id: this.id }));\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_save = function (fig, _msg) {\n", - " var format_dropdown = fig.format_dropdown;\n", - " var format = format_dropdown.options[format_dropdown.selectedIndex].value;\n", - " fig.ondownload(fig, format);\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_resize = function (fig, msg) {\n", - " var size = msg['size'];\n", - " if (size[0] !== fig.canvas.width || size[1] !== fig.canvas.height) {\n", - " fig._resize_canvas(size[0], size[1], msg['forward']);\n", - " fig.send_message('refresh', {});\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_rubberband = function (fig, msg) {\n", - " var x0 = msg['x0'] / fig.ratio;\n", - " var y0 = (fig.canvas.height - msg['y0']) / fig.ratio;\n", - " var x1 = msg['x1'] / fig.ratio;\n", - " var y1 = (fig.canvas.height - msg['y1']) / fig.ratio;\n", - " x0 = Math.floor(x0) + 0.5;\n", - " y0 = Math.floor(y0) + 0.5;\n", - " x1 = Math.floor(x1) + 0.5;\n", - " y1 = Math.floor(y1) + 0.5;\n", - " var min_x = Math.min(x0, x1);\n", - " var min_y = Math.min(y0, y1);\n", - " var width = Math.abs(x1 - x0);\n", - " var height = Math.abs(y1 - y0);\n", - "\n", - " fig.rubberband_context.clearRect(\n", - " 0,\n", - " 0,\n", - " fig.canvas.width / fig.ratio,\n", - " fig.canvas.height / fig.ratio\n", - " );\n", - "\n", - " fig.rubberband_context.strokeRect(min_x, min_y, width, height);\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_figure_label = function (fig, msg) {\n", - " // Updates the figure title.\n", - " fig.header.textContent = msg['label'];\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_cursor = function (fig, msg) {\n", - " fig.canvas_div.style.cursor = msg['cursor'];\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_message = function (fig, msg) {\n", - " fig.message.textContent = msg['message'];\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_draw = function (fig, _msg) {\n", - " // Request the server to send over a new figure.\n", - " fig.send_draw_message();\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_image_mode = function (fig, msg) {\n", - " fig.image_mode = msg['mode'];\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_history_buttons = function (fig, msg) {\n", - " for (var key in msg) {\n", - " if (!(key in fig.buttons)) {\n", - " continue;\n", - " }\n", - " fig.buttons[key].disabled = !msg[key];\n", - " fig.buttons[key].setAttribute('aria-disabled', !msg[key]);\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_navigate_mode = function (fig, msg) {\n", - " if (msg['mode'] === 'PAN') {\n", - " fig.buttons['Pan'].classList.add('active');\n", - " fig.buttons['Zoom'].classList.remove('active');\n", - " } else if (msg['mode'] === 'ZOOM') {\n", - " fig.buttons['Pan'].classList.remove('active');\n", - " fig.buttons['Zoom'].classList.add('active');\n", - " } else {\n", - " fig.buttons['Pan'].classList.remove('active');\n", - " fig.buttons['Zoom'].classList.remove('active');\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.updated_canvas_event = function () {\n", - " // Called whenever the canvas gets updated.\n", - " this.send_message('ack', {});\n", - "};\n", - "\n", - "// A function to construct a web socket function for onmessage handling.\n", - "// Called in the figure constructor.\n", - "mpl.figure.prototype._make_on_message_function = function (fig) {\n", - " return function socket_on_message(evt) {\n", - " if (evt.data instanceof Blob) {\n", - " var img = evt.data;\n", - " if (img.type !== 'image/png') {\n", - " /* FIXME: We get \"Resource interpreted as Image but\n", - " * transferred with MIME type text/plain:\" errors on\n", - " * Chrome. But how to set the MIME type? It doesn't seem\n", - " * to be part of the websocket stream */\n", - " img.type = 'image/png';\n", - " }\n", - "\n", - " /* Free the memory for the previous frames */\n", - " if (fig.imageObj.src) {\n", - " (window.URL || window.webkitURL).revokeObjectURL(\n", - " fig.imageObj.src\n", - " );\n", - " }\n", - "\n", - " fig.imageObj.src = (window.URL || window.webkitURL).createObjectURL(\n", - " img\n", - " );\n", - " fig.updated_canvas_event();\n", - " fig.waiting = false;\n", - " return;\n", - " } else if (\n", - " typeof evt.data === 'string' &&\n", - " evt.data.slice(0, 21) === 'data:image/png;base64'\n", - " ) {\n", - " fig.imageObj.src = evt.data;\n", - " fig.updated_canvas_event();\n", - " fig.waiting = false;\n", - " return;\n", - " }\n", - "\n", - " var msg = JSON.parse(evt.data);\n", - " var msg_type = msg['type'];\n", - "\n", - " // Call the \"handle_{type}\" callback, which takes\n", - " // the figure and JSON message as its only arguments.\n", - " try {\n", - " var callback = fig['handle_' + msg_type];\n", - " } catch (e) {\n", - " console.log(\n", - " \"No handler for the '\" + msg_type + \"' message type: \",\n", - " msg\n", - " );\n", - " return;\n", - " }\n", - "\n", - " if (callback) {\n", - " try {\n", - " // console.log(\"Handling '\" + msg_type + \"' message: \", msg);\n", - " callback(fig, msg);\n", - " } catch (e) {\n", - " console.log(\n", - " \"Exception inside the 'handler_\" + msg_type + \"' callback:\",\n", - " e,\n", - " e.stack,\n", - " msg\n", - " );\n", - " }\n", - " }\n", - " };\n", - "};\n", - "\n", - "function getModifiers(event) {\n", - " var mods = [];\n", - " if (event.ctrlKey) {\n", - " mods.push('ctrl');\n", - " }\n", - " if (event.altKey) {\n", - " mods.push('alt');\n", - " }\n", - " if (event.shiftKey) {\n", - " mods.push('shift');\n", - " }\n", - " if (event.metaKey) {\n", - " mods.push('meta');\n", - " }\n", - " return mods;\n", - "}\n", - "\n", - "/*\n", - " * return a copy of an object with only non-object keys\n", - " * we need this to avoid circular references\n", - " * https://stackoverflow.com/a/24161582/3208463\n", - " */\n", - "function simpleKeys(original) {\n", - " return Object.keys(original).reduce(function (obj, key) {\n", - " if (typeof original[key] !== 'object') {\n", - " obj[key] = original[key];\n", - " }\n", - " return obj;\n", - " }, {});\n", - "}\n", - "\n", - "mpl.figure.prototype.mouse_event = function (event, name) {\n", - " if (name === 'button_press') {\n", - " this.canvas.focus();\n", - " this.canvas_div.focus();\n", - " }\n", - "\n", - " // from https://stackoverflow.com/q/1114465\n", - " var boundingRect = this.canvas.getBoundingClientRect();\n", - " var x = (event.clientX - boundingRect.left) * this.ratio;\n", - " var y = (event.clientY - boundingRect.top) * this.ratio;\n", - "\n", - " this.send_message(name, {\n", - " x: x,\n", - " y: y,\n", - " button: event.button,\n", - " step: event.step,\n", - " modifiers: getModifiers(event),\n", - " guiEvent: simpleKeys(event),\n", - " });\n", - "\n", - " return false;\n", - "};\n", - "\n", - "mpl.figure.prototype._key_event_extra = function (_event, _name) {\n", - " // Handle any extra behaviour associated with a key event\n", - "};\n", - "\n", - "mpl.figure.prototype.key_event = function (event, name) {\n", - " // Prevent repeat events\n", - " if (name === 'key_press') {\n", - " if (event.key === this._key) {\n", - " return;\n", - " } else {\n", - " this._key = event.key;\n", - " }\n", - " }\n", - " if (name === 'key_release') {\n", - " this._key = null;\n", - " }\n", - "\n", - " var value = '';\n", - " if (event.ctrlKey && event.key !== 'Control') {\n", - " value += 'ctrl+';\n", - " }\n", - " else if (event.altKey && event.key !== 'Alt') {\n", - " value += 'alt+';\n", - " }\n", - " else if (event.shiftKey && event.key !== 'Shift') {\n", - " value += 'shift+';\n", - " }\n", - "\n", - " value += 'k' + event.key;\n", - "\n", - " this._key_event_extra(event, name);\n", - "\n", - " this.send_message(name, { key: value, guiEvent: simpleKeys(event) });\n", - " return false;\n", - "};\n", - "\n", - "mpl.figure.prototype.toolbar_button_onclick = function (name) {\n", - " if (name === 'download') {\n", - " this.handle_save(this, null);\n", - " } else {\n", - " this.send_message('toolbar_button', { name: name });\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.toolbar_button_onmouseover = function (tooltip) {\n", - " this.message.textContent = tooltip;\n", - "};\n", - "\n", - "///////////////// REMAINING CONTENT GENERATED BY embed_js.py /////////////////\n", - "// prettier-ignore\n", - "var _JSXTOOLS_RESIZE_OBSERVER=function(A){var t,i=new WeakMap,n=new WeakMap,a=new WeakMap,r=new WeakMap,o=new Set;function s(e){if(!(this instanceof s))throw new TypeError(\"Constructor requires 'new' operator\");i.set(this,e)}function h(){throw new TypeError(\"Function is not a constructor\")}function c(e,t,i,n){e=0 in arguments?Number(arguments[0]):0,t=1 in arguments?Number(arguments[1]):0,i=2 in arguments?Number(arguments[2]):0,n=3 in arguments?Number(arguments[3]):0,this.right=(this.x=this.left=e)+(this.width=i),this.bottom=(this.y=this.top=t)+(this.height=n),Object.freeze(this)}function d(){t=requestAnimationFrame(d);var s=new WeakMap,p=new Set;o.forEach((function(t){r.get(t).forEach((function(i){var r=t instanceof window.SVGElement,o=a.get(t),d=r?0:parseFloat(o.paddingTop),f=r?0:parseFloat(o.paddingRight),l=r?0:parseFloat(o.paddingBottom),u=r?0:parseFloat(o.paddingLeft),g=r?0:parseFloat(o.borderTopWidth),m=r?0:parseFloat(o.borderRightWidth),w=r?0:parseFloat(o.borderBottomWidth),b=u+f,F=d+l,v=(r?0:parseFloat(o.borderLeftWidth))+m,W=g+w,y=r?0:t.offsetHeight-W-t.clientHeight,E=r?0:t.offsetWidth-v-t.clientWidth,R=b+v,z=F+W,M=r?t.width:parseFloat(o.width)-R-E,O=r?t.height:parseFloat(o.height)-z-y;if(n.has(t)){var k=n.get(t);if(k[0]===M&&k[1]===O)return}n.set(t,[M,O]);var S=Object.create(h.prototype);S.target=t,S.contentRect=new c(u,d,M,O),s.has(i)||(s.set(i,[]),p.add(i)),s.get(i).push(S)}))})),p.forEach((function(e){i.get(e).call(e,s.get(e),e)}))}return s.prototype.observe=function(i){if(i instanceof window.Element){r.has(i)||(r.set(i,new Set),o.add(i),a.set(i,window.getComputedStyle(i)));var n=r.get(i);n.has(this)||n.add(this),cancelAnimationFrame(t),t=requestAnimationFrame(d)}},s.prototype.unobserve=function(i){if(i instanceof window.Element&&r.has(i)){var n=r.get(i);n.has(this)&&(n.delete(this),n.size||(r.delete(i),o.delete(i))),n.size||r.delete(i),o.size||cancelAnimationFrame(t)}},A.DOMRectReadOnly=c,A.ResizeObserver=s,A.ResizeObserverEntry=h,A}; // eslint-disable-line\n", - "mpl.toolbar_items = [[\"Home\", \"Reset original view\", \"fa fa-home\", \"home\"], [\"Back\", \"Back to previous view\", \"fa fa-arrow-left\", \"back\"], [\"Forward\", \"Forward to next view\", \"fa fa-arrow-right\", \"forward\"], [\"\", \"\", \"\", \"\"], [\"Pan\", \"Left button pans, Right button zooms\\nx/y fixes axis, CTRL fixes aspect\", \"fa fa-arrows\", \"pan\"], [\"Zoom\", \"Zoom to rectangle\\nx/y fixes axis\", \"fa fa-square-o\", \"zoom\"], [\"\", \"\", \"\", \"\"], [\"Download\", \"Download plot\", \"fa fa-floppy-o\", \"download\"]];\n", - "\n", - "mpl.extensions = [\"eps\", \"jpeg\", \"pgf\", \"pdf\", \"png\", \"ps\", \"raw\", \"svg\", \"tif\", \"webp\"];\n", - "\n", - "mpl.default_extension = \"png\";/* global mpl */\n", - "\n", - "var comm_websocket_adapter = function (comm) {\n", - " // Create a \"websocket\"-like object which calls the given IPython comm\n", - " // object with the appropriate methods. Currently this is a non binary\n", - " // socket, so there is still some room for performance tuning.\n", - " var ws = {};\n", - "\n", - " ws.binaryType = comm.kernel.ws.binaryType;\n", - " ws.readyState = comm.kernel.ws.readyState;\n", - " function updateReadyState(_event) {\n", - " if (comm.kernel.ws) {\n", - " ws.readyState = comm.kernel.ws.readyState;\n", - " } else {\n", - " ws.readyState = 3; // Closed state.\n", - " }\n", - " }\n", - " comm.kernel.ws.addEventListener('open', updateReadyState);\n", - " comm.kernel.ws.addEventListener('close', updateReadyState);\n", - " comm.kernel.ws.addEventListener('error', updateReadyState);\n", - "\n", - " ws.close = function () {\n", - " comm.close();\n", - " };\n", - " ws.send = function (m) {\n", - " //console.log('sending', m);\n", - " comm.send(m);\n", - " };\n", - " // Register the callback with on_msg.\n", - " comm.on_msg(function (msg) {\n", - " //console.log('receiving', msg['content']['data'], msg);\n", - " var data = msg['content']['data'];\n", - " if (data['blob'] !== undefined) {\n", - " data = {\n", - " data: new Blob(msg['buffers'], { type: data['blob'] }),\n", - " };\n", - " }\n", - " // Pass the mpl event to the overridden (by mpl) onmessage function.\n", - " ws.onmessage(data);\n", - " });\n", - " return ws;\n", - "};\n", - "\n", - "mpl.mpl_figure_comm = function (comm, msg) {\n", - " // This is the function which gets called when the mpl process\n", - " // starts-up an IPython Comm through the \"matplotlib\" channel.\n", - "\n", - " var id = msg.content.data.id;\n", - " // Get hold of the div created by the display call when the Comm\n", - " // socket was opened in Python.\n", - " var element = document.getElementById(id);\n", - " var ws_proxy = comm_websocket_adapter(comm);\n", - "\n", - " function ondownload(figure, _format) {\n", - " window.open(figure.canvas.toDataURL());\n", - " }\n", - "\n", - " var fig = new mpl.figure(id, ws_proxy, ondownload, element);\n", - "\n", - " // Call onopen now - mpl needs it, as it is assuming we've passed it a real\n", - " // web socket which is closed, not our websocket->open comm proxy.\n", - " ws_proxy.onopen();\n", - "\n", - " fig.parent_element = element;\n", - " fig.cell_info = mpl.find_output_cell(\"
\");\n", - " if (!fig.cell_info) {\n", - " console.error('Failed to find cell for figure', id, fig);\n", - " return;\n", - " }\n", - " fig.cell_info[0].output_area.element.on(\n", - " 'cleared',\n", - " { fig: fig },\n", - " fig._remove_fig_handler\n", - " );\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_close = function (fig, msg) {\n", - " var width = fig.canvas.width / fig.ratio;\n", - " fig.cell_info[0].output_area.element.off(\n", - " 'cleared',\n", - " fig._remove_fig_handler\n", - " );\n", - " fig.resizeObserverInstance.unobserve(fig.canvas_div);\n", - "\n", - " // Update the output cell to use the data from the current canvas.\n", - " fig.push_to_output();\n", - " var dataURL = fig.canvas.toDataURL();\n", - " // Re-enable the keyboard manager in IPython - without this line, in FF,\n", - " // the notebook keyboard shortcuts fail.\n", - " IPython.keyboard_manager.enable();\n", - " fig.parent_element.innerHTML =\n", - " '';\n", - " fig.close_ws(fig, msg);\n", - "};\n", - "\n", - "mpl.figure.prototype.close_ws = function (fig, msg) {\n", - " fig.send_message('closing', msg);\n", - " // fig.ws.close()\n", - "};\n", - "\n", - "mpl.figure.prototype.push_to_output = function (_remove_interactive) {\n", - " // Turn the data on the canvas into data in the output cell.\n", - " var width = this.canvas.width / this.ratio;\n", - " var dataURL = this.canvas.toDataURL();\n", - " this.cell_info[1]['text/html'] =\n", - " '';\n", - "};\n", - "\n", - "mpl.figure.prototype.updated_canvas_event = function () {\n", - " // Tell IPython that the notebook contents must change.\n", - " IPython.notebook.set_dirty(true);\n", - " this.send_message('ack', {});\n", - " var fig = this;\n", - " // Wait a second, then push the new image to the DOM so\n", - " // that it is saved nicely (might be nice to debounce this).\n", - " setTimeout(function () {\n", - " fig.push_to_output();\n", - " }, 1000);\n", - "};\n", - "\n", - "mpl.figure.prototype._init_toolbar = function () {\n", - " var fig = this;\n", - "\n", - " var toolbar = document.createElement('div');\n", - " toolbar.classList = 'btn-toolbar';\n", - " this.root.appendChild(toolbar);\n", - "\n", - " function on_click_closure(name) {\n", - " return function (_event) {\n", - " return fig.toolbar_button_onclick(name);\n", - " };\n", - " }\n", - "\n", - " function on_mouseover_closure(tooltip) {\n", - " return function (event) {\n", - " if (!event.currentTarget.disabled) {\n", - " return fig.toolbar_button_onmouseover(tooltip);\n", - " }\n", - " };\n", - " }\n", - "\n", - " fig.buttons = {};\n", - " var buttonGroup = document.createElement('div');\n", - " buttonGroup.classList = 'btn-group';\n", - " var button;\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", - " /* Instead of a spacer, we start a new button group. */\n", - " if (buttonGroup.hasChildNodes()) {\n", - " toolbar.appendChild(buttonGroup);\n", - " }\n", - " buttonGroup = document.createElement('div');\n", - " buttonGroup.classList = 'btn-group';\n", - " continue;\n", - " }\n", - "\n", - " button = fig.buttons[name] = document.createElement('button');\n", - " button.classList = 'btn btn-default';\n", - " button.href = '#';\n", - " button.title = name;\n", - " button.innerHTML = '';\n", - " button.addEventListener('click', on_click_closure(method_name));\n", - " button.addEventListener('mouseover', on_mouseover_closure(tooltip));\n", - " buttonGroup.appendChild(button);\n", - " }\n", - "\n", - " if (buttonGroup.hasChildNodes()) {\n", - " toolbar.appendChild(buttonGroup);\n", - " }\n", - "\n", - " // Add the status bar.\n", - " var status_bar = document.createElement('span');\n", - " status_bar.classList = 'mpl-message pull-right';\n", - " toolbar.appendChild(status_bar);\n", - " this.message = status_bar;\n", - "\n", - " // Add the close button to the window.\n", - " var buttongrp = document.createElement('div');\n", - " buttongrp.classList = 'btn-group inline pull-right';\n", - " button = document.createElement('button');\n", - " button.classList = 'btn btn-mini btn-primary';\n", - " button.href = '#';\n", - " button.title = 'Stop Interaction';\n", - " button.innerHTML = '';\n", - " button.addEventListener('click', function (_evt) {\n", - " fig.handle_close(fig, {});\n", - " });\n", - " button.addEventListener(\n", - " 'mouseover',\n", - " on_mouseover_closure('Stop Interaction')\n", - " );\n", - " buttongrp.appendChild(button);\n", - " var titlebar = this.root.querySelector('.ui-dialog-titlebar');\n", - " titlebar.insertBefore(buttongrp, titlebar.firstChild);\n", - "};\n", - "\n", - "mpl.figure.prototype._remove_fig_handler = function (event) {\n", - " var fig = event.data.fig;\n", - " if (event.target !== this) {\n", - " // Ignore bubbled events from children.\n", - " return;\n", - " }\n", - " fig.close_ws(fig, {});\n", - "};\n", - "\n", - "mpl.figure.prototype._root_extra_style = function (el) {\n", - " el.style.boxSizing = 'content-box'; // override notebook setting of border-box.\n", - "};\n", - "\n", - "mpl.figure.prototype._canvas_extra_style = function (el) {\n", - " // this is important to make the div 'focusable\n", - " el.setAttribute('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", - " } else {\n", - " // location in version 2\n", - " IPython.keyboard_manager.register_events(el);\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype._key_event_extra = function (event, _name) {\n", - " // Check for shift+enter\n", - " if (event.shiftKey && event.which === 13) {\n", - " this.canvas_div.blur();\n", - " // select the cell after this one\n", - " var index = IPython.notebook.find_cell_index(this.cell_info[0]);\n", - " IPython.notebook.select(index + 1);\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_save = function (fig, _msg) {\n", - " fig.ondownload(fig, null);\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 < ncells; i++) {\n", - " var cell = cells[i];\n", - " if (cell.cell_type === 'code') {\n", - " for (var j = 0; j < cell.output_area.outputs.length; j++) {\n", - " var data = cell.output_area.outputs[j];\n", - " if (data.data) {\n", - " // IPython >= 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(\n", - " 'matplotlib',\n", - " mpl.mpl_figure_comm\n", - " );\n", - "}\n" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/html": [ - "
" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "time_format: BJD_TDB\n", - "time_stamp: mid\n", - "exp_time: 120.0\n", - "flux_format: flux\n", - "filter_name: TESS\n" - ] - } - ], - "source": [ - "###############################################################################################\n", - "##### Load data\n", - "###############################################################################################\n", - "\n", - "# This dataset contains one transit observation of WASP-39b, obtained by TESS:\n", - "# https://tess.mit.edu\n", - "\n", - "data = plc.open_dict('wasp39b_tess.pickle')\n", - "\n", - "###############################################################################################\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "###############################################################################################\n", - "##### Inspect data\n", - "###############################################################################################\n", - "\n", - "# The dictionaly contains the necessary keywords:\n", - "# 'time'\n", - "# 'time_format'\n", - "# 'time_stamp'\n", - "# 'exp_time'\n", - "# 'flux'\n", - "# 'flux_unc'\n", - "# 'flux_format'\n", - "# 'filter_name'\n", - "\n", - "plt.figure()\n", - "plt.ylabel('flux')\n", - "plt.xlabel('time')\n", - "plt.errorbar(data['time'], data['flux'], data['flux_unc'], fmt='o')\n", - "\n", - "for i in ['time_format', 'time_stamp', 'exp_time', 'flux_format', 'filter_name']:\n", - " print('{0}: {1}'.format(i, data[i]))\n", - " \n", - "###############################################################################################\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "###############################################################################################\n", - "##### Define the trend function\n", - "###############################################################################################\n", - "\n", - "# By default, the detrending is done using a second order polynomial with time.\n", - "# Here, we will not change this.\n", - "\n", - "###############################################################################################\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "###############################################################################################\n", - "##### Define the stellar model\n", - "###############################################################################################\n", - "\n", - "# The default stellar model used to calculate the limb-darkening coefficients \n", - "# is the 'Pheonix_2018'. Here, we will not change this.\n", - "\n", - "###############################################################################################\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "###############################################################################################\n", - "##### Add observation to the Planet object\n", - "###############################################################################################\n", - "\n", - "# Then we are going to add the observation to the Planet object.\n", - "# It is advised to use planet.clear_observations() before, \n", - "# to avoid duplications, in case we forget that we have already added the same observation.\n", - "\n", - "planet.clear_observations()\n", - "planet.add_observation_from_dict(data)\n", - "\n", - "###############################################################################################\n" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "id": "fc4fcb81", - "metadata": { - "scrolled": false - }, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "WARNING:root:\n", - "PHOENIX models are only computed for solar metallicity stars. Setting stellar_metallicity = 0.\n", - "\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "File already here... teff05400_logg4.00_MH0.0.pickle\n", - "File already here... teff05400_logg4.50_MH0.0.pickle\n", - "\n", - "Observation: obs0\n", - "Filter: TESS\n", - "Epoch: 694\n", - "Data-points excluded: 0\n", - "Scaling uncertainties by: 1\n", - "\n", - "Optimising initial parameters...\n", - "Transit fitting...\n" - ] - }, - { - "data": { - "application/javascript": [ - "/* Put everything inside the global mpl namespace */\n", - "/* global mpl */\n", - "window.mpl = {};\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(\n", - " '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", - "\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 = document.createElement('div');\n", - " this.root.setAttribute('style', 'display: inline-block');\n", - " this._root_extra_style(this.root);\n", - "\n", - " parent_element.appendChild(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 (fig.ratio !== 1) {\n", - " fig.send_message('set_device_pixel_ratio', {\n", - " device_pixel_ratio: fig.ratio,\n", - " });\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 = document.createElement('div');\n", - " titlebar.classList =\n", - " 'ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix';\n", - " var titletext = document.createElement('div');\n", - " titletext.classList = 'ui-dialog-title';\n", - " titletext.setAttribute(\n", - " 'style',\n", - " 'width: 100%; text-align: center; padding: 3px;'\n", - " );\n", - " titlebar.appendChild(titletext);\n", - " this.root.appendChild(titlebar);\n", - " this.header = titletext;\n", - "};\n", - "\n", - "mpl.figure.prototype._canvas_extra_style = function (_canvas_div) {};\n", - "\n", - "mpl.figure.prototype._root_extra_style = function (_canvas_div) {};\n", - "\n", - "mpl.figure.prototype._init_canvas = function () {\n", - " var fig = this;\n", - "\n", - " var canvas_div = (this.canvas_div = document.createElement('div'));\n", - " canvas_div.setAttribute('tabindex', '0');\n", - " canvas_div.setAttribute(\n", - " 'style',\n", - " 'border: 1px solid #ddd;' +\n", - " 'box-sizing: content-box;' +\n", - " 'clear: both;' +\n", - " 'min-height: 1px;' +\n", - " 'min-width: 1px;' +\n", - " 'outline: 0;' +\n", - " 'overflow: hidden;' +\n", - " 'position: relative;' +\n", - " 'resize: both;' +\n", - " 'z-index: 2;'\n", - " );\n", - "\n", - " function on_keyboard_event_closure(name) {\n", - " return function (event) {\n", - " return fig.key_event(event, name);\n", - " };\n", - " }\n", - "\n", - " canvas_div.addEventListener(\n", - " 'keydown',\n", - " on_keyboard_event_closure('key_press')\n", - " );\n", - " canvas_div.addEventListener(\n", - " 'keyup',\n", - " on_keyboard_event_closure('key_release')\n", - " );\n", - "\n", - " this._canvas_extra_style(canvas_div);\n", - " this.root.appendChild(canvas_div);\n", - "\n", - " var canvas = (this.canvas = document.createElement('canvas'));\n", - " canvas.classList.add('mpl-canvas');\n", - " canvas.setAttribute(\n", - " 'style',\n", - " 'box-sizing: content-box;' +\n", - " 'pointer-events: none;' +\n", - " 'position: relative;' +\n", - " 'z-index: 0;'\n", - " );\n", - "\n", - " this.context = canvas.getContext('2d');\n", - "\n", - " var backingStore =\n", - " this.context.backingStorePixelRatio ||\n", - " this.context.webkitBackingStorePixelRatio ||\n", - " this.context.mozBackingStorePixelRatio ||\n", - " this.context.msBackingStorePixelRatio ||\n", - " this.context.oBackingStorePixelRatio ||\n", - " this.context.backingStorePixelRatio ||\n", - " 1;\n", - "\n", - " this.ratio = (window.devicePixelRatio || 1) / backingStore;\n", - "\n", - " var rubberband_canvas = (this.rubberband_canvas = document.createElement(\n", - " 'canvas'\n", - " ));\n", - " rubberband_canvas.setAttribute(\n", - " 'style',\n", - " 'box-sizing: content-box;' +\n", - " 'left: 0;' +\n", - " 'pointer-events: none;' +\n", - " 'position: absolute;' +\n", - " 'top: 0;' +\n", - " 'z-index: 1;'\n", - " );\n", - "\n", - " // Apply a ponyfill if ResizeObserver is not implemented by browser.\n", - " if (this.ResizeObserver === undefined) {\n", - " if (window.ResizeObserver !== undefined) {\n", - " this.ResizeObserver = window.ResizeObserver;\n", - " } else {\n", - " var obs = _JSXTOOLS_RESIZE_OBSERVER({});\n", - " this.ResizeObserver = obs.ResizeObserver;\n", - " }\n", - " }\n", - "\n", - " this.resizeObserverInstance = new this.ResizeObserver(function (entries) {\n", - " // There's no need to resize if the WebSocket is not connected:\n", - " // - If it is still connecting, then we will get an initial resize from\n", - " // Python once it connects.\n", - " // - If it has disconnected, then resizing will clear the canvas and\n", - " // never get anything back to refill it, so better to not resize and\n", - " // keep something visible.\n", - " if (fig.ws.readyState != 1) {\n", - " return;\n", - " }\n", - " var nentries = entries.length;\n", - " for (var i = 0; i < nentries; i++) {\n", - " var entry = entries[i];\n", - " var width, height;\n", - " if (entry.contentBoxSize) {\n", - " if (entry.contentBoxSize instanceof Array) {\n", - " // Chrome 84 implements new version of spec.\n", - " width = entry.contentBoxSize[0].inlineSize;\n", - " height = entry.contentBoxSize[0].blockSize;\n", - " } else {\n", - " // Firefox implements old version of spec.\n", - " width = entry.contentBoxSize.inlineSize;\n", - " height = entry.contentBoxSize.blockSize;\n", - " }\n", - " } else {\n", - " // Chrome <84 implements even older version of spec.\n", - " width = entry.contentRect.width;\n", - " height = entry.contentRect.height;\n", - " }\n", - "\n", - " // Keep the size of the canvas and rubber band canvas in sync with\n", - " // the canvas container.\n", - " if (entry.devicePixelContentBoxSize) {\n", - " // Chrome 84 implements new version of spec.\n", - " canvas.setAttribute(\n", - " 'width',\n", - " entry.devicePixelContentBoxSize[0].inlineSize\n", - " );\n", - " canvas.setAttribute(\n", - " 'height',\n", - " entry.devicePixelContentBoxSize[0].blockSize\n", - " );\n", - " } else {\n", - " canvas.setAttribute('width', width * fig.ratio);\n", - " canvas.setAttribute('height', height * fig.ratio);\n", - " }\n", - " /* This rescales the canvas back to display pixels, so that it\n", - " * appears correct on HiDPI screens. */\n", - " canvas.style.width = width + 'px';\n", - " canvas.style.height = height + 'px';\n", - "\n", - " rubberband_canvas.setAttribute('width', width);\n", - " rubberband_canvas.setAttribute('height', height);\n", - "\n", - " // And update the size in Python. We ignore the initial 0/0 size\n", - " // that occurs as the element is placed into the DOM, which should\n", - " // otherwise not happen due to the minimum size styling.\n", - " if (width != 0 && height != 0) {\n", - " fig.request_resize(width, height);\n", - " }\n", - " }\n", - " });\n", - " this.resizeObserverInstance.observe(canvas_div);\n", - "\n", - " function on_mouse_event_closure(name) {\n", - " /* User Agent sniffing is bad, but WebKit is busted:\n", - " * https://bugs.webkit.org/show_bug.cgi?id=144526\n", - " * https://bugs.webkit.org/show_bug.cgi?id=181818\n", - " * The worst that happens here is that they get an extra browser\n", - " * selection when dragging, if this check fails to catch them.\n", - " */\n", - " var UA = navigator.userAgent;\n", - " var isWebKit = /AppleWebKit/.test(UA) && !/Chrome/.test(UA);\n", - " if(isWebKit) {\n", - " return function (event) {\n", - " /* This prevents the web browser from automatically changing to\n", - " * the text insertion cursor when the button is pressed. We\n", - " * want to control all of the cursor setting manually through\n", - " * the 'cursor' event from matplotlib */\n", - " event.preventDefault()\n", - " return fig.mouse_event(event, name);\n", - " };\n", - " } else {\n", - " return function (event) {\n", - " return fig.mouse_event(event, name);\n", - " };\n", - " }\n", - " }\n", - "\n", - " canvas_div.addEventListener(\n", - " 'mousedown',\n", - " on_mouse_event_closure('button_press')\n", - " );\n", - " canvas_div.addEventListener(\n", - " 'mouseup',\n", - " on_mouse_event_closure('button_release')\n", - " );\n", - " canvas_div.addEventListener(\n", - " 'dblclick',\n", - " on_mouse_event_closure('dblclick')\n", - " );\n", - " // Throttle sequential mouse events to 1 every 20ms.\n", - " canvas_div.addEventListener(\n", - " 'mousemove',\n", - " on_mouse_event_closure('motion_notify')\n", - " );\n", - "\n", - " canvas_div.addEventListener(\n", - " 'mouseenter',\n", - " on_mouse_event_closure('figure_enter')\n", - " );\n", - " canvas_div.addEventListener(\n", - " 'mouseleave',\n", - " on_mouse_event_closure('figure_leave')\n", - " );\n", - "\n", - " canvas_div.addEventListener('wheel', function (event) {\n", - " if (event.deltaY < 0) {\n", - " event.step = 1;\n", - " } else {\n", - " event.step = -1;\n", - " }\n", - " on_mouse_event_closure('scroll')(event);\n", - " });\n", - "\n", - " canvas_div.appendChild(canvas);\n", - " canvas_div.appendChild(rubberband_canvas);\n", - "\n", - " this.rubberband_context = rubberband_canvas.getContext('2d');\n", - " this.rubberband_context.strokeStyle = '#000000';\n", - "\n", - " this._resize_canvas = function (width, height, forward) {\n", - " if (forward) {\n", - " canvas_div.style.width = width + 'px';\n", - " canvas_div.style.height = height + 'px';\n", - " }\n", - " };\n", - "\n", - " // Disable right mouse context menu.\n", - " canvas_div.addEventListener('contextmenu', function (_e) {\n", - " event.preventDefault();\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 toolbar = document.createElement('div');\n", - " toolbar.classList = 'mpl-toolbar';\n", - " this.root.appendChild(toolbar);\n", - "\n", - " function on_click_closure(name) {\n", - " return function (_event) {\n", - " return fig.toolbar_button_onclick(name);\n", - " };\n", - " }\n", - "\n", - " function on_mouseover_closure(tooltip) {\n", - " return function (event) {\n", - " if (!event.currentTarget.disabled) {\n", - " return fig.toolbar_button_onmouseover(tooltip);\n", - " }\n", - " };\n", - " }\n", - "\n", - " fig.buttons = {};\n", - " var buttonGroup = document.createElement('div');\n", - " buttonGroup.classList = 'mpl-button-group';\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", - " /* Instead of a spacer, we start a new button group. */\n", - " if (buttonGroup.hasChildNodes()) {\n", - " toolbar.appendChild(buttonGroup);\n", - " }\n", - " buttonGroup = document.createElement('div');\n", - " buttonGroup.classList = 'mpl-button-group';\n", - " continue;\n", - " }\n", - "\n", - " var button = (fig.buttons[name] = document.createElement('button'));\n", - " button.classList = 'mpl-widget';\n", - " button.setAttribute('role', 'button');\n", - " button.setAttribute('aria-disabled', 'false');\n", - " button.addEventListener('click', on_click_closure(method_name));\n", - " button.addEventListener('mouseover', on_mouseover_closure(tooltip));\n", - "\n", - " var icon_img = document.createElement('img');\n", - " icon_img.src = '_images/' + image + '.png';\n", - " icon_img.srcset = '_images/' + image + '_large.png 2x';\n", - " icon_img.alt = tooltip;\n", - " button.appendChild(icon_img);\n", - "\n", - " buttonGroup.appendChild(button);\n", - " }\n", - "\n", - " if (buttonGroup.hasChildNodes()) {\n", - " toolbar.appendChild(buttonGroup);\n", - " }\n", - "\n", - " var fmt_picker = document.createElement('select');\n", - " fmt_picker.classList = 'mpl-widget';\n", - " toolbar.appendChild(fmt_picker);\n", - " this.format_dropdown = fmt_picker;\n", - "\n", - " for (var ind in mpl.extensions) {\n", - " var fmt = mpl.extensions[ind];\n", - " var option = document.createElement('option');\n", - " option.selected = fmt === mpl.default_extension;\n", - " option.innerHTML = fmt;\n", - " fmt_picker.appendChild(option);\n", - " }\n", - "\n", - " var status_bar = document.createElement('span');\n", - " status_bar.classList = 'mpl-message';\n", - " toolbar.appendChild(status_bar);\n", - " this.message = status_bar;\n", - "};\n", - "\n", - "mpl.figure.prototype.request_resize = function (x_pixels, y_pixels) {\n", - " // Request matplotlib to resize the figure. Matplotlib will then trigger a resize in the client,\n", - " // which will in turn request a refresh of the image.\n", - " this.send_message('resize', { width: x_pixels, height: y_pixels });\n", - "};\n", - "\n", - "mpl.figure.prototype.send_message = function (type, properties) {\n", - " properties['type'] = type;\n", - " properties['figure_id'] = this.id;\n", - " this.ws.send(JSON.stringify(properties));\n", - "};\n", - "\n", - "mpl.figure.prototype.send_draw_message = function () {\n", - " if (!this.waiting) {\n", - " this.waiting = true;\n", - " this.ws.send(JSON.stringify({ type: 'draw', figure_id: this.id }));\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_save = function (fig, _msg) {\n", - " var format_dropdown = fig.format_dropdown;\n", - " var format = format_dropdown.options[format_dropdown.selectedIndex].value;\n", - " fig.ondownload(fig, format);\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_resize = function (fig, msg) {\n", - " var size = msg['size'];\n", - " if (size[0] !== fig.canvas.width || size[1] !== fig.canvas.height) {\n", - " fig._resize_canvas(size[0], size[1], msg['forward']);\n", - " fig.send_message('refresh', {});\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_rubberband = function (fig, msg) {\n", - " var x0 = msg['x0'] / fig.ratio;\n", - " var y0 = (fig.canvas.height - msg['y0']) / fig.ratio;\n", - " var x1 = msg['x1'] / fig.ratio;\n", - " var y1 = (fig.canvas.height - msg['y1']) / fig.ratio;\n", - " x0 = Math.floor(x0) + 0.5;\n", - " y0 = Math.floor(y0) + 0.5;\n", - " x1 = Math.floor(x1) + 0.5;\n", - " y1 = Math.floor(y1) + 0.5;\n", - " var min_x = Math.min(x0, x1);\n", - " var min_y = Math.min(y0, y1);\n", - " var width = Math.abs(x1 - x0);\n", - " var height = Math.abs(y1 - y0);\n", - "\n", - " fig.rubberband_context.clearRect(\n", - " 0,\n", - " 0,\n", - " fig.canvas.width / fig.ratio,\n", - " fig.canvas.height / fig.ratio\n", - " );\n", - "\n", - " fig.rubberband_context.strokeRect(min_x, min_y, width, height);\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_figure_label = function (fig, msg) {\n", - " // Updates the figure title.\n", - " fig.header.textContent = msg['label'];\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_cursor = function (fig, msg) {\n", - " fig.canvas_div.style.cursor = msg['cursor'];\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_message = function (fig, msg) {\n", - " fig.message.textContent = msg['message'];\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_draw = function (fig, _msg) {\n", - " // Request the server to send over a new figure.\n", - " fig.send_draw_message();\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_image_mode = function (fig, msg) {\n", - " fig.image_mode = msg['mode'];\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_history_buttons = function (fig, msg) {\n", - " for (var key in msg) {\n", - " if (!(key in fig.buttons)) {\n", - " continue;\n", - " }\n", - " fig.buttons[key].disabled = !msg[key];\n", - " fig.buttons[key].setAttribute('aria-disabled', !msg[key]);\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_navigate_mode = function (fig, msg) {\n", - " if (msg['mode'] === 'PAN') {\n", - " fig.buttons['Pan'].classList.add('active');\n", - " fig.buttons['Zoom'].classList.remove('active');\n", - " } else if (msg['mode'] === 'ZOOM') {\n", - " fig.buttons['Pan'].classList.remove('active');\n", - " fig.buttons['Zoom'].classList.add('active');\n", - " } else {\n", - " fig.buttons['Pan'].classList.remove('active');\n", - " fig.buttons['Zoom'].classList.remove('active');\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.updated_canvas_event = function () {\n", - " // Called whenever the canvas gets updated.\n", - " this.send_message('ack', {});\n", - "};\n", - "\n", - "// A function to construct a web socket function for onmessage handling.\n", - "// Called in the figure constructor.\n", - "mpl.figure.prototype._make_on_message_function = function (fig) {\n", - " return function socket_on_message(evt) {\n", - " if (evt.data instanceof Blob) {\n", - " var img = evt.data;\n", - " if (img.type !== 'image/png') {\n", - " /* FIXME: We get \"Resource interpreted as Image but\n", - " * transferred with MIME type text/plain:\" errors on\n", - " * Chrome. But how to set the MIME type? It doesn't seem\n", - " * to be part of the websocket stream */\n", - " img.type = 'image/png';\n", - " }\n", - "\n", - " /* Free the memory for the previous frames */\n", - " if (fig.imageObj.src) {\n", - " (window.URL || window.webkitURL).revokeObjectURL(\n", - " fig.imageObj.src\n", - " );\n", - " }\n", - "\n", - " fig.imageObj.src = (window.URL || window.webkitURL).createObjectURL(\n", - " img\n", - " );\n", - " fig.updated_canvas_event();\n", - " fig.waiting = false;\n", - " return;\n", - " } else if (\n", - " typeof evt.data === 'string' &&\n", - " evt.data.slice(0, 21) === 'data:image/png;base64'\n", - " ) {\n", - " fig.imageObj.src = evt.data;\n", - " fig.updated_canvas_event();\n", - " fig.waiting = false;\n", - " return;\n", - " }\n", - "\n", - " var msg = JSON.parse(evt.data);\n", - " var msg_type = msg['type'];\n", - "\n", - " // Call the \"handle_{type}\" callback, which takes\n", - " // the figure and JSON message as its only arguments.\n", - " try {\n", - " var callback = fig['handle_' + msg_type];\n", - " } catch (e) {\n", - " console.log(\n", - " \"No handler for the '\" + msg_type + \"' message type: \",\n", - " msg\n", - " );\n", - " return;\n", - " }\n", - "\n", - " if (callback) {\n", - " try {\n", - " // console.log(\"Handling '\" + msg_type + \"' message: \", msg);\n", - " callback(fig, msg);\n", - " } catch (e) {\n", - " console.log(\n", - " \"Exception inside the 'handler_\" + msg_type + \"' callback:\",\n", - " e,\n", - " e.stack,\n", - " msg\n", - " );\n", - " }\n", - " }\n", - " };\n", - "};\n", - "\n", - "function getModifiers(event) {\n", - " var mods = [];\n", - " if (event.ctrlKey) {\n", - " mods.push('ctrl');\n", - " }\n", - " if (event.altKey) {\n", - " mods.push('alt');\n", - " }\n", - " if (event.shiftKey) {\n", - " mods.push('shift');\n", - " }\n", - " if (event.metaKey) {\n", - " mods.push('meta');\n", - " }\n", - " return mods;\n", - "}\n", - "\n", - "/*\n", - " * return a copy of an object with only non-object keys\n", - " * we need this to avoid circular references\n", - " * https://stackoverflow.com/a/24161582/3208463\n", - " */\n", - "function simpleKeys(original) {\n", - " return Object.keys(original).reduce(function (obj, key) {\n", - " if (typeof original[key] !== 'object') {\n", - " obj[key] = original[key];\n", - " }\n", - " return obj;\n", - " }, {});\n", - "}\n", - "\n", - "mpl.figure.prototype.mouse_event = function (event, name) {\n", - " if (name === 'button_press') {\n", - " this.canvas.focus();\n", - " this.canvas_div.focus();\n", - " }\n", - "\n", - " // from https://stackoverflow.com/q/1114465\n", - " var boundingRect = this.canvas.getBoundingClientRect();\n", - " var x = (event.clientX - boundingRect.left) * this.ratio;\n", - " var y = (event.clientY - boundingRect.top) * this.ratio;\n", - "\n", - " this.send_message(name, {\n", - " x: x,\n", - " y: y,\n", - " button: event.button,\n", - " step: event.step,\n", - " modifiers: getModifiers(event),\n", - " guiEvent: simpleKeys(event),\n", - " });\n", - "\n", - " return false;\n", - "};\n", - "\n", - "mpl.figure.prototype._key_event_extra = function (_event, _name) {\n", - " // Handle any extra behaviour associated with a key event\n", - "};\n", - "\n", - "mpl.figure.prototype.key_event = function (event, name) {\n", - " // Prevent repeat events\n", - " if (name === 'key_press') {\n", - " if (event.key === this._key) {\n", - " return;\n", - " } else {\n", - " this._key = event.key;\n", - " }\n", - " }\n", - " if (name === 'key_release') {\n", - " this._key = null;\n", - " }\n", - "\n", - " var value = '';\n", - " if (event.ctrlKey && event.key !== 'Control') {\n", - " value += 'ctrl+';\n", - " }\n", - " else if (event.altKey && event.key !== 'Alt') {\n", - " value += 'alt+';\n", - " }\n", - " else if (event.shiftKey && event.key !== 'Shift') {\n", - " value += 'shift+';\n", - " }\n", - "\n", - " value += 'k' + event.key;\n", - "\n", - " this._key_event_extra(event, name);\n", - "\n", - " this.send_message(name, { key: value, guiEvent: simpleKeys(event) });\n", - " return false;\n", - "};\n", - "\n", - "mpl.figure.prototype.toolbar_button_onclick = function (name) {\n", - " if (name === 'download') {\n", - " this.handle_save(this, null);\n", - " } else {\n", - " this.send_message('toolbar_button', { name: name });\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.toolbar_button_onmouseover = function (tooltip) {\n", - " this.message.textContent = tooltip;\n", - "};\n", - "\n", - "///////////////// REMAINING CONTENT GENERATED BY embed_js.py /////////////////\n", - "// prettier-ignore\n", - "var _JSXTOOLS_RESIZE_OBSERVER=function(A){var t,i=new WeakMap,n=new WeakMap,a=new WeakMap,r=new WeakMap,o=new Set;function s(e){if(!(this instanceof s))throw new TypeError(\"Constructor requires 'new' operator\");i.set(this,e)}function h(){throw new TypeError(\"Function is not a constructor\")}function c(e,t,i,n){e=0 in arguments?Number(arguments[0]):0,t=1 in arguments?Number(arguments[1]):0,i=2 in arguments?Number(arguments[2]):0,n=3 in arguments?Number(arguments[3]):0,this.right=(this.x=this.left=e)+(this.width=i),this.bottom=(this.y=this.top=t)+(this.height=n),Object.freeze(this)}function d(){t=requestAnimationFrame(d);var s=new WeakMap,p=new Set;o.forEach((function(t){r.get(t).forEach((function(i){var r=t instanceof window.SVGElement,o=a.get(t),d=r?0:parseFloat(o.paddingTop),f=r?0:parseFloat(o.paddingRight),l=r?0:parseFloat(o.paddingBottom),u=r?0:parseFloat(o.paddingLeft),g=r?0:parseFloat(o.borderTopWidth),m=r?0:parseFloat(o.borderRightWidth),w=r?0:parseFloat(o.borderBottomWidth),b=u+f,F=d+l,v=(r?0:parseFloat(o.borderLeftWidth))+m,W=g+w,y=r?0:t.offsetHeight-W-t.clientHeight,E=r?0:t.offsetWidth-v-t.clientWidth,R=b+v,z=F+W,M=r?t.width:parseFloat(o.width)-R-E,O=r?t.height:parseFloat(o.height)-z-y;if(n.has(t)){var k=n.get(t);if(k[0]===M&&k[1]===O)return}n.set(t,[M,O]);var S=Object.create(h.prototype);S.target=t,S.contentRect=new c(u,d,M,O),s.has(i)||(s.set(i,[]),p.add(i)),s.get(i).push(S)}))})),p.forEach((function(e){i.get(e).call(e,s.get(e),e)}))}return s.prototype.observe=function(i){if(i instanceof window.Element){r.has(i)||(r.set(i,new Set),o.add(i),a.set(i,window.getComputedStyle(i)));var n=r.get(i);n.has(this)||n.add(this),cancelAnimationFrame(t),t=requestAnimationFrame(d)}},s.prototype.unobserve=function(i){if(i instanceof window.Element&&r.has(i)){var n=r.get(i);n.has(this)&&(n.delete(this),n.size||(r.delete(i),o.delete(i))),n.size||r.delete(i),o.size||cancelAnimationFrame(t)}},A.DOMRectReadOnly=c,A.ResizeObserver=s,A.ResizeObserverEntry=h,A}; // eslint-disable-line\n", - "mpl.toolbar_items = [[\"Home\", \"Reset original view\", \"fa fa-home\", \"home\"], [\"Back\", \"Back to previous view\", \"fa fa-arrow-left\", \"back\"], [\"Forward\", \"Forward to next view\", \"fa fa-arrow-right\", \"forward\"], [\"\", \"\", \"\", \"\"], [\"Pan\", \"Left button pans, Right button zooms\\nx/y fixes axis, CTRL fixes aspect\", \"fa fa-arrows\", \"pan\"], [\"Zoom\", \"Zoom to rectangle\\nx/y fixes axis\", \"fa fa-square-o\", \"zoom\"], [\"\", \"\", \"\", \"\"], [\"Download\", \"Download plot\", \"fa fa-floppy-o\", \"download\"]];\n", - "\n", - "mpl.extensions = [\"eps\", \"jpeg\", \"pgf\", \"pdf\", \"png\", \"ps\", \"raw\", \"svg\", \"tif\", \"webp\"];\n", - "\n", - "mpl.default_extension = \"png\";/* global mpl */\n", - "\n", - "var comm_websocket_adapter = function (comm) {\n", - " // Create a \"websocket\"-like object which calls the given IPython comm\n", - " // object with the appropriate methods. Currently this is a non binary\n", - " // socket, so there is still some room for performance tuning.\n", - " var ws = {};\n", - "\n", - " ws.binaryType = comm.kernel.ws.binaryType;\n", - " ws.readyState = comm.kernel.ws.readyState;\n", - " function updateReadyState(_event) {\n", - " if (comm.kernel.ws) {\n", - " ws.readyState = comm.kernel.ws.readyState;\n", - " } else {\n", - " ws.readyState = 3; // Closed state.\n", - " }\n", - " }\n", - " comm.kernel.ws.addEventListener('open', updateReadyState);\n", - " comm.kernel.ws.addEventListener('close', updateReadyState);\n", - " comm.kernel.ws.addEventListener('error', updateReadyState);\n", - "\n", - " ws.close = function () {\n", - " comm.close();\n", - " };\n", - " ws.send = function (m) {\n", - " //console.log('sending', m);\n", - " comm.send(m);\n", - " };\n", - " // Register the callback with on_msg.\n", - " comm.on_msg(function (msg) {\n", - " //console.log('receiving', msg['content']['data'], msg);\n", - " var data = msg['content']['data'];\n", - " if (data['blob'] !== undefined) {\n", - " data = {\n", - " data: new Blob(msg['buffers'], { type: data['blob'] }),\n", - " };\n", - " }\n", - " // Pass the mpl event to the overridden (by mpl) onmessage function.\n", - " ws.onmessage(data);\n", - " });\n", - " return ws;\n", - "};\n", - "\n", - "mpl.mpl_figure_comm = function (comm, msg) {\n", - " // This is the function which gets called when the mpl process\n", - " // starts-up an IPython Comm through the \"matplotlib\" channel.\n", - "\n", - " var id = msg.content.data.id;\n", - " // Get hold of the div created by the display call when the Comm\n", - " // socket was opened in Python.\n", - " var element = document.getElementById(id);\n", - " var ws_proxy = comm_websocket_adapter(comm);\n", - "\n", - " function ondownload(figure, _format) {\n", - " window.open(figure.canvas.toDataURL());\n", - " }\n", - "\n", - " var fig = new mpl.figure(id, ws_proxy, ondownload, element);\n", - "\n", - " // Call onopen now - mpl needs it, as it is assuming we've passed it a real\n", - " // web socket which is closed, not our websocket->open comm proxy.\n", - " ws_proxy.onopen();\n", - "\n", - " fig.parent_element = element;\n", - " fig.cell_info = mpl.find_output_cell(\"
\");\n", - " if (!fig.cell_info) {\n", - " console.error('Failed to find cell for figure', id, fig);\n", - " return;\n", - " }\n", - " fig.cell_info[0].output_area.element.on(\n", - " 'cleared',\n", - " { fig: fig },\n", - " fig._remove_fig_handler\n", - " );\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_close = function (fig, msg) {\n", - " var width = fig.canvas.width / fig.ratio;\n", - " fig.cell_info[0].output_area.element.off(\n", - " 'cleared',\n", - " fig._remove_fig_handler\n", - " );\n", - " fig.resizeObserverInstance.unobserve(fig.canvas_div);\n", - "\n", - " // Update the output cell to use the data from the current canvas.\n", - " fig.push_to_output();\n", - " var dataURL = fig.canvas.toDataURL();\n", - " // Re-enable the keyboard manager in IPython - without this line, in FF,\n", - " // the notebook keyboard shortcuts fail.\n", - " IPython.keyboard_manager.enable();\n", - " fig.parent_element.innerHTML =\n", - " '';\n", - " fig.close_ws(fig, msg);\n", - "};\n", - "\n", - "mpl.figure.prototype.close_ws = function (fig, msg) {\n", - " fig.send_message('closing', msg);\n", - " // fig.ws.close()\n", - "};\n", - "\n", - "mpl.figure.prototype.push_to_output = function (_remove_interactive) {\n", - " // Turn the data on the canvas into data in the output cell.\n", - " var width = this.canvas.width / this.ratio;\n", - " var dataURL = this.canvas.toDataURL();\n", - " this.cell_info[1]['text/html'] =\n", - " '';\n", - "};\n", - "\n", - "mpl.figure.prototype.updated_canvas_event = function () {\n", - " // Tell IPython that the notebook contents must change.\n", - " IPython.notebook.set_dirty(true);\n", - " this.send_message('ack', {});\n", - " var fig = this;\n", - " // Wait a second, then push the new image to the DOM so\n", - " // that it is saved nicely (might be nice to debounce this).\n", - " setTimeout(function () {\n", - " fig.push_to_output();\n", - " }, 1000);\n", - "};\n", - "\n", - "mpl.figure.prototype._init_toolbar = function () {\n", - " var fig = this;\n", - "\n", - " var toolbar = document.createElement('div');\n", - " toolbar.classList = 'btn-toolbar';\n", - " this.root.appendChild(toolbar);\n", - "\n", - " function on_click_closure(name) {\n", - " return function (_event) {\n", - " return fig.toolbar_button_onclick(name);\n", - " };\n", - " }\n", - "\n", - " function on_mouseover_closure(tooltip) {\n", - " return function (event) {\n", - " if (!event.currentTarget.disabled) {\n", - " return fig.toolbar_button_onmouseover(tooltip);\n", - " }\n", - " };\n", - " }\n", - "\n", - " fig.buttons = {};\n", - " var buttonGroup = document.createElement('div');\n", - " buttonGroup.classList = 'btn-group';\n", - " var button;\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", - " /* Instead of a spacer, we start a new button group. */\n", - " if (buttonGroup.hasChildNodes()) {\n", - " toolbar.appendChild(buttonGroup);\n", - " }\n", - " buttonGroup = document.createElement('div');\n", - " buttonGroup.classList = 'btn-group';\n", - " continue;\n", - " }\n", - "\n", - " button = fig.buttons[name] = document.createElement('button');\n", - " button.classList = 'btn btn-default';\n", - " button.href = '#';\n", - " button.title = name;\n", - " button.innerHTML = '';\n", - " button.addEventListener('click', on_click_closure(method_name));\n", - " button.addEventListener('mouseover', on_mouseover_closure(tooltip));\n", - " buttonGroup.appendChild(button);\n", - " }\n", - "\n", - " if (buttonGroup.hasChildNodes()) {\n", - " toolbar.appendChild(buttonGroup);\n", - " }\n", - "\n", - " // Add the status bar.\n", - " var status_bar = document.createElement('span');\n", - " status_bar.classList = 'mpl-message pull-right';\n", - " toolbar.appendChild(status_bar);\n", - " this.message = status_bar;\n", - "\n", - " // Add the close button to the window.\n", - " var buttongrp = document.createElement('div');\n", - " buttongrp.classList = 'btn-group inline pull-right';\n", - " button = document.createElement('button');\n", - " button.classList = 'btn btn-mini btn-primary';\n", - " button.href = '#';\n", - " button.title = 'Stop Interaction';\n", - " button.innerHTML = '';\n", - " button.addEventListener('click', function (_evt) {\n", - " fig.handle_close(fig, {});\n", - " });\n", - " button.addEventListener(\n", - " 'mouseover',\n", - " on_mouseover_closure('Stop Interaction')\n", - " );\n", - " buttongrp.appendChild(button);\n", - " var titlebar = this.root.querySelector('.ui-dialog-titlebar');\n", - " titlebar.insertBefore(buttongrp, titlebar.firstChild);\n", - "};\n", - "\n", - "mpl.figure.prototype._remove_fig_handler = function (event) {\n", - " var fig = event.data.fig;\n", - " if (event.target !== this) {\n", - " // Ignore bubbled events from children.\n", - " return;\n", - " }\n", - " fig.close_ws(fig, {});\n", - "};\n", - "\n", - "mpl.figure.prototype._root_extra_style = function (el) {\n", - " el.style.boxSizing = 'content-box'; // override notebook setting of border-box.\n", - "};\n", - "\n", - "mpl.figure.prototype._canvas_extra_style = function (el) {\n", - " // this is important to make the div 'focusable\n", - " el.setAttribute('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", - " } else {\n", - " // location in version 2\n", - " IPython.keyboard_manager.register_events(el);\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype._key_event_extra = function (event, _name) {\n", - " // Check for shift+enter\n", - " if (event.shiftKey && event.which === 13) {\n", - " this.canvas_div.blur();\n", - " // select the cell after this one\n", - " var index = IPython.notebook.find_cell_index(this.cell_info[0]);\n", - " IPython.notebook.select(index + 1);\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_save = function (fig, _msg) {\n", - " fig.ondownload(fig, null);\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 < ncells; i++) {\n", - " var cell = cells[i];\n", - " if (cell.cell_type === 'code') {\n", - " for (var j = 0; j < cell.output_area.outputs.length; j++) {\n", - " var data = cell.output_area.outputs[j];\n", - " if (data.data) {\n", - " // IPython >= 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(\n", - " 'matplotlib',\n", - " mpl.mpl_figure_comm\n", - " );\n", - "}\n" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/html": [ - "
" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "Observation: obs0\n", - "Filter: TESS\n", - "Epoch: 694\n", - "Number of outliers removed: 0\n", - "Uncertainties scale factor: 1\n", - "Residuals statistics:\n", - "res_max_autocorr: \t 0.12958710106102606\n", - "res_max_autocorr_flag: \t False\n", - "res_shapiro: \t\t 0.9927231073379517\n", - "res_shapiro_flag: \t False\n", - "res_mean: \t\t 2.3347082417404584e-06\n", - "res_std: \t\t 0.0023395315947714857\n", - "res_rms: \t\t 0.0023395327597186123\n", - "res_chi_sqr: \t\t 251.09963618717916\n", - "res_red_chi_sqr: \t 0.9657678314891506\n" - ] - } - ], - "source": [ - "\n", - "###############################################################################################\n", - "##### Test the performance of the trend function \n", - "###############################################################################################\n", - "\n", - "# We can test the performance of the trend function with quick fit, using: \n", - "# optimiser = 'curve_fit'.\n", - "# Here, the quality of the data is good enough to fit for the orbital parameters (sma and i):\n", - "# fit_sma_over_rs = True\n", - "# fit_inclination = True.\n", - "\n", - "test = planet.transit_fitting(\n", - " optimiser = 'curve_fit',\n", - " fit_sma_over_rs=True, \n", - " fit_inclination=True,\n", - ")\n", - "\n", - "###############################################################################################\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "###############################################################################################\n", - "##### Evaluate test results\n", - "###############################################################################################\n", - "\n", - "# To evaluate the test results we can plot the raw data, trend function, and residuals like this:\n", - "\n", - "observations = len(test['observations'])\n", - "plt.figure(figsize=(9,6))\n", - "for obs_n, obs_id in enumerate(test['observations']):\n", - " observation = test['observations'][obs_id]\n", - " plt.subplot(2, observations, obs_n + 1)\n", - " plt.errorbar(observation['input_series']['time'], \n", - " observation['input_series']['flux'], \n", - " observation['input_series']['flux_unc'], \n", - " fmt='o', zorder=0, label='raw data')\n", - " plt.plot(observation['input_series']['time'], observation['output_series']['trend'], 'r--', zorder=1, \n", - " label='trend model')\n", - " plt.plot(observation['input_series']['time'], observation['output_series']['model'], 'r-', zorder=1,\n", - " label='trend + transit model'\n", - " )\n", - " plt.legend(fontsize='small')\n", - " plt.ylabel('rel. flux')\n", - " plt.title(obs_id)\n", - "\n", - " plt.subplot(2, observations, observations + 1)\n", - " plt.errorbar(observation['input_series']['time'], \n", - " observation['output_series']['residuals'], \n", - " observation['input_series']['flux_unc'], \n", - " fmt='o', zorder=0)\n", - " plt.xlabel('time (BJD_TDB)')\n", - " plt.ylabel('rel. flux residuals')\n", - "\n", - " \n", - " \n", - "# And also print the residuals diagnostics like this:\n", - "\n", - "for obs_n, obs_id in enumerate(test['observations']):\n", - " observation = test['observations'][obs_id]\n", - " print('')\n", - " print('Observation: ', obs_id)\n", - " print('Filter: ', observation['model_info']['filter_id'])\n", - " print('Epoch: ', observation['model_info']['epoch'])\n", - " print('Number of outliers removed: ', observation['data_conversion_info']['outliers'])\n", - " print('Uncertainties scale factor: ', observation['data_conversion_info']['scale_factor'])\n", - "\n", - " print('Residuals statistics:')\n", - " print('res_max_autocorr:', '\\t', observation['statistics']['res_max_autocorr'])\n", - " print('res_max_autocorr_flag:', '\\t', observation['statistics']['res_max_autocorr_flag'])\n", - " print('res_shapiro:', '\\t\\t', observation['statistics']['res_shapiro'])\n", - " print('res_shapiro_flag:', '\\t', observation['statistics']['res_shapiro_flag'])\n", - " print('res_mean:', '\\t\\t', observation['statistics']['res_mean'])\n", - " print('res_std:', '\\t\\t', observation['statistics']['res_std'])\n", - " print('res_rms:', '\\t\\t', observation['statistics']['res_rms'])\n", - " print('res_chi_sqr:', '\\t\\t', observation['statistics']['res_chi_sqr'])\n", - " print('res_red_chi_sqr:', '\\t', observation['statistics']['res_red_chi_sqr'])\n", - " \n", - "###############################################################################################\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "0a5ae6df", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "Observation: obs0\n", - "Filter: TESS\n", - "Epoch: 694\n", - "Data-points excluded: 0\n", - "Scaling uncertainties by: 0.9827382245304214\n", - "\n", - "Optimising initial parameters...\n", - "\u001b[KTransit fitting: 1190 / 5000 , time left: 0:04:35, time elapsed: 0:01:25, total time: 0:06:01" - ] - } - ], - "source": [ - "\n", - "###############################################################################################\n", - "##### MCMC fit\n", - "###############################################################################################\n", - "\n", - "# If the residuals diagniostics look ok, we can run the MCMC.\n", - "# Here we will define the 'output_folder', so that all the results and plots are saved.\n", - "# We don't need to defile the optimiser, as the default one is 'mcmc'.\n", - "# It is also better to use filter_outliers=True to clear the outliers and \n", - "# and scale_uncertainties=True to scale the errorbars to match the residuals rms.\n", - "\n", - "final = planet.transit_fitting(\n", - " output_folder = 'wasp39b_tess',\n", - " fit_sma_over_rs=True, \n", - " fit_inclination=True,\n", - " filter_outliers=True,\n", - " scale_uncertainties=True,\n", - ")\n", - "\n", - "# By default, the number of iterations is 5000 and the burn in is 1000.\n", - "# If the chains do not converge, we can increase these number, for example by setting:\n", - "# iterations = 10000\n", - "# burn_in = 5000\n", - "\n", - "###############################################################################################\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "535dc50c", - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "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.11.5" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/notebooks/2_detrending_examples/.ipynb_checkpoints/3_wasp39b_jwst-checkpoint.ipynb b/notebooks/2_detrending_examples/.ipynb_checkpoints/3_wasp39b_jwst-checkpoint.ipynb deleted file mode 100644 index e4b6d01..0000000 --- a/notebooks/2_detrending_examples/.ipynb_checkpoints/3_wasp39b_jwst-checkpoint.ipynb +++ /dev/null @@ -1,2384 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "id": "988b5848", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "exoclock: Checking ephemerides database...\n", - "exoclock: Checking catalogues database...\n", - "exoclock: Checking ut database...\n", - "pylightcurve: Checking exotethys database...\n", - "pylightcurve: Checking photometry database...\n" - ] - } - ], - "source": [ - "%matplotlib notebook\n", - "import matplotlib.pyplot as plt\n", - "import pylightcurve as plc\n", - "import numpy as np\n", - "\n", - "\n", - "###############################################################################################\n", - "##### Create a Planet object\n", - "###############################################################################################\n", - "\n", - "# At first we need to create a Planet object.\n", - "# Planets include in the ExoClock project (https://www.exoclock.space/database/planets)\n", - "# can be loaded automatically. \n", - "# Alteranatively we can difine our custom Planet object (see notebook: The Planet class)\n", - "\n", - "planet = plc.get_planet('WASP-39b')\n", - "\n", - "###############################################################################################\n" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "id": "ec49ad07", - "metadata": {}, - "outputs": [ - { - "data": { - "application/javascript": [ - "/* Put everything inside the global mpl namespace */\n", - "/* global mpl */\n", - "window.mpl = {};\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(\n", - " '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", - "\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 = document.createElement('div');\n", - " this.root.setAttribute('style', 'display: inline-block');\n", - " this._root_extra_style(this.root);\n", - "\n", - " parent_element.appendChild(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 (fig.ratio !== 1) {\n", - " fig.send_message('set_device_pixel_ratio', {\n", - " device_pixel_ratio: fig.ratio,\n", - " });\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 = document.createElement('div');\n", - " titlebar.classList =\n", - " 'ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix';\n", - " var titletext = document.createElement('div');\n", - " titletext.classList = 'ui-dialog-title';\n", - " titletext.setAttribute(\n", - " 'style',\n", - " 'width: 100%; text-align: center; padding: 3px;'\n", - " );\n", - " titlebar.appendChild(titletext);\n", - " this.root.appendChild(titlebar);\n", - " this.header = titletext;\n", - "};\n", - "\n", - "mpl.figure.prototype._canvas_extra_style = function (_canvas_div) {};\n", - "\n", - "mpl.figure.prototype._root_extra_style = function (_canvas_div) {};\n", - "\n", - "mpl.figure.prototype._init_canvas = function () {\n", - " var fig = this;\n", - "\n", - " var canvas_div = (this.canvas_div = document.createElement('div'));\n", - " canvas_div.setAttribute('tabindex', '0');\n", - " canvas_div.setAttribute(\n", - " 'style',\n", - " 'border: 1px solid #ddd;' +\n", - " 'box-sizing: content-box;' +\n", - " 'clear: both;' +\n", - " 'min-height: 1px;' +\n", - " 'min-width: 1px;' +\n", - " 'outline: 0;' +\n", - " 'overflow: hidden;' +\n", - " 'position: relative;' +\n", - " 'resize: both;' +\n", - " 'z-index: 2;'\n", - " );\n", - "\n", - " function on_keyboard_event_closure(name) {\n", - " return function (event) {\n", - " return fig.key_event(event, name);\n", - " };\n", - " }\n", - "\n", - " canvas_div.addEventListener(\n", - " 'keydown',\n", - " on_keyboard_event_closure('key_press')\n", - " );\n", - " canvas_div.addEventListener(\n", - " 'keyup',\n", - " on_keyboard_event_closure('key_release')\n", - " );\n", - "\n", - " this._canvas_extra_style(canvas_div);\n", - " this.root.appendChild(canvas_div);\n", - "\n", - " var canvas = (this.canvas = document.createElement('canvas'));\n", - " canvas.classList.add('mpl-canvas');\n", - " canvas.setAttribute(\n", - " 'style',\n", - " 'box-sizing: content-box;' +\n", - " 'pointer-events: none;' +\n", - " 'position: relative;' +\n", - " 'z-index: 0;'\n", - " );\n", - "\n", - " this.context = canvas.getContext('2d');\n", - "\n", - " var backingStore =\n", - " this.context.backingStorePixelRatio ||\n", - " this.context.webkitBackingStorePixelRatio ||\n", - " this.context.mozBackingStorePixelRatio ||\n", - " this.context.msBackingStorePixelRatio ||\n", - " this.context.oBackingStorePixelRatio ||\n", - " this.context.backingStorePixelRatio ||\n", - " 1;\n", - "\n", - " this.ratio = (window.devicePixelRatio || 1) / backingStore;\n", - "\n", - " var rubberband_canvas = (this.rubberband_canvas = document.createElement(\n", - " 'canvas'\n", - " ));\n", - " rubberband_canvas.setAttribute(\n", - " 'style',\n", - " 'box-sizing: content-box;' +\n", - " 'left: 0;' +\n", - " 'pointer-events: none;' +\n", - " 'position: absolute;' +\n", - " 'top: 0;' +\n", - " 'z-index: 1;'\n", - " );\n", - "\n", - " // Apply a ponyfill if ResizeObserver is not implemented by browser.\n", - " if (this.ResizeObserver === undefined) {\n", - " if (window.ResizeObserver !== undefined) {\n", - " this.ResizeObserver = window.ResizeObserver;\n", - " } else {\n", - " var obs = _JSXTOOLS_RESIZE_OBSERVER({});\n", - " this.ResizeObserver = obs.ResizeObserver;\n", - " }\n", - " }\n", - "\n", - " this.resizeObserverInstance = new this.ResizeObserver(function (entries) {\n", - " // There's no need to resize if the WebSocket is not connected:\n", - " // - If it is still connecting, then we will get an initial resize from\n", - " // Python once it connects.\n", - " // - If it has disconnected, then resizing will clear the canvas and\n", - " // never get anything back to refill it, so better to not resize and\n", - " // keep something visible.\n", - " if (fig.ws.readyState != 1) {\n", - " return;\n", - " }\n", - " var nentries = entries.length;\n", - " for (var i = 0; i < nentries; i++) {\n", - " var entry = entries[i];\n", - " var width, height;\n", - " if (entry.contentBoxSize) {\n", - " if (entry.contentBoxSize instanceof Array) {\n", - " // Chrome 84 implements new version of spec.\n", - " width = entry.contentBoxSize[0].inlineSize;\n", - " height = entry.contentBoxSize[0].blockSize;\n", - " } else {\n", - " // Firefox implements old version of spec.\n", - " width = entry.contentBoxSize.inlineSize;\n", - " height = entry.contentBoxSize.blockSize;\n", - " }\n", - " } else {\n", - " // Chrome <84 implements even older version of spec.\n", - " width = entry.contentRect.width;\n", - " height = entry.contentRect.height;\n", - " }\n", - "\n", - " // Keep the size of the canvas and rubber band canvas in sync with\n", - " // the canvas container.\n", - " if (entry.devicePixelContentBoxSize) {\n", - " // Chrome 84 implements new version of spec.\n", - " canvas.setAttribute(\n", - " 'width',\n", - " entry.devicePixelContentBoxSize[0].inlineSize\n", - " );\n", - " canvas.setAttribute(\n", - " 'height',\n", - " entry.devicePixelContentBoxSize[0].blockSize\n", - " );\n", - " } else {\n", - " canvas.setAttribute('width', width * fig.ratio);\n", - " canvas.setAttribute('height', height * fig.ratio);\n", - " }\n", - " /* This rescales the canvas back to display pixels, so that it\n", - " * appears correct on HiDPI screens. */\n", - " canvas.style.width = width + 'px';\n", - " canvas.style.height = height + 'px';\n", - "\n", - " rubberband_canvas.setAttribute('width', width);\n", - " rubberband_canvas.setAttribute('height', height);\n", - "\n", - " // And update the size in Python. We ignore the initial 0/0 size\n", - " // that occurs as the element is placed into the DOM, which should\n", - " // otherwise not happen due to the minimum size styling.\n", - " if (width != 0 && height != 0) {\n", - " fig.request_resize(width, height);\n", - " }\n", - " }\n", - " });\n", - " this.resizeObserverInstance.observe(canvas_div);\n", - "\n", - " function on_mouse_event_closure(name) {\n", - " /* User Agent sniffing is bad, but WebKit is busted:\n", - " * https://bugs.webkit.org/show_bug.cgi?id=144526\n", - " * https://bugs.webkit.org/show_bug.cgi?id=181818\n", - " * The worst that happens here is that they get an extra browser\n", - " * selection when dragging, if this check fails to catch them.\n", - " */\n", - " var UA = navigator.userAgent;\n", - " var isWebKit = /AppleWebKit/.test(UA) && !/Chrome/.test(UA);\n", - " if(isWebKit) {\n", - " return function (event) {\n", - " /* This prevents the web browser from automatically changing to\n", - " * the text insertion cursor when the button is pressed. We\n", - " * want to control all of the cursor setting manually through\n", - " * the 'cursor' event from matplotlib */\n", - " event.preventDefault()\n", - " return fig.mouse_event(event, name);\n", - " };\n", - " } else {\n", - " return function (event) {\n", - " return fig.mouse_event(event, name);\n", - " };\n", - " }\n", - " }\n", - "\n", - " canvas_div.addEventListener(\n", - " 'mousedown',\n", - " on_mouse_event_closure('button_press')\n", - " );\n", - " canvas_div.addEventListener(\n", - " 'mouseup',\n", - " on_mouse_event_closure('button_release')\n", - " );\n", - " canvas_div.addEventListener(\n", - " 'dblclick',\n", - " on_mouse_event_closure('dblclick')\n", - " );\n", - " // Throttle sequential mouse events to 1 every 20ms.\n", - " canvas_div.addEventListener(\n", - " 'mousemove',\n", - " on_mouse_event_closure('motion_notify')\n", - " );\n", - "\n", - " canvas_div.addEventListener(\n", - " 'mouseenter',\n", - " on_mouse_event_closure('figure_enter')\n", - " );\n", - " canvas_div.addEventListener(\n", - " 'mouseleave',\n", - " on_mouse_event_closure('figure_leave')\n", - " );\n", - "\n", - " canvas_div.addEventListener('wheel', function (event) {\n", - " if (event.deltaY < 0) {\n", - " event.step = 1;\n", - " } else {\n", - " event.step = -1;\n", - " }\n", - " on_mouse_event_closure('scroll')(event);\n", - " });\n", - "\n", - " canvas_div.appendChild(canvas);\n", - " canvas_div.appendChild(rubberband_canvas);\n", - "\n", - " this.rubberband_context = rubberband_canvas.getContext('2d');\n", - " this.rubberband_context.strokeStyle = '#000000';\n", - "\n", - " this._resize_canvas = function (width, height, forward) {\n", - " if (forward) {\n", - " canvas_div.style.width = width + 'px';\n", - " canvas_div.style.height = height + 'px';\n", - " }\n", - " };\n", - "\n", - " // Disable right mouse context menu.\n", - " canvas_div.addEventListener('contextmenu', function (_e) {\n", - " event.preventDefault();\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 toolbar = document.createElement('div');\n", - " toolbar.classList = 'mpl-toolbar';\n", - " this.root.appendChild(toolbar);\n", - "\n", - " function on_click_closure(name) {\n", - " return function (_event) {\n", - " return fig.toolbar_button_onclick(name);\n", - " };\n", - " }\n", - "\n", - " function on_mouseover_closure(tooltip) {\n", - " return function (event) {\n", - " if (!event.currentTarget.disabled) {\n", - " return fig.toolbar_button_onmouseover(tooltip);\n", - " }\n", - " };\n", - " }\n", - "\n", - " fig.buttons = {};\n", - " var buttonGroup = document.createElement('div');\n", - " buttonGroup.classList = 'mpl-button-group';\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", - " /* Instead of a spacer, we start a new button group. */\n", - " if (buttonGroup.hasChildNodes()) {\n", - " toolbar.appendChild(buttonGroup);\n", - " }\n", - " buttonGroup = document.createElement('div');\n", - " buttonGroup.classList = 'mpl-button-group';\n", - " continue;\n", - " }\n", - "\n", - " var button = (fig.buttons[name] = document.createElement('button'));\n", - " button.classList = 'mpl-widget';\n", - " button.setAttribute('role', 'button');\n", - " button.setAttribute('aria-disabled', 'false');\n", - " button.addEventListener('click', on_click_closure(method_name));\n", - " button.addEventListener('mouseover', on_mouseover_closure(tooltip));\n", - "\n", - " var icon_img = document.createElement('img');\n", - " icon_img.src = '_images/' + image + '.png';\n", - " icon_img.srcset = '_images/' + image + '_large.png 2x';\n", - " icon_img.alt = tooltip;\n", - " button.appendChild(icon_img);\n", - "\n", - " buttonGroup.appendChild(button);\n", - " }\n", - "\n", - " if (buttonGroup.hasChildNodes()) {\n", - " toolbar.appendChild(buttonGroup);\n", - " }\n", - "\n", - " var fmt_picker = document.createElement('select');\n", - " fmt_picker.classList = 'mpl-widget';\n", - " toolbar.appendChild(fmt_picker);\n", - " this.format_dropdown = fmt_picker;\n", - "\n", - " for (var ind in mpl.extensions) {\n", - " var fmt = mpl.extensions[ind];\n", - " var option = document.createElement('option');\n", - " option.selected = fmt === mpl.default_extension;\n", - " option.innerHTML = fmt;\n", - " fmt_picker.appendChild(option);\n", - " }\n", - "\n", - " var status_bar = document.createElement('span');\n", - " status_bar.classList = 'mpl-message';\n", - " toolbar.appendChild(status_bar);\n", - " this.message = status_bar;\n", - "};\n", - "\n", - "mpl.figure.prototype.request_resize = function (x_pixels, y_pixels) {\n", - " // Request matplotlib to resize the figure. Matplotlib will then trigger a resize in the client,\n", - " // which will in turn request a refresh of the image.\n", - " this.send_message('resize', { width: x_pixels, height: y_pixels });\n", - "};\n", - "\n", - "mpl.figure.prototype.send_message = function (type, properties) {\n", - " properties['type'] = type;\n", - " properties['figure_id'] = this.id;\n", - " this.ws.send(JSON.stringify(properties));\n", - "};\n", - "\n", - "mpl.figure.prototype.send_draw_message = function () {\n", - " if (!this.waiting) {\n", - " this.waiting = true;\n", - " this.ws.send(JSON.stringify({ type: 'draw', figure_id: this.id }));\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_save = function (fig, _msg) {\n", - " var format_dropdown = fig.format_dropdown;\n", - " var format = format_dropdown.options[format_dropdown.selectedIndex].value;\n", - " fig.ondownload(fig, format);\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_resize = function (fig, msg) {\n", - " var size = msg['size'];\n", - " if (size[0] !== fig.canvas.width || size[1] !== fig.canvas.height) {\n", - " fig._resize_canvas(size[0], size[1], msg['forward']);\n", - " fig.send_message('refresh', {});\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_rubberband = function (fig, msg) {\n", - " var x0 = msg['x0'] / fig.ratio;\n", - " var y0 = (fig.canvas.height - msg['y0']) / fig.ratio;\n", - " var x1 = msg['x1'] / fig.ratio;\n", - " var y1 = (fig.canvas.height - msg['y1']) / fig.ratio;\n", - " x0 = Math.floor(x0) + 0.5;\n", - " y0 = Math.floor(y0) + 0.5;\n", - " x1 = Math.floor(x1) + 0.5;\n", - " y1 = Math.floor(y1) + 0.5;\n", - " var min_x = Math.min(x0, x1);\n", - " var min_y = Math.min(y0, y1);\n", - " var width = Math.abs(x1 - x0);\n", - " var height = Math.abs(y1 - y0);\n", - "\n", - " fig.rubberband_context.clearRect(\n", - " 0,\n", - " 0,\n", - " fig.canvas.width / fig.ratio,\n", - " fig.canvas.height / fig.ratio\n", - " );\n", - "\n", - " fig.rubberband_context.strokeRect(min_x, min_y, width, height);\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_figure_label = function (fig, msg) {\n", - " // Updates the figure title.\n", - " fig.header.textContent = msg['label'];\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_cursor = function (fig, msg) {\n", - " fig.canvas_div.style.cursor = msg['cursor'];\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_message = function (fig, msg) {\n", - " fig.message.textContent = msg['message'];\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_draw = function (fig, _msg) {\n", - " // Request the server to send over a new figure.\n", - " fig.send_draw_message();\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_image_mode = function (fig, msg) {\n", - " fig.image_mode = msg['mode'];\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_history_buttons = function (fig, msg) {\n", - " for (var key in msg) {\n", - " if (!(key in fig.buttons)) {\n", - " continue;\n", - " }\n", - " fig.buttons[key].disabled = !msg[key];\n", - " fig.buttons[key].setAttribute('aria-disabled', !msg[key]);\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_navigate_mode = function (fig, msg) {\n", - " if (msg['mode'] === 'PAN') {\n", - " fig.buttons['Pan'].classList.add('active');\n", - " fig.buttons['Zoom'].classList.remove('active');\n", - " } else if (msg['mode'] === 'ZOOM') {\n", - " fig.buttons['Pan'].classList.remove('active');\n", - " fig.buttons['Zoom'].classList.add('active');\n", - " } else {\n", - " fig.buttons['Pan'].classList.remove('active');\n", - " fig.buttons['Zoom'].classList.remove('active');\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.updated_canvas_event = function () {\n", - " // Called whenever the canvas gets updated.\n", - " this.send_message('ack', {});\n", - "};\n", - "\n", - "// A function to construct a web socket function for onmessage handling.\n", - "// Called in the figure constructor.\n", - "mpl.figure.prototype._make_on_message_function = function (fig) {\n", - " return function socket_on_message(evt) {\n", - " if (evt.data instanceof Blob) {\n", - " var img = evt.data;\n", - " if (img.type !== 'image/png') {\n", - " /* FIXME: We get \"Resource interpreted as Image but\n", - " * transferred with MIME type text/plain:\" errors on\n", - " * Chrome. But how to set the MIME type? It doesn't seem\n", - " * to be part of the websocket stream */\n", - " img.type = 'image/png';\n", - " }\n", - "\n", - " /* Free the memory for the previous frames */\n", - " if (fig.imageObj.src) {\n", - " (window.URL || window.webkitURL).revokeObjectURL(\n", - " fig.imageObj.src\n", - " );\n", - " }\n", - "\n", - " fig.imageObj.src = (window.URL || window.webkitURL).createObjectURL(\n", - " img\n", - " );\n", - " fig.updated_canvas_event();\n", - " fig.waiting = false;\n", - " return;\n", - " } else if (\n", - " typeof evt.data === 'string' &&\n", - " evt.data.slice(0, 21) === 'data:image/png;base64'\n", - " ) {\n", - " fig.imageObj.src = evt.data;\n", - " fig.updated_canvas_event();\n", - " fig.waiting = false;\n", - " return;\n", - " }\n", - "\n", - " var msg = JSON.parse(evt.data);\n", - " var msg_type = msg['type'];\n", - "\n", - " // Call the \"handle_{type}\" callback, which takes\n", - " // the figure and JSON message as its only arguments.\n", - " try {\n", - " var callback = fig['handle_' + msg_type];\n", - " } catch (e) {\n", - " console.log(\n", - " \"No handler for the '\" + msg_type + \"' message type: \",\n", - " msg\n", - " );\n", - " return;\n", - " }\n", - "\n", - " if (callback) {\n", - " try {\n", - " // console.log(\"Handling '\" + msg_type + \"' message: \", msg);\n", - " callback(fig, msg);\n", - " } catch (e) {\n", - " console.log(\n", - " \"Exception inside the 'handler_\" + msg_type + \"' callback:\",\n", - " e,\n", - " e.stack,\n", - " msg\n", - " );\n", - " }\n", - " }\n", - " };\n", - "};\n", - "\n", - "function getModifiers(event) {\n", - " var mods = [];\n", - " if (event.ctrlKey) {\n", - " mods.push('ctrl');\n", - " }\n", - " if (event.altKey) {\n", - " mods.push('alt');\n", - " }\n", - " if (event.shiftKey) {\n", - " mods.push('shift');\n", - " }\n", - " if (event.metaKey) {\n", - " mods.push('meta');\n", - " }\n", - " return mods;\n", - "}\n", - "\n", - "/*\n", - " * return a copy of an object with only non-object keys\n", - " * we need this to avoid circular references\n", - " * https://stackoverflow.com/a/24161582/3208463\n", - " */\n", - "function simpleKeys(original) {\n", - " return Object.keys(original).reduce(function (obj, key) {\n", - " if (typeof original[key] !== 'object') {\n", - " obj[key] = original[key];\n", - " }\n", - " return obj;\n", - " }, {});\n", - "}\n", - "\n", - "mpl.figure.prototype.mouse_event = function (event, name) {\n", - " if (name === 'button_press') {\n", - " this.canvas.focus();\n", - " this.canvas_div.focus();\n", - " }\n", - "\n", - " // from https://stackoverflow.com/q/1114465\n", - " var boundingRect = this.canvas.getBoundingClientRect();\n", - " var x = (event.clientX - boundingRect.left) * this.ratio;\n", - " var y = (event.clientY - boundingRect.top) * this.ratio;\n", - "\n", - " this.send_message(name, {\n", - " x: x,\n", - " y: y,\n", - " button: event.button,\n", - " step: event.step,\n", - " modifiers: getModifiers(event),\n", - " guiEvent: simpleKeys(event),\n", - " });\n", - "\n", - " return false;\n", - "};\n", - "\n", - "mpl.figure.prototype._key_event_extra = function (_event, _name) {\n", - " // Handle any extra behaviour associated with a key event\n", - "};\n", - "\n", - "mpl.figure.prototype.key_event = function (event, name) {\n", - " // Prevent repeat events\n", - " if (name === 'key_press') {\n", - " if (event.key === this._key) {\n", - " return;\n", - " } else {\n", - " this._key = event.key;\n", - " }\n", - " }\n", - " if (name === 'key_release') {\n", - " this._key = null;\n", - " }\n", - "\n", - " var value = '';\n", - " if (event.ctrlKey && event.key !== 'Control') {\n", - " value += 'ctrl+';\n", - " }\n", - " else if (event.altKey && event.key !== 'Alt') {\n", - " value += 'alt+';\n", - " }\n", - " else if (event.shiftKey && event.key !== 'Shift') {\n", - " value += 'shift+';\n", - " }\n", - "\n", - " value += 'k' + event.key;\n", - "\n", - " this._key_event_extra(event, name);\n", - "\n", - " this.send_message(name, { key: value, guiEvent: simpleKeys(event) });\n", - " return false;\n", - "};\n", - "\n", - "mpl.figure.prototype.toolbar_button_onclick = function (name) {\n", - " if (name === 'download') {\n", - " this.handle_save(this, null);\n", - " } else {\n", - " this.send_message('toolbar_button', { name: name });\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.toolbar_button_onmouseover = function (tooltip) {\n", - " this.message.textContent = tooltip;\n", - "};\n", - "\n", - "///////////////// REMAINING CONTENT GENERATED BY embed_js.py /////////////////\n", - "// prettier-ignore\n", - "var _JSXTOOLS_RESIZE_OBSERVER=function(A){var t,i=new WeakMap,n=new WeakMap,a=new WeakMap,r=new WeakMap,o=new Set;function s(e){if(!(this instanceof s))throw new TypeError(\"Constructor requires 'new' operator\");i.set(this,e)}function h(){throw new TypeError(\"Function is not a constructor\")}function c(e,t,i,n){e=0 in arguments?Number(arguments[0]):0,t=1 in arguments?Number(arguments[1]):0,i=2 in arguments?Number(arguments[2]):0,n=3 in arguments?Number(arguments[3]):0,this.right=(this.x=this.left=e)+(this.width=i),this.bottom=(this.y=this.top=t)+(this.height=n),Object.freeze(this)}function d(){t=requestAnimationFrame(d);var s=new WeakMap,p=new Set;o.forEach((function(t){r.get(t).forEach((function(i){var r=t instanceof window.SVGElement,o=a.get(t),d=r?0:parseFloat(o.paddingTop),f=r?0:parseFloat(o.paddingRight),l=r?0:parseFloat(o.paddingBottom),u=r?0:parseFloat(o.paddingLeft),g=r?0:parseFloat(o.borderTopWidth),m=r?0:parseFloat(o.borderRightWidth),w=r?0:parseFloat(o.borderBottomWidth),b=u+f,F=d+l,v=(r?0:parseFloat(o.borderLeftWidth))+m,W=g+w,y=r?0:t.offsetHeight-W-t.clientHeight,E=r?0:t.offsetWidth-v-t.clientWidth,R=b+v,z=F+W,M=r?t.width:parseFloat(o.width)-R-E,O=r?t.height:parseFloat(o.height)-z-y;if(n.has(t)){var k=n.get(t);if(k[0]===M&&k[1]===O)return}n.set(t,[M,O]);var S=Object.create(h.prototype);S.target=t,S.contentRect=new c(u,d,M,O),s.has(i)||(s.set(i,[]),p.add(i)),s.get(i).push(S)}))})),p.forEach((function(e){i.get(e).call(e,s.get(e),e)}))}return s.prototype.observe=function(i){if(i instanceof window.Element){r.has(i)||(r.set(i,new Set),o.add(i),a.set(i,window.getComputedStyle(i)));var n=r.get(i);n.has(this)||n.add(this),cancelAnimationFrame(t),t=requestAnimationFrame(d)}},s.prototype.unobserve=function(i){if(i instanceof window.Element&&r.has(i)){var n=r.get(i);n.has(this)&&(n.delete(this),n.size||(r.delete(i),o.delete(i))),n.size||r.delete(i),o.size||cancelAnimationFrame(t)}},A.DOMRectReadOnly=c,A.ResizeObserver=s,A.ResizeObserverEntry=h,A}; // eslint-disable-line\n", - "mpl.toolbar_items = [[\"Home\", \"Reset original view\", \"fa fa-home\", \"home\"], [\"Back\", \"Back to previous view\", \"fa fa-arrow-left\", \"back\"], [\"Forward\", \"Forward to next view\", \"fa fa-arrow-right\", \"forward\"], [\"\", \"\", \"\", \"\"], [\"Pan\", \"Left button pans, Right button zooms\\nx/y fixes axis, CTRL fixes aspect\", \"fa fa-arrows\", \"pan\"], [\"Zoom\", \"Zoom to rectangle\\nx/y fixes axis\", \"fa fa-square-o\", \"zoom\"], [\"\", \"\", \"\", \"\"], [\"Download\", \"Download plot\", \"fa fa-floppy-o\", \"download\"]];\n", - "\n", - "mpl.extensions = [\"eps\", \"jpeg\", \"pgf\", \"pdf\", \"png\", \"ps\", \"raw\", \"svg\", \"tif\", \"webp\"];\n", - "\n", - "mpl.default_extension = \"png\";/* global mpl */\n", - "\n", - "var comm_websocket_adapter = function (comm) {\n", - " // Create a \"websocket\"-like object which calls the given IPython comm\n", - " // object with the appropriate methods. Currently this is a non binary\n", - " // socket, so there is still some room for performance tuning.\n", - " var ws = {};\n", - "\n", - " ws.binaryType = comm.kernel.ws.binaryType;\n", - " ws.readyState = comm.kernel.ws.readyState;\n", - " function updateReadyState(_event) {\n", - " if (comm.kernel.ws) {\n", - " ws.readyState = comm.kernel.ws.readyState;\n", - " } else {\n", - " ws.readyState = 3; // Closed state.\n", - " }\n", - " }\n", - " comm.kernel.ws.addEventListener('open', updateReadyState);\n", - " comm.kernel.ws.addEventListener('close', updateReadyState);\n", - " comm.kernel.ws.addEventListener('error', updateReadyState);\n", - "\n", - " ws.close = function () {\n", - " comm.close();\n", - " };\n", - " ws.send = function (m) {\n", - " //console.log('sending', m);\n", - " comm.send(m);\n", - " };\n", - " // Register the callback with on_msg.\n", - " comm.on_msg(function (msg) {\n", - " //console.log('receiving', msg['content']['data'], msg);\n", - " var data = msg['content']['data'];\n", - " if (data['blob'] !== undefined) {\n", - " data = {\n", - " data: new Blob(msg['buffers'], { type: data['blob'] }),\n", - " };\n", - " }\n", - " // Pass the mpl event to the overridden (by mpl) onmessage function.\n", - " ws.onmessage(data);\n", - " });\n", - " return ws;\n", - "};\n", - "\n", - "mpl.mpl_figure_comm = function (comm, msg) {\n", - " // This is the function which gets called when the mpl process\n", - " // starts-up an IPython Comm through the \"matplotlib\" channel.\n", - "\n", - " var id = msg.content.data.id;\n", - " // Get hold of the div created by the display call when the Comm\n", - " // socket was opened in Python.\n", - " var element = document.getElementById(id);\n", - " var ws_proxy = comm_websocket_adapter(comm);\n", - "\n", - " function ondownload(figure, _format) {\n", - " window.open(figure.canvas.toDataURL());\n", - " }\n", - "\n", - " var fig = new mpl.figure(id, ws_proxy, ondownload, element);\n", - "\n", - " // Call onopen now - mpl needs it, as it is assuming we've passed it a real\n", - " // web socket which is closed, not our websocket->open comm proxy.\n", - " ws_proxy.onopen();\n", - "\n", - " fig.parent_element = element;\n", - " fig.cell_info = mpl.find_output_cell(\"
\");\n", - " if (!fig.cell_info) {\n", - " console.error('Failed to find cell for figure', id, fig);\n", - " return;\n", - " }\n", - " fig.cell_info[0].output_area.element.on(\n", - " 'cleared',\n", - " { fig: fig },\n", - " fig._remove_fig_handler\n", - " );\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_close = function (fig, msg) {\n", - " var width = fig.canvas.width / fig.ratio;\n", - " fig.cell_info[0].output_area.element.off(\n", - " 'cleared',\n", - " fig._remove_fig_handler\n", - " );\n", - " fig.resizeObserverInstance.unobserve(fig.canvas_div);\n", - "\n", - " // Update the output cell to use the data from the current canvas.\n", - " fig.push_to_output();\n", - " var dataURL = fig.canvas.toDataURL();\n", - " // Re-enable the keyboard manager in IPython - without this line, in FF,\n", - " // the notebook keyboard shortcuts fail.\n", - " IPython.keyboard_manager.enable();\n", - " fig.parent_element.innerHTML =\n", - " '';\n", - " fig.close_ws(fig, msg);\n", - "};\n", - "\n", - "mpl.figure.prototype.close_ws = function (fig, msg) {\n", - " fig.send_message('closing', msg);\n", - " // fig.ws.close()\n", - "};\n", - "\n", - "mpl.figure.prototype.push_to_output = function (_remove_interactive) {\n", - " // Turn the data on the canvas into data in the output cell.\n", - " var width = this.canvas.width / this.ratio;\n", - " var dataURL = this.canvas.toDataURL();\n", - " this.cell_info[1]['text/html'] =\n", - " '';\n", - "};\n", - "\n", - "mpl.figure.prototype.updated_canvas_event = function () {\n", - " // Tell IPython that the notebook contents must change.\n", - " IPython.notebook.set_dirty(true);\n", - " this.send_message('ack', {});\n", - " var fig = this;\n", - " // Wait a second, then push the new image to the DOM so\n", - " // that it is saved nicely (might be nice to debounce this).\n", - " setTimeout(function () {\n", - " fig.push_to_output();\n", - " }, 1000);\n", - "};\n", - "\n", - "mpl.figure.prototype._init_toolbar = function () {\n", - " var fig = this;\n", - "\n", - " var toolbar = document.createElement('div');\n", - " toolbar.classList = 'btn-toolbar';\n", - " this.root.appendChild(toolbar);\n", - "\n", - " function on_click_closure(name) {\n", - " return function (_event) {\n", - " return fig.toolbar_button_onclick(name);\n", - " };\n", - " }\n", - "\n", - " function on_mouseover_closure(tooltip) {\n", - " return function (event) {\n", - " if (!event.currentTarget.disabled) {\n", - " return fig.toolbar_button_onmouseover(tooltip);\n", - " }\n", - " };\n", - " }\n", - "\n", - " fig.buttons = {};\n", - " var buttonGroup = document.createElement('div');\n", - " buttonGroup.classList = 'btn-group';\n", - " var button;\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", - " /* Instead of a spacer, we start a new button group. */\n", - " if (buttonGroup.hasChildNodes()) {\n", - " toolbar.appendChild(buttonGroup);\n", - " }\n", - " buttonGroup = document.createElement('div');\n", - " buttonGroup.classList = 'btn-group';\n", - " continue;\n", - " }\n", - "\n", - " button = fig.buttons[name] = document.createElement('button');\n", - " button.classList = 'btn btn-default';\n", - " button.href = '#';\n", - " button.title = name;\n", - " button.innerHTML = '';\n", - " button.addEventListener('click', on_click_closure(method_name));\n", - " button.addEventListener('mouseover', on_mouseover_closure(tooltip));\n", - " buttonGroup.appendChild(button);\n", - " }\n", - "\n", - " if (buttonGroup.hasChildNodes()) {\n", - " toolbar.appendChild(buttonGroup);\n", - " }\n", - "\n", - " // Add the status bar.\n", - " var status_bar = document.createElement('span');\n", - " status_bar.classList = 'mpl-message pull-right';\n", - " toolbar.appendChild(status_bar);\n", - " this.message = status_bar;\n", - "\n", - " // Add the close button to the window.\n", - " var buttongrp = document.createElement('div');\n", - " buttongrp.classList = 'btn-group inline pull-right';\n", - " button = document.createElement('button');\n", - " button.classList = 'btn btn-mini btn-primary';\n", - " button.href = '#';\n", - " button.title = 'Stop Interaction';\n", - " button.innerHTML = '';\n", - " button.addEventListener('click', function (_evt) {\n", - " fig.handle_close(fig, {});\n", - " });\n", - " button.addEventListener(\n", - " 'mouseover',\n", - " on_mouseover_closure('Stop Interaction')\n", - " );\n", - " buttongrp.appendChild(button);\n", - " var titlebar = this.root.querySelector('.ui-dialog-titlebar');\n", - " titlebar.insertBefore(buttongrp, titlebar.firstChild);\n", - "};\n", - "\n", - "mpl.figure.prototype._remove_fig_handler = function (event) {\n", - " var fig = event.data.fig;\n", - " if (event.target !== this) {\n", - " // Ignore bubbled events from children.\n", - " return;\n", - " }\n", - " fig.close_ws(fig, {});\n", - "};\n", - "\n", - "mpl.figure.prototype._root_extra_style = function (el) {\n", - " el.style.boxSizing = 'content-box'; // override notebook setting of border-box.\n", - "};\n", - "\n", - "mpl.figure.prototype._canvas_extra_style = function (el) {\n", - " // this is important to make the div 'focusable\n", - " el.setAttribute('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", - " } else {\n", - " // location in version 2\n", - " IPython.keyboard_manager.register_events(el);\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype._key_event_extra = function (event, _name) {\n", - " // Check for shift+enter\n", - " if (event.shiftKey && event.which === 13) {\n", - " this.canvas_div.blur();\n", - " // select the cell after this one\n", - " var index = IPython.notebook.find_cell_index(this.cell_info[0]);\n", - " IPython.notebook.select(index + 1);\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_save = function (fig, _msg) {\n", - " fig.ondownload(fig, null);\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 < ncells; i++) {\n", - " var cell = cells[i];\n", - " if (cell.cell_type === 'code') {\n", - " for (var j = 0; j < cell.output_area.outputs.length; j++) {\n", - " var data = cell.output_area.outputs[j];\n", - " if (data.data) {\n", - " // IPython >= 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(\n", - " 'matplotlib',\n", - " mpl.mpl_figure_comm\n", - " );\n", - "}\n" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/html": [ - "
" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "time_format: BJD_TDB\n", - "time_stamp: mid\n", - "exp_time: 49.43311423994601\n", - "flux_format: flux\n", - "filter_name: jwst_niriss1\n", - "wlrange: [8600.0, 28000.0]\n" - ] - } - ], - "source": [ - "###############################################################################################\n", - "##### Load data\n", - "###############################################################################################\n", - "\n", - "# This dataset contains one transit observation of WASP-39b, obtained by JWST/NIRISS/SOSS, \n", - "# as part of the ERS program, and analysed with Iraclis:\n", - "# https://www.nature.com/articles/s41586-022-05674-1\n", - "# It is the white light curve of the first order spectrum, \n", - "# i.e. the sum of all the flux from 8600.0 to 28000.0 Angstrom.\n", - "\n", - "data = plc.open_dict('wasp39b_jwst.pickle')\n", - "\n", - "###############################################################################################\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "###############################################################################################\n", - "##### Inspect data\n", - "###############################################################################################\n", - "\n", - "# The dictionaly contains the necessary keywords:\n", - "# 'time'\n", - "# 'time_format'\n", - "# 'time_stamp'\n", - "# 'exp_time'\n", - "# 'flux'\n", - "# 'flux_unc'\n", - "# 'flux_format'\n", - "# 'filter_name'\n", - "\n", - "# and in additon, the wavelength region from which the flux was extracted:\n", - "# 'wlrange'\n", - "\n", - "plt.figure()\n", - "plt.ylabel('flux')\n", - "plt.xlabel('time')\n", - "plt.errorbar(data['time'], data['flux'], data['flux_unc'], fmt='o')\n", - "\n", - "for i in ['time_format', 'time_stamp', 'exp_time', 'flux_format', 'filter_name', 'wlrange']:\n", - " print('{0}: {1}'.format(i, data[i]))\n", - " \n", - "###############################################################################################\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "###############################################################################################\n", - "##### Define the trend function\n", - "###############################################################################################\n", - "\n", - "# By default, the detrending is done using a second order polynomial with time.\n", - "# Here, we will not change this.\n", - "\n", - "###############################################################################################\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "###############################################################################################\n", - "##### Define the stellar model\n", - "###############################################################################################\n", - "\n", - "# The default stellar model used to calculate the limb-darkening coefficients \n", - "# is the 'Pheonix_2018'. However, there are cases where the filter used for the observation is \n", - "# outside the wavelegth region covered by these specific stellar models, like this dataset.\n", - "# Here we will use a different strellar model: \n", - "\n", - "data['stellar_model'] = 'Stagger_2018'\n", - "\n", - "###############################################################################################\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "###############################################################################################\n", - "##### Add observation to the Planet object\n", - "###############################################################################################\n", - "\n", - "# Then we are going to add the observation to the Planet object.\n", - "# It is advised to use planet.clear_observations() before, \n", - "# to avoid duplications, in case we forget that we have already added the same observation.\n", - "\n", - "planet.clear_observations()\n", - "planet.add_observation_from_dict(data)\n", - "\n", - "###############################################################################################\n" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "id": "72560cbb", - "metadata": { - "scrolled": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "File already here... teff5000.0_logg4.0_MH-0.5.pickle\n", - "File already here... teff5000.0_logg4.0_MH0.0.pickle\n", - "File already here... teff5000.0_logg4.5_MH-1.0.pickle\n", - "File already here... teff5500.0_logg4.0_MH-0.5.pickle\n", - "File already here... teff5500.0_logg4.0_MH0.0.pickle\n", - "File already here... teff5500.0_logg4.5_MH-0.5.pickle\n", - "File already here... teff5500.0_logg4.5_MH0.0.pickle\n", - "File already here... teff5000.0_logg4.5_MH0.0.pickle\n", - "\n", - "Observation: obs0\n", - "Filter: jwst_niriss1:8600.0-28000.0\n", - "Epoch: 715\n", - "Data-points excluded: 0\n", - "Scaling uncertainties by: 1\n", - "\n", - "Optimising initial parameters...\n", - "Transit fitting...\n" - ] - }, - { - "data": { - "application/javascript": [ - "/* Put everything inside the global mpl namespace */\n", - "/* global mpl */\n", - "window.mpl = {};\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(\n", - " '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", - "\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 = document.createElement('div');\n", - " this.root.setAttribute('style', 'display: inline-block');\n", - " this._root_extra_style(this.root);\n", - "\n", - " parent_element.appendChild(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 (fig.ratio !== 1) {\n", - " fig.send_message('set_device_pixel_ratio', {\n", - " device_pixel_ratio: fig.ratio,\n", - " });\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 = document.createElement('div');\n", - " titlebar.classList =\n", - " 'ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix';\n", - " var titletext = document.createElement('div');\n", - " titletext.classList = 'ui-dialog-title';\n", - " titletext.setAttribute(\n", - " 'style',\n", - " 'width: 100%; text-align: center; padding: 3px;'\n", - " );\n", - " titlebar.appendChild(titletext);\n", - " this.root.appendChild(titlebar);\n", - " this.header = titletext;\n", - "};\n", - "\n", - "mpl.figure.prototype._canvas_extra_style = function (_canvas_div) {};\n", - "\n", - "mpl.figure.prototype._root_extra_style = function (_canvas_div) {};\n", - "\n", - "mpl.figure.prototype._init_canvas = function () {\n", - " var fig = this;\n", - "\n", - " var canvas_div = (this.canvas_div = document.createElement('div'));\n", - " canvas_div.setAttribute('tabindex', '0');\n", - " canvas_div.setAttribute(\n", - " 'style',\n", - " 'border: 1px solid #ddd;' +\n", - " 'box-sizing: content-box;' +\n", - " 'clear: both;' +\n", - " 'min-height: 1px;' +\n", - " 'min-width: 1px;' +\n", - " 'outline: 0;' +\n", - " 'overflow: hidden;' +\n", - " 'position: relative;' +\n", - " 'resize: both;' +\n", - " 'z-index: 2;'\n", - " );\n", - "\n", - " function on_keyboard_event_closure(name) {\n", - " return function (event) {\n", - " return fig.key_event(event, name);\n", - " };\n", - " }\n", - "\n", - " canvas_div.addEventListener(\n", - " 'keydown',\n", - " on_keyboard_event_closure('key_press')\n", - " );\n", - " canvas_div.addEventListener(\n", - " 'keyup',\n", - " on_keyboard_event_closure('key_release')\n", - " );\n", - "\n", - " this._canvas_extra_style(canvas_div);\n", - " this.root.appendChild(canvas_div);\n", - "\n", - " var canvas = (this.canvas = document.createElement('canvas'));\n", - " canvas.classList.add('mpl-canvas');\n", - " canvas.setAttribute(\n", - " 'style',\n", - " 'box-sizing: content-box;' +\n", - " 'pointer-events: none;' +\n", - " 'position: relative;' +\n", - " 'z-index: 0;'\n", - " );\n", - "\n", - " this.context = canvas.getContext('2d');\n", - "\n", - " var backingStore =\n", - " this.context.backingStorePixelRatio ||\n", - " this.context.webkitBackingStorePixelRatio ||\n", - " this.context.mozBackingStorePixelRatio ||\n", - " this.context.msBackingStorePixelRatio ||\n", - " this.context.oBackingStorePixelRatio ||\n", - " this.context.backingStorePixelRatio ||\n", - " 1;\n", - "\n", - " this.ratio = (window.devicePixelRatio || 1) / backingStore;\n", - "\n", - " var rubberband_canvas = (this.rubberband_canvas = document.createElement(\n", - " 'canvas'\n", - " ));\n", - " rubberband_canvas.setAttribute(\n", - " 'style',\n", - " 'box-sizing: content-box;' +\n", - " 'left: 0;' +\n", - " 'pointer-events: none;' +\n", - " 'position: absolute;' +\n", - " 'top: 0;' +\n", - " 'z-index: 1;'\n", - " );\n", - "\n", - " // Apply a ponyfill if ResizeObserver is not implemented by browser.\n", - " if (this.ResizeObserver === undefined) {\n", - " if (window.ResizeObserver !== undefined) {\n", - " this.ResizeObserver = window.ResizeObserver;\n", - " } else {\n", - " var obs = _JSXTOOLS_RESIZE_OBSERVER({});\n", - " this.ResizeObserver = obs.ResizeObserver;\n", - " }\n", - " }\n", - "\n", - " this.resizeObserverInstance = new this.ResizeObserver(function (entries) {\n", - " // There's no need to resize if the WebSocket is not connected:\n", - " // - If it is still connecting, then we will get an initial resize from\n", - " // Python once it connects.\n", - " // - If it has disconnected, then resizing will clear the canvas and\n", - " // never get anything back to refill it, so better to not resize and\n", - " // keep something visible.\n", - " if (fig.ws.readyState != 1) {\n", - " return;\n", - " }\n", - " var nentries = entries.length;\n", - " for (var i = 0; i < nentries; i++) {\n", - " var entry = entries[i];\n", - " var width, height;\n", - " if (entry.contentBoxSize) {\n", - " if (entry.contentBoxSize instanceof Array) {\n", - " // Chrome 84 implements new version of spec.\n", - " width = entry.contentBoxSize[0].inlineSize;\n", - " height = entry.contentBoxSize[0].blockSize;\n", - " } else {\n", - " // Firefox implements old version of spec.\n", - " width = entry.contentBoxSize.inlineSize;\n", - " height = entry.contentBoxSize.blockSize;\n", - " }\n", - " } else {\n", - " // Chrome <84 implements even older version of spec.\n", - " width = entry.contentRect.width;\n", - " height = entry.contentRect.height;\n", - " }\n", - "\n", - " // Keep the size of the canvas and rubber band canvas in sync with\n", - " // the canvas container.\n", - " if (entry.devicePixelContentBoxSize) {\n", - " // Chrome 84 implements new version of spec.\n", - " canvas.setAttribute(\n", - " 'width',\n", - " entry.devicePixelContentBoxSize[0].inlineSize\n", - " );\n", - " canvas.setAttribute(\n", - " 'height',\n", - " entry.devicePixelContentBoxSize[0].blockSize\n", - " );\n", - " } else {\n", - " canvas.setAttribute('width', width * fig.ratio);\n", - " canvas.setAttribute('height', height * fig.ratio);\n", - " }\n", - " /* This rescales the canvas back to display pixels, so that it\n", - " * appears correct on HiDPI screens. */\n", - " canvas.style.width = width + 'px';\n", - " canvas.style.height = height + 'px';\n", - "\n", - " rubberband_canvas.setAttribute('width', width);\n", - " rubberband_canvas.setAttribute('height', height);\n", - "\n", - " // And update the size in Python. We ignore the initial 0/0 size\n", - " // that occurs as the element is placed into the DOM, which should\n", - " // otherwise not happen due to the minimum size styling.\n", - " if (width != 0 && height != 0) {\n", - " fig.request_resize(width, height);\n", - " }\n", - " }\n", - " });\n", - " this.resizeObserverInstance.observe(canvas_div);\n", - "\n", - " function on_mouse_event_closure(name) {\n", - " /* User Agent sniffing is bad, but WebKit is busted:\n", - " * https://bugs.webkit.org/show_bug.cgi?id=144526\n", - " * https://bugs.webkit.org/show_bug.cgi?id=181818\n", - " * The worst that happens here is that they get an extra browser\n", - " * selection when dragging, if this check fails to catch them.\n", - " */\n", - " var UA = navigator.userAgent;\n", - " var isWebKit = /AppleWebKit/.test(UA) && !/Chrome/.test(UA);\n", - " if(isWebKit) {\n", - " return function (event) {\n", - " /* This prevents the web browser from automatically changing to\n", - " * the text insertion cursor when the button is pressed. We\n", - " * want to control all of the cursor setting manually through\n", - " * the 'cursor' event from matplotlib */\n", - " event.preventDefault()\n", - " return fig.mouse_event(event, name);\n", - " };\n", - " } else {\n", - " return function (event) {\n", - " return fig.mouse_event(event, name);\n", - " };\n", - " }\n", - " }\n", - "\n", - " canvas_div.addEventListener(\n", - " 'mousedown',\n", - " on_mouse_event_closure('button_press')\n", - " );\n", - " canvas_div.addEventListener(\n", - " 'mouseup',\n", - " on_mouse_event_closure('button_release')\n", - " );\n", - " canvas_div.addEventListener(\n", - " 'dblclick',\n", - " on_mouse_event_closure('dblclick')\n", - " );\n", - " // Throttle sequential mouse events to 1 every 20ms.\n", - " canvas_div.addEventListener(\n", - " 'mousemove',\n", - " on_mouse_event_closure('motion_notify')\n", - " );\n", - "\n", - " canvas_div.addEventListener(\n", - " 'mouseenter',\n", - " on_mouse_event_closure('figure_enter')\n", - " );\n", - " canvas_div.addEventListener(\n", - " 'mouseleave',\n", - " on_mouse_event_closure('figure_leave')\n", - " );\n", - "\n", - " canvas_div.addEventListener('wheel', function (event) {\n", - " if (event.deltaY < 0) {\n", - " event.step = 1;\n", - " } else {\n", - " event.step = -1;\n", - " }\n", - " on_mouse_event_closure('scroll')(event);\n", - " });\n", - "\n", - " canvas_div.appendChild(canvas);\n", - " canvas_div.appendChild(rubberband_canvas);\n", - "\n", - " this.rubberband_context = rubberband_canvas.getContext('2d');\n", - " this.rubberband_context.strokeStyle = '#000000';\n", - "\n", - " this._resize_canvas = function (width, height, forward) {\n", - " if (forward) {\n", - " canvas_div.style.width = width + 'px';\n", - " canvas_div.style.height = height + 'px';\n", - " }\n", - " };\n", - "\n", - " // Disable right mouse context menu.\n", - " canvas_div.addEventListener('contextmenu', function (_e) {\n", - " event.preventDefault();\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 toolbar = document.createElement('div');\n", - " toolbar.classList = 'mpl-toolbar';\n", - " this.root.appendChild(toolbar);\n", - "\n", - " function on_click_closure(name) {\n", - " return function (_event) {\n", - " return fig.toolbar_button_onclick(name);\n", - " };\n", - " }\n", - "\n", - " function on_mouseover_closure(tooltip) {\n", - " return function (event) {\n", - " if (!event.currentTarget.disabled) {\n", - " return fig.toolbar_button_onmouseover(tooltip);\n", - " }\n", - " };\n", - " }\n", - "\n", - " fig.buttons = {};\n", - " var buttonGroup = document.createElement('div');\n", - " buttonGroup.classList = 'mpl-button-group';\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", - " /* Instead of a spacer, we start a new button group. */\n", - " if (buttonGroup.hasChildNodes()) {\n", - " toolbar.appendChild(buttonGroup);\n", - " }\n", - " buttonGroup = document.createElement('div');\n", - " buttonGroup.classList = 'mpl-button-group';\n", - " continue;\n", - " }\n", - "\n", - " var button = (fig.buttons[name] = document.createElement('button'));\n", - " button.classList = 'mpl-widget';\n", - " button.setAttribute('role', 'button');\n", - " button.setAttribute('aria-disabled', 'false');\n", - " button.addEventListener('click', on_click_closure(method_name));\n", - " button.addEventListener('mouseover', on_mouseover_closure(tooltip));\n", - "\n", - " var icon_img = document.createElement('img');\n", - " icon_img.src = '_images/' + image + '.png';\n", - " icon_img.srcset = '_images/' + image + '_large.png 2x';\n", - " icon_img.alt = tooltip;\n", - " button.appendChild(icon_img);\n", - "\n", - " buttonGroup.appendChild(button);\n", - " }\n", - "\n", - " if (buttonGroup.hasChildNodes()) {\n", - " toolbar.appendChild(buttonGroup);\n", - " }\n", - "\n", - " var fmt_picker = document.createElement('select');\n", - " fmt_picker.classList = 'mpl-widget';\n", - " toolbar.appendChild(fmt_picker);\n", - " this.format_dropdown = fmt_picker;\n", - "\n", - " for (var ind in mpl.extensions) {\n", - " var fmt = mpl.extensions[ind];\n", - " var option = document.createElement('option');\n", - " option.selected = fmt === mpl.default_extension;\n", - " option.innerHTML = fmt;\n", - " fmt_picker.appendChild(option);\n", - " }\n", - "\n", - " var status_bar = document.createElement('span');\n", - " status_bar.classList = 'mpl-message';\n", - " toolbar.appendChild(status_bar);\n", - " this.message = status_bar;\n", - "};\n", - "\n", - "mpl.figure.prototype.request_resize = function (x_pixels, y_pixels) {\n", - " // Request matplotlib to resize the figure. Matplotlib will then trigger a resize in the client,\n", - " // which will in turn request a refresh of the image.\n", - " this.send_message('resize', { width: x_pixels, height: y_pixels });\n", - "};\n", - "\n", - "mpl.figure.prototype.send_message = function (type, properties) {\n", - " properties['type'] = type;\n", - " properties['figure_id'] = this.id;\n", - " this.ws.send(JSON.stringify(properties));\n", - "};\n", - "\n", - "mpl.figure.prototype.send_draw_message = function () {\n", - " if (!this.waiting) {\n", - " this.waiting = true;\n", - " this.ws.send(JSON.stringify({ type: 'draw', figure_id: this.id }));\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_save = function (fig, _msg) {\n", - " var format_dropdown = fig.format_dropdown;\n", - " var format = format_dropdown.options[format_dropdown.selectedIndex].value;\n", - " fig.ondownload(fig, format);\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_resize = function (fig, msg) {\n", - " var size = msg['size'];\n", - " if (size[0] !== fig.canvas.width || size[1] !== fig.canvas.height) {\n", - " fig._resize_canvas(size[0], size[1], msg['forward']);\n", - " fig.send_message('refresh', {});\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_rubberband = function (fig, msg) {\n", - " var x0 = msg['x0'] / fig.ratio;\n", - " var y0 = (fig.canvas.height - msg['y0']) / fig.ratio;\n", - " var x1 = msg['x1'] / fig.ratio;\n", - " var y1 = (fig.canvas.height - msg['y1']) / fig.ratio;\n", - " x0 = Math.floor(x0) + 0.5;\n", - " y0 = Math.floor(y0) + 0.5;\n", - " x1 = Math.floor(x1) + 0.5;\n", - " y1 = Math.floor(y1) + 0.5;\n", - " var min_x = Math.min(x0, x1);\n", - " var min_y = Math.min(y0, y1);\n", - " var width = Math.abs(x1 - x0);\n", - " var height = Math.abs(y1 - y0);\n", - "\n", - " fig.rubberband_context.clearRect(\n", - " 0,\n", - " 0,\n", - " fig.canvas.width / fig.ratio,\n", - " fig.canvas.height / fig.ratio\n", - " );\n", - "\n", - " fig.rubberband_context.strokeRect(min_x, min_y, width, height);\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_figure_label = function (fig, msg) {\n", - " // Updates the figure title.\n", - " fig.header.textContent = msg['label'];\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_cursor = function (fig, msg) {\n", - " fig.canvas_div.style.cursor = msg['cursor'];\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_message = function (fig, msg) {\n", - " fig.message.textContent = msg['message'];\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_draw = function (fig, _msg) {\n", - " // Request the server to send over a new figure.\n", - " fig.send_draw_message();\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_image_mode = function (fig, msg) {\n", - " fig.image_mode = msg['mode'];\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_history_buttons = function (fig, msg) {\n", - " for (var key in msg) {\n", - " if (!(key in fig.buttons)) {\n", - " continue;\n", - " }\n", - " fig.buttons[key].disabled = !msg[key];\n", - " fig.buttons[key].setAttribute('aria-disabled', !msg[key]);\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_navigate_mode = function (fig, msg) {\n", - " if (msg['mode'] === 'PAN') {\n", - " fig.buttons['Pan'].classList.add('active');\n", - " fig.buttons['Zoom'].classList.remove('active');\n", - " } else if (msg['mode'] === 'ZOOM') {\n", - " fig.buttons['Pan'].classList.remove('active');\n", - " fig.buttons['Zoom'].classList.add('active');\n", - " } else {\n", - " fig.buttons['Pan'].classList.remove('active');\n", - " fig.buttons['Zoom'].classList.remove('active');\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.updated_canvas_event = function () {\n", - " // Called whenever the canvas gets updated.\n", - " this.send_message('ack', {});\n", - "};\n", - "\n", - "// A function to construct a web socket function for onmessage handling.\n", - "// Called in the figure constructor.\n", - "mpl.figure.prototype._make_on_message_function = function (fig) {\n", - " return function socket_on_message(evt) {\n", - " if (evt.data instanceof Blob) {\n", - " var img = evt.data;\n", - " if (img.type !== 'image/png') {\n", - " /* FIXME: We get \"Resource interpreted as Image but\n", - " * transferred with MIME type text/plain:\" errors on\n", - " * Chrome. But how to set the MIME type? It doesn't seem\n", - " * to be part of the websocket stream */\n", - " img.type = 'image/png';\n", - " }\n", - "\n", - " /* Free the memory for the previous frames */\n", - " if (fig.imageObj.src) {\n", - " (window.URL || window.webkitURL).revokeObjectURL(\n", - " fig.imageObj.src\n", - " );\n", - " }\n", - "\n", - " fig.imageObj.src = (window.URL || window.webkitURL).createObjectURL(\n", - " img\n", - " );\n", - " fig.updated_canvas_event();\n", - " fig.waiting = false;\n", - " return;\n", - " } else if (\n", - " typeof evt.data === 'string' &&\n", - " evt.data.slice(0, 21) === 'data:image/png;base64'\n", - " ) {\n", - " fig.imageObj.src = evt.data;\n", - " fig.updated_canvas_event();\n", - " fig.waiting = false;\n", - " return;\n", - " }\n", - "\n", - " var msg = JSON.parse(evt.data);\n", - " var msg_type = msg['type'];\n", - "\n", - " // Call the \"handle_{type}\" callback, which takes\n", - " // the figure and JSON message as its only arguments.\n", - " try {\n", - " var callback = fig['handle_' + msg_type];\n", - " } catch (e) {\n", - " console.log(\n", - " \"No handler for the '\" + msg_type + \"' message type: \",\n", - " msg\n", - " );\n", - " return;\n", - " }\n", - "\n", - " if (callback) {\n", - " try {\n", - " // console.log(\"Handling '\" + msg_type + \"' message: \", msg);\n", - " callback(fig, msg);\n", - " } catch (e) {\n", - " console.log(\n", - " \"Exception inside the 'handler_\" + msg_type + \"' callback:\",\n", - " e,\n", - " e.stack,\n", - " msg\n", - " );\n", - " }\n", - " }\n", - " };\n", - "};\n", - "\n", - "function getModifiers(event) {\n", - " var mods = [];\n", - " if (event.ctrlKey) {\n", - " mods.push('ctrl');\n", - " }\n", - " if (event.altKey) {\n", - " mods.push('alt');\n", - " }\n", - " if (event.shiftKey) {\n", - " mods.push('shift');\n", - " }\n", - " if (event.metaKey) {\n", - " mods.push('meta');\n", - " }\n", - " return mods;\n", - "}\n", - "\n", - "/*\n", - " * return a copy of an object with only non-object keys\n", - " * we need this to avoid circular references\n", - " * https://stackoverflow.com/a/24161582/3208463\n", - " */\n", - "function simpleKeys(original) {\n", - " return Object.keys(original).reduce(function (obj, key) {\n", - " if (typeof original[key] !== 'object') {\n", - " obj[key] = original[key];\n", - " }\n", - " return obj;\n", - " }, {});\n", - "}\n", - "\n", - "mpl.figure.prototype.mouse_event = function (event, name) {\n", - " if (name === 'button_press') {\n", - " this.canvas.focus();\n", - " this.canvas_div.focus();\n", - " }\n", - "\n", - " // from https://stackoverflow.com/q/1114465\n", - " var boundingRect = this.canvas.getBoundingClientRect();\n", - " var x = (event.clientX - boundingRect.left) * this.ratio;\n", - " var y = (event.clientY - boundingRect.top) * this.ratio;\n", - "\n", - " this.send_message(name, {\n", - " x: x,\n", - " y: y,\n", - " button: event.button,\n", - " step: event.step,\n", - " modifiers: getModifiers(event),\n", - " guiEvent: simpleKeys(event),\n", - " });\n", - "\n", - " return false;\n", - "};\n", - "\n", - "mpl.figure.prototype._key_event_extra = function (_event, _name) {\n", - " // Handle any extra behaviour associated with a key event\n", - "};\n", - "\n", - "mpl.figure.prototype.key_event = function (event, name) {\n", - " // Prevent repeat events\n", - " if (name === 'key_press') {\n", - " if (event.key === this._key) {\n", - " return;\n", - " } else {\n", - " this._key = event.key;\n", - " }\n", - " }\n", - " if (name === 'key_release') {\n", - " this._key = null;\n", - " }\n", - "\n", - " var value = '';\n", - " if (event.ctrlKey && event.key !== 'Control') {\n", - " value += 'ctrl+';\n", - " }\n", - " else if (event.altKey && event.key !== 'Alt') {\n", - " value += 'alt+';\n", - " }\n", - " else if (event.shiftKey && event.key !== 'Shift') {\n", - " value += 'shift+';\n", - " }\n", - "\n", - " value += 'k' + event.key;\n", - "\n", - " this._key_event_extra(event, name);\n", - "\n", - " this.send_message(name, { key: value, guiEvent: simpleKeys(event) });\n", - " return false;\n", - "};\n", - "\n", - "mpl.figure.prototype.toolbar_button_onclick = function (name) {\n", - " if (name === 'download') {\n", - " this.handle_save(this, null);\n", - " } else {\n", - " this.send_message('toolbar_button', { name: name });\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.toolbar_button_onmouseover = function (tooltip) {\n", - " this.message.textContent = tooltip;\n", - "};\n", - "\n", - "///////////////// REMAINING CONTENT GENERATED BY embed_js.py /////////////////\n", - "// prettier-ignore\n", - "var _JSXTOOLS_RESIZE_OBSERVER=function(A){var t,i=new WeakMap,n=new WeakMap,a=new WeakMap,r=new WeakMap,o=new Set;function s(e){if(!(this instanceof s))throw new TypeError(\"Constructor requires 'new' operator\");i.set(this,e)}function h(){throw new TypeError(\"Function is not a constructor\")}function c(e,t,i,n){e=0 in arguments?Number(arguments[0]):0,t=1 in arguments?Number(arguments[1]):0,i=2 in arguments?Number(arguments[2]):0,n=3 in arguments?Number(arguments[3]):0,this.right=(this.x=this.left=e)+(this.width=i),this.bottom=(this.y=this.top=t)+(this.height=n),Object.freeze(this)}function d(){t=requestAnimationFrame(d);var s=new WeakMap,p=new Set;o.forEach((function(t){r.get(t).forEach((function(i){var r=t instanceof window.SVGElement,o=a.get(t),d=r?0:parseFloat(o.paddingTop),f=r?0:parseFloat(o.paddingRight),l=r?0:parseFloat(o.paddingBottom),u=r?0:parseFloat(o.paddingLeft),g=r?0:parseFloat(o.borderTopWidth),m=r?0:parseFloat(o.borderRightWidth),w=r?0:parseFloat(o.borderBottomWidth),b=u+f,F=d+l,v=(r?0:parseFloat(o.borderLeftWidth))+m,W=g+w,y=r?0:t.offsetHeight-W-t.clientHeight,E=r?0:t.offsetWidth-v-t.clientWidth,R=b+v,z=F+W,M=r?t.width:parseFloat(o.width)-R-E,O=r?t.height:parseFloat(o.height)-z-y;if(n.has(t)){var k=n.get(t);if(k[0]===M&&k[1]===O)return}n.set(t,[M,O]);var S=Object.create(h.prototype);S.target=t,S.contentRect=new c(u,d,M,O),s.has(i)||(s.set(i,[]),p.add(i)),s.get(i).push(S)}))})),p.forEach((function(e){i.get(e).call(e,s.get(e),e)}))}return s.prototype.observe=function(i){if(i instanceof window.Element){r.has(i)||(r.set(i,new Set),o.add(i),a.set(i,window.getComputedStyle(i)));var n=r.get(i);n.has(this)||n.add(this),cancelAnimationFrame(t),t=requestAnimationFrame(d)}},s.prototype.unobserve=function(i){if(i instanceof window.Element&&r.has(i)){var n=r.get(i);n.has(this)&&(n.delete(this),n.size||(r.delete(i),o.delete(i))),n.size||r.delete(i),o.size||cancelAnimationFrame(t)}},A.DOMRectReadOnly=c,A.ResizeObserver=s,A.ResizeObserverEntry=h,A}; // eslint-disable-line\n", - "mpl.toolbar_items = [[\"Home\", \"Reset original view\", \"fa fa-home\", \"home\"], [\"Back\", \"Back to previous view\", \"fa fa-arrow-left\", \"back\"], [\"Forward\", \"Forward to next view\", \"fa fa-arrow-right\", \"forward\"], [\"\", \"\", \"\", \"\"], [\"Pan\", \"Left button pans, Right button zooms\\nx/y fixes axis, CTRL fixes aspect\", \"fa fa-arrows\", \"pan\"], [\"Zoom\", \"Zoom to rectangle\\nx/y fixes axis\", \"fa fa-square-o\", \"zoom\"], [\"\", \"\", \"\", \"\"], [\"Download\", \"Download plot\", \"fa fa-floppy-o\", \"download\"]];\n", - "\n", - "mpl.extensions = [\"eps\", \"jpeg\", \"pgf\", \"pdf\", \"png\", \"ps\", \"raw\", \"svg\", \"tif\", \"webp\"];\n", - "\n", - "mpl.default_extension = \"png\";/* global mpl */\n", - "\n", - "var comm_websocket_adapter = function (comm) {\n", - " // Create a \"websocket\"-like object which calls the given IPython comm\n", - " // object with the appropriate methods. Currently this is a non binary\n", - " // socket, so there is still some room for performance tuning.\n", - " var ws = {};\n", - "\n", - " ws.binaryType = comm.kernel.ws.binaryType;\n", - " ws.readyState = comm.kernel.ws.readyState;\n", - " function updateReadyState(_event) {\n", - " if (comm.kernel.ws) {\n", - " ws.readyState = comm.kernel.ws.readyState;\n", - " } else {\n", - " ws.readyState = 3; // Closed state.\n", - " }\n", - " }\n", - " comm.kernel.ws.addEventListener('open', updateReadyState);\n", - " comm.kernel.ws.addEventListener('close', updateReadyState);\n", - " comm.kernel.ws.addEventListener('error', updateReadyState);\n", - "\n", - " ws.close = function () {\n", - " comm.close();\n", - " };\n", - " ws.send = function (m) {\n", - " //console.log('sending', m);\n", - " comm.send(m);\n", - " };\n", - " // Register the callback with on_msg.\n", - " comm.on_msg(function (msg) {\n", - " //console.log('receiving', msg['content']['data'], msg);\n", - " var data = msg['content']['data'];\n", - " if (data['blob'] !== undefined) {\n", - " data = {\n", - " data: new Blob(msg['buffers'], { type: data['blob'] }),\n", - " };\n", - " }\n", - " // Pass the mpl event to the overridden (by mpl) onmessage function.\n", - " ws.onmessage(data);\n", - " });\n", - " return ws;\n", - "};\n", - "\n", - "mpl.mpl_figure_comm = function (comm, msg) {\n", - " // This is the function which gets called when the mpl process\n", - " // starts-up an IPython Comm through the \"matplotlib\" channel.\n", - "\n", - " var id = msg.content.data.id;\n", - " // Get hold of the div created by the display call when the Comm\n", - " // socket was opened in Python.\n", - " var element = document.getElementById(id);\n", - " var ws_proxy = comm_websocket_adapter(comm);\n", - "\n", - " function ondownload(figure, _format) {\n", - " window.open(figure.canvas.toDataURL());\n", - " }\n", - "\n", - " var fig = new mpl.figure(id, ws_proxy, ondownload, element);\n", - "\n", - " // Call onopen now - mpl needs it, as it is assuming we've passed it a real\n", - " // web socket which is closed, not our websocket->open comm proxy.\n", - " ws_proxy.onopen();\n", - "\n", - " fig.parent_element = element;\n", - " fig.cell_info = mpl.find_output_cell(\"
\");\n", - " if (!fig.cell_info) {\n", - " console.error('Failed to find cell for figure', id, fig);\n", - " return;\n", - " }\n", - " fig.cell_info[0].output_area.element.on(\n", - " 'cleared',\n", - " { fig: fig },\n", - " fig._remove_fig_handler\n", - " );\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_close = function (fig, msg) {\n", - " var width = fig.canvas.width / fig.ratio;\n", - " fig.cell_info[0].output_area.element.off(\n", - " 'cleared',\n", - " fig._remove_fig_handler\n", - " );\n", - " fig.resizeObserverInstance.unobserve(fig.canvas_div);\n", - "\n", - " // Update the output cell to use the data from the current canvas.\n", - " fig.push_to_output();\n", - " var dataURL = fig.canvas.toDataURL();\n", - " // Re-enable the keyboard manager in IPython - without this line, in FF,\n", - " // the notebook keyboard shortcuts fail.\n", - " IPython.keyboard_manager.enable();\n", - " fig.parent_element.innerHTML =\n", - " '';\n", - " fig.close_ws(fig, msg);\n", - "};\n", - "\n", - "mpl.figure.prototype.close_ws = function (fig, msg) {\n", - " fig.send_message('closing', msg);\n", - " // fig.ws.close()\n", - "};\n", - "\n", - "mpl.figure.prototype.push_to_output = function (_remove_interactive) {\n", - " // Turn the data on the canvas into data in the output cell.\n", - " var width = this.canvas.width / this.ratio;\n", - " var dataURL = this.canvas.toDataURL();\n", - " this.cell_info[1]['text/html'] =\n", - " '';\n", - "};\n", - "\n", - "mpl.figure.prototype.updated_canvas_event = function () {\n", - " // Tell IPython that the notebook contents must change.\n", - " IPython.notebook.set_dirty(true);\n", - " this.send_message('ack', {});\n", - " var fig = this;\n", - " // Wait a second, then push the new image to the DOM so\n", - " // that it is saved nicely (might be nice to debounce this).\n", - " setTimeout(function () {\n", - " fig.push_to_output();\n", - " }, 1000);\n", - "};\n", - "\n", - "mpl.figure.prototype._init_toolbar = function () {\n", - " var fig = this;\n", - "\n", - " var toolbar = document.createElement('div');\n", - " toolbar.classList = 'btn-toolbar';\n", - " this.root.appendChild(toolbar);\n", - "\n", - " function on_click_closure(name) {\n", - " return function (_event) {\n", - " return fig.toolbar_button_onclick(name);\n", - " };\n", - " }\n", - "\n", - " function on_mouseover_closure(tooltip) {\n", - " return function (event) {\n", - " if (!event.currentTarget.disabled) {\n", - " return fig.toolbar_button_onmouseover(tooltip);\n", - " }\n", - " };\n", - " }\n", - "\n", - " fig.buttons = {};\n", - " var buttonGroup = document.createElement('div');\n", - " buttonGroup.classList = 'btn-group';\n", - " var button;\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", - " /* Instead of a spacer, we start a new button group. */\n", - " if (buttonGroup.hasChildNodes()) {\n", - " toolbar.appendChild(buttonGroup);\n", - " }\n", - " buttonGroup = document.createElement('div');\n", - " buttonGroup.classList = 'btn-group';\n", - " continue;\n", - " }\n", - "\n", - " button = fig.buttons[name] = document.createElement('button');\n", - " button.classList = 'btn btn-default';\n", - " button.href = '#';\n", - " button.title = name;\n", - " button.innerHTML = '';\n", - " button.addEventListener('click', on_click_closure(method_name));\n", - " button.addEventListener('mouseover', on_mouseover_closure(tooltip));\n", - " buttonGroup.appendChild(button);\n", - " }\n", - "\n", - " if (buttonGroup.hasChildNodes()) {\n", - " toolbar.appendChild(buttonGroup);\n", - " }\n", - "\n", - " // Add the status bar.\n", - " var status_bar = document.createElement('span');\n", - " status_bar.classList = 'mpl-message pull-right';\n", - " toolbar.appendChild(status_bar);\n", - " this.message = status_bar;\n", - "\n", - " // Add the close button to the window.\n", - " var buttongrp = document.createElement('div');\n", - " buttongrp.classList = 'btn-group inline pull-right';\n", - " button = document.createElement('button');\n", - " button.classList = 'btn btn-mini btn-primary';\n", - " button.href = '#';\n", - " button.title = 'Stop Interaction';\n", - " button.innerHTML = '';\n", - " button.addEventListener('click', function (_evt) {\n", - " fig.handle_close(fig, {});\n", - " });\n", - " button.addEventListener(\n", - " 'mouseover',\n", - " on_mouseover_closure('Stop Interaction')\n", - " );\n", - " buttongrp.appendChild(button);\n", - " var titlebar = this.root.querySelector('.ui-dialog-titlebar');\n", - " titlebar.insertBefore(buttongrp, titlebar.firstChild);\n", - "};\n", - "\n", - "mpl.figure.prototype._remove_fig_handler = function (event) {\n", - " var fig = event.data.fig;\n", - " if (event.target !== this) {\n", - " // Ignore bubbled events from children.\n", - " return;\n", - " }\n", - " fig.close_ws(fig, {});\n", - "};\n", - "\n", - "mpl.figure.prototype._root_extra_style = function (el) {\n", - " el.style.boxSizing = 'content-box'; // override notebook setting of border-box.\n", - "};\n", - "\n", - "mpl.figure.prototype._canvas_extra_style = function (el) {\n", - " // this is important to make the div 'focusable\n", - " el.setAttribute('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", - " } else {\n", - " // location in version 2\n", - " IPython.keyboard_manager.register_events(el);\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype._key_event_extra = function (event, _name) {\n", - " // Check for shift+enter\n", - " if (event.shiftKey && event.which === 13) {\n", - " this.canvas_div.blur();\n", - " // select the cell after this one\n", - " var index = IPython.notebook.find_cell_index(this.cell_info[0]);\n", - " IPython.notebook.select(index + 1);\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_save = function (fig, _msg) {\n", - " fig.ondownload(fig, null);\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 < ncells; i++) {\n", - " var cell = cells[i];\n", - " if (cell.cell_type === 'code') {\n", - " for (var j = 0; j < cell.output_area.outputs.length; j++) {\n", - " var data = cell.output_area.outputs[j];\n", - " if (data.data) {\n", - " // IPython >= 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(\n", - " 'matplotlib',\n", - " mpl.mpl_figure_comm\n", - " );\n", - "}\n" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/html": [ - "
" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "Observation: obs0\n", - "Filter: jwst_niriss1:8600.0-28000.0\n", - "Epoch: 715\n", - "Number of outliers removed: 0\n", - "Uncertainties scale factor: 1\n", - "Residuals statistics:\n", - "res_max_autocorr: \t 0.09376261428933856\n", - "res_max_autocorr_flag: \t False\n", - "res_shapiro: \t\t 0.9876790046691895\n", - "res_shapiro_flag: \t True\n", - "res_mean: \t\t 0.15030023209868584\n", - "res_std: \t\t 1006.7915189724673\n", - "res_rms: \t\t 1006.7915301913538\n", - "res_chi_sqr: \t\t 558.9456725427821\n", - "res_red_chi_sqr: \t 1.040867174195125\n" - ] - } - ], - "source": [ - "\n", - "###############################################################################################\n", - "##### Test the performance of the trend function \n", - "###############################################################################################\n", - "\n", - "# We can test the performance of the trend function with quick fit, using: \n", - "# optimiser = 'curve_fit'.\n", - "# Here, the quality of the data is good enough to fit for the orbital parameters (sma and i):\n", - "# fit_sma_over_rs = True\n", - "# fit_inclination = True.\n", - "\n", - "test = planet.transit_fitting(\n", - " optimiser = 'curve_fit',\n", - " fit_sma_over_rs=True, \n", - " fit_inclination=True,\n", - ")\n", - "\n", - "###############################################################################################\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "###############################################################################################\n", - "##### Evaluate test results\n", - "###############################################################################################\n", - "\n", - "# To evaluate the test results we can plot the raw data, trend function, and residuals like this:\n", - "\n", - "observations = len(test['observations'])\n", - "plt.figure(figsize=(9,6))\n", - "for obs_n, obs_id in enumerate(test['observations']):\n", - " observation = test['observations'][obs_id]\n", - " plt.subplot(2, observations, obs_n + 1)\n", - " plt.errorbar(observation['input_series']['time'], \n", - " observation['input_series']['flux'], \n", - " observation['input_series']['flux_unc'], \n", - " fmt='o', zorder=0, label='raw data')\n", - " plt.plot(observation['input_series']['time'], observation['output_series']['trend'], 'r--', zorder=1, \n", - " label='trend model')\n", - " plt.plot(observation['input_series']['time'], observation['output_series']['model'], 'r-', zorder=1,\n", - " label='trend + transit model'\n", - " )\n", - " plt.legend(fontsize='small')\n", - " plt.ylabel('rel. flux')\n", - " plt.title(obs_id)\n", - "\n", - " plt.subplot(2, observations, observations + 1)\n", - " plt.errorbar(observation['input_series']['time'], \n", - " observation['output_series']['residuals'], \n", - " observation['input_series']['flux_unc'], \n", - " fmt='o', zorder=0)\n", - " plt.xlabel('time (BJD_TDB)')\n", - " plt.ylabel('rel. flux residuals')\n", - "\n", - " \n", - " \n", - "# And also print the residuals diagnostics like this:\n", - "\n", - "for obs_n, obs_id in enumerate(test['observations']):\n", - " observation = test['observations'][obs_id]\n", - " print('')\n", - " print('Observation: ', obs_id)\n", - " print('Filter: ', observation['model_info']['filter_id'])\n", - " print('Epoch: ', observation['model_info']['epoch'])\n", - " print('Number of outliers removed: ', observation['data_conversion_info']['outliers'])\n", - " print('Uncertainties scale factor: ', observation['data_conversion_info']['scale_factor'])\n", - "\n", - " print('Residuals statistics:')\n", - " print('res_max_autocorr:', '\\t', observation['statistics']['res_max_autocorr'])\n", - " print('res_max_autocorr_flag:', '\\t', observation['statistics']['res_max_autocorr_flag'])\n", - " print('res_shapiro:', '\\t\\t', observation['statistics']['res_shapiro'])\n", - " print('res_shapiro_flag:', '\\t', observation['statistics']['res_shapiro_flag'])\n", - " print('res_mean:', '\\t\\t', observation['statistics']['res_mean'])\n", - " print('res_std:', '\\t\\t', observation['statistics']['res_std'])\n", - " print('res_rms:', '\\t\\t', observation['statistics']['res_rms'])\n", - " print('res_chi_sqr:', '\\t\\t', observation['statistics']['res_chi_sqr'])\n", - " print('res_red_chi_sqr:', '\\t', observation['statistics']['res_red_chi_sqr'])\n", - " \n", - "###############################################################################################\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "0a5ae6df", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "Observation: obs0\n", - "Filter: jwst_niriss1:8600.0-28000.0\n", - "Epoch: 715\n", - "Data-points excluded: 5\n", - "Scaling uncertainties by: 0.9587711920555325\n", - "\n", - "Optimising initial parameters...\n", - "\u001b[KTransit fitting: 1320 / 5000 , time left: 0:04:03, time elapsed: 0:01:27, total time: 0:05:30" - ] - } - ], - "source": [ - "\n", - "###############################################################################################\n", - "##### MCMC fit\n", - "###############################################################################################\n", - "\n", - "# If the residuals diagniostics look ok, we can run the MCMC.\n", - "# Here we will define the 'output_folder', so that all the results and plots are saved.\n", - "# We don't need to defile the optimiser, as the default one is 'mcmc'.\n", - "# It is also better to use filter_outliers=True to clear the outliers and \n", - "# and scale_uncertainties=True to scale the errorbars to match the residuals rms.\n", - "\n", - "final = planet.transit_fitting(\n", - " output_folder = 'wasp39b_jwst',\n", - " fit_sma_over_rs=True, \n", - " fit_inclination=True,\n", - " filter_outliers=True,\n", - " scale_uncertainties=True,\n", - ")\n", - "\n", - "# By default, the number of iterations is 5000 and the burn in is 1000.\n", - "# If the chains do not converge, we can increase these number, for example by setting:\n", - "# iterations = 10000\n", - "# burn_in = 5000\n", - "\n", - "###############################################################################################\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "8a63e738", - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "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.11.5" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/notebooks/2_detrending_examples/.ipynb_checkpoints/4_wasp39b_hst-checkpoint.ipynb b/notebooks/2_detrending_examples/.ipynb_checkpoints/4_wasp39b_hst-checkpoint.ipynb deleted file mode 100644 index 8635bfe..0000000 --- a/notebooks/2_detrending_examples/.ipynb_checkpoints/4_wasp39b_hst-checkpoint.ipynb +++ /dev/null @@ -1,3434 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "id": "988b5848", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "exoclock: Checking ephemerides database...\n", - "exoclock: Checking catalogues database...\n", - "exoclock: Checking ut database...\n", - "pylightcurve: Checking exotethys database...\n", - "pylightcurve: Checking photometry database...\n" - ] - } - ], - "source": [ - "%matplotlib notebook\n", - "import matplotlib.pyplot as plt\n", - "import pylightcurve as plc\n", - "import numpy as np\n", - "\n", - "\n", - "###############################################################################################\n", - "##### Create a Planet object\n", - "###############################################################################################\n", - "\n", - "# At first we need to create a Planet object.\n", - "# Planets include in the ExoClock project (https://www.exoclock.space/database/planets)\n", - "# can be loaded automatically. \n", - "# Alteranatively we can difine our custom Planet object (see notebook: The Planet class)\n", - "\n", - "planet = plc.get_planet('WASP-39b')\n", - "\n", - "###############################################################################################\n" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "id": "6e3c08e4", - "metadata": {}, - "outputs": [ - { - "data": { - "application/javascript": [ - "/* Put everything inside the global mpl namespace */\n", - "/* global mpl */\n", - "window.mpl = {};\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(\n", - " '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", - "\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 = document.createElement('div');\n", - " this.root.setAttribute('style', 'display: inline-block');\n", - " this._root_extra_style(this.root);\n", - "\n", - " parent_element.appendChild(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 (fig.ratio !== 1) {\n", - " fig.send_message('set_device_pixel_ratio', {\n", - " device_pixel_ratio: fig.ratio,\n", - " });\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 = document.createElement('div');\n", - " titlebar.classList =\n", - " 'ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix';\n", - " var titletext = document.createElement('div');\n", - " titletext.classList = 'ui-dialog-title';\n", - " titletext.setAttribute(\n", - " 'style',\n", - " 'width: 100%; text-align: center; padding: 3px;'\n", - " );\n", - " titlebar.appendChild(titletext);\n", - " this.root.appendChild(titlebar);\n", - " this.header = titletext;\n", - "};\n", - "\n", - "mpl.figure.prototype._canvas_extra_style = function (_canvas_div) {};\n", - "\n", - "mpl.figure.prototype._root_extra_style = function (_canvas_div) {};\n", - "\n", - "mpl.figure.prototype._init_canvas = function () {\n", - " var fig = this;\n", - "\n", - " var canvas_div = (this.canvas_div = document.createElement('div'));\n", - " canvas_div.setAttribute('tabindex', '0');\n", - " canvas_div.setAttribute(\n", - " 'style',\n", - " 'border: 1px solid #ddd;' +\n", - " 'box-sizing: content-box;' +\n", - " 'clear: both;' +\n", - " 'min-height: 1px;' +\n", - " 'min-width: 1px;' +\n", - " 'outline: 0;' +\n", - " 'overflow: hidden;' +\n", - " 'position: relative;' +\n", - " 'resize: both;' +\n", - " 'z-index: 2;'\n", - " );\n", - "\n", - " function on_keyboard_event_closure(name) {\n", - " return function (event) {\n", - " return fig.key_event(event, name);\n", - " };\n", - " }\n", - "\n", - " canvas_div.addEventListener(\n", - " 'keydown',\n", - " on_keyboard_event_closure('key_press')\n", - " );\n", - " canvas_div.addEventListener(\n", - " 'keyup',\n", - " on_keyboard_event_closure('key_release')\n", - " );\n", - "\n", - " this._canvas_extra_style(canvas_div);\n", - " this.root.appendChild(canvas_div);\n", - "\n", - " var canvas = (this.canvas = document.createElement('canvas'));\n", - " canvas.classList.add('mpl-canvas');\n", - " canvas.setAttribute(\n", - " 'style',\n", - " 'box-sizing: content-box;' +\n", - " 'pointer-events: none;' +\n", - " 'position: relative;' +\n", - " 'z-index: 0;'\n", - " );\n", - "\n", - " this.context = canvas.getContext('2d');\n", - "\n", - " var backingStore =\n", - " this.context.backingStorePixelRatio ||\n", - " this.context.webkitBackingStorePixelRatio ||\n", - " this.context.mozBackingStorePixelRatio ||\n", - " this.context.msBackingStorePixelRatio ||\n", - " this.context.oBackingStorePixelRatio ||\n", - " this.context.backingStorePixelRatio ||\n", - " 1;\n", - "\n", - " this.ratio = (window.devicePixelRatio || 1) / backingStore;\n", - "\n", - " var rubberband_canvas = (this.rubberband_canvas = document.createElement(\n", - " 'canvas'\n", - " ));\n", - " rubberband_canvas.setAttribute(\n", - " 'style',\n", - " 'box-sizing: content-box;' +\n", - " 'left: 0;' +\n", - " 'pointer-events: none;' +\n", - " 'position: absolute;' +\n", - " 'top: 0;' +\n", - " 'z-index: 1;'\n", - " );\n", - "\n", - " // Apply a ponyfill if ResizeObserver is not implemented by browser.\n", - " if (this.ResizeObserver === undefined) {\n", - " if (window.ResizeObserver !== undefined) {\n", - " this.ResizeObserver = window.ResizeObserver;\n", - " } else {\n", - " var obs = _JSXTOOLS_RESIZE_OBSERVER({});\n", - " this.ResizeObserver = obs.ResizeObserver;\n", - " }\n", - " }\n", - "\n", - " this.resizeObserverInstance = new this.ResizeObserver(function (entries) {\n", - " // There's no need to resize if the WebSocket is not connected:\n", - " // - If it is still connecting, then we will get an initial resize from\n", - " // Python once it connects.\n", - " // - If it has disconnected, then resizing will clear the canvas and\n", - " // never get anything back to refill it, so better to not resize and\n", - " // keep something visible.\n", - " if (fig.ws.readyState != 1) {\n", - " return;\n", - " }\n", - " var nentries = entries.length;\n", - " for (var i = 0; i < nentries; i++) {\n", - " var entry = entries[i];\n", - " var width, height;\n", - " if (entry.contentBoxSize) {\n", - " if (entry.contentBoxSize instanceof Array) {\n", - " // Chrome 84 implements new version of spec.\n", - " width = entry.contentBoxSize[0].inlineSize;\n", - " height = entry.contentBoxSize[0].blockSize;\n", - " } else {\n", - " // Firefox implements old version of spec.\n", - " width = entry.contentBoxSize.inlineSize;\n", - " height = entry.contentBoxSize.blockSize;\n", - " }\n", - " } else {\n", - " // Chrome <84 implements even older version of spec.\n", - " width = entry.contentRect.width;\n", - " height = entry.contentRect.height;\n", - " }\n", - "\n", - " // Keep the size of the canvas and rubber band canvas in sync with\n", - " // the canvas container.\n", - " if (entry.devicePixelContentBoxSize) {\n", - " // Chrome 84 implements new version of spec.\n", - " canvas.setAttribute(\n", - " 'width',\n", - " entry.devicePixelContentBoxSize[0].inlineSize\n", - " );\n", - " canvas.setAttribute(\n", - " 'height',\n", - " entry.devicePixelContentBoxSize[0].blockSize\n", - " );\n", - " } else {\n", - " canvas.setAttribute('width', width * fig.ratio);\n", - " canvas.setAttribute('height', height * fig.ratio);\n", - " }\n", - " /* This rescales the canvas back to display pixels, so that it\n", - " * appears correct on HiDPI screens. */\n", - " canvas.style.width = width + 'px';\n", - " canvas.style.height = height + 'px';\n", - "\n", - " rubberband_canvas.setAttribute('width', width);\n", - " rubberband_canvas.setAttribute('height', height);\n", - "\n", - " // And update the size in Python. We ignore the initial 0/0 size\n", - " // that occurs as the element is placed into the DOM, which should\n", - " // otherwise not happen due to the minimum size styling.\n", - " if (width != 0 && height != 0) {\n", - " fig.request_resize(width, height);\n", - " }\n", - " }\n", - " });\n", - " this.resizeObserverInstance.observe(canvas_div);\n", - "\n", - " function on_mouse_event_closure(name) {\n", - " /* User Agent sniffing is bad, but WebKit is busted:\n", - " * https://bugs.webkit.org/show_bug.cgi?id=144526\n", - " * https://bugs.webkit.org/show_bug.cgi?id=181818\n", - " * The worst that happens here is that they get an extra browser\n", - " * selection when dragging, if this check fails to catch them.\n", - " */\n", - " var UA = navigator.userAgent;\n", - " var isWebKit = /AppleWebKit/.test(UA) && !/Chrome/.test(UA);\n", - " if(isWebKit) {\n", - " return function (event) {\n", - " /* This prevents the web browser from automatically changing to\n", - " * the text insertion cursor when the button is pressed. We\n", - " * want to control all of the cursor setting manually through\n", - " * the 'cursor' event from matplotlib */\n", - " event.preventDefault()\n", - " return fig.mouse_event(event, name);\n", - " };\n", - " } else {\n", - " return function (event) {\n", - " return fig.mouse_event(event, name);\n", - " };\n", - " }\n", - " }\n", - "\n", - " canvas_div.addEventListener(\n", - " 'mousedown',\n", - " on_mouse_event_closure('button_press')\n", - " );\n", - " canvas_div.addEventListener(\n", - " 'mouseup',\n", - " on_mouse_event_closure('button_release')\n", - " );\n", - " canvas_div.addEventListener(\n", - " 'dblclick',\n", - " on_mouse_event_closure('dblclick')\n", - " );\n", - " // Throttle sequential mouse events to 1 every 20ms.\n", - " canvas_div.addEventListener(\n", - " 'mousemove',\n", - " on_mouse_event_closure('motion_notify')\n", - " );\n", - "\n", - " canvas_div.addEventListener(\n", - " 'mouseenter',\n", - " on_mouse_event_closure('figure_enter')\n", - " );\n", - " canvas_div.addEventListener(\n", - " 'mouseleave',\n", - " on_mouse_event_closure('figure_leave')\n", - " );\n", - "\n", - " canvas_div.addEventListener('wheel', function (event) {\n", - " if (event.deltaY < 0) {\n", - " event.step = 1;\n", - " } else {\n", - " event.step = -1;\n", - " }\n", - " on_mouse_event_closure('scroll')(event);\n", - " });\n", - "\n", - " canvas_div.appendChild(canvas);\n", - " canvas_div.appendChild(rubberband_canvas);\n", - "\n", - " this.rubberband_context = rubberband_canvas.getContext('2d');\n", - " this.rubberband_context.strokeStyle = '#000000';\n", - "\n", - " this._resize_canvas = function (width, height, forward) {\n", - " if (forward) {\n", - " canvas_div.style.width = width + 'px';\n", - " canvas_div.style.height = height + 'px';\n", - " }\n", - " };\n", - "\n", - " // Disable right mouse context menu.\n", - " canvas_div.addEventListener('contextmenu', function (_e) {\n", - " event.preventDefault();\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 toolbar = document.createElement('div');\n", - " toolbar.classList = 'mpl-toolbar';\n", - " this.root.appendChild(toolbar);\n", - "\n", - " function on_click_closure(name) {\n", - " return function (_event) {\n", - " return fig.toolbar_button_onclick(name);\n", - " };\n", - " }\n", - "\n", - " function on_mouseover_closure(tooltip) {\n", - " return function (event) {\n", - " if (!event.currentTarget.disabled) {\n", - " return fig.toolbar_button_onmouseover(tooltip);\n", - " }\n", - " };\n", - " }\n", - "\n", - " fig.buttons = {};\n", - " var buttonGroup = document.createElement('div');\n", - " buttonGroup.classList = 'mpl-button-group';\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", - " /* Instead of a spacer, we start a new button group. */\n", - " if (buttonGroup.hasChildNodes()) {\n", - " toolbar.appendChild(buttonGroup);\n", - " }\n", - " buttonGroup = document.createElement('div');\n", - " buttonGroup.classList = 'mpl-button-group';\n", - " continue;\n", - " }\n", - "\n", - " var button = (fig.buttons[name] = document.createElement('button'));\n", - " button.classList = 'mpl-widget';\n", - " button.setAttribute('role', 'button');\n", - " button.setAttribute('aria-disabled', 'false');\n", - " button.addEventListener('click', on_click_closure(method_name));\n", - " button.addEventListener('mouseover', on_mouseover_closure(tooltip));\n", - "\n", - " var icon_img = document.createElement('img');\n", - " icon_img.src = '_images/' + image + '.png';\n", - " icon_img.srcset = '_images/' + image + '_large.png 2x';\n", - " icon_img.alt = tooltip;\n", - " button.appendChild(icon_img);\n", - "\n", - " buttonGroup.appendChild(button);\n", - " }\n", - "\n", - " if (buttonGroup.hasChildNodes()) {\n", - " toolbar.appendChild(buttonGroup);\n", - " }\n", - "\n", - " var fmt_picker = document.createElement('select');\n", - " fmt_picker.classList = 'mpl-widget';\n", - " toolbar.appendChild(fmt_picker);\n", - " this.format_dropdown = fmt_picker;\n", - "\n", - " for (var ind in mpl.extensions) {\n", - " var fmt = mpl.extensions[ind];\n", - " var option = document.createElement('option');\n", - " option.selected = fmt === mpl.default_extension;\n", - " option.innerHTML = fmt;\n", - " fmt_picker.appendChild(option);\n", - " }\n", - "\n", - " var status_bar = document.createElement('span');\n", - " status_bar.classList = 'mpl-message';\n", - " toolbar.appendChild(status_bar);\n", - " this.message = status_bar;\n", - "};\n", - "\n", - "mpl.figure.prototype.request_resize = function (x_pixels, y_pixels) {\n", - " // Request matplotlib to resize the figure. Matplotlib will then trigger a resize in the client,\n", - " // which will in turn request a refresh of the image.\n", - " this.send_message('resize', { width: x_pixels, height: y_pixels });\n", - "};\n", - "\n", - "mpl.figure.prototype.send_message = function (type, properties) {\n", - " properties['type'] = type;\n", - " properties['figure_id'] = this.id;\n", - " this.ws.send(JSON.stringify(properties));\n", - "};\n", - "\n", - "mpl.figure.prototype.send_draw_message = function () {\n", - " if (!this.waiting) {\n", - " this.waiting = true;\n", - " this.ws.send(JSON.stringify({ type: 'draw', figure_id: this.id }));\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_save = function (fig, _msg) {\n", - " var format_dropdown = fig.format_dropdown;\n", - " var format = format_dropdown.options[format_dropdown.selectedIndex].value;\n", - " fig.ondownload(fig, format);\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_resize = function (fig, msg) {\n", - " var size = msg['size'];\n", - " if (size[0] !== fig.canvas.width || size[1] !== fig.canvas.height) {\n", - " fig._resize_canvas(size[0], size[1], msg['forward']);\n", - " fig.send_message('refresh', {});\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_rubberband = function (fig, msg) {\n", - " var x0 = msg['x0'] / fig.ratio;\n", - " var y0 = (fig.canvas.height - msg['y0']) / fig.ratio;\n", - " var x1 = msg['x1'] / fig.ratio;\n", - " var y1 = (fig.canvas.height - msg['y1']) / fig.ratio;\n", - " x0 = Math.floor(x0) + 0.5;\n", - " y0 = Math.floor(y0) + 0.5;\n", - " x1 = Math.floor(x1) + 0.5;\n", - " y1 = Math.floor(y1) + 0.5;\n", - " var min_x = Math.min(x0, x1);\n", - " var min_y = Math.min(y0, y1);\n", - " var width = Math.abs(x1 - x0);\n", - " var height = Math.abs(y1 - y0);\n", - "\n", - " fig.rubberband_context.clearRect(\n", - " 0,\n", - " 0,\n", - " fig.canvas.width / fig.ratio,\n", - " fig.canvas.height / fig.ratio\n", - " );\n", - "\n", - " fig.rubberband_context.strokeRect(min_x, min_y, width, height);\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_figure_label = function (fig, msg) {\n", - " // Updates the figure title.\n", - " fig.header.textContent = msg['label'];\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_cursor = function (fig, msg) {\n", - " fig.canvas_div.style.cursor = msg['cursor'];\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_message = function (fig, msg) {\n", - " fig.message.textContent = msg['message'];\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_draw = function (fig, _msg) {\n", - " // Request the server to send over a new figure.\n", - " fig.send_draw_message();\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_image_mode = function (fig, msg) {\n", - " fig.image_mode = msg['mode'];\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_history_buttons = function (fig, msg) {\n", - " for (var key in msg) {\n", - " if (!(key in fig.buttons)) {\n", - " continue;\n", - " }\n", - " fig.buttons[key].disabled = !msg[key];\n", - " fig.buttons[key].setAttribute('aria-disabled', !msg[key]);\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_navigate_mode = function (fig, msg) {\n", - " if (msg['mode'] === 'PAN') {\n", - " fig.buttons['Pan'].classList.add('active');\n", - " fig.buttons['Zoom'].classList.remove('active');\n", - " } else if (msg['mode'] === 'ZOOM') {\n", - " fig.buttons['Pan'].classList.remove('active');\n", - " fig.buttons['Zoom'].classList.add('active');\n", - " } else {\n", - " fig.buttons['Pan'].classList.remove('active');\n", - " fig.buttons['Zoom'].classList.remove('active');\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.updated_canvas_event = function () {\n", - " // Called whenever the canvas gets updated.\n", - " this.send_message('ack', {});\n", - "};\n", - "\n", - "// A function to construct a web socket function for onmessage handling.\n", - "// Called in the figure constructor.\n", - "mpl.figure.prototype._make_on_message_function = function (fig) {\n", - " return function socket_on_message(evt) {\n", - " if (evt.data instanceof Blob) {\n", - " var img = evt.data;\n", - " if (img.type !== 'image/png') {\n", - " /* FIXME: We get \"Resource interpreted as Image but\n", - " * transferred with MIME type text/plain:\" errors on\n", - " * Chrome. But how to set the MIME type? It doesn't seem\n", - " * to be part of the websocket stream */\n", - " img.type = 'image/png';\n", - " }\n", - "\n", - " /* Free the memory for the previous frames */\n", - " if (fig.imageObj.src) {\n", - " (window.URL || window.webkitURL).revokeObjectURL(\n", - " fig.imageObj.src\n", - " );\n", - " }\n", - "\n", - " fig.imageObj.src = (window.URL || window.webkitURL).createObjectURL(\n", - " img\n", - " );\n", - " fig.updated_canvas_event();\n", - " fig.waiting = false;\n", - " return;\n", - " } else if (\n", - " typeof evt.data === 'string' &&\n", - " evt.data.slice(0, 21) === 'data:image/png;base64'\n", - " ) {\n", - " fig.imageObj.src = evt.data;\n", - " fig.updated_canvas_event();\n", - " fig.waiting = false;\n", - " return;\n", - " }\n", - "\n", - " var msg = JSON.parse(evt.data);\n", - " var msg_type = msg['type'];\n", - "\n", - " // Call the \"handle_{type}\" callback, which takes\n", - " // the figure and JSON message as its only arguments.\n", - " try {\n", - " var callback = fig['handle_' + msg_type];\n", - " } catch (e) {\n", - " console.log(\n", - " \"No handler for the '\" + msg_type + \"' message type: \",\n", - " msg\n", - " );\n", - " return;\n", - " }\n", - "\n", - " if (callback) {\n", - " try {\n", - " // console.log(\"Handling '\" + msg_type + \"' message: \", msg);\n", - " callback(fig, msg);\n", - " } catch (e) {\n", - " console.log(\n", - " \"Exception inside the 'handler_\" + msg_type + \"' callback:\",\n", - " e,\n", - " e.stack,\n", - " msg\n", - " );\n", - " }\n", - " }\n", - " };\n", - "};\n", - "\n", - "function getModifiers(event) {\n", - " var mods = [];\n", - " if (event.ctrlKey) {\n", - " mods.push('ctrl');\n", - " }\n", - " if (event.altKey) {\n", - " mods.push('alt');\n", - " }\n", - " if (event.shiftKey) {\n", - " mods.push('shift');\n", - " }\n", - " if (event.metaKey) {\n", - " mods.push('meta');\n", - " }\n", - " return mods;\n", - "}\n", - "\n", - "/*\n", - " * return a copy of an object with only non-object keys\n", - " * we need this to avoid circular references\n", - " * https://stackoverflow.com/a/24161582/3208463\n", - " */\n", - "function simpleKeys(original) {\n", - " return Object.keys(original).reduce(function (obj, key) {\n", - " if (typeof original[key] !== 'object') {\n", - " obj[key] = original[key];\n", - " }\n", - " return obj;\n", - " }, {});\n", - "}\n", - "\n", - "mpl.figure.prototype.mouse_event = function (event, name) {\n", - " if (name === 'button_press') {\n", - " this.canvas.focus();\n", - " this.canvas_div.focus();\n", - " }\n", - "\n", - " // from https://stackoverflow.com/q/1114465\n", - " var boundingRect = this.canvas.getBoundingClientRect();\n", - " var x = (event.clientX - boundingRect.left) * this.ratio;\n", - " var y = (event.clientY - boundingRect.top) * this.ratio;\n", - "\n", - " this.send_message(name, {\n", - " x: x,\n", - " y: y,\n", - " button: event.button,\n", - " step: event.step,\n", - " modifiers: getModifiers(event),\n", - " guiEvent: simpleKeys(event),\n", - " });\n", - "\n", - " return false;\n", - "};\n", - "\n", - "mpl.figure.prototype._key_event_extra = function (_event, _name) {\n", - " // Handle any extra behaviour associated with a key event\n", - "};\n", - "\n", - "mpl.figure.prototype.key_event = function (event, name) {\n", - " // Prevent repeat events\n", - " if (name === 'key_press') {\n", - " if (event.key === this._key) {\n", - " return;\n", - " } else {\n", - " this._key = event.key;\n", - " }\n", - " }\n", - " if (name === 'key_release') {\n", - " this._key = null;\n", - " }\n", - "\n", - " var value = '';\n", - " if (event.ctrlKey && event.key !== 'Control') {\n", - " value += 'ctrl+';\n", - " }\n", - " else if (event.altKey && event.key !== 'Alt') {\n", - " value += 'alt+';\n", - " }\n", - " else if (event.shiftKey && event.key !== 'Shift') {\n", - " value += 'shift+';\n", - " }\n", - "\n", - " value += 'k' + event.key;\n", - "\n", - " this._key_event_extra(event, name);\n", - "\n", - " this.send_message(name, { key: value, guiEvent: simpleKeys(event) });\n", - " return false;\n", - "};\n", - "\n", - "mpl.figure.prototype.toolbar_button_onclick = function (name) {\n", - " if (name === 'download') {\n", - " this.handle_save(this, null);\n", - " } else {\n", - " this.send_message('toolbar_button', { name: name });\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.toolbar_button_onmouseover = function (tooltip) {\n", - " this.message.textContent = tooltip;\n", - "};\n", - "\n", - "///////////////// REMAINING CONTENT GENERATED BY embed_js.py /////////////////\n", - "// prettier-ignore\n", - "var _JSXTOOLS_RESIZE_OBSERVER=function(A){var t,i=new WeakMap,n=new WeakMap,a=new WeakMap,r=new WeakMap,o=new Set;function s(e){if(!(this instanceof s))throw new TypeError(\"Constructor requires 'new' operator\");i.set(this,e)}function h(){throw new TypeError(\"Function is not a constructor\")}function c(e,t,i,n){e=0 in arguments?Number(arguments[0]):0,t=1 in arguments?Number(arguments[1]):0,i=2 in arguments?Number(arguments[2]):0,n=3 in arguments?Number(arguments[3]):0,this.right=(this.x=this.left=e)+(this.width=i),this.bottom=(this.y=this.top=t)+(this.height=n),Object.freeze(this)}function d(){t=requestAnimationFrame(d);var s=new WeakMap,p=new Set;o.forEach((function(t){r.get(t).forEach((function(i){var r=t instanceof window.SVGElement,o=a.get(t),d=r?0:parseFloat(o.paddingTop),f=r?0:parseFloat(o.paddingRight),l=r?0:parseFloat(o.paddingBottom),u=r?0:parseFloat(o.paddingLeft),g=r?0:parseFloat(o.borderTopWidth),m=r?0:parseFloat(o.borderRightWidth),w=r?0:parseFloat(o.borderBottomWidth),b=u+f,F=d+l,v=(r?0:parseFloat(o.borderLeftWidth))+m,W=g+w,y=r?0:t.offsetHeight-W-t.clientHeight,E=r?0:t.offsetWidth-v-t.clientWidth,R=b+v,z=F+W,M=r?t.width:parseFloat(o.width)-R-E,O=r?t.height:parseFloat(o.height)-z-y;if(n.has(t)){var k=n.get(t);if(k[0]===M&&k[1]===O)return}n.set(t,[M,O]);var S=Object.create(h.prototype);S.target=t,S.contentRect=new c(u,d,M,O),s.has(i)||(s.set(i,[]),p.add(i)),s.get(i).push(S)}))})),p.forEach((function(e){i.get(e).call(e,s.get(e),e)}))}return s.prototype.observe=function(i){if(i instanceof window.Element){r.has(i)||(r.set(i,new Set),o.add(i),a.set(i,window.getComputedStyle(i)));var n=r.get(i);n.has(this)||n.add(this),cancelAnimationFrame(t),t=requestAnimationFrame(d)}},s.prototype.unobserve=function(i){if(i instanceof window.Element&&r.has(i)){var n=r.get(i);n.has(this)&&(n.delete(this),n.size||(r.delete(i),o.delete(i))),n.size||r.delete(i),o.size||cancelAnimationFrame(t)}},A.DOMRectReadOnly=c,A.ResizeObserver=s,A.ResizeObserverEntry=h,A}; // eslint-disable-line\n", - "mpl.toolbar_items = [[\"Home\", \"Reset original view\", \"fa fa-home\", \"home\"], [\"Back\", \"Back to previous view\", \"fa fa-arrow-left\", \"back\"], [\"Forward\", \"Forward to next view\", \"fa fa-arrow-right\", \"forward\"], [\"\", \"\", \"\", \"\"], [\"Pan\", \"Left button pans, Right button zooms\\nx/y fixes axis, CTRL fixes aspect\", \"fa fa-arrows\", \"pan\"], [\"Zoom\", \"Zoom to rectangle\\nx/y fixes axis\", \"fa fa-square-o\", \"zoom\"], [\"\", \"\", \"\", \"\"], [\"Download\", \"Download plot\", \"fa fa-floppy-o\", \"download\"]];\n", - "\n", - "mpl.extensions = [\"eps\", \"jpeg\", \"pgf\", \"pdf\", \"png\", \"ps\", \"raw\", \"svg\", \"tif\", \"webp\"];\n", - "\n", - "mpl.default_extension = \"png\";/* global mpl */\n", - "\n", - "var comm_websocket_adapter = function (comm) {\n", - " // Create a \"websocket\"-like object which calls the given IPython comm\n", - " // object with the appropriate methods. Currently this is a non binary\n", - " // socket, so there is still some room for performance tuning.\n", - " var ws = {};\n", - "\n", - " ws.binaryType = comm.kernel.ws.binaryType;\n", - " ws.readyState = comm.kernel.ws.readyState;\n", - " function updateReadyState(_event) {\n", - " if (comm.kernel.ws) {\n", - " ws.readyState = comm.kernel.ws.readyState;\n", - " } else {\n", - " ws.readyState = 3; // Closed state.\n", - " }\n", - " }\n", - " comm.kernel.ws.addEventListener('open', updateReadyState);\n", - " comm.kernel.ws.addEventListener('close', updateReadyState);\n", - " comm.kernel.ws.addEventListener('error', updateReadyState);\n", - "\n", - " ws.close = function () {\n", - " comm.close();\n", - " };\n", - " ws.send = function (m) {\n", - " //console.log('sending', m);\n", - " comm.send(m);\n", - " };\n", - " // Register the callback with on_msg.\n", - " comm.on_msg(function (msg) {\n", - " //console.log('receiving', msg['content']['data'], msg);\n", - " var data = msg['content']['data'];\n", - " if (data['blob'] !== undefined) {\n", - " data = {\n", - " data: new Blob(msg['buffers'], { type: data['blob'] }),\n", - " };\n", - " }\n", - " // Pass the mpl event to the overridden (by mpl) onmessage function.\n", - " ws.onmessage(data);\n", - " });\n", - " return ws;\n", - "};\n", - "\n", - "mpl.mpl_figure_comm = function (comm, msg) {\n", - " // This is the function which gets called when the mpl process\n", - " // starts-up an IPython Comm through the \"matplotlib\" channel.\n", - "\n", - " var id = msg.content.data.id;\n", - " // Get hold of the div created by the display call when the Comm\n", - " // socket was opened in Python.\n", - " var element = document.getElementById(id);\n", - " var ws_proxy = comm_websocket_adapter(comm);\n", - "\n", - " function ondownload(figure, _format) {\n", - " window.open(figure.canvas.toDataURL());\n", - " }\n", - "\n", - " var fig = new mpl.figure(id, ws_proxy, ondownload, element);\n", - "\n", - " // Call onopen now - mpl needs it, as it is assuming we've passed it a real\n", - " // web socket which is closed, not our websocket->open comm proxy.\n", - " ws_proxy.onopen();\n", - "\n", - " fig.parent_element = element;\n", - " fig.cell_info = mpl.find_output_cell(\"
\");\n", - " if (!fig.cell_info) {\n", - " console.error('Failed to find cell for figure', id, fig);\n", - " return;\n", - " }\n", - " fig.cell_info[0].output_area.element.on(\n", - " 'cleared',\n", - " { fig: fig },\n", - " fig._remove_fig_handler\n", - " );\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_close = function (fig, msg) {\n", - " var width = fig.canvas.width / fig.ratio;\n", - " fig.cell_info[0].output_area.element.off(\n", - " 'cleared',\n", - " fig._remove_fig_handler\n", - " );\n", - " fig.resizeObserverInstance.unobserve(fig.canvas_div);\n", - "\n", - " // Update the output cell to use the data from the current canvas.\n", - " fig.push_to_output();\n", - " var dataURL = fig.canvas.toDataURL();\n", - " // Re-enable the keyboard manager in IPython - without this line, in FF,\n", - " // the notebook keyboard shortcuts fail.\n", - " IPython.keyboard_manager.enable();\n", - " fig.parent_element.innerHTML =\n", - " '';\n", - " fig.close_ws(fig, msg);\n", - "};\n", - "\n", - "mpl.figure.prototype.close_ws = function (fig, msg) {\n", - " fig.send_message('closing', msg);\n", - " // fig.ws.close()\n", - "};\n", - "\n", - "mpl.figure.prototype.push_to_output = function (_remove_interactive) {\n", - " // Turn the data on the canvas into data in the output cell.\n", - " var width = this.canvas.width / this.ratio;\n", - " var dataURL = this.canvas.toDataURL();\n", - " this.cell_info[1]['text/html'] =\n", - " '';\n", - "};\n", - "\n", - "mpl.figure.prototype.updated_canvas_event = function () {\n", - " // Tell IPython that the notebook contents must change.\n", - " IPython.notebook.set_dirty(true);\n", - " this.send_message('ack', {});\n", - " var fig = this;\n", - " // Wait a second, then push the new image to the DOM so\n", - " // that it is saved nicely (might be nice to debounce this).\n", - " setTimeout(function () {\n", - " fig.push_to_output();\n", - " }, 1000);\n", - "};\n", - "\n", - "mpl.figure.prototype._init_toolbar = function () {\n", - " var fig = this;\n", - "\n", - " var toolbar = document.createElement('div');\n", - " toolbar.classList = 'btn-toolbar';\n", - " this.root.appendChild(toolbar);\n", - "\n", - " function on_click_closure(name) {\n", - " return function (_event) {\n", - " return fig.toolbar_button_onclick(name);\n", - " };\n", - " }\n", - "\n", - " function on_mouseover_closure(tooltip) {\n", - " return function (event) {\n", - " if (!event.currentTarget.disabled) {\n", - " return fig.toolbar_button_onmouseover(tooltip);\n", - " }\n", - " };\n", - " }\n", - "\n", - " fig.buttons = {};\n", - " var buttonGroup = document.createElement('div');\n", - " buttonGroup.classList = 'btn-group';\n", - " var button;\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", - " /* Instead of a spacer, we start a new button group. */\n", - " if (buttonGroup.hasChildNodes()) {\n", - " toolbar.appendChild(buttonGroup);\n", - " }\n", - " buttonGroup = document.createElement('div');\n", - " buttonGroup.classList = 'btn-group';\n", - " continue;\n", - " }\n", - "\n", - " button = fig.buttons[name] = document.createElement('button');\n", - " button.classList = 'btn btn-default';\n", - " button.href = '#';\n", - " button.title = name;\n", - " button.innerHTML = '';\n", - " button.addEventListener('click', on_click_closure(method_name));\n", - " button.addEventListener('mouseover', on_mouseover_closure(tooltip));\n", - " buttonGroup.appendChild(button);\n", - " }\n", - "\n", - " if (buttonGroup.hasChildNodes()) {\n", - " toolbar.appendChild(buttonGroup);\n", - " }\n", - "\n", - " // Add the status bar.\n", - " var status_bar = document.createElement('span');\n", - " status_bar.classList = 'mpl-message pull-right';\n", - " toolbar.appendChild(status_bar);\n", - " this.message = status_bar;\n", - "\n", - " // Add the close button to the window.\n", - " var buttongrp = document.createElement('div');\n", - " buttongrp.classList = 'btn-group inline pull-right';\n", - " button = document.createElement('button');\n", - " button.classList = 'btn btn-mini btn-primary';\n", - " button.href = '#';\n", - " button.title = 'Stop Interaction';\n", - " button.innerHTML = '';\n", - " button.addEventListener('click', function (_evt) {\n", - " fig.handle_close(fig, {});\n", - " });\n", - " button.addEventListener(\n", - " 'mouseover',\n", - " on_mouseover_closure('Stop Interaction')\n", - " );\n", - " buttongrp.appendChild(button);\n", - " var titlebar = this.root.querySelector('.ui-dialog-titlebar');\n", - " titlebar.insertBefore(buttongrp, titlebar.firstChild);\n", - "};\n", - "\n", - "mpl.figure.prototype._remove_fig_handler = function (event) {\n", - " var fig = event.data.fig;\n", - " if (event.target !== this) {\n", - " // Ignore bubbled events from children.\n", - " return;\n", - " }\n", - " fig.close_ws(fig, {});\n", - "};\n", - "\n", - "mpl.figure.prototype._root_extra_style = function (el) {\n", - " el.style.boxSizing = 'content-box'; // override notebook setting of border-box.\n", - "};\n", - "\n", - "mpl.figure.prototype._canvas_extra_style = function (el) {\n", - " // this is important to make the div 'focusable\n", - " el.setAttribute('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", - " } else {\n", - " // location in version 2\n", - " IPython.keyboard_manager.register_events(el);\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype._key_event_extra = function (event, _name) {\n", - " // Check for shift+enter\n", - " if (event.shiftKey && event.which === 13) {\n", - " this.canvas_div.blur();\n", - " // select the cell after this one\n", - " var index = IPython.notebook.find_cell_index(this.cell_info[0]);\n", - " IPython.notebook.select(index + 1);\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_save = function (fig, _msg) {\n", - " fig.ondownload(fig, null);\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 < ncells; i++) {\n", - " var cell = cells[i];\n", - " if (cell.cell_type === 'code') {\n", - " for (var j = 0; j < cell.output_area.outputs.length; j++) {\n", - " var data = cell.output_area.outputs[j];\n", - " if (data.data) {\n", - " // IPython >= 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(\n", - " 'matplotlib',\n", - " mpl.mpl_figure_comm\n", - " );\n", - "}\n" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/html": [ - "
" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Auxiliary data available:\n" - ] - }, - { - "data": { - "application/javascript": [ - "/* Put everything inside the global mpl namespace */\n", - "/* global mpl */\n", - "window.mpl = {};\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(\n", - " '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", - "\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 = document.createElement('div');\n", - " this.root.setAttribute('style', 'display: inline-block');\n", - " this._root_extra_style(this.root);\n", - "\n", - " parent_element.appendChild(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 (fig.ratio !== 1) {\n", - " fig.send_message('set_device_pixel_ratio', {\n", - " device_pixel_ratio: fig.ratio,\n", - " });\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 = document.createElement('div');\n", - " titlebar.classList =\n", - " 'ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix';\n", - " var titletext = document.createElement('div');\n", - " titletext.classList = 'ui-dialog-title';\n", - " titletext.setAttribute(\n", - " 'style',\n", - " 'width: 100%; text-align: center; padding: 3px;'\n", - " );\n", - " titlebar.appendChild(titletext);\n", - " this.root.appendChild(titlebar);\n", - " this.header = titletext;\n", - "};\n", - "\n", - "mpl.figure.prototype._canvas_extra_style = function (_canvas_div) {};\n", - "\n", - "mpl.figure.prototype._root_extra_style = function (_canvas_div) {};\n", - "\n", - "mpl.figure.prototype._init_canvas = function () {\n", - " var fig = this;\n", - "\n", - " var canvas_div = (this.canvas_div = document.createElement('div'));\n", - " canvas_div.setAttribute('tabindex', '0');\n", - " canvas_div.setAttribute(\n", - " 'style',\n", - " 'border: 1px solid #ddd;' +\n", - " 'box-sizing: content-box;' +\n", - " 'clear: both;' +\n", - " 'min-height: 1px;' +\n", - " 'min-width: 1px;' +\n", - " 'outline: 0;' +\n", - " 'overflow: hidden;' +\n", - " 'position: relative;' +\n", - " 'resize: both;' +\n", - " 'z-index: 2;'\n", - " );\n", - "\n", - " function on_keyboard_event_closure(name) {\n", - " return function (event) {\n", - " return fig.key_event(event, name);\n", - " };\n", - " }\n", - "\n", - " canvas_div.addEventListener(\n", - " 'keydown',\n", - " on_keyboard_event_closure('key_press')\n", - " );\n", - " canvas_div.addEventListener(\n", - " 'keyup',\n", - " on_keyboard_event_closure('key_release')\n", - " );\n", - "\n", - " this._canvas_extra_style(canvas_div);\n", - " this.root.appendChild(canvas_div);\n", - "\n", - " var canvas = (this.canvas = document.createElement('canvas'));\n", - " canvas.classList.add('mpl-canvas');\n", - " canvas.setAttribute(\n", - " 'style',\n", - " 'box-sizing: content-box;' +\n", - " 'pointer-events: none;' +\n", - " 'position: relative;' +\n", - " 'z-index: 0;'\n", - " );\n", - "\n", - " this.context = canvas.getContext('2d');\n", - "\n", - " var backingStore =\n", - " this.context.backingStorePixelRatio ||\n", - " this.context.webkitBackingStorePixelRatio ||\n", - " this.context.mozBackingStorePixelRatio ||\n", - " this.context.msBackingStorePixelRatio ||\n", - " this.context.oBackingStorePixelRatio ||\n", - " this.context.backingStorePixelRatio ||\n", - " 1;\n", - "\n", - " this.ratio = (window.devicePixelRatio || 1) / backingStore;\n", - "\n", - " var rubberband_canvas = (this.rubberband_canvas = document.createElement(\n", - " 'canvas'\n", - " ));\n", - " rubberband_canvas.setAttribute(\n", - " 'style',\n", - " 'box-sizing: content-box;' +\n", - " 'left: 0;' +\n", - " 'pointer-events: none;' +\n", - " 'position: absolute;' +\n", - " 'top: 0;' +\n", - " 'z-index: 1;'\n", - " );\n", - "\n", - " // Apply a ponyfill if ResizeObserver is not implemented by browser.\n", - " if (this.ResizeObserver === undefined) {\n", - " if (window.ResizeObserver !== undefined) {\n", - " this.ResizeObserver = window.ResizeObserver;\n", - " } else {\n", - " var obs = _JSXTOOLS_RESIZE_OBSERVER({});\n", - " this.ResizeObserver = obs.ResizeObserver;\n", - " }\n", - " }\n", - "\n", - " this.resizeObserverInstance = new this.ResizeObserver(function (entries) {\n", - " // There's no need to resize if the WebSocket is not connected:\n", - " // - If it is still connecting, then we will get an initial resize from\n", - " // Python once it connects.\n", - " // - If it has disconnected, then resizing will clear the canvas and\n", - " // never get anything back to refill it, so better to not resize and\n", - " // keep something visible.\n", - " if (fig.ws.readyState != 1) {\n", - " return;\n", - " }\n", - " var nentries = entries.length;\n", - " for (var i = 0; i < nentries; i++) {\n", - " var entry = entries[i];\n", - " var width, height;\n", - " if (entry.contentBoxSize) {\n", - " if (entry.contentBoxSize instanceof Array) {\n", - " // Chrome 84 implements new version of spec.\n", - " width = entry.contentBoxSize[0].inlineSize;\n", - " height = entry.contentBoxSize[0].blockSize;\n", - " } else {\n", - " // Firefox implements old version of spec.\n", - " width = entry.contentBoxSize.inlineSize;\n", - " height = entry.contentBoxSize.blockSize;\n", - " }\n", - " } else {\n", - " // Chrome <84 implements even older version of spec.\n", - " width = entry.contentRect.width;\n", - " height = entry.contentRect.height;\n", - " }\n", - "\n", - " // Keep the size of the canvas and rubber band canvas in sync with\n", - " // the canvas container.\n", - " if (entry.devicePixelContentBoxSize) {\n", - " // Chrome 84 implements new version of spec.\n", - " canvas.setAttribute(\n", - " 'width',\n", - " entry.devicePixelContentBoxSize[0].inlineSize\n", - " );\n", - " canvas.setAttribute(\n", - " 'height',\n", - " entry.devicePixelContentBoxSize[0].blockSize\n", - " );\n", - " } else {\n", - " canvas.setAttribute('width', width * fig.ratio);\n", - " canvas.setAttribute('height', height * fig.ratio);\n", - " }\n", - " /* This rescales the canvas back to display pixels, so that it\n", - " * appears correct on HiDPI screens. */\n", - " canvas.style.width = width + 'px';\n", - " canvas.style.height = height + 'px';\n", - "\n", - " rubberband_canvas.setAttribute('width', width);\n", - " rubberband_canvas.setAttribute('height', height);\n", - "\n", - " // And update the size in Python. We ignore the initial 0/0 size\n", - " // that occurs as the element is placed into the DOM, which should\n", - " // otherwise not happen due to the minimum size styling.\n", - " if (width != 0 && height != 0) {\n", - " fig.request_resize(width, height);\n", - " }\n", - " }\n", - " });\n", - " this.resizeObserverInstance.observe(canvas_div);\n", - "\n", - " function on_mouse_event_closure(name) {\n", - " /* User Agent sniffing is bad, but WebKit is busted:\n", - " * https://bugs.webkit.org/show_bug.cgi?id=144526\n", - " * https://bugs.webkit.org/show_bug.cgi?id=181818\n", - " * The worst that happens here is that they get an extra browser\n", - " * selection when dragging, if this check fails to catch them.\n", - " */\n", - " var UA = navigator.userAgent;\n", - " var isWebKit = /AppleWebKit/.test(UA) && !/Chrome/.test(UA);\n", - " if(isWebKit) {\n", - " return function (event) {\n", - " /* This prevents the web browser from automatically changing to\n", - " * the text insertion cursor when the button is pressed. We\n", - " * want to control all of the cursor setting manually through\n", - " * the 'cursor' event from matplotlib */\n", - " event.preventDefault()\n", - " return fig.mouse_event(event, name);\n", - " };\n", - " } else {\n", - " return function (event) {\n", - " return fig.mouse_event(event, name);\n", - " };\n", - " }\n", - " }\n", - "\n", - " canvas_div.addEventListener(\n", - " 'mousedown',\n", - " on_mouse_event_closure('button_press')\n", - " );\n", - " canvas_div.addEventListener(\n", - " 'mouseup',\n", - " on_mouse_event_closure('button_release')\n", - " );\n", - " canvas_div.addEventListener(\n", - " 'dblclick',\n", - " on_mouse_event_closure('dblclick')\n", - " );\n", - " // Throttle sequential mouse events to 1 every 20ms.\n", - " canvas_div.addEventListener(\n", - " 'mousemove',\n", - " on_mouse_event_closure('motion_notify')\n", - " );\n", - "\n", - " canvas_div.addEventListener(\n", - " 'mouseenter',\n", - " on_mouse_event_closure('figure_enter')\n", - " );\n", - " canvas_div.addEventListener(\n", - " 'mouseleave',\n", - " on_mouse_event_closure('figure_leave')\n", - " );\n", - "\n", - " canvas_div.addEventListener('wheel', function (event) {\n", - " if (event.deltaY < 0) {\n", - " event.step = 1;\n", - " } else {\n", - " event.step = -1;\n", - " }\n", - " on_mouse_event_closure('scroll')(event);\n", - " });\n", - "\n", - " canvas_div.appendChild(canvas);\n", - " canvas_div.appendChild(rubberband_canvas);\n", - "\n", - " this.rubberband_context = rubberband_canvas.getContext('2d');\n", - " this.rubberband_context.strokeStyle = '#000000';\n", - "\n", - " this._resize_canvas = function (width, height, forward) {\n", - " if (forward) {\n", - " canvas_div.style.width = width + 'px';\n", - " canvas_div.style.height = height + 'px';\n", - " }\n", - " };\n", - "\n", - " // Disable right mouse context menu.\n", - " canvas_div.addEventListener('contextmenu', function (_e) {\n", - " event.preventDefault();\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 toolbar = document.createElement('div');\n", - " toolbar.classList = 'mpl-toolbar';\n", - " this.root.appendChild(toolbar);\n", - "\n", - " function on_click_closure(name) {\n", - " return function (_event) {\n", - " return fig.toolbar_button_onclick(name);\n", - " };\n", - " }\n", - "\n", - " function on_mouseover_closure(tooltip) {\n", - " return function (event) {\n", - " if (!event.currentTarget.disabled) {\n", - " return fig.toolbar_button_onmouseover(tooltip);\n", - " }\n", - " };\n", - " }\n", - "\n", - " fig.buttons = {};\n", - " var buttonGroup = document.createElement('div');\n", - " buttonGroup.classList = 'mpl-button-group';\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", - " /* Instead of a spacer, we start a new button group. */\n", - " if (buttonGroup.hasChildNodes()) {\n", - " toolbar.appendChild(buttonGroup);\n", - " }\n", - " buttonGroup = document.createElement('div');\n", - " buttonGroup.classList = 'mpl-button-group';\n", - " continue;\n", - " }\n", - "\n", - " var button = (fig.buttons[name] = document.createElement('button'));\n", - " button.classList = 'mpl-widget';\n", - " button.setAttribute('role', 'button');\n", - " button.setAttribute('aria-disabled', 'false');\n", - " button.addEventListener('click', on_click_closure(method_name));\n", - " button.addEventListener('mouseover', on_mouseover_closure(tooltip));\n", - "\n", - " var icon_img = document.createElement('img');\n", - " icon_img.src = '_images/' + image + '.png';\n", - " icon_img.srcset = '_images/' + image + '_large.png 2x';\n", - " icon_img.alt = tooltip;\n", - " button.appendChild(icon_img);\n", - "\n", - " buttonGroup.appendChild(button);\n", - " }\n", - "\n", - " if (buttonGroup.hasChildNodes()) {\n", - " toolbar.appendChild(buttonGroup);\n", - " }\n", - "\n", - " var fmt_picker = document.createElement('select');\n", - " fmt_picker.classList = 'mpl-widget';\n", - " toolbar.appendChild(fmt_picker);\n", - " this.format_dropdown = fmt_picker;\n", - "\n", - " for (var ind in mpl.extensions) {\n", - " var fmt = mpl.extensions[ind];\n", - " var option = document.createElement('option');\n", - " option.selected = fmt === mpl.default_extension;\n", - " option.innerHTML = fmt;\n", - " fmt_picker.appendChild(option);\n", - " }\n", - "\n", - " var status_bar = document.createElement('span');\n", - " status_bar.classList = 'mpl-message';\n", - " toolbar.appendChild(status_bar);\n", - " this.message = status_bar;\n", - "};\n", - "\n", - "mpl.figure.prototype.request_resize = function (x_pixels, y_pixels) {\n", - " // Request matplotlib to resize the figure. Matplotlib will then trigger a resize in the client,\n", - " // which will in turn request a refresh of the image.\n", - " this.send_message('resize', { width: x_pixels, height: y_pixels });\n", - "};\n", - "\n", - "mpl.figure.prototype.send_message = function (type, properties) {\n", - " properties['type'] = type;\n", - " properties['figure_id'] = this.id;\n", - " this.ws.send(JSON.stringify(properties));\n", - "};\n", - "\n", - "mpl.figure.prototype.send_draw_message = function () {\n", - " if (!this.waiting) {\n", - " this.waiting = true;\n", - " this.ws.send(JSON.stringify({ type: 'draw', figure_id: this.id }));\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_save = function (fig, _msg) {\n", - " var format_dropdown = fig.format_dropdown;\n", - " var format = format_dropdown.options[format_dropdown.selectedIndex].value;\n", - " fig.ondownload(fig, format);\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_resize = function (fig, msg) {\n", - " var size = msg['size'];\n", - " if (size[0] !== fig.canvas.width || size[1] !== fig.canvas.height) {\n", - " fig._resize_canvas(size[0], size[1], msg['forward']);\n", - " fig.send_message('refresh', {});\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_rubberband = function (fig, msg) {\n", - " var x0 = msg['x0'] / fig.ratio;\n", - " var y0 = (fig.canvas.height - msg['y0']) / fig.ratio;\n", - " var x1 = msg['x1'] / fig.ratio;\n", - " var y1 = (fig.canvas.height - msg['y1']) / fig.ratio;\n", - " x0 = Math.floor(x0) + 0.5;\n", - " y0 = Math.floor(y0) + 0.5;\n", - " x1 = Math.floor(x1) + 0.5;\n", - " y1 = Math.floor(y1) + 0.5;\n", - " var min_x = Math.min(x0, x1);\n", - " var min_y = Math.min(y0, y1);\n", - " var width = Math.abs(x1 - x0);\n", - " var height = Math.abs(y1 - y0);\n", - "\n", - " fig.rubberband_context.clearRect(\n", - " 0,\n", - " 0,\n", - " fig.canvas.width / fig.ratio,\n", - " fig.canvas.height / fig.ratio\n", - " );\n", - "\n", - " fig.rubberband_context.strokeRect(min_x, min_y, width, height);\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_figure_label = function (fig, msg) {\n", - " // Updates the figure title.\n", - " fig.header.textContent = msg['label'];\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_cursor = function (fig, msg) {\n", - " fig.canvas_div.style.cursor = msg['cursor'];\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_message = function (fig, msg) {\n", - " fig.message.textContent = msg['message'];\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_draw = function (fig, _msg) {\n", - " // Request the server to send over a new figure.\n", - " fig.send_draw_message();\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_image_mode = function (fig, msg) {\n", - " fig.image_mode = msg['mode'];\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_history_buttons = function (fig, msg) {\n", - " for (var key in msg) {\n", - " if (!(key in fig.buttons)) {\n", - " continue;\n", - " }\n", - " fig.buttons[key].disabled = !msg[key];\n", - " fig.buttons[key].setAttribute('aria-disabled', !msg[key]);\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_navigate_mode = function (fig, msg) {\n", - " if (msg['mode'] === 'PAN') {\n", - " fig.buttons['Pan'].classList.add('active');\n", - " fig.buttons['Zoom'].classList.remove('active');\n", - " } else if (msg['mode'] === 'ZOOM') {\n", - " fig.buttons['Pan'].classList.remove('active');\n", - " fig.buttons['Zoom'].classList.add('active');\n", - " } else {\n", - " fig.buttons['Pan'].classList.remove('active');\n", - " fig.buttons['Zoom'].classList.remove('active');\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.updated_canvas_event = function () {\n", - " // Called whenever the canvas gets updated.\n", - " this.send_message('ack', {});\n", - "};\n", - "\n", - "// A function to construct a web socket function for onmessage handling.\n", - "// Called in the figure constructor.\n", - "mpl.figure.prototype._make_on_message_function = function (fig) {\n", - " return function socket_on_message(evt) {\n", - " if (evt.data instanceof Blob) {\n", - " var img = evt.data;\n", - " if (img.type !== 'image/png') {\n", - " /* FIXME: We get \"Resource interpreted as Image but\n", - " * transferred with MIME type text/plain:\" errors on\n", - " * Chrome. But how to set the MIME type? It doesn't seem\n", - " * to be part of the websocket stream */\n", - " img.type = 'image/png';\n", - " }\n", - "\n", - " /* Free the memory for the previous frames */\n", - " if (fig.imageObj.src) {\n", - " (window.URL || window.webkitURL).revokeObjectURL(\n", - " fig.imageObj.src\n", - " );\n", - " }\n", - "\n", - " fig.imageObj.src = (window.URL || window.webkitURL).createObjectURL(\n", - " img\n", - " );\n", - " fig.updated_canvas_event();\n", - " fig.waiting = false;\n", - " return;\n", - " } else if (\n", - " typeof evt.data === 'string' &&\n", - " evt.data.slice(0, 21) === 'data:image/png;base64'\n", - " ) {\n", - " fig.imageObj.src = evt.data;\n", - " fig.updated_canvas_event();\n", - " fig.waiting = false;\n", - " return;\n", - " }\n", - "\n", - " var msg = JSON.parse(evt.data);\n", - " var msg_type = msg['type'];\n", - "\n", - " // Call the \"handle_{type}\" callback, which takes\n", - " // the figure and JSON message as its only arguments.\n", - " try {\n", - " var callback = fig['handle_' + msg_type];\n", - " } catch (e) {\n", - " console.log(\n", - " \"No handler for the '\" + msg_type + \"' message type: \",\n", - " msg\n", - " );\n", - " return;\n", - " }\n", - "\n", - " if (callback) {\n", - " try {\n", - " // console.log(\"Handling '\" + msg_type + \"' message: \", msg);\n", - " callback(fig, msg);\n", - " } catch (e) {\n", - " console.log(\n", - " \"Exception inside the 'handler_\" + msg_type + \"' callback:\",\n", - " e,\n", - " e.stack,\n", - " msg\n", - " );\n", - " }\n", - " }\n", - " };\n", - "};\n", - "\n", - "function getModifiers(event) {\n", - " var mods = [];\n", - " if (event.ctrlKey) {\n", - " mods.push('ctrl');\n", - " }\n", - " if (event.altKey) {\n", - " mods.push('alt');\n", - " }\n", - " if (event.shiftKey) {\n", - " mods.push('shift');\n", - " }\n", - " if (event.metaKey) {\n", - " mods.push('meta');\n", - " }\n", - " return mods;\n", - "}\n", - "\n", - "/*\n", - " * return a copy of an object with only non-object keys\n", - " * we need this to avoid circular references\n", - " * https://stackoverflow.com/a/24161582/3208463\n", - " */\n", - "function simpleKeys(original) {\n", - " return Object.keys(original).reduce(function (obj, key) {\n", - " if (typeof original[key] !== 'object') {\n", - " obj[key] = original[key];\n", - " }\n", - " return obj;\n", - " }, {});\n", - "}\n", - "\n", - "mpl.figure.prototype.mouse_event = function (event, name) {\n", - " if (name === 'button_press') {\n", - " this.canvas.focus();\n", - " this.canvas_div.focus();\n", - " }\n", - "\n", - " // from https://stackoverflow.com/q/1114465\n", - " var boundingRect = this.canvas.getBoundingClientRect();\n", - " var x = (event.clientX - boundingRect.left) * this.ratio;\n", - " var y = (event.clientY - boundingRect.top) * this.ratio;\n", - "\n", - " this.send_message(name, {\n", - " x: x,\n", - " y: y,\n", - " button: event.button,\n", - " step: event.step,\n", - " modifiers: getModifiers(event),\n", - " guiEvent: simpleKeys(event),\n", - " });\n", - "\n", - " return false;\n", - "};\n", - "\n", - "mpl.figure.prototype._key_event_extra = function (_event, _name) {\n", - " // Handle any extra behaviour associated with a key event\n", - "};\n", - "\n", - "mpl.figure.prototype.key_event = function (event, name) {\n", - " // Prevent repeat events\n", - " if (name === 'key_press') {\n", - " if (event.key === this._key) {\n", - " return;\n", - " } else {\n", - " this._key = event.key;\n", - " }\n", - " }\n", - " if (name === 'key_release') {\n", - " this._key = null;\n", - " }\n", - "\n", - " var value = '';\n", - " if (event.ctrlKey && event.key !== 'Control') {\n", - " value += 'ctrl+';\n", - " }\n", - " else if (event.altKey && event.key !== 'Alt') {\n", - " value += 'alt+';\n", - " }\n", - " else if (event.shiftKey && event.key !== 'Shift') {\n", - " value += 'shift+';\n", - " }\n", - "\n", - " value += 'k' + event.key;\n", - "\n", - " this._key_event_extra(event, name);\n", - "\n", - " this.send_message(name, { key: value, guiEvent: simpleKeys(event) });\n", - " return false;\n", - "};\n", - "\n", - "mpl.figure.prototype.toolbar_button_onclick = function (name) {\n", - " if (name === 'download') {\n", - " this.handle_save(this, null);\n", - " } else {\n", - " this.send_message('toolbar_button', { name: name });\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.toolbar_button_onmouseover = function (tooltip) {\n", - " this.message.textContent = tooltip;\n", - "};\n", - "\n", - "///////////////// REMAINING CONTENT GENERATED BY embed_js.py /////////////////\n", - "// prettier-ignore\n", - "var _JSXTOOLS_RESIZE_OBSERVER=function(A){var t,i=new WeakMap,n=new WeakMap,a=new WeakMap,r=new WeakMap,o=new Set;function s(e){if(!(this instanceof s))throw new TypeError(\"Constructor requires 'new' operator\");i.set(this,e)}function h(){throw new TypeError(\"Function is not a constructor\")}function c(e,t,i,n){e=0 in arguments?Number(arguments[0]):0,t=1 in arguments?Number(arguments[1]):0,i=2 in arguments?Number(arguments[2]):0,n=3 in arguments?Number(arguments[3]):0,this.right=(this.x=this.left=e)+(this.width=i),this.bottom=(this.y=this.top=t)+(this.height=n),Object.freeze(this)}function d(){t=requestAnimationFrame(d);var s=new WeakMap,p=new Set;o.forEach((function(t){r.get(t).forEach((function(i){var r=t instanceof window.SVGElement,o=a.get(t),d=r?0:parseFloat(o.paddingTop),f=r?0:parseFloat(o.paddingRight),l=r?0:parseFloat(o.paddingBottom),u=r?0:parseFloat(o.paddingLeft),g=r?0:parseFloat(o.borderTopWidth),m=r?0:parseFloat(o.borderRightWidth),w=r?0:parseFloat(o.borderBottomWidth),b=u+f,F=d+l,v=(r?0:parseFloat(o.borderLeftWidth))+m,W=g+w,y=r?0:t.offsetHeight-W-t.clientHeight,E=r?0:t.offsetWidth-v-t.clientWidth,R=b+v,z=F+W,M=r?t.width:parseFloat(o.width)-R-E,O=r?t.height:parseFloat(o.height)-z-y;if(n.has(t)){var k=n.get(t);if(k[0]===M&&k[1]===O)return}n.set(t,[M,O]);var S=Object.create(h.prototype);S.target=t,S.contentRect=new c(u,d,M,O),s.has(i)||(s.set(i,[]),p.add(i)),s.get(i).push(S)}))})),p.forEach((function(e){i.get(e).call(e,s.get(e),e)}))}return s.prototype.observe=function(i){if(i instanceof window.Element){r.has(i)||(r.set(i,new Set),o.add(i),a.set(i,window.getComputedStyle(i)));var n=r.get(i);n.has(this)||n.add(this),cancelAnimationFrame(t),t=requestAnimationFrame(d)}},s.prototype.unobserve=function(i){if(i instanceof window.Element&&r.has(i)){var n=r.get(i);n.has(this)&&(n.delete(this),n.size||(r.delete(i),o.delete(i))),n.size||r.delete(i),o.size||cancelAnimationFrame(t)}},A.DOMRectReadOnly=c,A.ResizeObserver=s,A.ResizeObserverEntry=h,A}; // eslint-disable-line\n", - "mpl.toolbar_items = [[\"Home\", \"Reset original view\", \"fa fa-home\", \"home\"], [\"Back\", \"Back to previous view\", \"fa fa-arrow-left\", \"back\"], [\"Forward\", \"Forward to next view\", \"fa fa-arrow-right\", \"forward\"], [\"\", \"\", \"\", \"\"], [\"Pan\", \"Left button pans, Right button zooms\\nx/y fixes axis, CTRL fixes aspect\", \"fa fa-arrows\", \"pan\"], [\"Zoom\", \"Zoom to rectangle\\nx/y fixes axis\", \"fa fa-square-o\", \"zoom\"], [\"\", \"\", \"\", \"\"], [\"Download\", \"Download plot\", \"fa fa-floppy-o\", \"download\"]];\n", - "\n", - "mpl.extensions = [\"eps\", \"jpeg\", \"pgf\", \"pdf\", \"png\", \"ps\", \"raw\", \"svg\", \"tif\", \"webp\"];\n", - "\n", - "mpl.default_extension = \"png\";/* global mpl */\n", - "\n", - "var comm_websocket_adapter = function (comm) {\n", - " // Create a \"websocket\"-like object which calls the given IPython comm\n", - " // object with the appropriate methods. Currently this is a non binary\n", - " // socket, so there is still some room for performance tuning.\n", - " var ws = {};\n", - "\n", - " ws.binaryType = comm.kernel.ws.binaryType;\n", - " ws.readyState = comm.kernel.ws.readyState;\n", - " function updateReadyState(_event) {\n", - " if (comm.kernel.ws) {\n", - " ws.readyState = comm.kernel.ws.readyState;\n", - " } else {\n", - " ws.readyState = 3; // Closed state.\n", - " }\n", - " }\n", - " comm.kernel.ws.addEventListener('open', updateReadyState);\n", - " comm.kernel.ws.addEventListener('close', updateReadyState);\n", - " comm.kernel.ws.addEventListener('error', updateReadyState);\n", - "\n", - " ws.close = function () {\n", - " comm.close();\n", - " };\n", - " ws.send = function (m) {\n", - " //console.log('sending', m);\n", - " comm.send(m);\n", - " };\n", - " // Register the callback with on_msg.\n", - " comm.on_msg(function (msg) {\n", - " //console.log('receiving', msg['content']['data'], msg);\n", - " var data = msg['content']['data'];\n", - " if (data['blob'] !== undefined) {\n", - " data = {\n", - " data: new Blob(msg['buffers'], { type: data['blob'] }),\n", - " };\n", - " }\n", - " // Pass the mpl event to the overridden (by mpl) onmessage function.\n", - " ws.onmessage(data);\n", - " });\n", - " return ws;\n", - "};\n", - "\n", - "mpl.mpl_figure_comm = function (comm, msg) {\n", - " // This is the function which gets called when the mpl process\n", - " // starts-up an IPython Comm through the \"matplotlib\" channel.\n", - "\n", - " var id = msg.content.data.id;\n", - " // Get hold of the div created by the display call when the Comm\n", - " // socket was opened in Python.\n", - " var element = document.getElementById(id);\n", - " var ws_proxy = comm_websocket_adapter(comm);\n", - "\n", - " function ondownload(figure, _format) {\n", - " window.open(figure.canvas.toDataURL());\n", - " }\n", - "\n", - " var fig = new mpl.figure(id, ws_proxy, ondownload, element);\n", - "\n", - " // Call onopen now - mpl needs it, as it is assuming we've passed it a real\n", - " // web socket which is closed, not our websocket->open comm proxy.\n", - " ws_proxy.onopen();\n", - "\n", - " fig.parent_element = element;\n", - " fig.cell_info = mpl.find_output_cell(\"
\");\n", - " if (!fig.cell_info) {\n", - " console.error('Failed to find cell for figure', id, fig);\n", - " return;\n", - " }\n", - " fig.cell_info[0].output_area.element.on(\n", - " 'cleared',\n", - " { fig: fig },\n", - " fig._remove_fig_handler\n", - " );\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_close = function (fig, msg) {\n", - " var width = fig.canvas.width / fig.ratio;\n", - " fig.cell_info[0].output_area.element.off(\n", - " 'cleared',\n", - " fig._remove_fig_handler\n", - " );\n", - " fig.resizeObserverInstance.unobserve(fig.canvas_div);\n", - "\n", - " // Update the output cell to use the data from the current canvas.\n", - " fig.push_to_output();\n", - " var dataURL = fig.canvas.toDataURL();\n", - " // Re-enable the keyboard manager in IPython - without this line, in FF,\n", - " // the notebook keyboard shortcuts fail.\n", - " IPython.keyboard_manager.enable();\n", - " fig.parent_element.innerHTML =\n", - " '';\n", - " fig.close_ws(fig, msg);\n", - "};\n", - "\n", - "mpl.figure.prototype.close_ws = function (fig, msg) {\n", - " fig.send_message('closing', msg);\n", - " // fig.ws.close()\n", - "};\n", - "\n", - "mpl.figure.prototype.push_to_output = function (_remove_interactive) {\n", - " // Turn the data on the canvas into data in the output cell.\n", - " var width = this.canvas.width / this.ratio;\n", - " var dataURL = this.canvas.toDataURL();\n", - " this.cell_info[1]['text/html'] =\n", - " '';\n", - "};\n", - "\n", - "mpl.figure.prototype.updated_canvas_event = function () {\n", - " // Tell IPython that the notebook contents must change.\n", - " IPython.notebook.set_dirty(true);\n", - " this.send_message('ack', {});\n", - " var fig = this;\n", - " // Wait a second, then push the new image to the DOM so\n", - " // that it is saved nicely (might be nice to debounce this).\n", - " setTimeout(function () {\n", - " fig.push_to_output();\n", - " }, 1000);\n", - "};\n", - "\n", - "mpl.figure.prototype._init_toolbar = function () {\n", - " var fig = this;\n", - "\n", - " var toolbar = document.createElement('div');\n", - " toolbar.classList = 'btn-toolbar';\n", - " this.root.appendChild(toolbar);\n", - "\n", - " function on_click_closure(name) {\n", - " return function (_event) {\n", - " return fig.toolbar_button_onclick(name);\n", - " };\n", - " }\n", - "\n", - " function on_mouseover_closure(tooltip) {\n", - " return function (event) {\n", - " if (!event.currentTarget.disabled) {\n", - " return fig.toolbar_button_onmouseover(tooltip);\n", - " }\n", - " };\n", - " }\n", - "\n", - " fig.buttons = {};\n", - " var buttonGroup = document.createElement('div');\n", - " buttonGroup.classList = 'btn-group';\n", - " var button;\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", - " /* Instead of a spacer, we start a new button group. */\n", - " if (buttonGroup.hasChildNodes()) {\n", - " toolbar.appendChild(buttonGroup);\n", - " }\n", - " buttonGroup = document.createElement('div');\n", - " buttonGroup.classList = 'btn-group';\n", - " continue;\n", - " }\n", - "\n", - " button = fig.buttons[name] = document.createElement('button');\n", - " button.classList = 'btn btn-default';\n", - " button.href = '#';\n", - " button.title = name;\n", - " button.innerHTML = '';\n", - " button.addEventListener('click', on_click_closure(method_name));\n", - " button.addEventListener('mouseover', on_mouseover_closure(tooltip));\n", - " buttonGroup.appendChild(button);\n", - " }\n", - "\n", - " if (buttonGroup.hasChildNodes()) {\n", - " toolbar.appendChild(buttonGroup);\n", - " }\n", - "\n", - " // Add the status bar.\n", - " var status_bar = document.createElement('span');\n", - " status_bar.classList = 'mpl-message pull-right';\n", - " toolbar.appendChild(status_bar);\n", - " this.message = status_bar;\n", - "\n", - " // Add the close button to the window.\n", - " var buttongrp = document.createElement('div');\n", - " buttongrp.classList = 'btn-group inline pull-right';\n", - " button = document.createElement('button');\n", - " button.classList = 'btn btn-mini btn-primary';\n", - " button.href = '#';\n", - " button.title = 'Stop Interaction';\n", - " button.innerHTML = '';\n", - " button.addEventListener('click', function (_evt) {\n", - " fig.handle_close(fig, {});\n", - " });\n", - " button.addEventListener(\n", - " 'mouseover',\n", - " on_mouseover_closure('Stop Interaction')\n", - " );\n", - " buttongrp.appendChild(button);\n", - " var titlebar = this.root.querySelector('.ui-dialog-titlebar');\n", - " titlebar.insertBefore(buttongrp, titlebar.firstChild);\n", - "};\n", - "\n", - "mpl.figure.prototype._remove_fig_handler = function (event) {\n", - " var fig = event.data.fig;\n", - " if (event.target !== this) {\n", - " // Ignore bubbled events from children.\n", - " return;\n", - " }\n", - " fig.close_ws(fig, {});\n", - "};\n", - "\n", - "mpl.figure.prototype._root_extra_style = function (el) {\n", - " el.style.boxSizing = 'content-box'; // override notebook setting of border-box.\n", - "};\n", - "\n", - "mpl.figure.prototype._canvas_extra_style = function (el) {\n", - " // this is important to make the div 'focusable\n", - " el.setAttribute('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", - " } else {\n", - " // location in version 2\n", - " IPython.keyboard_manager.register_events(el);\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype._key_event_extra = function (event, _name) {\n", - " // Check for shift+enter\n", - " if (event.shiftKey && event.which === 13) {\n", - " this.canvas_div.blur();\n", - " // select the cell after this one\n", - " var index = IPython.notebook.find_cell_index(this.cell_info[0]);\n", - " IPython.notebook.select(index + 1);\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_save = function (fig, _msg) {\n", - " fig.ondownload(fig, null);\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 < ncells; i++) {\n", - " var cell = cells[i];\n", - " if (cell.cell_type === 'code') {\n", - " for (var j = 0; j < cell.output_area.outputs.length; j++) {\n", - " var data = cell.output_area.outputs[j];\n", - " if (data.data) {\n", - " // IPython >= 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(\n", - " 'matplotlib',\n", - " mpl.mpl_figure_comm\n", - " );\n", - "}\n" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/html": [ - "
" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "time_format: HJD_UTC\n", - "time_stamp: mid\n", - "exp_time: 134.354034\n", - "flux_format: flux\n", - "filter_name: hst_wfc3_ir_g141\n", - "wlrange: [10880.0, 16800.0]\n" - ] - } - ], - "source": [ - "###############################################################################################\n", - "##### Load data\n", - "###############################################################################################\n", - "\n", - "# This dataset contains one transit observation of WASP-39b, obtained by HST/WFC3/IR/G141, \n", - "# as part of the 14260 GO program, and analysed with Iraclis:\n", - "# https://iopscience.iop.org/article/10.3847/1538-3881/aaaf75\n", - "# It is the white light curve of the first order spectrum, \n", - "# i.e. the sum of all the flux from 10880 to 16800 Angstrom.\n", - "\n", - "data = plc.open_dict('wasp39b_hst.pickle')\n", - "\n", - "###############################################################################################\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "###############################################################################################\n", - "##### Inspect data\n", - "###############################################################################################\n", - "\n", - "# The dictionaly contains the necessary keywords:\n", - "# 'time'\n", - "# 'time_format'\n", - "# 'time_stamp'\n", - "# 'exp_time'\n", - "# 'flux'\n", - "# 'flux_unc'\n", - "# 'flux_format'\n", - "# 'filter_name'\n", - "\n", - "# In addition, the dictionaly contains as auxiliary data the HST orbital phase:\n", - "# 'ophase'\n", - "\n", - "plt.figure()\n", - "plt.ylabel('flux')\n", - "plt.xlabel('time')\n", - "plt.errorbar(data['time'], data['flux'], data['flux_unc'], fmt='o')\n", - "\n", - "if 'auxiliary_data' in data and data['auxiliary_data']:\n", - " print('Auxiliary data available:')\n", - " for i in data['auxiliary_data']:\n", - " plt.figure()\n", - " plt.ylabel(i)\n", - " plt.xlabel('time')\n", - " plt.plot(data['time'], data['auxiliary_data'][i])\n", - "\n", - "for i in ['time_format', 'time_stamp', 'exp_time', 'flux_format', 'filter_name', 'wlrange']:\n", - " print('{0}: {1}'.format(i, data[i]))\n", - " \n", - "###############################################################################################\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "###############################################################################################\n", - "##### Define the trend function\n", - "###############################################################################################\n", - "\n", - "# By default, the detrending is done using a second order polynomial with time.\n", - "# For HST, this trend function is not sufficient and we have to define our custon trend function.\n", - "# The trendt function should take as a first argument a dictionary. This dictionary contains all\n", - "# the input series: time, airmass (if observatory location is defined) and all \n", - "# the auxiliary time series (here the ophase).\n", - "# We need to experiment with the formula until you get a reasonalbe fit.\n", - "# Here we will use a well-established trend function for HST,\n", - "# a linear with time in the observation (time - start of the observation) \n", - "# and an exponential with orbital phase of HST (ophase in the auxiliary data).\n", - "# We will also define the exponential decay parameter in log-space, for a better sampling of the parameters space.\n", - "\n", - "def trend_function_hst(dictionary, c1, c2, c3):\n", - " return (1.0 \n", - " - c1 * (dictionary['time'] - min(dictionary['time']))\n", - " - c2 * np.exp(- (10**c3) * dictionary['ophase'])\n", - " )\n", - "\n", - "data['trend_function'] = trend_function_hst\n", - "\n", - "\n", - "\n", - "# We also need to define the prioprios for the trend function parameters. The number of rows \n", - "# should be equal to the number of parameters. We will need to expriment with the values until \n", - "# we get a reasonalbe fit.\n", - "# For example: \n", - "# trend_parameters = [\n", - "# [initial guess for c1, min value for c1, max value for c1, c1 name, c1 name for figures],\n", - "# [initial guess for c2, min value for c2, max value for c2, c2 name, c2 name for figures],\n", - "# [initial guess for c3, min value for c3, max value for c3, c3 name, c3 name for figures],\n", - "# ...\n", - "# ]\n", - "\n", - "trend_parameters_hst = [\n", - " [0.01, -1, 1, 'ls', '$l_s$'],\n", - " [0.01, -1, 1, 'sa', '$s_a$'],\n", - " [2, 0, 5, 'sd', '$s_d$'],\n", - "]\n", - "\n", - "data['trend_parameters'] = trend_parameters_hst\n", - "\n", - "###############################################################################################\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "###############################################################################################\n", - "##### Define the stellar model\n", - "###############################################################################################\n", - "\n", - "# The default stellar model used to calculate the limb-darkening coefficients \n", - "# is the 'Pheonix_2018'. Here, we will not change this.\n", - "\n", - "###############################################################################################\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "###############################################################################################\n", - "##### Add observation to the Planet object\n", - "###############################################################################################\n", - "\n", - "# Then we are going to add the observation to the Planet object.\n", - "# It is advised to use planet.clear_observations() before, \n", - "# to avoid duplications, in case we forget that we have already added the same observation.\n", - "\n", - "planet.clear_observations()\n", - "planet.add_observation_from_dict(data)\n", - "\n", - "###############################################################################################\n" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "id": "72560cbb", - "metadata": { - "scrolled": false - }, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "WARNING:root:\n", - "PHOENIX models are only computed for solar metallicity stars. Setting stellar_metallicity = 0.\n", - "\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "File already here... teff05400_logg4.00_MH0.0.pickle\n", - "File already here... teff05400_logg4.50_MH0.0.pickle\n", - "\n", - "Observation: obs0\n", - "Filter: hst_wfc3_ir_g141:10880.0-16800.0\n", - "Epoch: 183\n", - "Data-points excluded: 0\n", - "Scaling uncertainties by: 1\n", - "\n", - "Optimising initial parameters...\n", - "Transit fitting...\n" - ] - }, - { - "data": { - "application/javascript": [ - "/* Put everything inside the global mpl namespace */\n", - "/* global mpl */\n", - "window.mpl = {};\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(\n", - " '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", - "\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 = document.createElement('div');\n", - " this.root.setAttribute('style', 'display: inline-block');\n", - " this._root_extra_style(this.root);\n", - "\n", - " parent_element.appendChild(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 (fig.ratio !== 1) {\n", - " fig.send_message('set_device_pixel_ratio', {\n", - " device_pixel_ratio: fig.ratio,\n", - " });\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 = document.createElement('div');\n", - " titlebar.classList =\n", - " 'ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix';\n", - " var titletext = document.createElement('div');\n", - " titletext.classList = 'ui-dialog-title';\n", - " titletext.setAttribute(\n", - " 'style',\n", - " 'width: 100%; text-align: center; padding: 3px;'\n", - " );\n", - " titlebar.appendChild(titletext);\n", - " this.root.appendChild(titlebar);\n", - " this.header = titletext;\n", - "};\n", - "\n", - "mpl.figure.prototype._canvas_extra_style = function (_canvas_div) {};\n", - "\n", - "mpl.figure.prototype._root_extra_style = function (_canvas_div) {};\n", - "\n", - "mpl.figure.prototype._init_canvas = function () {\n", - " var fig = this;\n", - "\n", - " var canvas_div = (this.canvas_div = document.createElement('div'));\n", - " canvas_div.setAttribute('tabindex', '0');\n", - " canvas_div.setAttribute(\n", - " 'style',\n", - " 'border: 1px solid #ddd;' +\n", - " 'box-sizing: content-box;' +\n", - " 'clear: both;' +\n", - " 'min-height: 1px;' +\n", - " 'min-width: 1px;' +\n", - " 'outline: 0;' +\n", - " 'overflow: hidden;' +\n", - " 'position: relative;' +\n", - " 'resize: both;' +\n", - " 'z-index: 2;'\n", - " );\n", - "\n", - " function on_keyboard_event_closure(name) {\n", - " return function (event) {\n", - " return fig.key_event(event, name);\n", - " };\n", - " }\n", - "\n", - " canvas_div.addEventListener(\n", - " 'keydown',\n", - " on_keyboard_event_closure('key_press')\n", - " );\n", - " canvas_div.addEventListener(\n", - " 'keyup',\n", - " on_keyboard_event_closure('key_release')\n", - " );\n", - "\n", - " this._canvas_extra_style(canvas_div);\n", - " this.root.appendChild(canvas_div);\n", - "\n", - " var canvas = (this.canvas = document.createElement('canvas'));\n", - " canvas.classList.add('mpl-canvas');\n", - " canvas.setAttribute(\n", - " 'style',\n", - " 'box-sizing: content-box;' +\n", - " 'pointer-events: none;' +\n", - " 'position: relative;' +\n", - " 'z-index: 0;'\n", - " );\n", - "\n", - " this.context = canvas.getContext('2d');\n", - "\n", - " var backingStore =\n", - " this.context.backingStorePixelRatio ||\n", - " this.context.webkitBackingStorePixelRatio ||\n", - " this.context.mozBackingStorePixelRatio ||\n", - " this.context.msBackingStorePixelRatio ||\n", - " this.context.oBackingStorePixelRatio ||\n", - " this.context.backingStorePixelRatio ||\n", - " 1;\n", - "\n", - " this.ratio = (window.devicePixelRatio || 1) / backingStore;\n", - "\n", - " var rubberband_canvas = (this.rubberband_canvas = document.createElement(\n", - " 'canvas'\n", - " ));\n", - " rubberband_canvas.setAttribute(\n", - " 'style',\n", - " 'box-sizing: content-box;' +\n", - " 'left: 0;' +\n", - " 'pointer-events: none;' +\n", - " 'position: absolute;' +\n", - " 'top: 0;' +\n", - " 'z-index: 1;'\n", - " );\n", - "\n", - " // Apply a ponyfill if ResizeObserver is not implemented by browser.\n", - " if (this.ResizeObserver === undefined) {\n", - " if (window.ResizeObserver !== undefined) {\n", - " this.ResizeObserver = window.ResizeObserver;\n", - " } else {\n", - " var obs = _JSXTOOLS_RESIZE_OBSERVER({});\n", - " this.ResizeObserver = obs.ResizeObserver;\n", - " }\n", - " }\n", - "\n", - " this.resizeObserverInstance = new this.ResizeObserver(function (entries) {\n", - " // There's no need to resize if the WebSocket is not connected:\n", - " // - If it is still connecting, then we will get an initial resize from\n", - " // Python once it connects.\n", - " // - If it has disconnected, then resizing will clear the canvas and\n", - " // never get anything back to refill it, so better to not resize and\n", - " // keep something visible.\n", - " if (fig.ws.readyState != 1) {\n", - " return;\n", - " }\n", - " var nentries = entries.length;\n", - " for (var i = 0; i < nentries; i++) {\n", - " var entry = entries[i];\n", - " var width, height;\n", - " if (entry.contentBoxSize) {\n", - " if (entry.contentBoxSize instanceof Array) {\n", - " // Chrome 84 implements new version of spec.\n", - " width = entry.contentBoxSize[0].inlineSize;\n", - " height = entry.contentBoxSize[0].blockSize;\n", - " } else {\n", - " // Firefox implements old version of spec.\n", - " width = entry.contentBoxSize.inlineSize;\n", - " height = entry.contentBoxSize.blockSize;\n", - " }\n", - " } else {\n", - " // Chrome <84 implements even older version of spec.\n", - " width = entry.contentRect.width;\n", - " height = entry.contentRect.height;\n", - " }\n", - "\n", - " // Keep the size of the canvas and rubber band canvas in sync with\n", - " // the canvas container.\n", - " if (entry.devicePixelContentBoxSize) {\n", - " // Chrome 84 implements new version of spec.\n", - " canvas.setAttribute(\n", - " 'width',\n", - " entry.devicePixelContentBoxSize[0].inlineSize\n", - " );\n", - " canvas.setAttribute(\n", - " 'height',\n", - " entry.devicePixelContentBoxSize[0].blockSize\n", - " );\n", - " } else {\n", - " canvas.setAttribute('width', width * fig.ratio);\n", - " canvas.setAttribute('height', height * fig.ratio);\n", - " }\n", - " /* This rescales the canvas back to display pixels, so that it\n", - " * appears correct on HiDPI screens. */\n", - " canvas.style.width = width + 'px';\n", - " canvas.style.height = height + 'px';\n", - "\n", - " rubberband_canvas.setAttribute('width', width);\n", - " rubberband_canvas.setAttribute('height', height);\n", - "\n", - " // And update the size in Python. We ignore the initial 0/0 size\n", - " // that occurs as the element is placed into the DOM, which should\n", - " // otherwise not happen due to the minimum size styling.\n", - " if (width != 0 && height != 0) {\n", - " fig.request_resize(width, height);\n", - " }\n", - " }\n", - " });\n", - " this.resizeObserverInstance.observe(canvas_div);\n", - "\n", - " function on_mouse_event_closure(name) {\n", - " /* User Agent sniffing is bad, but WebKit is busted:\n", - " * https://bugs.webkit.org/show_bug.cgi?id=144526\n", - " * https://bugs.webkit.org/show_bug.cgi?id=181818\n", - " * The worst that happens here is that they get an extra browser\n", - " * selection when dragging, if this check fails to catch them.\n", - " */\n", - " var UA = navigator.userAgent;\n", - " var isWebKit = /AppleWebKit/.test(UA) && !/Chrome/.test(UA);\n", - " if(isWebKit) {\n", - " return function (event) {\n", - " /* This prevents the web browser from automatically changing to\n", - " * the text insertion cursor when the button is pressed. We\n", - " * want to control all of the cursor setting manually through\n", - " * the 'cursor' event from matplotlib */\n", - " event.preventDefault()\n", - " return fig.mouse_event(event, name);\n", - " };\n", - " } else {\n", - " return function (event) {\n", - " return fig.mouse_event(event, name);\n", - " };\n", - " }\n", - " }\n", - "\n", - " canvas_div.addEventListener(\n", - " 'mousedown',\n", - " on_mouse_event_closure('button_press')\n", - " );\n", - " canvas_div.addEventListener(\n", - " 'mouseup',\n", - " on_mouse_event_closure('button_release')\n", - " );\n", - " canvas_div.addEventListener(\n", - " 'dblclick',\n", - " on_mouse_event_closure('dblclick')\n", - " );\n", - " // Throttle sequential mouse events to 1 every 20ms.\n", - " canvas_div.addEventListener(\n", - " 'mousemove',\n", - " on_mouse_event_closure('motion_notify')\n", - " );\n", - "\n", - " canvas_div.addEventListener(\n", - " 'mouseenter',\n", - " on_mouse_event_closure('figure_enter')\n", - " );\n", - " canvas_div.addEventListener(\n", - " 'mouseleave',\n", - " on_mouse_event_closure('figure_leave')\n", - " );\n", - "\n", - " canvas_div.addEventListener('wheel', function (event) {\n", - " if (event.deltaY < 0) {\n", - " event.step = 1;\n", - " } else {\n", - " event.step = -1;\n", - " }\n", - " on_mouse_event_closure('scroll')(event);\n", - " });\n", - "\n", - " canvas_div.appendChild(canvas);\n", - " canvas_div.appendChild(rubberband_canvas);\n", - "\n", - " this.rubberband_context = rubberband_canvas.getContext('2d');\n", - " this.rubberband_context.strokeStyle = '#000000';\n", - "\n", - " this._resize_canvas = function (width, height, forward) {\n", - " if (forward) {\n", - " canvas_div.style.width = width + 'px';\n", - " canvas_div.style.height = height + 'px';\n", - " }\n", - " };\n", - "\n", - " // Disable right mouse context menu.\n", - " canvas_div.addEventListener('contextmenu', function (_e) {\n", - " event.preventDefault();\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 toolbar = document.createElement('div');\n", - " toolbar.classList = 'mpl-toolbar';\n", - " this.root.appendChild(toolbar);\n", - "\n", - " function on_click_closure(name) {\n", - " return function (_event) {\n", - " return fig.toolbar_button_onclick(name);\n", - " };\n", - " }\n", - "\n", - " function on_mouseover_closure(tooltip) {\n", - " return function (event) {\n", - " if (!event.currentTarget.disabled) {\n", - " return fig.toolbar_button_onmouseover(tooltip);\n", - " }\n", - " };\n", - " }\n", - "\n", - " fig.buttons = {};\n", - " var buttonGroup = document.createElement('div');\n", - " buttonGroup.classList = 'mpl-button-group';\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", - " /* Instead of a spacer, we start a new button group. */\n", - " if (buttonGroup.hasChildNodes()) {\n", - " toolbar.appendChild(buttonGroup);\n", - " }\n", - " buttonGroup = document.createElement('div');\n", - " buttonGroup.classList = 'mpl-button-group';\n", - " continue;\n", - " }\n", - "\n", - " var button = (fig.buttons[name] = document.createElement('button'));\n", - " button.classList = 'mpl-widget';\n", - " button.setAttribute('role', 'button');\n", - " button.setAttribute('aria-disabled', 'false');\n", - " button.addEventListener('click', on_click_closure(method_name));\n", - " button.addEventListener('mouseover', on_mouseover_closure(tooltip));\n", - "\n", - " var icon_img = document.createElement('img');\n", - " icon_img.src = '_images/' + image + '.png';\n", - " icon_img.srcset = '_images/' + image + '_large.png 2x';\n", - " icon_img.alt = tooltip;\n", - " button.appendChild(icon_img);\n", - "\n", - " buttonGroup.appendChild(button);\n", - " }\n", - "\n", - " if (buttonGroup.hasChildNodes()) {\n", - " toolbar.appendChild(buttonGroup);\n", - " }\n", - "\n", - " var fmt_picker = document.createElement('select');\n", - " fmt_picker.classList = 'mpl-widget';\n", - " toolbar.appendChild(fmt_picker);\n", - " this.format_dropdown = fmt_picker;\n", - "\n", - " for (var ind in mpl.extensions) {\n", - " var fmt = mpl.extensions[ind];\n", - " var option = document.createElement('option');\n", - " option.selected = fmt === mpl.default_extension;\n", - " option.innerHTML = fmt;\n", - " fmt_picker.appendChild(option);\n", - " }\n", - "\n", - " var status_bar = document.createElement('span');\n", - " status_bar.classList = 'mpl-message';\n", - " toolbar.appendChild(status_bar);\n", - " this.message = status_bar;\n", - "};\n", - "\n", - "mpl.figure.prototype.request_resize = function (x_pixels, y_pixels) {\n", - " // Request matplotlib to resize the figure. Matplotlib will then trigger a resize in the client,\n", - " // which will in turn request a refresh of the image.\n", - " this.send_message('resize', { width: x_pixels, height: y_pixels });\n", - "};\n", - "\n", - "mpl.figure.prototype.send_message = function (type, properties) {\n", - " properties['type'] = type;\n", - " properties['figure_id'] = this.id;\n", - " this.ws.send(JSON.stringify(properties));\n", - "};\n", - "\n", - "mpl.figure.prototype.send_draw_message = function () {\n", - " if (!this.waiting) {\n", - " this.waiting = true;\n", - " this.ws.send(JSON.stringify({ type: 'draw', figure_id: this.id }));\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_save = function (fig, _msg) {\n", - " var format_dropdown = fig.format_dropdown;\n", - " var format = format_dropdown.options[format_dropdown.selectedIndex].value;\n", - " fig.ondownload(fig, format);\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_resize = function (fig, msg) {\n", - " var size = msg['size'];\n", - " if (size[0] !== fig.canvas.width || size[1] !== fig.canvas.height) {\n", - " fig._resize_canvas(size[0], size[1], msg['forward']);\n", - " fig.send_message('refresh', {});\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_rubberband = function (fig, msg) {\n", - " var x0 = msg['x0'] / fig.ratio;\n", - " var y0 = (fig.canvas.height - msg['y0']) / fig.ratio;\n", - " var x1 = msg['x1'] / fig.ratio;\n", - " var y1 = (fig.canvas.height - msg['y1']) / fig.ratio;\n", - " x0 = Math.floor(x0) + 0.5;\n", - " y0 = Math.floor(y0) + 0.5;\n", - " x1 = Math.floor(x1) + 0.5;\n", - " y1 = Math.floor(y1) + 0.5;\n", - " var min_x = Math.min(x0, x1);\n", - " var min_y = Math.min(y0, y1);\n", - " var width = Math.abs(x1 - x0);\n", - " var height = Math.abs(y1 - y0);\n", - "\n", - " fig.rubberband_context.clearRect(\n", - " 0,\n", - " 0,\n", - " fig.canvas.width / fig.ratio,\n", - " fig.canvas.height / fig.ratio\n", - " );\n", - "\n", - " fig.rubberband_context.strokeRect(min_x, min_y, width, height);\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_figure_label = function (fig, msg) {\n", - " // Updates the figure title.\n", - " fig.header.textContent = msg['label'];\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_cursor = function (fig, msg) {\n", - " fig.canvas_div.style.cursor = msg['cursor'];\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_message = function (fig, msg) {\n", - " fig.message.textContent = msg['message'];\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_draw = function (fig, _msg) {\n", - " // Request the server to send over a new figure.\n", - " fig.send_draw_message();\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_image_mode = function (fig, msg) {\n", - " fig.image_mode = msg['mode'];\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_history_buttons = function (fig, msg) {\n", - " for (var key in msg) {\n", - " if (!(key in fig.buttons)) {\n", - " continue;\n", - " }\n", - " fig.buttons[key].disabled = !msg[key];\n", - " fig.buttons[key].setAttribute('aria-disabled', !msg[key]);\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_navigate_mode = function (fig, msg) {\n", - " if (msg['mode'] === 'PAN') {\n", - " fig.buttons['Pan'].classList.add('active');\n", - " fig.buttons['Zoom'].classList.remove('active');\n", - " } else if (msg['mode'] === 'ZOOM') {\n", - " fig.buttons['Pan'].classList.remove('active');\n", - " fig.buttons['Zoom'].classList.add('active');\n", - " } else {\n", - " fig.buttons['Pan'].classList.remove('active');\n", - " fig.buttons['Zoom'].classList.remove('active');\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.updated_canvas_event = function () {\n", - " // Called whenever the canvas gets updated.\n", - " this.send_message('ack', {});\n", - "};\n", - "\n", - "// A function to construct a web socket function for onmessage handling.\n", - "// Called in the figure constructor.\n", - "mpl.figure.prototype._make_on_message_function = function (fig) {\n", - " return function socket_on_message(evt) {\n", - " if (evt.data instanceof Blob) {\n", - " var img = evt.data;\n", - " if (img.type !== 'image/png') {\n", - " /* FIXME: We get \"Resource interpreted as Image but\n", - " * transferred with MIME type text/plain:\" errors on\n", - " * Chrome. But how to set the MIME type? It doesn't seem\n", - " * to be part of the websocket stream */\n", - " img.type = 'image/png';\n", - " }\n", - "\n", - " /* Free the memory for the previous frames */\n", - " if (fig.imageObj.src) {\n", - " (window.URL || window.webkitURL).revokeObjectURL(\n", - " fig.imageObj.src\n", - " );\n", - " }\n", - "\n", - " fig.imageObj.src = (window.URL || window.webkitURL).createObjectURL(\n", - " img\n", - " );\n", - " fig.updated_canvas_event();\n", - " fig.waiting = false;\n", - " return;\n", - " } else if (\n", - " typeof evt.data === 'string' &&\n", - " evt.data.slice(0, 21) === 'data:image/png;base64'\n", - " ) {\n", - " fig.imageObj.src = evt.data;\n", - " fig.updated_canvas_event();\n", - " fig.waiting = false;\n", - " return;\n", - " }\n", - "\n", - " var msg = JSON.parse(evt.data);\n", - " var msg_type = msg['type'];\n", - "\n", - " // Call the \"handle_{type}\" callback, which takes\n", - " // the figure and JSON message as its only arguments.\n", - " try {\n", - " var callback = fig['handle_' + msg_type];\n", - " } catch (e) {\n", - " console.log(\n", - " \"No handler for the '\" + msg_type + \"' message type: \",\n", - " msg\n", - " );\n", - " return;\n", - " }\n", - "\n", - " if (callback) {\n", - " try {\n", - " // console.log(\"Handling '\" + msg_type + \"' message: \", msg);\n", - " callback(fig, msg);\n", - " } catch (e) {\n", - " console.log(\n", - " \"Exception inside the 'handler_\" + msg_type + \"' callback:\",\n", - " e,\n", - " e.stack,\n", - " msg\n", - " );\n", - " }\n", - " }\n", - " };\n", - "};\n", - "\n", - "function getModifiers(event) {\n", - " var mods = [];\n", - " if (event.ctrlKey) {\n", - " mods.push('ctrl');\n", - " }\n", - " if (event.altKey) {\n", - " mods.push('alt');\n", - " }\n", - " if (event.shiftKey) {\n", - " mods.push('shift');\n", - " }\n", - " if (event.metaKey) {\n", - " mods.push('meta');\n", - " }\n", - " return mods;\n", - "}\n", - "\n", - "/*\n", - " * return a copy of an object with only non-object keys\n", - " * we need this to avoid circular references\n", - " * https://stackoverflow.com/a/24161582/3208463\n", - " */\n", - "function simpleKeys(original) {\n", - " return Object.keys(original).reduce(function (obj, key) {\n", - " if (typeof original[key] !== 'object') {\n", - " obj[key] = original[key];\n", - " }\n", - " return obj;\n", - " }, {});\n", - "}\n", - "\n", - "mpl.figure.prototype.mouse_event = function (event, name) {\n", - " if (name === 'button_press') {\n", - " this.canvas.focus();\n", - " this.canvas_div.focus();\n", - " }\n", - "\n", - " // from https://stackoverflow.com/q/1114465\n", - " var boundingRect = this.canvas.getBoundingClientRect();\n", - " var x = (event.clientX - boundingRect.left) * this.ratio;\n", - " var y = (event.clientY - boundingRect.top) * this.ratio;\n", - "\n", - " this.send_message(name, {\n", - " x: x,\n", - " y: y,\n", - " button: event.button,\n", - " step: event.step,\n", - " modifiers: getModifiers(event),\n", - " guiEvent: simpleKeys(event),\n", - " });\n", - "\n", - " return false;\n", - "};\n", - "\n", - "mpl.figure.prototype._key_event_extra = function (_event, _name) {\n", - " // Handle any extra behaviour associated with a key event\n", - "};\n", - "\n", - "mpl.figure.prototype.key_event = function (event, name) {\n", - " // Prevent repeat events\n", - " if (name === 'key_press') {\n", - " if (event.key === this._key) {\n", - " return;\n", - " } else {\n", - " this._key = event.key;\n", - " }\n", - " }\n", - " if (name === 'key_release') {\n", - " this._key = null;\n", - " }\n", - "\n", - " var value = '';\n", - " if (event.ctrlKey && event.key !== 'Control') {\n", - " value += 'ctrl+';\n", - " }\n", - " else if (event.altKey && event.key !== 'Alt') {\n", - " value += 'alt+';\n", - " }\n", - " else if (event.shiftKey && event.key !== 'Shift') {\n", - " value += 'shift+';\n", - " }\n", - "\n", - " value += 'k' + event.key;\n", - "\n", - " this._key_event_extra(event, name);\n", - "\n", - " this.send_message(name, { key: value, guiEvent: simpleKeys(event) });\n", - " return false;\n", - "};\n", - "\n", - "mpl.figure.prototype.toolbar_button_onclick = function (name) {\n", - " if (name === 'download') {\n", - " this.handle_save(this, null);\n", - " } else {\n", - " this.send_message('toolbar_button', { name: name });\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.toolbar_button_onmouseover = function (tooltip) {\n", - " this.message.textContent = tooltip;\n", - "};\n", - "\n", - "///////////////// REMAINING CONTENT GENERATED BY embed_js.py /////////////////\n", - "// prettier-ignore\n", - "var _JSXTOOLS_RESIZE_OBSERVER=function(A){var t,i=new WeakMap,n=new WeakMap,a=new WeakMap,r=new WeakMap,o=new Set;function s(e){if(!(this instanceof s))throw new TypeError(\"Constructor requires 'new' operator\");i.set(this,e)}function h(){throw new TypeError(\"Function is not a constructor\")}function c(e,t,i,n){e=0 in arguments?Number(arguments[0]):0,t=1 in arguments?Number(arguments[1]):0,i=2 in arguments?Number(arguments[2]):0,n=3 in arguments?Number(arguments[3]):0,this.right=(this.x=this.left=e)+(this.width=i),this.bottom=(this.y=this.top=t)+(this.height=n),Object.freeze(this)}function d(){t=requestAnimationFrame(d);var s=new WeakMap,p=new Set;o.forEach((function(t){r.get(t).forEach((function(i){var r=t instanceof window.SVGElement,o=a.get(t),d=r?0:parseFloat(o.paddingTop),f=r?0:parseFloat(o.paddingRight),l=r?0:parseFloat(o.paddingBottom),u=r?0:parseFloat(o.paddingLeft),g=r?0:parseFloat(o.borderTopWidth),m=r?0:parseFloat(o.borderRightWidth),w=r?0:parseFloat(o.borderBottomWidth),b=u+f,F=d+l,v=(r?0:parseFloat(o.borderLeftWidth))+m,W=g+w,y=r?0:t.offsetHeight-W-t.clientHeight,E=r?0:t.offsetWidth-v-t.clientWidth,R=b+v,z=F+W,M=r?t.width:parseFloat(o.width)-R-E,O=r?t.height:parseFloat(o.height)-z-y;if(n.has(t)){var k=n.get(t);if(k[0]===M&&k[1]===O)return}n.set(t,[M,O]);var S=Object.create(h.prototype);S.target=t,S.contentRect=new c(u,d,M,O),s.has(i)||(s.set(i,[]),p.add(i)),s.get(i).push(S)}))})),p.forEach((function(e){i.get(e).call(e,s.get(e),e)}))}return s.prototype.observe=function(i){if(i instanceof window.Element){r.has(i)||(r.set(i,new Set),o.add(i),a.set(i,window.getComputedStyle(i)));var n=r.get(i);n.has(this)||n.add(this),cancelAnimationFrame(t),t=requestAnimationFrame(d)}},s.prototype.unobserve=function(i){if(i instanceof window.Element&&r.has(i)){var n=r.get(i);n.has(this)&&(n.delete(this),n.size||(r.delete(i),o.delete(i))),n.size||r.delete(i),o.size||cancelAnimationFrame(t)}},A.DOMRectReadOnly=c,A.ResizeObserver=s,A.ResizeObserverEntry=h,A}; // eslint-disable-line\n", - "mpl.toolbar_items = [[\"Home\", \"Reset original view\", \"fa fa-home\", \"home\"], [\"Back\", \"Back to previous view\", \"fa fa-arrow-left\", \"back\"], [\"Forward\", \"Forward to next view\", \"fa fa-arrow-right\", \"forward\"], [\"\", \"\", \"\", \"\"], [\"Pan\", \"Left button pans, Right button zooms\\nx/y fixes axis, CTRL fixes aspect\", \"fa fa-arrows\", \"pan\"], [\"Zoom\", \"Zoom to rectangle\\nx/y fixes axis\", \"fa fa-square-o\", \"zoom\"], [\"\", \"\", \"\", \"\"], [\"Download\", \"Download plot\", \"fa fa-floppy-o\", \"download\"]];\n", - "\n", - "mpl.extensions = [\"eps\", \"jpeg\", \"pgf\", \"pdf\", \"png\", \"ps\", \"raw\", \"svg\", \"tif\", \"webp\"];\n", - "\n", - "mpl.default_extension = \"png\";/* global mpl */\n", - "\n", - "var comm_websocket_adapter = function (comm) {\n", - " // Create a \"websocket\"-like object which calls the given IPython comm\n", - " // object with the appropriate methods. Currently this is a non binary\n", - " // socket, so there is still some room for performance tuning.\n", - " var ws = {};\n", - "\n", - " ws.binaryType = comm.kernel.ws.binaryType;\n", - " ws.readyState = comm.kernel.ws.readyState;\n", - " function updateReadyState(_event) {\n", - " if (comm.kernel.ws) {\n", - " ws.readyState = comm.kernel.ws.readyState;\n", - " } else {\n", - " ws.readyState = 3; // Closed state.\n", - " }\n", - " }\n", - " comm.kernel.ws.addEventListener('open', updateReadyState);\n", - " comm.kernel.ws.addEventListener('close', updateReadyState);\n", - " comm.kernel.ws.addEventListener('error', updateReadyState);\n", - "\n", - " ws.close = function () {\n", - " comm.close();\n", - " };\n", - " ws.send = function (m) {\n", - " //console.log('sending', m);\n", - " comm.send(m);\n", - " };\n", - " // Register the callback with on_msg.\n", - " comm.on_msg(function (msg) {\n", - " //console.log('receiving', msg['content']['data'], msg);\n", - " var data = msg['content']['data'];\n", - " if (data['blob'] !== undefined) {\n", - " data = {\n", - " data: new Blob(msg['buffers'], { type: data['blob'] }),\n", - " };\n", - " }\n", - " // Pass the mpl event to the overridden (by mpl) onmessage function.\n", - " ws.onmessage(data);\n", - " });\n", - " return ws;\n", - "};\n", - "\n", - "mpl.mpl_figure_comm = function (comm, msg) {\n", - " // This is the function which gets called when the mpl process\n", - " // starts-up an IPython Comm through the \"matplotlib\" channel.\n", - "\n", - " var id = msg.content.data.id;\n", - " // Get hold of the div created by the display call when the Comm\n", - " // socket was opened in Python.\n", - " var element = document.getElementById(id);\n", - " var ws_proxy = comm_websocket_adapter(comm);\n", - "\n", - " function ondownload(figure, _format) {\n", - " window.open(figure.canvas.toDataURL());\n", - " }\n", - "\n", - " var fig = new mpl.figure(id, ws_proxy, ondownload, element);\n", - "\n", - " // Call onopen now - mpl needs it, as it is assuming we've passed it a real\n", - " // web socket which is closed, not our websocket->open comm proxy.\n", - " ws_proxy.onopen();\n", - "\n", - " fig.parent_element = element;\n", - " fig.cell_info = mpl.find_output_cell(\"
\");\n", - " if (!fig.cell_info) {\n", - " console.error('Failed to find cell for figure', id, fig);\n", - " return;\n", - " }\n", - " fig.cell_info[0].output_area.element.on(\n", - " 'cleared',\n", - " { fig: fig },\n", - " fig._remove_fig_handler\n", - " );\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_close = function (fig, msg) {\n", - " var width = fig.canvas.width / fig.ratio;\n", - " fig.cell_info[0].output_area.element.off(\n", - " 'cleared',\n", - " fig._remove_fig_handler\n", - " );\n", - " fig.resizeObserverInstance.unobserve(fig.canvas_div);\n", - "\n", - " // Update the output cell to use the data from the current canvas.\n", - " fig.push_to_output();\n", - " var dataURL = fig.canvas.toDataURL();\n", - " // Re-enable the keyboard manager in IPython - without this line, in FF,\n", - " // the notebook keyboard shortcuts fail.\n", - " IPython.keyboard_manager.enable();\n", - " fig.parent_element.innerHTML =\n", - " '';\n", - " fig.close_ws(fig, msg);\n", - "};\n", - "\n", - "mpl.figure.prototype.close_ws = function (fig, msg) {\n", - " fig.send_message('closing', msg);\n", - " // fig.ws.close()\n", - "};\n", - "\n", - "mpl.figure.prototype.push_to_output = function (_remove_interactive) {\n", - " // Turn the data on the canvas into data in the output cell.\n", - " var width = this.canvas.width / this.ratio;\n", - " var dataURL = this.canvas.toDataURL();\n", - " this.cell_info[1]['text/html'] =\n", - " '';\n", - "};\n", - "\n", - "mpl.figure.prototype.updated_canvas_event = function () {\n", - " // Tell IPython that the notebook contents must change.\n", - " IPython.notebook.set_dirty(true);\n", - " this.send_message('ack', {});\n", - " var fig = this;\n", - " // Wait a second, then push the new image to the DOM so\n", - " // that it is saved nicely (might be nice to debounce this).\n", - " setTimeout(function () {\n", - " fig.push_to_output();\n", - " }, 1000);\n", - "};\n", - "\n", - "mpl.figure.prototype._init_toolbar = function () {\n", - " var fig = this;\n", - "\n", - " var toolbar = document.createElement('div');\n", - " toolbar.classList = 'btn-toolbar';\n", - " this.root.appendChild(toolbar);\n", - "\n", - " function on_click_closure(name) {\n", - " return function (_event) {\n", - " return fig.toolbar_button_onclick(name);\n", - " };\n", - " }\n", - "\n", - " function on_mouseover_closure(tooltip) {\n", - " return function (event) {\n", - " if (!event.currentTarget.disabled) {\n", - " return fig.toolbar_button_onmouseover(tooltip);\n", - " }\n", - " };\n", - " }\n", - "\n", - " fig.buttons = {};\n", - " var buttonGroup = document.createElement('div');\n", - " buttonGroup.classList = 'btn-group';\n", - " var button;\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", - " /* Instead of a spacer, we start a new button group. */\n", - " if (buttonGroup.hasChildNodes()) {\n", - " toolbar.appendChild(buttonGroup);\n", - " }\n", - " buttonGroup = document.createElement('div');\n", - " buttonGroup.classList = 'btn-group';\n", - " continue;\n", - " }\n", - "\n", - " button = fig.buttons[name] = document.createElement('button');\n", - " button.classList = 'btn btn-default';\n", - " button.href = '#';\n", - " button.title = name;\n", - " button.innerHTML = '';\n", - " button.addEventListener('click', on_click_closure(method_name));\n", - " button.addEventListener('mouseover', on_mouseover_closure(tooltip));\n", - " buttonGroup.appendChild(button);\n", - " }\n", - "\n", - " if (buttonGroup.hasChildNodes()) {\n", - " toolbar.appendChild(buttonGroup);\n", - " }\n", - "\n", - " // Add the status bar.\n", - " var status_bar = document.createElement('span');\n", - " status_bar.classList = 'mpl-message pull-right';\n", - " toolbar.appendChild(status_bar);\n", - " this.message = status_bar;\n", - "\n", - " // Add the close button to the window.\n", - " var buttongrp = document.createElement('div');\n", - " buttongrp.classList = 'btn-group inline pull-right';\n", - " button = document.createElement('button');\n", - " button.classList = 'btn btn-mini btn-primary';\n", - " button.href = '#';\n", - " button.title = 'Stop Interaction';\n", - " button.innerHTML = '';\n", - " button.addEventListener('click', function (_evt) {\n", - " fig.handle_close(fig, {});\n", - " });\n", - " button.addEventListener(\n", - " 'mouseover',\n", - " on_mouseover_closure('Stop Interaction')\n", - " );\n", - " buttongrp.appendChild(button);\n", - " var titlebar = this.root.querySelector('.ui-dialog-titlebar');\n", - " titlebar.insertBefore(buttongrp, titlebar.firstChild);\n", - "};\n", - "\n", - "mpl.figure.prototype._remove_fig_handler = function (event) {\n", - " var fig = event.data.fig;\n", - " if (event.target !== this) {\n", - " // Ignore bubbled events from children.\n", - " return;\n", - " }\n", - " fig.close_ws(fig, {});\n", - "};\n", - "\n", - "mpl.figure.prototype._root_extra_style = function (el) {\n", - " el.style.boxSizing = 'content-box'; // override notebook setting of border-box.\n", - "};\n", - "\n", - "mpl.figure.prototype._canvas_extra_style = function (el) {\n", - " // this is important to make the div 'focusable\n", - " el.setAttribute('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", - " } else {\n", - " // location in version 2\n", - " IPython.keyboard_manager.register_events(el);\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype._key_event_extra = function (event, _name) {\n", - " // Check for shift+enter\n", - " if (event.shiftKey && event.which === 13) {\n", - " this.canvas_div.blur();\n", - " // select the cell after this one\n", - " var index = IPython.notebook.find_cell_index(this.cell_info[0]);\n", - " IPython.notebook.select(index + 1);\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_save = function (fig, _msg) {\n", - " fig.ondownload(fig, null);\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 < ncells; i++) {\n", - " var cell = cells[i];\n", - " if (cell.cell_type === 'code') {\n", - " for (var j = 0; j < cell.output_area.outputs.length; j++) {\n", - " var data = cell.output_area.outputs[j];\n", - " if (data.data) {\n", - " // IPython >= 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(\n", - " 'matplotlib',\n", - " mpl.mpl_figure_comm\n", - " );\n", - "}\n" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/html": [ - "
" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "Observation: obs0\n", - "Filter: hst_wfc3_ir_g141:10880.0-16800.0\n", - "Epoch: 183\n", - "Number of outliers removed: 0\n", - "Uncertainties scale factor: 1\n", - "Residuals statistics:\n", - "res_max_autocorr: \t 0.37896077757966584\n", - "res_max_autocorr_flag: \t False\n", - "res_shapiro: \t\t 0.9680696129798889\n", - "res_shapiro_flag: \t False\n", - "res_mean: \t\t 5.4112843324740725\n", - "res_std: \t\t 17231.47589067632\n", - "res_rms: \t\t 17231.476740342292\n", - "res_chi_sqr: \t\t 90.75523340420631\n", - "res_red_chi_sqr: \t 1.7795143804746334\n" - ] - } - ], - "source": [ - "\n", - "###############################################################################################\n", - "##### Test the performance of the trend function \n", - "###############################################################################################\n", - "\n", - "# We can test the performance of the trend function with quick fit, using: \n", - "# optimiser = 'curve_fit'.\n", - "\n", - "test = planet.transit_fitting(\n", - " optimiser = 'curve_fit',\n", - ")\n", - "\n", - "###############################################################################################\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "###############################################################################################\n", - "##### Evaluate test results\n", - "###############################################################################################\n", - "\n", - "# To evaluate the test results we can plot the raw data, trend function, and residuals like this:\n", - "\n", - "observations = len(test['observations'])\n", - "plt.figure(figsize=(9,6))\n", - "for obs_n, obs_id in enumerate(test['observations']):\n", - " observation = test['observations'][obs_id]\n", - " plt.subplot(2, observations, obs_n + 1)\n", - " plt.errorbar(observation['input_series']['time'], \n", - " observation['input_series']['flux'], \n", - " observation['input_series']['flux_unc'], \n", - " fmt='o', zorder=0, label='raw data')\n", - " plt.plot(observation['input_series']['time'], observation['output_series']['trend'], 'r--', zorder=1, \n", - " label='trend model')\n", - " plt.plot(observation['input_series']['time'], observation['output_series']['model'], 'r-', zorder=1,\n", - " label='trend + transit model'\n", - " )\n", - " plt.legend(fontsize='small')\n", - " plt.ylabel('rel. flux')\n", - " plt.title(obs_id)\n", - "\n", - " plt.subplot(2, observations, observations + 1)\n", - " plt.errorbar(observation['input_series']['time'], \n", - " observation['output_series']['residuals'], \n", - " observation['input_series']['flux_unc'], \n", - " fmt='o', zorder=0)\n", - " plt.xlabel('time (BJD_TDB)')\n", - " plt.ylabel('rel. flux residuals')\n", - "\n", - " \n", - " \n", - "# And also print the residuals diagnostics like this:\n", - "\n", - "for obs_n, obs_id in enumerate(test['observations']):\n", - " observation = test['observations'][obs_id]\n", - " print('')\n", - " print('Observation: ', obs_id)\n", - " print('Filter: ', observation['model_info']['filter_id'])\n", - " print('Epoch: ', observation['model_info']['epoch'])\n", - " print('Number of outliers removed: ', observation['data_conversion_info']['outliers'])\n", - " print('Uncertainties scale factor: ', observation['data_conversion_info']['scale_factor'])\n", - "\n", - " print('Residuals statistics:')\n", - " print('res_max_autocorr:', '\\t', observation['statistics']['res_max_autocorr'])\n", - " print('res_max_autocorr_flag:', '\\t', observation['statistics']['res_max_autocorr_flag'])\n", - " print('res_shapiro:', '\\t\\t', observation['statistics']['res_shapiro'])\n", - " print('res_shapiro_flag:', '\\t', observation['statistics']['res_shapiro_flag'])\n", - " print('res_mean:', '\\t\\t', observation['statistics']['res_mean'])\n", - " print('res_std:', '\\t\\t', observation['statistics']['res_std'])\n", - " print('res_rms:', '\\t\\t', observation['statistics']['res_rms'])\n", - " print('res_chi_sqr:', '\\t\\t', observation['statistics']['res_chi_sqr'])\n", - " print('res_red_chi_sqr:', '\\t', observation['statistics']['res_red_chi_sqr'])\n", - " \n", - "###############################################################################################\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "0a5ae6df", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "Observation: obs0\n", - "Filter: hst_wfc3_ir_g141:10880.0-16800.0\n", - "Epoch: 183\n", - "Data-points excluded: 1\n", - "Scaling uncertainties by: 1.112082018435905\n", - "\n", - "Optimising initial parameters...\n", - "\u001b[KTransit fitting: 3250 / 5000 , time left: 0:00:51, time elapsed: 0:01:35, total time: 0:02:27" - ] - } - ], - "source": [ - "\n", - "###############################################################################################\n", - "##### MCMC fit\n", - "###############################################################################################\n", - "\n", - "# If the residuals diagniostics look ok, we can run the MCMC.\n", - "# Here we will define the 'output_folder', so that all the results and plots are saved.\n", - "# We don't need to defile the optimiser, as the default one is 'mcmc'.\n", - "# It is also better to use filter_outliers=True to clear the outliers and \n", - "# and scale_uncertainties=True to scale the errorbars to match the residuals rms.\n", - "\n", - "final = planet.transit_fitting(\n", - " output_folder = 'wasp39b_hst',\n", - " filter_outliers=True,\n", - " scale_uncertainties=True,\n", - ")\n", - "\n", - "# By default, the number of iterations is 5000 and the burn in is 1000.\n", - "# If the chains do not converge, we can increase these number, for example by setting:\n", - "# iterations = 10000\n", - "# burn_in = 5000\n", - "\n", - "###############################################################################################\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "57a33b1f", - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "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.11.5" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/notebooks/2_detrending_examples/.ipynb_checkpoints/5_wasp39b_comb-checkpoint.ipynb b/notebooks/2_detrending_examples/.ipynb_checkpoints/5_wasp39b_comb-checkpoint.ipynb deleted file mode 100644 index 84f82dd..0000000 --- a/notebooks/2_detrending_examples/.ipynb_checkpoints/5_wasp39b_comb-checkpoint.ipynb +++ /dev/null @@ -1,389 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "id": "988b5848", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "exoclock: Checking ephemerides database...\n", - "exoclock: Checking catalogues database...\n", - "exoclock: Checking ut database...\n", - "pylightcurve: Checking exotethys database...\n", - "pylightcurve: Checking photometry database...\n" - ] - } - ], - "source": [ - "%matplotlib notebook\n", - "import matplotlib.pyplot as plt\n", - "import pylightcurve as plc\n", - "import numpy as np\n", - "\n", - "\n", - "###############################################################################################\n", - "##### Create a Planet object\n", - "###############################################################################################\n", - "\n", - "# At first we need to create a Planet object.\n", - "# Planets include in the ExoClock project (https://www.exoclock.space/database/planets)\n", - "# can be loaded automatically. \n", - "# Alteranatively we can difine our custom Planet object (see notebook: The Planet class)\n", - "\n", - "planet = plc.get_planet('WASP-39b')\n", - "\n", - "###############################################################################################\n" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "id": "d7d0615c", - "metadata": {}, - "outputs": [], - "source": [ - "###############################################################################################\n", - "##### Load data\n", - "###############################################################################################\n", - "\n", - "# Here we will combine all the data for WASP-39b from the previous notebooks.\n", - "\n", - "data_ground = plc.open_dict('wasp39b_ground.pickle')\n", - "data_tess = plc.open_dict('wasp39b_tess.pickle')\n", - "data_hst = plc.open_dict('wasp39b_hst.pickle')\n", - "data_jwst = plc.open_dict('wasp39b_jwst.pickle')\n", - "\n", - "###############################################################################################\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "###############################################################################################\n", - "##### Define the trend function\n", - "###############################################################################################\n", - "\n", - "# Here we will combine all the trend function from the previous notebooks.\n", - "\n", - "# Keep the default second order polynomial with time for JWST and TESS data.\n", - "\n", - "# A fisrt order polynomial with airmass for the ground-based data:\n", - "\n", - "data_ground['detrending_series'] = 'airmass'\n", - "data_ground['detrending_order'] = 1\n", - "\n", - "\n", - "# A linear with time in the observation (time - start of the observation) \n", - "# and an exponential with orbital phase of HST (ophase in the auxiliary data) for the HST data.\n", - "\n", - "def trend_function_hst(dictionary, c1, c2, c3):\n", - " return (1.0 \n", - " - c1 * (dictionary['time'] - min(dictionary['time']))\n", - " - c2 * np.exp(- (10**c3) * dictionary['ophase'])\n", - " )\n", - "\n", - "data_hst['trend_function'] = trend_function_hst\n", - "\n", - "trend_parameters_hst = [\n", - " [0.01, -1, 1, 'ls', '$l_s$'],\n", - " [0.01, -1, 1, 'sa', '$s_a$'],\n", - " [2, 0, 5, 'sd', '$s_d$'],\n", - "]\n", - "\n", - "data_hst['trend_parameters'] = trend_parameters_hst\n", - "\n", - "###############################################################################################\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "###############################################################################################\n", - "##### Define the stellar model\n", - "###############################################################################################\n", - "\n", - "# Here we will combine all the stellar models from the previous notebooks.\n", - "\n", - "# Keep the default 'Pheonix_2018' models for all the datasets, except for the JWST.\n", - "\n", - "data_jwst['stellar_model'] = 'Stagger_2018'\n", - "\n", - "###############################################################################################\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "###############################################################################################\n", - "##### Add observation to the Planet object\n", - "###############################################################################################\n", - "\n", - "# Then we are going to add the observation to the Planet object.\n", - "# It is advised to use planet.clear_observations() before, \n", - "# to avoid duplications, in case we forget that we have already added the same observation.\n", - "\n", - "planet.clear_observations()\n", - "planet.add_observation_from_dict(data_jwst)\n", - "planet.add_observation_from_dict(data_hst)\n", - "planet.add_observation_from_dict(data_tess)\n", - "planet.add_observation_from_dict(data_ground)\n", - "\n", - "###############################################################################################\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "72560cbb", - "metadata": { - "scrolled": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "File already here... teff5000.0_logg4.0_MH-0.5.pickle\n", - "File already here... teff5000.0_logg4.0_MH0.0.pickle\n", - "File already here... teff5000.0_logg4.5_MH-1.0.pickle\n", - "File already here... teff5500.0_logg4.0_MH-0.5.pickle\n", - "File already here... teff5500.0_logg4.0_MH0.0.pickle\n", - "File already here... teff5500.0_logg4.5_MH-0.5.pickle\n", - "File already here... teff5500.0_logg4.5_MH0.0.pickle\n", - "File already here... teff5000.0_logg4.5_MH0.0.pickle\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "WARNING:root:\n", - "PHOENIX models are only computed for solar metallicity stars. Setting stellar_metallicity = 0.\n", - "\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "File already here... teff05400_logg4.00_MH0.0.pickle\n", - "File already here... teff05400_logg4.50_MH0.0.pickle\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "WARNING:root:\n", - "PHOENIX models are only computed for solar metallicity stars. Setting stellar_metallicity = 0.\n", - "\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "File already here... teff05400_logg4.00_MH0.0.pickle\n", - "File already here... teff05400_logg4.50_MH0.0.pickle\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "WARNING:root:\n", - "PHOENIX models are only computed for solar metallicity stars. Setting stellar_metallicity = 0.\n", - "\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "File already here... teff05400_logg4.00_MH0.0.pickle\n", - "File already here... teff05400_logg4.50_MH0.0.pickle\n", - "\n", - "Observation: obs0\n", - "Filter: jwst_niriss1:8600.0-28000.0\n", - "Epoch: 715\n", - "Data-points excluded: 0\n", - "Scaling uncertainties by: 1\n", - "\n", - "Observation: obs1\n", - "Filter: hst_wfc3_ir_g141:10880.0-16800.0\n", - "Epoch: 183\n", - "Data-points excluded: 0\n", - "Scaling uncertainties by: 1\n", - "\n", - "Observation: obs2\n", - "Filter: TESS\n", - "Epoch: 694\n", - "Data-points excluded: 0\n", - "Scaling uncertainties by: 1\n", - "\n", - "Observation: obs3\n", - "Filter: luminance\n", - "Epoch: 603\n", - "Data-points excluded: 0\n", - "Scaling uncertainties by: 1\n", - "\n", - "Optimising initial parameters...\n" - ] - } - ], - "source": [ - "\n", - "###############################################################################################\n", - "##### Test the performance of the trend function \n", - "###############################################################################################\n", - "\n", - "# We can test the performance of the trend function with quick fit, using: \n", - "# optimiser = 'curve_fit'.\n", - "# Here, the quality of the data is good enough to fit for the orbital parameters (sma and i):\n", - "# fit_sma_over_rs = True\n", - "# fit_inclination = True.\n", - "\n", - "test = planet.transit_fitting(\n", - " optimiser = 'curve_fit',\n", - " fit_sma_over_rs=True, \n", - " fit_inclination=True,\n", - ")\n", - "\n", - "###############################################################################################\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "###############################################################################################\n", - "##### Evaluate test results\n", - "###############################################################################################\n", - "\n", - "# To evaluate the test results we can plot the raw data, trend function, and residuals like this:\n", - "\n", - "observations = len(test['observations'])\n", - "plt.figure(figsize=(9,6))\n", - "for obs_n, obs_id in enumerate(test['observations']):\n", - " observation = test['observations'][obs_id]\n", - " plt.subplot(2, observations, obs_n + 1)\n", - " plt.errorbar(observation['input_series']['time'], \n", - " observation['input_series']['flux'], \n", - " observation['input_series']['flux_unc'], \n", - " fmt='o', zorder=0, label='raw data')\n", - " plt.plot(observation['input_series']['time'], observation['output_series']['trend'], 'r--', zorder=1, \n", - " label='trend model')\n", - " plt.plot(observation['input_series']['time'], observation['output_series']['model'], 'r-', zorder=1,\n", - " label='trend + transit model'\n", - " )\n", - " if obs_n == 0:\n", - " plt.ylabel('rel. flux')\n", - " plt.title(obs_id)\n", - "\n", - " plt.subplot(2, observations, observations + obs_n + 1)\n", - " plt.errorbar(observation['input_series']['time'], \n", - " observation['output_series']['residuals'], \n", - " observation['input_series']['flux_unc'], \n", - " fmt='o', zorder=0)\n", - " if obs_n == 0:\n", - " plt.ylabel('rel. flux residuals')\n", - " \n", - "plt.subplots_adjust(wspace=0.5, hspace=0.2)\n", - "\n", - " \n", - " \n", - "# And also print the residuals diagnostics like this:\n", - "\n", - "for obs_n, obs_id in enumerate(test['observations']):\n", - " observation = test['observations'][obs_id]\n", - " print('')\n", - " print('Observation: ', obs_id)\n", - " print('Filter: ', observation['model_info']['filter_id'])\n", - " print('Epoch: ', observation['model_info']['epoch'])\n", - " print('Number of outliers removed: ', observation['data_conversion_info']['outliers'])\n", - " print('Uncertainties scale factor: ', observation['data_conversion_info']['scale_factor'])\n", - "\n", - " print('Residuals statistics:')\n", - " print('res_max_autocorr:', '\\t', observation['statistics']['res_max_autocorr'])\n", - " print('res_max_autocorr_flag:', '\\t', observation['statistics']['res_max_autocorr_flag'])\n", - " print('res_shapiro:', '\\t\\t', observation['statistics']['res_shapiro'])\n", - " print('res_shapiro_flag:', '\\t', observation['statistics']['res_shapiro_flag'])\n", - " print('res_mean:', '\\t\\t', observation['statistics']['res_mean'])\n", - " print('res_std:', '\\t\\t', observation['statistics']['res_std'])\n", - " print('res_rms:', '\\t\\t', observation['statistics']['res_rms'])\n", - " print('res_chi_sqr:', '\\t\\t', observation['statistics']['res_chi_sqr'])\n", - " print('res_red_chi_sqr:', '\\t', observation['statistics']['res_red_chi_sqr'])\n", - " \n", - "###############################################################################################\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "0a5ae6df", - "metadata": { - "scrolled": true - }, - "outputs": [], - "source": [ - "\n", - "###############################################################################################\n", - "##### MCMC fit\n", - "###############################################################################################\n", - "\n", - "# If the residuals diagniostics look ok, we can run the MCMC.\n", - "# Here we will define the 'output_folder', so that all the results and plots are saved.\n", - "# We don't need to defile the optimiser, as the default one is 'mcmc'.\n", - "# It is also better to use filter_outliers=True to clear the outliers and \n", - "# and scale_uncertainties=True to scale the errorbars to match the residuals rms.\n", - "\n", - "final = planet.transit_fitting(\n", - " output_folder = 'wasp39b_comb',\n", - " fit_sma_over_rs=True, \n", - " fit_inclination=True,\n", - " filter_outliers=True,\n", - " scale_uncertainties=True,\n", - ")\n", - "\n", - "# By default, the number of iterations is 5000 and the burn in is 1000.\n", - "# If the chains do not converge, we can increase these number, for example by setting:\n", - "# iterations = 10000\n", - "# burn_in = 5000\n", - "\n", - "###############################################################################################\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "d03acb94", - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "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.11.5" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/notebooks/2_detrending_examples/.ipynb_checkpoints/6_hd189733b_sst-checkpoint.ipynb b/notebooks/2_detrending_examples/.ipynb_checkpoints/6_hd189733b_sst-checkpoint.ipynb deleted file mode 100644 index f554754..0000000 --- a/notebooks/2_detrending_examples/.ipynb_checkpoints/6_hd189733b_sst-checkpoint.ipynb +++ /dev/null @@ -1,4417 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "id": "988b5848", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "exoclock: Checking ephemerides database...\n", - "exoclock: Checking catalogues database...\n", - "exoclock: Checking ut database...\n", - "pylightcurve: Checking exotethys database...\n", - "pylightcurve: Checking photometry database...\n" - ] - } - ], - "source": [ - "%matplotlib notebook\n", - "import matplotlib.pyplot as plt\n", - "import pylightcurve as plc\n", - "import numpy as np\n", - "\n", - "\n", - "###############################################################################################\n", - "##### Create a Planet object\n", - "###############################################################################################\n", - "\n", - "# At first we need to create a Planet object.\n", - "# Planets include in the ExoClock project (https://www.exoclock.space/database/planets)\n", - "# can be loaded automatically. \n", - "# Alteranatively we can difine our custom Planet object (see notebook: The Planet class)\n", - "\n", - "planet = plc.get_planet('HD189733b')\n", - "\n", - "###############################################################################################\n" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "id": "715a88fa", - "metadata": { - "scrolled": false - }, - "outputs": [ - { - "data": { - "application/javascript": [ - "/* Put everything inside the global mpl namespace */\n", - "/* global mpl */\n", - "window.mpl = {};\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(\n", - " '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", - "\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 = document.createElement('div');\n", - " this.root.setAttribute('style', 'display: inline-block');\n", - " this._root_extra_style(this.root);\n", - "\n", - " parent_element.appendChild(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 (fig.ratio !== 1) {\n", - " fig.send_message('set_device_pixel_ratio', {\n", - " device_pixel_ratio: fig.ratio,\n", - " });\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 = document.createElement('div');\n", - " titlebar.classList =\n", - " 'ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix';\n", - " var titletext = document.createElement('div');\n", - " titletext.classList = 'ui-dialog-title';\n", - " titletext.setAttribute(\n", - " 'style',\n", - " 'width: 100%; text-align: center; padding: 3px;'\n", - " );\n", - " titlebar.appendChild(titletext);\n", - " this.root.appendChild(titlebar);\n", - " this.header = titletext;\n", - "};\n", - "\n", - "mpl.figure.prototype._canvas_extra_style = function (_canvas_div) {};\n", - "\n", - "mpl.figure.prototype._root_extra_style = function (_canvas_div) {};\n", - "\n", - "mpl.figure.prototype._init_canvas = function () {\n", - " var fig = this;\n", - "\n", - " var canvas_div = (this.canvas_div = document.createElement('div'));\n", - " canvas_div.setAttribute('tabindex', '0');\n", - " canvas_div.setAttribute(\n", - " 'style',\n", - " 'border: 1px solid #ddd;' +\n", - " 'box-sizing: content-box;' +\n", - " 'clear: both;' +\n", - " 'min-height: 1px;' +\n", - " 'min-width: 1px;' +\n", - " 'outline: 0;' +\n", - " 'overflow: hidden;' +\n", - " 'position: relative;' +\n", - " 'resize: both;' +\n", - " 'z-index: 2;'\n", - " );\n", - "\n", - " function on_keyboard_event_closure(name) {\n", - " return function (event) {\n", - " return fig.key_event(event, name);\n", - " };\n", - " }\n", - "\n", - " canvas_div.addEventListener(\n", - " 'keydown',\n", - " on_keyboard_event_closure('key_press')\n", - " );\n", - " canvas_div.addEventListener(\n", - " 'keyup',\n", - " on_keyboard_event_closure('key_release')\n", - " );\n", - "\n", - " this._canvas_extra_style(canvas_div);\n", - " this.root.appendChild(canvas_div);\n", - "\n", - " var canvas = (this.canvas = document.createElement('canvas'));\n", - " canvas.classList.add('mpl-canvas');\n", - " canvas.setAttribute(\n", - " 'style',\n", - " 'box-sizing: content-box;' +\n", - " 'pointer-events: none;' +\n", - " 'position: relative;' +\n", - " 'z-index: 0;'\n", - " );\n", - "\n", - " this.context = canvas.getContext('2d');\n", - "\n", - " var backingStore =\n", - " this.context.backingStorePixelRatio ||\n", - " this.context.webkitBackingStorePixelRatio ||\n", - " this.context.mozBackingStorePixelRatio ||\n", - " this.context.msBackingStorePixelRatio ||\n", - " this.context.oBackingStorePixelRatio ||\n", - " this.context.backingStorePixelRatio ||\n", - " 1;\n", - "\n", - " this.ratio = (window.devicePixelRatio || 1) / backingStore;\n", - "\n", - " var rubberband_canvas = (this.rubberband_canvas = document.createElement(\n", - " 'canvas'\n", - " ));\n", - " rubberband_canvas.setAttribute(\n", - " 'style',\n", - " 'box-sizing: content-box;' +\n", - " 'left: 0;' +\n", - " 'pointer-events: none;' +\n", - " 'position: absolute;' +\n", - " 'top: 0;' +\n", - " 'z-index: 1;'\n", - " );\n", - "\n", - " // Apply a ponyfill if ResizeObserver is not implemented by browser.\n", - " if (this.ResizeObserver === undefined) {\n", - " if (window.ResizeObserver !== undefined) {\n", - " this.ResizeObserver = window.ResizeObserver;\n", - " } else {\n", - " var obs = _JSXTOOLS_RESIZE_OBSERVER({});\n", - " this.ResizeObserver = obs.ResizeObserver;\n", - " }\n", - " }\n", - "\n", - " this.resizeObserverInstance = new this.ResizeObserver(function (entries) {\n", - " // There's no need to resize if the WebSocket is not connected:\n", - " // - If it is still connecting, then we will get an initial resize from\n", - " // Python once it connects.\n", - " // - If it has disconnected, then resizing will clear the canvas and\n", - " // never get anything back to refill it, so better to not resize and\n", - " // keep something visible.\n", - " if (fig.ws.readyState != 1) {\n", - " return;\n", - " }\n", - " var nentries = entries.length;\n", - " for (var i = 0; i < nentries; i++) {\n", - " var entry = entries[i];\n", - " var width, height;\n", - " if (entry.contentBoxSize) {\n", - " if (entry.contentBoxSize instanceof Array) {\n", - " // Chrome 84 implements new version of spec.\n", - " width = entry.contentBoxSize[0].inlineSize;\n", - " height = entry.contentBoxSize[0].blockSize;\n", - " } else {\n", - " // Firefox implements old version of spec.\n", - " width = entry.contentBoxSize.inlineSize;\n", - " height = entry.contentBoxSize.blockSize;\n", - " }\n", - " } else {\n", - " // Chrome <84 implements even older version of spec.\n", - " width = entry.contentRect.width;\n", - " height = entry.contentRect.height;\n", - " }\n", - "\n", - " // Keep the size of the canvas and rubber band canvas in sync with\n", - " // the canvas container.\n", - " if (entry.devicePixelContentBoxSize) {\n", - " // Chrome 84 implements new version of spec.\n", - " canvas.setAttribute(\n", - " 'width',\n", - " entry.devicePixelContentBoxSize[0].inlineSize\n", - " );\n", - " canvas.setAttribute(\n", - " 'height',\n", - " entry.devicePixelContentBoxSize[0].blockSize\n", - " );\n", - " } else {\n", - " canvas.setAttribute('width', width * fig.ratio);\n", - " canvas.setAttribute('height', height * fig.ratio);\n", - " }\n", - " /* This rescales the canvas back to display pixels, so that it\n", - " * appears correct on HiDPI screens. */\n", - " canvas.style.width = width + 'px';\n", - " canvas.style.height = height + 'px';\n", - "\n", - " rubberband_canvas.setAttribute('width', width);\n", - " rubberband_canvas.setAttribute('height', height);\n", - "\n", - " // And update the size in Python. We ignore the initial 0/0 size\n", - " // that occurs as the element is placed into the DOM, which should\n", - " // otherwise not happen due to the minimum size styling.\n", - " if (width != 0 && height != 0) {\n", - " fig.request_resize(width, height);\n", - " }\n", - " }\n", - " });\n", - " this.resizeObserverInstance.observe(canvas_div);\n", - "\n", - " function on_mouse_event_closure(name) {\n", - " /* User Agent sniffing is bad, but WebKit is busted:\n", - " * https://bugs.webkit.org/show_bug.cgi?id=144526\n", - " * https://bugs.webkit.org/show_bug.cgi?id=181818\n", - " * The worst that happens here is that they get an extra browser\n", - " * selection when dragging, if this check fails to catch them.\n", - " */\n", - " var UA = navigator.userAgent;\n", - " var isWebKit = /AppleWebKit/.test(UA) && !/Chrome/.test(UA);\n", - " if(isWebKit) {\n", - " return function (event) {\n", - " /* This prevents the web browser from automatically changing to\n", - " * the text insertion cursor when the button is pressed. We\n", - " * want to control all of the cursor setting manually through\n", - " * the 'cursor' event from matplotlib */\n", - " event.preventDefault()\n", - " return fig.mouse_event(event, name);\n", - " };\n", - " } else {\n", - " return function (event) {\n", - " return fig.mouse_event(event, name);\n", - " };\n", - " }\n", - " }\n", - "\n", - " canvas_div.addEventListener(\n", - " 'mousedown',\n", - " on_mouse_event_closure('button_press')\n", - " );\n", - " canvas_div.addEventListener(\n", - " 'mouseup',\n", - " on_mouse_event_closure('button_release')\n", - " );\n", - " canvas_div.addEventListener(\n", - " 'dblclick',\n", - " on_mouse_event_closure('dblclick')\n", - " );\n", - " // Throttle sequential mouse events to 1 every 20ms.\n", - " canvas_div.addEventListener(\n", - " 'mousemove',\n", - " on_mouse_event_closure('motion_notify')\n", - " );\n", - "\n", - " canvas_div.addEventListener(\n", - " 'mouseenter',\n", - " on_mouse_event_closure('figure_enter')\n", - " );\n", - " canvas_div.addEventListener(\n", - " 'mouseleave',\n", - " on_mouse_event_closure('figure_leave')\n", - " );\n", - "\n", - " canvas_div.addEventListener('wheel', function (event) {\n", - " if (event.deltaY < 0) {\n", - " event.step = 1;\n", - " } else {\n", - " event.step = -1;\n", - " }\n", - " on_mouse_event_closure('scroll')(event);\n", - " });\n", - "\n", - " canvas_div.appendChild(canvas);\n", - " canvas_div.appendChild(rubberband_canvas);\n", - "\n", - " this.rubberband_context = rubberband_canvas.getContext('2d');\n", - " this.rubberband_context.strokeStyle = '#000000';\n", - "\n", - " this._resize_canvas = function (width, height, forward) {\n", - " if (forward) {\n", - " canvas_div.style.width = width + 'px';\n", - " canvas_div.style.height = height + 'px';\n", - " }\n", - " };\n", - "\n", - " // Disable right mouse context menu.\n", - " canvas_div.addEventListener('contextmenu', function (_e) {\n", - " event.preventDefault();\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 toolbar = document.createElement('div');\n", - " toolbar.classList = 'mpl-toolbar';\n", - " this.root.appendChild(toolbar);\n", - "\n", - " function on_click_closure(name) {\n", - " return function (_event) {\n", - " return fig.toolbar_button_onclick(name);\n", - " };\n", - " }\n", - "\n", - " function on_mouseover_closure(tooltip) {\n", - " return function (event) {\n", - " if (!event.currentTarget.disabled) {\n", - " return fig.toolbar_button_onmouseover(tooltip);\n", - " }\n", - " };\n", - " }\n", - "\n", - " fig.buttons = {};\n", - " var buttonGroup = document.createElement('div');\n", - " buttonGroup.classList = 'mpl-button-group';\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", - " /* Instead of a spacer, we start a new button group. */\n", - " if (buttonGroup.hasChildNodes()) {\n", - " toolbar.appendChild(buttonGroup);\n", - " }\n", - " buttonGroup = document.createElement('div');\n", - " buttonGroup.classList = 'mpl-button-group';\n", - " continue;\n", - " }\n", - "\n", - " var button = (fig.buttons[name] = document.createElement('button'));\n", - " button.classList = 'mpl-widget';\n", - " button.setAttribute('role', 'button');\n", - " button.setAttribute('aria-disabled', 'false');\n", - " button.addEventListener('click', on_click_closure(method_name));\n", - " button.addEventListener('mouseover', on_mouseover_closure(tooltip));\n", - "\n", - " var icon_img = document.createElement('img');\n", - " icon_img.src = '_images/' + image + '.png';\n", - " icon_img.srcset = '_images/' + image + '_large.png 2x';\n", - " icon_img.alt = tooltip;\n", - " button.appendChild(icon_img);\n", - "\n", - " buttonGroup.appendChild(button);\n", - " }\n", - "\n", - " if (buttonGroup.hasChildNodes()) {\n", - " toolbar.appendChild(buttonGroup);\n", - " }\n", - "\n", - " var fmt_picker = document.createElement('select');\n", - " fmt_picker.classList = 'mpl-widget';\n", - " toolbar.appendChild(fmt_picker);\n", - " this.format_dropdown = fmt_picker;\n", - "\n", - " for (var ind in mpl.extensions) {\n", - " var fmt = mpl.extensions[ind];\n", - " var option = document.createElement('option');\n", - " option.selected = fmt === mpl.default_extension;\n", - " option.innerHTML = fmt;\n", - " fmt_picker.appendChild(option);\n", - " }\n", - "\n", - " var status_bar = document.createElement('span');\n", - " status_bar.classList = 'mpl-message';\n", - " toolbar.appendChild(status_bar);\n", - " this.message = status_bar;\n", - "};\n", - "\n", - "mpl.figure.prototype.request_resize = function (x_pixels, y_pixels) {\n", - " // Request matplotlib to resize the figure. Matplotlib will then trigger a resize in the client,\n", - " // which will in turn request a refresh of the image.\n", - " this.send_message('resize', { width: x_pixels, height: y_pixels });\n", - "};\n", - "\n", - "mpl.figure.prototype.send_message = function (type, properties) {\n", - " properties['type'] = type;\n", - " properties['figure_id'] = this.id;\n", - " this.ws.send(JSON.stringify(properties));\n", - "};\n", - "\n", - "mpl.figure.prototype.send_draw_message = function () {\n", - " if (!this.waiting) {\n", - " this.waiting = true;\n", - " this.ws.send(JSON.stringify({ type: 'draw', figure_id: this.id }));\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_save = function (fig, _msg) {\n", - " var format_dropdown = fig.format_dropdown;\n", - " var format = format_dropdown.options[format_dropdown.selectedIndex].value;\n", - " fig.ondownload(fig, format);\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_resize = function (fig, msg) {\n", - " var size = msg['size'];\n", - " if (size[0] !== fig.canvas.width || size[1] !== fig.canvas.height) {\n", - " fig._resize_canvas(size[0], size[1], msg['forward']);\n", - " fig.send_message('refresh', {});\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_rubberband = function (fig, msg) {\n", - " var x0 = msg['x0'] / fig.ratio;\n", - " var y0 = (fig.canvas.height - msg['y0']) / fig.ratio;\n", - " var x1 = msg['x1'] / fig.ratio;\n", - " var y1 = (fig.canvas.height - msg['y1']) / fig.ratio;\n", - " x0 = Math.floor(x0) + 0.5;\n", - " y0 = Math.floor(y0) + 0.5;\n", - " x1 = Math.floor(x1) + 0.5;\n", - " y1 = Math.floor(y1) + 0.5;\n", - " var min_x = Math.min(x0, x1);\n", - " var min_y = Math.min(y0, y1);\n", - " var width = Math.abs(x1 - x0);\n", - " var height = Math.abs(y1 - y0);\n", - "\n", - " fig.rubberband_context.clearRect(\n", - " 0,\n", - " 0,\n", - " fig.canvas.width / fig.ratio,\n", - " fig.canvas.height / fig.ratio\n", - " );\n", - "\n", - " fig.rubberband_context.strokeRect(min_x, min_y, width, height);\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_figure_label = function (fig, msg) {\n", - " // Updates the figure title.\n", - " fig.header.textContent = msg['label'];\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_cursor = function (fig, msg) {\n", - " fig.canvas_div.style.cursor = msg['cursor'];\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_message = function (fig, msg) {\n", - " fig.message.textContent = msg['message'];\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_draw = function (fig, _msg) {\n", - " // Request the server to send over a new figure.\n", - " fig.send_draw_message();\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_image_mode = function (fig, msg) {\n", - " fig.image_mode = msg['mode'];\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_history_buttons = function (fig, msg) {\n", - " for (var key in msg) {\n", - " if (!(key in fig.buttons)) {\n", - " continue;\n", - " }\n", - " fig.buttons[key].disabled = !msg[key];\n", - " fig.buttons[key].setAttribute('aria-disabled', !msg[key]);\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_navigate_mode = function (fig, msg) {\n", - " if (msg['mode'] === 'PAN') {\n", - " fig.buttons['Pan'].classList.add('active');\n", - " fig.buttons['Zoom'].classList.remove('active');\n", - " } else if (msg['mode'] === 'ZOOM') {\n", - " fig.buttons['Pan'].classList.remove('active');\n", - " fig.buttons['Zoom'].classList.add('active');\n", - " } else {\n", - " fig.buttons['Pan'].classList.remove('active');\n", - " fig.buttons['Zoom'].classList.remove('active');\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.updated_canvas_event = function () {\n", - " // Called whenever the canvas gets updated.\n", - " this.send_message('ack', {});\n", - "};\n", - "\n", - "// A function to construct a web socket function for onmessage handling.\n", - "// Called in the figure constructor.\n", - "mpl.figure.prototype._make_on_message_function = function (fig) {\n", - " return function socket_on_message(evt) {\n", - " if (evt.data instanceof Blob) {\n", - " var img = evt.data;\n", - " if (img.type !== 'image/png') {\n", - " /* FIXME: We get \"Resource interpreted as Image but\n", - " * transferred with MIME type text/plain:\" errors on\n", - " * Chrome. But how to set the MIME type? It doesn't seem\n", - " * to be part of the websocket stream */\n", - " img.type = 'image/png';\n", - " }\n", - "\n", - " /* Free the memory for the previous frames */\n", - " if (fig.imageObj.src) {\n", - " (window.URL || window.webkitURL).revokeObjectURL(\n", - " fig.imageObj.src\n", - " );\n", - " }\n", - "\n", - " fig.imageObj.src = (window.URL || window.webkitURL).createObjectURL(\n", - " img\n", - " );\n", - " fig.updated_canvas_event();\n", - " fig.waiting = false;\n", - " return;\n", - " } else if (\n", - " typeof evt.data === 'string' &&\n", - " evt.data.slice(0, 21) === 'data:image/png;base64'\n", - " ) {\n", - " fig.imageObj.src = evt.data;\n", - " fig.updated_canvas_event();\n", - " fig.waiting = false;\n", - " return;\n", - " }\n", - "\n", - " var msg = JSON.parse(evt.data);\n", - " var msg_type = msg['type'];\n", - "\n", - " // Call the \"handle_{type}\" callback, which takes\n", - " // the figure and JSON message as its only arguments.\n", - " try {\n", - " var callback = fig['handle_' + msg_type];\n", - " } catch (e) {\n", - " console.log(\n", - " \"No handler for the '\" + msg_type + \"' message type: \",\n", - " msg\n", - " );\n", - " return;\n", - " }\n", - "\n", - " if (callback) {\n", - " try {\n", - " // console.log(\"Handling '\" + msg_type + \"' message: \", msg);\n", - " callback(fig, msg);\n", - " } catch (e) {\n", - " console.log(\n", - " \"Exception inside the 'handler_\" + msg_type + \"' callback:\",\n", - " e,\n", - " e.stack,\n", - " msg\n", - " );\n", - " }\n", - " }\n", - " };\n", - "};\n", - "\n", - "function getModifiers(event) {\n", - " var mods = [];\n", - " if (event.ctrlKey) {\n", - " mods.push('ctrl');\n", - " }\n", - " if (event.altKey) {\n", - " mods.push('alt');\n", - " }\n", - " if (event.shiftKey) {\n", - " mods.push('shift');\n", - " }\n", - " if (event.metaKey) {\n", - " mods.push('meta');\n", - " }\n", - " return mods;\n", - "}\n", - "\n", - "/*\n", - " * return a copy of an object with only non-object keys\n", - " * we need this to avoid circular references\n", - " * https://stackoverflow.com/a/24161582/3208463\n", - " */\n", - "function simpleKeys(original) {\n", - " return Object.keys(original).reduce(function (obj, key) {\n", - " if (typeof original[key] !== 'object') {\n", - " obj[key] = original[key];\n", - " }\n", - " return obj;\n", - " }, {});\n", - "}\n", - "\n", - "mpl.figure.prototype.mouse_event = function (event, name) {\n", - " if (name === 'button_press') {\n", - " this.canvas.focus();\n", - " this.canvas_div.focus();\n", - " }\n", - "\n", - " // from https://stackoverflow.com/q/1114465\n", - " var boundingRect = this.canvas.getBoundingClientRect();\n", - " var x = (event.clientX - boundingRect.left) * this.ratio;\n", - " var y = (event.clientY - boundingRect.top) * this.ratio;\n", - "\n", - " this.send_message(name, {\n", - " x: x,\n", - " y: y,\n", - " button: event.button,\n", - " step: event.step,\n", - " modifiers: getModifiers(event),\n", - " guiEvent: simpleKeys(event),\n", - " });\n", - "\n", - " return false;\n", - "};\n", - "\n", - "mpl.figure.prototype._key_event_extra = function (_event, _name) {\n", - " // Handle any extra behaviour associated with a key event\n", - "};\n", - "\n", - "mpl.figure.prototype.key_event = function (event, name) {\n", - " // Prevent repeat events\n", - " if (name === 'key_press') {\n", - " if (event.key === this._key) {\n", - " return;\n", - " } else {\n", - " this._key = event.key;\n", - " }\n", - " }\n", - " if (name === 'key_release') {\n", - " this._key = null;\n", - " }\n", - "\n", - " var value = '';\n", - " if (event.ctrlKey && event.key !== 'Control') {\n", - " value += 'ctrl+';\n", - " }\n", - " else if (event.altKey && event.key !== 'Alt') {\n", - " value += 'alt+';\n", - " }\n", - " else if (event.shiftKey && event.key !== 'Shift') {\n", - " value += 'shift+';\n", - " }\n", - "\n", - " value += 'k' + event.key;\n", - "\n", - " this._key_event_extra(event, name);\n", - "\n", - " this.send_message(name, { key: value, guiEvent: simpleKeys(event) });\n", - " return false;\n", - "};\n", - "\n", - "mpl.figure.prototype.toolbar_button_onclick = function (name) {\n", - " if (name === 'download') {\n", - " this.handle_save(this, null);\n", - " } else {\n", - " this.send_message('toolbar_button', { name: name });\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.toolbar_button_onmouseover = function (tooltip) {\n", - " this.message.textContent = tooltip;\n", - "};\n", - "\n", - "///////////////// REMAINING CONTENT GENERATED BY embed_js.py /////////////////\n", - "// prettier-ignore\n", - "var _JSXTOOLS_RESIZE_OBSERVER=function(A){var t,i=new WeakMap,n=new WeakMap,a=new WeakMap,r=new WeakMap,o=new Set;function s(e){if(!(this instanceof s))throw new TypeError(\"Constructor requires 'new' operator\");i.set(this,e)}function h(){throw new TypeError(\"Function is not a constructor\")}function c(e,t,i,n){e=0 in arguments?Number(arguments[0]):0,t=1 in arguments?Number(arguments[1]):0,i=2 in arguments?Number(arguments[2]):0,n=3 in arguments?Number(arguments[3]):0,this.right=(this.x=this.left=e)+(this.width=i),this.bottom=(this.y=this.top=t)+(this.height=n),Object.freeze(this)}function d(){t=requestAnimationFrame(d);var s=new WeakMap,p=new Set;o.forEach((function(t){r.get(t).forEach((function(i){var r=t instanceof window.SVGElement,o=a.get(t),d=r?0:parseFloat(o.paddingTop),f=r?0:parseFloat(o.paddingRight),l=r?0:parseFloat(o.paddingBottom),u=r?0:parseFloat(o.paddingLeft),g=r?0:parseFloat(o.borderTopWidth),m=r?0:parseFloat(o.borderRightWidth),w=r?0:parseFloat(o.borderBottomWidth),b=u+f,F=d+l,v=(r?0:parseFloat(o.borderLeftWidth))+m,W=g+w,y=r?0:t.offsetHeight-W-t.clientHeight,E=r?0:t.offsetWidth-v-t.clientWidth,R=b+v,z=F+W,M=r?t.width:parseFloat(o.width)-R-E,O=r?t.height:parseFloat(o.height)-z-y;if(n.has(t)){var k=n.get(t);if(k[0]===M&&k[1]===O)return}n.set(t,[M,O]);var S=Object.create(h.prototype);S.target=t,S.contentRect=new c(u,d,M,O),s.has(i)||(s.set(i,[]),p.add(i)),s.get(i).push(S)}))})),p.forEach((function(e){i.get(e).call(e,s.get(e),e)}))}return s.prototype.observe=function(i){if(i instanceof window.Element){r.has(i)||(r.set(i,new Set),o.add(i),a.set(i,window.getComputedStyle(i)));var n=r.get(i);n.has(this)||n.add(this),cancelAnimationFrame(t),t=requestAnimationFrame(d)}},s.prototype.unobserve=function(i){if(i instanceof window.Element&&r.has(i)){var n=r.get(i);n.has(this)&&(n.delete(this),n.size||(r.delete(i),o.delete(i))),n.size||r.delete(i),o.size||cancelAnimationFrame(t)}},A.DOMRectReadOnly=c,A.ResizeObserver=s,A.ResizeObserverEntry=h,A}; // eslint-disable-line\n", - "mpl.toolbar_items = [[\"Home\", \"Reset original view\", \"fa fa-home\", \"home\"], [\"Back\", \"Back to previous view\", \"fa fa-arrow-left\", \"back\"], [\"Forward\", \"Forward to next view\", \"fa fa-arrow-right\", \"forward\"], [\"\", \"\", \"\", \"\"], [\"Pan\", \"Left button pans, Right button zooms\\nx/y fixes axis, CTRL fixes aspect\", \"fa fa-arrows\", \"pan\"], [\"Zoom\", \"Zoom to rectangle\\nx/y fixes axis\", \"fa fa-square-o\", \"zoom\"], [\"\", \"\", \"\", \"\"], [\"Download\", \"Download plot\", \"fa fa-floppy-o\", \"download\"]];\n", - "\n", - "mpl.extensions = [\"eps\", \"jpeg\", \"pgf\", \"pdf\", \"png\", \"ps\", \"raw\", \"svg\", \"tif\", \"webp\"];\n", - "\n", - "mpl.default_extension = \"png\";/* global mpl */\n", - "\n", - "var comm_websocket_adapter = function (comm) {\n", - " // Create a \"websocket\"-like object which calls the given IPython comm\n", - " // object with the appropriate methods. Currently this is a non binary\n", - " // socket, so there is still some room for performance tuning.\n", - " var ws = {};\n", - "\n", - " ws.binaryType = comm.kernel.ws.binaryType;\n", - " ws.readyState = comm.kernel.ws.readyState;\n", - " function updateReadyState(_event) {\n", - " if (comm.kernel.ws) {\n", - " ws.readyState = comm.kernel.ws.readyState;\n", - " } else {\n", - " ws.readyState = 3; // Closed state.\n", - " }\n", - " }\n", - " comm.kernel.ws.addEventListener('open', updateReadyState);\n", - " comm.kernel.ws.addEventListener('close', updateReadyState);\n", - " comm.kernel.ws.addEventListener('error', updateReadyState);\n", - "\n", - " ws.close = function () {\n", - " comm.close();\n", - " };\n", - " ws.send = function (m) {\n", - " //console.log('sending', m);\n", - " comm.send(m);\n", - " };\n", - " // Register the callback with on_msg.\n", - " comm.on_msg(function (msg) {\n", - " //console.log('receiving', msg['content']['data'], msg);\n", - " var data = msg['content']['data'];\n", - " if (data['blob'] !== undefined) {\n", - " data = {\n", - " data: new Blob(msg['buffers'], { type: data['blob'] }),\n", - " };\n", - " }\n", - " // Pass the mpl event to the overridden (by mpl) onmessage function.\n", - " ws.onmessage(data);\n", - " });\n", - " return ws;\n", - "};\n", - "\n", - "mpl.mpl_figure_comm = function (comm, msg) {\n", - " // This is the function which gets called when the mpl process\n", - " // starts-up an IPython Comm through the \"matplotlib\" channel.\n", - "\n", - " var id = msg.content.data.id;\n", - " // Get hold of the div created by the display call when the Comm\n", - " // socket was opened in Python.\n", - " var element = document.getElementById(id);\n", - " var ws_proxy = comm_websocket_adapter(comm);\n", - "\n", - " function ondownload(figure, _format) {\n", - " window.open(figure.canvas.toDataURL());\n", - " }\n", - "\n", - " var fig = new mpl.figure(id, ws_proxy, ondownload, element);\n", - "\n", - " // Call onopen now - mpl needs it, as it is assuming we've passed it a real\n", - " // web socket which is closed, not our websocket->open comm proxy.\n", - " ws_proxy.onopen();\n", - "\n", - " fig.parent_element = element;\n", - " fig.cell_info = mpl.find_output_cell(\"
\");\n", - " if (!fig.cell_info) {\n", - " console.error('Failed to find cell for figure', id, fig);\n", - " return;\n", - " }\n", - " fig.cell_info[0].output_area.element.on(\n", - " 'cleared',\n", - " { fig: fig },\n", - " fig._remove_fig_handler\n", - " );\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_close = function (fig, msg) {\n", - " var width = fig.canvas.width / fig.ratio;\n", - " fig.cell_info[0].output_area.element.off(\n", - " 'cleared',\n", - " fig._remove_fig_handler\n", - " );\n", - " fig.resizeObserverInstance.unobserve(fig.canvas_div);\n", - "\n", - " // Update the output cell to use the data from the current canvas.\n", - " fig.push_to_output();\n", - " var dataURL = fig.canvas.toDataURL();\n", - " // Re-enable the keyboard manager in IPython - without this line, in FF,\n", - " // the notebook keyboard shortcuts fail.\n", - " IPython.keyboard_manager.enable();\n", - " fig.parent_element.innerHTML =\n", - " '';\n", - " fig.close_ws(fig, msg);\n", - "};\n", - "\n", - "mpl.figure.prototype.close_ws = function (fig, msg) {\n", - " fig.send_message('closing', msg);\n", - " // fig.ws.close()\n", - "};\n", - "\n", - "mpl.figure.prototype.push_to_output = function (_remove_interactive) {\n", - " // Turn the data on the canvas into data in the output cell.\n", - " var width = this.canvas.width / this.ratio;\n", - " var dataURL = this.canvas.toDataURL();\n", - " this.cell_info[1]['text/html'] =\n", - " '';\n", - "};\n", - "\n", - "mpl.figure.prototype.updated_canvas_event = function () {\n", - " // Tell IPython that the notebook contents must change.\n", - " IPython.notebook.set_dirty(true);\n", - " this.send_message('ack', {});\n", - " var fig = this;\n", - " // Wait a second, then push the new image to the DOM so\n", - " // that it is saved nicely (might be nice to debounce this).\n", - " setTimeout(function () {\n", - " fig.push_to_output();\n", - " }, 1000);\n", - "};\n", - "\n", - "mpl.figure.prototype._init_toolbar = function () {\n", - " var fig = this;\n", - "\n", - " var toolbar = document.createElement('div');\n", - " toolbar.classList = 'btn-toolbar';\n", - " this.root.appendChild(toolbar);\n", - "\n", - " function on_click_closure(name) {\n", - " return function (_event) {\n", - " return fig.toolbar_button_onclick(name);\n", - " };\n", - " }\n", - "\n", - " function on_mouseover_closure(tooltip) {\n", - " return function (event) {\n", - " if (!event.currentTarget.disabled) {\n", - " return fig.toolbar_button_onmouseover(tooltip);\n", - " }\n", - " };\n", - " }\n", - "\n", - " fig.buttons = {};\n", - " var buttonGroup = document.createElement('div');\n", - " buttonGroup.classList = 'btn-group';\n", - " var button;\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", - " /* Instead of a spacer, we start a new button group. */\n", - " if (buttonGroup.hasChildNodes()) {\n", - " toolbar.appendChild(buttonGroup);\n", - " }\n", - " buttonGroup = document.createElement('div');\n", - " buttonGroup.classList = 'btn-group';\n", - " continue;\n", - " }\n", - "\n", - " button = fig.buttons[name] = document.createElement('button');\n", - " button.classList = 'btn btn-default';\n", - " button.href = '#';\n", - " button.title = name;\n", - " button.innerHTML = '';\n", - " button.addEventListener('click', on_click_closure(method_name));\n", - " button.addEventListener('mouseover', on_mouseover_closure(tooltip));\n", - " buttonGroup.appendChild(button);\n", - " }\n", - "\n", - " if (buttonGroup.hasChildNodes()) {\n", - " toolbar.appendChild(buttonGroup);\n", - " }\n", - "\n", - " // Add the status bar.\n", - " var status_bar = document.createElement('span');\n", - " status_bar.classList = 'mpl-message pull-right';\n", - " toolbar.appendChild(status_bar);\n", - " this.message = status_bar;\n", - "\n", - " // Add the close button to the window.\n", - " var buttongrp = document.createElement('div');\n", - " buttongrp.classList = 'btn-group inline pull-right';\n", - " button = document.createElement('button');\n", - " button.classList = 'btn btn-mini btn-primary';\n", - " button.href = '#';\n", - " button.title = 'Stop Interaction';\n", - " button.innerHTML = '';\n", - " button.addEventListener('click', function (_evt) {\n", - " fig.handle_close(fig, {});\n", - " });\n", - " button.addEventListener(\n", - " 'mouseover',\n", - " on_mouseover_closure('Stop Interaction')\n", - " );\n", - " buttongrp.appendChild(button);\n", - " var titlebar = this.root.querySelector('.ui-dialog-titlebar');\n", - " titlebar.insertBefore(buttongrp, titlebar.firstChild);\n", - "};\n", - "\n", - "mpl.figure.prototype._remove_fig_handler = function (event) {\n", - " var fig = event.data.fig;\n", - " if (event.target !== this) {\n", - " // Ignore bubbled events from children.\n", - " return;\n", - " }\n", - " fig.close_ws(fig, {});\n", - "};\n", - "\n", - "mpl.figure.prototype._root_extra_style = function (el) {\n", - " el.style.boxSizing = 'content-box'; // override notebook setting of border-box.\n", - "};\n", - "\n", - "mpl.figure.prototype._canvas_extra_style = function (el) {\n", - " // this is important to make the div 'focusable\n", - " el.setAttribute('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", - " } else {\n", - " // location in version 2\n", - " IPython.keyboard_manager.register_events(el);\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype._key_event_extra = function (event, _name) {\n", - " // Check for shift+enter\n", - " if (event.shiftKey && event.which === 13) {\n", - " this.canvas_div.blur();\n", - " // select the cell after this one\n", - " var index = IPython.notebook.find_cell_index(this.cell_info[0]);\n", - " IPython.notebook.select(index + 1);\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_save = function (fig, _msg) {\n", - " fig.ondownload(fig, null);\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 < ncells; i++) {\n", - " var cell = cells[i];\n", - " if (cell.cell_type === 'code') {\n", - " for (var j = 0; j < cell.output_area.outputs.length; j++) {\n", - " var data = cell.output_area.outputs[j];\n", - " if (data.data) {\n", - " // IPython >= 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(\n", - " 'matplotlib',\n", - " mpl.mpl_figure_comm\n", - " );\n", - "}\n" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/html": [ - "
" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Auxiliary data available:\n" - ] - }, - { - "data": { - "application/javascript": [ - "/* Put everything inside the global mpl namespace */\n", - "/* global mpl */\n", - "window.mpl = {};\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(\n", - " '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", - "\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 = document.createElement('div');\n", - " this.root.setAttribute('style', 'display: inline-block');\n", - " this._root_extra_style(this.root);\n", - "\n", - " parent_element.appendChild(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 (fig.ratio !== 1) {\n", - " fig.send_message('set_device_pixel_ratio', {\n", - " device_pixel_ratio: fig.ratio,\n", - " });\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 = document.createElement('div');\n", - " titlebar.classList =\n", - " 'ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix';\n", - " var titletext = document.createElement('div');\n", - " titletext.classList = 'ui-dialog-title';\n", - " titletext.setAttribute(\n", - " 'style',\n", - " 'width: 100%; text-align: center; padding: 3px;'\n", - " );\n", - " titlebar.appendChild(titletext);\n", - " this.root.appendChild(titlebar);\n", - " this.header = titletext;\n", - "};\n", - "\n", - "mpl.figure.prototype._canvas_extra_style = function (_canvas_div) {};\n", - "\n", - "mpl.figure.prototype._root_extra_style = function (_canvas_div) {};\n", - "\n", - "mpl.figure.prototype._init_canvas = function () {\n", - " var fig = this;\n", - "\n", - " var canvas_div = (this.canvas_div = document.createElement('div'));\n", - " canvas_div.setAttribute('tabindex', '0');\n", - " canvas_div.setAttribute(\n", - " 'style',\n", - " 'border: 1px solid #ddd;' +\n", - " 'box-sizing: content-box;' +\n", - " 'clear: both;' +\n", - " 'min-height: 1px;' +\n", - " 'min-width: 1px;' +\n", - " 'outline: 0;' +\n", - " 'overflow: hidden;' +\n", - " 'position: relative;' +\n", - " 'resize: both;' +\n", - " 'z-index: 2;'\n", - " );\n", - "\n", - " function on_keyboard_event_closure(name) {\n", - " return function (event) {\n", - " return fig.key_event(event, name);\n", - " };\n", - " }\n", - "\n", - " canvas_div.addEventListener(\n", - " 'keydown',\n", - " on_keyboard_event_closure('key_press')\n", - " );\n", - " canvas_div.addEventListener(\n", - " 'keyup',\n", - " on_keyboard_event_closure('key_release')\n", - " );\n", - "\n", - " this._canvas_extra_style(canvas_div);\n", - " this.root.appendChild(canvas_div);\n", - "\n", - " var canvas = (this.canvas = document.createElement('canvas'));\n", - " canvas.classList.add('mpl-canvas');\n", - " canvas.setAttribute(\n", - " 'style',\n", - " 'box-sizing: content-box;' +\n", - " 'pointer-events: none;' +\n", - " 'position: relative;' +\n", - " 'z-index: 0;'\n", - " );\n", - "\n", - " this.context = canvas.getContext('2d');\n", - "\n", - " var backingStore =\n", - " this.context.backingStorePixelRatio ||\n", - " this.context.webkitBackingStorePixelRatio ||\n", - " this.context.mozBackingStorePixelRatio ||\n", - " this.context.msBackingStorePixelRatio ||\n", - " this.context.oBackingStorePixelRatio ||\n", - " this.context.backingStorePixelRatio ||\n", - " 1;\n", - "\n", - " this.ratio = (window.devicePixelRatio || 1) / backingStore;\n", - "\n", - " var rubberband_canvas = (this.rubberband_canvas = document.createElement(\n", - " 'canvas'\n", - " ));\n", - " rubberband_canvas.setAttribute(\n", - " 'style',\n", - " 'box-sizing: content-box;' +\n", - " 'left: 0;' +\n", - " 'pointer-events: none;' +\n", - " 'position: absolute;' +\n", - " 'top: 0;' +\n", - " 'z-index: 1;'\n", - " );\n", - "\n", - " // Apply a ponyfill if ResizeObserver is not implemented by browser.\n", - " if (this.ResizeObserver === undefined) {\n", - " if (window.ResizeObserver !== undefined) {\n", - " this.ResizeObserver = window.ResizeObserver;\n", - " } else {\n", - " var obs = _JSXTOOLS_RESIZE_OBSERVER({});\n", - " this.ResizeObserver = obs.ResizeObserver;\n", - " }\n", - " }\n", - "\n", - " this.resizeObserverInstance = new this.ResizeObserver(function (entries) {\n", - " // There's no need to resize if the WebSocket is not connected:\n", - " // - If it is still connecting, then we will get an initial resize from\n", - " // Python once it connects.\n", - " // - If it has disconnected, then resizing will clear the canvas and\n", - " // never get anything back to refill it, so better to not resize and\n", - " // keep something visible.\n", - " if (fig.ws.readyState != 1) {\n", - " return;\n", - " }\n", - " var nentries = entries.length;\n", - " for (var i = 0; i < nentries; i++) {\n", - " var entry = entries[i];\n", - " var width, height;\n", - " if (entry.contentBoxSize) {\n", - " if (entry.contentBoxSize instanceof Array) {\n", - " // Chrome 84 implements new version of spec.\n", - " width = entry.contentBoxSize[0].inlineSize;\n", - " height = entry.contentBoxSize[0].blockSize;\n", - " } else {\n", - " // Firefox implements old version of spec.\n", - " width = entry.contentBoxSize.inlineSize;\n", - " height = entry.contentBoxSize.blockSize;\n", - " }\n", - " } else {\n", - " // Chrome <84 implements even older version of spec.\n", - " width = entry.contentRect.width;\n", - " height = entry.contentRect.height;\n", - " }\n", - "\n", - " // Keep the size of the canvas and rubber band canvas in sync with\n", - " // the canvas container.\n", - " if (entry.devicePixelContentBoxSize) {\n", - " // Chrome 84 implements new version of spec.\n", - " canvas.setAttribute(\n", - " 'width',\n", - " entry.devicePixelContentBoxSize[0].inlineSize\n", - " );\n", - " canvas.setAttribute(\n", - " 'height',\n", - " entry.devicePixelContentBoxSize[0].blockSize\n", - " );\n", - " } else {\n", - " canvas.setAttribute('width', width * fig.ratio);\n", - " canvas.setAttribute('height', height * fig.ratio);\n", - " }\n", - " /* This rescales the canvas back to display pixels, so that it\n", - " * appears correct on HiDPI screens. */\n", - " canvas.style.width = width + 'px';\n", - " canvas.style.height = height + 'px';\n", - "\n", - " rubberband_canvas.setAttribute('width', width);\n", - " rubberband_canvas.setAttribute('height', height);\n", - "\n", - " // And update the size in Python. We ignore the initial 0/0 size\n", - " // that occurs as the element is placed into the DOM, which should\n", - " // otherwise not happen due to the minimum size styling.\n", - " if (width != 0 && height != 0) {\n", - " fig.request_resize(width, height);\n", - " }\n", - " }\n", - " });\n", - " this.resizeObserverInstance.observe(canvas_div);\n", - "\n", - " function on_mouse_event_closure(name) {\n", - " /* User Agent sniffing is bad, but WebKit is busted:\n", - " * https://bugs.webkit.org/show_bug.cgi?id=144526\n", - " * https://bugs.webkit.org/show_bug.cgi?id=181818\n", - " * The worst that happens here is that they get an extra browser\n", - " * selection when dragging, if this check fails to catch them.\n", - " */\n", - " var UA = navigator.userAgent;\n", - " var isWebKit = /AppleWebKit/.test(UA) && !/Chrome/.test(UA);\n", - " if(isWebKit) {\n", - " return function (event) {\n", - " /* This prevents the web browser from automatically changing to\n", - " * the text insertion cursor when the button is pressed. We\n", - " * want to control all of the cursor setting manually through\n", - " * the 'cursor' event from matplotlib */\n", - " event.preventDefault()\n", - " return fig.mouse_event(event, name);\n", - " };\n", - " } else {\n", - " return function (event) {\n", - " return fig.mouse_event(event, name);\n", - " };\n", - " }\n", - " }\n", - "\n", - " canvas_div.addEventListener(\n", - " 'mousedown',\n", - " on_mouse_event_closure('button_press')\n", - " );\n", - " canvas_div.addEventListener(\n", - " 'mouseup',\n", - " on_mouse_event_closure('button_release')\n", - " );\n", - " canvas_div.addEventListener(\n", - " 'dblclick',\n", - " on_mouse_event_closure('dblclick')\n", - " );\n", - " // Throttle sequential mouse events to 1 every 20ms.\n", - " canvas_div.addEventListener(\n", - " 'mousemove',\n", - " on_mouse_event_closure('motion_notify')\n", - " );\n", - "\n", - " canvas_div.addEventListener(\n", - " 'mouseenter',\n", - " on_mouse_event_closure('figure_enter')\n", - " );\n", - " canvas_div.addEventListener(\n", - " 'mouseleave',\n", - " on_mouse_event_closure('figure_leave')\n", - " );\n", - "\n", - " canvas_div.addEventListener('wheel', function (event) {\n", - " if (event.deltaY < 0) {\n", - " event.step = 1;\n", - " } else {\n", - " event.step = -1;\n", - " }\n", - " on_mouse_event_closure('scroll')(event);\n", - " });\n", - "\n", - " canvas_div.appendChild(canvas);\n", - " canvas_div.appendChild(rubberband_canvas);\n", - "\n", - " this.rubberband_context = rubberband_canvas.getContext('2d');\n", - " this.rubberband_context.strokeStyle = '#000000';\n", - "\n", - " this._resize_canvas = function (width, height, forward) {\n", - " if (forward) {\n", - " canvas_div.style.width = width + 'px';\n", - " canvas_div.style.height = height + 'px';\n", - " }\n", - " };\n", - "\n", - " // Disable right mouse context menu.\n", - " canvas_div.addEventListener('contextmenu', function (_e) {\n", - " event.preventDefault();\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 toolbar = document.createElement('div');\n", - " toolbar.classList = 'mpl-toolbar';\n", - " this.root.appendChild(toolbar);\n", - "\n", - " function on_click_closure(name) {\n", - " return function (_event) {\n", - " return fig.toolbar_button_onclick(name);\n", - " };\n", - " }\n", - "\n", - " function on_mouseover_closure(tooltip) {\n", - " return function (event) {\n", - " if (!event.currentTarget.disabled) {\n", - " return fig.toolbar_button_onmouseover(tooltip);\n", - " }\n", - " };\n", - " }\n", - "\n", - " fig.buttons = {};\n", - " var buttonGroup = document.createElement('div');\n", - " buttonGroup.classList = 'mpl-button-group';\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", - " /* Instead of a spacer, we start a new button group. */\n", - " if (buttonGroup.hasChildNodes()) {\n", - " toolbar.appendChild(buttonGroup);\n", - " }\n", - " buttonGroup = document.createElement('div');\n", - " buttonGroup.classList = 'mpl-button-group';\n", - " continue;\n", - " }\n", - "\n", - " var button = (fig.buttons[name] = document.createElement('button'));\n", - " button.classList = 'mpl-widget';\n", - " button.setAttribute('role', 'button');\n", - " button.setAttribute('aria-disabled', 'false');\n", - " button.addEventListener('click', on_click_closure(method_name));\n", - " button.addEventListener('mouseover', on_mouseover_closure(tooltip));\n", - "\n", - " var icon_img = document.createElement('img');\n", - " icon_img.src = '_images/' + image + '.png';\n", - " icon_img.srcset = '_images/' + image + '_large.png 2x';\n", - " icon_img.alt = tooltip;\n", - " button.appendChild(icon_img);\n", - "\n", - " buttonGroup.appendChild(button);\n", - " }\n", - "\n", - " if (buttonGroup.hasChildNodes()) {\n", - " toolbar.appendChild(buttonGroup);\n", - " }\n", - "\n", - " var fmt_picker = document.createElement('select');\n", - " fmt_picker.classList = 'mpl-widget';\n", - " toolbar.appendChild(fmt_picker);\n", - " this.format_dropdown = fmt_picker;\n", - "\n", - " for (var ind in mpl.extensions) {\n", - " var fmt = mpl.extensions[ind];\n", - " var option = document.createElement('option');\n", - " option.selected = fmt === mpl.default_extension;\n", - " option.innerHTML = fmt;\n", - " fmt_picker.appendChild(option);\n", - " }\n", - "\n", - " var status_bar = document.createElement('span');\n", - " status_bar.classList = 'mpl-message';\n", - " toolbar.appendChild(status_bar);\n", - " this.message = status_bar;\n", - "};\n", - "\n", - "mpl.figure.prototype.request_resize = function (x_pixels, y_pixels) {\n", - " // Request matplotlib to resize the figure. Matplotlib will then trigger a resize in the client,\n", - " // which will in turn request a refresh of the image.\n", - " this.send_message('resize', { width: x_pixels, height: y_pixels });\n", - "};\n", - "\n", - "mpl.figure.prototype.send_message = function (type, properties) {\n", - " properties['type'] = type;\n", - " properties['figure_id'] = this.id;\n", - " this.ws.send(JSON.stringify(properties));\n", - "};\n", - "\n", - "mpl.figure.prototype.send_draw_message = function () {\n", - " if (!this.waiting) {\n", - " this.waiting = true;\n", - " this.ws.send(JSON.stringify({ type: 'draw', figure_id: this.id }));\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_save = function (fig, _msg) {\n", - " var format_dropdown = fig.format_dropdown;\n", - " var format = format_dropdown.options[format_dropdown.selectedIndex].value;\n", - " fig.ondownload(fig, format);\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_resize = function (fig, msg) {\n", - " var size = msg['size'];\n", - " if (size[0] !== fig.canvas.width || size[1] !== fig.canvas.height) {\n", - " fig._resize_canvas(size[0], size[1], msg['forward']);\n", - " fig.send_message('refresh', {});\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_rubberband = function (fig, msg) {\n", - " var x0 = msg['x0'] / fig.ratio;\n", - " var y0 = (fig.canvas.height - msg['y0']) / fig.ratio;\n", - " var x1 = msg['x1'] / fig.ratio;\n", - " var y1 = (fig.canvas.height - msg['y1']) / fig.ratio;\n", - " x0 = Math.floor(x0) + 0.5;\n", - " y0 = Math.floor(y0) + 0.5;\n", - " x1 = Math.floor(x1) + 0.5;\n", - " y1 = Math.floor(y1) + 0.5;\n", - " var min_x = Math.min(x0, x1);\n", - " var min_y = Math.min(y0, y1);\n", - " var width = Math.abs(x1 - x0);\n", - " var height = Math.abs(y1 - y0);\n", - "\n", - " fig.rubberband_context.clearRect(\n", - " 0,\n", - " 0,\n", - " fig.canvas.width / fig.ratio,\n", - " fig.canvas.height / fig.ratio\n", - " );\n", - "\n", - " fig.rubberband_context.strokeRect(min_x, min_y, width, height);\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_figure_label = function (fig, msg) {\n", - " // Updates the figure title.\n", - " fig.header.textContent = msg['label'];\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_cursor = function (fig, msg) {\n", - " fig.canvas_div.style.cursor = msg['cursor'];\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_message = function (fig, msg) {\n", - " fig.message.textContent = msg['message'];\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_draw = function (fig, _msg) {\n", - " // Request the server to send over a new figure.\n", - " fig.send_draw_message();\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_image_mode = function (fig, msg) {\n", - " fig.image_mode = msg['mode'];\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_history_buttons = function (fig, msg) {\n", - " for (var key in msg) {\n", - " if (!(key in fig.buttons)) {\n", - " continue;\n", - " }\n", - " fig.buttons[key].disabled = !msg[key];\n", - " fig.buttons[key].setAttribute('aria-disabled', !msg[key]);\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_navigate_mode = function (fig, msg) {\n", - " if (msg['mode'] === 'PAN') {\n", - " fig.buttons['Pan'].classList.add('active');\n", - " fig.buttons['Zoom'].classList.remove('active');\n", - " } else if (msg['mode'] === 'ZOOM') {\n", - " fig.buttons['Pan'].classList.remove('active');\n", - " fig.buttons['Zoom'].classList.add('active');\n", - " } else {\n", - " fig.buttons['Pan'].classList.remove('active');\n", - " fig.buttons['Zoom'].classList.remove('active');\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.updated_canvas_event = function () {\n", - " // Called whenever the canvas gets updated.\n", - " this.send_message('ack', {});\n", - "};\n", - "\n", - "// A function to construct a web socket function for onmessage handling.\n", - "// Called in the figure constructor.\n", - "mpl.figure.prototype._make_on_message_function = function (fig) {\n", - " return function socket_on_message(evt) {\n", - " if (evt.data instanceof Blob) {\n", - " var img = evt.data;\n", - " if (img.type !== 'image/png') {\n", - " /* FIXME: We get \"Resource interpreted as Image but\n", - " * transferred with MIME type text/plain:\" errors on\n", - " * Chrome. But how to set the MIME type? It doesn't seem\n", - " * to be part of the websocket stream */\n", - " img.type = 'image/png';\n", - " }\n", - "\n", - " /* Free the memory for the previous frames */\n", - " if (fig.imageObj.src) {\n", - " (window.URL || window.webkitURL).revokeObjectURL(\n", - " fig.imageObj.src\n", - " );\n", - " }\n", - "\n", - " fig.imageObj.src = (window.URL || window.webkitURL).createObjectURL(\n", - " img\n", - " );\n", - " fig.updated_canvas_event();\n", - " fig.waiting = false;\n", - " return;\n", - " } else if (\n", - " typeof evt.data === 'string' &&\n", - " evt.data.slice(0, 21) === 'data:image/png;base64'\n", - " ) {\n", - " fig.imageObj.src = evt.data;\n", - " fig.updated_canvas_event();\n", - " fig.waiting = false;\n", - " return;\n", - " }\n", - "\n", - " var msg = JSON.parse(evt.data);\n", - " var msg_type = msg['type'];\n", - "\n", - " // Call the \"handle_{type}\" callback, which takes\n", - " // the figure and JSON message as its only arguments.\n", - " try {\n", - " var callback = fig['handle_' + msg_type];\n", - " } catch (e) {\n", - " console.log(\n", - " \"No handler for the '\" + msg_type + \"' message type: \",\n", - " msg\n", - " );\n", - " return;\n", - " }\n", - "\n", - " if (callback) {\n", - " try {\n", - " // console.log(\"Handling '\" + msg_type + \"' message: \", msg);\n", - " callback(fig, msg);\n", - " } catch (e) {\n", - " console.log(\n", - " \"Exception inside the 'handler_\" + msg_type + \"' callback:\",\n", - " e,\n", - " e.stack,\n", - " msg\n", - " );\n", - " }\n", - " }\n", - " };\n", - "};\n", - "\n", - "function getModifiers(event) {\n", - " var mods = [];\n", - " if (event.ctrlKey) {\n", - " mods.push('ctrl');\n", - " }\n", - " if (event.altKey) {\n", - " mods.push('alt');\n", - " }\n", - " if (event.shiftKey) {\n", - " mods.push('shift');\n", - " }\n", - " if (event.metaKey) {\n", - " mods.push('meta');\n", - " }\n", - " return mods;\n", - "}\n", - "\n", - "/*\n", - " * return a copy of an object with only non-object keys\n", - " * we need this to avoid circular references\n", - " * https://stackoverflow.com/a/24161582/3208463\n", - " */\n", - "function simpleKeys(original) {\n", - " return Object.keys(original).reduce(function (obj, key) {\n", - " if (typeof original[key] !== 'object') {\n", - " obj[key] = original[key];\n", - " }\n", - " return obj;\n", - " }, {});\n", - "}\n", - "\n", - "mpl.figure.prototype.mouse_event = function (event, name) {\n", - " if (name === 'button_press') {\n", - " this.canvas.focus();\n", - " this.canvas_div.focus();\n", - " }\n", - "\n", - " // from https://stackoverflow.com/q/1114465\n", - " var boundingRect = this.canvas.getBoundingClientRect();\n", - " var x = (event.clientX - boundingRect.left) * this.ratio;\n", - " var y = (event.clientY - boundingRect.top) * this.ratio;\n", - "\n", - " this.send_message(name, {\n", - " x: x,\n", - " y: y,\n", - " button: event.button,\n", - " step: event.step,\n", - " modifiers: getModifiers(event),\n", - " guiEvent: simpleKeys(event),\n", - " });\n", - "\n", - " return false;\n", - "};\n", - "\n", - "mpl.figure.prototype._key_event_extra = function (_event, _name) {\n", - " // Handle any extra behaviour associated with a key event\n", - "};\n", - "\n", - "mpl.figure.prototype.key_event = function (event, name) {\n", - " // Prevent repeat events\n", - " if (name === 'key_press') {\n", - " if (event.key === this._key) {\n", - " return;\n", - " } else {\n", - " this._key = event.key;\n", - " }\n", - " }\n", - " if (name === 'key_release') {\n", - " this._key = null;\n", - " }\n", - "\n", - " var value = '';\n", - " if (event.ctrlKey && event.key !== 'Control') {\n", - " value += 'ctrl+';\n", - " }\n", - " else if (event.altKey && event.key !== 'Alt') {\n", - " value += 'alt+';\n", - " }\n", - " else if (event.shiftKey && event.key !== 'Shift') {\n", - " value += 'shift+';\n", - " }\n", - "\n", - " value += 'k' + event.key;\n", - "\n", - " this._key_event_extra(event, name);\n", - "\n", - " this.send_message(name, { key: value, guiEvent: simpleKeys(event) });\n", - " return false;\n", - "};\n", - "\n", - "mpl.figure.prototype.toolbar_button_onclick = function (name) {\n", - " if (name === 'download') {\n", - " this.handle_save(this, null);\n", - " } else {\n", - " this.send_message('toolbar_button', { name: name });\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.toolbar_button_onmouseover = function (tooltip) {\n", - " this.message.textContent = tooltip;\n", - "};\n", - "\n", - "///////////////// REMAINING CONTENT GENERATED BY embed_js.py /////////////////\n", - "// prettier-ignore\n", - "var _JSXTOOLS_RESIZE_OBSERVER=function(A){var t,i=new WeakMap,n=new WeakMap,a=new WeakMap,r=new WeakMap,o=new Set;function s(e){if(!(this instanceof s))throw new TypeError(\"Constructor requires 'new' operator\");i.set(this,e)}function h(){throw new TypeError(\"Function is not a constructor\")}function c(e,t,i,n){e=0 in arguments?Number(arguments[0]):0,t=1 in arguments?Number(arguments[1]):0,i=2 in arguments?Number(arguments[2]):0,n=3 in arguments?Number(arguments[3]):0,this.right=(this.x=this.left=e)+(this.width=i),this.bottom=(this.y=this.top=t)+(this.height=n),Object.freeze(this)}function d(){t=requestAnimationFrame(d);var s=new WeakMap,p=new Set;o.forEach((function(t){r.get(t).forEach((function(i){var r=t instanceof window.SVGElement,o=a.get(t),d=r?0:parseFloat(o.paddingTop),f=r?0:parseFloat(o.paddingRight),l=r?0:parseFloat(o.paddingBottom),u=r?0:parseFloat(o.paddingLeft),g=r?0:parseFloat(o.borderTopWidth),m=r?0:parseFloat(o.borderRightWidth),w=r?0:parseFloat(o.borderBottomWidth),b=u+f,F=d+l,v=(r?0:parseFloat(o.borderLeftWidth))+m,W=g+w,y=r?0:t.offsetHeight-W-t.clientHeight,E=r?0:t.offsetWidth-v-t.clientWidth,R=b+v,z=F+W,M=r?t.width:parseFloat(o.width)-R-E,O=r?t.height:parseFloat(o.height)-z-y;if(n.has(t)){var k=n.get(t);if(k[0]===M&&k[1]===O)return}n.set(t,[M,O]);var S=Object.create(h.prototype);S.target=t,S.contentRect=new c(u,d,M,O),s.has(i)||(s.set(i,[]),p.add(i)),s.get(i).push(S)}))})),p.forEach((function(e){i.get(e).call(e,s.get(e),e)}))}return s.prototype.observe=function(i){if(i instanceof window.Element){r.has(i)||(r.set(i,new Set),o.add(i),a.set(i,window.getComputedStyle(i)));var n=r.get(i);n.has(this)||n.add(this),cancelAnimationFrame(t),t=requestAnimationFrame(d)}},s.prototype.unobserve=function(i){if(i instanceof window.Element&&r.has(i)){var n=r.get(i);n.has(this)&&(n.delete(this),n.size||(r.delete(i),o.delete(i))),n.size||r.delete(i),o.size||cancelAnimationFrame(t)}},A.DOMRectReadOnly=c,A.ResizeObserver=s,A.ResizeObserverEntry=h,A}; // eslint-disable-line\n", - "mpl.toolbar_items = [[\"Home\", \"Reset original view\", \"fa fa-home\", \"home\"], [\"Back\", \"Back to previous view\", \"fa fa-arrow-left\", \"back\"], [\"Forward\", \"Forward to next view\", \"fa fa-arrow-right\", \"forward\"], [\"\", \"\", \"\", \"\"], [\"Pan\", \"Left button pans, Right button zooms\\nx/y fixes axis, CTRL fixes aspect\", \"fa fa-arrows\", \"pan\"], [\"Zoom\", \"Zoom to rectangle\\nx/y fixes axis\", \"fa fa-square-o\", \"zoom\"], [\"\", \"\", \"\", \"\"], [\"Download\", \"Download plot\", \"fa fa-floppy-o\", \"download\"]];\n", - "\n", - "mpl.extensions = [\"eps\", \"jpeg\", \"pgf\", \"pdf\", \"png\", \"ps\", \"raw\", \"svg\", \"tif\", \"webp\"];\n", - "\n", - "mpl.default_extension = \"png\";/* global mpl */\n", - "\n", - "var comm_websocket_adapter = function (comm) {\n", - " // Create a \"websocket\"-like object which calls the given IPython comm\n", - " // object with the appropriate methods. Currently this is a non binary\n", - " // socket, so there is still some room for performance tuning.\n", - " var ws = {};\n", - "\n", - " ws.binaryType = comm.kernel.ws.binaryType;\n", - " ws.readyState = comm.kernel.ws.readyState;\n", - " function updateReadyState(_event) {\n", - " if (comm.kernel.ws) {\n", - " ws.readyState = comm.kernel.ws.readyState;\n", - " } else {\n", - " ws.readyState = 3; // Closed state.\n", - " }\n", - " }\n", - " comm.kernel.ws.addEventListener('open', updateReadyState);\n", - " comm.kernel.ws.addEventListener('close', updateReadyState);\n", - " comm.kernel.ws.addEventListener('error', updateReadyState);\n", - "\n", - " ws.close = function () {\n", - " comm.close();\n", - " };\n", - " ws.send = function (m) {\n", - " //console.log('sending', m);\n", - " comm.send(m);\n", - " };\n", - " // Register the callback with on_msg.\n", - " comm.on_msg(function (msg) {\n", - " //console.log('receiving', msg['content']['data'], msg);\n", - " var data = msg['content']['data'];\n", - " if (data['blob'] !== undefined) {\n", - " data = {\n", - " data: new Blob(msg['buffers'], { type: data['blob'] }),\n", - " };\n", - " }\n", - " // Pass the mpl event to the overridden (by mpl) onmessage function.\n", - " ws.onmessage(data);\n", - " });\n", - " return ws;\n", - "};\n", - "\n", - "mpl.mpl_figure_comm = function (comm, msg) {\n", - " // This is the function which gets called when the mpl process\n", - " // starts-up an IPython Comm through the \"matplotlib\" channel.\n", - "\n", - " var id = msg.content.data.id;\n", - " // Get hold of the div created by the display call when the Comm\n", - " // socket was opened in Python.\n", - " var element = document.getElementById(id);\n", - " var ws_proxy = comm_websocket_adapter(comm);\n", - "\n", - " function ondownload(figure, _format) {\n", - " window.open(figure.canvas.toDataURL());\n", - " }\n", - "\n", - " var fig = new mpl.figure(id, ws_proxy, ondownload, element);\n", - "\n", - " // Call onopen now - mpl needs it, as it is assuming we've passed it a real\n", - " // web socket which is closed, not our websocket->open comm proxy.\n", - " ws_proxy.onopen();\n", - "\n", - " fig.parent_element = element;\n", - " fig.cell_info = mpl.find_output_cell(\"
\");\n", - " if (!fig.cell_info) {\n", - " console.error('Failed to find cell for figure', id, fig);\n", - " return;\n", - " }\n", - " fig.cell_info[0].output_area.element.on(\n", - " 'cleared',\n", - " { fig: fig },\n", - " fig._remove_fig_handler\n", - " );\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_close = function (fig, msg) {\n", - " var width = fig.canvas.width / fig.ratio;\n", - " fig.cell_info[0].output_area.element.off(\n", - " 'cleared',\n", - " fig._remove_fig_handler\n", - " );\n", - " fig.resizeObserverInstance.unobserve(fig.canvas_div);\n", - "\n", - " // Update the output cell to use the data from the current canvas.\n", - " fig.push_to_output();\n", - " var dataURL = fig.canvas.toDataURL();\n", - " // Re-enable the keyboard manager in IPython - without this line, in FF,\n", - " // the notebook keyboard shortcuts fail.\n", - " IPython.keyboard_manager.enable();\n", - " fig.parent_element.innerHTML =\n", - " '';\n", - " fig.close_ws(fig, msg);\n", - "};\n", - "\n", - "mpl.figure.prototype.close_ws = function (fig, msg) {\n", - " fig.send_message('closing', msg);\n", - " // fig.ws.close()\n", - "};\n", - "\n", - "mpl.figure.prototype.push_to_output = function (_remove_interactive) {\n", - " // Turn the data on the canvas into data in the output cell.\n", - " var width = this.canvas.width / this.ratio;\n", - " var dataURL = this.canvas.toDataURL();\n", - " this.cell_info[1]['text/html'] =\n", - " '';\n", - "};\n", - "\n", - "mpl.figure.prototype.updated_canvas_event = function () {\n", - " // Tell IPython that the notebook contents must change.\n", - " IPython.notebook.set_dirty(true);\n", - " this.send_message('ack', {});\n", - " var fig = this;\n", - " // Wait a second, then push the new image to the DOM so\n", - " // that it is saved nicely (might be nice to debounce this).\n", - " setTimeout(function () {\n", - " fig.push_to_output();\n", - " }, 1000);\n", - "};\n", - "\n", - "mpl.figure.prototype._init_toolbar = function () {\n", - " var fig = this;\n", - "\n", - " var toolbar = document.createElement('div');\n", - " toolbar.classList = 'btn-toolbar';\n", - " this.root.appendChild(toolbar);\n", - "\n", - " function on_click_closure(name) {\n", - " return function (_event) {\n", - " return fig.toolbar_button_onclick(name);\n", - " };\n", - " }\n", - "\n", - " function on_mouseover_closure(tooltip) {\n", - " return function (event) {\n", - " if (!event.currentTarget.disabled) {\n", - " return fig.toolbar_button_onmouseover(tooltip);\n", - " }\n", - " };\n", - " }\n", - "\n", - " fig.buttons = {};\n", - " var buttonGroup = document.createElement('div');\n", - " buttonGroup.classList = 'btn-group';\n", - " var button;\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", - " /* Instead of a spacer, we start a new button group. */\n", - " if (buttonGroup.hasChildNodes()) {\n", - " toolbar.appendChild(buttonGroup);\n", - " }\n", - " buttonGroup = document.createElement('div');\n", - " buttonGroup.classList = 'btn-group';\n", - " continue;\n", - " }\n", - "\n", - " button = fig.buttons[name] = document.createElement('button');\n", - " button.classList = 'btn btn-default';\n", - " button.href = '#';\n", - " button.title = name;\n", - " button.innerHTML = '';\n", - " button.addEventListener('click', on_click_closure(method_name));\n", - " button.addEventListener('mouseover', on_mouseover_closure(tooltip));\n", - " buttonGroup.appendChild(button);\n", - " }\n", - "\n", - " if (buttonGroup.hasChildNodes()) {\n", - " toolbar.appendChild(buttonGroup);\n", - " }\n", - "\n", - " // Add the status bar.\n", - " var status_bar = document.createElement('span');\n", - " status_bar.classList = 'mpl-message pull-right';\n", - " toolbar.appendChild(status_bar);\n", - " this.message = status_bar;\n", - "\n", - " // Add the close button to the window.\n", - " var buttongrp = document.createElement('div');\n", - " buttongrp.classList = 'btn-group inline pull-right';\n", - " button = document.createElement('button');\n", - " button.classList = 'btn btn-mini btn-primary';\n", - " button.href = '#';\n", - " button.title = 'Stop Interaction';\n", - " button.innerHTML = '';\n", - " button.addEventListener('click', function (_evt) {\n", - " fig.handle_close(fig, {});\n", - " });\n", - " button.addEventListener(\n", - " 'mouseover',\n", - " on_mouseover_closure('Stop Interaction')\n", - " );\n", - " buttongrp.appendChild(button);\n", - " var titlebar = this.root.querySelector('.ui-dialog-titlebar');\n", - " titlebar.insertBefore(buttongrp, titlebar.firstChild);\n", - "};\n", - "\n", - "mpl.figure.prototype._remove_fig_handler = function (event) {\n", - " var fig = event.data.fig;\n", - " if (event.target !== this) {\n", - " // Ignore bubbled events from children.\n", - " return;\n", - " }\n", - " fig.close_ws(fig, {});\n", - "};\n", - "\n", - "mpl.figure.prototype._root_extra_style = function (el) {\n", - " el.style.boxSizing = 'content-box'; // override notebook setting of border-box.\n", - "};\n", - "\n", - "mpl.figure.prototype._canvas_extra_style = function (el) {\n", - " // this is important to make the div 'focusable\n", - " el.setAttribute('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", - " } else {\n", - " // location in version 2\n", - " IPython.keyboard_manager.register_events(el);\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype._key_event_extra = function (event, _name) {\n", - " // Check for shift+enter\n", - " if (event.shiftKey && event.which === 13) {\n", - " this.canvas_div.blur();\n", - " // select the cell after this one\n", - " var index = IPython.notebook.find_cell_index(this.cell_info[0]);\n", - " IPython.notebook.select(index + 1);\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_save = function (fig, _msg) {\n", - " fig.ondownload(fig, null);\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 < ncells; i++) {\n", - " var cell = cells[i];\n", - " if (cell.cell_type === 'code') {\n", - " for (var j = 0; j < cell.output_area.outputs.length; j++) {\n", - " var data = cell.output_area.outputs[j];\n", - " if (data.data) {\n", - " // IPython >= 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(\n", - " 'matplotlib',\n", - " mpl.mpl_figure_comm\n", - " );\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", - "/* global mpl */\n", - "window.mpl = {};\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(\n", - " '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", - "\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 = document.createElement('div');\n", - " this.root.setAttribute('style', 'display: inline-block');\n", - " this._root_extra_style(this.root);\n", - "\n", - " parent_element.appendChild(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 (fig.ratio !== 1) {\n", - " fig.send_message('set_device_pixel_ratio', {\n", - " device_pixel_ratio: fig.ratio,\n", - " });\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 = document.createElement('div');\n", - " titlebar.classList =\n", - " 'ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix';\n", - " var titletext = document.createElement('div');\n", - " titletext.classList = 'ui-dialog-title';\n", - " titletext.setAttribute(\n", - " 'style',\n", - " 'width: 100%; text-align: center; padding: 3px;'\n", - " );\n", - " titlebar.appendChild(titletext);\n", - " this.root.appendChild(titlebar);\n", - " this.header = titletext;\n", - "};\n", - "\n", - "mpl.figure.prototype._canvas_extra_style = function (_canvas_div) {};\n", - "\n", - "mpl.figure.prototype._root_extra_style = function (_canvas_div) {};\n", - "\n", - "mpl.figure.prototype._init_canvas = function () {\n", - " var fig = this;\n", - "\n", - " var canvas_div = (this.canvas_div = document.createElement('div'));\n", - " canvas_div.setAttribute('tabindex', '0');\n", - " canvas_div.setAttribute(\n", - " 'style',\n", - " 'border: 1px solid #ddd;' +\n", - " 'box-sizing: content-box;' +\n", - " 'clear: both;' +\n", - " 'min-height: 1px;' +\n", - " 'min-width: 1px;' +\n", - " 'outline: 0;' +\n", - " 'overflow: hidden;' +\n", - " 'position: relative;' +\n", - " 'resize: both;' +\n", - " 'z-index: 2;'\n", - " );\n", - "\n", - " function on_keyboard_event_closure(name) {\n", - " return function (event) {\n", - " return fig.key_event(event, name);\n", - " };\n", - " }\n", - "\n", - " canvas_div.addEventListener(\n", - " 'keydown',\n", - " on_keyboard_event_closure('key_press')\n", - " );\n", - " canvas_div.addEventListener(\n", - " 'keyup',\n", - " on_keyboard_event_closure('key_release')\n", - " );\n", - "\n", - " this._canvas_extra_style(canvas_div);\n", - " this.root.appendChild(canvas_div);\n", - "\n", - " var canvas = (this.canvas = document.createElement('canvas'));\n", - " canvas.classList.add('mpl-canvas');\n", - " canvas.setAttribute(\n", - " 'style',\n", - " 'box-sizing: content-box;' +\n", - " 'pointer-events: none;' +\n", - " 'position: relative;' +\n", - " 'z-index: 0;'\n", - " );\n", - "\n", - " this.context = canvas.getContext('2d');\n", - "\n", - " var backingStore =\n", - " this.context.backingStorePixelRatio ||\n", - " this.context.webkitBackingStorePixelRatio ||\n", - " this.context.mozBackingStorePixelRatio ||\n", - " this.context.msBackingStorePixelRatio ||\n", - " this.context.oBackingStorePixelRatio ||\n", - " this.context.backingStorePixelRatio ||\n", - " 1;\n", - "\n", - " this.ratio = (window.devicePixelRatio || 1) / backingStore;\n", - "\n", - " var rubberband_canvas = (this.rubberband_canvas = document.createElement(\n", - " 'canvas'\n", - " ));\n", - " rubberband_canvas.setAttribute(\n", - " 'style',\n", - " 'box-sizing: content-box;' +\n", - " 'left: 0;' +\n", - " 'pointer-events: none;' +\n", - " 'position: absolute;' +\n", - " 'top: 0;' +\n", - " 'z-index: 1;'\n", - " );\n", - "\n", - " // Apply a ponyfill if ResizeObserver is not implemented by browser.\n", - " if (this.ResizeObserver === undefined) {\n", - " if (window.ResizeObserver !== undefined) {\n", - " this.ResizeObserver = window.ResizeObserver;\n", - " } else {\n", - " var obs = _JSXTOOLS_RESIZE_OBSERVER({});\n", - " this.ResizeObserver = obs.ResizeObserver;\n", - " }\n", - " }\n", - "\n", - " this.resizeObserverInstance = new this.ResizeObserver(function (entries) {\n", - " // There's no need to resize if the WebSocket is not connected:\n", - " // - If it is still connecting, then we will get an initial resize from\n", - " // Python once it connects.\n", - " // - If it has disconnected, then resizing will clear the canvas and\n", - " // never get anything back to refill it, so better to not resize and\n", - " // keep something visible.\n", - " if (fig.ws.readyState != 1) {\n", - " return;\n", - " }\n", - " var nentries = entries.length;\n", - " for (var i = 0; i < nentries; i++) {\n", - " var entry = entries[i];\n", - " var width, height;\n", - " if (entry.contentBoxSize) {\n", - " if (entry.contentBoxSize instanceof Array) {\n", - " // Chrome 84 implements new version of spec.\n", - " width = entry.contentBoxSize[0].inlineSize;\n", - " height = entry.contentBoxSize[0].blockSize;\n", - " } else {\n", - " // Firefox implements old version of spec.\n", - " width = entry.contentBoxSize.inlineSize;\n", - " height = entry.contentBoxSize.blockSize;\n", - " }\n", - " } else {\n", - " // Chrome <84 implements even older version of spec.\n", - " width = entry.contentRect.width;\n", - " height = entry.contentRect.height;\n", - " }\n", - "\n", - " // Keep the size of the canvas and rubber band canvas in sync with\n", - " // the canvas container.\n", - " if (entry.devicePixelContentBoxSize) {\n", - " // Chrome 84 implements new version of spec.\n", - " canvas.setAttribute(\n", - " 'width',\n", - " entry.devicePixelContentBoxSize[0].inlineSize\n", - " );\n", - " canvas.setAttribute(\n", - " 'height',\n", - " entry.devicePixelContentBoxSize[0].blockSize\n", - " );\n", - " } else {\n", - " canvas.setAttribute('width', width * fig.ratio);\n", - " canvas.setAttribute('height', height * fig.ratio);\n", - " }\n", - " /* This rescales the canvas back to display pixels, so that it\n", - " * appears correct on HiDPI screens. */\n", - " canvas.style.width = width + 'px';\n", - " canvas.style.height = height + 'px';\n", - "\n", - " rubberband_canvas.setAttribute('width', width);\n", - " rubberband_canvas.setAttribute('height', height);\n", - "\n", - " // And update the size in Python. We ignore the initial 0/0 size\n", - " // that occurs as the element is placed into the DOM, which should\n", - " // otherwise not happen due to the minimum size styling.\n", - " if (width != 0 && height != 0) {\n", - " fig.request_resize(width, height);\n", - " }\n", - " }\n", - " });\n", - " this.resizeObserverInstance.observe(canvas_div);\n", - "\n", - " function on_mouse_event_closure(name) {\n", - " /* User Agent sniffing is bad, but WebKit is busted:\n", - " * https://bugs.webkit.org/show_bug.cgi?id=144526\n", - " * https://bugs.webkit.org/show_bug.cgi?id=181818\n", - " * The worst that happens here is that they get an extra browser\n", - " * selection when dragging, if this check fails to catch them.\n", - " */\n", - " var UA = navigator.userAgent;\n", - " var isWebKit = /AppleWebKit/.test(UA) && !/Chrome/.test(UA);\n", - " if(isWebKit) {\n", - " return function (event) {\n", - " /* This prevents the web browser from automatically changing to\n", - " * the text insertion cursor when the button is pressed. We\n", - " * want to control all of the cursor setting manually through\n", - " * the 'cursor' event from matplotlib */\n", - " event.preventDefault()\n", - " return fig.mouse_event(event, name);\n", - " };\n", - " } else {\n", - " return function (event) {\n", - " return fig.mouse_event(event, name);\n", - " };\n", - " }\n", - " }\n", - "\n", - " canvas_div.addEventListener(\n", - " 'mousedown',\n", - " on_mouse_event_closure('button_press')\n", - " );\n", - " canvas_div.addEventListener(\n", - " 'mouseup',\n", - " on_mouse_event_closure('button_release')\n", - " );\n", - " canvas_div.addEventListener(\n", - " 'dblclick',\n", - " on_mouse_event_closure('dblclick')\n", - " );\n", - " // Throttle sequential mouse events to 1 every 20ms.\n", - " canvas_div.addEventListener(\n", - " 'mousemove',\n", - " on_mouse_event_closure('motion_notify')\n", - " );\n", - "\n", - " canvas_div.addEventListener(\n", - " 'mouseenter',\n", - " on_mouse_event_closure('figure_enter')\n", - " );\n", - " canvas_div.addEventListener(\n", - " 'mouseleave',\n", - " on_mouse_event_closure('figure_leave')\n", - " );\n", - "\n", - " canvas_div.addEventListener('wheel', function (event) {\n", - " if (event.deltaY < 0) {\n", - " event.step = 1;\n", - " } else {\n", - " event.step = -1;\n", - " }\n", - " on_mouse_event_closure('scroll')(event);\n", - " });\n", - "\n", - " canvas_div.appendChild(canvas);\n", - " canvas_div.appendChild(rubberband_canvas);\n", - "\n", - " this.rubberband_context = rubberband_canvas.getContext('2d');\n", - " this.rubberband_context.strokeStyle = '#000000';\n", - "\n", - " this._resize_canvas = function (width, height, forward) {\n", - " if (forward) {\n", - " canvas_div.style.width = width + 'px';\n", - " canvas_div.style.height = height + 'px';\n", - " }\n", - " };\n", - "\n", - " // Disable right mouse context menu.\n", - " canvas_div.addEventListener('contextmenu', function (_e) {\n", - " event.preventDefault();\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 toolbar = document.createElement('div');\n", - " toolbar.classList = 'mpl-toolbar';\n", - " this.root.appendChild(toolbar);\n", - "\n", - " function on_click_closure(name) {\n", - " return function (_event) {\n", - " return fig.toolbar_button_onclick(name);\n", - " };\n", - " }\n", - "\n", - " function on_mouseover_closure(tooltip) {\n", - " return function (event) {\n", - " if (!event.currentTarget.disabled) {\n", - " return fig.toolbar_button_onmouseover(tooltip);\n", - " }\n", - " };\n", - " }\n", - "\n", - " fig.buttons = {};\n", - " var buttonGroup = document.createElement('div');\n", - " buttonGroup.classList = 'mpl-button-group';\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", - " /* Instead of a spacer, we start a new button group. */\n", - " if (buttonGroup.hasChildNodes()) {\n", - " toolbar.appendChild(buttonGroup);\n", - " }\n", - " buttonGroup = document.createElement('div');\n", - " buttonGroup.classList = 'mpl-button-group';\n", - " continue;\n", - " }\n", - "\n", - " var button = (fig.buttons[name] = document.createElement('button'));\n", - " button.classList = 'mpl-widget';\n", - " button.setAttribute('role', 'button');\n", - " button.setAttribute('aria-disabled', 'false');\n", - " button.addEventListener('click', on_click_closure(method_name));\n", - " button.addEventListener('mouseover', on_mouseover_closure(tooltip));\n", - "\n", - " var icon_img = document.createElement('img');\n", - " icon_img.src = '_images/' + image + '.png';\n", - " icon_img.srcset = '_images/' + image + '_large.png 2x';\n", - " icon_img.alt = tooltip;\n", - " button.appendChild(icon_img);\n", - "\n", - " buttonGroup.appendChild(button);\n", - " }\n", - "\n", - " if (buttonGroup.hasChildNodes()) {\n", - " toolbar.appendChild(buttonGroup);\n", - " }\n", - "\n", - " var fmt_picker = document.createElement('select');\n", - " fmt_picker.classList = 'mpl-widget';\n", - " toolbar.appendChild(fmt_picker);\n", - " this.format_dropdown = fmt_picker;\n", - "\n", - " for (var ind in mpl.extensions) {\n", - " var fmt = mpl.extensions[ind];\n", - " var option = document.createElement('option');\n", - " option.selected = fmt === mpl.default_extension;\n", - " option.innerHTML = fmt;\n", - " fmt_picker.appendChild(option);\n", - " }\n", - "\n", - " var status_bar = document.createElement('span');\n", - " status_bar.classList = 'mpl-message';\n", - " toolbar.appendChild(status_bar);\n", - " this.message = status_bar;\n", - "};\n", - "\n", - "mpl.figure.prototype.request_resize = function (x_pixels, y_pixels) {\n", - " // Request matplotlib to resize the figure. Matplotlib will then trigger a resize in the client,\n", - " // which will in turn request a refresh of the image.\n", - " this.send_message('resize', { width: x_pixels, height: y_pixels });\n", - "};\n", - "\n", - "mpl.figure.prototype.send_message = function (type, properties) {\n", - " properties['type'] = type;\n", - " properties['figure_id'] = this.id;\n", - " this.ws.send(JSON.stringify(properties));\n", - "};\n", - "\n", - "mpl.figure.prototype.send_draw_message = function () {\n", - " if (!this.waiting) {\n", - " this.waiting = true;\n", - " this.ws.send(JSON.stringify({ type: 'draw', figure_id: this.id }));\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_save = function (fig, _msg) {\n", - " var format_dropdown = fig.format_dropdown;\n", - " var format = format_dropdown.options[format_dropdown.selectedIndex].value;\n", - " fig.ondownload(fig, format);\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_resize = function (fig, msg) {\n", - " var size = msg['size'];\n", - " if (size[0] !== fig.canvas.width || size[1] !== fig.canvas.height) {\n", - " fig._resize_canvas(size[0], size[1], msg['forward']);\n", - " fig.send_message('refresh', {});\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_rubberband = function (fig, msg) {\n", - " var x0 = msg['x0'] / fig.ratio;\n", - " var y0 = (fig.canvas.height - msg['y0']) / fig.ratio;\n", - " var x1 = msg['x1'] / fig.ratio;\n", - " var y1 = (fig.canvas.height - msg['y1']) / fig.ratio;\n", - " x0 = Math.floor(x0) + 0.5;\n", - " y0 = Math.floor(y0) + 0.5;\n", - " x1 = Math.floor(x1) + 0.5;\n", - " y1 = Math.floor(y1) + 0.5;\n", - " var min_x = Math.min(x0, x1);\n", - " var min_y = Math.min(y0, y1);\n", - " var width = Math.abs(x1 - x0);\n", - " var height = Math.abs(y1 - y0);\n", - "\n", - " fig.rubberband_context.clearRect(\n", - " 0,\n", - " 0,\n", - " fig.canvas.width / fig.ratio,\n", - " fig.canvas.height / fig.ratio\n", - " );\n", - "\n", - " fig.rubberband_context.strokeRect(min_x, min_y, width, height);\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_figure_label = function (fig, msg) {\n", - " // Updates the figure title.\n", - " fig.header.textContent = msg['label'];\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_cursor = function (fig, msg) {\n", - " fig.canvas_div.style.cursor = msg['cursor'];\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_message = function (fig, msg) {\n", - " fig.message.textContent = msg['message'];\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_draw = function (fig, _msg) {\n", - " // Request the server to send over a new figure.\n", - " fig.send_draw_message();\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_image_mode = function (fig, msg) {\n", - " fig.image_mode = msg['mode'];\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_history_buttons = function (fig, msg) {\n", - " for (var key in msg) {\n", - " if (!(key in fig.buttons)) {\n", - " continue;\n", - " }\n", - " fig.buttons[key].disabled = !msg[key];\n", - " fig.buttons[key].setAttribute('aria-disabled', !msg[key]);\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_navigate_mode = function (fig, msg) {\n", - " if (msg['mode'] === 'PAN') {\n", - " fig.buttons['Pan'].classList.add('active');\n", - " fig.buttons['Zoom'].classList.remove('active');\n", - " } else if (msg['mode'] === 'ZOOM') {\n", - " fig.buttons['Pan'].classList.remove('active');\n", - " fig.buttons['Zoom'].classList.add('active');\n", - " } else {\n", - " fig.buttons['Pan'].classList.remove('active');\n", - " fig.buttons['Zoom'].classList.remove('active');\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.updated_canvas_event = function () {\n", - " // Called whenever the canvas gets updated.\n", - " this.send_message('ack', {});\n", - "};\n", - "\n", - "// A function to construct a web socket function for onmessage handling.\n", - "// Called in the figure constructor.\n", - "mpl.figure.prototype._make_on_message_function = function (fig) {\n", - " return function socket_on_message(evt) {\n", - " if (evt.data instanceof Blob) {\n", - " var img = evt.data;\n", - " if (img.type !== 'image/png') {\n", - " /* FIXME: We get \"Resource interpreted as Image but\n", - " * transferred with MIME type text/plain:\" errors on\n", - " * Chrome. But how to set the MIME type? It doesn't seem\n", - " * to be part of the websocket stream */\n", - " img.type = 'image/png';\n", - " }\n", - "\n", - " /* Free the memory for the previous frames */\n", - " if (fig.imageObj.src) {\n", - " (window.URL || window.webkitURL).revokeObjectURL(\n", - " fig.imageObj.src\n", - " );\n", - " }\n", - "\n", - " fig.imageObj.src = (window.URL || window.webkitURL).createObjectURL(\n", - " img\n", - " );\n", - " fig.updated_canvas_event();\n", - " fig.waiting = false;\n", - " return;\n", - " } else if (\n", - " typeof evt.data === 'string' &&\n", - " evt.data.slice(0, 21) === 'data:image/png;base64'\n", - " ) {\n", - " fig.imageObj.src = evt.data;\n", - " fig.updated_canvas_event();\n", - " fig.waiting = false;\n", - " return;\n", - " }\n", - "\n", - " var msg = JSON.parse(evt.data);\n", - " var msg_type = msg['type'];\n", - "\n", - " // Call the \"handle_{type}\" callback, which takes\n", - " // the figure and JSON message as its only arguments.\n", - " try {\n", - " var callback = fig['handle_' + msg_type];\n", - " } catch (e) {\n", - " console.log(\n", - " \"No handler for the '\" + msg_type + \"' message type: \",\n", - " msg\n", - " );\n", - " return;\n", - " }\n", - "\n", - " if (callback) {\n", - " try {\n", - " // console.log(\"Handling '\" + msg_type + \"' message: \", msg);\n", - " callback(fig, msg);\n", - " } catch (e) {\n", - " console.log(\n", - " \"Exception inside the 'handler_\" + msg_type + \"' callback:\",\n", - " e,\n", - " e.stack,\n", - " msg\n", - " );\n", - " }\n", - " }\n", - " };\n", - "};\n", - "\n", - "function getModifiers(event) {\n", - " var mods = [];\n", - " if (event.ctrlKey) {\n", - " mods.push('ctrl');\n", - " }\n", - " if (event.altKey) {\n", - " mods.push('alt');\n", - " }\n", - " if (event.shiftKey) {\n", - " mods.push('shift');\n", - " }\n", - " if (event.metaKey) {\n", - " mods.push('meta');\n", - " }\n", - " return mods;\n", - "}\n", - "\n", - "/*\n", - " * return a copy of an object with only non-object keys\n", - " * we need this to avoid circular references\n", - " * https://stackoverflow.com/a/24161582/3208463\n", - " */\n", - "function simpleKeys(original) {\n", - " return Object.keys(original).reduce(function (obj, key) {\n", - " if (typeof original[key] !== 'object') {\n", - " obj[key] = original[key];\n", - " }\n", - " return obj;\n", - " }, {});\n", - "}\n", - "\n", - "mpl.figure.prototype.mouse_event = function (event, name) {\n", - " if (name === 'button_press') {\n", - " this.canvas.focus();\n", - " this.canvas_div.focus();\n", - " }\n", - "\n", - " // from https://stackoverflow.com/q/1114465\n", - " var boundingRect = this.canvas.getBoundingClientRect();\n", - " var x = (event.clientX - boundingRect.left) * this.ratio;\n", - " var y = (event.clientY - boundingRect.top) * this.ratio;\n", - "\n", - " this.send_message(name, {\n", - " x: x,\n", - " y: y,\n", - " button: event.button,\n", - " step: event.step,\n", - " modifiers: getModifiers(event),\n", - " guiEvent: simpleKeys(event),\n", - " });\n", - "\n", - " return false;\n", - "};\n", - "\n", - "mpl.figure.prototype._key_event_extra = function (_event, _name) {\n", - " // Handle any extra behaviour associated with a key event\n", - "};\n", - "\n", - "mpl.figure.prototype.key_event = function (event, name) {\n", - " // Prevent repeat events\n", - " if (name === 'key_press') {\n", - " if (event.key === this._key) {\n", - " return;\n", - " } else {\n", - " this._key = event.key;\n", - " }\n", - " }\n", - " if (name === 'key_release') {\n", - " this._key = null;\n", - " }\n", - "\n", - " var value = '';\n", - " if (event.ctrlKey && event.key !== 'Control') {\n", - " value += 'ctrl+';\n", - " }\n", - " else if (event.altKey && event.key !== 'Alt') {\n", - " value += 'alt+';\n", - " }\n", - " else if (event.shiftKey && event.key !== 'Shift') {\n", - " value += 'shift+';\n", - " }\n", - "\n", - " value += 'k' + event.key;\n", - "\n", - " this._key_event_extra(event, name);\n", - "\n", - " this.send_message(name, { key: value, guiEvent: simpleKeys(event) });\n", - " return false;\n", - "};\n", - "\n", - "mpl.figure.prototype.toolbar_button_onclick = function (name) {\n", - " if (name === 'download') {\n", - " this.handle_save(this, null);\n", - " } else {\n", - " this.send_message('toolbar_button', { name: name });\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.toolbar_button_onmouseover = function (tooltip) {\n", - " this.message.textContent = tooltip;\n", - "};\n", - "\n", - "///////////////// REMAINING CONTENT GENERATED BY embed_js.py /////////////////\n", - "// prettier-ignore\n", - "var _JSXTOOLS_RESIZE_OBSERVER=function(A){var t,i=new WeakMap,n=new WeakMap,a=new WeakMap,r=new WeakMap,o=new Set;function s(e){if(!(this instanceof s))throw new TypeError(\"Constructor requires 'new' operator\");i.set(this,e)}function h(){throw new TypeError(\"Function is not a constructor\")}function c(e,t,i,n){e=0 in arguments?Number(arguments[0]):0,t=1 in arguments?Number(arguments[1]):0,i=2 in arguments?Number(arguments[2]):0,n=3 in arguments?Number(arguments[3]):0,this.right=(this.x=this.left=e)+(this.width=i),this.bottom=(this.y=this.top=t)+(this.height=n),Object.freeze(this)}function d(){t=requestAnimationFrame(d);var s=new WeakMap,p=new Set;o.forEach((function(t){r.get(t).forEach((function(i){var r=t instanceof window.SVGElement,o=a.get(t),d=r?0:parseFloat(o.paddingTop),f=r?0:parseFloat(o.paddingRight),l=r?0:parseFloat(o.paddingBottom),u=r?0:parseFloat(o.paddingLeft),g=r?0:parseFloat(o.borderTopWidth),m=r?0:parseFloat(o.borderRightWidth),w=r?0:parseFloat(o.borderBottomWidth),b=u+f,F=d+l,v=(r?0:parseFloat(o.borderLeftWidth))+m,W=g+w,y=r?0:t.offsetHeight-W-t.clientHeight,E=r?0:t.offsetWidth-v-t.clientWidth,R=b+v,z=F+W,M=r?t.width:parseFloat(o.width)-R-E,O=r?t.height:parseFloat(o.height)-z-y;if(n.has(t)){var k=n.get(t);if(k[0]===M&&k[1]===O)return}n.set(t,[M,O]);var S=Object.create(h.prototype);S.target=t,S.contentRect=new c(u,d,M,O),s.has(i)||(s.set(i,[]),p.add(i)),s.get(i).push(S)}))})),p.forEach((function(e){i.get(e).call(e,s.get(e),e)}))}return s.prototype.observe=function(i){if(i instanceof window.Element){r.has(i)||(r.set(i,new Set),o.add(i),a.set(i,window.getComputedStyle(i)));var n=r.get(i);n.has(this)||n.add(this),cancelAnimationFrame(t),t=requestAnimationFrame(d)}},s.prototype.unobserve=function(i){if(i instanceof window.Element&&r.has(i)){var n=r.get(i);n.has(this)&&(n.delete(this),n.size||(r.delete(i),o.delete(i))),n.size||r.delete(i),o.size||cancelAnimationFrame(t)}},A.DOMRectReadOnly=c,A.ResizeObserver=s,A.ResizeObserverEntry=h,A}; // eslint-disable-line\n", - "mpl.toolbar_items = [[\"Home\", \"Reset original view\", \"fa fa-home\", \"home\"], [\"Back\", \"Back to previous view\", \"fa fa-arrow-left\", \"back\"], [\"Forward\", \"Forward to next view\", \"fa fa-arrow-right\", \"forward\"], [\"\", \"\", \"\", \"\"], [\"Pan\", \"Left button pans, Right button zooms\\nx/y fixes axis, CTRL fixes aspect\", \"fa fa-arrows\", \"pan\"], [\"Zoom\", \"Zoom to rectangle\\nx/y fixes axis\", \"fa fa-square-o\", \"zoom\"], [\"\", \"\", \"\", \"\"], [\"Download\", \"Download plot\", \"fa fa-floppy-o\", \"download\"]];\n", - "\n", - "mpl.extensions = [\"eps\", \"jpeg\", \"pgf\", \"pdf\", \"png\", \"ps\", \"raw\", \"svg\", \"tif\", \"webp\"];\n", - "\n", - "mpl.default_extension = \"png\";/* global mpl */\n", - "\n", - "var comm_websocket_adapter = function (comm) {\n", - " // Create a \"websocket\"-like object which calls the given IPython comm\n", - " // object with the appropriate methods. Currently this is a non binary\n", - " // socket, so there is still some room for performance tuning.\n", - " var ws = {};\n", - "\n", - " ws.binaryType = comm.kernel.ws.binaryType;\n", - " ws.readyState = comm.kernel.ws.readyState;\n", - " function updateReadyState(_event) {\n", - " if (comm.kernel.ws) {\n", - " ws.readyState = comm.kernel.ws.readyState;\n", - " } else {\n", - " ws.readyState = 3; // Closed state.\n", - " }\n", - " }\n", - " comm.kernel.ws.addEventListener('open', updateReadyState);\n", - " comm.kernel.ws.addEventListener('close', updateReadyState);\n", - " comm.kernel.ws.addEventListener('error', updateReadyState);\n", - "\n", - " ws.close = function () {\n", - " comm.close();\n", - " };\n", - " ws.send = function (m) {\n", - " //console.log('sending', m);\n", - " comm.send(m);\n", - " };\n", - " // Register the callback with on_msg.\n", - " comm.on_msg(function (msg) {\n", - " //console.log('receiving', msg['content']['data'], msg);\n", - " var data = msg['content']['data'];\n", - " if (data['blob'] !== undefined) {\n", - " data = {\n", - " data: new Blob(msg['buffers'], { type: data['blob'] }),\n", - " };\n", - " }\n", - " // Pass the mpl event to the overridden (by mpl) onmessage function.\n", - " ws.onmessage(data);\n", - " });\n", - " return ws;\n", - "};\n", - "\n", - "mpl.mpl_figure_comm = function (comm, msg) {\n", - " // This is the function which gets called when the mpl process\n", - " // starts-up an IPython Comm through the \"matplotlib\" channel.\n", - "\n", - " var id = msg.content.data.id;\n", - " // Get hold of the div created by the display call when the Comm\n", - " // socket was opened in Python.\n", - " var element = document.getElementById(id);\n", - " var ws_proxy = comm_websocket_adapter(comm);\n", - "\n", - " function ondownload(figure, _format) {\n", - " window.open(figure.canvas.toDataURL());\n", - " }\n", - "\n", - " var fig = new mpl.figure(id, ws_proxy, ondownload, element);\n", - "\n", - " // Call onopen now - mpl needs it, as it is assuming we've passed it a real\n", - " // web socket which is closed, not our websocket->open comm proxy.\n", - " ws_proxy.onopen();\n", - "\n", - " fig.parent_element = element;\n", - " fig.cell_info = mpl.find_output_cell(\"
\");\n", - " if (!fig.cell_info) {\n", - " console.error('Failed to find cell for figure', id, fig);\n", - " return;\n", - " }\n", - " fig.cell_info[0].output_area.element.on(\n", - " 'cleared',\n", - " { fig: fig },\n", - " fig._remove_fig_handler\n", - " );\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_close = function (fig, msg) {\n", - " var width = fig.canvas.width / fig.ratio;\n", - " fig.cell_info[0].output_area.element.off(\n", - " 'cleared',\n", - " fig._remove_fig_handler\n", - " );\n", - " fig.resizeObserverInstance.unobserve(fig.canvas_div);\n", - "\n", - " // Update the output cell to use the data from the current canvas.\n", - " fig.push_to_output();\n", - " var dataURL = fig.canvas.toDataURL();\n", - " // Re-enable the keyboard manager in IPython - without this line, in FF,\n", - " // the notebook keyboard shortcuts fail.\n", - " IPython.keyboard_manager.enable();\n", - " fig.parent_element.innerHTML =\n", - " '';\n", - " fig.close_ws(fig, msg);\n", - "};\n", - "\n", - "mpl.figure.prototype.close_ws = function (fig, msg) {\n", - " fig.send_message('closing', msg);\n", - " // fig.ws.close()\n", - "};\n", - "\n", - "mpl.figure.prototype.push_to_output = function (_remove_interactive) {\n", - " // Turn the data on the canvas into data in the output cell.\n", - " var width = this.canvas.width / this.ratio;\n", - " var dataURL = this.canvas.toDataURL();\n", - " this.cell_info[1]['text/html'] =\n", - " '';\n", - "};\n", - "\n", - "mpl.figure.prototype.updated_canvas_event = function () {\n", - " // Tell IPython that the notebook contents must change.\n", - " IPython.notebook.set_dirty(true);\n", - " this.send_message('ack', {});\n", - " var fig = this;\n", - " // Wait a second, then push the new image to the DOM so\n", - " // that it is saved nicely (might be nice to debounce this).\n", - " setTimeout(function () {\n", - " fig.push_to_output();\n", - " }, 1000);\n", - "};\n", - "\n", - "mpl.figure.prototype._init_toolbar = function () {\n", - " var fig = this;\n", - "\n", - " var toolbar = document.createElement('div');\n", - " toolbar.classList = 'btn-toolbar';\n", - " this.root.appendChild(toolbar);\n", - "\n", - " function on_click_closure(name) {\n", - " return function (_event) {\n", - " return fig.toolbar_button_onclick(name);\n", - " };\n", - " }\n", - "\n", - " function on_mouseover_closure(tooltip) {\n", - " return function (event) {\n", - " if (!event.currentTarget.disabled) {\n", - " return fig.toolbar_button_onmouseover(tooltip);\n", - " }\n", - " };\n", - " }\n", - "\n", - " fig.buttons = {};\n", - " var buttonGroup = document.createElement('div');\n", - " buttonGroup.classList = 'btn-group';\n", - " var button;\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", - " /* Instead of a spacer, we start a new button group. */\n", - " if (buttonGroup.hasChildNodes()) {\n", - " toolbar.appendChild(buttonGroup);\n", - " }\n", - " buttonGroup = document.createElement('div');\n", - " buttonGroup.classList = 'btn-group';\n", - " continue;\n", - " }\n", - "\n", - " button = fig.buttons[name] = document.createElement('button');\n", - " button.classList = 'btn btn-default';\n", - " button.href = '#';\n", - " button.title = name;\n", - " button.innerHTML = '';\n", - " button.addEventListener('click', on_click_closure(method_name));\n", - " button.addEventListener('mouseover', on_mouseover_closure(tooltip));\n", - " buttonGroup.appendChild(button);\n", - " }\n", - "\n", - " if (buttonGroup.hasChildNodes()) {\n", - " toolbar.appendChild(buttonGroup);\n", - " }\n", - "\n", - " // Add the status bar.\n", - " var status_bar = document.createElement('span');\n", - " status_bar.classList = 'mpl-message pull-right';\n", - " toolbar.appendChild(status_bar);\n", - " this.message = status_bar;\n", - "\n", - " // Add the close button to the window.\n", - " var buttongrp = document.createElement('div');\n", - " buttongrp.classList = 'btn-group inline pull-right';\n", - " button = document.createElement('button');\n", - " button.classList = 'btn btn-mini btn-primary';\n", - " button.href = '#';\n", - " button.title = 'Stop Interaction';\n", - " button.innerHTML = '';\n", - " button.addEventListener('click', function (_evt) {\n", - " fig.handle_close(fig, {});\n", - " });\n", - " button.addEventListener(\n", - " 'mouseover',\n", - " on_mouseover_closure('Stop Interaction')\n", - " );\n", - " buttongrp.appendChild(button);\n", - " var titlebar = this.root.querySelector('.ui-dialog-titlebar');\n", - " titlebar.insertBefore(buttongrp, titlebar.firstChild);\n", - "};\n", - "\n", - "mpl.figure.prototype._remove_fig_handler = function (event) {\n", - " var fig = event.data.fig;\n", - " if (event.target !== this) {\n", - " // Ignore bubbled events from children.\n", - " return;\n", - " }\n", - " fig.close_ws(fig, {});\n", - "};\n", - "\n", - "mpl.figure.prototype._root_extra_style = function (el) {\n", - " el.style.boxSizing = 'content-box'; // override notebook setting of border-box.\n", - "};\n", - "\n", - "mpl.figure.prototype._canvas_extra_style = function (el) {\n", - " // this is important to make the div 'focusable\n", - " el.setAttribute('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", - " } else {\n", - " // location in version 2\n", - " IPython.keyboard_manager.register_events(el);\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype._key_event_extra = function (event, _name) {\n", - " // Check for shift+enter\n", - " if (event.shiftKey && event.which === 13) {\n", - " this.canvas_div.blur();\n", - " // select the cell after this one\n", - " var index = IPython.notebook.find_cell_index(this.cell_info[0]);\n", - " IPython.notebook.select(index + 1);\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_save = function (fig, _msg) {\n", - " fig.ondownload(fig, null);\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 < ncells; i++) {\n", - " var cell = cells[i];\n", - " if (cell.cell_type === 'code') {\n", - " for (var j = 0; j < cell.output_area.outputs.length; j++) {\n", - " var data = cell.output_area.outputs[j];\n", - " if (data.data) {\n", - " // IPython >= 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(\n", - " 'matplotlib',\n", - " mpl.mpl_figure_comm\n", - " );\n", - "}\n" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/html": [ - "
" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "time_format: BJD_UTC\n", - "time_stamp: start\n", - "exp_time: 0.32\n", - "flux_format: flux\n", - "filter_name: irac4\n" - ] - } - ], - "source": [ - "###############################################################################################\n", - "##### Load data\n", - "###############################################################################################\n", - "\n", - "# This dataset contains one transit observation of WASP-39b, obtained by SPITZER/IRAC/CH4\n", - "\n", - "data = plc.open_dict('hd189733b_sst.pickle')\n", - "\n", - "###############################################################################################\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "###############################################################################################\n", - "##### Inspect data\n", - "###############################################################################################\n", - "\n", - "# The dictionaly contains the necessary keywords:\n", - "# 'time'\n", - "# 'time_format'\n", - "# 'time_stamp'\n", - "# 'exp_time'\n", - "# 'flux'\n", - "# 'flux_unc'\n", - "# 'flux_format'\n", - "# 'filter_name'\n", - "\n", - "# In addition, the dictionaly contains as auxiliary data the star position on the detector:\n", - "# 'xpix'\n", - "# 'ypix'\n", - "\n", - "plt.figure()\n", - "plt.ylabel('flux')\n", - "plt.xlabel('time')\n", - "plt.errorbar(data['time'], data['flux'], data['flux_unc'], fmt='o')\n", - "\n", - "if 'auxiliary_data' in data and data['auxiliary_data']:\n", - " print('Auxiliary data available:')\n", - " for i in data['auxiliary_data']:\n", - " plt.figure()\n", - " plt.ylabel(i)\n", - " plt.xlabel('time')\n", - " plt.plot(data['time'], data['auxiliary_data'][i])\n", - "\n", - "for i in ['time_format', 'time_stamp', 'exp_time', 'flux_format', 'filter_name']:\n", - " print('{0}: {1}'.format(i, data[i]))\n", - " \n", - "###############################################################################################\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "###############################################################################################\n", - "##### Define the trend function\n", - "###############################################################################################\n", - "\n", - "# By default, the detrending is done using a second order polynomial with time.\n", - "# For SPITZER, this trend function is not sufficient.\n", - "# Here, we will use a second order polynomial with x and y position.\n", - "\n", - "data['detrending_series'] = ['xpix', 'ypix']\n", - "data['detrending_order'] = 2\n", - "\n", - "###############################################################################################\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "###############################################################################################\n", - "##### Define the stellar model\n", - "###############################################################################################\n", - "\n", - "# The default stellar model used to calculate the limb-darkening coefficients \n", - "# is the 'Pheonix_2018'. However, there are cases where the filter used for the observation is \n", - "# outside the wavelegth region covered by these specific stellar models, like this dataset.\n", - "# Here we will use a different strellar model: \n", - "\n", - "data['stellar_model'] = 'Atlas_2000'\n", - "\n", - "###############################################################################################\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "###############################################################################################\n", - "##### Add observation to the Planet object\n", - "###############################################################################################\n", - "\n", - "# Then we are going to add the observation to the Planet object.\n", - "# It is advised to use planet.clear_observations() before, \n", - "# to avoid duplications, in case we forget that we have already added the same observation.\n", - "\n", - "planet.clear_observations()\n", - "planet.add_observation_from_dict(data)\n", - "\n", - "###############################################################################################\n", - "\n", - "\n" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "id": "72560cbb", - "metadata": { - "scrolled": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "File already here... teff05000_logg4.5_MH-0.1.pickle\n", - "File already here... teff05000_logg4.5_MH0.0.pickle\n", - "File already here... teff05000_logg5.0_MH-0.1.pickle\n", - "File already here... teff05000_logg5.0_MH0.0.pickle\n", - "File already here... teff05250_logg4.5_MH-0.1.pickle\n", - "File already here... teff05250_logg4.5_MH0.0.pickle\n", - "File already here... teff05250_logg5.0_MH-0.1.pickle\n", - "File already here... teff05250_logg5.0_MH0.0.pickle\n", - "\n", - "Observation: obs0\n", - "Filter: irac4\n", - "Epoch: -862\n", - "Data-points excluded: 0\n", - "Scaling uncertainties by: 1\n", - "\n", - "Optimising initial parameters...\n", - "Transit fitting...\n" - ] - }, - { - "data": { - "application/javascript": [ - "/* Put everything inside the global mpl namespace */\n", - "/* global mpl */\n", - "window.mpl = {};\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(\n", - " '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", - "\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 = document.createElement('div');\n", - " this.root.setAttribute('style', 'display: inline-block');\n", - " this._root_extra_style(this.root);\n", - "\n", - " parent_element.appendChild(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 (fig.ratio !== 1) {\n", - " fig.send_message('set_device_pixel_ratio', {\n", - " device_pixel_ratio: fig.ratio,\n", - " });\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 = document.createElement('div');\n", - " titlebar.classList =\n", - " 'ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix';\n", - " var titletext = document.createElement('div');\n", - " titletext.classList = 'ui-dialog-title';\n", - " titletext.setAttribute(\n", - " 'style',\n", - " 'width: 100%; text-align: center; padding: 3px;'\n", - " );\n", - " titlebar.appendChild(titletext);\n", - " this.root.appendChild(titlebar);\n", - " this.header = titletext;\n", - "};\n", - "\n", - "mpl.figure.prototype._canvas_extra_style = function (_canvas_div) {};\n", - "\n", - "mpl.figure.prototype._root_extra_style = function (_canvas_div) {};\n", - "\n", - "mpl.figure.prototype._init_canvas = function () {\n", - " var fig = this;\n", - "\n", - " var canvas_div = (this.canvas_div = document.createElement('div'));\n", - " canvas_div.setAttribute('tabindex', '0');\n", - " canvas_div.setAttribute(\n", - " 'style',\n", - " 'border: 1px solid #ddd;' +\n", - " 'box-sizing: content-box;' +\n", - " 'clear: both;' +\n", - " 'min-height: 1px;' +\n", - " 'min-width: 1px;' +\n", - " 'outline: 0;' +\n", - " 'overflow: hidden;' +\n", - " 'position: relative;' +\n", - " 'resize: both;' +\n", - " 'z-index: 2;'\n", - " );\n", - "\n", - " function on_keyboard_event_closure(name) {\n", - " return function (event) {\n", - " return fig.key_event(event, name);\n", - " };\n", - " }\n", - "\n", - " canvas_div.addEventListener(\n", - " 'keydown',\n", - " on_keyboard_event_closure('key_press')\n", - " );\n", - " canvas_div.addEventListener(\n", - " 'keyup',\n", - " on_keyboard_event_closure('key_release')\n", - " );\n", - "\n", - " this._canvas_extra_style(canvas_div);\n", - " this.root.appendChild(canvas_div);\n", - "\n", - " var canvas = (this.canvas = document.createElement('canvas'));\n", - " canvas.classList.add('mpl-canvas');\n", - " canvas.setAttribute(\n", - " 'style',\n", - " 'box-sizing: content-box;' +\n", - " 'pointer-events: none;' +\n", - " 'position: relative;' +\n", - " 'z-index: 0;'\n", - " );\n", - "\n", - " this.context = canvas.getContext('2d');\n", - "\n", - " var backingStore =\n", - " this.context.backingStorePixelRatio ||\n", - " this.context.webkitBackingStorePixelRatio ||\n", - " this.context.mozBackingStorePixelRatio ||\n", - " this.context.msBackingStorePixelRatio ||\n", - " this.context.oBackingStorePixelRatio ||\n", - " this.context.backingStorePixelRatio ||\n", - " 1;\n", - "\n", - " this.ratio = (window.devicePixelRatio || 1) / backingStore;\n", - "\n", - " var rubberband_canvas = (this.rubberband_canvas = document.createElement(\n", - " 'canvas'\n", - " ));\n", - " rubberband_canvas.setAttribute(\n", - " 'style',\n", - " 'box-sizing: content-box;' +\n", - " 'left: 0;' +\n", - " 'pointer-events: none;' +\n", - " 'position: absolute;' +\n", - " 'top: 0;' +\n", - " 'z-index: 1;'\n", - " );\n", - "\n", - " // Apply a ponyfill if ResizeObserver is not implemented by browser.\n", - " if (this.ResizeObserver === undefined) {\n", - " if (window.ResizeObserver !== undefined) {\n", - " this.ResizeObserver = window.ResizeObserver;\n", - " } else {\n", - " var obs = _JSXTOOLS_RESIZE_OBSERVER({});\n", - " this.ResizeObserver = obs.ResizeObserver;\n", - " }\n", - " }\n", - "\n", - " this.resizeObserverInstance = new this.ResizeObserver(function (entries) {\n", - " // There's no need to resize if the WebSocket is not connected:\n", - " // - If it is still connecting, then we will get an initial resize from\n", - " // Python once it connects.\n", - " // - If it has disconnected, then resizing will clear the canvas and\n", - " // never get anything back to refill it, so better to not resize and\n", - " // keep something visible.\n", - " if (fig.ws.readyState != 1) {\n", - " return;\n", - " }\n", - " var nentries = entries.length;\n", - " for (var i = 0; i < nentries; i++) {\n", - " var entry = entries[i];\n", - " var width, height;\n", - " if (entry.contentBoxSize) {\n", - " if (entry.contentBoxSize instanceof Array) {\n", - " // Chrome 84 implements new version of spec.\n", - " width = entry.contentBoxSize[0].inlineSize;\n", - " height = entry.contentBoxSize[0].blockSize;\n", - " } else {\n", - " // Firefox implements old version of spec.\n", - " width = entry.contentBoxSize.inlineSize;\n", - " height = entry.contentBoxSize.blockSize;\n", - " }\n", - " } else {\n", - " // Chrome <84 implements even older version of spec.\n", - " width = entry.contentRect.width;\n", - " height = entry.contentRect.height;\n", - " }\n", - "\n", - " // Keep the size of the canvas and rubber band canvas in sync with\n", - " // the canvas container.\n", - " if (entry.devicePixelContentBoxSize) {\n", - " // Chrome 84 implements new version of spec.\n", - " canvas.setAttribute(\n", - " 'width',\n", - " entry.devicePixelContentBoxSize[0].inlineSize\n", - " );\n", - " canvas.setAttribute(\n", - " 'height',\n", - " entry.devicePixelContentBoxSize[0].blockSize\n", - " );\n", - " } else {\n", - " canvas.setAttribute('width', width * fig.ratio);\n", - " canvas.setAttribute('height', height * fig.ratio);\n", - " }\n", - " /* This rescales the canvas back to display pixels, so that it\n", - " * appears correct on HiDPI screens. */\n", - " canvas.style.width = width + 'px';\n", - " canvas.style.height = height + 'px';\n", - "\n", - " rubberband_canvas.setAttribute('width', width);\n", - " rubberband_canvas.setAttribute('height', height);\n", - "\n", - " // And update the size in Python. We ignore the initial 0/0 size\n", - " // that occurs as the element is placed into the DOM, which should\n", - " // otherwise not happen due to the minimum size styling.\n", - " if (width != 0 && height != 0) {\n", - " fig.request_resize(width, height);\n", - " }\n", - " }\n", - " });\n", - " this.resizeObserverInstance.observe(canvas_div);\n", - "\n", - " function on_mouse_event_closure(name) {\n", - " /* User Agent sniffing is bad, but WebKit is busted:\n", - " * https://bugs.webkit.org/show_bug.cgi?id=144526\n", - " * https://bugs.webkit.org/show_bug.cgi?id=181818\n", - " * The worst that happens here is that they get an extra browser\n", - " * selection when dragging, if this check fails to catch them.\n", - " */\n", - " var UA = navigator.userAgent;\n", - " var isWebKit = /AppleWebKit/.test(UA) && !/Chrome/.test(UA);\n", - " if(isWebKit) {\n", - " return function (event) {\n", - " /* This prevents the web browser from automatically changing to\n", - " * the text insertion cursor when the button is pressed. We\n", - " * want to control all of the cursor setting manually through\n", - " * the 'cursor' event from matplotlib */\n", - " event.preventDefault()\n", - " return fig.mouse_event(event, name);\n", - " };\n", - " } else {\n", - " return function (event) {\n", - " return fig.mouse_event(event, name);\n", - " };\n", - " }\n", - " }\n", - "\n", - " canvas_div.addEventListener(\n", - " 'mousedown',\n", - " on_mouse_event_closure('button_press')\n", - " );\n", - " canvas_div.addEventListener(\n", - " 'mouseup',\n", - " on_mouse_event_closure('button_release')\n", - " );\n", - " canvas_div.addEventListener(\n", - " 'dblclick',\n", - " on_mouse_event_closure('dblclick')\n", - " );\n", - " // Throttle sequential mouse events to 1 every 20ms.\n", - " canvas_div.addEventListener(\n", - " 'mousemove',\n", - " on_mouse_event_closure('motion_notify')\n", - " );\n", - "\n", - " canvas_div.addEventListener(\n", - " 'mouseenter',\n", - " on_mouse_event_closure('figure_enter')\n", - " );\n", - " canvas_div.addEventListener(\n", - " 'mouseleave',\n", - " on_mouse_event_closure('figure_leave')\n", - " );\n", - "\n", - " canvas_div.addEventListener('wheel', function (event) {\n", - " if (event.deltaY < 0) {\n", - " event.step = 1;\n", - " } else {\n", - " event.step = -1;\n", - " }\n", - " on_mouse_event_closure('scroll')(event);\n", - " });\n", - "\n", - " canvas_div.appendChild(canvas);\n", - " canvas_div.appendChild(rubberband_canvas);\n", - "\n", - " this.rubberband_context = rubberband_canvas.getContext('2d');\n", - " this.rubberband_context.strokeStyle = '#000000';\n", - "\n", - " this._resize_canvas = function (width, height, forward) {\n", - " if (forward) {\n", - " canvas_div.style.width = width + 'px';\n", - " canvas_div.style.height = height + 'px';\n", - " }\n", - " };\n", - "\n", - " // Disable right mouse context menu.\n", - " canvas_div.addEventListener('contextmenu', function (_e) {\n", - " event.preventDefault();\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 toolbar = document.createElement('div');\n", - " toolbar.classList = 'mpl-toolbar';\n", - " this.root.appendChild(toolbar);\n", - "\n", - " function on_click_closure(name) {\n", - " return function (_event) {\n", - " return fig.toolbar_button_onclick(name);\n", - " };\n", - " }\n", - "\n", - " function on_mouseover_closure(tooltip) {\n", - " return function (event) {\n", - " if (!event.currentTarget.disabled) {\n", - " return fig.toolbar_button_onmouseover(tooltip);\n", - " }\n", - " };\n", - " }\n", - "\n", - " fig.buttons = {};\n", - " var buttonGroup = document.createElement('div');\n", - " buttonGroup.classList = 'mpl-button-group';\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", - " /* Instead of a spacer, we start a new button group. */\n", - " if (buttonGroup.hasChildNodes()) {\n", - " toolbar.appendChild(buttonGroup);\n", - " }\n", - " buttonGroup = document.createElement('div');\n", - " buttonGroup.classList = 'mpl-button-group';\n", - " continue;\n", - " }\n", - "\n", - " var button = (fig.buttons[name] = document.createElement('button'));\n", - " button.classList = 'mpl-widget';\n", - " button.setAttribute('role', 'button');\n", - " button.setAttribute('aria-disabled', 'false');\n", - " button.addEventListener('click', on_click_closure(method_name));\n", - " button.addEventListener('mouseover', on_mouseover_closure(tooltip));\n", - "\n", - " var icon_img = document.createElement('img');\n", - " icon_img.src = '_images/' + image + '.png';\n", - " icon_img.srcset = '_images/' + image + '_large.png 2x';\n", - " icon_img.alt = tooltip;\n", - " button.appendChild(icon_img);\n", - "\n", - " buttonGroup.appendChild(button);\n", - " }\n", - "\n", - " if (buttonGroup.hasChildNodes()) {\n", - " toolbar.appendChild(buttonGroup);\n", - " }\n", - "\n", - " var fmt_picker = document.createElement('select');\n", - " fmt_picker.classList = 'mpl-widget';\n", - " toolbar.appendChild(fmt_picker);\n", - " this.format_dropdown = fmt_picker;\n", - "\n", - " for (var ind in mpl.extensions) {\n", - " var fmt = mpl.extensions[ind];\n", - " var option = document.createElement('option');\n", - " option.selected = fmt === mpl.default_extension;\n", - " option.innerHTML = fmt;\n", - " fmt_picker.appendChild(option);\n", - " }\n", - "\n", - " var status_bar = document.createElement('span');\n", - " status_bar.classList = 'mpl-message';\n", - " toolbar.appendChild(status_bar);\n", - " this.message = status_bar;\n", - "};\n", - "\n", - "mpl.figure.prototype.request_resize = function (x_pixels, y_pixels) {\n", - " // Request matplotlib to resize the figure. Matplotlib will then trigger a resize in the client,\n", - " // which will in turn request a refresh of the image.\n", - " this.send_message('resize', { width: x_pixels, height: y_pixels });\n", - "};\n", - "\n", - "mpl.figure.prototype.send_message = function (type, properties) {\n", - " properties['type'] = type;\n", - " properties['figure_id'] = this.id;\n", - " this.ws.send(JSON.stringify(properties));\n", - "};\n", - "\n", - "mpl.figure.prototype.send_draw_message = function () {\n", - " if (!this.waiting) {\n", - " this.waiting = true;\n", - " this.ws.send(JSON.stringify({ type: 'draw', figure_id: this.id }));\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_save = function (fig, _msg) {\n", - " var format_dropdown = fig.format_dropdown;\n", - " var format = format_dropdown.options[format_dropdown.selectedIndex].value;\n", - " fig.ondownload(fig, format);\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_resize = function (fig, msg) {\n", - " var size = msg['size'];\n", - " if (size[0] !== fig.canvas.width || size[1] !== fig.canvas.height) {\n", - " fig._resize_canvas(size[0], size[1], msg['forward']);\n", - " fig.send_message('refresh', {});\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_rubberband = function (fig, msg) {\n", - " var x0 = msg['x0'] / fig.ratio;\n", - " var y0 = (fig.canvas.height - msg['y0']) / fig.ratio;\n", - " var x1 = msg['x1'] / fig.ratio;\n", - " var y1 = (fig.canvas.height - msg['y1']) / fig.ratio;\n", - " x0 = Math.floor(x0) + 0.5;\n", - " y0 = Math.floor(y0) + 0.5;\n", - " x1 = Math.floor(x1) + 0.5;\n", - " y1 = Math.floor(y1) + 0.5;\n", - " var min_x = Math.min(x0, x1);\n", - " var min_y = Math.min(y0, y1);\n", - " var width = Math.abs(x1 - x0);\n", - " var height = Math.abs(y1 - y0);\n", - "\n", - " fig.rubberband_context.clearRect(\n", - " 0,\n", - " 0,\n", - " fig.canvas.width / fig.ratio,\n", - " fig.canvas.height / fig.ratio\n", - " );\n", - "\n", - " fig.rubberband_context.strokeRect(min_x, min_y, width, height);\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_figure_label = function (fig, msg) {\n", - " // Updates the figure title.\n", - " fig.header.textContent = msg['label'];\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_cursor = function (fig, msg) {\n", - " fig.canvas_div.style.cursor = msg['cursor'];\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_message = function (fig, msg) {\n", - " fig.message.textContent = msg['message'];\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_draw = function (fig, _msg) {\n", - " // Request the server to send over a new figure.\n", - " fig.send_draw_message();\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_image_mode = function (fig, msg) {\n", - " fig.image_mode = msg['mode'];\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_history_buttons = function (fig, msg) {\n", - " for (var key in msg) {\n", - " if (!(key in fig.buttons)) {\n", - " continue;\n", - " }\n", - " fig.buttons[key].disabled = !msg[key];\n", - " fig.buttons[key].setAttribute('aria-disabled', !msg[key]);\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_navigate_mode = function (fig, msg) {\n", - " if (msg['mode'] === 'PAN') {\n", - " fig.buttons['Pan'].classList.add('active');\n", - " fig.buttons['Zoom'].classList.remove('active');\n", - " } else if (msg['mode'] === 'ZOOM') {\n", - " fig.buttons['Pan'].classList.remove('active');\n", - " fig.buttons['Zoom'].classList.add('active');\n", - " } else {\n", - " fig.buttons['Pan'].classList.remove('active');\n", - " fig.buttons['Zoom'].classList.remove('active');\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.updated_canvas_event = function () {\n", - " // Called whenever the canvas gets updated.\n", - " this.send_message('ack', {});\n", - "};\n", - "\n", - "// A function to construct a web socket function for onmessage handling.\n", - "// Called in the figure constructor.\n", - "mpl.figure.prototype._make_on_message_function = function (fig) {\n", - " return function socket_on_message(evt) {\n", - " if (evt.data instanceof Blob) {\n", - " var img = evt.data;\n", - " if (img.type !== 'image/png') {\n", - " /* FIXME: We get \"Resource interpreted as Image but\n", - " * transferred with MIME type text/plain:\" errors on\n", - " * Chrome. But how to set the MIME type? It doesn't seem\n", - " * to be part of the websocket stream */\n", - " img.type = 'image/png';\n", - " }\n", - "\n", - " /* Free the memory for the previous frames */\n", - " if (fig.imageObj.src) {\n", - " (window.URL || window.webkitURL).revokeObjectURL(\n", - " fig.imageObj.src\n", - " );\n", - " }\n", - "\n", - " fig.imageObj.src = (window.URL || window.webkitURL).createObjectURL(\n", - " img\n", - " );\n", - " fig.updated_canvas_event();\n", - " fig.waiting = false;\n", - " return;\n", - " } else if (\n", - " typeof evt.data === 'string' &&\n", - " evt.data.slice(0, 21) === 'data:image/png;base64'\n", - " ) {\n", - " fig.imageObj.src = evt.data;\n", - " fig.updated_canvas_event();\n", - " fig.waiting = false;\n", - " return;\n", - " }\n", - "\n", - " var msg = JSON.parse(evt.data);\n", - " var msg_type = msg['type'];\n", - "\n", - " // Call the \"handle_{type}\" callback, which takes\n", - " // the figure and JSON message as its only arguments.\n", - " try {\n", - " var callback = fig['handle_' + msg_type];\n", - " } catch (e) {\n", - " console.log(\n", - " \"No handler for the '\" + msg_type + \"' message type: \",\n", - " msg\n", - " );\n", - " return;\n", - " }\n", - "\n", - " if (callback) {\n", - " try {\n", - " // console.log(\"Handling '\" + msg_type + \"' message: \", msg);\n", - " callback(fig, msg);\n", - " } catch (e) {\n", - " console.log(\n", - " \"Exception inside the 'handler_\" + msg_type + \"' callback:\",\n", - " e,\n", - " e.stack,\n", - " msg\n", - " );\n", - " }\n", - " }\n", - " };\n", - "};\n", - "\n", - "function getModifiers(event) {\n", - " var mods = [];\n", - " if (event.ctrlKey) {\n", - " mods.push('ctrl');\n", - " }\n", - " if (event.altKey) {\n", - " mods.push('alt');\n", - " }\n", - " if (event.shiftKey) {\n", - " mods.push('shift');\n", - " }\n", - " if (event.metaKey) {\n", - " mods.push('meta');\n", - " }\n", - " return mods;\n", - "}\n", - "\n", - "/*\n", - " * return a copy of an object with only non-object keys\n", - " * we need this to avoid circular references\n", - " * https://stackoverflow.com/a/24161582/3208463\n", - " */\n", - "function simpleKeys(original) {\n", - " return Object.keys(original).reduce(function (obj, key) {\n", - " if (typeof original[key] !== 'object') {\n", - " obj[key] = original[key];\n", - " }\n", - " return obj;\n", - " }, {});\n", - "}\n", - "\n", - "mpl.figure.prototype.mouse_event = function (event, name) {\n", - " if (name === 'button_press') {\n", - " this.canvas.focus();\n", - " this.canvas_div.focus();\n", - " }\n", - "\n", - " // from https://stackoverflow.com/q/1114465\n", - " var boundingRect = this.canvas.getBoundingClientRect();\n", - " var x = (event.clientX - boundingRect.left) * this.ratio;\n", - " var y = (event.clientY - boundingRect.top) * this.ratio;\n", - "\n", - " this.send_message(name, {\n", - " x: x,\n", - " y: y,\n", - " button: event.button,\n", - " step: event.step,\n", - " modifiers: getModifiers(event),\n", - " guiEvent: simpleKeys(event),\n", - " });\n", - "\n", - " return false;\n", - "};\n", - "\n", - "mpl.figure.prototype._key_event_extra = function (_event, _name) {\n", - " // Handle any extra behaviour associated with a key event\n", - "};\n", - "\n", - "mpl.figure.prototype.key_event = function (event, name) {\n", - " // Prevent repeat events\n", - " if (name === 'key_press') {\n", - " if (event.key === this._key) {\n", - " return;\n", - " } else {\n", - " this._key = event.key;\n", - " }\n", - " }\n", - " if (name === 'key_release') {\n", - " this._key = null;\n", - " }\n", - "\n", - " var value = '';\n", - " if (event.ctrlKey && event.key !== 'Control') {\n", - " value += 'ctrl+';\n", - " }\n", - " else if (event.altKey && event.key !== 'Alt') {\n", - " value += 'alt+';\n", - " }\n", - " else if (event.shiftKey && event.key !== 'Shift') {\n", - " value += 'shift+';\n", - " }\n", - "\n", - " value += 'k' + event.key;\n", - "\n", - " this._key_event_extra(event, name);\n", - "\n", - " this.send_message(name, { key: value, guiEvent: simpleKeys(event) });\n", - " return false;\n", - "};\n", - "\n", - "mpl.figure.prototype.toolbar_button_onclick = function (name) {\n", - " if (name === 'download') {\n", - " this.handle_save(this, null);\n", - " } else {\n", - " this.send_message('toolbar_button', { name: name });\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.toolbar_button_onmouseover = function (tooltip) {\n", - " this.message.textContent = tooltip;\n", - "};\n", - "\n", - "///////////////// REMAINING CONTENT GENERATED BY embed_js.py /////////////////\n", - "// prettier-ignore\n", - "var _JSXTOOLS_RESIZE_OBSERVER=function(A){var t,i=new WeakMap,n=new WeakMap,a=new WeakMap,r=new WeakMap,o=new Set;function s(e){if(!(this instanceof s))throw new TypeError(\"Constructor requires 'new' operator\");i.set(this,e)}function h(){throw new TypeError(\"Function is not a constructor\")}function c(e,t,i,n){e=0 in arguments?Number(arguments[0]):0,t=1 in arguments?Number(arguments[1]):0,i=2 in arguments?Number(arguments[2]):0,n=3 in arguments?Number(arguments[3]):0,this.right=(this.x=this.left=e)+(this.width=i),this.bottom=(this.y=this.top=t)+(this.height=n),Object.freeze(this)}function d(){t=requestAnimationFrame(d);var s=new WeakMap,p=new Set;o.forEach((function(t){r.get(t).forEach((function(i){var r=t instanceof window.SVGElement,o=a.get(t),d=r?0:parseFloat(o.paddingTop),f=r?0:parseFloat(o.paddingRight),l=r?0:parseFloat(o.paddingBottom),u=r?0:parseFloat(o.paddingLeft),g=r?0:parseFloat(o.borderTopWidth),m=r?0:parseFloat(o.borderRightWidth),w=r?0:parseFloat(o.borderBottomWidth),b=u+f,F=d+l,v=(r?0:parseFloat(o.borderLeftWidth))+m,W=g+w,y=r?0:t.offsetHeight-W-t.clientHeight,E=r?0:t.offsetWidth-v-t.clientWidth,R=b+v,z=F+W,M=r?t.width:parseFloat(o.width)-R-E,O=r?t.height:parseFloat(o.height)-z-y;if(n.has(t)){var k=n.get(t);if(k[0]===M&&k[1]===O)return}n.set(t,[M,O]);var S=Object.create(h.prototype);S.target=t,S.contentRect=new c(u,d,M,O),s.has(i)||(s.set(i,[]),p.add(i)),s.get(i).push(S)}))})),p.forEach((function(e){i.get(e).call(e,s.get(e),e)}))}return s.prototype.observe=function(i){if(i instanceof window.Element){r.has(i)||(r.set(i,new Set),o.add(i),a.set(i,window.getComputedStyle(i)));var n=r.get(i);n.has(this)||n.add(this),cancelAnimationFrame(t),t=requestAnimationFrame(d)}},s.prototype.unobserve=function(i){if(i instanceof window.Element&&r.has(i)){var n=r.get(i);n.has(this)&&(n.delete(this),n.size||(r.delete(i),o.delete(i))),n.size||r.delete(i),o.size||cancelAnimationFrame(t)}},A.DOMRectReadOnly=c,A.ResizeObserver=s,A.ResizeObserverEntry=h,A}; // eslint-disable-line\n", - "mpl.toolbar_items = [[\"Home\", \"Reset original view\", \"fa fa-home\", \"home\"], [\"Back\", \"Back to previous view\", \"fa fa-arrow-left\", \"back\"], [\"Forward\", \"Forward to next view\", \"fa fa-arrow-right\", \"forward\"], [\"\", \"\", \"\", \"\"], [\"Pan\", \"Left button pans, Right button zooms\\nx/y fixes axis, CTRL fixes aspect\", \"fa fa-arrows\", \"pan\"], [\"Zoom\", \"Zoom to rectangle\\nx/y fixes axis\", \"fa fa-square-o\", \"zoom\"], [\"\", \"\", \"\", \"\"], [\"Download\", \"Download plot\", \"fa fa-floppy-o\", \"download\"]];\n", - "\n", - "mpl.extensions = [\"eps\", \"jpeg\", \"pgf\", \"pdf\", \"png\", \"ps\", \"raw\", \"svg\", \"tif\", \"webp\"];\n", - "\n", - "mpl.default_extension = \"png\";/* global mpl */\n", - "\n", - "var comm_websocket_adapter = function (comm) {\n", - " // Create a \"websocket\"-like object which calls the given IPython comm\n", - " // object with the appropriate methods. Currently this is a non binary\n", - " // socket, so there is still some room for performance tuning.\n", - " var ws = {};\n", - "\n", - " ws.binaryType = comm.kernel.ws.binaryType;\n", - " ws.readyState = comm.kernel.ws.readyState;\n", - " function updateReadyState(_event) {\n", - " if (comm.kernel.ws) {\n", - " ws.readyState = comm.kernel.ws.readyState;\n", - " } else {\n", - " ws.readyState = 3; // Closed state.\n", - " }\n", - " }\n", - " comm.kernel.ws.addEventListener('open', updateReadyState);\n", - " comm.kernel.ws.addEventListener('close', updateReadyState);\n", - " comm.kernel.ws.addEventListener('error', updateReadyState);\n", - "\n", - " ws.close = function () {\n", - " comm.close();\n", - " };\n", - " ws.send = function (m) {\n", - " //console.log('sending', m);\n", - " comm.send(m);\n", - " };\n", - " // Register the callback with on_msg.\n", - " comm.on_msg(function (msg) {\n", - " //console.log('receiving', msg['content']['data'], msg);\n", - " var data = msg['content']['data'];\n", - " if (data['blob'] !== undefined) {\n", - " data = {\n", - " data: new Blob(msg['buffers'], { type: data['blob'] }),\n", - " };\n", - " }\n", - " // Pass the mpl event to the overridden (by mpl) onmessage function.\n", - " ws.onmessage(data);\n", - " });\n", - " return ws;\n", - "};\n", - "\n", - "mpl.mpl_figure_comm = function (comm, msg) {\n", - " // This is the function which gets called when the mpl process\n", - " // starts-up an IPython Comm through the \"matplotlib\" channel.\n", - "\n", - " var id = msg.content.data.id;\n", - " // Get hold of the div created by the display call when the Comm\n", - " // socket was opened in Python.\n", - " var element = document.getElementById(id);\n", - " var ws_proxy = comm_websocket_adapter(comm);\n", - "\n", - " function ondownload(figure, _format) {\n", - " window.open(figure.canvas.toDataURL());\n", - " }\n", - "\n", - " var fig = new mpl.figure(id, ws_proxy, ondownload, element);\n", - "\n", - " // Call onopen now - mpl needs it, as it is assuming we've passed it a real\n", - " // web socket which is closed, not our websocket->open comm proxy.\n", - " ws_proxy.onopen();\n", - "\n", - " fig.parent_element = element;\n", - " fig.cell_info = mpl.find_output_cell(\"
\");\n", - " if (!fig.cell_info) {\n", - " console.error('Failed to find cell for figure', id, fig);\n", - " return;\n", - " }\n", - " fig.cell_info[0].output_area.element.on(\n", - " 'cleared',\n", - " { fig: fig },\n", - " fig._remove_fig_handler\n", - " );\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_close = function (fig, msg) {\n", - " var width = fig.canvas.width / fig.ratio;\n", - " fig.cell_info[0].output_area.element.off(\n", - " 'cleared',\n", - " fig._remove_fig_handler\n", - " );\n", - " fig.resizeObserverInstance.unobserve(fig.canvas_div);\n", - "\n", - " // Update the output cell to use the data from the current canvas.\n", - " fig.push_to_output();\n", - " var dataURL = fig.canvas.toDataURL();\n", - " // Re-enable the keyboard manager in IPython - without this line, in FF,\n", - " // the notebook keyboard shortcuts fail.\n", - " IPython.keyboard_manager.enable();\n", - " fig.parent_element.innerHTML =\n", - " '';\n", - " fig.close_ws(fig, msg);\n", - "};\n", - "\n", - "mpl.figure.prototype.close_ws = function (fig, msg) {\n", - " fig.send_message('closing', msg);\n", - " // fig.ws.close()\n", - "};\n", - "\n", - "mpl.figure.prototype.push_to_output = function (_remove_interactive) {\n", - " // Turn the data on the canvas into data in the output cell.\n", - " var width = this.canvas.width / this.ratio;\n", - " var dataURL = this.canvas.toDataURL();\n", - " this.cell_info[1]['text/html'] =\n", - " '';\n", - "};\n", - "\n", - "mpl.figure.prototype.updated_canvas_event = function () {\n", - " // Tell IPython that the notebook contents must change.\n", - " IPython.notebook.set_dirty(true);\n", - " this.send_message('ack', {});\n", - " var fig = this;\n", - " // Wait a second, then push the new image to the DOM so\n", - " // that it is saved nicely (might be nice to debounce this).\n", - " setTimeout(function () {\n", - " fig.push_to_output();\n", - " }, 1000);\n", - "};\n", - "\n", - "mpl.figure.prototype._init_toolbar = function () {\n", - " var fig = this;\n", - "\n", - " var toolbar = document.createElement('div');\n", - " toolbar.classList = 'btn-toolbar';\n", - " this.root.appendChild(toolbar);\n", - "\n", - " function on_click_closure(name) {\n", - " return function (_event) {\n", - " return fig.toolbar_button_onclick(name);\n", - " };\n", - " }\n", - "\n", - " function on_mouseover_closure(tooltip) {\n", - " return function (event) {\n", - " if (!event.currentTarget.disabled) {\n", - " return fig.toolbar_button_onmouseover(tooltip);\n", - " }\n", - " };\n", - " }\n", - "\n", - " fig.buttons = {};\n", - " var buttonGroup = document.createElement('div');\n", - " buttonGroup.classList = 'btn-group';\n", - " var button;\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", - " /* Instead of a spacer, we start a new button group. */\n", - " if (buttonGroup.hasChildNodes()) {\n", - " toolbar.appendChild(buttonGroup);\n", - " }\n", - " buttonGroup = document.createElement('div');\n", - " buttonGroup.classList = 'btn-group';\n", - " continue;\n", - " }\n", - "\n", - " button = fig.buttons[name] = document.createElement('button');\n", - " button.classList = 'btn btn-default';\n", - " button.href = '#';\n", - " button.title = name;\n", - " button.innerHTML = '';\n", - " button.addEventListener('click', on_click_closure(method_name));\n", - " button.addEventListener('mouseover', on_mouseover_closure(tooltip));\n", - " buttonGroup.appendChild(button);\n", - " }\n", - "\n", - " if (buttonGroup.hasChildNodes()) {\n", - " toolbar.appendChild(buttonGroup);\n", - " }\n", - "\n", - " // Add the status bar.\n", - " var status_bar = document.createElement('span');\n", - " status_bar.classList = 'mpl-message pull-right';\n", - " toolbar.appendChild(status_bar);\n", - " this.message = status_bar;\n", - "\n", - " // Add the close button to the window.\n", - " var buttongrp = document.createElement('div');\n", - " buttongrp.classList = 'btn-group inline pull-right';\n", - " button = document.createElement('button');\n", - " button.classList = 'btn btn-mini btn-primary';\n", - " button.href = '#';\n", - " button.title = 'Stop Interaction';\n", - " button.innerHTML = '';\n", - " button.addEventListener('click', function (_evt) {\n", - " fig.handle_close(fig, {});\n", - " });\n", - " button.addEventListener(\n", - " 'mouseover',\n", - " on_mouseover_closure('Stop Interaction')\n", - " );\n", - " buttongrp.appendChild(button);\n", - " var titlebar = this.root.querySelector('.ui-dialog-titlebar');\n", - " titlebar.insertBefore(buttongrp, titlebar.firstChild);\n", - "};\n", - "\n", - "mpl.figure.prototype._remove_fig_handler = function (event) {\n", - " var fig = event.data.fig;\n", - " if (event.target !== this) {\n", - " // Ignore bubbled events from children.\n", - " return;\n", - " }\n", - " fig.close_ws(fig, {});\n", - "};\n", - "\n", - "mpl.figure.prototype._root_extra_style = function (el) {\n", - " el.style.boxSizing = 'content-box'; // override notebook setting of border-box.\n", - "};\n", - "\n", - "mpl.figure.prototype._canvas_extra_style = function (el) {\n", - " // this is important to make the div 'focusable\n", - " el.setAttribute('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", - " } else {\n", - " // location in version 2\n", - " IPython.keyboard_manager.register_events(el);\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype._key_event_extra = function (event, _name) {\n", - " // Check for shift+enter\n", - " if (event.shiftKey && event.which === 13) {\n", - " this.canvas_div.blur();\n", - " // select the cell after this one\n", - " var index = IPython.notebook.find_cell_index(this.cell_info[0]);\n", - " IPython.notebook.select(index + 1);\n", - " }\n", - "};\n", - "\n", - "mpl.figure.prototype.handle_save = function (fig, _msg) {\n", - " fig.ondownload(fig, null);\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 < ncells; i++) {\n", - " var cell = cells[i];\n", - " if (cell.cell_type === 'code') {\n", - " for (var j = 0; j < cell.output_area.outputs.length; j++) {\n", - " var data = cell.output_area.outputs[j];\n", - " if (data.data) {\n", - " // IPython >= 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(\n", - " 'matplotlib',\n", - " mpl.mpl_figure_comm\n", - " );\n", - "}\n" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/html": [ - "
" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "Observation: obs0\n", - "Filter: irac4\n", - "Epoch: -862\n", - "Number of outliers removed: 0\n", - "Uncertainties scale factor: 1\n", - "Residuals statistics:\n", - "res_max_autocorr: \t 0.17432337219829974\n", - "res_max_autocorr_flag: \t True\n", - "res_shapiro: \t\t 0.9930962324142456\n", - "res_shapiro_flag: \t True\n", - "res_mean: \t\t 0.03794841466875843\n", - "res_std: \t\t 41.434208957286316\n", - "res_rms: \t\t 41.43422633522003\n", - "res_chi_sqr: \t\t 808.1586364352573\n", - "res_red_chi_sqr: \t 1.1712444006308078\n" - ] - } - ], - "source": [ - "\n", - "###############################################################################################\n", - "##### Test the performance of the trend function \n", - "###############################################################################################\n", - "\n", - "# We can test the performance of the trend function with quick fit, using: \n", - "# optimiser = 'curve_fit'.\n", - "# Here, the quality of the data is good enough to fit for the orbital parameters (sma and i):\n", - "# fit_sma_over_rs = True\n", - "# fit_inclination = True.\n", - "\n", - "test = planet.transit_fitting(\n", - " optimiser = 'curve_fit',\n", - " fit_sma_over_rs=True, \n", - " fit_inclination=True,\n", - ")\n", - "\n", - "###############################################################################################\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "###############################################################################################\n", - "##### Evaluate test results\n", - "###############################################################################################\n", - "\n", - "# To evaluate the test results we can plot the raw data, trend function, and residuals like this:\n", - "\n", - "observations = len(test['observations'])\n", - "plt.figure(figsize=(9,6))\n", - "for obs_n, obs_id in enumerate(test['observations']):\n", - " observation = test['observations'][obs_id]\n", - " plt.subplot(2, observations, obs_n + 1)\n", - " plt.errorbar(observation['input_series']['time'], \n", - " observation['input_series']['flux'], \n", - " observation['input_series']['flux_unc'], \n", - " fmt='o', zorder=0, label='raw data')\n", - " plt.plot(observation['input_series']['time'], observation['output_series']['trend'], 'r--', zorder=1, \n", - " label='trend model')\n", - " plt.plot(observation['input_series']['time'], observation['output_series']['model'], 'r-', zorder=1,\n", - " label='trend + transit model'\n", - " )\n", - " plt.legend(fontsize='small')\n", - " plt.ylabel('rel. flux')\n", - " plt.title(obs_id)\n", - "\n", - " plt.subplot(2, observations, observations + 1)\n", - " plt.errorbar(observation['input_series']['time'], \n", - " observation['output_series']['residuals'], \n", - " observation['input_series']['flux_unc'], \n", - " fmt='o', zorder=0)\n", - " plt.xlabel('time (BJD_TDB)')\n", - " plt.ylabel('rel. flux residuals')\n", - "\n", - " \n", - " \n", - "# And also print the residuals diagnostics like this:\n", - "\n", - "for obs_n, obs_id in enumerate(test['observations']):\n", - " observation = test['observations'][obs_id]\n", - " print('')\n", - " print('Observation: ', obs_id)\n", - " print('Filter: ', observation['model_info']['filter_id'])\n", - " print('Epoch: ', observation['model_info']['epoch'])\n", - " print('Number of outliers removed: ', observation['data_conversion_info']['outliers'])\n", - " print('Uncertainties scale factor: ', observation['data_conversion_info']['scale_factor'])\n", - "\n", - " print('Residuals statistics:')\n", - " print('res_max_autocorr:', '\\t', observation['statistics']['res_max_autocorr'])\n", - " print('res_max_autocorr_flag:', '\\t', observation['statistics']['res_max_autocorr_flag'])\n", - " print('res_shapiro:', '\\t\\t', observation['statistics']['res_shapiro'])\n", - " print('res_shapiro_flag:', '\\t', observation['statistics']['res_shapiro_flag'])\n", - " print('res_mean:', '\\t\\t', observation['statistics']['res_mean'])\n", - " print('res_std:', '\\t\\t', observation['statistics']['res_std'])\n", - " print('res_rms:', '\\t\\t', observation['statistics']['res_rms'])\n", - " print('res_chi_sqr:', '\\t\\t', observation['statistics']['res_chi_sqr'])\n", - " print('res_red_chi_sqr:', '\\t', observation['statistics']['res_red_chi_sqr'])\n", - " \n", - "###############################################################################################\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "0a5ae6df", - "metadata": { - "scrolled": true - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "Observation: obs0\n", - "Filter: irac4\n", - "Epoch: -862\n", - "Data-points excluded: 6\n", - "Scaling uncertainties by: 1.0303924632984718\n", - "\n", - "Optimising initial parameters...\n", - "\u001b[KTransit fitting: 1860 / 5000 , time left: 0:02:15, time elapsed: 0:01:20, total time: 0:03:36" - ] - } - ], - "source": [ - "\n", - "###############################################################################################\n", - "##### MCMC fit\n", - "###############################################################################################\n", - "\n", - "# If the residuals diagniostics look ok, we can run the MCMC.\n", - "# Here we will define the 'output_folder', so that all the results and plots are saved.\n", - "# We don't need to defile the optimiser, as the default one is 'mcmc'.\n", - "# It is also better to use filter_outliers=True to clear the outliers and \n", - "# and scale_uncertainties=True to scale the errorbars to match the residuals rms.\n", - "\n", - "final = planet.transit_fitting(\n", - " output_folder = 'hd189733b_sst',\n", - " fit_sma_over_rs=True, \n", - " fit_inclination=True,\n", - " filter_outliers=True,\n", - " scale_uncertainties=True,\n", - ")\n", - "\n", - "# By default, the number of iterations is 5000 and the burn in is 1000.\n", - "# If the chains do not converge, we can increase these number, for example by setting:\n", - "# iterations = 10000\n", - "# burn_in = 5000\n", - "\n", - "###############################################################################################\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "f2ed2921", - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "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.11.5" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/notebooks/2_detrending_examples/hd189733b_sst/global_correlations.pdf b/notebooks/2_detrending_examples/hd189733b_sst/global_correlations.pdf deleted file mode 100644 index 5262902..0000000 Binary files a/notebooks/2_detrending_examples/hd189733b_sst/global_correlations.pdf and /dev/null differ diff --git a/notebooks/2_detrending_examples/hd189733b_sst/global_results.pickle b/notebooks/2_detrending_examples/hd189733b_sst/global_results.pickle deleted file mode 100644 index 694b6df..0000000 Binary files a/notebooks/2_detrending_examples/hd189733b_sst/global_results.pickle and /dev/null differ diff --git a/notebooks/2_detrending_examples/hd189733b_sst/global_results.txt b/notebooks/2_detrending_examples/hd189733b_sst/global_results.txt deleted file mode 100644 index abb4997..0000000 --- a/notebooks/2_detrending_examples/hd189733b_sst/global_results.txt +++ /dev/null @@ -1,29 +0,0 @@ -# variable fix/fit value uncertainty initial min.allowed max.allowed -n fit 45665.0 -54.0 +56.0 45662.78210316213 41651.754523536896 48354.48053417234 -xpix_xpix fit 0.131 -0.054 +0.055 0.12902122314383657 -2.0 2.0 -xpix_ypix fit -0.008 -0.038 +0.038 -0.008931443314766918 -2.0 2.0 -xpix fit -0.012 -0.017 +0.016 -0.01102465896605187 -2.0 2.0 -ypix_ypix fit 0.062 -0.01 +0.01 0.061220965069987976 -2.0 2.0 -ypix fit -0.0574 -0.0063 +0.0063 -0.05704523210870516 -2.0 2.0 -a_1 fix 0.2816219280069006 -a_2 fix -0.11997094589598502 -a_3 fix 0.014663328340121214 -a_4 fix 0.02353282527382742 -rp_over_rs fit 0.15457 -0.0003 +0.00028 0.15457992649966637 0.015534000000000001 1.5534000000000001 -period fix 2.218574944 -sma_over_rs fit 9.058 -0.068 +0.069 9.058493374105757 0.00892 8920.0 -eccentricity fix 0.0 -inclination fit 85.877 -0.073 +0.074 85.87704154221593 10.0 90.0 -periastron fix 0.0 -mid_time fit 2454281.65585 -5.8e-05 +5.9e-05 2454281.655851555 2454281.456017272 2454281.8560172725 - -#Residuals: -#Mean: -0.4738549932111635 -#STD: 39.453996612262074 -#RMS: 39.456842083914644 -#Chi squared: 684.1453902763466 -#Reduced chi squared: 1.0150525078284074 -#Max auto-correlation: 0.18249042494786444 -#Max auto-correlation flag: True -#Shapiro test: 0.9968221187591553 -#Shapiro test flag: False \ No newline at end of file diff --git a/notebooks/2_detrending_examples/hd189733b_sst/global_traces.pdf b/notebooks/2_detrending_examples/hd189733b_sst/global_traces.pdf deleted file mode 100644 index 8a1f8ec..0000000 Binary files a/notebooks/2_detrending_examples/hd189733b_sst/global_traces.pdf and /dev/null differ diff --git a/notebooks/2_detrending_examples/hd189733b_sst/obs0_lightcurve.pdf b/notebooks/2_detrending_examples/hd189733b_sst/obs0_lightcurve.pdf deleted file mode 100644 index 534a2a4..0000000 Binary files a/notebooks/2_detrending_examples/hd189733b_sst/obs0_lightcurve.pdf and /dev/null differ diff --git a/notebooks/2_detrending_examples/hd189733b_sst/obs0_results.pickle b/notebooks/2_detrending_examples/hd189733b_sst/obs0_results.pickle deleted file mode 100644 index 1911d93..0000000 Binary files a/notebooks/2_detrending_examples/hd189733b_sst/obs0_results.pickle and /dev/null differ diff --git a/notebooks/2_detrending_examples/hd189733b_sst/obs0_results.txt b/notebooks/2_detrending_examples/hd189733b_sst/obs0_results.txt deleted file mode 100644 index 066281b..0000000 --- a/notebooks/2_detrending_examples/hd189733b_sst/obs0_results.txt +++ /dev/null @@ -1,45 +0,0 @@ -# variable fix/fit value uncertainty initial min.allowed max.allowed -n fit 45665.0 -54.0 +56.0 45662.78210316213 41651.754523536896 48354.48053417234 -xpix_xpix fit 0.131 -0.054 +0.055 0.12902122314383657 -2.0 2.0 -xpix_ypix fit -0.008 -0.038 +0.038 -0.008931443314766918 -2.0 2.0 -xpix fit -0.012 -0.017 +0.016 -0.01102465896605187 -2.0 2.0 -ypix_ypix fit 0.062 -0.01 +0.01 0.061220965069987976 -2.0 2.0 -ypix fit -0.0574 -0.0063 +0.0063 -0.05704523210870516 -2.0 2.0 -a_1 fix 0.2816219280069006 -- -- -- -- -- -a_2 fix -0.11997094589598502 -- -- -- -- -- -a_3 fix 0.014663328340121214 -- -- -- -- -- -a_4 fix 0.02353282527382742 -- -- -- -- -- -rp_over_rs fit 0.15457 -0.0003 +0.00028 0.15457992649966637 0.015534000000000001 1.5534000000000001 -period fix 2.218574944 -- -- -- -- -- -sma_over_rs fit 9.058 -0.068 +0.069 9.058493374105757 0.00892 8920.0 -eccentricity fix 0.0 -- -- -- -- -- -inclination fit 85.877 -0.073 +0.074 85.87704154221593 10.0 90.0 -periastron fix 0.0 -- -- -- -- -- -mid_time fit 2454281.65585 -5.8e-05 +5.9e-05 2454281.655851555 2454281.456017272 2454281.8560172725 - -#Filter: irac4 -#Epoch: -862 -#Number of outliers removed: 6 -#Uncertainties scale factor: 1.0303924632984718 - -#Residuals: -#Mean: -0.4738549932111635 -#STD: 39.453996612262074 -#RMS: 39.456842083914644 -#Chi squared: 684.1453902763466 -#Reduced chi squared: 1.0002125588835475 -#Max auto-correlation: 0.18249042494786444 -#Max auto-correlation flag: True -#Shapiro test: 0.9968221187591553 -#Shapiro test flag: False - -#Detrended Residuals: -#Mean: -1.0399254771998288e-05 -#STD: 0.0008670962174027471 -#RMS: 0.0008671585753101707 -#Chi squared: 684.1453902763426 -#Reduced chi squared: 1.0002125588835418 -#Max auto-correlation: 0.1824904249478608 -#Max auto-correlation flag: True -#Shapiro test: 0.9968221187591553 -#Shapiro test flag: False \ No newline at end of file diff --git a/notebooks/2_detrending_examples/wasp39b_comb/global_correlations.pdf b/notebooks/2_detrending_examples/wasp39b_comb/global_correlations.pdf deleted file mode 100644 index 275e8ad..0000000 Binary files a/notebooks/2_detrending_examples/wasp39b_comb/global_correlations.pdf and /dev/null differ diff --git a/notebooks/2_detrending_examples/wasp39b_comb/global_results.pickle b/notebooks/2_detrending_examples/wasp39b_comb/global_results.pickle deleted file mode 100644 index 1980f14..0000000 Binary files a/notebooks/2_detrending_examples/wasp39b_comb/global_results.pickle and /dev/null differ diff --git a/notebooks/2_detrending_examples/wasp39b_comb/global_results.txt b/notebooks/2_detrending_examples/wasp39b_comb/global_results.txt deleted file mode 100644 index 752ed34..0000000 --- a/notebooks/2_detrending_examples/wasp39b_comb/global_results.txt +++ /dev/null @@ -1,53 +0,0 @@ -# variable fix/fit value uncertainty initial min.allowed max.allowed -n::obs0 fit 6792120.0 -140.0 +140.0 6792113.03102554 6320735.249790188 7108717.790418691 -time_time::obs0 fit 0.0021 -0.00099 +0.00099 0.0021464508150259576 -2.0 2.0 -time::obs0 fit -0.00065 -0.00036 +0.00035 -0.0006590987360688416 -2.0 2.0 -n::obs1 fit 136402300.0 -5200.0 +4900.0 136401981.1300839 128010934.92953071 141488415.83591858 -ls::obs1 fit 0.00141 -0.0002 +0.00021 0.0014145227354940282 -1.0 1.0 -sa::obs1 fit 0.001425 -5.6e-05 +5.7e-05 0.0014275801072529681 -1.0 1.0 -sd::obs1 fit 2.302 -0.038 +0.038 2.303312550902399 0.0 5.0 -n::obs2 fit 1.00108 -0.00046 +0.00043 1.0010487327205049 0.9232893586158752 1.0589704513549805 -time_time::obs2 fit -0.04 -0.019 +0.02 -0.04062645224565831 -2.0 2.0 -time::obs2 fit 0.0129 -0.0072 +0.0069 0.013155506061823807 -2.0 2.0 -n::obs3 fit 0.145486 -7.7e-05 +7.8e-05 0.14548557611650242 0.13289290206522572 0.154034717385994 -airmass::obs3 fit -0.0061 -0.00069 +0.0007 -0.006098762597659846 -2.0 2.0 -a_1::jwst_niriss1:8600.0-28000.0 fix 0.5985089796355353 -a_2::jwst_niriss1:8600.0-28000.0 fix -0.025920976432747087 -a_3::jwst_niriss1:8600.0-28000.0 fix -0.010021731025638638 -a_4::jwst_niriss1:8600.0-28000.0 fix -0.0057742806884076335 -a_1::hst_wfc3_ir_g141:10880.0-16800.0 fix 0.45038007495085725 -a_2::hst_wfc3_ir_g141:10880.0-16800.0 fix 0.2609004213071497 -a_3::hst_wfc3_ir_g141:10880.0-16800.0 fix -0.17332583459874426 -a_4::hst_wfc3_ir_g141:10880.0-16800.0 fix 0.01601986680568826 -a_1::TESS fix 0.49893510519234197 -a_2::TESS fix -0.07295549722120057 -a_3::TESS fix 0.46617321219107144 -a_4::TESS fix -0.21643294363957313 -a_1::luminance fix 0.5391853403024727 -a_2::luminance fix -0.37264959241326223 -a_3::luminance fix 1.1257479811875823 -a_4::luminance fix -0.4761825657534536 -rp_over_rs::jwst_niriss1:8600.0-28000.0 fit 0.145085 -7.6e-05 +7.5e-05 0.14508686769210757 0.01457 1.4569999999999999 -rp_over_rs::hst_wfc3_ir_g141:10880.0-16800.0 fit 0.14529 -0.00011 +0.00011 0.14529110648501378 0.01457 1.4569999999999999 -rp_over_rs::TESS fit 0.1445 -0.0015 +0.0014 0.14448283143445767 0.01457 1.4569999999999999 -rp_over_rs::luminance fit 0.1464 -0.0018 +0.0017 0.1464829946011631 0.01457 1.4569999999999999 -period fix 4.05528043 -sma_over_rs fit 11.42 -0.021 +0.023 11.419782032926328 0.01137 11370.0 -eccentricity fix 0.0 -inclination fit 87.773 -0.021 +0.023 87.77244721997879 10.0 90.0 -periastron fix 0.0 -mid_time::715 fit 2459787.556726 -1.6e-05 +1.6e-05 2459787.5567257865 2459787.35687145 2459787.75687145 -mid_time::183 fit 2457630.14757 -4.2e-05 +4.2e-05 2457630.1475686776 2457629.94768269 2457630.3476826902 -mid_time::694 fit 2459702.39586 -0.00044 +0.00043 2459702.395850253 2459702.19598242 2459702.5959824203 -mid_time::603 fit 2459333.36448 -0.00063 +0.0006 2459333.364479083 2459333.1654632897 2459333.56546329 - -#Residuals: -#Mean: -17.377354102625578 -#STD: 3278.816411296094 -#RMS: 3278.862459973002 -#Chi squared: 1049.3908214552557 -#Reduced chi squared: 1.0090296360146689 -#Max auto-correlation: 0.09530244218309314 -#Max auto-correlation flag: False -#Shapiro test: 0.9981696605682373 -#Shapiro test flag: False \ No newline at end of file diff --git a/notebooks/2_detrending_examples/wasp39b_comb/global_traces.pdf b/notebooks/2_detrending_examples/wasp39b_comb/global_traces.pdf deleted file mode 100644 index c6389bd..0000000 Binary files a/notebooks/2_detrending_examples/wasp39b_comb/global_traces.pdf and /dev/null differ diff --git a/notebooks/2_detrending_examples/wasp39b_comb/obs0_lightcurve.pdf b/notebooks/2_detrending_examples/wasp39b_comb/obs0_lightcurve.pdf deleted file mode 100644 index 596cf5d..0000000 Binary files a/notebooks/2_detrending_examples/wasp39b_comb/obs0_lightcurve.pdf and /dev/null differ diff --git a/notebooks/2_detrending_examples/wasp39b_comb/obs0_results.pickle b/notebooks/2_detrending_examples/wasp39b_comb/obs0_results.pickle deleted file mode 100644 index 413085d..0000000 Binary files a/notebooks/2_detrending_examples/wasp39b_comb/obs0_results.pickle and /dev/null differ diff --git a/notebooks/2_detrending_examples/wasp39b_comb/obs0_results.txt b/notebooks/2_detrending_examples/wasp39b_comb/obs0_results.txt deleted file mode 100644 index e6ac318..0000000 --- a/notebooks/2_detrending_examples/wasp39b_comb/obs0_results.txt +++ /dev/null @@ -1,42 +0,0 @@ -# variable fix/fit value uncertainty initial min.allowed max.allowed -n fit 6792120.0 -140.0 +140.0 6792113.03102554 6320735.249790188 7108717.790418691 -time_time fit 0.0021 -0.00099 +0.00099 0.0021464508150259576 -2.0 2.0 -time fit -0.00065 -0.00036 +0.00035 -0.0006590987360688416 -2.0 2.0 -a_1 fix 0.5985089796355353 -- -- -- -- -- -a_2 fix -0.025920976432747087 -- -- -- -- -- -a_3 fix -0.010021731025638638 -- -- -- -- -- -a_4 fix -0.0057742806884076335 -- -- -- -- -- -rp_over_rs fit 0.145085 -7.6e-05 +7.5e-05 0.14508686769210757 0.01457 1.4569999999999999 -period fix 4.05528043 -- -- -- -- -- -sma_over_rs fit 11.42 -0.021 +0.023 11.419782032926328 0.01137 11370.0 -eccentricity fix 0.0 -- -- -- -- -- -inclination fit 87.773 -0.021 +0.023 87.77244721997879 10.0 90.0 -periastron fix 0.0 -- -- -- -- -- -mid_time fit 2459787.556726 -1.6e-05 +1.6e-05 2459787.5567257865 2459787.35687145 2459787.75687145 - -#Filter: jwst_niriss1:8600.0-28000.0 -#Epoch: 715 -#Number of outliers removed: 5 -#Uncertainties scale factor: 0.9587710242466524 - -#Residuals: -#Mean: -3.817392600033278 -#STD: 946.227387626565 -#RMS: 946.2350879040877 -#Chi squared: 532.2487083682851 -#Reduced chi squared: 1.0004674969328666 -#Max auto-correlation: 0.13821387657150339 -#Max auto-correlation flag: False -#Shapiro test: 0.9959384799003601 -#Shapiro test flag: False - -#Detrended Residuals: -#Mean: -5.620526690824452e-07 -#STD: 0.00013931713234010724 -#RMS: 0.00013931826609125516 -#Chi squared: 532.2487083682647 -#Reduced chi squared: 1.0004674969328284 -#Max auto-correlation: 0.13821387657151937 -#Max auto-correlation flag: False -#Shapiro test: 0.9959384799003601 -#Shapiro test flag: False \ No newline at end of file diff --git a/notebooks/2_detrending_examples/wasp39b_comb/obs1_lightcurve.pdf b/notebooks/2_detrending_examples/wasp39b_comb/obs1_lightcurve.pdf deleted file mode 100644 index 2492f98..0000000 Binary files a/notebooks/2_detrending_examples/wasp39b_comb/obs1_lightcurve.pdf and /dev/null differ diff --git a/notebooks/2_detrending_examples/wasp39b_comb/obs1_results.pickle b/notebooks/2_detrending_examples/wasp39b_comb/obs1_results.pickle deleted file mode 100644 index 9dea104..0000000 Binary files a/notebooks/2_detrending_examples/wasp39b_comb/obs1_results.pickle and /dev/null differ diff --git a/notebooks/2_detrending_examples/wasp39b_comb/obs1_results.txt b/notebooks/2_detrending_examples/wasp39b_comb/obs1_results.txt deleted file mode 100644 index 7e0a31a..0000000 --- a/notebooks/2_detrending_examples/wasp39b_comb/obs1_results.txt +++ /dev/null @@ -1,43 +0,0 @@ -# variable fix/fit value uncertainty initial min.allowed max.allowed -n fit 136402300.0 -5200.0 +4900.0 136401981.1300839 128010934.92953071 141488415.83591858 -ls fit 0.00141 -0.0002 +0.00021 0.0014145227354940282 -1.0 1.0 -sa fit 0.001425 -5.6e-05 +5.7e-05 0.0014275801072529681 -1.0 1.0 -sd fit 2.302 -0.038 +0.038 2.303312550902399 0.0 5.0 -a_1 fix 0.45038007495085725 -- -- -- -- -- -a_2 fix 0.2609004213071497 -- -- -- -- -- -a_3 fix -0.17332583459874426 -- -- -- -- -- -a_4 fix 0.01601986680568826 -- -- -- -- -- -rp_over_rs fit 0.14529 -0.00011 +0.00011 0.14529110648501378 0.01457 1.4569999999999999 -period fix 4.05528043 -- -- -- -- -- -sma_over_rs fit 11.42 -0.021 +0.023 11.419782032926328 0.01137 11370.0 -eccentricity fix 0.0 -- -- -- -- -- -inclination fit 87.773 -0.021 +0.023 87.77244721997879 10.0 90.0 -periastron fix 0.0 -- -- -- -- -- -mid_time fit 2457630.14757 -4.2e-05 +4.2e-05 2457630.1475686776 2457629.94768269 2457630.3476826902 - -#Filter: hst_wfc3_ir_g141:10880.0-16800.0 -#Epoch: 183 -#Number of outliers removed: 1 -#Uncertainties scale factor: 1.0471186495881333 - -#Residuals: -#Mean: -328.47793735980986 -#STD: 14789.02998568814 -#RMS: 14792.677434221132 -#Chi squared: 59.99932280485938 -#Reduced chi squared: 1.1999864560971876 -#Max auto-correlation: 0.3123026112051119 -#Max auto-correlation flag: False -#Shapiro test: 0.978934109210968 -#Shapiro test flag: False - -#Detrended Residuals: -#Mean: -2.4094036154664876e-06 -#STD: 0.00010846929572456785 -#RMS: 0.00010849605218977313 -#Chi squared: 59.999322804863915 -#Reduced chi squared: 1.1999864560972784 -#Max auto-correlation: 0.31230261120493696 -#Max auto-correlation flag: False -#Shapiro test: 0.978934109210968 -#Shapiro test flag: False \ No newline at end of file diff --git a/notebooks/2_detrending_examples/wasp39b_comb/obs2_lightcurve.pdf b/notebooks/2_detrending_examples/wasp39b_comb/obs2_lightcurve.pdf deleted file mode 100644 index 076e8d0..0000000 Binary files a/notebooks/2_detrending_examples/wasp39b_comb/obs2_lightcurve.pdf and /dev/null differ diff --git a/notebooks/2_detrending_examples/wasp39b_comb/obs2_results.pickle b/notebooks/2_detrending_examples/wasp39b_comb/obs2_results.pickle deleted file mode 100644 index cbcfbb5..0000000 Binary files a/notebooks/2_detrending_examples/wasp39b_comb/obs2_results.pickle and /dev/null differ diff --git a/notebooks/2_detrending_examples/wasp39b_comb/obs2_results.txt b/notebooks/2_detrending_examples/wasp39b_comb/obs2_results.txt deleted file mode 100644 index fbd15ac..0000000 --- a/notebooks/2_detrending_examples/wasp39b_comb/obs2_results.txt +++ /dev/null @@ -1,42 +0,0 @@ -# variable fix/fit value uncertainty initial min.allowed max.allowed -n fit 1.00108 -0.00046 +0.00043 1.0010487327205049 0.9232893586158752 1.0589704513549805 -time_time fit -0.04 -0.019 +0.02 -0.04062645224565831 -2.0 2.0 -time fit 0.0129 -0.0072 +0.0069 0.013155506061823807 -2.0 2.0 -a_1 fix 0.49893510519234197 -- -- -- -- -- -a_2 fix -0.07295549722120057 -- -- -- -- -- -a_3 fix 0.46617321219107144 -- -- -- -- -- -a_4 fix -0.21643294363957313 -- -- -- -- -- -rp_over_rs fit 0.1445 -0.0015 +0.0014 0.14448283143445767 0.01457 1.4569999999999999 -period fix 4.05528043 -- -- -- -- -- -sma_over_rs fit 11.42 -0.021 +0.023 11.419782032926328 0.01137 11370.0 -eccentricity fix 0.0 -- -- -- -- -- -inclination fit 87.773 -0.021 +0.023 87.77244721997879 10.0 90.0 -periastron fix 0.0 -- -- -- -- -- -mid_time fit 2459702.39586 -0.00044 +0.00043 2459702.395850253 2459702.19598242 2459702.5959824203 - -#Filter: TESS -#Epoch: 694 -#Number of outliers removed: 0 -#Uncertainties scale factor: 0.9827348743120348 - -#Residuals: -#Mean: -6.0245394305559795e-06 -#STD: 0.002341144200406136 -#RMS: 0.002341151951960965 -#Chi squared: 260.35404802061345 -#Reduced chi squared: 1.0013617231562055 -#Max auto-correlation: 0.12796889274224243 -#Max auto-correlation flag: False -#Shapiro test: 0.9929477572441101 -#Shapiro test flag: False - -#Detrended Residuals: -#Mean: -6.017552278628427e-06 -#STD: 0.0023373351644849134 -#RMS: 0.0023373429106729594 -#Chi squared: 260.3540480206128 -#Reduced chi squared: 1.001361723156203 -#Max auto-correlation: 0.12796889274224146 -#Max auto-correlation flag: False -#Shapiro test: 0.9929477572441101 -#Shapiro test flag: False \ No newline at end of file diff --git a/notebooks/2_detrending_examples/wasp39b_comb/obs3_lightcurve.pdf b/notebooks/2_detrending_examples/wasp39b_comb/obs3_lightcurve.pdf deleted file mode 100644 index 4382ef7..0000000 Binary files a/notebooks/2_detrending_examples/wasp39b_comb/obs3_lightcurve.pdf and /dev/null differ diff --git a/notebooks/2_detrending_examples/wasp39b_comb/obs3_results.pickle b/notebooks/2_detrending_examples/wasp39b_comb/obs3_results.pickle deleted file mode 100644 index 29348b3..0000000 Binary files a/notebooks/2_detrending_examples/wasp39b_comb/obs3_results.pickle and /dev/null differ diff --git a/notebooks/2_detrending_examples/wasp39b_comb/obs3_results.txt b/notebooks/2_detrending_examples/wasp39b_comb/obs3_results.txt deleted file mode 100644 index a9c9e80..0000000 --- a/notebooks/2_detrending_examples/wasp39b_comb/obs3_results.txt +++ /dev/null @@ -1,41 +0,0 @@ -# variable fix/fit value uncertainty initial min.allowed max.allowed -n fit 0.145486 -7.7e-05 +7.8e-05 0.14548557611650242 0.13289290206522572 0.154034717385994 -airmass fit -0.0061 -0.00069 +0.0007 -0.006098762597659846 -2.0 2.0 -a_1 fix 0.5391853403024727 -- -- -- -- -- -a_2 fix -0.37264959241326223 -- -- -- -- -- -a_3 fix 1.1257479811875823 -- -- -- -- -- -a_4 fix -0.4761825657534536 -- -- -- -- -- -rp_over_rs fit 0.1464 -0.0018 +0.0017 0.1464829946011631 0.01457 1.4569999999999999 -period fix 4.05528043 -- -- -- -- -- -sma_over_rs fit 11.42 -0.021 +0.023 11.419782032926328 0.01137 11370.0 -eccentricity fix 0.0 -- -- -- -- -- -inclination fit 87.773 -0.021 +0.023 87.77244721997879 10.0 90.0 -periastron fix 0.0 -- -- -- -- -- -mid_time fit 2459333.36448 -0.00063 +0.0006 2459333.364479083 2459333.1654632897 2459333.56546329 - -#Filter: luminance -#Epoch: 603 -#Number of outliers removed: 2 -#Uncertainties scale factor: 1.0962105114475804 - -#Residuals: -#Mean: 5.639091101296289e-06 -#STD: 0.0005305937995402822 -#RMS: 0.0005306237645064928 -#Chi squared: 196.78874226149802 -#Reduced chi squared: 0.8944942830068091 -#Max auto-correlation: 0.21771998302373652 -#Max auto-correlation flag: False -#Shapiro test: 0.9909476637840271 -#Shapiro test flag: False - -#Detrended Residuals: -#Mean: 3.9104551885893454e-05 -#STD: 0.0036551244921143636 -#RMS: 0.003655333667236478 -#Chi squared: 196.78874226149821 -#Reduced chi squared: 0.8944942830068101 -#Max auto-correlation: 0.21771998302373716 -#Max auto-correlation flag: False -#Shapiro test: 0.9909476637840271 -#Shapiro test flag: False \ No newline at end of file diff --git a/notebooks/2_detrending_examples/wasp39b_ground/global_correlations.pdf b/notebooks/2_detrending_examples/wasp39b_ground/global_correlations.pdf deleted file mode 100644 index dec5275..0000000 Binary files a/notebooks/2_detrending_examples/wasp39b_ground/global_correlations.pdf and /dev/null differ diff --git a/notebooks/2_detrending_examples/wasp39b_ground/global_results.pickle b/notebooks/2_detrending_examples/wasp39b_ground/global_results.pickle deleted file mode 100644 index 8c7af3f..0000000 Binary files a/notebooks/2_detrending_examples/wasp39b_ground/global_results.pickle and /dev/null differ diff --git a/notebooks/2_detrending_examples/wasp39b_ground/global_results.txt b/notebooks/2_detrending_examples/wasp39b_ground/global_results.txt deleted file mode 100644 index d5b0197..0000000 --- a/notebooks/2_detrending_examples/wasp39b_ground/global_results.txt +++ /dev/null @@ -1,25 +0,0 @@ -# variable fix/fit value uncertainty initial min.allowed max.allowed -n fit 0.145505 -7.2e-05 +7.3e-05 0.14550462793793484 0.13289290206522572 0.154034717385994 -airmass fit -0.00609 -0.00064 +0.00064 -0.006113937025102656 -2.0 2.0 -a_1 fix 0.5391853403024727 -a_2 fix -0.37264959241326223 -a_3 fix 1.1257479811875823 -a_4 fix -0.4761825657534536 -rp_over_rs fit 0.1467 -0.0018 +0.0018 0.14676597782902992 0.01457 1.4569999999999999 -period fix 4.05528043 -sma_over_rs fix 11.37 -eccentricity fix 0.0 -inclination fix 87.75 -periastron fix 0.0 -mid_time fit 2459333.36478 -0.00058 +0.00058 2459333.364775375 2459333.1654632897 2459333.56546329 - -#Residuals: -#Mean: 3.0989811939289175e-06 -#STD: 0.0005350376710864824 -#RMS: 0.0005350466457852879 -#Chi squared: 221.00849021965064 -#Reduced chi squared: 1.0184723051596805 -#Max auto-correlation: 0.2356294999567778 -#Max auto-correlation flag: False -#Shapiro test: 0.990524172782898 -#Shapiro test flag: False \ No newline at end of file diff --git a/notebooks/2_detrending_examples/wasp39b_ground/global_traces.pdf b/notebooks/2_detrending_examples/wasp39b_ground/global_traces.pdf deleted file mode 100644 index 01eeb10..0000000 Binary files a/notebooks/2_detrending_examples/wasp39b_ground/global_traces.pdf and /dev/null differ diff --git a/notebooks/2_detrending_examples/wasp39b_ground/obs0_lightcurve.pdf b/notebooks/2_detrending_examples/wasp39b_ground/obs0_lightcurve.pdf deleted file mode 100644 index cba2bac..0000000 Binary files a/notebooks/2_detrending_examples/wasp39b_ground/obs0_lightcurve.pdf and /dev/null differ diff --git a/notebooks/2_detrending_examples/wasp39b_ground/obs0_results.pickle b/notebooks/2_detrending_examples/wasp39b_ground/obs0_results.pickle deleted file mode 100644 index 4c501d9..0000000 Binary files a/notebooks/2_detrending_examples/wasp39b_ground/obs0_results.pickle and /dev/null differ diff --git a/notebooks/2_detrending_examples/wasp39b_ground/obs0_results.txt b/notebooks/2_detrending_examples/wasp39b_ground/obs0_results.txt deleted file mode 100644 index d3e26b9..0000000 --- a/notebooks/2_detrending_examples/wasp39b_ground/obs0_results.txt +++ /dev/null @@ -1,41 +0,0 @@ -# variable fix/fit value uncertainty initial min.allowed max.allowed -n fit 0.145505 -7.2e-05 +7.3e-05 0.14550462793793484 0.13289290206522572 0.154034717385994 -airmass fit -0.00609 -0.00064 +0.00064 -0.006113937025102656 -2.0 2.0 -a_1 fix 0.5391853403024727 -- -- -- -- -- -a_2 fix -0.37264959241326223 -- -- -- -- -- -a_3 fix 1.1257479811875823 -- -- -- -- -- -a_4 fix -0.4761825657534536 -- -- -- -- -- -rp_over_rs fit 0.1467 -0.0018 +0.0018 0.14676597782902992 0.01457 1.4569999999999999 -period fix 4.05528043 -- -- -- -- -- -sma_over_rs fix 11.37 -- -- -- -- -- -eccentricity fix 0.0 -- -- -- -- -- -inclination fix 87.75 -- -- -- -- -- -periastron fix 0.0 -- -- -- -- -- -mid_time fit 2459333.36478 -0.00058 +0.00058 2459333.364775375 2459333.1654632897 2459333.56546329 - -#Filter: luminance -#Epoch: 603 -#Number of outliers removed: 1 -#Uncertainties scale factor: 1.0563870819342949 - -#Residuals: -#Mean: 3.0989811939289175e-06 -#STD: 0.0005350376710864824 -#RMS: 0.0005350466457852879 -#Chi squared: 221.00849021965064 -#Reduced chi squared: 1.000038417283487 -#Max auto-correlation: 0.2356294999567778 -#Max auto-correlation flag: False -#Shapiro test: 0.990524172782898 -#Shapiro test flag: False - -#Detrended Residuals: -#Mean: 2.15392502992743e-05 -#STD: 0.0036855807539618577 -#RMS: 0.003685643693207132 -#Chi squared: 221.00849021965098 -#Reduced chi squared: 1.0000384172834886 -#Max auto-correlation: 0.23562949995677826 -#Max auto-correlation flag: False -#Shapiro test: 0.990524172782898 -#Shapiro test flag: False \ No newline at end of file diff --git a/notebooks/2_detrending_examples/wasp39b_hst/global_correlations.pdf b/notebooks/2_detrending_examples/wasp39b_hst/global_correlations.pdf deleted file mode 100644 index d34236f..0000000 Binary files a/notebooks/2_detrending_examples/wasp39b_hst/global_correlations.pdf and /dev/null differ diff --git a/notebooks/2_detrending_examples/wasp39b_hst/global_results.pickle b/notebooks/2_detrending_examples/wasp39b_hst/global_results.pickle deleted file mode 100644 index cd2bd71..0000000 Binary files a/notebooks/2_detrending_examples/wasp39b_hst/global_results.pickle and /dev/null differ diff --git a/notebooks/2_detrending_examples/wasp39b_hst/global_results.txt b/notebooks/2_detrending_examples/wasp39b_hst/global_results.txt deleted file mode 100644 index dafbcec..0000000 --- a/notebooks/2_detrending_examples/wasp39b_hst/global_results.txt +++ /dev/null @@ -1,27 +0,0 @@ -# variable fix/fit value uncertainty initial min.allowed max.allowed -n fit 136402400.0 -5400.0 +5400.0 136401998.7578836 128010934.92953071 141488415.83591858 -ls fit 0.00139 -0.00021 +0.00021 0.0013869024161110577 -1.0 1.0 -sa fit 0.001415 -5.9e-05 +5.8e-05 0.0014145035667048056 -1.0 1.0 -sd fit 2.294 -0.043 +0.043 2.295082539913287 0.0 5.0 -a_1 fix 0.45038007495085725 -a_2 fix 0.2609004213071497 -a_3 fix -0.17332583459874426 -a_4 fix 0.01601986680568826 -rp_over_rs fit 0.14529 -0.00011 +0.00011 0.14528255440686877 0.01457 1.4569999999999999 -period fix 4.05528043 -sma_over_rs fix 11.37 -eccentricity fix 0.0 -inclination fix 87.75 -periastron fix 0.0 -mid_time fit 2457630.1477 -4.1e-05 +4.1e-05 2457630.1477019116 2457629.94768269 2457630.3476826902 - -#Residuals: -#Mean: -154.0571419698 -#STD: 14346.545596872695 -#RMS: 14347.37272695385 -#Chi squared: 50.0131076463221 -#Reduced chi squared: 1.1366615374164113 -#Max auto-correlation: 0.2928122557161001 -#Max auto-correlation flag: False -#Shapiro test: 0.9790969491004944 -#Shapiro test flag: False \ No newline at end of file diff --git a/notebooks/2_detrending_examples/wasp39b_hst/global_traces.pdf b/notebooks/2_detrending_examples/wasp39b_hst/global_traces.pdf deleted file mode 100644 index 812ab14..0000000 Binary files a/notebooks/2_detrending_examples/wasp39b_hst/global_traces.pdf and /dev/null differ diff --git a/notebooks/2_detrending_examples/wasp39b_hst/obs0_lightcurve.pdf b/notebooks/2_detrending_examples/wasp39b_hst/obs0_lightcurve.pdf deleted file mode 100644 index ed42864..0000000 Binary files a/notebooks/2_detrending_examples/wasp39b_hst/obs0_lightcurve.pdf and /dev/null differ diff --git a/notebooks/2_detrending_examples/wasp39b_hst/obs0_results.pickle b/notebooks/2_detrending_examples/wasp39b_hst/obs0_results.pickle deleted file mode 100644 index 604929a..0000000 Binary files a/notebooks/2_detrending_examples/wasp39b_hst/obs0_results.pickle and /dev/null differ diff --git a/notebooks/2_detrending_examples/wasp39b_hst/obs0_results.txt b/notebooks/2_detrending_examples/wasp39b_hst/obs0_results.txt deleted file mode 100644 index 19d67f5..0000000 --- a/notebooks/2_detrending_examples/wasp39b_hst/obs0_results.txt +++ /dev/null @@ -1,43 +0,0 @@ -# variable fix/fit value uncertainty initial min.allowed max.allowed -n fit 136402400.0 -5400.0 +5400.0 136401998.7578836 128010934.92953071 141488415.83591858 -ls fit 0.00139 -0.00021 +0.00021 0.0013869024161110577 -1.0 1.0 -sa fit 0.001415 -5.9e-05 +5.8e-05 0.0014145035667048056 -1.0 1.0 -sd fit 2.294 -0.043 +0.043 2.295082539913287 0.0 5.0 -a_1 fix 0.45038007495085725 -- -- -- -- -- -a_2 fix 0.2609004213071497 -- -- -- -- -- -a_3 fix -0.17332583459874426 -- -- -- -- -- -a_4 fix 0.01601986680568826 -- -- -- -- -- -rp_over_rs fit 0.14529 -0.00011 +0.00011 0.14528255440686877 0.01457 1.4569999999999999 -period fix 4.05528043 -- -- -- -- -- -sma_over_rs fix 11.37 -- -- -- -- -- -eccentricity fix 0.0 -- -- -- -- -- -inclination fix 87.75 -- -- -- -- -- -periastron fix 0.0 -- -- -- -- -- -mid_time fit 2457630.1477 -4.1e-05 +4.1e-05 2457630.1477019116 2457629.94768269 2457630.3476826902 - -#Filter: hst_wfc3_ir_g141:10880.0-16800.0 -#Epoch: 183 -#Number of outliers removed: 1 -#Uncertainties scale factor: 1.112082018435905 - -#Residuals: -#Mean: -154.0571419698 -#STD: 14346.545596872695 -#RMS: 14347.37272695385 -#Chi squared: 50.0131076463221 -#Reduced chi squared: 1.000262152926442 -#Max auto-correlation: 0.2928122557161001 -#Max auto-correlation flag: False -#Shapiro test: 0.9790969491004944 -#Shapiro test flag: False - -#Detrended Residuals: -#Mean: -1.129749680930381e-06 -#STD: 0.000105224618709278 -#RMS: 0.0001052306833430939 -#Chi squared: 50.01310764632264 -#Reduced chi squared: 1.0002621529264528 -#Max auto-correlation: 0.2928122557160432 -#Max auto-correlation flag: False -#Shapiro test: 0.9790969491004944 -#Shapiro test flag: False \ No newline at end of file diff --git a/notebooks/2_detrending_examples/wasp39b_jwst/global_correlations.pdf b/notebooks/2_detrending_examples/wasp39b_jwst/global_correlations.pdf deleted file mode 100644 index 1e46e46..0000000 Binary files a/notebooks/2_detrending_examples/wasp39b_jwst/global_correlations.pdf and /dev/null differ diff --git a/notebooks/2_detrending_examples/wasp39b_jwst/global_results.pickle b/notebooks/2_detrending_examples/wasp39b_jwst/global_results.pickle deleted file mode 100644 index 5c9aab8..0000000 Binary files a/notebooks/2_detrending_examples/wasp39b_jwst/global_results.pickle and /dev/null differ diff --git a/notebooks/2_detrending_examples/wasp39b_jwst/global_results.txt b/notebooks/2_detrending_examples/wasp39b_jwst/global_results.txt deleted file mode 100644 index 0a6d70d..0000000 --- a/notebooks/2_detrending_examples/wasp39b_jwst/global_results.txt +++ /dev/null @@ -1,26 +0,0 @@ -# variable fix/fit value uncertainty initial min.allowed max.allowed -n fit 6792120.0 -140.0 +130.0 6792115.678977596 6320735.249790188 7108717.790418691 -time_time fit 0.00218 -0.00095 +0.0009 0.0021715844422729447 -2.0 2.0 -time fit -0.00068 -0.00032 +0.00034 -0.000669378312350144 -2.0 2.0 -a_1 fix 0.5985089796355353 -a_2 fix -0.025920976432747087 -a_3 fix -0.010021731025638638 -a_4 fix -0.0057742806884076335 -rp_over_rs fit 0.145102 -8.3e-05 +7.7e-05 0.1450985987863956 0.01457 1.4569999999999999 -period fix 4.05528043 -sma_over_rs fit 11.415 -0.025 +0.025 11.416061115792422 0.01137 11370.0 -eccentricity fix 0.0 -inclination fit 87.767 -0.025 +0.024 87.76765600363002 10.0 90.0 -periastron fix 0.0 -mid_time fit 2459787.556724 -1.7e-05 +1.7e-05 2459787.5567254843 2459787.35687145 2459787.75687145 - -#Residuals: -#Mean: 3.9144862263806557 -#STD: 946.0467266458576 -#RMS: 946.0548251553704 -#Chi squared: 532.0437209418865 -#Reduced chi squared: 1.013416611317879 -#Max auto-correlation: 0.13993470331098803 -#Max auto-correlation flag: False -#Shapiro test: 0.9959012269973755 -#Shapiro test flag: False \ No newline at end of file diff --git a/notebooks/2_detrending_examples/wasp39b_jwst/global_traces.pdf b/notebooks/2_detrending_examples/wasp39b_jwst/global_traces.pdf deleted file mode 100644 index 1dbaeef..0000000 Binary files a/notebooks/2_detrending_examples/wasp39b_jwst/global_traces.pdf and /dev/null differ diff --git a/notebooks/2_detrending_examples/wasp39b_jwst/obs0_lightcurve.pdf b/notebooks/2_detrending_examples/wasp39b_jwst/obs0_lightcurve.pdf deleted file mode 100644 index 52cffc1..0000000 Binary files a/notebooks/2_detrending_examples/wasp39b_jwst/obs0_lightcurve.pdf and /dev/null differ diff --git a/notebooks/2_detrending_examples/wasp39b_jwst/obs0_results.pickle b/notebooks/2_detrending_examples/wasp39b_jwst/obs0_results.pickle deleted file mode 100644 index f0984aa..0000000 Binary files a/notebooks/2_detrending_examples/wasp39b_jwst/obs0_results.pickle and /dev/null differ diff --git a/notebooks/2_detrending_examples/wasp39b_jwst/obs0_results.txt b/notebooks/2_detrending_examples/wasp39b_jwst/obs0_results.txt deleted file mode 100644 index 65d87d5..0000000 --- a/notebooks/2_detrending_examples/wasp39b_jwst/obs0_results.txt +++ /dev/null @@ -1,42 +0,0 @@ -# variable fix/fit value uncertainty initial min.allowed max.allowed -n fit 6792120.0 -140.0 +130.0 6792115.678977596 6320735.249790188 7108717.790418691 -time_time fit 0.00218 -0.00095 +0.0009 0.0021715844422729447 -2.0 2.0 -time fit -0.00068 -0.00032 +0.00034 -0.000669378312350144 -2.0 2.0 -a_1 fix 0.5985089796355353 -- -- -- -- -- -a_2 fix -0.025920976432747087 -- -- -- -- -- -a_3 fix -0.010021731025638638 -- -- -- -- -- -a_4 fix -0.0057742806884076335 -- -- -- -- -- -rp_over_rs fit 0.145102 -8.3e-05 +7.7e-05 0.1450985987863956 0.01457 1.4569999999999999 -period fix 4.05528043 -- -- -- -- -- -sma_over_rs fit 11.415 -0.025 +0.025 11.416061115792422 0.01137 11370.0 -eccentricity fix 0.0 -- -- -- -- -- -inclination fit 87.767 -0.025 +0.024 87.76765600363002 10.0 90.0 -periastron fix 0.0 -- -- -- -- -- -mid_time fit 2459787.556724 -1.7e-05 +1.7e-05 2459787.5567254843 2459787.35687145 2459787.75687145 - -#Filter: jwst_niriss1:8600.0-28000.0 -#Epoch: 715 -#Number of outliers removed: 5 -#Uncertainties scale factor: 0.9587711920555325 - -#Residuals: -#Mean: 3.9144862263806557 -#STD: 946.0467266458576 -#RMS: 946.0548251553704 -#Chi squared: 532.0437209418865 -#Reduced chi squared: 1.000082182221591 -#Max auto-correlation: 0.13993470331098803 -#Max auto-correlation flag: False -#Shapiro test: 0.9959012269973755 -#Shapiro test flag: False - -#Detrended Residuals: -#Mean: 5.763538585582047e-07 -#STD: 0.00013929072065419745 -#RMS: 0.00013929191306079455 -#Chi squared: 532.0437209418881 -#Reduced chi squared: 1.0000821822215942 -#Max auto-correlation: 0.1399347033109959 -#Max auto-correlation flag: False -#Shapiro test: 0.9959012269973755 -#Shapiro test flag: False \ No newline at end of file diff --git a/notebooks/2_detrending_examples/wasp39b_tess/global_correlations.pdf b/notebooks/2_detrending_examples/wasp39b_tess/global_correlations.pdf deleted file mode 100644 index 33280f9..0000000 Binary files a/notebooks/2_detrending_examples/wasp39b_tess/global_correlations.pdf and /dev/null differ diff --git a/notebooks/2_detrending_examples/wasp39b_tess/global_results.pickle b/notebooks/2_detrending_examples/wasp39b_tess/global_results.pickle deleted file mode 100644 index b7df01a..0000000 Binary files a/notebooks/2_detrending_examples/wasp39b_tess/global_results.pickle and /dev/null differ diff --git a/notebooks/2_detrending_examples/wasp39b_tess/global_results.txt b/notebooks/2_detrending_examples/wasp39b_tess/global_results.txt deleted file mode 100644 index cc8d52f..0000000 --- a/notebooks/2_detrending_examples/wasp39b_tess/global_results.txt +++ /dev/null @@ -1,26 +0,0 @@ -# variable fix/fit value uncertainty initial min.allowed max.allowed -n fit 1.00105 -0.00047 +0.00047 1.0010458591621263 0.9232893586158752 1.0589704513549805 -time_time fit -0.04 -0.021 +0.021 -0.04045614948455345 -2.0 2.0 -time fit 0.0131 -0.008 +0.0077 0.013107509570403408 -2.0 2.0 -a_1 fix 0.49893510519234197 -a_2 fix -0.07295549722120057 -a_3 fix 0.46617321219107144 -a_4 fix -0.21643294363957313 -rp_over_rs fit 0.145 -0.0031 +0.0032 0.1456619833270916 0.01457 1.4569999999999999 -period fix 4.05528043 -sma_over_rs fit 11.28 -0.76 +0.92 11.100968648573899 0.01137 11370.0 -eccentricity fix 0.0 -inclination fit 87.61 -0.71 +0.98 87.4356297500474 10.0 90.0 -periastron fix 0.0 -mid_time fit 2459702.39584 -0.00044 +0.00045 2459702.395883799 2459702.19598242 2459702.5959824203 - -#Residuals: -#Mean: -1.4079691944855434e-05 -#STD: 0.002339905123467466 -#RMS: 0.002339947483289862 -#Chi squared: 260.08895506327633 -#Reduced chi squared: 1.0280195852303413 -#Max auto-correlation: 0.1283405397916046 -#Max auto-correlation flag: False -#Shapiro test: 0.992683470249176 -#Shapiro test flag: False \ No newline at end of file diff --git a/notebooks/2_detrending_examples/wasp39b_tess/global_traces.pdf b/notebooks/2_detrending_examples/wasp39b_tess/global_traces.pdf deleted file mode 100644 index 8ce3f7b..0000000 Binary files a/notebooks/2_detrending_examples/wasp39b_tess/global_traces.pdf and /dev/null differ diff --git a/notebooks/2_detrending_examples/wasp39b_tess/obs0_lightcurve.pdf b/notebooks/2_detrending_examples/wasp39b_tess/obs0_lightcurve.pdf deleted file mode 100644 index 7d43225..0000000 Binary files a/notebooks/2_detrending_examples/wasp39b_tess/obs0_lightcurve.pdf and /dev/null differ diff --git a/notebooks/2_detrending_examples/wasp39b_tess/obs0_results.pickle b/notebooks/2_detrending_examples/wasp39b_tess/obs0_results.pickle deleted file mode 100644 index fa0aac5..0000000 Binary files a/notebooks/2_detrending_examples/wasp39b_tess/obs0_results.pickle and /dev/null differ diff --git a/notebooks/2_detrending_examples/wasp39b_tess/obs0_results.txt b/notebooks/2_detrending_examples/wasp39b_tess/obs0_results.txt deleted file mode 100644 index fc93b2e..0000000 --- a/notebooks/2_detrending_examples/wasp39b_tess/obs0_results.txt +++ /dev/null @@ -1,42 +0,0 @@ -# variable fix/fit value uncertainty initial min.allowed max.allowed -n fit 1.00105 -0.00047 +0.00047 1.0010458591621263 0.9232893586158752 1.0589704513549805 -time_time fit -0.04 -0.021 +0.021 -0.04045614948455345 -2.0 2.0 -time fit 0.0131 -0.008 +0.0077 0.013107509570403408 -2.0 2.0 -a_1 fix 0.49893510519234197 -- -- -- -- -- -a_2 fix -0.07295549722120057 -- -- -- -- -- -a_3 fix 0.46617321219107144 -- -- -- -- -- -a_4 fix -0.21643294363957313 -- -- -- -- -- -rp_over_rs fit 0.145 -0.0031 +0.0032 0.1456619833270916 0.01457 1.4569999999999999 -period fix 4.05528043 -- -- -- -- -- -sma_over_rs fit 11.28 -0.76 +0.92 11.100968648573899 0.01137 11370.0 -eccentricity fix 0.0 -- -- -- -- -- -inclination fit 87.61 -0.71 +0.98 87.4356297500474 10.0 90.0 -periastron fix 0.0 -- -- -- -- -- -mid_time fit 2459702.39584 -0.00044 +0.00045 2459702.395883799 2459702.19598242 2459702.5959824203 - -#Filter: TESS -#Epoch: 694 -#Number of outliers removed: 0 -#Uncertainties scale factor: 0.9827382245304214 - -#Residuals: -#Mean: -1.4079691944855434e-05 -#STD: 0.002339905123467466 -#RMS: 0.002339947483289862 -#Chi squared: 260.08895506327633 -#Reduced chi squared: 1.0003421348587551 -#Max auto-correlation: 0.1283405397916046 -#Max auto-correlation flag: False -#Shapiro test: 0.992683470249176 -#Shapiro test flag: False - -#Detrended Residuals: -#Mean: -1.405508314329182e-05 -#STD: 0.0023361097729541363 -#RMS: 0.0023361520534104776 -#Chi squared: 260.0889550632769 -#Reduced chi squared: 1.0003421348587573 -#Max auto-correlation: 0.12834053979160717 -#Max auto-correlation flag: False -#Shapiro test: 0.992683470249176 -#Shapiro test flag: False \ No newline at end of file diff --git a/notebooks/3_core_calculations.ipynb b/notebooks/3_core_calculations.ipynb index 51772a7..e267c93 100644 --- a/notebooks/3_core_calculations.ipynb +++ b/notebooks/3_core_calculations.ipynb @@ -7,8 +7,8 @@ "source": [ "# PyLightcurve core culculations\n", "\n", - "The core culculations are provided to offer maximum efficiency and help you \n", - "**build you own scripts or codes** upon the functionalities of PyLigthcurve.\n", + "The core calculations are provided to offer maximum efficiency and help you \n", + "**build you own scripts** using the functionalities of PyLigthcurve.\n", "\n", "The functions that are included in the core calulations are:\n", "\n", @@ -30,7 +30,6 @@ "- **```plc.eclipse```**: calculates the eclipse model (in relative flux)\n", "- **```plc.transit_integrated```**: calculates the exposure-integtared transit model (in relative flux)\n", "- **```plc.eclipse_integrated```**: calculates the exposure-integtared eclipse model (in relative flux)\n", - "- Angle conversions \n", "\n" ] }, @@ -67,7 +66,7 @@ "\n", "## 1. Definitions\n", "\n", - "To use the core calculation in PyLightcurve we will need to provide some of the the following \n", + "To use the core calculations in PyLightcurve we will need to provide some of the the following \n", "information.\n", "\n", "\n", @@ -94,13 +93,6 @@ "| ``emissivity`` |``float`` |planet emissivity |no units |\n", "\n", "\n", - "Parameters that can be provided by the user or calculated through PyLightcurve:\n", - "\n", - "| variable name | type | decription |unit |\n", - "|:-------------------------------|:----------:|:-----------------------------------------:|:----------------------:|\n", - "|``limb_darkening_coefficients``|``list`` |4-element list with the limb-darkening coefficients |no units |\n", - "|``fp_over_fs`` |``float`` |plant-to-star flux ratio (emmitted + reflected) |no units |\n", - "| ``eclipse_mid_time`` |``float`` |the time of conjunction with the planet behind the star |days (BJDTDB)|\n", "\n", "\n", "### 1.2 ```filter_name```\n", @@ -136,7 +128,7 @@ "\n", "### 1.4 ```method = 'claret'```\n", "\n", - "This parameter refers to the limb-darkening law that we want to use. The default value is ```claret```, and the other options are: ```linear``` and ```quad```.\n", + "This parameter refers to the limb-darkening law that we want to use. The default value is ```claret```, and the other options are: ```power2```, ```linear``` and ```quad```.\n", "\n", "\n", "\n", @@ -154,7 +146,7 @@ " \n", "### 1.6 ```precision = 2```\n", "\n", - "This parameter is an option for the fulctions that calculate the relative flux during a transit or an eclipse. It refers to the precision of the numerical calculation of the Gauss–Legendre quadrature, the default value is 2, and the other options are 3, 4, ... 10, meaning that 20, 30, 40, ... 100 quadrature points will be used." + "This parameter is an option for the fulctions that calculate the relative flux during a transit or an eclipse. It refers to the precision of the numerical calculation of the Gauss–Kronrod quadrature, the default value is 2, and the other options are 3, 4, ... 10, meaning that 20, 30, 40, ... 100 quadrature points will be used." ] }, { diff --git a/notebooks/2_detrending_examples/1_wasp39b_ground.ipynb b/notebooks/detrending_examples/1_wasp39b_ground.ipynb similarity index 100% rename from notebooks/2_detrending_examples/1_wasp39b_ground.ipynb rename to notebooks/detrending_examples/1_wasp39b_ground.ipynb diff --git a/notebooks/2_detrending_examples/2_wasp39b_tess.ipynb b/notebooks/detrending_examples/2_wasp39b_tess.ipynb similarity index 100% rename from notebooks/2_detrending_examples/2_wasp39b_tess.ipynb rename to notebooks/detrending_examples/2_wasp39b_tess.ipynb diff --git a/notebooks/2_detrending_examples/3_wasp39b_jwst.ipynb b/notebooks/detrending_examples/3_wasp39b_jwst.ipynb similarity index 100% rename from notebooks/2_detrending_examples/3_wasp39b_jwst.ipynb rename to notebooks/detrending_examples/3_wasp39b_jwst.ipynb diff --git a/notebooks/2_detrending_examples/4_wasp39b_hst.ipynb b/notebooks/detrending_examples/4_wasp39b_hst.ipynb similarity index 100% rename from notebooks/2_detrending_examples/4_wasp39b_hst.ipynb rename to notebooks/detrending_examples/4_wasp39b_hst.ipynb diff --git a/notebooks/2_detrending_examples/5_wasp39b_comb.ipynb b/notebooks/detrending_examples/5_wasp39b_comb.ipynb similarity index 100% rename from notebooks/2_detrending_examples/5_wasp39b_comb.ipynb rename to notebooks/detrending_examples/5_wasp39b_comb.ipynb diff --git a/notebooks/2_detrending_examples/6_hd189733b_sst.ipynb b/notebooks/detrending_examples/6_hd189733b_sst.ipynb similarity index 100% rename from notebooks/2_detrending_examples/6_hd189733b_sst.ipynb rename to notebooks/detrending_examples/6_hd189733b_sst.ipynb diff --git a/notebooks/2_detrending_examples/hd189733b_sst.pickle b/notebooks/detrending_examples/hd189733b_sst.pickle similarity index 100% rename from notebooks/2_detrending_examples/hd189733b_sst.pickle rename to notebooks/detrending_examples/hd189733b_sst.pickle diff --git a/notebooks/2_detrending_examples/wasp39b_ground.pickle b/notebooks/detrending_examples/wasp39b_ground.pickle similarity index 100% rename from notebooks/2_detrending_examples/wasp39b_ground.pickle rename to notebooks/detrending_examples/wasp39b_ground.pickle diff --git a/notebooks/2_detrending_examples/wasp39b_hst.pickle b/notebooks/detrending_examples/wasp39b_hst.pickle similarity index 100% rename from notebooks/2_detrending_examples/wasp39b_hst.pickle rename to notebooks/detrending_examples/wasp39b_hst.pickle diff --git a/notebooks/2_detrending_examples/wasp39b_jwst.pickle b/notebooks/detrending_examples/wasp39b_jwst.pickle similarity index 100% rename from notebooks/2_detrending_examples/wasp39b_jwst.pickle rename to notebooks/detrending_examples/wasp39b_jwst.pickle diff --git a/notebooks/2_detrending_examples/wasp39b_tess.pickle b/notebooks/detrending_examples/wasp39b_tess.pickle similarity index 100% rename from notebooks/2_detrending_examples/wasp39b_tess.pickle rename to notebooks/detrending_examples/wasp39b_tess.pickle diff --git a/pylightcurve/__databases_setup__.py b/pylightcurve/__databases_setup__.py index 3b7f144..40412cb 100644 --- a/pylightcurve/__databases_setup__.py +++ b/pylightcurve/__databases_setup__.py @@ -3,7 +3,7 @@ import time import shutil -from pylightcurve.processes.files import open_dict, download +from .processes.files import open_dict, download try: import zipfile @@ -25,6 +25,12 @@ def _setup_database(plc_data, database_name): database_file_path_old = os.path.join(plc_data.databases_directory_path, database_name + '_old.pickle') last_update_file_path = os.path.join(plc_data.databases_directory_path, '{0}_last_update.txt'.format(database_name)) + if os.path.isfile(database_file_path): + try: + _ = open_dict(database_file_path) + except: + os.remove(database_file_path) + # define paths # check if everything exists, if not reset database diff --git a/pylightcurve/analysis/numerical_integration.py b/pylightcurve/analysis/numerical_integration.py index 5da7633..a073aaa 100644 --- a/pylightcurve/analysis/numerical_integration.py +++ b/pylightcurve/analysis/numerical_integration.py @@ -2,15 +2,6 @@ import numpy as np -gauss_legendre0 = [ - [0.1713244923791703450403, -0.9324695142031520278123], - [0.3607615730481386075698, -0.661209386466264513661 ], - [0.4679139345726910473899, -0.2386191860831969086305], - [0.46791393457269104739 , 0.238619186083196908631 ], - [0.3607615730481386075698, 0.661209386466264513661 ], - [0.1713244923791703450403, 0.9324695142031520278123 ], -] - gauss_legendre10 = [ [0.0666713443086881375936, -0.973906528517171720078 ], [0.149451349150580593146 , -0.8650633666889845107321], @@ -592,14 +583,6 @@ [7.3463449050567173e-4 , 0.9997137267734412336782], ] -gauss_kronrod0 = [ - [0.197979797979797979798 , -0.9258200997725514615666], - [0.4909090909090909090909, -0.5773502691896257645092], - [0.6222222222222222222222, 0 ], - [0.490909090909090909091 , 0.5773502691896257645092 ], - [0.197979797979797979798 , 0.9258200997725514615666 ], - ] - gauss_kronrod10 = [ [0.06297737366547301476549, -0.9765602507375731115345], @@ -1172,19 +1155,21 @@ ] -gauss_legendre_table = [np.swapaxes(gauss_legendre0, 0, 1), - np.swapaxes(gauss_legendre10, 0, 1), np.swapaxes(gauss_legendre20, 0, 1), np.swapaxes(gauss_legendre30, 0, 1), - np.swapaxes(gauss_legendre40, 0, 1), np.swapaxes(gauss_legendre50, 0, 1), np.swapaxes(gauss_legendre60, 0, 1), - np.swapaxes(gauss_legendre70, 0, 1), np.swapaxes(gauss_legendre80, 0, 1), np.swapaxes(gauss_legendre90, 0, 1), - np.swapaxes(gauss_legendre100, 0, 1) - ] +gauss_legendre_table = [ + np.swapaxes(gauss_legendre10, 0, 1), + np.swapaxes(gauss_legendre10, 0, 1), np.swapaxes(gauss_legendre20, 0, 1), np.swapaxes(gauss_legendre30, 0, 1), + np.swapaxes(gauss_legendre40, 0, 1), np.swapaxes(gauss_legendre50, 0, 1), np.swapaxes(gauss_legendre60, 0, 1), + np.swapaxes(gauss_legendre70, 0, 1), np.swapaxes(gauss_legendre80, 0, 1), np.swapaxes(gauss_legendre90, 0, 1), + np.swapaxes(gauss_legendre100, 0, 1) +] -gauss_kronrod_table = [np.swapaxes(gauss_kronrod0, 0, 1), - np.swapaxes(gauss_kronrod10, 0, 1), np.swapaxes(gauss_kronrod20, 0, 1), np.swapaxes(gauss_kronrod30, 0, 1), - np.swapaxes(gauss_kronrod40, 0, 1), np.swapaxes(gauss_kronrod50, 0, 1), np.swapaxes(gauss_kronrod60, 0, 1), - np.swapaxes(gauss_kronrod70, 0, 1), np.swapaxes(gauss_kronrod80, 0, 1), np.swapaxes(gauss_kronrod90, 0, 1), - np.swapaxes(gauss_kronrod100, 0, 1) - ] +gauss_kronrod_table = [ + np.swapaxes(gauss_kronrod10, 0, 1), + np.swapaxes(gauss_kronrod10, 0, 1), np.swapaxes(gauss_kronrod20, 0, 1), np.swapaxes(gauss_kronrod30, 0, 1), + np.swapaxes(gauss_kronrod40, 0, 1), np.swapaxes(gauss_kronrod50, 0, 1), np.swapaxes(gauss_kronrod60, 0, 1), + np.swapaxes(gauss_kronrod70, 0, 1), np.swapaxes(gauss_kronrod80, 0, 1), np.swapaxes(gauss_kronrod90, 0, 1), + np.swapaxes(gauss_kronrod100, 0, 1) +] gauss_table = gauss_kronrod_table # gauss_table = gauss_legendre_table diff --git a/pylightcurve/analysis/optimisation.py b/pylightcurve/analysis/optimisation.py index fa8107a..4b7904d 100644 --- a/pylightcurve/analysis/optimisation.py +++ b/pylightcurve/analysis/optimisation.py @@ -120,6 +120,7 @@ def __init__(self, input_data_x, input_data_y, input_data_y_unc, self.walkers_spread = float(walkers_spread) self.walkers_initial_positions = None self.sampler = None + self.sampler_steps = 100 self.progress = 0 if counter: @@ -140,7 +141,9 @@ def __init__(self, input_data_x, input_data_y, input_data_y_unc, 'parameters': {}, 'parameters_final': [], 'output_series': {}, - 'statistics': {}} + 'statistics': {}, + 'mcmc_run_complete': False, + } self.fitted_parameters = [] @@ -380,7 +383,7 @@ def run(self, verbose=False): self._postfit() - elif self.optimiser == 'emcee': + elif self.optimiser == 'emcee':= sys.setrecursionlimit(self.iterations) @@ -389,7 +392,7 @@ def run(self, verbose=False): option = int(bool(self.counter_name)) self.counter = Counter(['MCMC', self.counter_name][option], self.iterations - self.progress, - show_every=[self.iterations, 0][option] + 10, increment=10) + show_every=[self.iterations, 0][option] + self.sampler_steps, increment=self.sampler_steps) self._emcee_run() def _emcee_run(self): @@ -404,8 +407,8 @@ def _emcee_run(self): self.walkers_initial_positions = np.minimum(self.walkers_initial_positions, 1) self.walkers_initial_positions = np.maximum(self.walkers_initial_positions, 0) - self.sampler.run_mcmc(self.walkers_initial_positions, 10) - self.progress += 10 + self.sampler.run_mcmc(self.walkers_initial_positions, self.sampler_steps) + self.progress += self.sampler_steps self.counter.update() self._emcee_run() @@ -415,8 +418,8 @@ def _emcee_run(self): elif self.progress < self.iterations: - self.sampler.run_mcmc(None, 10, skip_initial_state_check=True) - self.progress += 10 + self.sampler.run_mcmc(None, self.sampler_steps, skip_initial_state_check=True) + self.progress += self.sampler_steps self.counter.update() self._emcee_run() @@ -515,6 +518,7 @@ def _postfit(self): self.results['statistics'][statistic] = statistics[statistic] self.mcmc_run_complete = True + self.results['mcmc_run_complete'] = True def save_all(self, export_file): diff --git a/pylightcurve/databases.py b/pylightcurve/databases.py index ef074aa..fae33f7 100644 --- a/pylightcurve/databases.py +++ b/pylightcurve/databases.py @@ -9,7 +9,7 @@ from exotethys import ls_database -from pylightcurve.processes.files import open_dict, save_dict, open_dict_online +from .processes.files import open_dict, save_dict, open_dict_online from .errors import * from .__databases_setup__ import _setup_database diff --git a/pylightcurve/models/exoplanet.py b/pylightcurve/models/exoplanet.py index 6b916d5..f785181 100644 --- a/pylightcurve/models/exoplanet.py +++ b/pylightcurve/models/exoplanet.py @@ -124,7 +124,7 @@ def reset(self, planet): self.dict['original_data']['time_format']), format='jd' ).datetime.isoformat().split('T')[0], - 'ldc_method': planet.method, + 'ldc_method': planet.ldc_method, 'max_sub_exp_time': planet.max_sub_exp_time, 'precision': planet.precision, 'stellar_temperature': planet.stellar_temperature, @@ -136,13 +136,11 @@ def reset(self, planet): 'emissivity': planet.emissivity, 'albedo': planet.albedo, 'sma_over_rs': planet.sma_over_rs, - 'fp_over_fs': planet.fp_over_fs(self.dict['original_data']['filter_name'], - self.dict['original_data']['wlrange']) } self.precision = planet.precision self.max_sub_exp_time = planet.max_sub_exp_time - self.ldc_method = planet.method + self.ldc_method = planet.ldc_method # convert time @@ -213,6 +211,8 @@ def reset(self, planet): else: self.observation_type = 'eclipse' self.epoch = eclipse_epoch + self.dict['model_info']['fp_over_fs'] = planet.fp_over_fs( + self.dict['original_data']['filter_name'], self.dict['original_data']['wlrange']) self.dict['model_info']['observation_type'] = self.observation_type self.dict['model_info']['epoch'] = self.epoch @@ -275,7 +275,7 @@ def reset(self, planet): # adjust normalisation factor df = max(np.median(flux) - np.min(flux), np.max(flux) - np.median(flux)) self.initial[0] = np.median(flux) - self.limits1[0] = np.min(flux) - 2 * df + self.limits1[0] = max(10**-10, np.min(flux) - 2 * df) self.limits2[0] = np.max(flux) + 2 * df def add_to_parameters_map(self, idx): @@ -299,7 +299,7 @@ def _signal_model(self, parameters): ldc1, ldc2, ldc3, ldc4, r, p, a, e, i, w, mt = parameters return np.mean(np.reshape( transit([ldc1, ldc2, ldc3, ldc4], r, p, a, e, i, w, mt, self.time_hr, - method=self.ldc_method, precision=self.precision), + ldc_method=self.ldc_method, precision=self.precision), (self.series_length, self.time_factor)), 1) elif self.dict['model_info']['observation_type'] == 'eclipse': @@ -342,7 +342,6 @@ class Planet: def __init__(self, name, ra, dec, stellar_logg, stellar_temperature, stellar_metallicity, rp_over_rs, period, sma_over_rs, eccentricity, inclination, periastron, mid_time, - mid_time_format='BJD_TDB', ldc_method='claret', max_sub_exp_time=10, precision=2, asc_node=0, albedo=0.15, emissivity=1.0): @@ -362,13 +361,13 @@ def __init__(self, name, ra, dec, stellar_logg, stellar_temperature, stellar_met self.eccentricity = eccentricity self.inclination = inclination self.periastron = periastron - self.mid_time = convert_to_bjd_tdb(ra, dec, mid_time, mid_time_format) + self.mid_time = mid_time self.asc_node = asc_node self.albedo = albedo self.emissivity = emissivity - self.method = ldc_method + self.ldc_method = ldc_method self.max_sub_exp_time = max_sub_exp_time self.precision = precision @@ -392,14 +391,14 @@ def airmass(self, time_array, observatory_latitude, observatory_longitude): # filter-dependent values def exotethys(self, filter_name, wlrange=None, stellar_model='Phoenix_2018'): - options = '{0}_{1}_{2}_{3}'.format(filter_name, wlrange, self.method, stellar_model) + options = '{0}_{1}_{2}_{3}'.format(filter_name, wlrange, self.ldc_method, stellar_model) if options not in self.ldcs_memory: self.ldcs_memory[options] = exotethys(self.stellar_logg, self.stellar_temperature, self.stellar_metallicity, - filter_name, wlrange, self.method, stellar_model) + filter_name, wlrange, self.ldc_method, stellar_model) return self.ldcs_memory[options] def add_custom_limb_darkening_coefficients(self, limb_darkening_coefficients, filter_name, wlrange, stellar_model): - options = '{0}_{1}_{2}_{3}'.format(filter_name, wlrange, self.method, stellar_model) + options = '{0}_{1}_{2}_{3}'.format(filter_name, wlrange, self.ldc_method, stellar_model) self.ldcs_memory[options] = limb_darkening_coefficients def fp_over_fs(self, filter_name, wlrange=None): @@ -421,13 +420,13 @@ def transit(self, time, filter_name, wlrange=None, stellar_model='Phoenix_2018') return transit(self.exotethys(filter_name, wlrange, stellar_model), self.rp_over_rs, self.period, self.sma_over_rs, self.eccentricity, self.inclination, self.periastron, self.mid_time, time, - self.method, self.precision) + self.ldc_method, self.precision) def transit_integrated(self, time, exp_time, filter_name, wlrange=None, stellar_model='Phoenix_2018'): return transit_integrated(self.exotethys(filter_name, wlrange, stellar_model), self.rp_over_rs, self.period, self.sma_over_rs, self.eccentricity, self.inclination, self.periastron, self.mid_time, time, exp_time, - self.max_sub_exp_time, self.method, self.precision) + self.max_sub_exp_time, self.ldc_method, self.precision) def transit_duration(self): return transit_duration(self.rp_over_rs, self.period, self.sma_over_rs, self.eccentricity, self.inclination, @@ -441,7 +440,7 @@ def transit_depth(self, filter_name, wlrange=None, stellar_model='Phoenix_2018') return transit_depth(self.exotethys(filter_name, wlrange, stellar_model), self.rp_over_rs, self.period, self.sma_over_rs, self.eccentricity, self.inclination, self.periastron, - self.method, self.precision) + self.ldc_method, self.precision) def eclipse(self, time, filter_name, wlrange=None): return eclipse(self.fp_over_fs(filter_name, wlrange), self.rp_over_rs, @@ -607,10 +606,10 @@ def transit_fitting(self, output_folder=None, if len(unique_filters) > 1: names.append('a_{0}::{1}'.format(ldc + 1, phot_filter)) - print_names.append(r'$a_{{{0}}}::{1}$'.format(ldc +1, phot_filter)) + print_names.append('a_{{{0}}}::{1}'.format(ldc +1, phot_filter)) else: names.append('a_{0}'.format(ldc + 1)) - print_names.append(r'$a_{{{0}}}$'.format(ldc +1)) + print_names.append('a_{{{0}}}'.format(ldc +1)) initial.append(ldcs[ldc]) if fit_ldcs[ldc]: @@ -630,7 +629,7 @@ def transit_fitting(self, output_folder=None, if fit_individual_rp_over_rs: for phot_filter in unique_filters: names.append('rp_over_rs::{0}'.format(phot_filter)) - print_names.append(r'$R_\mathrm{{p}}/R_*$::{0}'.format(phot_filter)) + print_names.append(r'R_\mathrm{{p}}/R_*::{0}'.format(phot_filter)) initial.append(self.rp_over_rs) limits1.append(fit_rp_over_rs_limits[0]) limits2.append(fit_rp_over_rs_limits[1]) @@ -648,7 +647,7 @@ def transit_fitting(self, output_folder=None, else: global_parameters_names = ['rp_over_rs'] - global_parameters_print_names = [r'$R_\mathrm{p}/R_*$'] + global_parameters_print_names = [r'R_\mathrm{p}/R_*'] global_parameters_initial = [self.rp_over_rs] global_parameters_fit = [True] global_parameters_limits = [fit_rp_over_rs_limits] @@ -657,7 +656,7 @@ def transit_fitting(self, output_folder=None, # orbital parameters global_parameters_names += ['period', 'sma_over_rs', 'eccentricity', 'inclination', 'periastron'] - global_parameters_print_names += [r'$P$', r'$a$', r'$e$', r'$i$', r'$\omega$'] + global_parameters_print_names += ['P', 'a', 'e', 'i', r'\omega'] global_parameters_initial += [self.period, self.sma_over_rs, self.eccentricity, self.inclination, self.periastron] global_parameters_fit += [fit_period, fit_sma_over_rs, False, fit_inclination, False] global_parameters_limits += [fit_period_limits, fit_sma_over_rs_limits, False, fit_inclination_limits, False] @@ -678,7 +677,7 @@ def transit_fitting(self, output_folder=None, new_mid_time = self.mid_time + new_epoch * self.period global_parameters_names += ['mid_time'] - global_parameters_print_names += [r'$T_\mathrm{mid}$'] + global_parameters_print_names += [r'T_\mathrm{mid}'] global_parameters_initial += [new_mid_time] global_parameters_fit += [fit_mid_time] global_parameters_limits += [[new_mid_time + fit_mid_time_limits[0], new_mid_time + fit_mid_time_limits[1]]] @@ -705,7 +704,7 @@ def transit_fitting(self, output_folder=None, for epoch in unique_epochs: names.append('mid_time::{0}'.format(epoch)) - print_names.append(r'$T_\mathrm{{mid}}$::{0}'.format(epoch)) + print_names.append(r'T_\mathrm{{mid}}::{0}'.format(epoch)) initial.append(self.mid_time + epoch * self.period) limits1.append(self.mid_time + epoch * self.period + fit_mid_time_limits[0]) limits2.append(self.mid_time + epoch * self.period + fit_mid_time_limits[1]) @@ -733,7 +732,7 @@ def single_observation_full_model(indices, *model_variables): single_observation_full_model, initial, limits1, limits2, logspace=logspace, data_x_name='time', data_y_name='flux', - data_x_print_name='r$t_{BJD_{TDB}}$', data_y_print_name='Relative Flux', + data_x_print_name='t_{BJD_{TDB}}', data_y_print_name='Relative Flux', parameters_names=names, parameters_print_names=print_names, walkers=walkers, iterations=iterations, burn_in=burn_in, counter=counter, @@ -790,7 +789,7 @@ def full_model(model_time, *model_variables): full_model, initial, limits1, limits2, logspace=logspace, data_x_name='time', data_y_name='flux', - data_x_print_name='r$t_{BJD_{TDB}}$', data_y_print_name='Relative Flux', + data_x_print_name='t_{BJD_{TDB}}', data_y_print_name='Relative Flux', parameters_names=names, parameters_print_names=print_names, walkers=walkers, iterations=iterations, burn_in=burn_in, counter=counter, @@ -818,7 +817,7 @@ def full_model(model_time, *model_variables): 'filter_outliers': filter_outliers, 'optimiser': optimiser, 'data_x_name': 'time', - 'data_x_print_name': r't_${BJD_{TDB}}$', + 'data_x_print_name': 't_{BJD_{TDB}}', 'data_y_name': 'flux', 'data_y_print_name': 'Relative Flux', 'fit_ldc1': fit_ldc1, @@ -1109,7 +1108,7 @@ def eclipse_fitting(self, output_folder=None, if fit_individual_fp_over_fs: for phot_filter in unique_filters: names.append('fp_over_fs::{0}'.format(phot_filter)) - print_names.append(r'$F_\mathrm{{p}}/F_*$::{0}'.format(phot_filter)) + print_names.append(r'F_\mathrm{{p}}/F_*::{0}'.format(phot_filter)) initial.append(unique_filters[phot_filter]) limits1.append(unique_filters[phot_filter] * fit_fp_over_fs_limits[0]) limits2.append(unique_filters[phot_filter] * fit_fp_over_fs_limits[1]) @@ -1120,7 +1119,7 @@ def eclipse_fitting(self, output_folder=None, else: phot_filter = list(unique_filters.keys())[0] names.append('fp_over_fs') - print_names.append(r'$F_\mathrm{{p}}/F_*$') + print_names.append(r'F_\mathrm{{p}}/F_*') initial.append(unique_filters[phot_filter]) limits1.append(unique_filters[phot_filter] * fit_fp_over_fs_limits[0]) limits2.append(unique_filters[phot_filter] * fit_fp_over_fs_limits[1]) @@ -1133,7 +1132,7 @@ def eclipse_fitting(self, output_folder=None, if fit_rp_over_rs and fit_individual_rp_over_rs: for phot_filter in unique_filters: names.append('rp_ovr_rs::{0}'.format(phot_filter)) - print_names.append(r'$R_\mathrm{{p}}/R_*$::{0}'.format(phot_filter)) + print_names.append(r'R_\mathrm{{p}}/R_*::{0}'.format(phot_filter)) initial.append(self.rp_over_rs) limits1.append(fit_rp_over_rs_limits[0]) limits2.append(fit_rp_over_rs_limits[1]) @@ -1151,7 +1150,7 @@ def eclipse_fitting(self, output_folder=None, else: global_parameters_names = ['rp_over_rs'] - global_parameters_print_names = [r'$R_\mathrm{p}/R_*$'] + global_parameters_print_names = [r'R_\mathrm{p}/R_*'] global_parameters_initial = [self.rp_over_rs] global_parameters_fit = [fit_rp_over_rs] global_parameters_limits = [fit_rp_over_rs_limits] @@ -1160,7 +1159,7 @@ def eclipse_fitting(self, output_folder=None, # orbital parameters global_parameters_names += ['period', 'sma_over_rs', 'eccentricity', 'inclination', 'periastron'] - global_parameters_print_names += [r'$P$', r'$a$', r'$e$', r'$i$', r'$\omega$'] + global_parameters_print_names += ['P', 'a', 'e', 'i', r'\omega'] global_parameters_initial += [self.period, self.sma_over_rs, self.eccentricity, self.inclination, self.periastron] global_parameters_fit += [fit_period, fit_sma_over_rs, False, fit_inclination, False] global_parameters_limits += [fit_period_limits, fit_sma_over_rs_limits, False, fit_inclination_limits, False] @@ -1181,7 +1180,7 @@ def eclipse_fitting(self, output_folder=None, new_mid_time = self.eclipse_mid_time() + new_epoch * self.period global_parameters_names += ['eclipse_mid_time'] - global_parameters_print_names += [r'$T_\mathrm{ec}$'] + global_parameters_print_names += [r'T_\mathrm{ec}'] global_parameters_initial += [new_mid_time] global_parameters_fit += [fit_mid_time] global_parameters_limits += [[new_mid_time + fit_mid_time_limits[0], new_mid_time + fit_mid_time_limits[1]]] @@ -1209,7 +1208,7 @@ def eclipse_fitting(self, output_folder=None, for epoch in unique_epochs: names.append('eclipse_mid_time::{0}'.format(epoch)) - print_names.append(r'$T_\mathrm{{ec}}$::{0}'.format(epoch)) + print_names.append(r'T_\mathrm{{ec}}::{0}'.format(epoch)) initial.append(eclipse_mid_time + epoch * self.period) limits1.append(eclipse_mid_time + epoch * self.period + fit_mid_time_limits[0]) limits2.append(eclipse_mid_time + epoch * self.period + fit_mid_time_limits[1]) @@ -1237,7 +1236,7 @@ def single_observation_full_model(indices, *model_variables): single_observation_full_model, initial, limits1, limits2, logspace=logspace, data_x_name='time', data_y_name='flux', - data_x_print_name=r'$t_{BJD_{TDB}}$', data_y_print_name='Relative Flux', + data_x_print_name='t_{BJD_{TDB}}', data_y_print_name='Relative Flux', parameters_names=names, parameters_print_names=print_names, walkers=walkers, iterations=iterations, burn_in=burn_in, counter=counter, @@ -1293,7 +1292,7 @@ def full_model(model_time, *model_variables): fitting = Fitting(model_time, model_flux, model_flux_unc, full_model, initial, limits1, limits2, data_x_name='time', data_y_name='flux', - data_x_print_name=r'$t_{BJD_{TDB}}$', data_y_print_name='Relative Flux', + data_x_print_name='t_{BJD_{TDB}}', data_y_print_name='Relative Flux', parameters_names=names, parameters_print_names=print_names, walkers=walkers, iterations=iterations, burn_in=burn_in, counter=counter, @@ -1321,7 +1320,7 @@ def full_model(model_time, *model_variables): 'filter_outliers': filter_outliers, 'optimiser': optimiser, 'data_x_name': 'time', - 'data_x_print_name': r't_${BJD_{TDB}}$', + 'data_x_print_name': 't_{BJD_{TDB}}', 'data_y_name': 'flux', 'data_y_print_name': 'Relative Flux', 'fit_individual_fp_over_fs': fit_individual_fp_over_fs, diff --git a/pylightcurve/models/exoplanet_lc.py b/pylightcurve/models/exoplanet_lc.py index 756189d..6800290 100644 --- a/pylightcurve/models/exoplanet_lc.py +++ b/pylightcurve/models/exoplanet_lc.py @@ -101,13 +101,14 @@ def planet_phase(period, mid_time, time_array): phase = (time_array - mid_time)/period - return phase - np.int_(phase) + return phase - np.round(phase, 0) # flux drop - new + class Integrals: - def __init__(self, rprs, limb_darkening_coefficients, method, precision): + def __init__(self, rprs, limb_darkening_coefficients, ldc_method, precision): self.rprs = rprs self.limb_darkening_coefficients = limb_darkening_coefficients @@ -118,12 +119,12 @@ def __init__(self, rprs, limb_darkening_coefficients, method, precision): 'power2': self.kappa_power2, 'claret': self.kappa_claret, 'eclipse': self.kappa_eclipse - }[method] + }[ldc_method] self.a1 = limb_darkening_coefficients[0] - if method != 'linear': + if ldc_method != 'linear': self.a2 = limb_darkening_coefficients[1] - if method == 'claret': + if ldc_method == 'claret': self.a3 = limb_darkening_coefficients[2] self.a4 = limb_darkening_coefficients[3] @@ -185,10 +186,9 @@ def integral_kappa_r(self, u1, u2, spoint, sign, z, zsq): ) +def transit_flux_drop(limb_darkening_coefficients, rp_over_rs, z_over_rs, ldc_method, precision, spoint=None): -def transit_flux_drop(limb_darkening_coefficients, rp_over_rs, z_over_rs, method, precision, spoint=None): - - integral_class = Integrals(rp_over_rs, limb_darkening_coefficients, method, precision) + integral_class = Integrals(rp_over_rs, limb_darkening_coefficients, ldc_method, precision) len_z_over_rs = len(z_over_rs) @@ -222,24 +222,11 @@ def transit_flux_drop(limb_darkening_coefficients, rp_over_rs, z_over_rs, method u2[case4] = np.arccos((1.0 - rp_over_rs ** 2 + zsq[case4]) / (2.0 * z_over_rs[case4])) u2[case5] = 2*np.pi - np.arccos((1.0 - rp_over_rs ** 2 + zsq[case5]) / (2.0 * z_over_rs[case5])) - if precision =='ref': + if precision == 'ref': spoint_minus = np.ones(len_z_over_rs) * 0.999 spoint_plus = np.ones(len_z_over_rs) * 0.999 else: if not spoint: - # spoint = [ - # 0.9218282226562504, - # 0.9563458007812503, - # 0.9834234375000003, - # 0.9906437500000003, - # 0.9940283203125003, - # 0.9957342773437505, - # 0.9967330078125005, - # 0.9975126953125002, - # 0.9979268554687502, - # 0.9983170898437501, - # 0.9985122070312502, - # ][precision] spoint = [ 0.9225257991338730, 0.9563656913370522, @@ -277,7 +264,11 @@ def transit_flux_drop(limb_darkening_coefficients, rp_over_rs, z_over_rs, method # transit def transit(limb_darkening_coefficients, rp_over_rs, period, sma_over_rs, eccentricity, inclination, periastron, - mid_time, time_array, method='claret', precision=2): + mid_time, time_array, ldc_method='claret', precision=2, method=None): + + # for compatibility with iraclis 1.xx.xx + if method: + ldc_method = method position_vector = planet_orbit(period, sma_over_rs, eccentricity, inclination, periastron, mid_time, time_array) @@ -285,11 +276,16 @@ def transit(limb_darkening_coefficients, rp_over_rs, period, sma_over_rs, eccent position_vector[0] < 0, 1.0 + 10.0 * rp_over_rs, np.sqrt(position_vector[1] * position_vector[1] + position_vector[2] * position_vector[2])) - return transit_flux_drop(limb_darkening_coefficients, rp_over_rs, projected_distance, method, precision) + return transit_flux_drop(limb_darkening_coefficients, rp_over_rs, projected_distance, ldc_method, precision) def transit_integrated(limb_darkening_coefficients, rp_over_rs, period, sma_over_rs, eccentricity, inclination, - periastron, mid_time, time_array, exp_time, max_sub_exp_time=10, method='claret', precision=2): + periastron, mid_time, time_array, exp_time, max_sub_exp_time=10, ldc_method='claret', + precision=2, method=None): + + # for compatibility with iraclis 1.xx.xx + if method: + ldc_method = method time_factor = int(exp_time / max_sub_exp_time) + 1 exp_time /= (60.0 * 60.0 * 24.0) @@ -305,7 +301,7 @@ def transit_integrated(limb_darkening_coefficients, rp_over_rs, period, sma_over np.sqrt(position_vector[1] * position_vector[1] + position_vector[2] * position_vector[2])) return np.mean(np.reshape( - transit_flux_drop(limb_darkening_coefficients, rp_over_rs, projected_distance, method, precision), + transit_flux_drop(limb_darkening_coefficients, rp_over_rs, projected_distance, ldc_method, precision), (len(time_array), time_factor)), 1) @@ -350,10 +346,14 @@ def function_to_fit(x, t): def transit_depth(limb_darkening_coefficients, rp_over_rs, period, sma_over_rs, eccentricity, inclination, - periastron, method='claret', precision=2): + periastron, ldc_method='claret', precision=2, method=None): + + # for compatibility with iraclis 1.xx.xx + if method: + ldc_method = method return 1 - transit(limb_darkening_coefficients, rp_over_rs, period, sma_over_rs, eccentricity, inclination, - periastron, 10000, np.array([10000]), method, precision)[0] + periastron, 10000, np.array([10000]), ldc_method, precision)[0] # eclipse @@ -471,8 +471,8 @@ def _black_body(w, t): return reflection + emission -def exotethys(stellar_logg, stellar_temperature, stellar_metallicity, filter_name, wlrange=None, method='claret', - stellar_model='Phoenix_2018'): +def exotethys(stellar_logg, stellar_temperature, stellar_metallicity, filter_name, wlrange=None, + ldc_method='claret', stellar_model='Phoenix_2018', method=None): """Calculates the limb-darkening coefficients for the host star, by calling the ExoTehys package. Not all the combinations of filters and stellar models are available. This will depend on the stellar temperature, the stellar model and the wavelength range of the filter. @@ -484,14 +484,18 @@ def exotethys(stellar_logg, stellar_temperature, stellar_metallicity, filter_nam :type filter_name: str :param wlrange: A 2-element list, defining the wavelength range (in Angstrom) within the filter, Useful for spectroscopic observations. :type wlrange: list - :param method: Limb-darkening model to de used. Available methods: claret, power2, quad, linear, - :type method: str + :param ldc_method: Limb-darkening model to de used. Available methods: claret, power2, quad, linear, + :type ldc_method: str :param stellar_model: Stellar model to be used. Available methods: check ExoTethys documentation. :type stellar_model: str :return: Limb-darkening coefficients. Four coefficients are always returned (for methods that need less than four coefficents, the rest are 0). :rtype: numpy.ndarray """ + # for compatibility with iraclis 1.xx.xx + if method: + ldc_method = method + if 'phoenix' in stellar_model.lower() and stellar_metallicity != 0: logging.warning('\nPHOENIX models are only computed for solar metallicity stars. ' 'Setting stellar_metallicity = 0.\n') @@ -512,9 +516,9 @@ def exotethys(stellar_logg, stellar_temperature, stellar_metallicity, filter_nam 'quad': 'quadratic', 'linear': 'linear' } - if method not in method_map: + if ldc_method not in method_map: raise PyLCInputError('Method {0} is not valid. Available methods: {1}'.format( - method, ','.join(list(method_map.keys())))) + ldc_method, ','.join(list(method_map.keys())))) run_id = ''.join([str(np.random.randint(0, 99)) for ff in range(10)]) bandpass_file = os.path.join(path, 'ww_{0}.pass'.format(run_id)) @@ -528,7 +532,7 @@ def exotethys(stellar_logg, stellar_temperature, stellar_metallicity, filter_nam r = r.replace('{{output}}', path) r = r.replace('{{id}}', str(run_id)) r = r.replace('{{model}}', stellar_model) - r = r.replace('{{law}}', method_map[method]) + r = r.replace('{{law}}', method_map[ldc_method]) r = r.replace('{{teff}}', str(stellar_temperature)) r = r.replace('{{logg}}', str(stellar_logg)) r = r.replace('{{meta}}', str(stellar_metallicity)) @@ -545,7 +549,7 @@ def exotethys(stellar_logg, stellar_temperature, stellar_metallicity, filter_nam for ff in glob.glob(os.path.join(path, '*{0}*'.format(run_id))): os.remove(ff) - ldcs = results['passbands']['ww_{0}.pass'.format(run_id)][method_map[method]]['coefficients'] + ldcs = results['passbands']['ww_{0}.pass'.format(run_id)][method_map[ldc_method]]['coefficients'] while len(ldcs) < 4: ldcs = np.append(ldcs, 0) @@ -554,7 +558,7 @@ def exotethys(stellar_logg, stellar_temperature, stellar_metallicity, filter_nam except: plc_data.reset_exotethys_data() - return exotethys(stellar_logg, stellar_temperature, stellar_metallicity, filter_name, wlrange, method, + return exotethys(stellar_logg, stellar_temperature, stellar_metallicity, filter_name, wlrange, ldc_method, stellar_model) diff --git a/pylightcurve/plots/plots_fitting.py b/pylightcurve/plots/plots_fitting.py index 871e083..5d8e764 100644 --- a/pylightcurve/plots/plots_fitting.py +++ b/pylightcurve/plots/plots_fitting.py @@ -138,7 +138,7 @@ def plot_mcmc_corner(fitting_object, export_file): ax.tick_params(left=False, right=False, top=False, bottom=False, labelbottom=False, labelleft=False) ax.set_xlabel( - r'{0}\n'.format(names[var]) + + r'${0}$'.format(names[var]) + '\n' + r'${0}_{{-{1}}}^{{+{2}}}$'.format( print_results[var], print_errors1[var], print_errors2[var]) , fontsize=fontsize, ha='right', x=0.8) @@ -195,7 +195,7 @@ def plot_mcmc_traces(fitting_object, export_file): # ax.tick_params(left=False, right=False, labelleft=False) ax.set_title( - r'{0}\n'.format(fitting_object.results['parameters'][var]['print_name']) + + r'${0}$'.format(fitting_object.results['parameters'][var]['print_name']) + '\n' + r'${0}_{{-{1}}}^{{+{2}}}$'.format(fitting_object.results['parameters'][var]['print_value'], fitting_object.results['parameters'][var]['print_m_error'], fitting_object.results['parameters'][var]['print_p_error']) diff --git a/tests/test_emcee.zip b/tests/test_emcee.zip index 7f443e4..8b9e3dd 100644 Binary files a/tests/test_emcee.zip and b/tests/test_emcee.zip differ diff --git a/tests/test_models_exoplanet_lc.py b/tests/test_models_exoplanet_lc.py index b8fb76e..09bdb90 100644 --- a/tests/test_models_exoplanet_lc.py +++ b/tests/test_models_exoplanet_lc.py @@ -102,19 +102,19 @@ def test_exoplanet_lc(): limb_darkening_coefficients = plc.exotethys(stellar_logg, stellar_temperature, stellar_metallicity, photometric_filter, - method=method, stellar_model=stellar_model) + ldc_method=method, stellar_model=stellar_model) assert len(limb_darkening_coefficients) == 4 transit = plc.transit(limb_darkening_coefficients, rp_over_rs, period, sma_over_rs, eccentricity, inclination, - periastron, mid_time, time_array, method=method) + periastron, mid_time, time_array, ldc_method=method) assert min(transit) > 0.98 assert max(transit) == 1.0 transit_integrated = plc.transit_integrated(limb_darkening_coefficients, rp_over_rs, period, sma_over_rs, eccentricity, inclination, periastron, mid_time, time_array, - 30, max_sub_exp_time=10, method=method, precision=3) + 30, max_sub_exp_time=10, ldc_method=method, precision=3) assert min(transit_integrated) > 0.98 assert max(transit_integrated) == 1.0 @@ -142,19 +142,19 @@ def test_exoplanet_lc(): with pytest.raises(plc.PyLCError): plc.exotethys(stellar_logg, stellar_temperature, stellar_metallicity, 'bla', - method='claret', stellar_model=stellar_model) + ldc_method='claret', stellar_model=stellar_model) with pytest.raises(plc.PyLCError): plc.exotethys(stellar_logg, stellar_temperature, stellar_metallicity, photometric_filter, - method='bla', stellar_model=stellar_model) + ldc_method='bla', stellar_model=stellar_model) with pytest.raises(plc.PyLCError): plc.exotethys(stellar_logg, stellar_temperature, stellar_metallicity, photometric_filter, - method='claret', stellar_model='bla') + ldc_method='claret', stellar_model='bla') with pytest.raises(plc.PyLCError): plc.exotethys(stellar_logg, stellar_temperature, stellar_metallicity, photometric_filter, - method='claret', stellar_model=stellar_model, wlrange=[5, 10]) + ldc_method='claret', stellar_model=stellar_model, wlrange=[5, 10]) with pytest.raises(plc.PyLCError): plc.fp_over_fs(rp_over_rs, sma_over_rs, 0.2, 1.0, stellar_temperature, 'bla') @@ -162,7 +162,7 @@ def test_exoplanet_lc(): with pytest.raises(plc.PyLCError): plc.fp_over_fs(rp_over_rs, sma_over_rs, 0.2, 1.0, stellar_temperature, photometric_filter, wlrange=[5, 10]) - assert len(plc.exotethys(stellar_logg, stellar_temperature, 0.1, 'JOHNSON_V', method='claret', + assert len(plc.exotethys(stellar_logg, stellar_temperature, 0.1, 'JOHNSON_V', ldc_method='claret', stellar_model=stellar_model)) == 4 assert round(plc.convert_to_bjd_tdb(ra, dec, 2458485.0, 'JD_UTC'), 7) == 2458485.0046340