{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Detailed example\n", "\n", "This overview of the most important functions repeats the previous 30-seconds-example, but in more detail and shows additional functionality and alternative steps." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Authentificate & access project" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import up42\n", "up42.authenticate(project_id=\"12345\", project_api_key=\"12345\")\n", "#up42.authenticate(cfg_file=\"config.json\")\n", "\n", "project = up42.initialize_project()\n", "project" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Get information about the available blocks to later construct your workflow." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "up42.get_blocks(basic=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Create or access the workflow\n", "You can either create a new workflow, use project.get_workflows() to get all existing workflows within the project, or access an exisiting workflow directly via its workflow_id." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "A new workflow is created and filled with tasks ([Sentinel-2 data](https://marketplace.up42.com/block/018dfb34-fc19-4334-8125-14fd7535f979), \n", "[Land-Surface-Temperature](https://marketplace.up42.com/block/34767300-5caf-472b-a684-a351212b5c14)). \n", "The area of interest and workflow parameters are defined. After running the job, \n", "the results are downloaded and visualized." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Create a new, empty workflow.\n", "\n", "workflow = project.create_workflow(name=\"30-seconds-workflow\", use_existing=False)\n", "workflow" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Add workflow tasks\n", "\n", "input_tasks = [\"Sentinel-2 Level 2 (BOA) AOI clipped\", \"Land Surface Temperature Estimation\"]\n", "workflow.add_workflow_tasks(input_tasks=input_tasks)\n", "\n", "# Check the added tasks.\n", "workflow.get_workflow_tasks(basic=True)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Alternative: Get all existing workflows within the project.\n", "\n", "all_workflows = project.get_workflows()\n", "workflow = all_workflows[0]\n", "workflow" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Alternative: Directly access the existing workflow the id (has to exist within the accessed project).\n", "\n", "UP42_WORKFLOW_ID=\"7fb2ec8a-45be-41ad-a50f-98ba6b528b98\"\n", "workflow = up42.initialize_workflow(workflow_id=UP42_WORKFLOW_ID)\n", "\n", "workflow" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Select the aoi\n", "\n", "There are multiple ways to select an aoi, you can:\n", "- Provide aoi the geometry directly in code as a FeatureCollection, Feature, GeoDataFrame, shapely Polygon or list of bounds coordinates.\n", "- Use up42.draw_aoi() to draw the aoi and export it as a geojson.\n", "- Use up42.read_vector_file() to read a geojson, json, shapefile, kml or wkt file.\n", "- Use up42.get_example_aoi() to read multiple provided sample aois." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "aoi = [13.375966, 52.515068, 13.378314, 52.516639]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "aoi = up42.read_vector_file(\"data/aoi_berlin.geojson\", as_dataframe=True)\n", "aoi.head(1)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#aoi = up42.get_example_aoi(location=\"Berlin\")\n", "#aoi" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#up42.draw_aoi()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Select the workflow parameters\n", "\n", "There are also multiple ways to construct the workflow input parameters, you can:\n", "- Provide the parameters directly in code as a json string.\n", "- Use .get_parameters_info() to get a an overview of all potential parameters for the selected workflow and information about the parameter defaults and ranges.\n", "- Use .get_input_parameters(aoi_type=\"bbox\", aoi_geometry=aoi) to construct the parameters with the provided aoi and all default parameters. Selecting the aoi_type is independent from the provided aoi, you can e.g. provide a irregular Polygon and still select aoi_type=\"bbox\", then the bounding box of the polygon will be selected." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "workflow.get_parameters_info()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "input_parameters = workflow.construct_parameters(geometry=aoi, geometry_operation=\"bbox\", limit=1)\n", "\n", "# Further update the input_parameters manually\n", "input_parameters[\"sentinelhub-s2-aoiclipped:1\"].update({\"max_cloud_cover\":10})\n", "input_parameters" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Price estimation & Test Job" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "workflow.estimate_job(input_parameters)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Run a test job to query data availability and check the configuration.\n", "test_job = workflow.test_job(input_parameters=input_parameters, track_status=True)\n", "test_results = test_job.get_results_json()\n", "print(test_results)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Run the workflow & download results" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Run the actual job.\n", "job = workflow.run_job(input_parameters=input_parameters, track_status=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

\n", " \n", "

" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Download & Display results" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Download job result (default downloads to Desktop). Only works after download is finished.\n", "results_fp = job.download_results()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "job.plot_results(figsize=(6,6), bands=[1], cmap=\"YlOrBr\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#job.map_results(bands=[1])" ] } ], "metadata": { "kernelspec": { "display_name": "up42-py", "language": "python", "name": "up42-py" }, "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.8.3" } }, "nbformat": 4, "nbformat_minor": 4 }