{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Getting Started : Basic Inputs and Outputs\n", "\n", "If you are here then you have already successfully \n", "\n", "1) Installed the code\n", "\n", "2) Downloaded the necessary reference data\n", "\n", "3) Added ``export picaso_refdata=\"/path/to/picaso/reference\"`` to ~/.bash_profile\n", "\n", "If you have not done these things, please return to [Installation Guilde](https://natashabatalha.github.io/picaso/installation.html)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#picaso\n", "from picaso import justdoit as jdi \n", "from picaso import justplotit as jpi\n", "import numpy as np\n", "\n", "jpi.output_notebook()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#double check that your reference file path has been set \n", "import os\n", "refdata = os.getenv(\"picaso_refdata\")\n", "print(refdata)\n", "#if you are having trouble setting this you can do it right here in the command line\n", "#os.environ[\"picaso_refdata\"]= add your path here AND COPY AND PASTE ABOVE \n", "#IT WILL NEED TO GO ABOVE YOUR PICASO IMPORT" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Connect to Opacity Database\n", "\n", "There is a full notebook in the tutorials devoted to learning how to make opacity databases in our format. If you cloned from `github`, there should also be an opacity database there called `opacity.db`. " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "help(jdi.opannection)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`opannection` has a few default parameters. A few notes: \n", "\n", " 1) `wave_range` can be used to select a subset of the full opacity database you are using\n", " \n", " 2) `filename_db` is a sqlite database that should have been downloaded and stored with your reference data (see [Installation Documentation](https://natashabatalha.github.io/picaso/installation.html))\n", " \n", " 3) `raman_db` is a small file that should already be in your reference folder from Github." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "opacity = jdi.opannection(wave_range=[0.3,1]) #lets just use all defaults" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Load blank slate" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "start_case = jdi.inputs()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In order to run the code we need (at the minimum) specific info about the:\n", "\n", "- **phase angle** \n", "\n", "- **planet** : gravity\n", "\n", "- **star** : temperature, metallicity, gravity\n", "\n", "- **atmosphere** : P-T profile, chemical composition, cloud properties (discussed later)\n", "\n", "Additionally, we have some optional parameters that will be discussed in later notebooks: \n", "\n", "- **approx** : approximations to rapidly compute reflected light \n", "\n", "- **disco** : number of individual facets you want to compute before integrating to 1D spectrum (think disco ball) \n", "\n", "- **opacities** : keeping track of opacity files used \n", "\n", "- **test_mode** : used to do benchmark testing " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Set Planet & Star Properties " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#phase angle \n", "start_case.phase_angle(0) #radians\n", "\n", "#define gravity\n", "start_case.gravity(gravity=25, gravity_unit=jdi.u.Unit('m/(s**2)')) #any astropy units available\n", "\n", "#define star \n", "start_case.star(opacity, 5000,0,4.0) #opacity db, pysynphot database, temp, metallicity, logg " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Set Atmospheric Composition\n", "\n", "There are different options for setting atmospheric composition. \n", "\n", " 1) Specifying a file path to model run \n", " 2) Give arbitrary pressure, temperature and composition directly as a dictionary input \n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Option 1) Specify file path \n", "\n", "Below, I am loading in a profile path for Jupiter that should be included in your reference data" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(jdi.jupiter_pt()) #should return the path to your reference data" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "start_case.atmosphere(filename=jdi.jupiter_pt(), delim_whitespace=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### File format\n", "\n", "1) Must have **pressure**(bars), **temperature**(Kelvin), and `case sensitive` molecule names (e.g. TiO, Na, H2O, etc) for mixing ratios (in no particular order)\n", "\n", "2) Can specify any necessary key word arguments for pd.read_csv at the end\n", "\n", "**PICASO will auto-compute mixing ratios, determine what CIA is neceesary and compute mean molecular weight based on these headers. Take at the preloaded example below**" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#to give you an idea\n", "comp_file = jdi.pd.read_csv(jdi.jupiter_pt(), delim_whitespace=True) \n", "#see example below\n", "comp_file.head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Create 1D Reflected Light Spectrum\n", "\n", "Let's create our first spectrum of Jupiter's reflected light at full phase" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df = start_case.spectrum(opacity)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Checkout out what was returned (Note this is a change in v1.0)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df.keys()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Regrid Opacities to Constant Resolution\n", " " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "wno, alb, fpfs = df['wavenumber'] , df['albedo'] , df['fpfs_reflected'] \n", "wno, alb = jdi.mean_regrid(wno, alb , R=150)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "jpi.show(jpi.spectrum(wno, alb, plot_width=500,x_range=[0.3,1]))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "FpFs is the relative flux of the planet and star or : \n", "\n", "$\\frac{f_p}{f_s} = a_\\lambda \\left( \\frac{ r_p}{a} \\right) ^2$\n", "\n", "where $a$ is the semi-major axis. You may have noticed that **we did not supply a radius or semi-major axis in the above code**. Therefore, if you print out $\\frac{f_p}{f_s}$ you will see this: " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fpfs" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's add this to the star function so we can get the relative flux as well.." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "start_case.star(opacity, 5000,0,4.0,semi_major=1, semi_major_unit=jdi.u.Unit('au'))\n", "start_case.gravity(radius=1, radius_unit=jdi.u.Unit('R_jup'), \n", " mass = 1, mass_unit=jdi.u.Unit('M_jup'))\n", "df = start_case.spectrum(opacity)\n", "wno, alb, fpfs = df['wavenumber'] , df['albedo'] , df['fpfs_reflected'] " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fpfs" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Option 2) Arbitrary PT and Chemistry\n", "\n", "Sometimes for testing (or for atmospheres that we don't fully understand) an isothermal, well-mixed profile is sufficient. If we don't want to load in a full profile, we can give it a simple DataFrame with the info we need. \n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "start_case.atmosphere( df = jdi.pd.DataFrame({'pressure':np.logspace(-6,2,60),\n", " 'temperature':np.logspace(-6,2,60)*0+200,\n", " \"H2\":np.logspace(-6,2,60)*0+0.837,\n", " \"He\":np.logspace(-6,2,60)*0+0.163,\n", " \"CH4\":np.logspace(-6,2,60)*0+0.000466})\n", " )" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df = start_case.spectrum(opacity)\n", "wno_ch4, alb_ch4, fpfs = df['wavenumber'] , df['albedo'] , df['fpfs_reflected'] \n", "wno_ch4, alb_ch4 = jdi.mean_regrid(wno_ch4, alb_ch4 , R=150)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "jpi.show(jpi.spectrum(wno_ch4, alb_ch4, plot_width=500,x_range=[0.3,1]))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "See how the plot above is much easier to interpret than the one with the full set of molecular input. Here we can clearly see the effects of methane opacity, raman and rayleigh scattering (the next notebook will include a tutorial for more diagnostic plotting)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Diagnostic help: Sometimes it helps to exclude molecule to see how it is influencing the spectrum\n", "\n", "Take a look below" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "start_case.atmosphere(filename=jdi.jupiter_pt(), exclude_mol='H2O', delim_whitespace=True)\n", "\n", "df = start_case.spectrum(opacity)\n", "wno_nowater, alb_nowater, fpfs = df['wavenumber'] , df['albedo'] , df['fpfs_reflected'] \n", "wno_nowater, alb_nowater= jdi.mean_regrid(wno_ch4, alb_ch4 , R=150)\n", "fig = jpi.spectrum(wno, alb, plot_width=500)\n", "fig.line(1e4/wno_nowater, alb_nowater, line_width=2, color='red')\n", "jpi.show(fig)" ] } ], "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.8.12" }, "nbsphinx": { "execute": "always" }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": true, "sideBar": true, "skip_h1_title": false, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": true, "toc_position": {}, "toc_section_display": true, "toc_window_display": false }, "varInspector": { "cols": { "lenName": 16, "lenType": 16, "lenVar": 40 }, "kernels_config": { "python": { "delete_cmd_postfix": "", "delete_cmd_prefix": "del ", "library": "var_list.py", "varRefreshCmd": "print(var_dic_list())" }, "r": { "delete_cmd_postfix": ") ", "delete_cmd_prefix": "rm(", "library": "var_list.r", "varRefreshCmd": "cat(var_dic_list()) " } }, "types_to_exclude": [ "module", "function", "builtin_function_or_method", "instance", "_Feature" ], "window_display": false } }, "nbformat": 4, "nbformat_minor": 2 }