Skip to content

Error Model

Error model module.

ErrorModel dataclass

Bases: Component

Measurement precision model component for the model.

Attributes:

Name Type Description
n_sensor int

number of sensors in the sensor object used for analysis.

precision_index ndarray

index mapping precision parameters onto observations. Will be set up differently for different model types.

precision_parameter Parameter

parameter object which constructs the full measurement error precision matrix from the components stored in state. Will be passed to the distribution for the observed when the full model is constructed.

prior_precision_shape Union[ndarray, float]

prior shape parameters for the precision model. Set up differently per model type.

prior_precision_rate Union[ndarray, float]

prior rate parameters for the precision model. Set up differently per model type.

initial_precision Union[ndarray, float]

initial value for the precision to be passed to the analysis routine. Set up differently per model type.

precision ndarray

array of sampled measurement error precision values, populated in self.from_mcmc() after the MCMC run is completed.

Source code in src/pyelq/component/error_model.py
 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
@dataclass
class ErrorModel(Component):
    """Measurement precision model component for the model.

    Attributes:
        n_sensor (int): number of sensors in the sensor object used for analysis.
        precision_index (np.ndarray): index mapping precision parameters onto observations. Will be set up differently
            for different model types.
        precision_parameter (parameter.Parameter): parameter object which constructs the full measurement error
            precision matrix from the components stored in state. Will be passed to the distribution for the observed
            when the full model is constructed.
        prior_precision_shape (Union[np.ndarray, float]): prior shape parameters for the precision model. Set up
            differently per model type.
        prior_precision_rate (Union[np.ndarray, float]): prior rate parameters for the precision model. Set up
            differently per model type.
        initial_precision (Union[np.ndarray, float]): initial value for the precision to be passed to the analysis
            routine. Set up differently per model type.
        precision (np.ndarray): array of sampled measurement error precision values, populated in self.from_mcmc() after
            the MCMC run is completed.

    """

    n_sensor: int = field(init=False)
    precision_index: np.ndarray = field(init=False)
    precision_parameter: parameter.Parameter = field(init=False)
    prior_precision_shape: Union[np.ndarray, float] = field(init=False)
    prior_precision_rate: Union[np.ndarray, float] = field(init=False)
    initial_precision: Union[np.ndarray, float] = field(init=False)
    precision: np.ndarray = field(init=False)

    def initialise(
        self, sensor_object: SensorGroup, meteorology: MeteorologyGroup = None, gas_species: GasSpecies = None
    ):
        """Take data inputs and extract relevant properties.

        Args:
            sensor_object (SensorGroup): sensor data.
            meteorology (MeteorologyGroup): meteorology data. Defaults to None.
            gas_species (GasSpecies): gas species information. Defaults to None.

        """
        self.n_sensor = sensor_object.nof_sensors

    def make_model(self, model: list = None) -> list:
        """Take model list and append new elements from current model component.

        Args:
            model (list, optional): Current list of model elements. Defaults to None.

        Returns:
            list: model output list.

        """
        if model is None:
            model = []
        model.append(Gamma("tau", shape="a_tau", rate="b_tau"))
        return model

    def make_sampler(self, model: Model, sampler_list: list = None) -> list:
        """Take sampler list and append new elements from current model component.

        Args:
            model (Model): Full model list of distributions.
            sampler_list (list, optional): Current list of samplers. Defaults to None.

        Returns:
            list: sampler output list.

        """
        if sampler_list is None:
            sampler_list = []
        sampler_list.append(NormalGamma("tau", model))
        return sampler_list

    def make_state(self, state: dict = None) -> dict:
        """Take state dictionary and append initial values from model component.

        Args:
            state (dict, optional): current state vector. Defaults to None.

        Returns:
            dict: current state vector with components added.

        """
        if state is None:
            state = {}
        state["a_tau"] = self.prior_precision_shape.flatten()
        state["b_tau"] = self.prior_precision_rate.flatten()
        state["precision_index"] = self.precision_index
        state["tau"] = self.initial_precision.flatten()
        return state

    def from_mcmc(self, store: dict):
        """Extract results of mcmc from mcmc.store and attach to components.

        Args:
            store (dict): mcmc result dictionary.

        """
        self.precision = store["tau"]

initialise(sensor_object, meteorology=None, gas_species=None)

