VRULE for sunset, sunrise

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

VRULE for sunset, sunrise

Joseph Mack NA3T
(I've scanned the archive for the strings in the subject
line).

I'm collecting weather data and would like to plot the
sunrise and sunset time with a VRULE. It seems that VRULE
must be passed a number, rather than whatever is in a
DEF/CDEF variable. I can extract sunset/sunrise into shell
variables and plot them with VRULE, but I'd like to be able
to save the sunrise/sunset times into a rrd database and
recall them later.

Here's how I'm storing sunrise sunset (from the create.rrd
script)

$RRDTOOL create belhaven_weather-sunrise-sunset.rrd -s 300 \
.
.
DS:Sunrise:GAUGE:7200:0:86400 \
DS:Sunset:GAUGE:7200:0:86400 \


Here's my attempt at plotting sunset/sunsite with a VRULE

DAY=`date -d '00:00' +%s`

/$RRDTOOL graph /$DOCUMENTROOT/graphs/belhaven_weather-sunrise-sunset-index.gif
-z -i --no-minor -s -1d -h 200 -w 600 -u24 -l0 --y-grid 3:1 -t "Sunrise/Sunset (Belhaven, NC) - Day" -v "hr" \

DEF:SunriseA=/$DOCUMENTROOT/belhaven_weather-sunrise-sunset.rrd:Sunrise:AVERAGE \
DEF:SunsetA=/$DOCUMENTROOT/belhaven_weather-sunrise-sunset.rrd:Sunset:AVERAGE \
.
.
VRULE:$DAY#0000CC \
VRULE:SunriseA#FF8800 \
VRULE:SunsetA#0088FF \
  -c CANVAS#E5E5E5


I get a parse error for the sunrise/sunset VRULE times.

I'm using rrdtool-1.0.45. I know this is a bit old, but it's
working. If I need to upgrade to handle the VRULE problem,
is the latest rrdtool backward compatible?

Thanks Joe


--
Joseph Mack NA3T EME(B,D), FM05lw North Carolina
jmack (at) wm7d (dot) net - azimuthal equidistant map
generator at http://www.wm7d.net/azproj.shtml
Homepage http://www.austintek.com/ It's GNU/Linux!


Reply | Threaded
Open this post in threaded view
|

Re: VRULE for sunset, sunrise

Alex van den Bogaerdt-2
On Sun, Aug 26, 2007 at 06:45:52AM -0700, Joseph Mack NA3T wrote:

> I'm collecting weather data and would like to plot the
> sunrise and sunset time with a VRULE. It seems that VRULE
> must be passed a number, rather than whatever is in a
> DEF/CDEF variable. I can extract sunset/sunrise into shell
> variables and plot them with VRULE, but I'd like to be able
> to save the sunrise/sunset times into a rrd database and
> recall them later.

Do you want to plot those times, or does it HAVE to be using vrule ?

I can think of ways to achieve what you apparently want. Those ways
do not include VRULE.

