Git Product home page Git Product logo

weewx-aqi-xtype's Introduction

weewx-aqi-xtype

Description

This extension uses WeeWX Xtypes capability to dynamically calculate AQI. Currently it only supports pm 2.5 and pm 10. For supported pollutants, mutiple sensors are supported. Currently only the US EPA algorithm is supported.

Installation notes

Because there are multiple methods to install WeeWX, location of files can vary. See where to find things in the WeeWX User's Guide for the definitive information. The following symbolic names are used to define the various locations:

  • $DOWNLOAD_ROOT - The directory containing the downloaded weewx-aqi-xtype extension.
  • $BIN_ROOT - The directory where WeeWX executables are located.
  • $CONFIG_ROOT - The directory where the configuration (typically, weewx.conf) is located.

The notation vX.Y.Z designates the version being installed. X.Y.Z is the release.

Prior to making any updates/changes, always make a backup.

Preqrequisites

WeeWX version Python version
4.6.0 or greater Python 3.6 or greater

Installation

  1. Download weewx-aqi-xtype

    wget -P $DOWNLOAD_ROOT https://github.com/bellrichm/weewx-aqi-ztype/archive/vX.Y.Z.tar.gz
    

    All of the releases can be found here and this is the latest.

  2. Install weewx-aqi-xtype

    wee_extension --install=$DOWNLOAD_DIR/vX.Y.Z.tar.gz
    
  3. Restart WeeWX

    sudo /etc/init.d/weewx restart
    

    or

    sudo sudo service restart weewx
    

    or

    sudo systemctl restart weewx
    

Customizing

The installation of weewx-aqi-xtype configures it so that will work with the WeeWX 'extended schema.' It will calculate the Instacast AQI and Nowcast AQI for the value of pm 2.5. To do this three sections of weewx configuration are updated. The first is [[[Generic]]] section of [StdReport][[Labels]]. Here the default label is added.

[StdReport]
    [[Labels]]
        [[[Generic]]]
            .
            .
            .
            pm2_5_aqi = AQI
            pm2_5_aqi_nowcast = AQI (Nowcast)

The second is the [[Calculations]] section of [StdWXCalculate]. Here, the calculated AQI field is added. Doing this adds it to the WeeWX loop packets and archive records.

[StdWXCalculate]
    [[Calculations]]
    .
    .
    .
        pm2_5_aqi = prefer_hardware
        # Since this requires a database look up, by default do not populate loop packets
        pm2_5_aqi_nowcast = prefer_hardware, archive        

The third update is an additional section, [aqitype]. This is where the information needed to calculate the AQI is configured.

[aqitype]
    # The name of AQI field.
    # Create a section for each field to be calculated.
    [[pm2_5_aqi]]
        # The name of the WeeWX observation to be used in the calculation.
        input = pm2_5
        # The name of the algorithm.
        # Supported values: EPAAQI
        algorithm = EPAAQI
        # If the algorithm supports different pollutants(pm 2.5, pm 10, etc)
        # Supported values: pm2_5, pm10
        type = pm2_5
    [[pm2_5_aqi_nowcast]]
        # The name of the WeeWX observation to be used in the calculation.
        input = pm2_5
        # The name of the algorithm.
        # Supported values: EPAAQI, NOWCAST
        algorithm = NOWCAST
        # If the algorithm supports different pollutants(pm 2.5, pm 10, etc)
        # Supported values: pm2_5, pm10
        type = pm2_5                

Suppose one has a second air quality sensor and WeeWX has been configured to store it in pm2_51. To calculate the AQI value for this sensor, both the [[Calculations]] section and [aqitype] section need to be updated. The result should look something like this.

[StdReport]
    [[Labels]]
        [[[Generic]]]
            .
            .
            .
            pm2_5_aqi = Inside AQI
            pm2_5_aqi = Outside AQI
            pm2_5_aqi_nowcast = Inside AQI (Nowcast)
            pm2_51_aqi_nowcast = Outside AQI (Nowcast)