Take data inputs and extract relevant properties.

Parameters:

Name Type Description Default
sensor_object SensorGroup

sensor data.

required
meteorology MeteorologyGroup

meteorology data. Defaults to None.

None
gas_species GasSpecies

gas species information. Defaults to None.

None
Source code in src/pyelq/component/error_model.py
55
56
57
58
59
60
61
62
63
64
65
66
def initialise(
    self, sensor_object: SensorGroup, meteorology: MeteorologyGroup = None, gas_species: GasSpecies = None
):
    """Take data inputs and extract relevant properties.

    Args:
        sensor_object (SensorGroup): sensor data.
        meteorology (MeteorologyGroup): meteorology data. Defaults to None.
        gas_species (GasSpecies): gas species information. Defaults to None.

    """
    self.n_sensor = sensor_object.nof_sensors

make_model(model=None)

Take model list and append new elements from current model component.

Parameters:

Name Type Description Default
model list

Current list of model elements. Defaults to None.

None

Returns:

Name Type Description
list list

model output list.

Source code in src/pyelq/component/error_model.py
68
69
70
71
72
73
74
75
76
77
78
79
80
81
def make_model(self, model: list = None) -> list:
    """Take model list and append new elements from current model component.

    Args:
        model (list, optional): Current list of model elements. Defaults to None.

    Returns:
        list: model output list.

    """
    if model is None:
        model = []
    model.append(Gamma("tau", shape="a_tau", rate="b_tau"))
    return model

make_sampler(model, sampler_list=None)

Take sampler list and append new elements from current model component.

Parameters:

Name Type Description Default
model Model

Full model list of distributions.

required
sampler_list list

Current list of samplers. Defaults to None.

None

Returns:

Name Type Description
list list

sampler output list.

Source code in src/pyelq/component/error_model.py
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
def make_sampler(self, model: Model, sampler_list: list = None) -> list:
    """Take sampler list and append new elements from current model component.

    Args:
        model (Model): Full model list of distributions.
        sampler_list (list, optional): Current list of samplers. Defaults to None.

    Returns:
        list: sampler output list.

    """
    if sampler_list is None:
        sampler_list = []
    sampler_list.append(NormalGamma("tau", model))
    return sampler_list

make_state(state=None)

Take state dictionary and append initial values from model component.

Parameters:

Name Type Description Default
state dict

current state vector. Defaults to None.

None

Returns:

Name Type Description
dict dict

current state vector with components added.

Source code in src/pyelq/component/error_model.py
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
def make_state(self, state: dict = None) -> dict:
    """Take state dictionary and append initial values from model component.

    Args:
        state (dict, optional): current state vector. Defaults to None.

    Returns:
        dict: current state vector with components added.

    """
    if state is None:
        state = {}
    state["a_tau"] = self.prior_precision_shape.flatten()
    state["b_tau"] = self.prior_precision_rate.flatten()
    state["precision_index"] = self.precision_index
    state["tau"] = self.initial_precision.flatten()
    return state

from_mcmc(store)

Extract results of mcmc from mcmc.store and attach to components.

Parameters:

Name Type Description Default
store dict

mcmc result dictionary.

required
Source code in src/pyelq/component/error_model.py
117
118
119
120
121
122
123
124
def from_mcmc(self, store: dict):
    """Extract results of mcmc from mcmc.store and attach to components.

    Args:
        store (dict): mcmc result dictionary.

    """
    self.precision = store["tau"]

BySensor dataclass

Bases: ErrorModel

Version of measurement precision where each sensor object has a different precision.

Attributes:

Name Type Description
prior_precision_shape Union[ndarray, float]

prior shape parameters for the precision model, can be specified either as a float or as a (nof_sensors, ) np.ndarray: a float specification will result in the same parameter value for each sensor. Defaults to 1e-3.

prior_precision_rate Union[ndarray, float]

prior rate parameters for the precision model, can be specified either as a float or as a (nof_sensors, ) np.ndarray: a float specification will result in the same parameter value for each sensor. Defaults to 1e-3.

initial_precision Union[ndarray, float]

initial value for the precision parameters, can be specified either as a float or as a (nof_sensors, ) np.ndarray: a float specification will result in the same parameter value for each sensor. Defaults to 1.

precision_index ndarray

