{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Vertical extrapolation\n\nExample of using PyWAsP to perform vertical extrapolation.\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Prepare TopographyMap\nFirst, we need to prepare the topography map. This is done by reading the\nelevation and roughness maps and creating a TopographyMap object.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import numpy as np\nimport windkit as wk\nimport pywasp as pw\n\nssl = wk.load_tutorial_data(\"serra_santa_luzia\")\n# The wind directions are relative to the grid north of the UTM 29N maps\nbwc = ssl.bwc.assign_attrs(wind_dir_crs=\"EPSG:32629\")\n\ntopo_map = pw.wasp.TopographyMap(ssl.elev, ssl.rgh)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Define output locations\nSecond, we need to define the output locations. This is done by creating a\ndataset with the coordinates of the output locations.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "output_locs = wk.spatial.create_dataset(\n    west_east=bwc.west_east.values,\n    south_north=bwc.south_north.values,\n    height=np.linspace(10.0, 100.0, 10),\n    crs=\"EPSG:32629\",\n    struct=\"stacked_point\",\n)\nprint(output_locs)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Calculate resource grid\nFinally, we can calculate the resource grid. This is done by calling the\npredict_wwc function. This function takes the output locations,\nthe boundary conditions, and the topography map as input.\nThe output is a weibull wind climate dataset at the output locations.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "wwc = pw.wasp.predict_wwc(bwc, topo_map, output_locs)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Plot the mean wind speed\nWe can plot the mean wind speed to see the result.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "wwc[\"wspd\"].plot.line(y=\"height\")"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "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.13.13"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}