Sun & Moon sine plot/graph

534 views
Skip to first unread message

Xant

unread,
Nov 10, 2019, 4:58:20 PM11/10/19
to weewx-user
How to plot the Sun & Moon sine elevation (sun/moon rise, sun/moon set) based on local coordinates?

Thomas Keffer

unread,
Nov 10, 2019, 8:21:27 PM11/10/19
to weewx-user
The only way I can think of is to put it in the database. Then it can be treated like any other observation type.

On Sun, Nov 10, 2019 at 1:58 PM Xant <armando...@gmail.com> wrote:
How to plot the Sun & Moon sine elevation (sun/moon rise, sun/moon set) based on local coordinates?

--
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/d8ebbdbb-be38-489b-9278-9f8b6f2bb003%40googlegroups.com.

Xant

unread,
Nov 10, 2019, 8:50:07 PM11/10/19
to weewx-user

Thank you Thomas, as that might be a way.

Actually, upon your response, for Sun just occurred to me to make use of Theoretical MaxSolarRad, which is calculated and already in the database for Sunset/Sunrise chart according to location.

Will check the above, while still searching for a generic Sun/Moon sine plot.

gjr80

unread,
Nov 12, 2019, 4:09:21 AM11/12/19
to weewx-user
Agree that if you are using the WeeWX plot engine you have to archive the data you wish to plot; however, if you use something other than the WeeWX plot engine to render your plots then you can avoid archiving the data. I played around with a sun position plot routine in some php a few years ago to produce a graphic file showing a plot of solar altitude through the day with the current sun position highlighted. Whilst the details escape me (whilst I had it working I never actually deployed it) I believe I used WeeWX to produce a report with time and solar altitude data for the day. This report was produced one per day at midnight for the coming day. The php routine then read this data and generated the plot. A similar thing could be done with a json format data file and highcharts or some other plot library.

Developing the report will take a little thought, It could be done with some inline python code in a template or via a SLE to do the hard work and a basic template (SLE would probably be a little easier to deal with setting up pyephem). The report timing option provides the means to control when the report is produced.

Gary

Xant

unread,
Nov 12, 2019, 8:26:34 PM11/12/19
to weewx-user

Thank you Gary, as your feedback always appreciated.

Yes! That's the thinking... although I tweak here and there, and I'm not a programmer sort to say but hobbyist, and still searching for an "easy recipe" :P

Ideally, its something as the following for Sun/Mon:



In a veeery non-scientific way (I recognize), as sunrise/sunset most available, could [(sunrise + sunset)/2] to 'y= +1', [(sunrise(i+1) + sunset)/2] to 'y= -1' and "spline"... no sine perfection here, but a sun cycle graph sort to say.

Meanwhile, I'm playing with Belchertown skin and highcharts:



As winter almost here in upStateNY, the above shows freeze temp and Illuminance on top, so one can immediately verify day-time from visual.

Tried to make right yAxis "invisible" as just to be "day-light", but not working somehow.

    [[chart1]]
        title = Temperature
        type = spline
        time_length = 90000 # Last 25 hours
        [[[outTemp]]]
            zIndex = 1
            type = areaspline
            threshold = 32
            negativeColor = '#A0A0A0'
        [[[windchill]]]
        [[[heatindex]]]
            color = "#f7a35c"
        [[[dewpoint]]]
            name = Temperature
            color = purple
            yAxis_tickInterval = 8
            yAxis_softMin = 32
        [[[maxSolarRad]]]
            name = Illuminance
            yAxis = 1
            color = "#f7f2b4"
            yAxis_visible = false
            observation_type = 120.0*maxSolarRad

Xant

Xant

unread,
Nov 13, 2019, 1:12:07 PM11/13/19
to weewx-user
 
Considering the approach of archive and plot, how to move towards a Sun path "sine" plot?

WeeWX with 'pyephem' provides Sunrise, transit, sunset: $almanac.sun.rise $almanac.sun.transit $almanac.sun.set , which is indeed good info and a start... but may not be sufficient for a continuous plot/graph.

WeeWX and pyephem are powerful tools, and I believe the capability is there, but need feedback and possible recipe.

p q

unread,
Nov 13, 2019, 2:05:25 PM11/13/19
to weewx...@googlegroups.com
Have you looked at using solar altitude (elevation)?

--
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.


--
Peter Quinn
(415)794-2264

Xant

unread,
Nov 13, 2019, 2:30:19 PM11/13/19
to weewx-user
Getting myself into more I wished for, but Astronomical journey and learning experience going through Thomas extensive work (almanac.py, sun.py, moon.py, etc).

Xant

unread,
Nov 14, 2019, 9:29:51 PM11/14/19
to weewx-user

Thomas, Gary et Peter

