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.
- 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)
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
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')
The library is compatible python 2.7 and python 3, and has limited requirements. 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.
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
The python packages mentioned in the Requirements section need to be installed.
pip install -e .
or
python setup.py install
There are two ways to add a file format. If your file format is fairly generic (e.g. CSV, Excel) you can add it directly to weio (see Option 1 below). Otherwise, it is recommended to use Option 2 below.
Additional file formats (that are either generic, or commonly used by the wind energy community) can be added as follows:
- Copy paste the template file
weio/_NEWFILE_TEMPLATE.py
, to, for instanceweio/my_format_file.py
- Edit this file. Adjust the classname and the default extensions. Implement the reader (function
_read()
) and optionally the writer. Look for XXX in this file and replace them with appropriate value for your file format. - Register the fileformat in
weio/__init__.py
by adding an import line in the functionfileFormats()
. Registering the fileformat is useful when usingweio
withpyDatView
, 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 filetest_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
.
Specific file formats can be added in the <UserData>
folder of weio.
Depending on your platform, the <UserData>
directory will be:
C:/Users/<USERNAME>/AppData/Roaming/weio
on Windows<HOME>/.local/share/weio/
on Linux<HOME>/Library/Application Support/weio/
on MacOS
To add specfic file formats, follow the following steps:
-
Create the
<UserData>
directory if it doesn't exist. -
Copy paste the template file
weio/_NEWFILE_TEMPLATE.py
, to, for instance<UserData>/my_format_file.py
. -
Edit this file. Adjust the classname and the default extensions. Implementing the reader (function
_read()
) and optionally the writer. Look for XXX in this file and replace them with appropriate values for your file format. NOTE: it's important to have "File" in your classname, for instance the class name could be "MyFormatFile". You can also adjust the priority level (the priority static method), which will define how early the fileformat will be tried in the list of fileformats.
The fileformats should now be available within weio. The function weio.read
will loop through all available file formats and attempt to read a given file. You can call weio.fileFormats
to see the list of supported fileformats and see where your newly added format is located in this list. The added class may be accessed as follows `from weio.user import MyFormatFile".
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: