Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDFS default overriding sensortoolkit.Parameter #6

Open
silverfoxpt opened this issue Jan 14, 2025 · 0 comments
Open

SDFS default overriding sensortoolkit.Parameter #6

silverfoxpt opened this issue Jan 14, 2025 · 0 comments

Comments

@silverfoxpt
Copy link

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 silverfoxpt changed the title Default SDFS default overriding sensortoolkit.Parameter SDFS default overriding sensortoolkit.Parameter Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant