Skip to main content

Wind Resource binary reader and writer

Project description

Whiffle App

The pywrb library for reading and writing WRB files.

Features

  • Read and write WRB files

Requirements

  • Python 3.12+
  • NumPy

Optional:

  • Xarray

Installation

To install the pywrb, follow these steps:

  1. Clone the repository: git clone https://gitlab.com/whiffle/common/pywrb.git and change directory cd pywrb
  2. Create a virtual environment python3 -m venv .venv
  3. Install the dependencies: pip install -r requirements.txt
  4. Run the tests pip install -e .[dev] and pytest tests

Usage

Xarray interface

For almost all use cases we recommend using the xarray interface. This can be installed using:

pip install pywrb[xarray]

You can then open an existing WRB directly from xarray

import pywrb

ds = xarray.open_dataset(filename="tests/fixtures/real_world.wrb", engine="pywrb")

ds["elevation"].plot.imshow()

Or writing a WRB can be done using

    import xarray as xr
    import numpy as np
    import pywrb

    n_x, n_y, n_directions, n_wind_speed, n_heights = 128, 128, 12, 10, 3

    ds = xr.Dataset(
        data_vars=dict(
            weibull_scale=(["x", "y", "directions", "heights"], np.random.randn(n_x, n_y, n_directions, n_heights)),
            weibull_shape=(["x", "y", "directions", "heights"], np.random.randn(n_x, n_y, n_directions, n_heights)),
            wind_shear_exponent=(["x", "y", "directions"], np.random.randn(n_x, n_y, n_directions)),
            inflow_angle=(["x", "y", "directions", "heights"], np.random.randn(n_x, n_y, n_directions, n_heights)),
            turbulence_intensity=(
                ["x", "y", "directions", "wind_speeds", "heights"],
                np.random.randn(n_x, n_y, n_directions, n_wind_speed, n_heights),
            ),
            elevation=(["x", "y"], np.ones((n_x, n_y))),
            roughness_length=(["x", "y"], np.ones((n_x, n_y))),
            probability=(
                ["x", "y", "directions", "wind_speeds", "heights"],
                (lambda a: a / np.linalg.norm(a))(np.random.rand(n_x, n_y, n_directions, n_wind_speed, n_heights)),
            ),
        ),
        coords=dict(
            x=(["x"], np.arange(n_x)),
            y=(["y"], np.arange(n_y)),
            directions=(["directions"], np.linspace(0, 360, n_directions, endpoint=False)),
            wind_speeds=(["wind_speeds"], np.linspace(6, 15, n_wind_speed)),
            heights=(["heights"], [100, 150, 200]),
        ),
    )
    # WRB's require a coordinate system
    ds = ds.rio.write_crs("epsg:4326")
    ds.pywrb.to.to_wrb("my-new.wrb")

Low-level interface

With the low level interface you can specifically add blocks to the WRB for specific quantities. This is mostly intended for incorporating more exotic data in the WRB that can't be done through the xarray interface.

To open an existing WRB file you can:

import pywrb
import matplotlib.pyplot as plt
data = numpy.ones(10, 10)

with pywrb.open(filename="existing.wrb", mode="r") as wrb:
    elevation = None
    for block, data in wrb.items:
        if block["meaning"] == pywrb.WRB_BLOCK_MEANING.ELEVATION:
            plt.imshow(data)

To generate a new WRB file you can

import pywrb
data = numpy.ones(10, 10)

with pywrb.open(
    filename="test.wrb",
    mode="w",
    crs="EPSG:25832",
    minx=0,
    miny=0,
    maxx=900,
    maxy=900,
    resolutionx=100,
    resolutiony=100,
    heights=[100],
    directions=0,
    wind_speeds=[]
) as wrb:
    wrb.add_block('elevation', data=data, unit=pywrb.WRB_UNIT.METER)
    wrb.add_block('mean_wind_speed', data=data+1, height=100, unit=pywrb.WRB_UNIT.METER_PER_SECOND)
    wrb.write()

Contributing

Contributions to pywrb are welcome! If you'd like to contribute, please fork the repository and submit a pull request.

License

pywrb is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pywrb-0.0.0.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pywrb-0.0.0-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

Details for the file pywrb-0.0.0.tar.gz.

File metadata

  • Download URL: pywrb-0.0.0.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for pywrb-0.0.0.tar.gz
Algorithm Hash digest
SHA256 c4b527086ca2316463deb55badf0e3a0764baba51f18ed9c6ec1324a3bb277a6
MD5 f0a83ebf2c817e0f0030bf94e8f271fc
BLAKE2b-256 31cbe7195e6b90a8513fb10b50825ef7a7bc3fcb7037f25bca27bc62a4e7c079

See more details on using hashes here.

File details

Details for the file pywrb-0.0.0-py3-none-any.whl.

File metadata

  • Download URL: pywrb-0.0.0-py3-none-any.whl
  • Upload date:
  • Size: 3.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for pywrb-0.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e2a1107b801c0b8b66c966e9861b8fcb97616e8661bc980192023e1f51050517
MD5 4a493a851ca61d8cf63593c0c46f0c38
BLAKE2b-256 34183536e1068d12178e506dc1dab86375217bcd6def82b46c4a73195ac0cbeb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page