Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^2: calculate length of day as function of space at onset of fall

by Aldebaran (Curate)
on Sep 28, 2016 at 08:01 UTC ( [id://1172808]=note: print w/replies, xml ) Need Help??


in reply to Re: calculate length of day as function of space at onset of fall
in thread calculate length of day as function of space at onset of fall

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:

C:\Users\Fred\Desktop>perl astro5.pl sun height is 0 At 45N 122.5W: In 2016: Spring begins on the March equinox at 2016-03-19 21:29:48 PDT. Sunrise is at 07:15:36 PDT, sunset is at 19:17:02 PDT, and the day is 12 hours, 1 minute, and 26 seconds long. Summer begins on the June solstice at 2016-06-20 15:33:55 PDT. Sunrise is at 05:27:45 PDT, sunset is at 20:53:24 PDT, and the day is 15 hours, 25 minutes, and 39 seconds long. Fall begins on the September equinox at 2016-09-22 07:20:41 PDT. Sunrise is at 07:02:13 PDT, sunset is at 18:58:39 PDT, and the day is 11 hours, 56 minutes, and 26 seconds long. Winter begins on the December solstice at 2016-12-21 02:44:00 PST. Sunrise is at 07:50:12 PST, sunset is at 16:24:55 PST, and the day is 8 hours, 34 minutes, and 43 seconds long. sun height is -0.833 At 45N 122.5W: In 2016: Spring begins on the March equinox at 2016-03-19 21:29:48 PDT. Sunrise is at 07:10:53 PDT, sunset is at 19:21:45 PDT, and the day is 12 hours, 10 minutes, and 52 seconds long. Summer begins on the June solstice at 2016-06-20 15:33:55 PDT. Sunrise is at 05:22:01 PDT, sunset is at 20:59:08 PDT, and the day is 15 hours, 37 minutes, and 7 seconds long. Fall begins on the September equinox at 2016-09-22 07:20:41 PDT. Sunrise is at 06:57:30 PDT, sunset is at 19:03:21 PDT, and the day is 12 hours, 5 minutes, and 51 seconds long. Winter begins on the December solstice at 2016-12-21 02:44:00 PST. Sunrise is at 07:44:32 PST, sunset is at 16:30:35 PST, and the day is 8 hours, 46 minutes, and 3 seconds long. sun height is -6 At 45N 122.5W: In 2016: Spring begins on the March equinox at 2016-03-19 21:29:48 PDT. Sunrise is at 06:41:38 PDT, sunset is at 19:51:05 PDT, and the day is 13 hours, 9 minutes, and 27 seconds long. Summer begins on the June solstice at 2016-06-20 15:33:55 PDT. Sunrise is at 04:44:34 PDT, sunset is at 21:36:35 PDT, and the day is 16 hours, 52 minutes, and 1 second long. Fall begins on the September equinox at 2016-09-22 07:20:41 PDT. Sunrise is at 06:28:12 PDT, sunset is at 19:32:35 PDT, and the day is 13 hours, 4 minutes, and 23 seconds long. Winter begins on the December solstice at 2016-12-21 02:44:00 PST. Sunrise is at 07:10:39 PST, sunset is at 17:04:27 PST, and the day is 9 hours, 53 minutes, and 48 seconds long. sun height is -12 At 45N 122.5W: In 2016: Spring begins on the March equinox at 2016-03-19 21:29:48 PDT. Sunrise is at 06:07:16 PDT, sunset is at 20:25:33 PDT, and the day is 14 hours, 18 minutes, and 17 seconds long. Summer begins on the June solstice at 2016-06-20 15:33:55 PDT. Sunrise is at 03:54:46 PDT, sunset is at 22:26:23 PDT, and the day is 18 hours, 31 minutes, and 37 seconds long. Fall begins on the September equinox at 2016-09-22 07:20:41 PDT. Sunrise is at 05:53:49 PDT, sunset is at 20:06:52 PDT, and the day is 14 hours, 13 minutes, and 3 seconds long. Winter begins on the December solstice at 2016-12-21 02:44:00 PST. Sunrise is at 06:33:22 PST, sunset is at 17:41:44 PST, and the day is 11 hours, 8 minutes, and 22 seconds long. sun height is -18 At 45N 122.5W: In 2016: Spring begins on the March equinox at 2016-03-19 21:29:48 PDT. Sunrise is at 05:32:02 PDT, sunset is at 21:00:56 PDT, and the day is 15 hours, 28 minutes, and 54 seconds long. Summer begins on the June solstice at 2016-06-20 15:33:55 PDT. Sunrise is at 02:48:34 PDT, sunset is at 23:32:32 PDT, and the day is 20 hours, 43 minutes, and 58 seconds long. Fall begins on the September equinox at 2016-09-22 07:20:41 PDT. Sunrise is at 05:18:36 PDT, sunset is at 20:41:56 PDT, and the day is 15 hours, 23 minutes, and 20 seconds long. Winter begins on the December solstice at 2016-12-21 02:44:00 PST. Sunrise is at 05:57:35 PST, sunset is at 18:17:31 PST, and the day is 12 hours, 19 minutes, and 56 seconds long.

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1172808]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2025-01-17 05:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which URL do you most often use to access this site?












    Results (55 votes). Check out past polls.