index mapping precision parameters onto observations. Parameters 1:n_sensor are mapped as the measurement error precisions of the corresponding sensors.

precision_parameter MixtureParameterMatrix

parameter specification for this model, maps the current value of the parameter in the state dict onto the concentration data precisions.

Source code in src/pyelq/component/error_model.py
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
@dataclass
class BySensor(ErrorModel):
    """Version of measurement precision where each sensor object has a different precision.

    Attributes:
        prior_precision_shape (Union[np.ndarray, float]): prior shape parameters for the precision model, can be
            specified either as a float or as a (nof_sensors, ) np.ndarray: a float specification will result in
            the same parameter value for each sensor. Defaults to 1e-3.
        prior_precision_rate (Union[np.ndarray, float]): prior rate parameters for the precision model, can be
            specified either as a float or as a (nof_sensors, ) np.ndarray: a float specification will result in
            the same parameter value for each sensor. Defaults to 1e-3.
        initial_precision (Union[np.ndarray, float]): initial value for the precision parameters, can be specified
            either as a float or as a (nof_sensors, ) np.ndarray: a float specification will result in the same
            parameter value for each sensor. Defaults to 1.
        precision_index (np.ndarray): index mapping precision parameters onto observations. Parameters 1:n_sensor are
            mapped as the measurement error precisions of the corresponding sensors.
        precision_parameter (Parameter.MixtureParameterMatrix): parameter specification for this model, maps the
            current value of the parameter in the state dict onto the concentration data precisions.

    """

    prior_precision_shape: Union[np.ndarray, float] = 1e-3
    prior_precision_rate: Union[np.ndarray, float] = 1e-3
    initial_precision: Union[np.ndarray, float] = 1.0

    def initialise(
        self, sensor_object: SensorGroup, meteorology: MeteorologyGroup = None, gas_species: GasSpecies = None
    ):
        """Set up the error model using sensor properties.

        Args:
            sensor_object (SensorGroup): sensor data.
            meteorology (MeteorologyGroup): meteorology data. Defaults to None.
            gas_species (GasSpecies): gas species information. Defaults to None.

        """
        super().initialise(sensor_object=sensor_object, meteorology=meteorology, gas_species=gas_species)
        self.prior_precision_shape = self.prior_precision_shape * np.ones((self.n_sensor,))
        self.prior_precision_rate = self.prior_precision_rate * np.ones((self.n_sensor,))
        self.initial_precision = self.initial_precision * np.ones((self.n_sensor,))
        self.precision_index = sensor_object.sensor_index
        self.precision_parameter = parameter.MixtureParameterMatrix(param="tau", allocation="precision_index")

    def plot_iterations(self, plot: "Plot", sensor_object: Union[SensorGroup, Sensor], burn_in_value: int) -> "Plot":
        """Plots the error model values for every sensor with respect to the MCMC iterations.

        Args:
            sensor_object (Union[SensorGroup, Sensor]): Sensor object associated with the error_model
            burn_in_value (int): Burn in value to show in plot.
            plot (Plot): Plot object to which this figure will be added in the figure dictionary

        Returns:
            plot (Plot): Plot object to which this figure is added in the figure dictionary with
                key 'error_model_iterations'

        """
        plot.plot_trace_per_sensor(
            object_to_plot=self, sensor_object=sensor_object, plot_type="line", burn_in=burn_in_value
        )

        return plot

    def plot_distributions(self, plot: "Plot", sensor_object: Union[SensorGroup, Sensor], burn_in_value: int) -> "Plot":
        """Plots the distribution of the error model values after the burn in for every sensor.

        Args:
            sensor_object (Union[SensorGroup, Sensor]): Sensor object associated with the error_model
            burn_in_value (int): Burn in value to show in plot.
            plot (Plot): Plot object to which this figure will be added in the figure dictionary

        Returns:
            plot (Plot): Plot object to which this figure is added in the figure dictionary with
                key 'error_model_distributions'

        """
        plot.plot_trace_per_sensor(
            object_to_plot=self, sensor_object=sensor_object, plot_type="box", burn_in=burn_in_value
        )

        return plot

initialise(sensor_object, meteorology=None, gas_species=None)

Set up the error model using sensor properties.

Parameters:

Name Type Description Default
sensor_object SensorGroup

sensor data.