[StdWXCalculate]
    [[Calculations]]
    .
    .
    .
        pm2_5_aqi = prefer_hardware
        pm2_51_aqi = prefer_hardware
        # Since this requires a database look up, by default do not populate loop packets
        pm2_5_aqi_nowcast = prefer_hardware, archive     
        pm2_51_aqi_nowcast = prefer_hardware, archive                     
[aqitype]
    # The name of AQI field.
    # Create a section for each field to be calculated.
    [[pm2_5_aqi]]
        # The name of the WeeWX observation to be used in the calculation.
        input = pm2_5
        # The name of the algorithm.
        # Supported values: EPAAQI
        algorithm = EPAAQI
        # If the algorithm supports different pollutants(pm 2.5, pm 10, etc)
        # Supported values: pm2_5, pm10
        type = pm2_5      
    [[pm2_51_aqi]]
        # The name of the WeeWX observation to be used in the calculation.
        input = pm2_51
        # The name of the algorithm.
        # Supported values: EPAAQI
        algorithm = EPAAQI
        # If the algorithm supports different pollutants(pm 2.5, pm 10, etc)
        # Supported values: pm2_5, pm10
        type = pm2_5         
    [[pm2_51_aqi_nowcast]]
        # The name of the WeeWX observation to be used in the calculation.
        input = pm2_51
        # The name of the algorithm.
        # Supported values: EPAAQI, NOWCAST
        algorithm = NOWCAST
        # If the algorithm supports different pollutants(pm 2.5, pm 10, etc)
        # Supported values: pm2_5, pm10
        type = pm2_5                 

By default aqi_xtype is added to the beginning of the list of xtypes. This has the effect of overriding other xtypes (except for any added to the beginning after aqi-xtype). If for some reason it is desired to add it to the end, set prepend = False

[aqitype]
    # Add aqi-xtype to the end of the list of xtypes.
    prepend = False

Using

Now the calculated value, pm2_5_aqi can be used like any built-in WeeWX type.

Note: Nowcast values are only available with the $current and $latest tags. It does not support aggregation nor series.

Display values

For example, in a Cheetah template

Desired display Cheetah code
Current value $current.pm2_5_aqi
Maximum value for the year $year.pm2_5_aqi.max
A json series of maximum values for the days of the current year $year.pm2_5_aqi.series(aggregate_type='max', aggregate_interval='day').json

Charting

WeeWX ImageGenerator

The values are also available to the builtin WeeWX charting subsystem Here are two charts. One of the calculated pm 2.5 AQI. The scond of the pm 2.5 values.

    [[year_images]]
        aggregate_type = max
        aggregate_interval = 86400

        [[[yearaqi]]]
            yscale = 0, None, None
            [[[[pm2_5_aqi]]]]

        [[[yearpm2_5]]]
            yscale = 0, None, None
            [[[[pm2_5]]]]

weewx-jas

The values are also available to user extensions. For exanmple a graph in the weewx-jas would look like this

    [[jas]]
        [[[Extras]]]
            [[[[chart_definitions]]]]
                [[[[[pm]]]]]
                    [[[[[[series]]]]]]
                        [[[[[[[pm2_5]]]]]]]
                            yAxisIndex = 0
                        [[[[[[[pm2_5_aqi]]]]]]]
                            yAxisIndex = 1
                        [[[[[[[pm10_0]]]]]]]

Additional Cheetah Tags

In addition to the XTtype to calculate the AQI, WeeWX-aqi-xtype has a WeeWX SearchList extension which given an AQI value and standard/algorithm will return the associated color hex value. It also can look up the AQI label for a given AQI value and standard/algorithm.

$AQIColor

This is called like, $AQIColor(value, standard).

$AQIDescription

This is called like, $AQIDescription(value, standard).

Getting Help

Feel free to open an issue, start a discussion in github, or post on WeeWX google group. When doing so, see Help! Posting to weewx user for information on capturing the log. And yes, capturing the log from WeeWX startup makes debugging much easeier.

