forked from contrailcirrus/pycontrails
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgsp_api.py
56 lines (49 loc) · 2.37 KB
/
gsp_api.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
import sys
import csv
from gsp_api_functions import gsp_api_initialize, gsp_api_close, process_single_row_direct
if __name__ == "__main__":
input_csv_path = sys.argv[1]
output_csv_path = sys.argv[2]
# Read input CSV file with the first column as the index
with open(input_csv_path, mode='r') as input_file:
reader = csv.DictReader(input_file)
rows = [row for row in reader]
if rows:
engine_model = rows[1]['engine_model'] # Assuming the column is named 'engine_model'
print(f"Engine Model: {engine_model}")
else:
print("No rows found in the input CSV.")
# Initialize the DLL
gspdll = gsp_api_initialize(engine_model)
# Prepare to write the output CSV
output_headers = ['index', 'PT3', 'TT3', 'TT4', 'specific_humidity_gsp', 'FAR', 'fuel_flow_gsp', 'thrust_gsp', 'W3']
with open(output_csv_path, mode='w', newline='') as output_file:
writer = csv.writer(output_file)
writer.writerow(output_headers) # Write the header row
# Process each row
try:
for row in rows:
# Extract the index and inputs
index = row['index'] # Unnamed column for the index
mach = float(row['mach'])
specific_humidity = float(row['specific_humidity'])
air_temperature = float(row['air_temperature'])
air_pressure = float(row['air_pressure'])
thrust_per_engine = float(row['thrust_per_engine'])
water_injection_kg_s = float(row['water_injection_kg_s'])
lhv = float(row['LHV'])
engine = engine_model
flight_phase = row['flight_phase']
# Process the row using the DLL
try:
output_values = process_single_row_direct(
gspdll, mach, specific_humidity, air_temperature, air_pressure, thrust_per_engine, water_injection_kg_s, lhv, engine, flight_phase
)
except Exception as e:
print(f"Error processing row with index {index}: {e}")
output_values = [None] * 8 # Placeholder for failed rows
# Write the result to the output CSV
writer.writerow([index] + output_values)
finally:
# Ensure the DLL is properly closed
gsp_api_close(gspdll)