Skip to content
Snippets Groups Projects
get_sample_data.ipynb 2.28 KiB
Newer Older
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# creation of all required metadata for the request to the analysis service."
   ]
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": [
    "from datetime import datetime\n",
    "\n",
    "from toargridding.metadata import TimeSample, Metadata\n",
    "\n",
    "sampling = \"daily\"  # FIXME check monthly !!!\n",
    "start = datetime(2010, 1, 1)\n",
    "end = datetime(2010, 1, 3)\n",
    "\n",
    "statistics_endpoint = \"https://toar-data.fz-juelich.de/api/v2/analysis/statistics/\"\n",
    "statistic = \"mean\"\n",
    "\n",
    "time = TimeSample(start, end, sampling=sampling)\n",
    "metadata = Metadata.construct(\"mole_fraction_of_ozone_in_air\", time, statistic)\n",
    "\n",
    "start_time = datetime.now()\n",
    "print(start_time)"
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# setting up of directories for the download of the data and retrival of dataset"
   ]
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": [
    "from pathlib import Path\n",
    "from toargridding.toar_rest_client import AnalysisServiceDownload\n",
    "\n",
    "\n",
    "#creation of output directories\n",
    "toargridding_base_path = Path(\".\")\n",
    "cache_dir = toargridding_base_path / \"cache\"\n",
    "download_dir = toargridding_base_path / \"results\"\n",
    "cache_dir.mkdir(parents=True, exist_ok=True)\n",
    "download_dir.mkdir(parents=True, exist_ok=True)\n",
    "\n",
    "analysis_service = AnalysisServiceDownload(statistics_endpoint, cache_dir, download_dir)\n",
    "\n",
    "results = analysis_service.get_data(metadata)\n",
    "\n",
    "end_time = datetime.now()\n",
    "print(end_time-start_time)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "toargridding-g-KQ1Hyq-py3.10",
   "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.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}