Skip to content
forked from ebranlard/weio

Library to read and write files (in particular files used in the Wind Energy community)

Notifications You must be signed in to change notification settings

hivanov-nrel/weio

 
 

Repository files navigation

Build Status Donate just a small amount, buy me a coffee!

weio

Library to read and write files, in particular files used by the Wind Energy community. This library is for instance used by the GUI tool pyDatView to plot, export and compare these different files.

Typical file formats supported

  • Various CSV and delimited files
  • Simple Excel files
  • FAST input and output files (including some turbulence files)
  • HAWC2 and HawcStab2 input and output files (still some missing)
  • Bladed output files
  • FLEX output files
  • NetCDF files (partial support for 1D and 2D data for now)

Quickstart

Download, install dependencies, install package and run tests:

git clone https://github.com/ebranlard/weio
cd weio
python -m pip install --user -r requirements.txt  
python -m pip install -e .      # install
python -m unittest discover -v  # run test

Python package usage

import weio 
f=weio.read('file.csv')
print(f.toDataFrame())
f.write('out.csv')

Example for an OpenFAST binary file:

import weio 
df=weio.read('Output.outb').toDataFrame()
plt.plot(df['Time_[s]'], df['GenPwr_[kW']))

Example to change an OpenFAST input file:

import weio 
ED=weio.read('ElastoDyn.dat')
print(ED.keys())
ED['NacMass'] = 100000 # changing nacelle mass value
ED['HubMass'] = 10000  # changing hub mass value
ED.write('ElastoDyn_modified.dat')

Example to change an OpenFAST aerodynamic blade file :

import weio
import numpy as np
Bld=weio.read('NREL5MW_AD15_blade.dat')
nSpan = 10
Spn   = np.linspace(0, 15, nSpan)       # BlSpn, radial stations [m]
CrvAC = np.zeros((nSpan,))              # BlCrvAC, prebend (usually <0) [m]
SwpAC = np.zeros((nSpan,))              # BlSwpC,  sweep                [m]
CrvAng = np.concatenate(([0], np.arctan2((CrvAC[1:]-CrvAC[:-1]),(Spn[1:]-Spn[:-1]))*180/np.pi))
Twist  = np.zeros((nSpan,)) + 1         # BlTwist [deg]
Chord  = np.zeros((nSpan,)) + 5         # BlChord [m]
AFID   = np.zeros((nSpan,)).astype(int) # BlAFID [-]
ADProp = np.column_stack((Spn,CrvAC,SwpAC,CrvAng,Twist,Chord,AFID))
Bld['NumBlNds']     = ADProp.shape[0]
Bld['BldAeroNodes'] = ADProp
Bld.write('AeroDyn_Blade_Modified.dat')

Requirements

The library is compatible python 2.7 and python 3. The script relies on the following python packages: numpy, pandas, xarray

If you have pip installed on your system, you can install them by typing in a terminal:

pip install -r requirements.txt

or type make dep from the main directory.

Download

From the github page, click on the "Clone or download" button, and you may chose to download as Zip. Alternatively, from a command line:

git clone https://github.com/ebranlard/weio
cd weio

Installation

The python packages mentioned in the Requirements section need to be installed.

pip install -e .

or

python setup.py install

Adding more file formats

Additional file formats can be added as follows:

  • Copy paste the template file _weio/_NEWFILE_TEMPLATE.py, for instance to weio/MyFormatFile.py
  • Adjust the classname, the default extensions, and implement the reader (function _read()) and optionally the writer.
  • Register the fileformat in weio/__init__.py by adding an import line in the function fileFormats(). Registering the fileformat is useful when using weio with pyDatView, or, when using the automatic reader functionality: weio.read('any_file.ext')

That's it. If possible, add some unittests and examples files:

  • Unittests are found in the folder weio/tests/. You can create a file test_myformat.py in this folder, using existing tests for inspiration.
  • Examples files can be placed in the folder weio/tests/example_files/. Try to use a minimal size for the example files (e.g. a couple of bytes/Kb).
  • To run your test from the repository root, type python -m weio.tests.tests_myformat.

Contributing

Any contributions to this project are welcome! If you find this project useful, you can also buy me a coffee (donate a small amount) with the link below:

Donate just a small amount, buy me a coffee!

About

Library to read and write files (in particular files used in the Wind Energy community)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 92.0%
  • Smalltalk 7.6%
  • Other 0.4%