Adding a new object in the ephem database

106 views
Skip to first unread message

Paul Bartholdi

unread,
Jan 19, 2019, 1:20:21 PM1/19/19
to weewx-user
Hi,

I nodified a few years ago the "Standard/index.html.tmpl" to print the main solar systems objects (sun, moon, Jupiter...).
Now I want to pint the same informations but for the minor planet Eros that pass very (very relative!) the earth in the few next days.
This implies adding the python line:

     eros = ephem.readdb("433 Eros,e,10.8276,304.3222,178.8165,1.457940,0.5598795,0.22258902,71.2803,09/04.0/2017,2000,H11.16,0.46")

and then (in index.html.tmp) :

               <tr>
                  <td class="label">Rise  :</td>
                  <td class="data">$almanac.eros.rise</td>
                </tr>

Where should I add the " eros = ephem.readdb(...) line ?   ( index.html.tmpl ?  almanac.py ? elsewhere ?).

Thanks for any help/advice!     Paul


Thomas Keffer

unread,
Jan 19, 2019, 7:28:33 PM1/19/19
to weewx-user
This is a good question, and it took me a while to figure out how to work around the limitations of pyephem. Try this:

1. Put the following in user/extensions.py:

import ephem
eros = ephem.readdb("433 Eros,e,10.8276,304.3222,178.8165,1.457940,0.5598795,0.22258902,71.2803,09/04.0/2017,2000,H11.16,0.46")
ephem.Eros = eros

2. Modify the WeeWX module weewx/almanac.py so that the function _get_ephem_body() looks like this:

def _get_ephem_body(heavenly_body):
    # The library 'ephem' refers to heavenly bodies using a capitalized
    # name. For example, the module used for 'mars' is 'ephem.Mars'.
    cap_name = heavenly_body.capitalize()
    
    # If the heavenly body is a star, or if the body does not exist, then an
    # exception will be raised. Be prepared to catch it.
    try:
        ephem_body = getattr(ephem, cap_name)()
    except AttributeError:
        # That didn't work. Try a star. If this doesn't work either,
        # then a KeyError exception will be raised.
        ephem_body = ephem.star(cap_name)
    except TypeError:
        ephem_body = getattr(ephem, cap_name)

    return ephem_body

You are adding the two highlighted lines.

3. Then use this in your template:

$almanac.eros.rise

for when it rises, etc. (treat it just like any other planet).

Double check the answer. I'm not 100% confident this will work. If it does, I'll add the changes for weewx/almanac.py to the code base.

-tk

--
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.
For more options, visit https://groups.google.com/d/optout.

gjr80

unread,
Jan 20, 2019, 1:58:48 AM1/20/19
to weewx-user
This will be handy provided it works, I have had a few extra stars that I wanted to include in some reports. Some I have picked up by downloading the latest stars.py from the pyephem repo but there are others that are not included in pyephem. This gives me a suitable way to add them.

Gary

Paul Bartholdi

unread,
Jan 20, 2019, 12:29:07 PM1/20/19
to weewx...@googlegroups.com
Dear Thommas,

Once more you impressed me a lot, such quick and well formed answer. Thanks.

Now I am afraid to say that there is still a buf, probably a typo or some thing like that. I checked "my" additions in "extensions.py" and "almanac.py" (and of course in "index.html.tmpl"), and believe they were correctly done.
Just a question: where can I find the generated file  "cheetah__etc_weewx_skins_Standard_index_html_tmpl_1548001524_26_16364.py" ?

Here is the .log of the error:

reportengine: Found configuration file /etc/weewx/skins/Standard/skin.conf for report StandardReport
cheetahgenerator: using search list ['weewx.cheetahgenerator.Almanac', 'weewx.cheetahgenerator.Station', 'weewx.cheetahgenerator.Current', 'weewx.cheetahgenerator.Stats', 'weewx.cheetahgenerator.UnitInfo', 'weewx.cheetahgenerator.Extras']
manager: Daily summary version is 2.0
cheetahgenerator: Generate failed with exception '<type 'exceptions.TypeError'>'
cheetahgenerator: **** Ignoring template /etc/weewx/skins/Standard/index.html.tmpl
cheetahgenerator: **** Reason: 'ephem.EllipticalBody' object is not callable
****  Traceback (most recent call last):
****    File "/usr/share/weewx/weewx/cheetahgenerator.py", line 330, in generate
****      print >> _file, compiled_template
****    File "/usr/lib/python2.7/dist-packages/Cheetah/Template.py", line 1005, in __str__
****      rc = getattr(self, mainMethName)()
****    File "cheetah__etc_weewx_skins_Standard_index_html_tmpl_1548001524_26_16364.py", line 2545, in respond
****    File "cheetah__etc_weewx_skins_Standard_index_html_tmpl_1548001524_26_16364.py", line 1155, in __errorCatcher156
****    File "<string>", line 1, in <module>
****    File "/usr/share/weewx/weewx/almanac.py", line 355, in __getattr__
****      ephem_body = _get_ephem_body(self.heavenly_body)
****    File "/usr/share/weewx/weewx/almanac.py", line 424, in _get_ephem_body
****      ephem_body = getattr(ephem, cap_name)()
****  TypeError: 'ephem.EllipticalBody' object is not callable
cheetahgenerator: Generated 13 files for report StandardReport in 0.56 seconds
manager: Daily summary version is 2.0

Best regards,     Paul


You received this message because you are subscribed to a topic in the Google Groups "weewx-user" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/weewx-user/XdRQgtqWfFo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to weewx-user+...@googlegroups.com.

Thomas Keffer

unread,
Jan 20, 2019, 8:59:38 PM1/20/19
to weewx-user
This is the error I got before modifying almanac.py. Make sure you're using the version of almanac.py you think you are.

I've attached the patched version I'm using.

-tk
almanac.py

Paul Bartholdi

unread,
Jan 22, 2019, 6:14:10 AM1/22/19
to weewx-user
Dear Thomas, 

Just a line to say that now everything is perfect (see http://shire-bdi.gotdns.com/weewx ). ! Thank for all your help.    Paul
Reply all
Reply to author
Forward
0 new messages