{ "cells": [ { "attachments": {}, "cell_type": "markdown", "id": "3e61c1aa-b033-4628-939c-81f08eeaa32c", "metadata": {}, "source": [ "**Note**: many of the jupyter notebooks provided here have SVG figures as cell outputs, which will only be displayed by JupyterLab or Jupyter Notebook if the notebook is marked as **trusted** (In JupyterLab: Ctrl+Shift+C -> Trust Notebook)." ] }, { "cell_type": "markdown", "id": "5ec7e27e-3eef-427a-ac74-f4f6ea49c935", "metadata": {}, "source": [ "# Data Input" ] }, { "cell_type": "markdown", "id": "fca2771e-61e8-4f29-a6ae-8bbce26c4762", "metadata": {}, "source": [ "There are 3 alternatives to import wind farm layout data for use within **optiwindnet**:\n", "- optiwindnet API\n", "- `.yaml` file\n", "- `.osm.pbf` file" ] }, { "cell_type": "code", "execution_count": 1, "id": "fa29e2ac-26f7-4927-bebf-eeef30a5ab37", "metadata": {}, "outputs": [], "source": [ "from optiwindnet.svg import svgplot" ] }, { "cell_type": "markdown", "id": "1bcfeda4-e9da-4305-b7ab-22c38f96f199", "metadata": {}, "source": [ "## Option 0: Use the optiwindnet API from Python" ] }, { "cell_type": "code", "execution_count": 2, "id": "1d2c0acc-b5ff-4ca0-b447-786a8d9c7ad2", "metadata": {}, "outputs": [], "source": [ "from optiwindnet.importer import L_from_site" ] }, { "cell_type": "code", "execution_count": 3, "id": "5854d182-84b6-4c64-aab2-46accfbb93a8", "metadata": {}, "outputs": [], "source": [ "from itertools import pairwise" ] }, { "cell_type": "code", "execution_count": 4, "id": "f82d5c6e-408c-4173-a434-157d53347e58", "metadata": {}, "outputs": [], "source": [ "import numpy as np" ] }, { "cell_type": "code", "execution_count": 5, "id": "e93a9280-594e-4840-8ea6-ec2a0bd800b3", "metadata": {}, "outputs": [], "source": [ "# all coordinates are sequences of (x, y) pairs\n", "# if input coordinates are in arrays X and Y, use `np.hstack((X, Y))`\n", "border = np.array( # coordinate sequence defines the polygon, last-first segment implicit\n", " [[1951, 200], [1951, 1383], [386, 1383], [650, 708], [624, 678],\n", " [4, 1036], [4, 3], [1152, 3], [917, 819], [957, 854]],\n", " dtype=float)\n", "# 'obstacles' is an optional location attribute\n", "obstacles = [\n", " # - obstacles must be strictly inside the border polygon\n", " # - undefined behavior if obstacles and border overlap\n", " # first obstacle\n", " np.array([[1540, 920], [1600, 940], [1600, 1150], [1400, 1200]]),\n", " # [second obstacle] ...\n", "]\n", "substations = np.array([[696, 1063],], dtype=float)\n", "turbines = np.array(\n", " [[1940, 279], [1920, 703], [1475, 696], [1839, 1250],\n", " [1277, 1296], [442, 1359], [737, 435], [1060, 26],\n", " [522, 176], [87, 35], [184, 417], [71, 878]],\n", " dtype=float\n", ")\n", "R = substations.shape[0]\n", "T = turbines.shape[0]\n", "border_sizes = np.array([border.shape[0]] +\n", " [obstacle.shape[0] for obstacle in obstacles])\n", "B = border_sizes.sum()\n", "obstacle_idxs = np.cumsum(border_sizes) + T\n", "\n", "L = L_from_site(\n", " R=R, T=T, B=B,\n", " border=np.arange(T, T + border.shape[0]),\n", " obstacles=[np.arange(a, b) for a, b in pairwise(obstacle_idxs)],\n", " name='Example Location',\n", " handle='example',\n", " VertexC=np.vstack((turbines, border, *obstacles, substations)),\n", ")" ] }, { "cell_type": "code", "execution_count": 6, "id": "5539b8f8-a4d6-4aa6-b1c3-faf04331f38a", "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "" ], "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "svgplot(L)" ] }, { "cell_type": "markdown", "id": "ac064931-e789-467f-8378-0e64d098d46a", "metadata": {}, "source": [ "## Option 1: YAML input file" ] }, { "cell_type": "code", "execution_count": 7, "id": "f9d1c872-2453-419e-9e02-57e309b29441", "metadata": {}, "outputs": [], "source": [ "from optiwindnet.importer import L_from_yaml" ] }, { "cell_type": "code", "execution_count": 8, "id": "501eb6be-c087-46c2-85cd-11b5de328c57", "metadata": {}, "outputs": [], "source": [ "with open('data/example_location.yaml', 'w') as yaml_file:\n", " yaml_file.write('''\n", "# coordinate format can be \"planar\" or \"latlon\"\n", "# - for \"latlon\" examples, see `optiwindnet/data/*.yaml`\n", "# - this field is optional, default is \"latlon\"\n", "# - coordinates are converted to floats, so floats may be used as well\n", "COORDINATE_FORMAT: planar\n", "\n", "# handle is optional (if omited, one is derived from the file name)\n", "HANDLE: example\n", "\n", "# extents define a polygon:\n", "# - do not repeat the initial vertex at the end\n", "# - line breaks are optional\n", "EXTENTS: [\n", " [1951, 200],\n", " [1951, 1383],\n", " [386, 1383],\n", " [650, 708],\n", " [624, 678],\n", " [4, 1036],\n", " [4, 3],\n", " [1152, 3],\n", " [917, 819],\n", " [957, 854]\n", "]\n", "\n", "# obstacles is optional and must be a list of polygons (even if 1 obstacle)\n", "# - obstacles must be strictly inside the extents polygon\n", "# - the parser will not complain about borders of obstacles overlapping\n", "# borders of extents, but optiwindnet will behave unpredictably\n", "OBSTACLES: [\n", " [ # first obstacle\n", " [1540, 920],\n", " [1600, 940],\n", " [1600, 1150],\n", " [1400, 1200],\n", " ],\n", " # [second obstacle]\n", "]\n", "\n", "SUBSTATIONS: [\n", " [696, 1063],\n", "]\n", "\n", "TURBINES: [\n", " [1940, 279],\n", " [1920, 703],\n", " [1475, 696],\n", " [1839, 1250],\n", " [1277, 1296],\n", " [442, 1359],\n", " [737, 435],\n", " [1060, 26],\n", " [522, 176],\n", " [87, 35],\n", " [184, 417],\n", " [71, 878],\n", "]\n", "''')" ] }, { "cell_type": "code", "execution_count": 9, "id": "a42be570-4222-4faf-a247-60611d55a09a", "metadata": {}, "outputs": [], "source": [ "L = L_from_yaml('data/example_location.yaml')" ] }, { "cell_type": "code", "execution_count": 10, "id": "5dc83b7b-d9be-48e0-9255-fabcef9cc7c2", "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "" ], "text/plain": [ "" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "svgplot(L)" ] }, { "cell_type": "markdown", "id": "ace13a16-228e-419c-b014-e7bba9da09e5", "metadata": {}, "source": [ "## Option 2: OSM.PBF input file (aka OpenStreetMap protobuffer format)" ] }, { "cell_type": "markdown", "id": "8530db3e-a4b1-4e94-b97c-714fe14f44fb", "metadata": {}, "source": [ "The JOSM open-source map editor is recommended if using this format: . In addition, the JOSM plugin **pbf** is required to save in the `.osm.pbf` format. The plugin **opendata** is useful for importing many common GIS file formats." ] }, { "cell_type": "markdown", "id": "71c381c7-9040-4c32-b01f-9d5328265a2c", "metadata": {}, "source": [ "The OpenStreetMaps objects used for representing a windfarm location are:\n", "- *nodes*\n", "- *ways*\n", "- *multipolygons* (relation between closed ways)\n", "\n", "Wind turbines are represented by *nodes* with the tag `power=generator`. Substations are represented either by *nodes* or by closed *ways* tagged `power=substation` or `power=transformer`. Substations based on *ways* will be reduced to the point at the centroid of the polygon defined by the *way*.\n", "\n", "The border of the windfarm can be a closed *way* tagged `power=plant`. If obstacles are required, then the closed *way* for the border must be combined with the closed *ways* for the obstacles in a *multipolygon* with the tag `power=plant` (in which case the *ways* themselves should not be tagged)." ] }, { "cell_type": "markdown", "id": "66e8ff88-400c-4a1a-a182-19d60cf1270a", "metadata": {}, "source": [ "See `optiwindnet/data/*.osm.pbf` for more examples." ] }, { "cell_type": "code", "execution_count": 11, "id": "ebff6d6c-ae49-4634-adc8-d780dbd3ae6d", "metadata": {}, "outputs": [], "source": [ "from optiwindnet.importer import L_from_pbf" ] }, { "cell_type": "code", "execution_count": 12, "id": "0baae019-4743-40cd-b7d9-bfbd49dc3137", "metadata": {}, "outputs": [], "source": [ "L = L_from_pbf('data/example_location.osm.pbf')" ] }, { "cell_type": "code", "execution_count": 13, "id": "45f77ec2-53e9-4858-8771-d6fa22cc032e", "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "" ], "text/plain": [ "" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "svgplot(L)" ] } ], "metadata": { "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 5 }