You ALL correct, and Sun/Moon-Altitude is the way to go. Thus for a start, '$almanac.sun.alt' and '$almanac.moon.alt', and will be added to database for plot/graph.

Instead of  "$almanac.variable.name", how to rename to something more meaningful as 'sun-alt = $almanac.sun.alt' and 'moon-alt = $almanac.moon.alt'? Where those statements can go?

Apologies if awkward to rename as such, but there is a later logic for Belchertown skin to call its Graph routine.

Xant

Xant

unread,
Nov 15, 2019, 1:09:34 AM11/15/19
to weewx-user

(addendum)

Not sure if incorrect format or syntax to Database, but extend database with '$almanac.sun.alt' and '$almanac.moon.alt' generate errors upon "wee_database --rebuild-daily"

schema_extended = schemas.wview.schema + [('maxSolarRad', 'REAL'),...., ('$almanac.sun.alt', 'REAL'), ('$almanac.moon.alt', 'REAL')]


Also, upon adding new extensions to Database, on the "schema_extended =..." you keep the previously added, or delete previously added extensions?

gjr80

unread,
Nov 15, 2019, 3:33:26 AM11/15/19
to weewx-user
Why use something like $almanc.sun.alt, at best it is confusing and at worst it will break SQLite or MySQL/MariaDB. Why not use something like solar_altitude. For your wee_database error far better to post the exact command entered and the exact response received rather than "it doesn't work".

Not sure exactly what you are getting at with your second question, I hope you did not literally use ,...., in the schema_extended line. If you mean do you include any previously added fields then yes you do, schema_extended needs to comprise all of the fields in your schema, whether original, added earlier or added now.

Gary

Xant

unread,
Nov 15, 2019, 8:59:44 AM11/15/19
to weewx-user
1) Almanac/pyephem
"$almanac.sun.alt" indeed confusing, and as you mentioned, think that's what is "breaking" SQLite. Nomenclature, format or syntax doesn't seems appropriate.
As not yet much familiar with the Astronomy portion of WeeWX, and following User's Guide, "$almanac.sun.alt" and "$almanac.moon.alt" (besides the awkward nomenclature) provides info on call.
I was not aware of "solar_altitude" and just found the reference inside weewx/Sun.py (no "moon_altitude" inside weewx/Moon.py, though). Still not aware on how to call it, as direct call "solar_altitude" doesn't seems to provide info.

2) schema_extended
Did not use ",...," in the schema, but reference that it's getting longer.
Acknowledged that "schema_extended needs to comprise all of the fields in your schema, whether original, added earlier or added now".

Thanks, Xant

gjr80

unread,
Nov 15, 2019, 4:49:28 PM11/15/19
to weewx-user
You have decided to record solar and lunar altitude in your database in custom fields so that you can use the WeeWX plot engine to plot each. To do this there are two distinct tasks you need to complete. First you need to extend your database schema to include the new fields. Second you need to populate the WeeWX archive record with the current solar and lunar altitudes (WeeWX will then automatically store your altitude data in the database). Whilst related these are quite separate tasks.

To add the custom fields you need to choose field names, these can be anything, you could call them ‘elephant’ and ‘giraffe’ if you wanted. However, it is best if they are short descriptive names that indicate the field contents. If solar_altitude happens to appear in almanac.py then that is coincidental and will in no way cause your custom field to be populated with the data that almanac.py stores in the solar_altitude variable.

The second task is to have WeeWX add solar altitude and lunar altitude data to the archive record. This is where the field names you chose earlier are used. You need to write some code that will calculate the solar and lunar altitude and store this data in the WeeWX archive record in the fields with names corresponding to those you added to the schema. WeeWX will not automatically do this calculation for you, you will need to write some code. Tags such as $almanac.sun.alt are of no use to you, these are tags that can be used in weewx reports (templates) only and that is not what you are doing here.

You chose to go down the path of adding fields to the database so that you can plot them. This has the advantage of plot generation itself being very simple (WeeWX will do it all for you) but there is moderate complexity involved in getting WeeWX to archive the data for you. The approach I outlined earlier requires a fairly simple report be generated but moderate complexity in implementing highcharts (or similar) to plot the generated data.

Unfortunately there are no free lunches :)

Gary

Xant

unread,
Nov 15, 2019, 5:48:59 PM11/15/19
to weewx-user

If not free lunch, thank you Gary for the snack (as I continue learning through the experience....)

1) To Database, or Not To Database
Sure, your previous mention coding would be the ideal ("sun position plot routine in some php a few years ago to produce a graphic file showing a plot of solar altitude through the day with the current sun position highlighted"). Indeed, this approach would address past/present/future.

As WeeWX has pyephem and "Almanac", thought to be a normal path. '$almanac.sun.alt' and '$almanac.moon.alt' does provide uptime print info, but as said (and by trying) it breaks the Database. Was still thinking on rename to 'elephant' and 'giraffe', but still...

