Skip to content

Commit

Permalink
101 enhc add ability to disable individual ldar sim outputs (#103)
Browse files Browse the repository at this point in the history
* feat: Add ability to disable outputs

Reason for change:
This allows users to disable  LDAR-Sim results that are not of interest.

Resolution:
Created flags under simulation settings outputs to allow users to disable
the site_visits, leaks, sites, timeseries, plots and batch reporting outputs. Also modified
LDAR-Sim running scripts so that if any of the sites, leaks or timeseries csv outputs are disabled,
batch reporting will also be disabled.

Effect(s) of change:
Site visits, leaks, sites and timeseries csv's can now be disabled, along with plots
and batch reporting functionality. Removed write_data and make_plots.
  • Loading branch information
ThomasGalesloot authored Aug 22, 2023
1 parent d2ea41a commit 5273638
Show file tree
Hide file tree
Showing 64 changed files with 626 additions and 145,723 deletions.
2 changes: 1 addition & 1 deletion LDAR_Sim/simulations/M_OGI.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameter_level: method
version: "3.0"
version: "3.2"
label: OGI
deployment_type: mobile
measurement_scale: component
Expand Down
2 changes: 1 addition & 1 deletion LDAR_Sim/simulations/M_OGI_FU.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameter_level: method
version: "3.0"
version: "3.2"
label: OGI_FU
deployment_type: mobile
measurement_scale: component
Expand Down
2 changes: 1 addition & 1 deletion LDAR_Sim/simulations/M_aircraft.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameter_level: method
version: "3.0"
version: "3.2"
label: aircraft
deployment_type: mobile
measurement_scale: equipment
Expand Down
2 changes: 1 addition & 1 deletion LDAR_Sim/simulations/M_aircraft_ex_sensor.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameter_level: method
version: "3.0"
version: "3.2"
label: aircraft_ex_sensor
deployment_type: mobile
measurement_scale: equipment
Expand Down
2 changes: 1 addition & 1 deletion LDAR_Sim/simulations/M_drone.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameter_level: method
version: "3.0"
version: "3.2"
label: drone
deployment_type: mobile
measurement_scale: equipment
Expand Down
2 changes: 1 addition & 1 deletion LDAR_Sim/simulations/M_truck.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameter_level: method
version: "3.0"
version: "3.2"
label: truck
deployment_type: mobile
measurement_scale: equipment
Expand Down
2 changes: 1 addition & 1 deletion LDAR_Sim/simulations/P_OGI.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
program_name: P_OGI
parameter_level: program
version: "3.0"
version: "3.2"
method_labels:
- OGI
2 changes: 1 addition & 1 deletion LDAR_Sim/simulations/P_aircraft.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
program_name: P_aircraft
parameter_level: program
version: "3.0"
version: "3.2"
method_labels:
- aircraft
- OGI_FU
2 changes: 1 addition & 1 deletion LDAR_Sim/simulations/P_aircraft_ex_sensor.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
program_name: P_aircraft_ex_sensor
parameter_level: program
version: "3.0"
version: "3.2"
method_labels:
- aircraft_ex_sensor
- OGI_FU
2 changes: 1 addition & 1 deletion LDAR_Sim/simulations/P_drone.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
program_name: P_drone
parameter_level: program
version: "3.0"
version: "3.2"
method_labels:
- drone
- OGI_FU
2 changes: 1 addition & 1 deletion LDAR_Sim/simulations/P_none.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
program_name: P_none
parameter_level: program
version: "3.0"
version: "3.2"
method_labels: []
2 changes: 1 addition & 1 deletion LDAR_Sim/simulations/P_truck.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
program_name: P_truck
parameter_level: program
version: "3.0"
version: "3.2"
method_labels:
- truck
- OGI_FU
2 changes: 1 addition & 1 deletion LDAR_Sim/simulations/Simulation_settings.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameter_level: simulation_settings
version: "3.0"
version: "3.2"
pregenerate_leaks: True
reference_program: P_OGI
baseline_program: P_none
2 changes: 1 addition & 1 deletion LDAR_Sim/simulations/virtual_world.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version: "3.0"
version: "3.2"
parameter_level: "virtual_world"
Empty file added LDAR_Sim/src/config/__init__.py
Empty file.
27 changes: 27 additions & 0 deletions LDAR_Sim/src/config/output_flag_mapping.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# ------------------------------------------------------------------------------
# Program: The LDAR Simulator (LDAR-Sim)
# File: output_flag_mapping
# Purpose: Variables mapping to the expected string for output flags,
# making it easier to refactor output flags in the future
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the MIT License as published
# by the Free Software Foundation, version 3.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# MIT License for more details.

# You should have received a copy of the MIT License
# along with this program. If not, see <https://opensource.org/licenses/MIT>.
#
# ------------------------------------------------------------------------------

OUTPUTS = 'outputs'
SITE_VISITS = 'site_visits'
LEAKS = "leaks"
SITES = "sites"
TIMESERIES = "timeseries"
PLOTS = "plots"
BATCH_REPORTING = "batch_reporting"
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ n_processes: 6 # Recommend: 6
n_simulations: 2
start_date: [2023, 1, 1]
end_date: [2027, 12, 31]
make_plots: True # True/False
print_from_simulations: True # True/False
write_data: True # True/False
pregenerate_leaks: True # True/False
preseed_random: False # True/False
outputs:
site_visits: False
leaks: True
sites: True
timeseries: True
plots: True
batch_reporting: True
102 changes: 66 additions & 36 deletions LDAR_Sim/src/initialization/input_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,35 @@
import os
import sys
from pathlib import Path
from typing import Union

import yaml
from config.output_flag_mapping import (BATCH_REPORTING, LEAKS, OUTPUTS, PLOTS, SITES,
TIMESERIES)
from initialization.versioning import (CURRENT_FULL_VERSION,
CURRENT_MAJOR_VERSION,
CURRENT_MINOR_VERSION,
LEGACY_PARAMETER_WARNING,
MAJOR_VERSION_ONLY_WARNING,
MINOR_VERSION_MISMATCH_WARNING,
check_major_version)
from utils.check_parameter_types import check_types
from initialization.versioning import (
LEGACY_PARAMETER_WARNING,
CURRENT_MAJOR_VERSION,
CURRENT_MINOR_VERSION,
MINOR_VERSION_MISMATCH_WARNING,
CURRENT_FULL_VERSION,
MAJOR_VERSION_ONLY_WARNING,
check_major_version
)


class InputManager:

MAKE_PLOTS = "make_plots"
WRITE_DATA = "write_data"

def __init__(self) -> None:
""" Constructor creates a lookup of method defaults to run validation against
"""
sim_settings_file = './src/default_parameters/simulation_settings_default.yml'
with open(sim_settings_file, 'r') as f:
default_sim_setting_parameters = yaml.load(f.read(), Loader=yaml.SafeLoader)
self.simulation_parameters = copy.deepcopy(default_sim_setting_parameters)

self.old_params = False
# Simulation parameter are parameters that are set up for this simulation
return

Expand Down Expand Up @@ -81,16 +88,8 @@ def read_parameter_files(self, parameter_filenames):
new_parameters_list.append(self.read_parameter_file(parameter_filename))

# Perform any mapping, optionally accumulating mined global parameters
sim_setting_parameters = {}
for i in range(len(new_parameters_list)):
new_parameters_list[i], mined_sim_setting_parameters = \
self.map_parameters(new_parameters_list[i])
sim_setting_parameters.update(mined_sim_setting_parameters)

# Append the mined global parameters for installation after all other parameter updates
if len(sim_setting_parameters) > 0:
sim_setting_parameters['parameter_level'] = 'simulation_settings'
new_parameters_list.append(sim_setting_parameters)
new_parameters_list[i] = self.map_parameters(new_parameters_list[i])

return (new_parameters_list)

Expand Down Expand Up @@ -124,31 +123,62 @@ def read_parameter_file(self, filename):

return (new_parameters)

def handle_parameter_versioning(self, parameters) -> None:
if not self.old_params:
if 'version' not in parameters:
print(('Warning: interpreting parameters as version ' +
CURRENT_FULL_VERSION +
' because version key was missing'))
parameters['version'] = CURRENT_FULL_VERSION

expected_version_string = ".".join([CURRENT_MAJOR_VERSION, CURRENT_MINOR_VERSION])

if str(parameters['version']) != expected_version_string:
if str(parameters['version']) == CURRENT_MAJOR_VERSION:
print(MAJOR_VERSION_ONLY_WARNING)
sys.exit()
elif not check_major_version(str(parameters['version']), CURRENT_MAJOR_VERSION):
print(LEGACY_PARAMETER_WARNING)
sys.exit()
else:
print(MINOR_VERSION_MISMATCH_WARNING)
self.old_params = True
return

def map_simulation_settings(self, parameters) -> None:
outputs: Union[bool, None] = parameters.get(OUTPUTS)

if outputs is None:
parameters[OUTPUTS] = {}

make_plots: Union[bool, None] = parameters.get(self.MAKE_PLOTS)

if make_plots is not None:
parameters[OUTPUTS][PLOTS] = make_plots
del parameters[self.MAKE_PLOTS]

write_data: Union[bool, None] = parameters.get(self.WRITE_DATA)

if write_data is not None:
parameters[OUTPUTS][BATCH_REPORTING] = write_data
parameters[OUTPUTS][SITES] = write_data
parameters[OUTPUTS][LEAKS] = write_data
parameters[OUTPUTS][TIMESERIES] = write_data

return

def map_parameters(self, parameters):
"""Function to map parameters from older versions to the present version, all mappings are
externally specified in the relevant function.
:param parameters = the input parameter dictionary
:return returns the compliant parameters dictionary, and optionally mined global parameters
"""
if 'version' not in parameters:
print('Warning: interpreting parameters as version 3.0 because version key was missing')
parameters['version'] = CURRENT_FULL_VERSION

expected_version_string = ".".join([CURRENT_MAJOR_VERSION, CURRENT_MINOR_VERSION])

if str(parameters['version']) != expected_version_string:
if str(parameters['version']) == CURRENT_MAJOR_VERSION:
print(MAJOR_VERSION_ONLY_WARNING)
sys.exit()
elif not check_major_version(str(parameters['version']), CURRENT_MAJOR_VERSION):
print(LEGACY_PARAMETER_WARNING)
sys.exit()
else:
print(MINOR_VERSION_MISMATCH_WARNING)
self.handle_parameter_versioning(parameters)

mined_global_parameters = {}
if parameters['parameter_level'] == "simulation_settings":
self.map_simulation_settings(parameters)

return (parameters, mined_global_parameters)
return parameters

def parse_parameters(self, new_parameters_list):
"""Method to parse and validate new parameters, perform type checking, and organize for
Expand Down Expand Up @@ -176,7 +206,7 @@ def parse_parameters(self, new_parameters_list):
programs = programs + new_parameters.pop('programs')

check_types(self.simulation_parameters, new_parameters, omit_keys=['programs'])
self.simulation_parameters.update(new_parameters)
self.retain_update(self.simulation_parameters, new_parameters)

elif new_parameters['parameter_level'] == 'virtual_world':
if 'default_parameters' not in new_parameters:
Expand Down
4 changes: 2 additions & 2 deletions LDAR_Sim/src/initialization/versioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ def check_major_version(version_string, major_version):

CURRENT_MAJOR_VERSION = "3"

CURRENT_MINOR_VERSION = "0"
CURRENT_MINOR_VERSION = "2"

CURRENT_FULL_VERSION = "3.0"
CURRENT_FULL_VERSION = "3.2"
Loading

0 comments on commit 5273638

Please sign in to comment.