From 2e4d18f5027a6be2cfa7507aff54c3045d9c7978 Mon Sep 17 00:00:00 2001 From: Carsten Hinz <c.hinz@fz-juelich.de> Date: Tue, 7 May 2024 16:39:24 +0200 Subject: [PATCH] introduced option to add further options. --- README.md | 3 +++ tests/produce_data.ipynb | 50 ++++++++++++++-------------------------- 2 files changed, 20 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 82a98dd..aeae3c6 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,9 @@ Provides an example on how to download data, apply gridding and save the results A possible improvement for is the exchange of the AnalysisService with AnalysisServiceDownload, which caches requests from the TOARDB. This allows different griddings without the necessity to repeat the request to the TOARDB and subsequent download. +The example uses a dictionary to pass additional arguments to the request to the TAOR database. +A detailed list can be found at https://toar-data.fz-juelich.de/api/v2/#stationmeta + ## Retrieving data ``` tests/get_sample_data.ipynb diff --git a/tests/produce_data.ipynb b/tests/produce_data.ipynb index c604deb..7407066 100644 --- a/tests/produce_data.ipynb +++ b/tests/produce_data.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -10,7 +10,7 @@ "from collections import namedtuple\n", "from pathlib import Path\n", "\n", - "from toargridding.toar_rest_client import AnalysisService\n", + "from toargridding.toar_rest_client import AnalysisServiceDownload\n", "from toargridding.grids import RegularGrid\n", "from toargridding.gridding import get_gridded_toar_data\n", "from toargridding.metadata import TimeSample" @@ -18,7 +18,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -28,27 +28,22 @@ "\n", "#moreOptions is implemented as a dict to add additional arguments to the query to the REST API\n", "#For example the field toar1_category with its possible values Urban, RuralLowElevation, RuralHighElevation and Unclassified can be added.\n", - "#see page 18 in https://toar-data.fz-juelich.de/sphinx/TOAR_UG_Vol03_Database/build/latex/toardatabase--userguide.pdf\n", + "#see page 18 in https://toar-data.fz-juelich.de/sphinx/TOAR_UG_Vol03_Database/build/latex/toardatabase--userguide.pdf\n", + "\n", + "details4Query ={\n", + " #\"toar1_category\" : \"Urban\" #uncomment if wished:-)\n", + "}\n", "\n", "valid_data = Config(\n", " RegularGrid( lat_resolution=1.9, lon_resolution=2.5, ),\n", - " TimeSample( start=dt(2014,1,1), end=dt(2019,12,31), sampling=\"daily\"),\n", + " TimeSample( start=dt(2000,1,1), end=dt(2019,12,31), sampling=\"daily\"),\n", " [\"mole_fraction_of_ozone_in_air\"],#variable name\n", - " [\"mean\"],# [\"dma8epax\"], # enable when finished\n", - " {}\n", - ")\n", - "missing_data = Config(\n", - " RegularGrid( lat_resolution=1.9, lon_resolution=2.5),\n", - " TimeSample( start=dt(2000,1,1), end=dt(2013,12,31), sampling=\"daily\"),\n", - " [\"mole_fraction_of_ozone_in_air\"],\n", - " [\"mean\"],\n", - " #[\"dma8epax\"],\n", - " {}\n", + " [\"mean\", \"dma8epax\"],# will start one request after another other...\n", + " details4Query\n", ")\n", "\n", "configs = {\n", - " #\"test_ta\" : valid_data\n", - " \"test_ta2\" : missing_data\n", + " \"test_ta\" : valid_data\n", "}\n", "\n", "#testing access:\n", @@ -58,22 +53,9 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "load status endpoint from cache\n", - "try: 1, wait_time: 300\n", - "try: 2, wait_time: 300\n", - "try: 3, wait_time: 300\n", - "try: 4, wait_time: 300\n", - "try: 5, wait_time: 300\n" - ] - } - ], + "outputs": [], "source": [ "#CAVE: this cell runs about 30minutes per requested year\n", "#the processing is done on the server of the TOAR database.\n", @@ -81,9 +63,11 @@ "# The download can also take a few minutes\n", "\n", "stats_endpoint = \"https://toar-data.fz-juelich.de/api/v2/analysis/statistics/\"\n", + "cache_basepath = Path(\"cache\")\n", "result_basepath = Path(\"results\")\n", + "cache_basepath.mkdir(exist_ok=True)\n", "result_basepath.mkdir(exist_ok=True)\n", - "analysis_service = AnalysisService(stats_endpoint, result_basepath)\n", + "analysis_service = AnalysisServiceDownload(stats_endpoint=stats_endpoint, cache_dir=cache_basepath, sample_dir=result_basepath)\n", "\n", "for person, config in configs.items():\n", " datasets, metadatas = get_gridded_toar_data(\n", -- GitLab