-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmainframe.py
166 lines (150 loc) · 8.57 KB
/
mainframe.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
from input_script_functions import *
from output_processing_functions import *
from os import system
from sys import exit
from time import time
from openpyxl import Workbook
__author__ = 'Max'
# all parameters are defined in depth in run_framework.py
def run_aermod_framework(surface_observations_file,
upper_air_data_file,
source_coordinate_list_x,
source_coordinate_list_y,
source_release_height_list,
source_emission_rate_list,
source_type,
source_area_x_direction_length_list,
source_area_y_direction_length_list,
source_point_stack_gas_exit_temperature_list,
source_point_stack_gas_exit_velocity_list,
source_point_stack_inside_diameter_list,
met_data_start_year,
receptor_style,
receptor_coordinate_list_x,
receptor_coordinate_list_y,
receptor_grid_starting_point_x,
receptor_grid_starting_point_y,
receptor_grid_number_receptors_x,
receptor_grid_number_receptors_y,
receptor_grid_spacing_x,
receptor_grid_spacing_y,
base_elevation,
uair_data_station_number,
surf_data_station_number,
receptor_aermap_output_file_name=None,
source_aermap_output_file_name=None,
run_aerplot='no',
aerplot_northing=None,
aerplot_easting=None,
aerplot_UTM_zone=None,
aerplot_northern_hemisphere=None
):
# setup see time it took for program to run
start_time = time()
# ********* INPUT CHECKS **************
number_sources = len(source_coordinate_list_x)
if receptor_style == 'discrete':
number_receptors = len(receptor_coordinate_list_x)
else:
number_receptors = receptor_grid_number_receptors_x * receptor_grid_number_receptors_y
# running the check_source_data_for_length on parameters
# if there is only one data point, copies to correct number of source points
# also checks if data is valid, returns a string if data is not valid
source_emission_rate_list = check_source_data_for_length(source_emission_rate_list, number_sources)
source_release_height_list = check_source_data_for_length(source_release_height_list, number_sources)
source_area_x_direction_length_list = check_source_data_for_length(source_area_x_direction_length_list,
number_sources)
source_area_y_direction_length_list = check_source_data_for_length(source_area_y_direction_length_list,
number_sources)
source_point_stack_gas_exit_temperature_list = \
check_source_data_for_length(source_point_stack_gas_exit_temperature_list, number_sources)
source_point_stack_gas_exit_velocity_list = \
check_source_data_for_length(source_point_stack_gas_exit_velocity_list, number_sources)
source_point_stack_inside_diameter_list = \
check_source_data_for_length(source_point_stack_inside_diameter_list, number_sources)
# runs check_for_valid_inputs to check if check_source_data_for_length returned an error for any input
valid_inputs_result = check_for_valid_inputs(source_coordinate_list_x,
source_coordinate_list_y,
source_type,
source_emission_rate_list,
source_release_height_list,
source_area_x_direction_length_list,
source_area_y_direction_length_list,
source_point_stack_gas_exit_temperature_list,
source_point_stack_gas_exit_velocity_list,
source_point_stack_inside_diameter_list,
receptor_coordinate_list_y,
receptor_coordinate_list_x,
receptor_style
)
# exits the program if there is any problems in the inputs
if not valid_inputs_result:
print('errors exist in inputs, exiting program')
exit()
# ***** CREATING AERMOD INPUT FILE *****
write_aermod_input_file(surface_observations_file,
upper_air_data_file,
source_coordinate_list_x,
source_coordinate_list_y,
source_release_height_list,
source_emission_rate_list,
source_type,
source_area_x_direction_length_list,
source_area_y_direction_length_list,
source_point_stack_gas_exit_temperature_list,
source_point_stack_gas_exit_velocity_list,
source_point_stack_inside_diameter_list,
met_data_start_year,
receptor_style,
receptor_coordinate_list_x,
receptor_coordinate_list_y,
receptor_grid_starting_point_x,
receptor_grid_starting_point_y,
receptor_grid_number_receptors_x,
receptor_grid_number_receptors_y,
receptor_grid_spacing_x,
receptor_grid_spacing_y,
base_elevation,
uair_data_station_number,
surf_data_station_number,
receptor_aermap_output_file_name[0],
source_aermap_output_file_name[0],
run_aerplot
)
# ***** CREATING AERPLOT INPUT FILE *****
if run_aerplot == 'yes':
write_aerplot_input_file(easting=aerplot_easting,
northing=aerplot_northing,
utm_zone=aerplot_UTM_zone,
northern_hemisphere=aerplot_northern_hemisphere,
google_earth_display_name="aerplot_output",
plot_file_name="aerplot_data.PLT",
output_file_name="aerplot_output")
# ***** RUNNING AERMOD *****
# for running on linux you will need a version of aermod compiled for linux, add a ./ in front of aermod
system("aermod.exe >nul")
# if aerplot is set to run, runs aerplot as well
if run_aerplot == 'yes':
system("aerplot.exe >nul")
# ***** PROCESSING OUTPUTS *****
# setting up spreadsheet and output file data
output_file_name = 'aermod.out'
spreadsheet_name = "AERMOD concentration outputs.xlsx"
output_workbook = Workbook()
output_spreadsheet = output_workbook.active
output_spreadsheet.title = "Data"
if receptor_style == 'discrete':
# setting up spreadsheet headers
spreadsheet_setup_discrete(number_receptors,output_spreadsheet, receptor_coordinate_list_x,
receptor_coordinate_list_y)
# setting up list of times that the concentration was analyzed at
find_time_lines(output_file_name, output_spreadsheet)
# adding concentrations from all receptors to excel spreadsheet
find_concentration_lines_discrete(output_file_name, number_receptors, output_spreadsheet)
elif receptor_style == 'grid':
# just runs script to find annual averages at each receptor in grid
find_grid_concentration_average(output_spreadsheet, output_file_name)
# Saving workbook to excel file and printing runtime of program
output_workbook.save(spreadsheet_name)
run_time = time() - start_time
print("Program runtime: " + str(int(run_time / 60)) + " minutes " + str(int(run_time % 60)) + " seconds")