Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pydatview/io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,14 @@ def fileFormats(userpath=None, ignoreErrors=False, verbose=False):
from .raawmat_file import RAAWMatFile
from .rosco_discon_file import ROSCODISCONFile
from .rosco_performance_file import ROSCOPerformanceFile
try:
from .hawc2_hdf5_file import HAWC2Hdf5File
except ImportError:
HAWC2Hdf5File=None
from .plot3d_file import Plot3DFile
from .yaml_file import YAMLFile
from .airfoil_file import AirfoilShapeFile

priorities = []
formats = []
def addFormat(priority, fmt):
Expand All @@ -97,6 +102,8 @@ def addFormat(priority, fmt):
addFormat(30, FileFormat(HAWCStab2PwrFile))
addFormat(30, FileFormat(HAWCStab2IndFile))
addFormat(30, FileFormat(HAWCStab2CmbFile))
if HAWC2Hdf5File is not None:
addFormat(30, FileFormat(HAWC2Hdf5File))
addFormat(30, FileFormat(MannBoxFile))
addFormat(40, FileFormat(FLEXBladeFile))
addFormat(40, FileFormat(FLEXProfileFile))
Expand Down
43 changes: 43 additions & 0 deletions pydatview/io/hawc2_hdf5_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from .wetb.gtsdf.gtsdf import load
from .file import File, WrongFormatError
import numpy as np
import pandas as pd

class HAWC2Hdf5File(File):

@staticmethod
def defaultExtensions():
return ['.hdf5']

@staticmethod
def formatName():
return 'HAWC2 hdf5 file'

def __init__(self, filename=None, **kwargs):
self.info = {}
self.data = np.array([])
super(HAWC2Hdf5File, self).__init__(filename=filename, **kwargs)

def _read(self):
try:
time, data, info = load(self.filename)
self.time = time
self.time = self.time.reshape(self.time.size, 1) # force shape(C, 1) for concatenation
self.data = data
self.info['attribute_names'] = info['attribute_names']
self.info['attribute_units'] = info['attribute_units']
self.info['attribute_descr'] = info['attribute_descriptions']
except WrongFormatError as e:
raise WrongFormatError('hdf5 File {}: '.format(self.filename)+'\n'+e.args[0])

def _toDataFrame(self):
# Appending time to form the dataframe
names = ['Time'] + self.info['attribute_names']
units = ['s'] + self.info['attribute_units']
units = [u.replace('(','').replace(')','').replace('[','').replace(']','') for u in units]
data = np.concatenate((self.time, self.data), axis=1)
cols = [n + '_[' + u + ']' for n, u in zip(names, units)]
return pd.DataFrame(data=data, columns=cols)

def _write(self):
pass
7 changes: 7 additions & 0 deletions pydatview/io/wetb/AUTHORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
==========
Developers
==========

* Mads Mølgaard Pedersen
* David R.S. Verelst
* Carlo Tibaldi
14 changes: 14 additions & 0 deletions pydatview/io/wetb/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
wetb is free software; you can redistribute it and/or modify it under the terms
of the GNU General Public License (GPL, http://www.gnu.org/copyleft/gpl.html)
as published by the Free Software Foundation; either version 3 of the License,
or (at your option) any later version.

wetb is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

See the GNU General Public License for more details http://www.gnu.org/licenses/

We encourage you to submit new code for possible inclusion in future versions of
wetb.

6 changes: 6 additions & 0 deletions pydatview/io/wetb/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

The wind energy toolbox (WETB) is available here:

https://toolbox.pages.windenergy.dtu.dk/WindEnergyToolbox/

License and authors can be found in this directory.
74 changes: 74 additions & 0 deletions pydatview/io/wetb/gtsdf/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
"""
The 'General Time Series Data Format', gtsdf, is a binary hdf5 data format for storing time series data,\n
specified by \n
Mads M. Pedersen (mmpe@dtu.dk), DTU-Wind Energy, Aeroelastic design (AED)

Features:

- Single file
- Optional data type, e.g. 16bit integer (compact) or 64 bit floating point (high precision)
- Precise time representation (including absolute times)
- Additional data blocks can be appended continuously
- Optional specification of name and description of dataset
- Optional specification of name, unit and description of attributes
- NaN support

This module contains three methods:

- load_
- save_
- append_block_

.. _load: gtsdf.html#gtsdf.load
.. _save: gtsdf.html#gtsdf.save
.. _append_block: gtsdf.html#gtsdf.append_block

"""

d = None
d = dir()

from .gtsdf import save
from .gtsdf import load
from .gtsdf import append_block
from .gtsdf import load_pandas

class Dataset(object):
def __init__(self, filename):
self.filename = filename
self.time, self.data, self.info = load(filename)
def __call__(self, id):
if isinstance(id, str):
if id=="Time":
return self.time
else:
return self(self.info['attribute_names'].index(id) + 2)
if id == 1:
return self.time
else:
return self.data[:, id - 2]

def attribute_names_str(self):
return "\n".join(["1: Time"]+["%d: %s"%(i,n) for i, n in enumerate(self.info['attribute_names'],2)])

def __getattribute__(self, name):
try:
return object.__getattribute__(self, name)

except Exception as e:
try:
return self(name)
except:
# for i, n in enumerate(self.info['attribute_names']):
# print (i,n)
raise e

def __contains__(self, name):
return name in self.info['attribute_names']


__all__ = sorted([m for m in set(dir()) - set(d)])




Loading