required
meteorology MeteorologyGroup

meteorology data. Defaults to None.

None
gas_species GasSpecies

gas species information. Defaults to None.

None
Source code in src/pyelq/component/error_model.py
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
def initialise(
    self, sensor_object: SensorGroup, meteorology: MeteorologyGroup = None, gas_species: GasSpecies = None
):
    """Set up the error model using sensor properties.

    Args:
        sensor_object (SensorGroup): sensor data.
        meteorology (MeteorologyGroup): meteorology data. Defaults to None.
        gas_species (GasSpecies): gas species information. Defaults to None.

    """
    super().initialise(sensor_object=sensor_object, meteorology=meteorology, gas_species=gas_species)
    self.prior_precision_shape = self.prior_precision_shape * np.ones((self.n_sensor,))
    self.prior_precision_rate = self.prior_precision_rate * np.ones((self.n_sensor,))
    self.initial_precision = self.initial_precision * np.ones((self.n_sensor,))
    self.precision_index = sensor_object.sensor_index
    self.precision_parameter = parameter.MixtureParameterMatrix(param="tau", allocation="precision_index")

plot_iterations(plot, sensor_object, burn_in_value)

Plots the error model values for every sensor with respect to the MCMC iterations.

Parameters:

Name Type Description Default
sensor_object Union[SensorGroup, Sensor]

Sensor object associated with the error_model

required
burn_in_value int

Burn in value to show in plot.

required
plot Plot

Plot object to which this figure will be added in the figure dictionary

required

Returns:

Name Type Description
plot Plot

Plot object to which this figure is added in the figure dictionary with key 'error_model_iterations'

Source code in src/pyelq/component/error_model.py
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
def plot_iterations(self, plot: "Plot", sensor_object: Union[SensorGroup, Sensor], burn_in_value: int) -> "Plot":
    """Plots the error model values for every sensor with respect to the MCMC iterations.

    Args:
        sensor_object (Union[SensorGroup, Sensor]): Sensor object associated with the error_model
        burn_in_value (int): Burn in value to show in plot.
        plot (Plot): Plot object to which this figure will be added in the figure dictionary

    Returns:
        plot (Plot): Plot object to which this figure is added in the figure dictionary with
            key 'error_model_iterations'

    """
    plot.plot_trace_per_sensor(
        object_to_plot=self, sensor_object=sensor_object, plot_type="line", burn_in=burn_in_value
    )

    return plot

plot_distributions(plot, sensor_object, burn_in_value)

Plots the distribution of the error model values after the burn in for every sensor.

Parameters:

Name Type Description Default
sensor_object Union[SensorGroup, Sensor]

Sensor object associated with the error_model

required
burn_in_value int

Burn in value to show in plot.

required
plot Plot

Plot object to which this figure will be added in the figure dictionary

required

Returns:

Name Type Description
plot Plot

Plot object to which this figure is added in the figure dictionary with key 'error_model_distributions'

Source code in src/pyelq/component/error_model.py
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
def plot_distributions(self, plot: "Plot", sensor_object: Union[SensorGroup, Sensor], burn_in_value: int) -> "Plot":
    """Plots the distribution of the error model values after the burn in for every sensor.

    Args:
        sensor_object (Union[SensorGroup, Sensor]): Sensor object associated with the error_model
        burn_in_value (int): Burn in value to show in plot.
        plot (Plot): Plot object to which this figure will be added in the figure dictionary

    Returns:
        plot (Plot): Plot object to which this figure is added in the figure dictionary with
            key 'error_model_distributions'

    """
    plot.plot_trace_per_sensor(
        object_to_plot=self, sensor_object=sensor_object, plot_type="box", burn_in=burn_in_value
    )

    return plot

ByRelease dataclass

Bases: ErrorModel

ByRelease error model, special case of the measurement precision model.

Version of the measurement precision model where each sensor object has a different precision, and there are different precisions for periods inside and outside controlled release periods. For all parameters: the first element corresponds to the case where the sources are OFF; the second element corresponds to the case where the sources are ON.

Attributes:

Name Type Description
prior_precision_shape ndarray

prior shape parameters for the precision model, can be specified either as a (2, 1) np.ndarray or as a (2, nof_sensors) np.ndarray: the former specification will result in the same prior specification for the off/on precisions for each sensor. Defaults to np.array([1e-3, 1e-3]).

