Thank you, hauke. You have answered my question much more thoroughly than I had hoped for as a final result on this thread. What a tour de force for cpan. I removed the loop that iterated over years, and instead created one that supplies the sun heights for several of the cases mentioned here: http://search.cpan.org/dist/DateTime-Event-Sunrise/lib/DateTime/Event/Sunrise.pm#Sun_Height I had always puzzled about how you account for the sun not being a point source. Well, this is it, mod one. My current script is:
#!/usr/bin/perl
use warnings;
use strict;
use 5.010;
use Astro::Utils;
use DateTime;
use DateTime::Event::Sunrise;
use DateTime::Format::Strptime;
use DateTime::Format::Human::Duration;
my $LONG = -122.5; # E = +, W = -
my $LAT = 45; # N = +, S = -
my $ZONE = 'America/Los_Angeles';
for my $sun_height ( 0, -0.833, -6, -12, -18 ) {
my $sun = DateTime::Event::Sunrise->new(
precise => 1,
longitude => $LONG,
latitude => $LAT,
altitude => $sun_height
);
say "sun height is $sun_height";
my $strp = DateTime::Format::Strptime->new(
pattern => '%Y-%m-%d %H:%M:%S',
time_zone => 'UTC',
on_error => 'croak'
);
my $durfmt = DateTime::Format::Human::Duration->new();
print "At "
. abs($LAT)
. ( $LAT > 0 ? "N" : "S" ) . " "
. abs($LONG)
. ( $LONG > 0 ? "E" : "W" ) . ":\n";
my $now_year = DateTime->now->year;
for my $year ($now_year) {
print " In $year:\n";
my @seas = (
[
'Spring', 'March equinox', calculate_equinox( 'mar', 'utc'
+, $year )
],
[
'Summer',
'June solstice',
calculate_solstice( 'jun', 'utc', $year )
],
[
'Fall',
'September equinox',
calculate_equinox( 'sep', 'utc', $year )
],
[
'Winter',
'December solstice',
calculate_solstice( 'dec', 'utc', $year )
],
);
for my $seas (@seas) {
my ( $sname, $when, $start ) = @$seas;
$start = $strp->parse_datetime($start);
$start->set_time_zone($ZONE);
my $rise = $sun->sunrise_datetime($start);
my $set = $sun->sunset_datetime($start);
my $dur = $durfmt->format_duration_between( $rise, $set );
print " $sname begins on the $when at ",
$start->strftime('%Y-%m-%d %H:%M:%S %Z'), ".\n";
print " Sunrise is at ", $rise->strftime('%H:%M:%S %Z'),
", sunset is at ", $set->strftime('%H:%M:%S %Z'), ",\n";
print " and the day is $dur long.\n";
}
}
}
The output is interesting but verbose:
It is true that D. Rolsky, haukex, and many others made the solution to my question simply a matter of installing cpan modules and replicating code, yet I seek to extend this result into the idiom of _Intermediate Perl_ and Gilligan's island. I've been checking off exercises as I go through, and submitting a pull request on github was one of them. https://github.com/TBlazer66/ephemeris/pull/1/commits/523b4584798a0589cb3c083cc3db3716c37dd046
I know this doesn't address the "as function of space" part of the question, but still, a fun little weekend project :-)
On the contrary, it covers it pretty well for a terrestrial coordinate system with r fixed. Having latitude and longitude, they form an orthogonal spacial basis of order 3, which along with time creates the Vierervektor. The missing element I can't get over is r. There's a lot of things that make a viewer taller at a given location, like mountains, or being a couple standard deviations above the norm in height, and to the contrary dwarves, but they see the sun set too with a differing metric. The shape of this "shell" is particularly important when we consider glaciation. I know NASA has a lot on it, wonder if perl does.
Finally, there's nothing to apologize for with terrestrial-based coordinate systems unless you start claiming that it's the *only* way to look at matters, as we learn from Uncle Albert that the choice of an origin is beliebig...arbitrary. Just like you wouldn't use the sun as an origin to build a house, you wouldn't use heliocentrism for the task of "when does the sun set?" It has been an act of revolution to suggest that the "Gods" were one way or the other.
Happy that the world revolved today....
|