sensortoolkit icon indicating copy to clipboard operation
sensortoolkit copied to clipboard

SDFS default overriding sensortoolkit.Parameter

Open silverfoxpt opened this issue 11 months ago • 0 comments

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.Parameter will override parameters if name is found in __param_dict__ (in this case, name is 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_dict is stored and regenerated from param_info.json stored in C:\Users\<UserName>\AppData\Local\USEPA\sensortoolkit through 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.json file stored PM2.5 as having ["1-hour", "24-hour"] as option of averaging:
"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.Parameter to retain the user-specified values and not be overridden by preset SDFS values.

silverfoxpt avatar Jan 14 '25 03:01 silverfoxpt