Commit 6d12de64 authored by Nikola Vasiljevic's avatar Nikola Vasiljevic
Browse files

added tutorial 5

parent 213e0fcd
%% Cell type:markdown id: tags:
# <center> *PyWAsP* tutorial 5 <br><br> Importing objects from WWH file <center>
In this tutorial we will cover a `pywasp` feature that lets users work import objects from `WAsP` workspace file (`wwh` file) and perform `pywasp` calculations. We will use an example of 'Parque Ficticio' workspace, which is a common example from `WAsP` tutorials. For this location we will generate site effectes and predicted wind climate over a uniform grid.
First let's import necessary libraries and read WAsP Workspace file (`wwh`) and list its content:
%% Cell type:code id: tags:
``` python
import pywasp as pw
import numpy as np
```
%% Cell type:code id: tags:
``` python
wwh = pw.io.Workspace.read_wwh('./data/import/ParqueFicticio.wwh')
wwh
```
%% Output
Object ID Object description
3 Vector map
4 Turbine site group
15 Generalised wind climate
17 Observed wind climate
20 Vector map
%% Cell type:markdown id: tags:
The listed objects can be imported as `pywasp` `xarray` datasets by calling specifing `geter` methods and suppling the desired object `id` and depending on the object type also some additional parameters. First thing to notice is that we have two ids assigned to a vector map object. In reallity both ids are pointing to the same vector map. The reason why there two ids is that each id tells `WAsP` to read the vector map differently, one as an `elevation` map while the second as `roughness` map. As you will see later in this tutorial we do this a bit different in `pywasp`.
Let's now start importing listed objects and as an exercise exporting them as `NetCDF` files.
Let's start with `Observed Wind Climate`. To get the `OWC`, we call method `get_owc()` and provide id of this object:
%% Cell type:code id: tags:
``` python
bwc = wwh.get_owc(17)
bwc
```
%% Output
<xarray.Dataset>
Dimensions: (point3d: 1, sector: 12, wsbin: 27)
Coordinates:
* wsbin (wsbin) float64 0.5 1.5 2.5 3.5 4.5 ... 23.5 24.5 25.5 26.5
* sector (sector) float64 0.0 30.0 60.0 90.0 ... 240.0 270.0 300.0 330.0
south_north (point3d) float64 -31.5
west_east (point3d) float64 -71.5
height (point3d) float64 42.25
wsceil (wsbin) float64 1.0 2.0 3.0 4.0 5.0 ... 24.0 25.0 26.0 27.0
crs int64 0
Dimensions without coordinates: point3d
Data variables:
wdfreq (sector, point3d) float64 0.0706 0.0318 ... 0.1284 0.0883
wsfreq (wsbin, sector, point3d) float64 0.02467 0.01616 ... 0.0002156
amplif float64 1.0
offset float64 0.0
Attributes:
header: Cerro
%% Cell type:code id: tags:
``` python
bwc.to_netcdf('./data/export/bwc.nc')
```
%% Cell type:markdown id: tags:
In a similar fashion we are importing `Generalised wind climate`, and exporting it to `NetCDF` file:
%% Cell type:code id: tags:
``` python
gwc = wwh.get_gwc(15)
gwc
```
%% Output
<xarray.Dataset>
Dimensions: (gen_height: 5, gen_roughness: 5, point3d: 1, sector: 12)
Coordinates:
* gen_roughness (gen_roughness) float64 0.0 0.03 0.1 0.4 1.5
* gen_height (gen_height) float64 10.0 25.0 50.0 100.0 200.0
* sector (sector) float64 0.0 30.0 60.0 90.0 ... 270.0 300.0 330.0
south_north (point3d) float64 -31.5
west_east (point3d) float64 -71.5
height (point3d) float64 42.25
crs int64 0
Dimensions without coordinates: point3d
Data variables:
wdfreq (sector, gen_roughness, point3d) float64 0.009726 ... 0.02108
A (sector, gen_height, gen_roughness, point3d) float64 4.515 ... 5.945
k (sector, gen_height, gen_roughness, point3d) float64 1.83 ... 1.775
Attributes:
header: Cerro
%% Cell type:code id: tags:
``` python
gwc.to_netcdf('./data/export/gwc.nc')
```
%% Cell type:markdown id: tags:
Now let's load the maps. To do this we call method `get_vectormap` which requires following parameters:
- `id`: id of the vector map object in the wwh list (integer)
- `map_type`: feature type to extract from mapfile, it can be 0 (elevation) or 1 (roughness)
- `reproj`: dictionary indicating EPSG code of the map in the form of `{'from_epsg': epsg_code_of_vector_map}`
In our example the EPSG code is `32719`, since the vector map header has following information:
```
UTM-Proj.-S.hemisph. Zone 19 (WGS 1984)
```
We will extract both the elevation and roughness map, and we can supply and of the two `id`s (3 or 20).
We will then boundle these two maps creating topo map.
%% Cell type:code id: tags:
``` python
elev_map = wwh.get_vectormap(20, 0, {'from_epsg':32719})
rough_map = wwh.get_vectormap(20, 1,{'from_epsg':32719})
topo_map = pw.TopographyMap(elev_map, rough_map)
```
%% Cell type:markdown id: tags:
If we closely inspect `bwc` data we will notice that the provided geospatial location of the mast in this dataset is in the projected coordinates of the EPSG:4326 projection (i.e., south_north=latitude and west_east=longitude). However, as our terrain and rougness data are in the South UTM Zone 19 (EPSG:32719) we will convert and update the mast coordinates. Once the coordiantes are converted we will store them in in variables `loc_x` and `loc_y` for later use
%% Cell type:code id: tags:
``` python
bwc = pw.gis_tools.reproject_ds(bwc, 32719) #
loc_y = bwc.south_north
loc_x = bwc.west_east
```
%% Cell type:markdown id: tags:
Let's now create uniform grid, with resolution of 100 m in `west_east` and `north_south` coordinate. The grid will be positioned 200 m above the ground level. We will supply this uniform grid of points to the `pywasp` routine that will calculate the site effects for the given points. Afterwards we will export the site effects dataset as a `NetCDF` file.
%% Cell type:code id: tags:
``` python
height = 200
x_res = 100
y_res = 100
output_locs = pw.create_dataset(
np.arange(262878, 265078 + x_res, x_res),
np.arange(6504214, 6507414 + y_res, y_res),
np.array([height]),
32719
)
conf = pw.Config()
site_effects = topo_map.get_site_effects(output_locs, conf, 12)
site_effects.to_netcdf('./data/export/site_effects_'+str(height)+'_m.nc')
```
%% Cell type:markdown id: tags:
Let's now calcualte predicted wind climate for the uniform grid and export as `NetCDF` file:
%% Cell type:code id: tags:
``` python
pwc = pw.wasp._get_wasp_down(gwc, site_effects, conf, genwc_interp='nearest')
```
%% Cell type:code id: tags:
``` python
pwc
```
%% Output
<xarray.Dataset>
Dimensions: (height: 1, sector: 12, south_north: 33, west_east: 23)
Coordinates:
* sector (sector) float64 0.0 30.0 60.0 90.0 ... 240.0 270.0 300.0 330.0
crs int64 0
* height (height) int64 200
* south_north (south_north) int64 6504214 6504314 6504414 ... 6507314 6507414
* west_east (west_east) int64 262878 262978 263078 ... 264878 264978 265078
Data variables:
A (sector, height, south_north, west_east) float32 5.847679 ... 7.3445773
k (sector, height, south_north, west_east) float32 1.9941406 ... 1.7480469
wdfreq (sector, height, south_north, west_east) float32 5.2802725 ... 9.509093
A_tot (height, south_north, west_east) float32 9.157562 ... 9.329962
k_tot (height, south_north, west_east) float32 2.0800781 ... 2.0800781
%% Cell type:code id: tags:
``` python
pwc.to_netcdf('./data/export/pwc_'+str(height)+'_m.nc')
```
%% Cell type:code id: tags:
``` python
```
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment