{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Advanced Rooki Usage" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Use enviroment to change rooki config" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import os\n", "from rooki import rooki, reinit\n", "os.environ['ROOK_URL'] = 'http://rook.dkrz.de/wps'\n", "# os.environ['ROOK_URL'] = 'http://localhost:5000/wps'\n", "# mode: sync or async\n", "# os.environ['ROOK_MODE'] = 'async'" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# change default download folder\n", "os.environ['ROOKI_OUTPUT_DIR'] = '/tmp/rooki'" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# HINT: re-init rooki!\n", "reinit()\n", "rooki.url" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "rooki.output_dir" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "resp = rooki.subset(\n", " collection='c3s-cmip6.CMIP.IPSL.IPSL-CM6A-LR.historical.r1i1p1f1.Amon.rlds.gr.v20180803', \n", " time='1985-01-01/2014-12-30')\n", "resp.ok" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# number of files to download\n", "resp.num_files" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# total size of all files in bytes\n", "resp.size" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "resp.size_in_mb" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "resp.download_urls()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "files = resp.download()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Use Rooki client" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from rooki.client import Rooki\n", "url='http://rook.dkrz.de/wps'\n", "# url='http://localhost:5000/wps'\n", "\n", "rooki = Rooki(url, mode='async', output_dir='/tmp/rooki')\n", "rooki.url" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "resp = rooki.subset(\n", " collection='c3s-cmip6.CMIP.IPSL.IPSL-CM6A-LR.historical.r1i1p1f1.Amon.rlds.gr.v20180803', \n", " time='1985-01-01/2014-12-30')\n", "resp.ok" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# total size\n", "resp.size_in_mb" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# download files\n", "files = resp.download()\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "files[0]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# open as xarray dataset\n", "dsets = resp.datasets()\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ds = dsets[0]\n", "ds" ] } ], "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.9.5" } }, "nbformat": 4, "nbformat_minor": 4 }