weewx-aqi-xtype's People

Contributors

bellrichm avatar

Stargazers

David Shanske avatar

Watchers

David Shanske avatar  avatar  avatar

weewx-aqi-xtype's Issues

Default Formatting for AQI

By default, the air quality index shows with decimal...I know I can manually set it, but shouldn't the default be a whole number?

weewx-aqi-xtype installer issue

the installer is adding these lines in the wrong section of weewx.conf file:

[StdReport]
[[Labels]]
[[[Generic]]]
pm2_5_aqi = AQI
pm2_5_aqi_nowcast = AQI (Nowcast)

this caused weewx to crash:

weewxd[1202]: skin_dict['skin'])) as cwd:
weewxd[1202]: File "/usr/lib/python3/dist-packages/configobj.py", line 554, in getitem
weewxd[1202]: val = dict.getitem(self, key)
weewxd[1202]: KeyError: 'skin'
weewxd[1202]: INFO main: Received signal TERM (15).
weewxd[1202]: INFO weewx.engine: Main loop exiting. Shutting engine down.
systemd[1]: Stopping WeeWX...

correcting the location of these lines fixed the problem:

[[Defaults]]
    [[[Labels]]]
        [[[[Generic]]]]
            pm2_5_aqi = AQI
            pm2_5_aqi_nowcast = AQI (Nowcast)

aqi_EPAAQI_description

Hi
just installed weewx-aqi-xtype v1.2.0-rc01 and we are using its default skin, the web page is displaying the aqi description as blow:

1st FL AQI (Nowcast): 15 (aqi_EPAAQI_description 1)
1st FL AQI: 14 (aqi_EPAAQI_description 1)

I believe it should display (Normal) instead of (aqi_EPAAQI_description 1), how to fix it.

thank you

AQI Type Error in WeeWx 5.0

an 15 19:58:21 weewxd[1195199]: CRITICAL main: **** Traceback (most recent call last):
Jan 15 19:58:21 weewxd[1195199]: CRITICAL main: **** File "/usr/share/weewx/weewx/xtypes.py", line 86, in get_scalar
Jan 15 19:58:21 weewxd[1195199]: CRITICAL main: **** return xtype.get_scalar(obs_type, record, db_manager, **option_dict)
Jan 15 19:58:21 weewxd[1195199]: CRITICAL main: **** File "/etc/weewx/bin/user/aqitype.py", line 347, in get_scalar
Jan 15 19:58:21 weewxd[1195199]: CRITICAL main: **** aqi = self.aqi_fields[obs_type]['calculator'].calculate(db_manager, record['dateTime'], record[dependent_field], aqi_type)
Jan 15 19:58:21 weewxd[1195199]: CRITICAL main: **** File "/etc/weewx/bin/user/aqitype.py", line 168, in calculate
Jan 15 19:58:21 weewxd[1195199]: CRITICAL main: **** concentration = self.calculate_concentration(db_manager, time_stamp)
Jan 15 19:58:21 weewxd[1195199]: CRITICAL main: **** File "/etc/weewx/bin/user/aqitype.py", line 139, in calculate_concentration
Jan 15 19:58:21 weewxd[1195199]: CRITICAL main: **** min_value = min(data[0])
Jan 15 19:58:21 weewxd[1195199]: CRITICAL main: **** TypeError: '<' not supported between instances of 'NoneType' and 'NoneType'
Jan 15 19:58:21 weewxd[1195199]: CRITICAL main: ****

NowCast vs AQI Current Conditions

If I'm reading the technical documentation currently, there are two EPA AQI methods.

AQI is an averaged amount over a 24 hour period for pm2.5 and pm10. So, once the day is over, this is the one that would be used for the calendar day.

The NowCast is computed from the most recent 12 hours, but weighing the most recent hours of data more heavily than an ordinary 12-hour average. It is used in lieu of a 24-hour average PM concentration in the calculation of the AQI until an entire calendar day is completed.

Curious what your plans are, because averaging out is a hard thing to do.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.