prior_precision_rate ndarray

prior rate parameters for the precision model, can be specified either as a (2, 1) np.ndarray or as a (2, nof_sensors) np.ndarray: the former specification will result in the same prior specification for the off/on precisions for each sensor. Defaults to np.array([1e-3, 1e-3]).

initial_precision ndarray

initial value for the precision parameters, can be specified either as a (2, 1) np.ndarray or as a (2, nof_sensors) np.ndarray: the former specification will result in the same prior specification for the off/on precisions for each sensor. Defaults to np.array([1.0, 1.0]).

precision_index ndarray

index mapping precision parameters onto observations. Parameters 1:n_sensor are mapped onto each sensor for the periods where the sources are OFF; parameters (n_sensor + 1):(2 * n_sensor) are mapped onto each sensor for the periods where the sources are ON.

precision_parameter MixtureParameterMatrix

parameter specification for this model, maps the current value of the parameter in the state dict onto the concentration data precisions.

Source code in src/pyelq/component/error_model.py
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
@dataclass
class ByRelease(ErrorModel):
    """ByRelease error model, special case of the measurement precision model.

    Version of the measurement precision model where each sensor object has a different precision, and there are
    different precisions for periods inside and outside controlled release periods. For all parameters: the first
    element corresponds to the case where the sources are OFF; the second element corresponds to the case where the
    sources are ON.

    Attributes:
        prior_precision_shape (np.ndarray): prior shape parameters for the precision model, can be
            specified either as a (2, 1) np.ndarray or as a (2, nof_sensors) np.ndarray: the former specification
            will result in the same prior specification for the off/on precisions for each sensor. Defaults to
            np.array([1e-3, 1e-3]).
        prior_precision_rate (np.ndarray): prior rate parameters for the precision model, can be
            specified either as a (2, 1) np.ndarray or as a (2, nof_sensors) np.ndarray: the former specification
            will result in the same prior specification for the off/on precisions for each sensor. Defaults to
            np.array([1e-3, 1e-3]).
        initial_precision (np.ndarray): initial value for the precision parameters, can be
            specified either as a (2, 1) np.ndarray or as a (2, nof_sensors) np.ndarray: the former specification
            will result in the same prior specification for the off/on precisions for each sensor. Defaults to
            np.array([1.0, 1.0]).
        precision_index (np.ndarray): index mapping precision parameters onto observations. Parameters 1:n_sensor are
            mapped onto each sensor for the periods where the sources are OFF; parameters (n_sensor + 1):(2 * n_sensor)
            are mapped onto each sensor for the periods where the sources are ON.
        precision_parameter (Parameter.MixtureParameterMatrix): parameter specification for this model, maps the
            current value of the parameter in the state dict onto the concentration data precisions.

    """

    prior_precision_shape: np.ndarray = field(default_factory=lambda: np.array([1e-3, 1e-3], ndmin=2).T)
    prior_precision_rate: np.ndarray = field(default_factory=lambda: np.array([1e-3, 1e-3], ndmin=2).T)
    initial_precision: np.ndarray = field(default_factory=lambda: np.array([1.0, 1.0], ndmin=2).T)

    def initialise(
        self, sensor_object: SensorGroup, meteorology: MeteorologyGroup = None, gas_species: GasSpecies = None
    ):
        """Set up the error model using sensor properties.

        Args:
            sensor_object (SensorGroup): sensor data.
            meteorology (MeteorologyGroup): meteorology data. Defaults to None.
            gas_species (GasSpecies): gas species information. Defaults to None.

        """
        super().initialise(sensor_object=sensor_object, meteorology=meteorology, gas_species=gas_species)
        self.prior_precision_shape = self.prior_precision_shape * np.ones((2, self.n_sensor))
        self.prior_precision_rate = self.prior_precision_rate * np.ones((2, self.n_sensor))
        self.initial_precision = self.initial_precision * np.ones((2, self.n_sensor))
        self.precision_index = sensor_object.sensor_index + sensor_object.source_on * self.n_sensor
        self.precision_parameter = parameter.MixtureParameterMatrix(param="tau", allocation="precision_index")

    def plot_iterations(self, plot: "Plot", sensor_object: Union[SensorGroup, Sensor], burn_in_value: int) -> "Plot":
        """Plot the estimated error model parameters against iterations of the MCMC chain.

        Works by simply creating a separate plot for each of the two categories of precision parameter (when the
        sources are on/off). Creates a BySensor() object for each of the off/on precision cases, and then makes a
        call to its plot function.

        Args:
            sensor_object (Union[SensorGroup, Sensor]): Sensor object associated with the error_model
            burn_in_value (int): Burn in value to show in plot.
            plot (Plot): Plot object to which this figure will be added in the figure dictionary

        Returns:
            plot (Plot): Plot object to which this figure is added in the figure dictionary with
                key 'error_model_iterations'

        """
        figure_keys = ["error_model_off_iterations", "error_model_on_iterations"]
        figure_titles = [
            "Estimated error parameter values: sources off",
            "Estimated error parameter values: sources on",
        ]
        precision_arrays = [
            self.precision[: sensor_object.nof_sensors, :],
            self.precision[sensor_object.nof_sensors :, :],
        ]
        for key, title, array in zip(figure_keys, figure_titles, precision_arrays):
            error_model = BySensor()
            error_model.precision = array
            plot = error_model.plot_iterations(plot, sensor_object, burn_in_value)
            plot.figure_dict[key] = plot.figure_dict.pop("error_model_iterations")
            plot.figure_dict[key].update_layout(title=title)
        return plot

    def plot_distributions(self, plot: "Plot", sensor_object: Union[SensorGroup, Sensor], burn_in_value: int) -> "Plot":
        """Plot the estimated distributions of error model parameters.

        Works by simply creating a separate plot for each of the two categories of precision parameter (when the
        sources are off/on). Creates a BySensor() object for each of the off/on precision cases, and then makes a
        call to its plot function.

        Args:
            sensor_object (Union[SensorGroup, Sensor]): Sensor object associated with the error_model
            burn_in_value (int): Burn in value to show in plot.
            plot (Plot): Plot object to which this figure will be added in the figure dictionary

        Returns:
            plot (Plot): Plot object to which this figure is added in the figure dictionary with
                key 'error_model_distributions'

        """
        figure_keys = ["error_model_off_distributions", "error_model_on_distributions"]
        figure_titles = [
            "Estimated error parameter distribution: sources off",
            "Estimated error parameter distribution: sources on",
        ]
        precision_arrays = [
            self.precision[: sensor_object.nof_sensors, :],
            self.precision[sensor_object.nof_sensors :, :],
        ]
        for key, title, array in zip(figure_keys, figure_titles, precision_arrays):
            error_model = BySensor()
            error_model.precision = array
            plot = error_model.plot_distributions(plot, sensor_object, burn_in_value)
            plot.figure_dict[key] = plot.figure_dict.pop("error_model_distributions")
            plot.figure_dict[key].update_layout(title=title)
        return plot

