Skip to content

Commit cf73e7d

Browse files
committed
Add some fallback when reading lava data.iter files
1 parent b4cb3a6 commit cf73e7d

File tree

1 file changed

+30
-10
lines changed

1 file changed

+30
-10
lines changed

cape/pylava/databook.py

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import os
1313

1414
# Third-party imports
15+
from numpy import ndarray
1516

1617
# Local imports
1718
from .dataiterfile import DataIterFile
@@ -107,27 +108,46 @@ def readfile(self, fname: str) -> dict:
107108
# Read the data.iter
108109
data = DataIterFile(fname)
109110
# Unpack component name
110-
comp = self.comp
111+
comp = self.comp.lower()
111112
# Initialize data for output
112113
db = basedata.BaseData()
113114
# Identify iteration column to use
114115
icol = "nt" if "nt" in data else "iter"
115116
# Force coeff prefix
116-
fpre = "c" if f"cx_{comp}" in data else "cf"
117+
infix = '' if (f'cx_{comp}' in data or f"fx_{comp}" in data) else 'f'
117118
# Save data
118119
db.save_col("i", data[icol])
119120
db.save_col("solver_iter", data[icol])
120-
db.save_col("CL", data[f"cl_{comp}"])
121-
db.save_col("CD", data[f"cd_{comp}"])
122-
db.save_col("CA", data[f"{fpre}x_{comp}"])
123-
db.save_col("CY", data[f"{fpre}y_{comp}"])
124-
db.save_col("CN", data[f"{fpre}z_{comp}"])
125-
db.save_col("CLL", data[f"cmx_{comp}"])
126-
db.save_col("CLM", data[f"cmy_{comp}"])
127-
db.save_col("CLN", data[f"cmz_{comp}"])
121+
# Save coefficients
122+
db.save_col("CL", self.get_datacol(data, '', 'l'))
123+
db.save_col("CD", self.get_datacol(data, '', 'd'))
124+
db.save_col("CA", self.get_datacol(data, infix, 'x'))
125+
db.save_col("CY", self.get_datacol(data, infix, 'y'))
126+
db.save_col("CN", self.get_datacol(data, infix, 'z'))
127+
db.save_col("CLL", self.get_datacol(data, '', 'mx', ''))
128+
db.save_col("CLM", self.get_datacol(data, '', 'my', ''))
129+
db.save_col("CLN", self.get_datacol(data, '', 'mz', ''))
128130
# Output
129131
return db
130132

133+
def get_datacol(
134+
self,
135+
data: dict,
136+
infix: str,
137+
coeff: str,
138+
prefix: str = 'f') -> ndarray:
139+
# Possible col names
140+
col = f"{coeff}_{self.comp.lower()}"
141+
col1 = f"c{infix}{col}"
142+
col2 = f"{prefix}{col}"
143+
# Use best
144+
if col1 in data:
145+
# Coefficient defined directly
146+
return data[col1]
147+
else:
148+
# Use force
149+
return data.get(col2)
150+
131151

132152
# Iterative residual history
133153
class CaseResid(cdbook.CaseResid):

0 commit comments

Comments
 (0)