{ "cells": [ { "cell_type": "markdown", "id": "139bb3ef", "metadata": {}, "source": [ "# Model Storage: Preservation and Reuse \n", "\n", "Storing data is often tricky. You may be wondering what output to save, what output to throw away. You may also have questions surround what formats to use to store your data. \n", "\n", "PICASO's recommended model output is `xarray`. There are several `xarray` tutorials throughout the picaso documentation. [The most thorough is in the data uniformity tutorial](https://natashabatalha.github.io/picaso/notebooks/codehelp/data_uniformity_tutorial.html). \n", "\n", "Here you will learn how to use a nifty picaso function that will store your the **minimum data needed to reproduce your 1D spectrum**. The one caveat is that we will not store opacity data. However, you can always get your reference opacity data using the [auto citation tools](https://natashabatalha.github.io/picaso/notebooks/References.html). \n", "\n", "For this tutorial we assume you already know the basics of running 1D models. Note that we have still not enabled this functionality for 3D and 4D runs. Please contact the developers if you are interested in this functionality. " ] }, { "cell_type": "code", "execution_count": null, "id": "a4ec01e3", "metadata": {}, "outputs": [], "source": [ "import picaso.justdoit as jdi\n", "import picaso.justplotit as jpi\n", "u = jdi.u #astropy units" ] }, { "cell_type": "markdown", "id": "82d6ecaf", "metadata": {}, "source": [ "## Storing your run with xarray\n", "\n", "Here we show a simple example of how to use the `output_xarray` function for preservation" ] }, { "cell_type": "code", "execution_count": null, "id": "e8273189", "metadata": {}, "outputs": [], "source": [ "opa = jdi.opannection(wave_range=[0.3,1])\n", "pl = jdi.inputs()#calculation='brown')\n", "pl.gravity(radius=1, radius_unit=u.Unit('R_jup'), \n", " mass=1, mass_unit=u.Unit('M_jup'))\n", "pl.atmosphere(filename=jdi.jupiter_pt(), sep='\\s+')\n", "pl.phase_angle(0)\n", "pl.clouds(filename=jdi.jupiter_cld(), sep='\\s+')\n", "pl.star(opa, 5000,0,4, radius=1, radius_unit=u.Unit(\"R_sun\"), semi_major=1, semi_major_unit=1*u.AU)\n", "#MUST USE full output=True for this functionality\n", "df= pl.spectrum(opa, calculation='reflected', full_output=True)\n" ] }, { "cell_type": "code", "execution_count": null, "id": "9dda4aa4", "metadata": {}, "outputs": [], "source": [ "preserve = jdi.output_xarray(df,pl,savefile='/data/picaso_dbs/model.nc')" ] }, { "cell_type": "code", "execution_count": null, "id": "3189ce39", "metadata": {}, "outputs": [], "source": [ "preserve" ] }, { "cell_type": "markdown", "id": "51aa5fce", "metadata": {}, "source": [ "## Reusing your run with xarray\n", "\n", "We often revisit models time and time again. Maybe you want to change your wavelength range, or observing geometry (e.g. transit vs emission). \n", "\n", "Here we show a simple example of how to use the `input_xarray` function for reuse. In this simple example, we will take our previous input but instead of computing reflected light, add thermal emission and transmission" ] }, { "cell_type": "code", "execution_count": null, "id": "b924c648", "metadata": {}, "outputs": [], "source": [ "opa = jdi.opannection(wave_range=[0.3,14])\n", "ds = jdi.xr.load_dataset('/data/picaso_dbs/model.nc')\n", "reuse = jdi.input_xarray(ds, opa)\n", "new_model = reuse.spectrum(opa, calculation='reflected+thermal', full_output=True)" ] }, { "cell_type": "code", "execution_count": null, "id": "7b531f30", "metadata": {}, "outputs": [], "source": [ "new_output= jdi.output_xarray(new_model, reuse)" ] }, { "cell_type": "code", "execution_count": null, "id": "67842f86", "metadata": {}, "outputs": [], "source": [ "new_output" ] }, { "cell_type": "markdown", "id": "662c1355", "metadata": {}, "source": [ "## Adding meta data\n", "\n", "We have a tutorial that shows what some recommended meta data might be. `output_xarray` has a field `add_output` that allows you to add extra arguments to the `xarray.Dataset.attrs`. However, it has to be in a very specific format. \n", "\n", "You can see the basic format by running this function: \n", "\n" ] }, { "cell_type": "code", "execution_count": null, "id": "26c9ae51", "metadata": {}, "outputs": [], "source": [ "jdi.standard_metadata()" ] }, { "cell_type": "code", "execution_count": null, "id": "d0d934ff", "metadata": {}, "outputs": [], "source": [ "opa = jdi.opannection(wave_range=[0.3,1])\n", "pl = jdi.inputs()#calculation='brown')\n", "pl.gravity(radius=1, radius_unit=u.Unit('R_jup'), \n", " mass=1, mass_unit=u.Unit('M_jup'))\n", "mh = 0 \n", "cto = 1\n", "\n", "pl.atmosphere(filename=jdi.jupiter_pt(), sep='\\s+') \n", "pl.chemeq_visscher(cto, mh)\n", "pl.phase_angle(0)\n", "pl.clouds(filename=jdi.jupiter_cld(), sep='\\s+')\n", "pl.star(opa, 5000,0,4, radius=1, radius_unit=u.Unit(\"R_sun\"), semi_major=1, semi_major_unit=1*u.AU)\n", "#MUST USE full output=True for this functionality\n", "df= pl.spectrum(opa, calculation='reflected', full_output=True)\n", "\n", "preserve = jdi.output_xarray(df,pl,add_output={\n", " 'author':\"Awesome Scientist\",\n", " 'contact' : \"awesomescientist@universe.com\",\n", " 'code' : \"picaso\", \n", " 'planet_params':{'mh':mh, 'co':cto}, \n", " 'cloud_params':{'fsed':3}\n", "})\n" ] }, { "cell_type": "code", "execution_count": null, "id": "ad0972e0", "metadata": {}, "outputs": [], "source": [ "preserve" ] }, { "cell_type": "code", "execution_count": null, "id": "e396a6c8", "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" }, "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": 5 }