initialise(sensor_object, meteorology=None, gas_species=None)

Set up the error model using sensor properties.

Parameters:

Name Type Description Default
sensor_object SensorGroup

sensor data.

required
meteorology MeteorologyGroup

meteorology data. Defaults to None.

None
gas_species GasSpecies

gas species information. Defaults to None.

None
Source code in src/pyelq/component/error_model.py
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
def initialise(
    self, sensor_object: SensorGroup, meteorology: MeteorologyGroup = None, gas_species: GasSpecies = None
):
    """Set up the error model using sensor properties.

    Args:
        sensor_object (SensorGroup): sensor data.
        meteorology (MeteorologyGroup): meteorology data. Defaults to None.
        gas_species (GasSpecies): gas species information. Defaults to None.

    """
    super().initialise(sensor_object=sensor_object, meteorology=meteorology, gas_species=gas_species)
    self.prior_precision_shape = self.prior_precision_shape * np.ones((2, self.n_sensor))
    self.prior_precision_rate = self.prior_precision_rate * np.ones((2, self.n_sensor))
    self.initial_precision = self.initial_precision * np.ones((2, self.n_sensor))
    self.precision_index = sensor_object.sensor_index + sensor_object.source_on * self.n_sensor
    self.precision_parameter = parameter.MixtureParameterMatrix(param="tau", allocation="precision_index")

plot_iterations(plot, sensor_object, burn_in_value)

Plot the estimated error model parameters against iterations of the MCMC chain.

