-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathturbineStreamTubeSliceCompile.py
executable file
·115 lines (78 loc) · 3.83 KB
/
turbineStreamTubeSliceCompile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/env python3
import logging
LEVEL = logging.INFO
logger = logging.getLogger(__name__)
import sys
import argparse
import numpy as np
import utils
import constants as const
################################################################################
def turbineStreamTubeSliceIntegrated(casename):
"""Created by Jeffrey Johnston for sowfatools. October 2024.
Read csv files containing integrated velocity data for streamtube slices and
stitch together. One file created for each turbine.
"""
directory = const.PARAVIEW_DIRECTORY/casename/'streamtube'
if not directory.is_dir():
logger.warning(f'No directory found for case {casename}')
return
upstream_filepath = directory/f'{casename}_streamtube_upstreamTurbine_integratedAreaVelocity'
downstream_filepath = directory/f'{casename}_streamtube_downstreamTurbine_integratedAreaVelocity'
# add overwrite option / filecheck here
# find files named e.g. t006_streamTube_upstreamTurbine_slice_6D_integrated.csv
filepaths = [filepath for filepath in directory.iterdir()
if filepath.name.startswith(f'{casename}_streamtube')
and filepath.name.endswith('D_integrated.csv')]
if not filepaths:
logger.warning(f'No files found for case {casename}. Continuing.')
return
############################################################################
logger.info(f'Processing case {casename}')
# extract numerical distance preceeding 'D' in filename
# extract numerical distance preceeding 'D' in filename
distances = []
for filepath in filepaths:
filepath_parts = filepath.stem.split('_')
if len(filepath_parts) == 6:
distance = int(filepath_parts[4].removesuffix('D'))
else:
distance = float('.'.join(filepath_parts[4:6]).removesuffix('D'))
distances.append(distance)
filepaths = list(zip(distances,filepaths))
del distances
filepaths.sort(key=lambda x: x[0])
upstream = len([filepath for filepath in filepaths
if 'upstream' in filepath[1].name])
downstream = len([filepath for filepath in filepaths
if 'downstream' in filepath[1].name])
logger.debug(f'Found {len(filepaths)} files: {upstream=}, {downstream=}')
upstream_data = np.empty((upstream,3))
downstream_data = np.empty((downstream,3))
upstream_i = 0
downstream_i = 0
for filepath in filepaths:
data = np.genfromtxt(filepath[1], delimiter=',', skip_header=1)
row_to_write = np.array([filepath[0],data[3],data[0]])
if 'upstream' in filepath[1].name:
upstream_data[upstream_i,:] = row_to_write
upstream_i += 1
if 'downstream' in filepath[1].name:
downstream_data[downstream_i,:] = row_to_write
downstream_i += 1
np.savetxt(upstream_filepath,upstream_data,fmt='%.4e')
np.savetxt(downstream_filepath,downstream_data,fmt='%.4e')
################################################################################
if __name__ == '__main__':
utils.configure_root_logger(level=LEVEL)
logger.debug(f'Python version: {sys.version}')
logger.debug(f'Python executable location: {sys.executable}')
description = """Read csv files containing integrated velocity data for
streamtube slices and stitch together."""
parser = argparse.ArgumentParser(description=description)
parser.add_argument('cases', help='cases to perform analysis for',
nargs='+')
args = parser.parse_args()
logger.debug(f'Parsed Command Line Arguments: {args}')
for casename in args.cases:
turbineStreamTubeSliceIntegrated(casename)