{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Example: Calculating atmospheric dispersion for H-band\n", "Using atmosphericModel.py is made as simple as importing the python package and calling its functions. Several parameters are needed, such as location, temperature, pressure and relative humidity. Then the dispersion model object is initiated, allowing us to calculate the index of refraction for any set of TPH and CO2 content values." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Installation\n", "We install the package using the `setup.py` file and running the following command:\n", "`python setup.py install`\n", "\n", "Now the package can be imported using `import AstroAtmosphere` in Python." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### How it works" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "#!/usr/bin/env Python\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "from AstroAtmosphere import *\n", "\n", "\n", "# Parameters at Cerro Armazones\n", "T = 279.65 # k\n", "P = 71200 # Pa\n", "H = 0.22\n", "xc = 450 # ppm\n", "lat = -24.5983 # degrees\n", "h = 3064 # m\n", "l1 = 1.49 # micron\n", "l2 = 1.78 # micron\n", "\n", "# Initializing dispersion model\n", "at = Observatory()\n", "\n", "# Calculating indices of refraction for l1 and l2\n", "n1 = at.n_tph(l=l1, T=T, p=P, RH=H, xc=xc)\n", "n2 = at.n_tph(l=l2, T=T, p=P, RH=H, xc=xc)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can also calculate the density of the air, which will be useful when calculating the scale height of the atmosphere, necessary for the refraction calculations." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "\n", "# Density of the atmosphere (following CIPM-81/91 equations)\n", "rho = at.rho(p=P, T=T, RH=H, xc=xc)\n", "\n", "# Initializing refraction model and setting the reduced height\n", "ref = refraction(lat, h)\n", "ref.setReducedHeight(P, rho)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The refraction for 1.49 um light at a zenith angle of 45 degrees, as calculated by the Cassini model, is found to be:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "The refraction is 40.697 arc seconds\n" ] } ], "source": [ "zenith_obs = 45\n", "refraction_obs = ref.cassini(n1, zenith_obs) * 3.6e3\n", "print ('The refraction is %.03f arc seconds' %(refraction_obs))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Some error propagation is included in the module as well. It takes is able to calculate the uncertainty in the refractive index and uses that to propagate it into the refraction formule for the cassini model. Note: The Cassini model is the only refraction model for which error propagation is possible, in this module.\n", "\n", "In this example we assume the following uncertainties:\n", "* Wavelength: 1 nm\n", "* Temperature: 0.2 K\n", "* Pressure: 30 Pa\n", "* Relative humidity: 0.03 (3%)\n", "* CO2 density: 25 ppm\n", "* Observed zenith angle: 1 arc second" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "The refraction is: 40.697 +/- 0.035 arc seconds\n" ] } ], "source": [ "# Calculating the uncertainty in the refractive index\n", "n1 = at.n_tph(l=l1, T=T, p=P, RH=H, xc=xc)\n", "dn1 = at.dn_tph(l1, T, P, H, xc, dl=0.001, dT=0.2, dP=30, dRH=0.03, dCO2=25)\n", "\n", "# Calculating the uncertainty in the atmospheric refraction\n", "refError = ref.cassiniError(n1, dn1, zenith_obs, dz=1/3600)*3.6e3\n", "print ('The refraction is: %.3f +/- %.3f arc seconds' %(refraction_obs, refError))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Dispersion is simply the refraction differential between two wavelengths. This is calculated with a dispersion object. Again, we can also calculate the uncertainty in the dispersion based on the measurement uncertainties. We take the same values as above.\n", "\n", "Note that, since the unertainties in the refractive index at two wavelengths observated at the same time are correlated, we cannot simply use n1, n2, dn1 and dn2 as an input but require the whole set of conditions and uncertainties." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "The dispersion is 31.019 +/- 0.164 milli arc seconds\n" ] } ], "source": [ "# Initializing dispersion object\n", "disp = dispersion(lat, h)\n", "disp.setReducedHeight(P, rho)\n", "\n", "dispersion_obs = disp.cassini(n1, n2, zenith_obs)*3.6e6\n", "\n", "# Calculating the uncertainty in the atmospheric dispersion\n", "dispersion_unc = disp.cassiniError(zenith_obs, l1, l2, T, P, H, xc, \n", " dl1=0.001, dl2=0.001, dT=0.2, dP=30, dRH=0.03, dCO2=25, dz=1/3600) * 3.6e6\n", "\n", "print ('The dispersion is %.03f +/- %.03f milli arc seconds' %(dispersion_obs, dispersion_unc))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "There are also some quick calculation functions defined in the `examples.py` file, if you just want to know the refractive index, the refraction or the dispersion at standard atmospheric conditions (`conditions='STANDARD'`) or at Cerro Armazones (`conditions='CERRO_ARMAZONES'`)." ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Quick refractive index: 1.0002733131243147\n", "Quick refraction: 40.697 arcsec\n", "Quick dispersion: 31.019 mas\n" ] } ], "source": [ "# Quick refractive index\n", "nq = quick_refractive_index(l=1.49, conditions='STANDARD')\n", "print('Quick refractive index: {}'.format(nq))\n", "\n", "# Quick refraction\n", "rq = quick_refraction(l1, zenith_obs, conditions='CERRO_ARMAZONES') * 3.6e3\n", "print('Quick refraction: {:.3f} arcsec'.format(rq))\n", "\n", "# Quick dispersion\n", "dq = quick_dispersion(l1, l2, zenith_obs, conditions='CERRO_ARMAZONES') * 3.6e6\n", "print('Quick dispersion: {:.3f} mas'.format(dq))\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.4" } }, "nbformat": 4, "nbformat_minor": 2 }