{ "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", "os.environ['ROOK_URL'] = 'http://cp4cds-cn1.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: restart to re-init rooki!\n", "from rooki import rooki\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-cmip5.output1.ICHEC.EC-EARTH.historical.day.atmos.day.r1i1p1.tas.latest', \n", " time='1880-01-01/1900-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://cp4cds-cn1.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-cmip5.output1.ICHEC.EC-EARTH.historical.day.atmos.day.r1i1p1.tas.latest', \n", " time='1850-01-01/2008-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.1" } }, "nbformat": 4, "nbformat_minor": 4 }