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 
<http://weewx.com/docs/customizing.htm#add_archive_type>. 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 <http://weewx.com/docs/customizing.htm#introduction> and the 
section Customising the WeeWX service engine. 
<http://weewx.com/docs/customizing.htm#service_engine> 

Gary

On Saturday, 16 November 2019 08:48:59 UTC+10, Xant wrote:
>
>
> 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
>
> https://github.com/weewx/weewx/blob/master/bin/weeutil/Sun.py
>
> 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
>
>
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/weewx-user/c54a11c9-1d89-465f-845d-ac35753b4468%40googlegroups.com.

Reply via email to