{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Welcome to ATMOS\n",
    "\n",
    "This package is an archive of scientific routines that estimates the vertical structure of atmosphere with various *atmospheric density models*, such as **Exponential**(-0.611\\~1000 km), **COESA76**(-0.611\\~1000 km), **NRLMSISE-00**(0\\~2000 km), and **JB2008**(90\\~2500 km). "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## How to install\n",
    "\n",
    "On Linux, macOS and Windows architectures, the binary wheels can be installed using pip by executing one of the following commands:\n",
    "\n",
    "```python\n",
    "pip install pyatmos\n",
    "pip install pyatmos --upgrade # to upgrade a pre-existing installation\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## How to use"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Exponential"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1.22500000e+00 7.76098911e-02 3.97200000e-03 3.20600000e-04\n",
      " 1.90500000e-05]\n"
     ]
    }
   ],
   "source": [
    ">>> from pyatmos import expo\n",
    ">>> expo_geom = expo([0,20,40,60,80]) # geometric altitudes by default\n",
    ">>> print(expo_geom.rho) # [kg/m^3]\n",
    ">>> # expo_geop = expo([0,20,40,60,80],'geopotential') # geopotential altitudes"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### COESA 1976"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1.22499916e+00 8.89079563e-02 3.99535051e-03 3.09628985e-04\n",
      " 1.84514759e-05]\n",
      "[288.15       216.65       250.35120115 247.01740767 198.63418825]\n",
      "[1.01325000e+05 5.52919008e+03 2.87122194e+02 2.19548951e+01\n",
      " 1.05207648e+00]\n"
     ]
    }
   ],
   "source": [
    ">>> from pyatmos import coesa76\n",
    ">>> coesa76_geom = coesa76([0,20,40,60,80]) # geometric altitudes by default\n",
    ">>> print(coesa76_geom.rho) # [kg/m^3]\n",
    ">>> print(coesa76_geom.T) # [K]\n",
    ">>> print(coesa76_geom.P) # [Pa]\n",
    ">>> # coesa76_geop = coesa76([0,20,40,60,80],'geopotential') # geopotential altitudes"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### NRLMSISE-00"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "*Before using NRLMSISE-00, the space weather data needs to be prepared in advance.*"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The space weather data in /Users/lichunxiao/src/sw-data/ is already the latest.\n"
     ]
    }
   ],
   "source": [
    ">>> from pyatmos import download_sw_nrlmsise00,read_sw_nrlmsise00\n",
    ">>> # Download or update the space weather file from www.celestrak.com\n",
    ">>> swfile = download_sw_nrlmsise00() \n",
    ">>> # Read the space weather data\n",
    ">>> swdata = read_sw_nrlmsise00(swfile) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1.714115212984513e-14\n",
      "765.8976564552341\n",
      "{'He': 645851224907.2849, 'O': 456706971423.5056, 'N2': 531545420.00015724, 'O2': 2681352.1654067687, 'Ar': 406.9308900607773, 'H': 157249711103.90558, 'N': 6759664327.87355, 'ANM O': 10526544596.059282}\n"
     ]
    }
   ],
   "source": [
    ">>> from pyatmos import nrlmsise00\n",
    ">>> # Set a specific time and location\n",
    ">>> t = '2014-07-22 22:18:45' # time(UTC) \n",
    ">>> lat,lon,alt = 25,102,600 # latitude, longitude in [degree], and altitude in [km]\n",
    ">>> nrl00 = nrlmsise00(t,(lat,lon,alt),swdata)\n",
    ">>> print(nrl00.rho) # [kg/m^3]\n",
    ">>> print(nrl00.T) # [K]\n",
    ">>> print(nrl00.nd) # composition in [1/m^3]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### JB2008"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "*Before using JB2008, the space weather data needs to be prepared in advance.*"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The space weather data in /Users/lichunxiao/src/sw-data/ is already the latest.\n"
     ]
    }
   ],
   "source": [
    ">>> from pyatmos import download_sw_jb2008,read_sw_jb2008\n",
    ">>> # Download or update the space weather file from https://sol.spacenvironment.net\n",
    ">>> swfile = download_sw_jb2008() \n",
    ">>> # Read the space weather data\n",
    ">>> swdata = read_sw_jb2008(swfile) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1.2991711750265394e-14\n",
      "754.2803276187265\n"
     ]
    }
   ],
   "source": [
    ">>> from pyatmos import jb2008\n",
    ">>> # Set a specific time and location\n",
    ">>> t = '2014-07-22 22:18:45' # time(UTC) \n",
    ">>> lat,lon,alt = 25,102,600 # latitude, longitude in [degree], and altitude in [km]\n",
    ">>> jb08 = jb2008(t,(lat,lon,alt),swdata)\n",
    ">>> print(jb08.rho) # [kg/m^3]\n",
    ">>> print(jb08.T) # [K]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Change log\n",
    "\n",
    "- **1.2.3 — Jun 7, 2021**\n",
    "  - Added atmospheric models **JB2008**\n",
    "  - Changed the output of the result to an instance\n",
    "  - Improved the code structure for NRLMSISE-00, and the running speed is nearly threefold\n",
    "- **1.2.1 — Jan 22, 2021**\n",
    "  - Added **Exponential Atmosphere** up to 1000 km\n",
    "  - Added **Committee on Extension to the Standard Atmosphere(COESA)** up to 1000 km\n",
    "  - Completed part of the help documentation for NRLMSISE-00\n",
    "  - Improved the code structure to make it easier to read\n",
    "- **1.1.2 — Jul 26, 2020**\n",
    "  - Added colored-progress bar for downloading data\n",
    "- **1.1.0 — Mar 29,  2020**\n",
    "  - Added the International Standard Atmosphere(ISA) Model up to 86kms   \n",
    "\n",
    "## Next release\n",
    "\n",
    "- Complete the help documentation for NRLMSISE-00\n",
    "- Add other atmospheric models, such as the **Earth Global Reference Atmospheric Model(Earth-GRAM) 2016**, and the **Jacchia-Bowman 2008 Empirical Thermospheric Density Model(JB2008)**\n",
    "\n",
    "## Reference\n",
    "\n",
    "- U.S. Standard Atmosphere, 1976, U.S. Government Printing Office, Washington, D.C. \n",
    "- [Public Domain Aeronautical Software](http://www.pdas.com/atmos.html) \n",
    "- https://gist.github.com/buzzerrookie/5b6438c603eabf13d07e\n",
    "- https://ww2.mathworks.cn/help/aerotbx/ug/atmosisa.html\n",
    "- [Original Fortran and C code](https://ccmc.gsfc.nasa.gov/pub/modelweb/atmospheric/msis/)\n",
    "- [MSISE-00 in Python and Matlab](https://github.com/space-physics/msise00)\n",
    "- [NRLMSISE-00 Atmosphere Model - Matlab](https://ww2.mathworks.cn/matlabcentral/fileexchange/56253-nrlmsise-00-atmosphere-model?requestedDomain=zh)\n",
    "- [NRLMSISE-00 Atmosphere Model - Aerospace Blockset](https://www.mathworks.com/help/aeroblks/nrlmsise00atmospheremodel.html?requestedDomain=)\n",
    "- [NRLMSISE-00 Atmosphere Model - CCMC](https://ccmc.gsfc.nasa.gov/modelweb/models/nrlmsise00.php)\n",
    "- [NRLMSISE-00 empirical model of the atmosphere: Statistical comparisons and scientific issues](http://onlinelibrary.wiley.com/doi/10.1029/2002JA009430/pdf)\n",
    "- [ATMOSPHERIC MODELS](http://www.braeunig.us/space/atmmodel.htm)\n",
    "- [poliastro-Atmosphere module](https://docs.poliastro.space/en/latest/autoapi/poliastro/earth/atmosphere/index.html?highlight=poliastro.earth.atmosphere)\n",
    "- [ATMOSPHERE API](https://amentum.com.au/atmosphere)\n",
    "- [COSPAR International Reference Atmosphere - 2012](https://spacewx.com/wp-content/uploads/2021/03/chapters_1_3.pdf)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "py3.9",
   "language": "python",
   "name": "py3.9"
  },
  "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.9.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}