Wrong XTypes output after upgrading WeeWX 4.1.1 to 4.3.0

68 views
Skip to first unread message

Arend

unread,
Jan 6, 2021, 12:33:12 PM1/6/21
to weewx-user
Everything worked fine until I did the upgrade.

I guess something has changed in the way XTypes are handled?

This is the code I use in extensions.py:

#
#    Copyright (c) 2009-2015 Tom Keffer <tke...@gmail.com>
#
#    See the file LICENSE.txt for your full rights.
#

"""User extensions module

This module is imported from the main executable, so anything put here will be
executed before anything else happens. This makes it a good place to put user
extensions.
"""

import locale
# This will use the locale specified by the environment variable 'LANG'
# Other options are possible. See:
locale.setlocale(locale.LC_ALL, '')

import user.lowest_temperature
import weewx.xtypes

weewx.xtypes.xtypes.append(user.lowest_temperature.LowestTemperature())


This is the code in lowest_temperature.py:

import weewx.units
import weewx.xtypes
from weewx.units import ValueTuple

class LowestTemperature(weewx.xtypes.XType):

  def get_scalar(self, obs_type, record, dbmanager):
    """Determine which sensor has lowest temperature."""
    if obs_type != 'lowTemperature':
      raise weewx.UnknownType
    try:
      record_us = weewx.units.to_US(record)
      if record_us['outTemp'] == None or record_us['extraTemp1'] == None:
      # if record_us['outTemp'] < 100 or record_us['extraTemp1'] < 100:
        raise TypeError("Temperature(s) equal to None")
      if record_us['outTemp'] <= record_us['extraTemp1']:
        lowTemperature = record_us['outTemp']
      else:
        lowTemperature = record_us['extraTemp1']
      return ValueTuple(lowTemperature, "degree_F", "group_temperature")
    except KeyError:
      # Don't have everything we need. Raise an exception.
      raise weewx.CannotCalculate(obs_type)
  
  def get_series(self, obs_type, timespan, db_manager, aggregate_type=None, aggregate_interval=None):
    if obs_type != 'lowTemperature':
      raise weewx.UnknownType
    start_vec = list()
    stop_vec = list()
    data_vec = list()
    if aggregate_type:
      raise weewx.UnknownAggregation(aggregate_type)
    for record in db_manager.genSql("SELECT `dateTime`, `interval`, `usUnits`, `outTemp`, `extraTemp1` FROM `archive` WHERE `dateTime` > %(start)s AND `dateTime` <= %(stop)s;" % {'start': timespan[0], 'stop': timespan[1]}):
      if (record[2] != 1):
        raise weewx.CannotCalculate("units are not US")
      if record[3] == None or record[4] == None:
      # if record[3] < 100 or record[4] < 100:
        raise TypeError("Temperature(s) equal to None")
      start_vec.append(record[0] - record[1] * 60)
      stop_vec.append(record[0])
      if record[3] <= record[4]:
        data_vec.append(record[3])
      else:
        data_vec.append(record[4])
    return (ValueTuple(start_vec, 'unix_epoch', 'group_time'), ValueTuple(stop_vec, 'unix_epoch', 'group_time'), ValueTuple(data_vec, "degree_F", "group_temperature"))

Do I need to rewrite all code?

Arend

unread,
Jan 6, 2021, 1:00:09 PM1/6/21
to weewx-user
In addition to the previous: the get_scalar function still seems to be working but the get_series function no longer works.

Op woensdag 6 januari 2021 om 18:33:12 UTC+1 schreef Arend:

Tom Keffer

unread,
Jan 6, 2021, 1:12:47 PM1/6/21
to weewx-user
It would help if we knew what the problem was. "No longer works" doesn't tell us much.

--
You received this message because you are subscribed to the Google Groups "weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to weewx-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/5ac947ed-240d-428b-8a69-c0186359d97cn%40googlegroups.com.

Arend

unread,
Jan 6, 2021, 1:16:20 PM1/6/21
to weewx-user
Hello Tom,

I get strange output as can be seen in the chart below. It apperas the series isn't calculated/retrieved as it did before the upgrade. I hope this helps to understand.

daytempdew.png

Regards, Arend
Op woensdag 6 januari 2021 om 19:12:47 UTC+1 schreef tke...@gmail.com:

Tom Keffer

unread,
Jan 6, 2021, 1:24:22 PM1/6/21
to weewx-user
I would guess that the problem is that you are always returning lowestTemperature in Fahrenheit, but your data records are in Celsius.

That part of XTypes has not changed. I don't know why it worked before. Perhaps units were in Fahrenheit before?

-tk

Arend

unread,
Jan 6, 2021, 1:51:20 PM1/6/21
to weewx-user
The get_scalar function is still returning the correct values:
Current conditions.png
I have put Outside Temperature, Temperature1 and the calculated Lowest Temperature in one chart. I really don't understand why the get_series calculation is now outputting such high values. Any suggestions are welcome.

daytempdew (1).png

Op woensdag 6 januari 2021 om 19:24:22 UTC+1 schreef tke...@gmail.com:

Arend

unread,
Jan 6, 2021, 2:40:06 PM1/6/21
to weewx-user
Found a solution to the problem, everything is back to normal now.

Added these lines to the end of  lowest_temperature.py:

# Tell the unit system what group our new observation type, 'lowTemperature', belongs to:
weewx.units.obs_group_dict['lowTemperature'] = "group_temperature" 

Somehow this wasn't required in 4.1.1. Maybe more people will run into this issue when upgrading to 4.3.0.

Op woensdag 6 januari 2021 om 19:51:20 UTC+1 schreef Arend:
Reply all
Reply to author
Forward
0 new messages