Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

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

by haukex (Archbishop)
on Sep 24, 2016 at 11:01 UTC ( [id://1172535]=note: print w/replies, xml ) Need Help??


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

Hi Datz_cozee75,

When did fall begin? Is there only one answer to that question?

A quick reading of Wikipedia leads me to believe that there are plenty of different definitions of the beginnings and ends of the seasons, depending on region and culture. But apparently in North America (aside from the simpler meteorological definitions based on calendar months), it's the March & September equinoxes and the June & December solstices. That also seems to match with your definition, "fall occurs exactly when the sun sets in the west".

how long was the day today?

A bit more research, and CPAN comes to the rescue. First, the output:

At 21.3N 157.816667W: In 2016: Spring begins on the March equinox at 2016-03-19 18:29:48 HST. Sunrise is at 06:32:58 HST, sunset is at 18:40:50 HST, and the day is 12 hours, 7 minutes, and 52 seconds long. Summer begins on the June solstice at 2016-06-20 12:33:55 HST. Sunrise is at 05:48:34 HST, sunset is at 19:14:27 HST, and the day is 13 hours, 25 minutes, and 53 seconds long. Fall begins on the September equinox at 2016-09-22 04:20:41 HST. Sunrise is at 06:18:46 HST, sunset is at 18:24:11 HST, and the day is 12 hours, 5 minutes, and 25 seconds long. Winter begins on the December solstice at 2016-12-21 00:44:00 HST. Sunrise is at 07:03:22 HST, sunset is at 17:53:41 HST, and the day is 10 hours, 50 minutes, and 19 seconds long. In 2017: Spring begins on the March equinox at 2017-03-20 00:28:31 HST. Sunrise is at 06:32:16 HST, sunset is at 18:41:04 HST, and the day is 12 hours, 8 minutes, and 48 seconds long. Summer begins on the June solstice at 2017-06-20 18:23:42 HST. Sunrise is at 05:48:31 HST, sunset is at 19:14:24 HST, and the day is 13 hours, 25 minutes, and 53 seconds long. Fall begins on the September equinox at 2017-09-22 10:01:07 HST. Sunrise is at 06:18:43 HST, sunset is at 18:24:25 HST, and the day is 12 hours, 5 minutes, and 42 seconds long. Winter begins on the December solstice at 2017-12-21 06:27:50 HST. Sunrise is at 07:03:15 HST, sunset is at 17:53:33 HST, and the day is 10 hours, 50 minutes, and 18 seconds long.

And the code:

I know this doesn't address the "as function of space" part of the question, but still, a fun little weekend project :-)

Update: Perhaps Astro::Coord::ECI::Sun could be useful?

Regards,
-- Hauke D

Replies are listed 'Best First'.
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

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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2025-01-17 04: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.