crunchflow 2.0.3__tar.gz → 2.0.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {crunchflow-2.0.3 → crunchflow-2.0.4}/PKG-INFO +1 -1
- {crunchflow-2.0.3 → crunchflow-2.0.4}/crunchflow/input/blocks.py +1 -1
- {crunchflow-2.0.3 → crunchflow-2.0.4}/crunchflow/output/spatial.py +82 -16
- {crunchflow-2.0.3 → crunchflow-2.0.4}/pyproject.toml +1 -1
- {crunchflow-2.0.3 → crunchflow-2.0.4}/LICENSE +0 -0
- {crunchflow-2.0.3 → crunchflow-2.0.4}/README.md +0 -0
- {crunchflow-2.0.3 → crunchflow-2.0.4}/crunchflow/__init__.py +0 -0
- {crunchflow-2.0.3 → crunchflow-2.0.4}/crunchflow/input/__init__.py +0 -0
- {crunchflow-2.0.3 → crunchflow-2.0.4}/crunchflow/input/inputfile.py +0 -0
- {crunchflow-2.0.3 → crunchflow-2.0.4}/crunchflow/output/__init__.py +0 -0
- {crunchflow-2.0.3 → crunchflow-2.0.4}/crunchflow/output/timeseries.py +0 -0
- {crunchflow-2.0.3 → crunchflow-2.0.4}/crunchflow/util.py +0 -0
|
@@ -42,21 +42,24 @@ def get_tec_metadata(file, folder='.'):
|
|
|
42
42
|
# Open file and read line by line
|
|
43
43
|
inpath = os.path.join(folder, file)
|
|
44
44
|
with open(inpath) as f:
|
|
45
|
+
lines = f.readlines()
|
|
46
|
+
|
|
45
47
|
# Read the first line to determine the format of the file
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
title = line.split('"')[1]
|
|
48
|
+
if "TITLE" in lines[0]:
|
|
49
|
+
title = lines[0].split('"')[1]
|
|
49
50
|
fmt = '.tec'
|
|
50
|
-
elif 'Time' in
|
|
51
|
+
elif 'Time' in lines[0]:
|
|
51
52
|
title = ''
|
|
52
53
|
fmt = '.out'
|
|
54
|
+
elif 'Units' in lines[0]:
|
|
55
|
+
title = ''
|
|
56
|
+
fmt = '.dat'
|
|
53
57
|
else:
|
|
54
58
|
raise ValueError("Could not determine the format of this file")
|
|
55
59
|
|
|
56
60
|
# Read the rest of the header
|
|
57
61
|
if fmt == '.tec':
|
|
58
|
-
|
|
59
|
-
columns = line.split('"')
|
|
62
|
+
columns = lines[1].split('"')
|
|
60
63
|
|
|
61
64
|
# Remove x, y, z
|
|
62
65
|
columns = [col.strip() for col in columns]
|
|
@@ -70,11 +73,14 @@ def get_tec_metadata(file, folder='.'):
|
|
|
70
73
|
for col in remove_fields:
|
|
71
74
|
columns.remove(col)
|
|
72
75
|
elif fmt == '.out':
|
|
73
|
-
|
|
74
|
-
|
|
76
|
+
# pH files do not have a units line
|
|
77
|
+
if 'pH' in file:
|
|
78
|
+
columns_line = lines[1] # skip units line
|
|
79
|
+
else:
|
|
80
|
+
columns_line = lines[2]
|
|
75
81
|
|
|
76
82
|
# Split on whitespace
|
|
77
|
-
raw_cols =
|
|
83
|
+
raw_cols = columns_line.split()
|
|
78
84
|
|
|
79
85
|
# Some versions of CrunchFlow don't include column names
|
|
80
86
|
# in this case, the column entries should be numeric and we'll
|
|
@@ -84,6 +90,35 @@ def get_tec_metadata(file, folder='.'):
|
|
|
84
90
|
else:
|
|
85
91
|
columns = raw_cols
|
|
86
92
|
|
|
93
|
+
elif fmt == '.dat':
|
|
94
|
+
title = lines[1].split('"')[1]
|
|
95
|
+
columns = lines[2].split('"')
|
|
96
|
+
|
|
97
|
+
# Remove x, y, z
|
|
98
|
+
columns = [col.strip() for col in columns]
|
|
99
|
+
for col in ['VARIABLES =']:
|
|
100
|
+
if col in columns:
|
|
101
|
+
columns.remove(col)
|
|
102
|
+
|
|
103
|
+
# Remove commas, which can be repeated so will not be removed with loop above
|
|
104
|
+
columns = [col.replace(',', '') for col in columns]
|
|
105
|
+
|
|
106
|
+
# Remove whitespace, which was reduced to len 0 via col.strip()
|
|
107
|
+
remove_fields = [col for col in columns if len(col) == 0]
|
|
108
|
+
for col in remove_fields:
|
|
109
|
+
columns.remove(col)
|
|
110
|
+
|
|
111
|
+
# With .dat files, the naming scheme for x, y and z varies
|
|
112
|
+
# depending on the spatial units
|
|
113
|
+
if len(lines[3].split(',')) == 3:
|
|
114
|
+
# then this is 2d, so remove first two columns
|
|
115
|
+
columns = columns[2:]
|
|
116
|
+
elif len(lines[3].split(',')) == 4:
|
|
117
|
+
# then this is 3d, so remove first three columns
|
|
118
|
+
columns = columns[3:]
|
|
119
|
+
else:
|
|
120
|
+
raise ValueError("Could not determine the format of this file")
|
|
121
|
+
|
|
87
122
|
return columns, title, fmt
|
|
88
123
|
|
|
89
124
|
|
|
@@ -248,19 +283,22 @@ class SpatialProfile:
|
|
|
248
283
|
output, in CrunchFlow time units
|
|
249
284
|
suffix : str, optional
|
|
250
285
|
file ending of the tec files to read in. This can vary depending on the
|
|
251
|
-
version of CrunchTope used. The default is '.tec', but '.out'
|
|
252
|
-
tried if '.tec' files are not found.
|
|
286
|
+
version of CrunchTope used. The default is '.tec', but '.out' and '.dat'
|
|
287
|
+
are also tried if '.tec' files are not found.
|
|
253
288
|
"""
|
|
254
289
|
|
|
255
290
|
# Glob doesn't support regex, so match manually using re and os
|
|
256
291
|
search_str = '^' + fileprefix + '[0-9]+%s' % suffix
|
|
257
292
|
unsort_files = [f for f in os.listdir(folder) if re.search(search_str, f)]
|
|
258
293
|
|
|
294
|
+
# Try again with .out or .dat suffix
|
|
259
295
|
if len(unsort_files) == 0:
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
296
|
+
for try_suffix in ['.out', '.dat']:
|
|
297
|
+
search_str = '^' + fileprefix + '[0-9]+' + try_suffix
|
|
298
|
+
unsort_files = [f for f in os.listdir(folder) if re.search(search_str, f)]
|
|
299
|
+
if len(unsort_files) > 0:
|
|
300
|
+
suffix = try_suffix
|
|
301
|
+
break
|
|
264
302
|
|
|
265
303
|
if len(unsort_files) == 0:
|
|
266
304
|
raise ValueError("No files found matching %s. Double check the suffix and\n "
|
|
@@ -286,7 +324,7 @@ class SpatialProfile:
|
|
|
286
324
|
# Otherwise, try setting it by reading from each .out file
|
|
287
325
|
if self.fmt == '.out':
|
|
288
326
|
self.output_times = [get_out_output_time(f) for f in self.files]
|
|
289
|
-
elif self.fmt
|
|
327
|
+
elif self.fmt in ['.tec', '.dat']:
|
|
290
328
|
self.output_times = None
|
|
291
329
|
|
|
292
330
|
# Get the grid size
|
|
@@ -321,6 +359,24 @@ class SpatialProfile:
|
|
|
321
359
|
else:
|
|
322
360
|
skiprows = 3
|
|
323
361
|
self.coords = np.loadtxt(self.files[0], skiprows=skiprows, usecols=[0])
|
|
362
|
+
elif self.fmt == '.dat':
|
|
363
|
+
with open(self.files[0]) as f:
|
|
364
|
+
lines = f.readlines()
|
|
365
|
+
|
|
366
|
+
fields = lines[3].split(',')[1:]
|
|
367
|
+
if len(fields) == 2:
|
|
368
|
+
self.nx = int(re.sub('\\D', '', fields[0]))
|
|
369
|
+
self.ny = int(re.sub('\\D', '', fields[1]))
|
|
370
|
+
self.nz = np.nan
|
|
371
|
+
elif len(fields) == 3:
|
|
372
|
+
self.nx = int(re.sub('\\D', '', fields[0]))
|
|
373
|
+
self.ny = int(re.sub('\\D', '', fields[1]))
|
|
374
|
+
self.nz = int(re.sub('\\D', '', fields[2]))
|
|
375
|
+
else:
|
|
376
|
+
raise ValueError("Could not determine the coordinates in this file")
|
|
377
|
+
self.coords = np.loadtxt(self.files[0], skiprows=4, usecols=[0, 1])
|
|
378
|
+
self.griddedX = self.coords[:, 0].reshape(self.ny, self.nx)
|
|
379
|
+
self.griddedY = self.coords[:, 1].reshape(self.ny, self.nx)
|
|
324
380
|
|
|
325
381
|
def plot(self, var, time=None, plot_type='image', figsize=(12,3),
|
|
326
382
|
**kwargs):
|
|
@@ -584,6 +640,16 @@ class SpatialProfile:
|
|
|
584
640
|
skiprows = 3
|
|
585
641
|
col_no = self.columns.index(var)
|
|
586
642
|
data = np.loadtxt(self.files[time - 1], skiprows=skiprows, usecols=col_no)
|
|
643
|
+
elif self.fmt == '.dat':
|
|
644
|
+
if np.isnan(self.nz):
|
|
645
|
+
col_no = self.columns.index(var) + 2
|
|
646
|
+
data = np.loadtxt(self.files[time - 1], skiprows=4, usecols=col_no)
|
|
647
|
+
data = data.reshape(self.ny, self.nx)
|
|
648
|
+
else:
|
|
649
|
+
col_no = self.columns.index(var) + 3
|
|
650
|
+
data = np.loadtxt(self.files[time - 1], skiprows=4, usecols=col_no)
|
|
651
|
+
data = data.reshape(self.nz, self.ny, self.nx)
|
|
652
|
+
|
|
587
653
|
else:
|
|
588
654
|
raise ValueError("Could not determine the format of this file")
|
|
589
655
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|