Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit 8e902a8

Browse files
committed
HAWC2: update of readers
1 parent ce03cb2 commit 8e902a8

11 files changed

+1142
-1069
lines changed

Diff for: pyFAST/input_output/hawc2_ae_file.py

+20
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Hawc2 AE file
33
"""
44
import os
5+
import numpy as np
56
import pandas as pd
67

78
try:
@@ -65,7 +66,26 @@ def toDataFrame(self):
6566
dfs[name] = pd.DataFrame(data=self.data.ae_sets[iset+1], columns=cols)
6667
return dfs
6768

69+
@property
70+
def sets(self):
71+
# Returns a list of ae_sets, otherwise not easy to iterate
72+
sets=[]
73+
for iset,aeset in enumerate(self.data.ae_sets):
74+
sets.append(self.data.ae_sets[iset+1])
75+
return sets
76+
6877
# --- Convenient utils
6978
def add_set(self, **kwargs):
7079
self.data.add_set(**kwargs)
7180

81+
def __repr__(self):
82+
cols=['radius_[m]','chord_[m]','thickness_[%]','pc_set_[#]']
83+
nRows = [np.asarray(s).shape[0] for s in self.sets]
84+
s='<{} object>\n'.format(type(self).__name__)
85+
s+='| Attributes:\n'
86+
s+='| - filename: {}\n'.format(self.filename)
87+
s+='| - data: AEFile, with attributes `ae_sets`\n'
88+
s+='| Derived attributes:\n'
89+
s+='| * sets: list of {} arrays, length: {}, 4 columns: {}\n'.format(len(self.data.ae_sets), nRows, cols)
90+
s+='| Methods: add_set, toDataFrame\n'
91+
return s

Diff for: pyFAST/input_output/hawc2_htc_file.py

+25-10
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,41 @@ def formatName():
2323

2424
def _read(self):
2525
self.data = HTCFile(self.filename)
26-
self.data.contents # trigger read
2726

2827
def _write(self):
2928
self.data.save(self.filename)
3029

3130
def __repr__(self):
32-
s='<{} object> with attribute `data`\n'.format(type(self).__name__)
31+
s='<{} object>\n'.format(type(self).__name__)
32+
s+='| Attributes:\n'
33+
s+='| - data: HTCFile with keys: {}`\n'.format(list(self.data.keys()))
34+
s+='| Derived attributes:\n'
35+
s+='| * bodyNames: {}\n'.format(self.bodyNames)
36+
s+='| * bodyDict: dict with keys bodyNames\n'
37+
s+='| Methods: bodyByName, bodyC2, setBodyC2\n'
3338
return s
3439

35-
def bodyByName(self, bodyname):
36-
""" return body inputs given a body name"""
40+
@property
41+
def bodyNames(self):
42+
return list(self.bodyDict.keys())
43+
44+
@property
45+
def bodyDict(self):
3746
struct = self.data.new_htc_structure
3847
bodyKeys = [k for k in struct.keys() if k.startswith('main_body')]
39-
bdies = [struct[k] for k in bodyKeys if struct[k].name[0]==bodyname]
40-
if len(bdies)==1:
41-
return bdies[0]
42-
elif len(bdies)==0:
48+
#print('>>> keys', struct.keys())
49+
bdDict={}
50+
for k in bodyKeys:
51+
bodyName = struct[k].name[0]
52+
bdDict[bodyName] = struct[k]
53+
return bdDict
54+
55+
def bodyByName(self, bodyname):
56+
""" return body inputs given a body name"""
57+
bodyDict= self.bodyDict
58+
if bodyname not in bodyDict.keys():
4359
raise Exception('No body found with name {} in file {}'.format(bodyname,self.filename))
44-
else:
45-
raise Exception('Several bodies found with name {} in file {}'.format(bodyname,self.filename))
60+
return bodyDict[bodyname]
4661

4762
def bodyC2(self, bdy):
4863
""" return body C2_def given body inputs"""

Diff for: pyFAST/input_output/hawc2_pc_file.py

+20
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,23 @@ def add_set(self, set_label, thicknesses, profiles):
7575
"""
7676
self.data.pc_sets[set_label] = (np.array(thicknesses), profiles)
7777

78+
@property
79+
def sets(self):
80+
return self.pc_sets
81+
82+
def __repr__(self):
83+
cols=['Alpha_[deg]','Cl_[-]','Cd_[-]','Cm_[-]']
84+
#nRows = 0
85+
s='<{} object>\n'.format(type(self).__name__)
86+
s+='| Attributes:\n'
87+
s+='| - filename: {}\n'.format(self.filename)
88+
s+='| - data: PCFile, with attributes `pc_sets`\n'
89+
s+='| Derived attributes:\n'
90+
s+='| * sets: dict of length: {}:\n'.format(len(self.data.pc_sets))
91+
for iset in self.data.pc_sets.keys():
92+
vt, vpolar = self.data.pc_sets[iset]
93+
nRows = [np.asarray(s).shape[0] for s in vpolar]
94+
s+='| key: {}, len: {}, thicknesses: {}, rows: {}\n'.format(iset, len(vt), vt, nRows)
95+
s+='| Methods: add_set, toDataFrame\n'
96+
return s
97+

0 commit comments

Comments
 (0)