pyelq 1.1.0__py3-none-any.whl
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.
- pyelq/__init__.py +19 -0
- pyelq/component/__init__.py +6 -0
- pyelq/component/background.py +391 -0
- pyelq/component/component.py +79 -0
- pyelq/component/error_model.py +327 -0
- pyelq/component/offset.py +183 -0
- pyelq/component/source_model.py +875 -0
- pyelq/coordinate_system.py +598 -0
- pyelq/data_access/__init__.py +5 -0
- pyelq/data_access/data_access.py +104 -0
- pyelq/dispersion_model/__init__.py +5 -0
- pyelq/dispersion_model/gaussian_plume.py +625 -0
- pyelq/dlm.py +497 -0
- pyelq/gas_species.py +232 -0
- pyelq/meteorology.py +387 -0
- pyelq/model.py +209 -0
- pyelq/plotting/__init__.py +5 -0
- pyelq/plotting/plot.py +1183 -0
- pyelq/preprocessing.py +262 -0
- pyelq/sensor/__init__.py +5 -0
- pyelq/sensor/beam.py +55 -0
- pyelq/sensor/satellite.py +59 -0
- pyelq/sensor/sensor.py +241 -0
- pyelq/source_map.py +115 -0
- pyelq/support_functions/__init__.py +5 -0
- pyelq/support_functions/post_processing.py +377 -0
- pyelq/support_functions/spatio_temporal_interpolation.py +229 -0
- pyelq-1.1.0.dist-info/LICENSE.md +202 -0
- pyelq-1.1.0.dist-info/LICENSES/Apache-2.0.txt +73 -0
- pyelq-1.1.0.dist-info/METADATA +127 -0
- pyelq-1.1.0.dist-info/RECORD +32 -0
- pyelq-1.1.0.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,625 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2024 Shell Global Solutions International B.V. All Rights Reserved.
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
# -*- coding: utf-8 -*-
|
|
6
|
+
"""Gaussian Plume module.
|
|
7
|
+
|
|
8
|
+
The class for the Gaussian Plume dispersion model used in pyELQ.
|
|
9
|
+
|
|
10
|
+
The Mathematics of Atmospheric Dispersion Modeling, John M. Stockie, DOI. 10.1137/10080991X
|
|
11
|
+
|
|
12
|
+
"""
|
|
13
|
+
from copy import deepcopy
|
|
14
|
+
from dataclasses import dataclass
|
|
15
|
+
from typing import Callable, Union
|
|
16
|
+
|
|
17
|
+
import numpy as np
|
|
18
|
+
|
|
19
|
+
import pyelq.support_functions.spatio_temporal_interpolation as sti
|
|
20
|
+
from pyelq.coordinate_system import ENU, LLA
|
|
21
|
+
from pyelq.gas_species import GasSpecies
|
|
22
|
+
from pyelq.meteorology import Meteorology, MeteorologyGroup
|
|
23
|
+
from pyelq.sensor.beam import Beam
|
|
24
|
+
from pyelq.sensor.satellite import Satellite
|
|
25
|
+
from pyelq.sensor.sensor import Sensor, SensorGroup
|
|
26
|
+
from pyelq.source_map import SourceMap
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@dataclass
|
|
30
|
+
class GaussianPlume:
|
|
31
|
+
"""Defines the Gaussian plume dispersion model class.
|
|
32
|
+
|
|
33
|
+
Attributes:
|
|
34
|
+
source_map (Sourcemap): SourceMap object used for the dispersion model
|
|
35
|
+
source_half_width (float): Source half width (radius) to be used in the Gaussian plume model (in meters)
|
|
36
|
+
minimum_contribution (float): All elements in the Gaussian plume coupling smaller than this number will be set
|
|
37
|
+
to 0. Helps to speed up matrix multiplications/matrix inverses, also helps with stability
|
|
38
|
+
|
|
39
|
+
"""
|
|
40
|
+
|
|
41
|
+
source_map: SourceMap
|
|
42
|
+
source_half_width: float = 1
|
|
43
|
+
minimum_contribution: float = 0
|
|
44
|
+
|
|
45
|
+
def compute_coupling(
|
|
46
|
+
self,
|
|
47
|
+
sensor_object: Union[SensorGroup, Sensor],
|
|
48
|
+
meteorology_object: Union[MeteorologyGroup, Meteorology],
|
|
49
|
+
gas_object: GasSpecies = None,
|
|
50
|
+
output_stacked: bool = False,
|
|
51
|
+
run_interpolation: bool = True,
|
|
52
|
+
) -> Union[list, np.ndarray, dict]:
|
|
53
|
+
"""Top level function to calculate the Gaussian plume coupling.
|
|
54
|
+
|
|
55
|
+
Calculates the coupling for either a single sensor object or a dictionary of sensor objects.
|
|
56
|
+
|
|
57
|
+
When both a SensorGroup and a MeteorologyGroup have been passed in, we assume they are consistent and contain
|
|
58
|
+
exactly the same keys for each item in both groups. Also assuming interpolation has been performed and time axes
|
|
59
|
+
are consistent, so we set run_interpolation to False
|
|
60
|
+
|
|
61
|
+
When you input a SensorGroup and a single Meteorology object we convert this object into a dictionary, so we
|
|
62
|
+
don't have to duplicate the same code.
|
|
63
|
+
|
|
64
|
+
Args:
|
|
65
|
+
sensor_object (Union[SensorGroup, Sensor]): Single sensor object or SensorGroup object which is used in the
|
|
66
|
+
calculation of the plume coupling.
|
|
67
|
+
meteorology_object (Union[MeteorologyGroup, Meteorology]): Meteorology object or MeteorologyGroup object
|
|
68
|
+
which is used in the calculation of the plume coupling.
|
|
69
|
+
gas_object (GasSpecies, optional): Optional input, a gas species object to correctly calculate the
|
|
70
|
+
gas density which is used in the conversion of the units of the Gaussian plume coupling
|
|
71
|
+
output_stacked (bool, optional): if true outputs as stacked np.array across sensors if not
|
|
72
|
+
outputs as dict
|
|
73
|
+
run_interpolation (bool, optional): logical indicating whether interpolation of the meteorological data to
|
|
74
|
+
the sensor/source is required. Defaults to True.
|
|
75
|
+
|
|
76
|
+
Returns:
|
|
77
|
+
plume_coupling (Union[list, np.ndarray, dict]): List of arrays, single array or dictionary containing the
|
|
78
|
+
plume coupling in hr/kg. When a single source object is passed in as input this function returns a list
|
|
79
|
+
or an array depending on the sensor type.
|
|
80
|
+
If a dictionary of sensor objects is passed in as input and output_stacked=False this function returns
|
|
81
|
+
a dictionary consistent with the input dictionary keys, containing the corresponding plume coupling
|
|
82
|
+
outputs for each sensor.
|
|
83
|
+
If a dictionary of sensor objects is passed in as input and output_stacked=True this function returns
|
|
84
|
+
a np.array containing the stacked coupling matrices.
|
|
85
|
+
|
|
86
|
+
"""
|
|
87
|
+
if isinstance(sensor_object, SensorGroup):
|
|
88
|
+
output = {}
|
|
89
|
+
if isinstance(meteorology_object, Meteorology):
|
|
90
|
+
meteorology_object = dict.fromkeys(sensor_object.keys(), meteorology_object)
|
|
91
|
+
elif isinstance(meteorology_object, MeteorologyGroup):
|
|
92
|
+
run_interpolation = False
|
|
93
|
+
|
|
94
|
+
for sensor_key in sensor_object:
|
|
95
|
+
output[sensor_key] = self.compute_coupling_single_sensor(
|
|
96
|
+
sensor_object=sensor_object[sensor_key],
|
|
97
|
+
meteorology=meteorology_object[sensor_key],
|
|
98
|
+
gas_object=gas_object,
|
|
99
|
+
run_interpolation=run_interpolation,
|
|
100
|
+
)
|
|
101
|
+
if output_stacked:
|
|
102
|
+
output = np.concatenate(tuple(output.values()), axis=0)
|
|
103
|
+
|
|
104
|
+
elif isinstance(sensor_object, Sensor):
|
|
105
|
+
if isinstance(meteorology_object, MeteorologyGroup):
|
|
106
|
+
raise TypeError("Please provide a single Meteorology object when using a single Sensor object")
|
|
107
|
+
|
|
108
|
+
output = self.compute_coupling_single_sensor(
|
|
109
|
+
sensor_object=sensor_object,
|
|
110
|
+
meteorology=meteorology_object,
|
|
111
|
+
gas_object=gas_object,
|
|
112
|
+
run_interpolation=run_interpolation,
|
|
113
|
+
)
|
|
114
|
+
else:
|
|
115
|
+
raise TypeError("Please provide either a Sensor or SensorGroup as input argument")
|
|
116
|
+
|
|
117
|
+
return output
|
|
118
|
+
|
|
119
|
+
def compute_coupling_single_sensor(
|
|
120
|
+
self,
|
|
121
|
+
sensor_object: Sensor,
|
|
122
|
+
meteorology: Meteorology,
|
|
123
|
+
gas_object: GasSpecies = None,
|
|
124
|
+
run_interpolation: bool = True,
|
|
125
|
+
) -> Union[list, np.ndarray]:
|
|
126
|
+
"""Wrapper function to compute the gaussian plume coupling for a single sensor.
|
|
127
|
+
|
|
128
|
+
Wrapper is used to identify specific cases and calculate the Gaussian plume coupling accordingly.
|
|
129
|
+
|
|
130
|
+
When the sensor object contains the source_on attribute we set all coupling values to 0 for observations for
|
|
131
|
+
which source_on is False. Making sure the source_on is column array, aligning with the 1st dimension
|
|
132
|
+
(nof_observations) of the plume coupling array.
|
|
133
|
+
|
|
134
|
+
Args:
|
|
135
|
+
sensor_object (Sensor): Single sensor object which is used in the calculation of the plume coupling
|
|
136
|
+
meteorology (Meteorology): Meteorology object which is used in the calculation of the plume coupling
|
|
137
|
+
gas_object (GasSpecies, optional): Optionally input a gas species object to correctly calculate the
|
|
138
|
+
gas density which is used in the conversion of the units of the Gaussian plume coupling
|
|
139
|
+
run_interpolation (bool): logical indicating whether interpolation of the meteorological data to
|
|
140
|
+
the sensor/source is required. Default passed from compute_coupling.
|
|
141
|
+
|
|
142
|
+
Returns:
|
|
143
|
+
plume_coupling (Union[list, np.ndarray]): List of arrays or single array containing the plume coupling
|
|
144
|
+
in 1e6*[hr/kg]. Entries of the list are per source in the case of a satellite sensor, if a single array
|
|
145
|
+
is returned the coupling for each observation (first dimension) to each source (second dimension) is
|
|
146
|
+
provided.
|
|
147
|
+
|
|
148
|
+
"""
|
|
149
|
+
if not isinstance(sensor_object, Sensor):
|
|
150
|
+
raise NotImplementedError("Please provide a valid sensor type")
|
|
151
|
+
|
|
152
|
+
(
|
|
153
|
+
gas_density,
|
|
154
|
+
u_interpolated,
|
|
155
|
+
v_interpolated,
|
|
156
|
+
wind_turbulence_horizontal,
|
|
157
|
+
wind_turbulence_vertical,
|
|
158
|
+
) = self.interpolate_all_meteorology(
|
|
159
|
+
meteorology=meteorology,
|
|
160
|
+
sensor_object=sensor_object,
|
|
161
|
+
gas_object=gas_object,
|
|
162
|
+
run_interpolation=run_interpolation,
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
wind_speed = np.sqrt(u_interpolated**2 + v_interpolated**2)
|
|
166
|
+
theta = np.arctan2(v_interpolated, u_interpolated)
|
|
167
|
+
|
|
168
|
+
if isinstance(sensor_object, Satellite):
|
|
169
|
+
plume_coupling = self.compute_coupling_satellite(
|
|
170
|
+
sensor_object=sensor_object,
|
|
171
|
+
wind_speed=wind_speed,
|
|
172
|
+
theta=theta,
|
|
173
|
+
wind_turbulence_horizontal=wind_turbulence_horizontal,
|
|
174
|
+
wind_turbulence_vertical=wind_turbulence_vertical,
|
|
175
|
+
gas_density=gas_density,
|
|
176
|
+
)
|
|
177
|
+
|
|
178
|
+
else:
|
|
179
|
+
plume_coupling = self.compute_coupling_ground(
|
|
180
|
+
sensor_object=sensor_object,
|
|
181
|
+
wind_speed=wind_speed,
|
|
182
|
+
theta=theta,
|
|
183
|
+
wind_turbulence_horizontal=wind_turbulence_horizontal,
|
|
184
|
+
wind_turbulence_vertical=wind_turbulence_vertical,
|
|
185
|
+
gas_density=gas_density,
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
if sensor_object.source_on is not None:
|
|
189
|
+
plume_coupling = plume_coupling * sensor_object.source_on[:, None]
|
|
190
|
+
|
|
191
|
+
return plume_coupling
|
|
192
|
+
|
|
193
|
+
def compute_coupling_array(
|
|
194
|
+
self,
|
|
195
|
+
sensor_x: np.ndarray,
|
|
196
|
+
sensor_y: np.ndarray,
|
|
197
|
+
sensor_z: np.ndarray,
|
|
198
|
+
source_z: np.ndarray,
|
|
199
|
+
wind_speed: np.ndarray,
|
|
200
|
+
theta: np.ndarray,
|
|
201
|
+
wind_turbulence_horizontal: np.ndarray,
|
|
202
|
+
wind_turbulence_vertical: np.ndarray,
|
|
203
|
+
gas_density: Union[float, np.ndarray],
|
|
204
|
+
) -> np.ndarray:
|
|
205
|
+
"""Compute the Gaussian plume coupling.
|
|
206
|
+
|
|
207
|
+
Most low level function to calculate the Gaussian plume coupling. Assuming input shapes are consistent but no
|
|
208
|
+
checking is done on this.
|
|
209
|
+
|
|
210
|
+
Setting sigma_vert to 1e-16 when it is identically zero (distance_x == 0) so we don't get a divide by 0 error
|
|
211
|
+
all the time.
|
|
212
|
+
|
|
213
|
+
Args:
|
|
214
|
+
sensor_x (np.ndarray): sensor x location relative to source [m].
|
|
215
|
+
sensor_y (np.ndarray): sensor y location relative to source [m].
|
|
216
|
+
sensor_z (np.ndarray): sensor z location relative to ground height [m].
|
|
217
|
+
source_z (np.ndarray): source z location relative to ground height [m].
|
|
218
|
+
wind_speed (np.ndarray): wind speed at source locations in [m/s].
|
|
219
|
+
theta (np.ndarray): Mathematical wind direction at source locations [radians]:
|
|
220
|
+
calculated as np.arctan2(v_component_wind, u_component_wind).
|
|
221
|
+
wind_turbulence_horizontal (np.ndarray): Horizontal wind turbulence [deg].
|
|
222
|
+
wind_turbulence_vertical (np.ndarray): Vertical wind turbulence [deg].
|
|
223
|
+
gas_density (Union[float, np.ndarray]): Gas density to use in coupling calculation [kg/m^3].
|
|
224
|
+
|
|
225
|
+
Returns:
|
|
226
|
+
plume_coupling (np.ndarray): Gaussian plume coupling in (1e6)*[hr/kg]: gives concentrations
|
|
227
|
+
in [ppm] when multiplied by sources in [kg/hr].
|
|
228
|
+
|
|
229
|
+
"""
|
|
230
|
+
cos_theta = np.cos(theta)
|
|
231
|
+
sin_theta = np.sin(theta)
|
|
232
|
+
|
|
233
|
+
distance_x = cos_theta * sensor_x + sin_theta * sensor_y
|
|
234
|
+
if np.all(distance_x < 0):
|
|
235
|
+
return np.zeros_like(distance_x)
|
|
236
|
+
|
|
237
|
+
distance_y = -sin_theta * sensor_x + cos_theta * sensor_y
|
|
238
|
+
|
|
239
|
+
sigma_hor = np.tan(wind_turbulence_horizontal * (np.pi / 180)) * np.abs(distance_x) + self.source_half_width
|
|
240
|
+
sigma_vert = np.tan(wind_turbulence_vertical * (np.pi / 180)) * np.abs(distance_x)
|
|
241
|
+
|
|
242
|
+
sigma_vert[sigma_vert == 0] = 1e-16
|
|
243
|
+
|
|
244
|
+
plume_coupling = (
|
|
245
|
+
(1 / (2 * np.pi * wind_speed * sigma_hor * sigma_vert))
|
|
246
|
+
* np.exp(-0.5 * (distance_y / sigma_hor) ** 2)
|
|
247
|
+
* (
|
|
248
|
+
np.exp(-0.5 * (((sensor_z + source_z) / sigma_vert) ** 2))
|
|
249
|
+
+ np.exp(-0.5 * (((sensor_z - source_z) / sigma_vert) ** 2))
|
|
250
|
+
)
|
|
251
|
+
)
|
|
252
|
+
|
|
253
|
+
plume_coupling = np.divide(np.multiply(plume_coupling, 1e6), (gas_density * 3600))
|
|
254
|
+
plume_coupling[np.logical_or(distance_x < 0, plume_coupling < self.minimum_contribution)] = 0
|
|
255
|
+
|
|
256
|
+
return plume_coupling
|
|
257
|
+
|
|
258
|
+
def calculate_gas_density(
|
|
259
|
+
self, meteorology: Meteorology, sensor_object: Sensor, gas_object: Union[GasSpecies, None]
|
|
260
|
+
) -> np.ndarray:
|
|
261
|
+
"""Helper function to calculate the gas density using ideal gas law.
|
|
262
|
+
|
|
263
|
+
https://en.wikipedia.org/wiki/Ideal_gas
|
|
264
|
+
|
|
265
|
+
When a gas object is passed as input we calculate the density according to that gas. We check if the
|
|
266
|
+
meteorology object has a temperature and/or pressure value and use those accordingly. Otherwise, we use Standard
|
|
267
|
+
Temperature and Pressure (STP).
|
|
268
|
+
|
|
269
|
+
We interpolate the temperature and pressure values to the source locations/times such that this is consistent
|
|
270
|
+
with the other calculations, i.e. we only do spatial interpolation when the sensor is a Satellite object
|
|
271
|
+
and temporal interpolation otherwise.
|
|
272
|
+
|
|
273
|
+
When no gas_object is passed in we just set the gas density value to 1.
|
|
274
|
+
|
|
275
|
+
Args:
|
|
276
|
+
meteorology (Meteorology): Meteorology object potentially containing temperature or pressure values
|
|
277
|
+
sensor_object (Sensor): Sensor object containing information about where to interpolate to
|
|
278
|
+
gas_object (Union[GasSpecies, None]): Gas species object which actually calculates the correct density
|
|
279
|
+
|
|
280
|
+
Returns:
|
|
281
|
+
gas_density (np.ndarray): Numpy array of shape [1 x nof_sources] (Satellite sensor)
|
|
282
|
+
or [nof_observations x 1] (otherwise) containing the gas density values to use
|
|
283
|
+
|
|
284
|
+
"""
|
|
285
|
+
if not isinstance(gas_object, GasSpecies):
|
|
286
|
+
if isinstance(sensor_object, Satellite):
|
|
287
|
+
return np.ones((1, self.source_map.nof_sources))
|
|
288
|
+
return np.ones((sensor_object.nof_observations, 1))
|
|
289
|
+
|
|
290
|
+
temperature_interpolated = self.interpolate_meteorology(
|
|
291
|
+
meteorology=meteorology, variable_name="temperature", sensor_object=sensor_object
|
|
292
|
+
)
|
|
293
|
+
if temperature_interpolated is None:
|
|
294
|
+
temperature_interpolated = np.array([[273.15]])
|
|
295
|
+
|
|
296
|
+
pressure_interpolated = self.interpolate_meteorology(
|
|
297
|
+
meteorology=meteorology, variable_name="pressure", sensor_object=sensor_object
|
|
298
|
+
)
|
|
299
|
+
if pressure_interpolated is None:
|
|
300
|
+
pressure_interpolated = np.array([[101.325]])
|
|
301
|
+
|
|
302
|
+
gas_density = gas_object.gas_density(temperature=temperature_interpolated, pressure=pressure_interpolated)
|
|
303
|
+
|
|
304
|
+
return gas_density
|
|
305
|
+
|
|
306
|
+
def interpolate_all_meteorology(
|
|
307
|
+
self, sensor_object: Sensor, meteorology: Meteorology, gas_object: GasSpecies, run_interpolation: bool
|
|
308
|
+
):
|
|
309
|
+
"""Function which carries out interpolation of all meteorological information.
|
|
310
|
+
|
|
311
|
+
The flag run_interpolation determines whether the interpolation should be carried out. If this
|
|
312
|
+
is set to be False, the meteorological parameters are simply set to the values stored on the
|
|
313
|
+
meteorology object (i.e. we assume that the meteorology has already been interpolated). This
|
|
314
|
+
functionality is required to avoid wasted computation in the case of e.g. a reversible jump run.
|
|
315
|
+
|
|
316
|
+
Args:
|
|
317
|
+
sensor_object (Sensor): object containing locations/times onto which met information should
|
|
318
|
+
be interpolated.
|
|
319
|
+
meteorology (Meteorology): object containing meteorology information for interpolation.
|
|
320
|
+
gas_object (GasSpecies): object containing gas information.
|
|
321
|
+
run_interpolation (bool): logical indicating whether the meteorology information needs to be interpolated.
|
|
322
|
+
|
|
323
|
+
Returns:
|
|
324
|
+
gas_density (np.ndarray): numpy array of shape [n_data x 1] of gas densities.
|
|
325
|
+
u_interpolated (np.ndarray): numpy array of shape [n_data x 1] of northerly wind components.
|
|
326
|
+
v_interpolated (np.ndarray): numpy array of shape [n_data x 1] of easterly wind components.
|
|
327
|
+
wind_turbulence_horizontal (np.ndarray): numpy array of shape [n_data x 1] of horizontal turbulence
|
|
328
|
+
parameters.
|
|
329
|
+
wind_turbulence_vertical (np.ndarray): numpy array of shape [n_data x 1] of vertical turbulence
|
|
330
|
+
parameters.
|
|
331
|
+
|
|
332
|
+
"""
|
|
333
|
+
if run_interpolation:
|
|
334
|
+
gas_density = self.calculate_gas_density(
|
|
335
|
+
meteorology=meteorology, sensor_object=sensor_object, gas_object=gas_object
|
|
336
|
+
)
|
|
337
|
+
u_interpolated = self.interpolate_meteorology(
|
|
338
|
+
meteorology=meteorology, variable_name="u_component", sensor_object=sensor_object
|
|
339
|
+
)
|
|
340
|
+
v_interpolated = self.interpolate_meteorology(
|
|
341
|
+
meteorology=meteorology, variable_name="v_component", sensor_object=sensor_object
|
|
342
|
+
)
|
|
343
|
+
wind_turbulence_horizontal = self.interpolate_meteorology(
|
|
344
|
+
meteorology=meteorology, variable_name="wind_turbulence_horizontal", sensor_object=sensor_object
|
|
345
|
+
)
|
|
346
|
+
wind_turbulence_vertical = self.interpolate_meteorology(
|
|
347
|
+
meteorology=meteorology, variable_name="wind_turbulence_vertical", sensor_object=sensor_object
|
|
348
|
+
)
|
|
349
|
+
else:
|
|
350
|
+
gas_density = gas_object.gas_density(temperature=meteorology.temperature, pressure=meteorology.pressure)
|
|
351
|
+
gas_density = gas_density.reshape((gas_density.size, 1))
|
|
352
|
+
u_interpolated = meteorology.u_component.reshape((meteorology.u_component.size, 1))
|
|
353
|
+
v_interpolated = meteorology.v_component.reshape((meteorology.v_component.size, 1))
|
|
354
|
+
wind_turbulence_horizontal = meteorology.wind_turbulence_horizontal.reshape(
|
|
355
|
+
(meteorology.wind_turbulence_horizontal.size, 1)
|
|
356
|
+
)
|
|
357
|
+
wind_turbulence_vertical = meteorology.wind_turbulence_vertical.reshape(
|
|
358
|
+
(meteorology.wind_turbulence_vertical.size, 1)
|
|
359
|
+
)
|
|
360
|
+
|
|
361
|
+
return gas_density, u_interpolated, v_interpolated, wind_turbulence_horizontal, wind_turbulence_vertical
|
|
362
|
+
|
|
363
|
+
def interpolate_meteorology(
|
|
364
|
+
self, meteorology: Meteorology, variable_name: str, sensor_object: Sensor
|
|
365
|
+
) -> Union[np.ndarray, None]:
|
|
366
|
+
"""Helper function to interpolate meteorology variables.
|
|
367
|
+
|
|
368
|
+
This function interpolates meteorological variables to times in Sensor or Sources in sourcemap. It also
|
|
369
|
+
calculates the wind speed and mathematical angle between the u- and v-components which in turn gets used in the
|
|
370
|
+
calculation of the Gaussian plume.
|
|
371
|
+
|
|
372
|
+
When the input sensor object is a Satellite type we use spatial interpolation using the interpolation method
|
|
373
|
+
from the coordinate system class as this takes care of the coordinate systems.
|
|
374
|
+
When the input sensor object is of another time we use temporal interpolation (assumption is spatial uniformity
|
|
375
|
+
for all observations over a small(er) area).
|
|
376
|
+
|
|
377
|
+
Args:
|
|
378
|
+
meteorology (Meteorology): Meteorology object containing u- and v-components of wind including their
|
|
379
|
+
spatial location
|
|
380
|
+
variable_name (str): String name of an attribute in the meteorology input object which needs to be
|
|
381
|
+
interpolated
|
|
382
|
+
sensor_object (Sensor): Sensor object containing information about where to interpolate to
|
|
383
|
+
|
|
384
|
+
Returns:
|
|
385
|
+
variable_interpolated (np.ndarray): Interpolated values
|
|
386
|
+
|
|
387
|
+
"""
|
|
388
|
+
variable = getattr(meteorology, variable_name)
|
|
389
|
+
if variable is None:
|
|
390
|
+
return None
|
|
391
|
+
|
|
392
|
+
if isinstance(sensor_object, Satellite):
|
|
393
|
+
variable_interpolated = meteorology.location.interpolate(variable, self.source_map.location)
|
|
394
|
+
variable_interpolated = variable_interpolated.reshape(1, self.source_map.nof_sources)
|
|
395
|
+
else:
|
|
396
|
+
variable_interpolated = sti.interpolate(
|
|
397
|
+
time_in=meteorology.time, values_in=variable, time_out=sensor_object.time
|
|
398
|
+
)
|
|
399
|
+
variable_interpolated = variable_interpolated.reshape(sensor_object.nof_observations, 1)
|
|
400
|
+
return variable_interpolated
|
|
401
|
+
|
|
402
|
+
def compute_coupling_satellite(
|
|
403
|
+
self,
|
|
404
|
+
sensor_object: Sensor,
|
|
405
|
+
wind_speed: np.ndarray,
|
|
406
|
+
theta: np.ndarray,
|
|
407
|
+
wind_turbulence_horizontal: np.ndarray,
|
|
408
|
+
wind_turbulence_vertical: np.ndarray,
|
|
409
|
+
gas_density: np.ndarray,
|
|
410
|
+
) -> list:
|
|
411
|
+
"""Compute Gaussian plume coupling for satellite sensor.
|
|
412
|
+
|
|
413
|
+
When the sensor is a Satellite object we calculate the plume coupling per source. Given the large number of
|
|
414
|
+
sources and the possibility of using the inclusion radius and inclusion indices here and validity of a local
|
|
415
|
+
ENU system over large distances we loop over each source and calculate the coupling on a per-source basis.
|
|
416
|
+
|
|
417
|
+
If source_map.inclusion_n_obs is None, we do not do any filtering on observations and we want to include all
|
|
418
|
+
observations in the plume coupling calculations.
|
|
419
|
+
|
|
420
|
+
All np.ndarray inputs should have a shape of [1 x nof_sources]
|
|
421
|
+
|
|
422
|
+
Args:
|
|
423
|
+
sensor_object (Sensor): Sensor object used in plume coupling calculation
|
|
424
|
+
wind_speed (np.ndarray): Wind speed [m/s]
|
|
425
|
+
theta (np.ndarray): Mathematical angle between the u- and v-components of wind [radians]
|
|
426
|
+
wind_turbulence_horizontal (np.ndarray): Parameter of the wind stability in horizontal direction [deg]
|
|
427
|
+
wind_turbulence_vertical (np.ndarray): Parameter of the wind stability in vertical direction [deg]
|
|
428
|
+
gas_density: (np.ndarray): Numpy array containing the gas density values to use [kg/m^3]
|
|
429
|
+
|
|
430
|
+
Returns:
|
|
431
|
+
plume_coupling (list): List of Gaussian plume coupling 1e6*[hr/kg] arrays. The list has a length of
|
|
432
|
+
nof_sources, each array has the shape [nof_observations x 1] or [inclusion_n_obs x 1] when
|
|
433
|
+
inclusion_idx is used.
|
|
434
|
+
|
|
435
|
+
"""
|
|
436
|
+
plume_coupling = []
|
|
437
|
+
|
|
438
|
+
source_map_location_lla = self.source_map.location.to_lla()
|
|
439
|
+
for current_source in range(self.source_map.nof_sources):
|
|
440
|
+
if self.source_map.inclusion_n_obs is None:
|
|
441
|
+
enu_sensor_array = sensor_object.location.to_enu(
|
|
442
|
+
ref_latitude=source_map_location_lla.latitude[current_source],
|
|
443
|
+
ref_longitude=source_map_location_lla.longitude[current_source],
|
|
444
|
+
ref_altitude=0,
|
|
445
|
+
).to_array()
|
|
446
|
+
|
|
447
|
+
else:
|
|
448
|
+
if self.source_map.inclusion_n_obs[current_source] == 0:
|
|
449
|
+
plume_coupling.append(np.array([]))
|
|
450
|
+
continue
|
|
451
|
+
|
|
452
|
+
enu_sensor_array = _create_enu_sensor_array(
|
|
453
|
+
inclusion_idx=self.source_map.inclusion_idx[current_source],
|
|
454
|
+
sensor_object=sensor_object,
|
|
455
|
+
source_map_location_lla=source_map_location_lla,
|
|
456
|
+
current_source=current_source,
|
|
457
|
+
)
|
|
458
|
+
|
|
459
|
+
temp_coupling = self.compute_coupling_array(
|
|
460
|
+
enu_sensor_array[:, [0]],
|
|
461
|
+
enu_sensor_array[:, [1]],
|
|
462
|
+
enu_sensor_array[:, [2]],
|
|
463
|
+
source_map_location_lla.altitude[current_source],
|
|
464
|
+
wind_speed[:, current_source],
|
|
465
|
+
theta[:, current_source],
|
|
466
|
+
wind_turbulence_horizontal[:, current_source],
|
|
467
|
+
wind_turbulence_vertical[:, current_source],
|
|
468
|
+
gas_density[:, current_source],
|
|
469
|
+
)
|
|
470
|
+
|
|
471
|
+
plume_coupling.append(temp_coupling)
|
|
472
|
+
|
|
473
|
+
return plume_coupling
|
|
474
|
+
|
|
475
|
+
def compute_coupling_ground(
|
|
476
|
+
self,
|
|
477
|
+
sensor_object: Sensor,
|
|
478
|
+
wind_speed: np.ndarray,
|
|
479
|
+
theta: np.ndarray,
|
|
480
|
+
wind_turbulence_horizontal: np.ndarray,
|
|
481
|
+
wind_turbulence_vertical: np.ndarray,
|
|
482
|
+
gas_density: np.ndarray,
|
|
483
|
+
) -> np.ndarray:
|
|
484
|
+
"""Compute Gaussian plume coupling for a ground sensor.
|
|
485
|
+
|
|
486
|
+
If the source map is already defined as ENU the reference location is maintained but the sensor is checked
|
|
487
|
+
to make sure the same reference location is used. Otherwise, when converting to ENU object for the sensor
|
|
488
|
+
observations we use a single source and altitude 0 as the reference location. This way our ENU system is a
|
|
489
|
+
system w.r.t. ground level which is required for the current implementation of the actual coupling calculation.
|
|
490
|
+
|
|
491
|
+
When the sensor is a Beam object we calculate the plume coupling for all sources to all beam knot locations at
|
|
492
|
+
once in the same ENU coordinate system and finally averaged over the beam knots to get the final output.
|
|
493
|
+
|
|
494
|
+
In general, we calculate the coupling from all sources to all sensor observation locations. In order to achieve
|
|
495
|
+
this we input the sensor array as column and source array as row vector in calculating relative x etc.,
|
|
496
|
+
with the beam knot locations being the third dimension. When the sensor is a single point Sensor or a Drone
|
|
497
|
+
sensor we effectively have one beam knot, making the mean operation at the end effectively a reshape operation
|
|
498
|
+
which gets rid of the third dimension.
|
|
499
|
+
|
|
500
|
+
All np.ndarray inputs should have a shape of [nof_observations x 1]
|
|
501
|
+
|
|
502
|
+
Args:
|
|
503
|
+
sensor_object (Sensor): Sensor object used in plume coupling calculation
|
|
504
|
+
wind_speed (np.ndarray): Wind speed [m/s]
|
|
505
|
+
theta (np.ndarray): Mathematical angle between the u- and v-components of wind [radians]
|
|
506
|
+
wind_turbulence_horizontal (np.ndarray): Parameter of the wind stability in horizontal direction [deg]
|
|
507
|
+
wind_turbulence_vertical (np.ndarray): Parameter of the wind stability in vertical direction [deg]
|
|
508
|
+
gas_density: (np.ndarray): Numpy array containing the gas density values to use [kg/m^3]
|
|
509
|
+
|
|
510
|
+
Returns:
|
|
511
|
+
plume_coupling (np.ndarray): Gaussian plume coupling 1e6*[hr/kg] array. The array has the
|
|
512
|
+
shape [nof_observations x nof_sources]
|
|
513
|
+
|
|
514
|
+
"""
|
|
515
|
+
if not isinstance(self.source_map.location, ENU):
|
|
516
|
+
source_map_lla = self.source_map.location.to_lla()
|
|
517
|
+
source_map_enu = source_map_lla.to_enu(
|
|
518
|
+
ref_latitude=source_map_lla.latitude[0], ref_longitude=source_map_lla.longitude[0], ref_altitude=0
|
|
519
|
+
)
|
|
520
|
+
else:
|
|
521
|
+
source_map_enu = self.source_map.location
|
|
522
|
+
|
|
523
|
+
enu_source_array = source_map_enu.to_array()
|
|
524
|
+
|
|
525
|
+
if isinstance(sensor_object, Beam):
|
|
526
|
+
enu_sensor_array = sensor_object.make_beam_knots(
|
|
527
|
+
ref_latitude=source_map_enu.ref_latitude,
|
|
528
|
+
ref_longitude=source_map_enu.ref_longitude,
|
|
529
|
+
ref_altitude=source_map_enu.ref_altitude,
|
|
530
|
+
)
|
|
531
|
+
relative_x = np.subtract(enu_sensor_array[:, 0][None, None, :], enu_source_array[:, 0][None, :, None])
|
|
532
|
+
relative_y = np.subtract(enu_sensor_array[:, 1][None, None, :], enu_source_array[:, 1][None, :, None])
|
|
533
|
+
z_sensor = enu_sensor_array[:, 2][None, None, :]
|
|
534
|
+
else:
|
|
535
|
+
enu_sensor_array = sensor_object.location.to_enu(
|
|
536
|
+
ref_latitude=source_map_enu.ref_latitude,
|
|
537
|
+
ref_longitude=source_map_enu.ref_longitude,
|
|
538
|
+
ref_altitude=source_map_enu.ref_altitude,
|
|
539
|
+
).to_array()
|
|
540
|
+
relative_x = np.subtract(enu_sensor_array[:, 0][:, None, None], enu_source_array[:, 0][None, :, None])
|
|
541
|
+
relative_y = np.subtract(enu_sensor_array[:, 1][:, None, None], enu_source_array[:, 1][None, :, None])
|
|
542
|
+
z_sensor = enu_sensor_array[:, 2][:, None, None]
|
|
543
|
+
|
|
544
|
+
z_source = enu_source_array[:, 2][None, :, None]
|
|
545
|
+
|
|
546
|
+
plume_coupling = self.compute_coupling_array(
|
|
547
|
+
relative_x,
|
|
548
|
+
relative_y,
|
|
549
|
+
z_sensor,
|
|
550
|
+
z_source,
|
|
551
|
+
wind_speed[:, :, None],
|
|
552
|
+
theta[:, :, None],
|
|
553
|
+
wind_turbulence_horizontal[:, :, None],
|
|
554
|
+
wind_turbulence_vertical[:, :, None],
|
|
555
|
+
gas_density[:, :, None],
|
|
556
|
+
)
|
|
557
|
+
|
|
558
|
+
plume_coupling = plume_coupling.mean(axis=2)
|
|
559
|
+
|
|
560
|
+
return plume_coupling
|
|
561
|
+
|
|
562
|
+
@staticmethod
|
|
563
|
+
def compute_coverage(
|
|
564
|
+
couplings: np.ndarray, threshold_function: Callable, coverage_threshold: float = 6, **kwargs
|
|
565
|
+
) -> Union[np.ndarray, dict]:
|
|
566
|
+
"""Returns a logical vector that indicates which sources in the couplings are, or are not, within the coverage.
|
|
567
|
+
|
|
568
|
+
The 'coverage' is the area inside which all sources are well covered by wind data. E.g. If wind exclusively
|
|
569
|
+
blows towards East, then all sources to the East of any sensor are 'invisible', and are not within the coverage.
|
|
570
|
+
|
|
571
|
+
Couplings are returned in hr/kg. Some threshold function defines the largest allowed coupling value. This is
|
|
572
|
+
used to calculate estimated emission rates in kg/hr. Any emissions which are greater than the value of
|
|
573
|
+
'coverage_threshold' are defined as not within the coverage.
|
|
574
|
+
|
|
575
|
+
Args:
|
|
576
|
+
couplings (np.ndarray): Array of coupling values. Dimensions: n_datapoints x n_sources.
|
|
577
|
+
threshold_function (Callable): Callable function which returns some single value that defines the
|
|
578
|
+
maximum or 'threshold' coupling. For example: np.quantile(., q=0.95)
|
|
579
|
+
coverage_threshold (float, optional): The threshold value of the estimated emission rate which is
|
|
580
|
+
considered to be within the coverage. Defaults to 6 kg/hr.
|
|
581
|
+
kwargs (dict, optional): Keyword arguments required for the threshold function.
|
|
582
|
+
|
|
583
|
+
Returns:
|
|
584
|
+
coverage (Union[np.ndarray, dict]): A logical array specifying which sources are within the coverage.
|
|
585
|
+
|
|
586
|
+
"""
|
|
587
|
+
coupling_threshold = threshold_function(couplings, **kwargs)
|
|
588
|
+
no_warning_threshold = np.where(coupling_threshold <= 1e-100, 1, coupling_threshold)
|
|
589
|
+
no_warning_estimated_emission_rates = np.where(coupling_threshold <= 1e-100, np.inf, 1 / no_warning_threshold)
|
|
590
|
+
coverage = no_warning_estimated_emission_rates < coverage_threshold
|
|
591
|
+
|
|
592
|
+
return coverage
|
|
593
|
+
|
|
594
|
+
|
|
595
|
+
def _create_enu_sensor_array(
|
|
596
|
+
inclusion_idx: np.ndarray, sensor_object: Sensor, source_map_location_lla: LLA, current_source: int
|
|
597
|
+
):
|
|
598
|
+
"""Helper function to create ENU sensor array when we only want ot include specific observation locations.
|
|
599
|
+
|
|
600
|
+
This function gets called when we need to create the enu_sensor_array when we only want to include specific
|
|
601
|
+
observation locations. First we obtain the subset of locations from the sensor object and convert that to an array.
|
|
602
|
+
Given we don't know which coordinate system the sensor_object is created in, we make a copy of the original sensor
|
|
603
|
+
object, thereby keeping all key details of the coordinate system and repopulate the location values accordingly
|
|
604
|
+
through the from_array method using the subset of locations from the sensor object. Finally, we convert the subset
|
|
605
|
+
to ENU and return that as output.
|
|
606
|
+
|
|
607
|
+
Args:
|
|
608
|
+
inclusion_idx (np.ndarray): Numpy array containing the indices of observations in the sensor_object to be used
|
|
609
|
+
in the Gaussian plume coupling.
|
|
610
|
+
sensor_object (Sensor): Sensor object to be used in the Gaussian Plume calculation.
|
|
611
|
+
source_map_location_lla (LLA): LLA coordinate object of the source map locations.
|
|
612
|
+
current_source (int): Integer index of the current source for which we want to use in the Gaussian plume
|
|
613
|
+
calculation.
|
|
614
|
+
|
|
615
|
+
"""
|
|
616
|
+
temp_array = sensor_object.location.to_array()[inclusion_idx, :]
|
|
617
|
+
temp_object = deepcopy(sensor_object.location)
|
|
618
|
+
temp_object.from_array(array=temp_array)
|
|
619
|
+
enu_sensor_array = temp_object.to_enu(
|
|
620
|
+
ref_latitude=source_map_location_lla.latitude[current_source],
|
|
621
|
+
ref_longitude=source_map_location_lla.longitude[current_source],
|
|
622
|
+
ref_altitude=0,
|
|
623
|
+
).to_array()
|
|
624
|
+
|
|
625
|
+
return enu_sensor_array
|