sensortoolkit
sensortoolkit copied to clipboard
SDFS default overriding sensortoolkit.Parameter
Description
While using this code:
pollutant = sensortoolkit.Parameter('PM25', averaging=['24-hour'])
print(pollutant.averaging)
I've discovered that the Parameter's averaging param will get reset back to ["1-hour", "24-hour"] if the PM2.5 option is chosen from SDFS options (I think this will happen to any SDFS option).
Expected behavior
For the sensortoolkit.Parameter to be as set, ['24-hour'].
Details
Tracing back the error:
sensortoolkit.Parameterwill override parameters ifnameis found in__param_dict__(in this case,nameis PM2.5) inside_parameter.py:
if self.name in self.__param_dict__:
self._autoset_param()
__param_dict__is derived from__param_dict:
__param_dict__ = _param_dict
__param_dictis stored and regenerated fromparam_info.jsonstored inC:\Users\<UserName>\AppData\Local\USEPA\sensortoolkitthrough this initialization inside__init__.py:
_lib_path = _os.path.dirname(_os.path.abspath(__file__))
_app_name='sensortoolkit'
_app_author='USEPA'
_app_data_dir = user_data_dir(_app_name, _app_author)
# Load in SDFS parameter attributes
_param_dict = {}
data = None
if not _os.path.exists(_app_data_dir):
_os.makedirs(_app_data_dir)
# copy param data from site-packages to folder location (initial install)
copy2(_os.path.join(_lib_path, 'param', 'param_info.json'),
_os.path.join(_app_data_dir, 'param_info.json'))
# load in param data at appdata location (including any custom params)
with open(_os.path.join(_app_data_dir, 'param_info.json'), 'r') as file:
data = load(file)
for key, val in data.items():
_param_dict[key] = val
- Finally, the
param_info.jsonfile stored PM2.5 as having["1-hour", "24-hour"]as option ofaveraging:
"PM25": {
"baseline": "PM",
"classifier": "PM",
"subscript": "2.5",
"aqs_unit_code": 105,
"averaging": [
"1-hour",
"24-hour"
],
"usepa_targets": true,
"criteria": true,
"aqs_param_code": 88101,
"custom": false,
"unit_info": {
"Unit Code": 105,
"Description": "Micrograms per Cubic Meter",
"Label": "\u00b5g/m\u00b3",
"Conditions": "Local Conditions",
"Context": null,
"SDFS": "PM1, PM25, PM10",
"Classification": "PM"
}
}
Suggested solutions
- Update the documentation to reflect the overriding behavior of SDFS options, or
- Alternatively, allow
sensortoolkit.Parameterto retain the user-specified values and not be overridden by preset SDFS values.