PyWAsP tutorial 1 From observed wind climate to resource map
A notebook by the PyWAsP team
Introduction
This is an interactive tutorial that will introduce you to the basic WAsP workflow using PyWAsP.
After completing this tutorial you will be familiar with basic pywasp
functionality, including:
opening and inspecting wind climate files;
opening map files and inspecting terrain data;
calculating and inspecting terrain-induced effects on the wind at various sites;
creating a generalized wind climate from the observed wind climate;
creating a resource map by “downscaling” the generalized wind climate.
As you work your way through the notebook, make sure to run the python code in each cell, in the order that the cells appear. You run the code by clicking on the cell (outlines around the cell should appear) and pressing <shift> + <enter>
on the keyboard.
notebook note if something looks wrong, or when errors occur, it can be helpful to restart the python kernel via the kernel tab in the top
Import packages
Usually the first step when writing (or using) a python program is to import the standard (external) packages we will need. For the analysis in this tutorial we will import numpy
, matplotlib
, xarray
, windkit
and pywasp
itself.
numpy
is python’s main numerical array package https://www.numpy.org/matplotlib
is python’s main plotting package https://matplotlib.org/xarray
is a powerful high level package for labelled multi-dimensional arrays http://xarray.pydata.orgpywasp
docummentation is found at http://docs.wasp.dk/windkit
documentation is found at http://docs.wasp.dk/windkit
[1]:
import warnings
warnings.filterwarnings('ignore') # We will ignore warnings to avoid cluttering the notebook
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
import xarray as xr
import windkit as wk
import pywasp as pw
It is common to make a short alias of a package when importing it, using the syntax import [package] as [short alias for package]
; for example you can see import pywasp as pw
above. The functions and classes of imported packages must be accessed through explicitly typing the package name or alias; e.g., np.cos(3.14)
will use the cosine function from numpy
.
Next, we will use a python “magic” command; this particular one makes matplotlib figures appear in the notebook when a plot
command is used.
[2]:
%matplotlib inline
Observed wind climate
Now we will import our (observed) binned wind climate from the Høvsøre mast. The data is stored in hovsore.tab
in the data
folder. It represents the observed wind climate for the period 2007-2015 at 100 m above ground level.
pywasp note
pywasp
includes functionality to both read and write wind climate files in many data formats, including ascii (.tab
), xml (.owc
), and netCDF (.nc
).
The geospatial coordinate in the file is in the European grid projection (EPSG:3035), which is the recommended projection for high-resolution studies in Europe. We will tell pywasp
this by explicitly passing a keyword argument srs="EPSG:3035"
to the open_bwc
call.
[3]:
bwc = wk.read_bwc('data/hovsore.tab', crs="EPSG:3035")
print(bwc)
<xarray.Dataset>
Dimensions: (point: 1, sector: 12, wsbin: 30)
Coordinates:
height (point) float64 100.0
south_north (point) float64 3.706e+06
west_east (point) float64 4.207e+06
crs int8 0
* wsbin (wsbin) float64 0.5 1.5 2.5 3.5 4.5 ... 26.5 27.5 28.5 29.5
wsceil (wsbin) float64 1.0 2.0 3.0 4.0 5.0 ... 27.0 28.0 29.0 30.0
wsfloor (wsbin) float64 0.0 1.0 2.0 3.0 4.0 ... 26.0 27.0 28.0 29.0
* sector (sector) float64 0.0 30.0 60.0 90.0 ... 270.0 300.0 330.0
sector_ceil (sector) float64 15.0 45.0 75.0 105.0 ... 285.0 315.0 345.0
sector_floor (sector) float64 345.0 15.0 45.0 75.0 ... 255.0 285.0 315.0
Dimensions without coordinates: point
Data variables:
wdfreq (sector, point) float64 0.02869 0.04459 ... 0.09727 0.0156
wsfreq (wsbin, sector, point) float64 0.01167 0.01544 ... 0.0 0.0
Attributes:
Conventions: CF-1.8
history: 2024-06-03T15:05:01+00:00:\twindkit==0.7.1.dev53+gcced3...
wasp_header: Høvsøre observed wind climate EPSG:3035
Package name: windkit
Package version: 0.7.1.dev53+gcced321
Creation date: 2024-06-03T15:05:01+00:00
Object type: Binned Wind Climate
author: Bjarke Tobias Olsen
author_email: btol@dtu.dk
institution: DTU Wind Energy
Notice that the bwc
object is of type <xarray.Dataset>
and that it contains four kinds of data:
Dimensions: core named dimensions
Coordinates: coordinate values along dimensions
Data variables: named arrays with data along 0-N named dimensions
Attributes: additional meta data attached to the dataset
xarray note the primitive datatype and dimensions of each variable are also shown, along with a small sample of the data.
wsfreq
is a four-dimensionalfloat64
(double precision) variable along dimensions(wsbin, sector, height, point)
Xarray datasets wrap numpy arrays, annotating them with human-readable dimensions and coordinates, and allowing for easy subsetting, data manipulation, and plotting of the underlying data. An xarray.Dataset
object is a collection of data variables, while each varible itself has type xarray.DataArray
.
xarray note Use the
.values
object attribute to access the underlying numpy array
Beyond the wind speed and wind direction distributions, the wind climate contains information about the height of the measurements (height
) and the geospatial location (west_east
and south_north
), which in this case hold the location information in the projected coordinates of the EPSG:3035 projection.
In the cell below, we will store the location of the Høvsøre mast in variables loc_x
and loc_y
for later use.
[4]:
loc_x = bwc['west_east']
loc_y = bwc['south_north']
The next step is to plot the wind rose and wind speed distributions in the binned wind climate. For convinience a plotting function plot_bwc
has been implemented in pywasp_tutorial
that will do this.
notebook note: you can view the documentation for a function in jupyter notebooks by placing a
?
in front of the function, and you can get the entire function by using??
.
[5]:
wk.plot.histogram_lines(bwc)