First thing to consider: rrdtool works with intervals, not with
times (except vrule, which won't work afaik).

You'll have to deal with consolidation, and want to distinguish
between relevant times (sunset, sunrise) and irrelevant times.

The database resolution needs to be in the same resolution as you
want your data. If you have 86400 seconds per rra-row, you won't
be able to have two different times (time ranges really). This
means: use one minute per row, or even one second.

Then think about what you want to see. Do you want a spike at
sunrise and sunset, or do you want to display daylight and night?

Intervals have a beginning, duration and end. Suppose you want to
display the period between sunrise and sunset, you do want to include
the interval which ends at sunset but you do NOT want to include the
interval which ends at sunrise.

If on the other hand you want spikes, you need mostly UNKN or zero
in your database, with an occasional INF or high value.

In both cases: I'm not sure what happens when {UN,UN,UN,UN,INF,UN,UN,UN}
(for example) is consolidated. Try it. If that results in INF then
you could use UNKN for graph off and INF for graph on (be it a spike
or a range). Else, use zero and a huge value, then use a CDEF to
find the difference between zero and non-zero. Change non-zero into
INF and continue.

Graphing is a matter of displaying the resulting data. INF results
in a bar upto the top of the graph, UNKN or zero won't be visible.

--
Alex van den Bogaerdt
http://www.vandenbogaerdt.nl/rrdtool/


Reply | Threaded
Open this post in threaded view
|

Re: VRULE for sunset, sunrise

Joseph Mack NA3T
On Sun, 26 Aug 2007, Alex van den Bogaerdt wrote:

> On Sun, Aug 26, 2007 at 06:45:52AM -0700, Joseph Mack NA3T wrote:
>
>> I'm collecting weather data and would like to plot the
>> sunrise and sunset time with a VRULE. It seems that VRULE
>> must be passed a number, rather than whatever is in a
>> DEF/CDEF variable. I can extract sunset/sunrise into shell
>> variables and plot them with VRULE, but I'd like to be able
>> to save the sunrise/sunset times into a rrd database and
>> recall them later.

thanks for the quick reply.

> Do you want to plot those times, or does it HAVE to be using vrule ?

Over a year I'd like to plot them on their own graph. I can
do that already, and it wasn't the reason for posting.

Since putting midnight on the graph was so easy with VRULE,
I assumed for the day graph of temp/humidity, a VRULE for
sunrise/sunset, would be equally easy. However I'd be happy
with a light background shading to show the day or night
interval.

> I can think of ways to achieve what you apparently want. Those ways
> do not include VRULE.
>
> First thing to consider: rrdtool works with intervals, not with
> times

I see, I'll have to think about that. I realise there's a
few things about rrdtool that I don't understand.

> (except vrule, which won't work afaik).

:-(

> You'll have to deal with consolidation, and want to distinguish
> between relevant times (sunset, sunrise) and irrelevant times.
>
> The database resolution needs to be in the same resolution as you
> want your data. If you have 86400 seconds per rra-row, you won't
> be able to have two different times (time ranges really). This
> means: use one minute per row, or even one second.
>
> Then think about what you want to see. Do you want a spike at
> sunrise and sunset, or do you want to display daylight and night?

either would be fine

> Intervals have a beginning, duration and end. Suppose you want to
> display the period between sunrise and sunset, you do want to include
> the interval which ends at sunset but you do NOT want to include the
> interval which ends at sunrise.

don't care. Sunrise/Sunset are just decorative guideposts
on the graph.

> If on the other hand you want spikes, you need mostly UNKN or zero
> in your database, with an occasional INF or high value.

hmm. I could get into trouble if I don't grab a sample near
enough to sunrise/sunset.

> In both cases: I'm not sure what happens when {UN,UN,UN,UN,INF,UN,UN,UN}
> (for example) is consolidated. Try it. If that results in INF then
> you could use UNKN for graph off and INF for graph on (be it a spike
> or a range). Else, use zero and a huge value, then use a CDEF to
> find the difference between zero and non-zero. Change non-zero into
> INF and continue.
>
> Graphing is a matter of displaying the resulting data. INF results
> in a bar upto the top of the graph, UNKN or zero won't be visible.

I hadn't thought about any of this. It seems I'm not
thinking about rrdtool the right way.

If VRULE is not going to do it, how about I just shade
between sunrise and sunset? To do that, I can extract the
current value of sunrise and sunset and shade between them
(presumably I can test LTIME when setting the background and
see if it's less than sunset AND more that sunrise).

However how would I shade for yesterday? Instead of using
LTIME, do I calculate

LTIME,86400,-

and use that in the background calculation?

Thanks
Joe
--
Joseph Mack NA3T EME(B,D), FM05lw North Carolina
jmack (at) wm7d (dot) net - azimuthal equidistant map
generator at http://www.wm7d.net/azproj.shtml
Homepage http://www.austintek.com/ It's GNU/Linux!


Reply | Threaded
Open this post in threaded view
|

Re: VRULE for sunset, sunrise

Alex van den Bogaerdt-2
On Sun, Aug 26, 2007 at 09:12:42AM -0700, Joseph Mack NA3T wrote:

> Since putting midnight on the graph was so easy with VRULE,
> I assumed for the day graph of temp/humidity, a VRULE for
> sunrise/sunset, would be equally easy.

And it is. You don't know the time of midnight from your RRD,
do you?  RRDtool knows about rates during time intervals, not
about timestamps.

Your problem is where to get the data. I suggest a separate
file or database (not an RRD).

> >I can think of ways to achieve what you apparently want. Those ways
> >do not include VRULE.

It seems that your goal is not to store sunset/sunrise in the RRD.
In that case my statement was wrong.

New try:

In pseudo_but_almost_real_bash_and_SQL:

echo -n 'rrdtool graph' > rrdtool_commands
[... rrdtool command list is built here ...]
for vrule in `
   sql select sunrise from sun_table
     where timedate < rrdtool_graph_end_time_and_date
       and timedate > rrdtool_graph_start_time_and_date
   sql select sunset from sun_table
     where timedate < rrdtool_graph_end_time_and_date
       and timedate > rrdtool_graph_start_time_and_date
  `
do
  echo " VRULE:$vrule" >> rrdtool_commands
done
[... rest of rrdtool command list is built here ...]
./rrdtool_commands


> If VRULE is not going to do it, how about I just shade
> between sunrise and sunset? To do that, I can extract the
> current value of sunrise and sunset and shade between them
> (presumably I can test LTIME when setting the background and
> see if it's less than sunset AND more that sunrise).
>
> However how would I shade for yesterday? Instead of using
> LTIME, do I calculate
>
> LTIME,86400,-

I think you have to use the modulo function for this. You want
LTIME,86400,%
and then [... quote from earlier in your message...]

> (presumably I can test LTIME when setting the background and
> see if it's less than sunset AND more that sunrise).

Here sunset and sunrise are time-of-day, and that LTIME combined
with a modulo function also returns time-of-day.

But this is for shading, not for those vrules.


HTH
--
Alex van den Bogaerdt
http://www.vandenbogaerdt.nl/rrdtool/


Reply | Threaded
Open this post in threaded view
|

Re: VRULE for sunset, sunrise

Joseph Mack NA3T
On Mon, 27 Aug 2007, Alex van den Bogaerdt wrote:

> On Sun, Aug 26, 2007 at 09:12:42AM -0700, Joseph Mack NA3T wrote:
>
>> Since putting midnight on the graph was so easy with VRULE,
>> I assumed for the day graph of temp/humidity, a VRULE for
>> sunrise/sunset, would be equally easy.
>
> And it is. You don't know the time of midnight from your RRD,
> do you?  RRDtool knows about rates during time intervals, not
> about timestamps.
>
> Your problem is where to get the data. I suggest a separate
> file or database (not an RRD).

yes that was how I got it to work in the first attempt. I
had hoped to use sunset/sunrise in the RRD.

>>> I can think of ways to achieve what you apparently want. Those ways
>>> do not include VRULE.
>
> It seems that your goal is not to store sunset/sunrise in the RRD.
> In that case my statement was wrong.

I want it in the RRD, so I can plot it as a graph, for the
year graph, but I'd like to show the day/night somehow for
any particular day.


>
> New try:
>
> In pseudo_but_almost_real_bash_and_SQL:
>
> echo -n 'rrdtool graph' > rrdtool_commands
> [... rrdtool command list is built here ...]
> for vrule in `
>   sql select sunrise from sun_table
>     where timedate < rrdtool_graph_end_time_and_date
>       and timedate > rrdtool_graph_start_time_and_date
>   sql select sunset from sun_table
>     where timedate < rrdtool_graph_end_time_and_date
>       and timedate > rrdtool_graph_start_time_and_date
>  `
> do
>  echo " VRULE:$vrule" >> rrdtool_commands
> done
> [... rest of rrdtool command list is built here ...]
> ./rrdtool_commands
>
>
>> If VRULE is not going to do it, how about I just shade
>> between sunrise and sunset? To do that, I can extract the
>> current value of sunrise and sunset and shade between them
>> (presumably I can test LTIME when setting the background and
>> see if it's less than sunset AND more that sunrise).
>>
>> However how would I shade for yesterday? Instead of using
>> LTIME, do I calculate
>>
>> LTIME,86400,-
>
> I think you have to use the modulo function for this. You want
> LTIME,86400,%
> and then [... quote from earlier in your message...]

I was trying to retreive yesterday's sunset/sunrise time and
so thought I'd need LTIME for yesterday.

>> (presumably I can test LTIME when setting the background and
>> see if it's less than sunset AND more that sunrise).
>
> Here sunset and sunrise are time-of-day, and that LTIME combined
> with a modulo function also returns time-of-day.
>
> But this is for shading, not for those vrules.

shading is fine.

Thanks Joe

--
Joseph Mack NA3T EME(B,D), FM05lw North Carolina
jmack (at) wm7d (dot) net - azimuthal equidistant map
generator at http://www.wm7d.net/azproj.shtml
Homepage http://www.austintek.com/ It's GNU/Linux!


Reply | Threaded
Open this post in threaded view
|

Re: VRULE for sunset, sunrise

Jason Fesler
> I want it in the RRD, so I can plot it as a graph, for the
> year graph, but I'd like to show the day/night somehow for
> any particular day.

At whatever interval you store regular data, do a lookup and also store
into RRD, whether it is day or night (perhaps as 1 and 0, or 1 and NaN?).
Using that, you can have have an RRD graph that loads your data, + day or
night, and a CDEF can make a choice what to show based on that.

That'll make it so that you only have to worry about the changing time for
sunrise/sunset at the time of insert, and not for any of your later
graphs.


Reply | Threaded
Open this post in threaded view
|

Re: VRULE for sunset, sunrise

Joseph Mack NA3T
On Mon, 27 Aug 2007, Jason Fesler wrote:

>> I want it in the RRD, so I can plot it as a graph, for the
>> year graph, but I'd like to show the day/night somehow for
>> any particular day.
>
> At whatever interval you store regular data, do a lookup and also store into
> RRD, whether it is day or night (perhaps as 1 and 0, or 1 and NaN?).
> Using that, you can have have an RRD graph that loads your data, + day or
> night, and a CDEF can make a choice what to show based on that.
>
> That'll make it so that you only have to worry about the changing time for
> sunrise/sunset at the time of insert, and not for any of your later graphs.

OK.

Currently I have to calculate is_day for any time/interval
at plotting time. I could store two lots of variables

o sunset/sunrise times for plotting the varying times on the
year graph

o is_day as a separate variable for shading the background
in the day graphs.

Joe

--
Joseph Mack NA3T EME(B,D), FM05lw North Carolina
jmack (at) wm7d (dot) net - azimuthal equidistant map
generator at http://www.wm7d.net/azproj.shtml
Homepage http://www.austintek.com/ It's GNU/Linux!


Reply | Threaded
Open this post in threaded view
|

Re: VRULE for sunset, sunrise

Kimball, Conrad
In reply to this post by Jason Fesler
Something to consider...  (maybe the original poster is already aware of
this, but perhaps others on the list are not).

The time of sunrise/sunset is inherently tied to a specific geographic
location.  Within the same time zone sunrise/sunset varies from place to
place - consider that a time zone is nominally one hour wide, so
sunrise/sunset will occur one hour earlier at the eastern edge of a time
zone than at its western edge (indeed, for any given latitude, a
difference of 15 minutes of longitude results in a one minute difference
in sunrise/sunset).  And even at the same longitude sunrise/sunset
varies by latitude - as a limiting case consider the June 21 solstice,
in which the sun never sets at the north pole and never rises at the
south pole.

So one can't even pose a well-defined sunrise/sunset question without
choosing some specific geographic reference point.

Assuming the objective is to graph sunrise/sunset with respect to the
data sources, then...

If all the data you want to display in any one particular graph is
collected from sources within some suitably small distance of your
reference point then you can generate a graph in which sunrise/sunset is
reasonably well-defined.  But as the distance of your sources from the
reference point increases then the idea of plotting sunrise/sunset
becomes increasingly ill-defined.  For example, consider a graph
composed of data from sources across the continental US, or a graph
composed of data from sources in Stockholm and Cape Town which are
nearly the same longitude (roughly 20 minute difference), but on Aug 27,
2007 Stockholm sunrise was 5:32 AM and Cape Town sunrise was 7:12 AM -
both times are UTC+2 (from the very interesting site
http://www.timeanddate.com/worldclock/sunrise.html).

Conrad Kimball

-----Original Message-----
From: Jason Fesler [mailto:[hidden email]]
Sent: Monday, August 27, 2007 8:05 AM
To: Joseph Mack NA3T
Cc: [hidden email]
Subject: Re: [rrd-users] VRULE for sunset, sunrise

> I want it in the RRD, so I can plot it as a graph, for the
> year graph, but I'd like to show the day/night somehow for
> any particular day.

At whatever interval you store regular data, do a lookup and also store
into RRD, whether it is day or night (perhaps as 1 and 0, or 1 and
NaN?).
Using that, you can have have an RRD graph that loads your data, + day
or
night, and a CDEF can make a choice what to show based on that.

That'll make it so that you only have to worry about the changing time
for
sunrise/sunset at the time of insert, and not for any of your later
graphs.

_______________________________________________
rrd-users mailing list
[hidden email]
https://lists.oetiker.ch/cgi-bin/listinfo/rrd-users