{ "cells": [ { "cell_type": "markdown", "id": "5a295af8-0b13-4332-a2c9-59d4961909fa", "metadata": {}, "source": [ "How to work with STA2STAC\n", "==========================\n", "\n", "Below are few examples demonstrating how to begin using STA2STAC:\n", "\n", "Prior to proceeding, it is necessary to install STA2STAC:\n" ] }, { "cell_type": "code", "execution_count": null, "id": "5028cf35-aac9-487c-a28f-bcf9db53c007", "metadata": {}, "outputs": [], "source": [ "pip install sta2stac" ] }, { "cell_type": "markdown", "id": "6955e1e8-c98f-4aac-8a5c-ec1d845165ab", "metadata": {}, "source": [ "In this example, our objective is to harvest data from the SensorThingsAPI of IMK-IFU, without any supplementary assets and extensions.\n" ] }, { "cell_type": "code", "execution_count": null, "id": "03791c71-9711-4273-bac0-189b529113d1", "metadata": {}, "outputs": [], "source": [ "from sta2stac import STA2STAC\n", "\n", "STA2STAC(sta_link=\"https://sensorthings.imk-ifu.kit.edu/\",\n", " sta_version=\"v1.1\",\n", " logger_properties={\"logger_handler\": \"StreamHandler\"})" ] }, { "cell_type": "markdown", "id": "eaaba9bb-4d06-4708-836d-721497bd2cdf", "metadata": {}, "source": [ "In the upcoming example, we will determine the values of stac_dir, stac_id, stac_title, and stac_dir." ] }, { "cell_type": "code", "execution_count": null, "id": "32ee6810-f160-4653-a081-6e67cabfba03", "metadata": {}, "outputs": [], "source": [ "from sta2stac import STA2STAC\n", "import os\n", "\n", "STA2STAC(sta_link=\"https://sensorthings.imk-ifu.kit.edu/\",\n", " sta_version=\"v1.1\",\n", " stac_dir=os.getcwd(),\n", " stac_id=\"test-id\",\n", " stac_title=\"This is a test title\",\n", " stac_description=\"This is a test description\",\n", " logger_properties={\"logger_handler\": \"StreamHandler\"})" ] }, { "cell_type": "markdown", "id": "a817a590-6f50-408a-839c-3594af97ab72", "metadata": {}, "source": [ "In this example, we execute the `ItemInfoHandler` class initially to retrieve the auto-generated ID, title, and description of the items. Subsequently, we create our own `items_tuples` to substitute the automatically created ones. " ] }, { "cell_type": "code", "execution_count": null, "id": "23da2905-3e04-4a74-9467-e1b8cfb8cf11", "metadata": {}, "outputs": [], "source": [ "from sta2stac import ItemInfoHandler\n", "\n", "result = ItemInfoHandler(\n", " logger_properties={\"logger_handler\": \"StreamHandler\"}\n", " ).get_entity_tuples_info(\n", " sta_link=\"https://sensorthings.imk-ifu.kit.edu/\", \n", " sta_version=\"v1.1\", \n", " entity=\"Things\", )\n", "print(result)\n" ] }, { "cell_type": "markdown", "id": "7fd62dd7-34fe-49cf-be19-d139708b597d", "metadata": {}, "source": [ "[('BE_K_000', 'BE_K_000', 'Climate Station at TERENO Site Berg'), ('FEN_MET_000', 'FEN_MET_000', 'Climate Station at TERENO Pre-Alpine Site Fendt'), ('KOL_MET_001', 'KOL_MET_001', 'Climate Station at TERENO Pre-Alpine Site Kolbensattel'), ('LaS_MET_001', 'LaS_MET_001', 'Climate Station at TERENO Pre-Alpine Site Laber'), ('ROT_MET_000', 'ROT_MET_000', 'Climate Station at TERENO Pre-Alpine Site Rottenbuch'), ('GRA_MET_000', 'GRA_MET_000', 'Climate Station at TERENO Pre-Alpine Site Graswang'), ('ACH_MET_000', 'ACH_MET_000', 'Climate Station at TERENO Site Acheleschwaig'), ('KIT_Campus_Alpin_Greenhouse_experiment-2022_heat_limit', 'KIT_Campus_Alpin_Greenhouse_experiment:2022_heat_limit', 'experiment:2022_heat_limit campaign at KIT Campus Alpin'), ('Kitchen', 'Kitchen', 'The Kitchen in my house'), ('Kitchen', 'Kitchen', 'The Kitchen in my house'), ('Kitchen', 'Kitchen', 'The Kitchen in my house'), ('Kitchen', 'Kitchen', 'The Kitchen in my house'), ('Kitchen', 'Kitchen', 'The Kitchen in my house'), ('Kitchen', 'Kitchen', 'The Kitchen in my house'), ('Kitchen', 'Kitchen', 'The Kitchen in my house')]" ] }, { "cell_type": "code", "execution_count": null, "id": "30600168-355c-46b5-ae81-374650cc4b9c", "metadata": {}, "outputs": [], "source": [ "from sta2stac import STA2STAC\n", "items_tuples = [('BE_K_000', 'test-id','test title', 'test description'),('ACH_MET_000', 'test-id1','test title1', 'test description2')]\n", "\n", "STA2STAC(sta_link=\"https://sensorthings.imk-ifu.kit.edu/\",\n", " sta_version=\"v1.1\",\n", " items_tuples=items_tuples,\n", " logger_properties={\"logger_handler\": \"StreamHandler\"})" ] }, { "cell_type": "markdown", "id": "0bd835f4-551a-4645-9a5d-918c3b4dd374", "metadata": {}, "source": [ "In this example, we seek to employ the `filter` function to selectively improve the output result of STA. In this instance, our objective is to employ a filter to exclusively choose the Things that possess an id of 65." ] }, { "cell_type": "code", "execution_count": null, "id": "600e144a-fa1a-4fbf-aae6-0a80e9c11573", "metadata": {}, "outputs": [], "source": [ "from sta2stac import STA2STAC\n", "\n", "STA2STAC(sta_link=\"https://sensorthings.imk-ifu.kit.edu/\",\n", " sta_version=\"v1.1\",\n", " filter=\"$filter=id%20eq%2065\",\n", " logger_properties={\"logger_handler\": \"StreamHandler\"})" ] }, { "cell_type": "markdown", "id": "64e8d09e-daad-4ebf-acbb-16c45724b57d", "metadata": {}, "source": [ "In the above example, we aim to activate the `datacube_extension` during the harvesting process." ] }, { "cell_type": "code", "execution_count": null, "id": "6e147da5-04ee-48e6-b1eb-5b023d8e3e31", "metadata": {}, "outputs": [], "source": [ "from sta2stac import STA2STAC\n", "\n", "STA2STAC(sta_link=\"https://sensorthings.imk-ifu.kit.edu/\",\n", " sta_version=\"v1.1\",\n", " datacube_extension=True,\n", " logger_properties={\"logger_handler\": \"StreamHandler\"})" ] } ], "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.12.0" } }, "nbformat": 4, "nbformat_minor": 5 }