Works by simply creating a separate plot for each of the two categories of precision parameter (when the sources are on/off). Creates a BySensor() object for each of the off/on precision cases, and then makes a call to its plot function.

Parameters:

Name Type Description Default
sensor_object Union[SensorGroup, Sensor]

Sensor object associated with the error_model

required
burn_in_value int

Burn in value to show in plot.

required
plot Plot

Plot object to which this figure will be added in the figure dictionary

required

Returns:

Name Type Description
plot Plot

Plot object to which this figure is added in the figure dictionary with key 'error_model_iterations'

Source code in src/pyelq/component/error_model.py
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
def plot_iterations(self, plot: "Plot", sensor_object: Union[SensorGroup, Sensor], burn_in_value: int) -> "Plot":
    """Plot the estimated error model parameters against iterations of the MCMC chain.

    Works by simply creating a separate plot for each of the two categories of precision parameter (when the
    sources are on/off). Creates a BySensor() object for each of the off/on precision cases, and then makes a
    call to its plot function.

    Args:
        sensor_object (Union[SensorGroup, Sensor]): Sensor object associated with the error_model
        burn_in_value (int): Burn in value to show in plot.
        plot (Plot): Plot object to which this figure will be added in the figure dictionary

    Returns:
        plot (Plot): Plot object to which this figure is added in the figure dictionary with
            key 'error_model_iterations'

    """
    figure_keys = ["error_model_off_iterations", "error_model_on_iterations"]
    figure_titles = [
        "Estimated error parameter values: sources off",
        "Estimated error parameter values: sources on",
    ]
    precision_arrays = [
        self.precision[: sensor_object.nof_sensors, :],
        self.precision[sensor_object.nof_sensors :, :],
    ]
    for key, title, array in zip(figure_keys, figure_titles, precision_arrays):
        error_model = BySensor()
        error_model.precision = array
        plot = error_model.plot_iterations(plot, sensor_object, burn_in_value)
        plot.figure_dict[key] = plot.figure_dict.pop("error_model_iterations")
        plot.figure_dict[key].update_layout(title=title)
    return plot

plot_distributions(plot, sensor_object, burn_in_value)

Plot the estimated distributions of error model parameters.

Works by simply creating a separate plot for each of the two categories of precision parameter (when the sources are off/on). Creates a BySensor() object for each of the off/on precision cases, and then makes a call to its plot function.

Parameters:

Name Type Description Default
sensor_object Union[SensorGroup, Sensor]

Sensor object associated with the error_model

required
burn_in_value int

Burn in value to show in plot.

required
plot Plot

Plot object to which this figure will be added in the figure dictionary

required

Returns:

Name Type Description
plot Plot

Plot object to which this figure is added in the figure dictionary with key 'error_model_distributions'

Source code in src/pyelq/component/error_model.py
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
def plot_distributions(self, plot: "Plot", sensor_object: Union[SensorGroup, Sensor], burn_in_value: int) -> "Plot":
    """Plot the estimated distributions of error model parameters.

    Works by simply creating a separate plot for each of the two categories of precision parameter (when the
    sources are off/on). Creates a BySensor() object for each of the off/on precision cases, and then makes a
    call to its plot function.

    Args:
        sensor_object (Union[SensorGroup, Sensor]): Sensor object associated with the error_model
        burn_in_value (int): Burn in value to show in plot.
        plot (Plot): Plot object to which this figure will be added in the figure dictionary

    Returns:
        plot (Plot): Plot object to which this figure is added in the figure dictionary with
            key 'error_model_distributions'

    """
    figure_keys = ["error_model_off_distributions", "error_model_on_distributions"]
    figure_titles = [
        "Estimated error parameter distribution: sources off",
        "Estimated error parameter distribution: sources on",
    ]
    precision_arrays = [
        self.precision[: sensor_object.nof_sensors, :],
        self.precision[sensor_object.nof_sensors :, :],
    ]
    for key, title, array in zip(figure_keys, figure_titles, precision_arrays):
        error_model = BySensor()
        error_model.precision = array
        plot = error_model.plot_distributions(plot, sensor_object, burn_in_value)
        plot.figure_dict[key] = plot.figure_dict.pop("error_model_distributions")
        plot.figure_dict[key].update_layout(title=title)
    return plot