Extend database was not a chosen path, but baby-steps... would prefer to avoid this approach, as to avoid "another variable/extension" (which no meaning to PWS Observations), for a more educated track.

Even if a dirty coding, puzzles me why '$alamanac.sun.alt" breaks the Database (for the sake to be just a number... but will not stress on that).

The search for an "easy recipe" (so I could make my own lunch and dinner), still escaping me.


2) solar_altitude
Coincidentally or not, 'solar_altitude' is in /usr/share/weewx/weeutil/Sun.py (not 'almanac.py'; there is a Moon.py as well, but no altitude).
In fact, routine seems "fairly simple" sort to say, as the following:

def solar_altitude(latitude, year, month, day):
   
"""
    Compute the altitude of the sun. No atmospherical refraction taken
    in account.
    Altitude of the southern hemisphere are given relative to
    true north.
    Altitude of the northern hemisphere are given relative to
    true south.
    Declination is between 23.5° North and 23.5° South depending
    on the period of the year.
    Source of formula for altitude is PhysicalGeography.net
    http://www.physicalgeography.net/fundamentals/6h.html
    """

   
# Compute declination
    N
= daysSince2000Jan0(year, month, day)
    res
=  sunRADec(N)
    declination
= res[1]

   
# Compute the altitude
    altitude
= 90.0 - latitude  + declination

   
# In the tropical and  in extreme latitude, values over 90 may occurs.
   
if altitude > 90:
        altitude
= 90 - (altitude-90)

   
if altitude < 0:
        altitude
= 0

   
return altitude


In my limited coding, not yet aware on how to call this variable, add to database or use "as is" to just call a plot (no history needed here...).

Best, Xant


gjr80

unread,
Nov 17, 2019, 5:39:05 PM11/17/19
to weewx-user
I think you need to completely forget the likes of $almanac.sun.alt, it is a tag used in WeeWX reports and has no bearing or use in the approach you have taken. I am not surprised that it's use as a field name in a db would cause problems. It is not uncommon for special characters like $ and . to cause problems when used as field or variable names. Sometimes they cannot be used, other times the need to be escaped so they are not mistaken for other commands/actions/functions. It is usually best to avoid them unless absolutely necessary.

If you intend to continue I suggest you work through this one step at a time. Either get your database schema in place and then worry about how to populate it or get your solar and lunar altitude data into the WeeWX generated archive record and then modify your schema to have your data saved to database. There is plenty of information in the Customization Guide regarding adding a new type to the database. Creating a custom WeeWX service to add fields to the archive record will be more challenging, I suggest you thoroughly read and understand the Customisation Guide Introduction and the section Customising the WeeWX service engine.

Gary

Xant

unread,
Nov 17, 2019, 7:18:08 PM11/17/19
to weewx-user
Truly acknowledge all above.

Thought ext-database and Almanac/pyephem to be the "natural" path, as all "embedded" in WeeWX... but it seems to generate another discussion.

Just searching for a Sun/Moon path, and the Altitude, as suggested, seems the right path.

Expectations were to be simple, but... "no free lunch".

The search continuous... and feedback always welcome.

Best, X

Xant

unread,
Nov 22, 2019, 10:06:38 PM11/22/19
to weewx-user
Acknowledged Pyephem '$almanac.sun.alt' not suitable to extend db.

Sun.py (/usr/share/weewx/weeutil/Sun.py) available within WeeWX package, but could not find documentation or supporting reference.

Does someone knows how to use/call the package and input to db? (sure indeed, would need some sort of timestamp along with data).

Once again, the goal is to create a Sun/Moon altitude plot/graph.

Xant

unread,
Nov 23, 2019, 4:34:23 PM11/23/19
to weewx-user
While still searching for a Sun/Moon plot solution, either to extend db or other means, found an interesting little piece of code: SunPlot, by Wilmslow Astro (https://weather.wilmslowastro.com/scripts.php).

sun plot


Embeded in Belchertown:


sunplot.png



Pat

unread,
Nov 24, 2019, 4:20:47 PM11/24/19
to weewx-user
Interesting idea. Not everyone can run PHP. If you find it in JS then maybe it's worth an add on for the skin pending any licensing restrictions.

Xant

unread,
Dec 2, 2019, 9:35:55 AM12/2/19
to weewx-user

Any volunteer to transpose small PHP script to JS?

X

Xant

unread,
Dec 15, 2019, 5:08:36 PM12/15/19
to weewx-user
Not a perfect solution yet, but a good temporary option. Underneath, Sun & Moon 24hrs altitude plot through Grafana Sun and Moon Datasource Plugin:


Embedded into Belchertown skin front page:



X
Reply all
Reply to author
Forward
0 new messages