So, I think this is correct:   universal ($start_time_dateobj->epoch()

Yes, I think so too. I may be re-ordering your response, because I don't have time to do a *good* write-up, just a sufficient one.

your link to Astro::Coord::ECI::Sun should be formatted as Astro::Coord::ECI::Sun and not as Astro::Coord::ECI::Sun

Thanks for the tip. How does a person strike out characters, like you did with 'Linux'?

UTC (universal time; I have just learned that its name was born out of perfect delicate diplomatic balance) (equivalent to GMT for the layman)

...imagine that, we settled for Her Majesty at the center of the time world, of the empire on which the sun does not set....

Negative UTC offsets describe a time zone west of UTC±00:00, where the civil time is behind (or earlier) than UTC so the zone designator will look like "−03:00","−0300", or "−03". "+14:00" for Kiribati (UTC+14:00)

This was fascinating. These islands are below Hawaii. (You know, because north is up). We're at minus 7 for PDT (Pacific Daylight Time). What decides when someone's day starts? Is it 12 am local? (Is that a given?)

The startTime you get from the api.weather.gov already contains a timezone. I remember output like 2020-04-26T06:00:00-05:00. Interesting question is what place's that time zone (-05:00) is: the enquiring coordinates or the enquirer's computer location (unlikely). You can deduce that by running a couple of tests for far away locations.

I'm still testing and trying to make sense of what I have. I'm gonna put output and source between readmore tags:

I was able to write more of it in terms Mojo but could not do the whole thing. To manage the amount of data I have to lay eyes on, I added

## sample records probabilistically next unless ( rand() > .95 ); # 1 of every 20

Source:

#!/usr/bin/env perl use strict; use warnings; use DateTime::Format::Strptime; use 5.016; use Log::Log4perl; use Mojo::UserAgent; use open ':std', OUT => ':utf8'; use Mojo::Util qw(dumper); use Astro::Coord::ECI; use Astro::Coord::ECI::Sun; use Astro::Coord::ECI::Utils qw{deg2rad rad2deg}; use Path::Tiny; # get rid of old log my $file = '/home/hogan/Documents/hogan/logs/4.log4perl.txt'; unlink $file or warn "Could not unlink $file: $!"; my $log_conf4 = "/home/hogan/Documents/hogan/logs/conf_files/4.conf"; Log::Log4perl::init($log_conf4); #info my $logger = Log::Log4perl->get_logger(); $logger->info("$0"); ## important...no trailing zeroes else 301 error my $lat = 33.4; my $long = -112.1; my $elev = .346; #km $logger->info("$lat $long $elev"); # Set up observer's location my $loc = Astro::Coord::ECI->geodetic( deg2rad($lat), deg2rad($long), +$elev ); my $url1 = "https://api.weather.gov/points/$lat,$long"; $logger->info("=============="); $logger->info("$url1"); # the API docs says you must identify yourself, please make this somet +hing legit my $name = '(example.com, contact@example.com)'; my $ua = Mojo::UserAgent->new; $ua->transactor->name($name); # get JSON response my $pv = $ua->get($url1)->res->json->{properties}; my $station = $pv->{'cwa'}; my $gridX = $pv->{'gridX'}; my $gridY = $pv->{'gridY'}; $logger->info("$station"); $logger->info("$gridX $gridY"); my $url = "https://api.weather.gov/gridpoints/$station/$gridX,$gridY/forecast/ +hourly"; $logger->info("=============="); $logger->info("$url"); # the API docs says you must identify yourself, please make this somet +hing legit $name = '(example.com, contact@example.com)'; $ua = Mojo::UserAgent->new; $ua->transactor->name($name); # get JSON response my $forecasts = $ua->get($url)->res->json->{properties}->{periods}; use DateTime::Format::Strptime; my $dateparser = DateTime::Format::Strptime->new( # parses 2020-04-26T06:00:00-05:00, # %F then literal T then %T then timezone offset pattern => '%FT%T%z' ) or die "failed to DateTime::Format::Strptime->new()"; my @ordered; my $refordered = \@ordered; my $index = 0; for my $aforecast (@$forecasts) { ## sample records probabilistically next unless ( rand() > .95 ); # 1 of every 20 my $number = $aforecast->{number}; # start and end times of the prediction, convert them to objects my $start_time_str = $aforecast->{'startTime'}; my $start_time_dateobj = $dateparser->parse_datetime($start_time_str +) or die "parsing date '$start_time_str'."; my $jd = $start_time_dateobj->jd; $start_time_dateobj->set_time_zone('America/Los_Angeles'); my $st = $start_time_dateobj->strftime('%Y-%m-%d-%H:%M:%S %Z'); my $hour = $start_time_dateobj->hour_12(); my $which_m = $start_time_dateobj->am_or_pm(); my $abrv = $start_time_dateobj->day_abbr(); # sunny? my $forecast_str = $aforecast->{'shortForecast'}; # temperature as a number, see later for the units my $temp = $aforecast->{'temperature'}; my $cloud_layers = $aforecast->{cloudLayers}; ### using Astro::Coord::ECI::Sun # Instantiate the Sun. my $sun = Astro::Coord::ECI::Sun->universal( $start_time_dateobj->ep +och() ); # Figure out if the Sun is up at the observer's location. my ( $azimuth, $elevation, $range ) = $loc->azel($sun); ### using Your Sky fourmilab my $west_long = -$long; my $pturl = 'http://www.fourmilab.ch/cgi-bin/Yoursky?z=1&lat=$lat&ns=North&lon=$we +st_long&ew=West'; # you wanted Julian date so it looks like date should be '2' from th +e source. my $tx = $ua->post( $pturl => form => { utc => $jd, date => '2' } ); my $sunrow = $tx->res->dom->at('center:nth-of-type(3) table tr:nth-of-type(3)') +; my $alt2 = $sunrow->children->[4]->text; say 'Altitude: ' . $sunrow->children->[4]->text; my $az2 = $sunrow->children->[5]->text; say 'Azimuth: ' . $sunrow->children->[5]->text; my $vis = $sunrow->children->[6]->text; # new scope for hash my %parsed; # store this record/prediction in our %parsed hash # keyed on this: my $key = $start_time_str; $parsed{$key} = { "Sun degrees above horizon" => rad2deg($elevation), 'azimuth' => rad2deg($azimuth), 'human-readable' => "$abrv $hour $which_m", 'cloud layers' => $cloud_layers, 'date-from-local' => $st, 'number' => $number, 'forecast-string' => $forecast_str, 'julian day' => $jd, 'Altitude: ' => $alt2, 'Azimuth: ' => $az2, 'Visible: ' => $vis, # we append temp unit to the key, e.g. 'F' 'forecast-temp-' . $aforecast->{'temperatureUnit'} => $temp, }; my $refparsed = \%parsed; $ordered[$index] = $refparsed; #$logger->info( dumper $refparsed); ++$index; } $logger->info( dumper $refordered); __END__

Sample log:

2020/05/29 18:07:49 INFO ./4.5.pho.pl 2020/05/29 18:07:49 INFO 33.4 -112.1 0.346 2020/05/29 18:07:49 INFO ============== 2020/05/29 18:07:49 INFO https://api.weather.gov/points/33.4,-112.1 2020/05/29 18:07:49 INFO PSR 2020/05/29 18:07:49 INFO 157 55 2020/05/29 18:07:49 INFO ============== 2020/05/29 18:07:49 INFO https://api.weather.gov/gridpoints/PSR/157,55 +/forecast/hourly 2020/05/29 18:07:52 INFO [ { "2020-05-29T21:00:00-07:00" => { "Altitude: " => "\x{2212}17.703", "Azimuth: " => "\x{2212}156.087", "Sun degrees above horizon" => "-16.1346147595787", "Visible: " => "Set", "azimuth" => "310.872811707612", "cloud layers" => undef, "date-from-local" => "2020-05-29-21:00:00 PDT", "forecast-string" => "Mostly Clear", "forecast-temp-F" => 99, "human-readable" => "Fri 9 PM", "julian day" => "2458999.66666667", "number" => 4 } }, { "2020-05-30T18:00:00-07:00" => { "Altitude: " => "\x{2212}17.703", "Azimuth: " => "\x{2212}156.087", "Sun degrees above horizon" => "17.1340319222249", "Visible: " => "Set", "azimuth" => "285.418507531741", "cloud layers" => undef, "date-from-local" => "2020-05-30-18:00:00 PDT", "forecast-string" => "Clear", "forecast-temp-F" => 105, "human-readable" => "Sat 6 PM", "julian day" => "2459000.54166667", "number" => 25 } }, { "2020-06-01T18:00:00-07:00" => { "Altitude: " => "\x{2212}17.703", "Azimuth: " => "\x{2212}156.087", "Sun degrees above horizon" => "17.3283178854741", "Visible: " => "Set", "azimuth" => "285.624647720491", "cloud layers" => undef, "date-from-local" => "2020-06-01-18:00:00 PDT", "forecast-string" => "Partly Cloudy", "forecast-temp-F" => 104, "human-readable" => "Mon 6 PM", "julian day" => "2459002.54166667", "number" => 73 } }, { "2020-06-02T12:00:00-07:00" => { "Altitude: " => "\x{2212}17.701", "Azimuth: " => "\x{2212}156.084", "Sun degrees above horizon" => "77.4732937742126", "Visible: " => "Set", "azimuth" => "150.511216157841", "cloud layers" => undef, "date-from-local" => "2020-06-02-12:00:00 PDT", "forecast-string" => "Mostly Sunny", "forecast-temp-F" => 101, "human-readable" => "Tue 12 PM", "julian day" => "2459003.29166667", "number" => 91 } }, { "2020-06-03T05:00:00-07:00" => { "Altitude: " => "\x{2212}17.701", "Azimuth: " => "\x{2212}156.084", "Sun degrees above horizon" => "-4.30877305256147", "Visible: " => "Set", "azimuth" => "59.5078006913088", "cloud layers" => undef, "date-from-local" => "2020-06-03-05:00:00 PDT", "forecast-string" => "Partly Cloudy", "forecast-temp-F" => 80, "human-readable" => "Wed 5 AM", "julian day" => 2459004, "number" => 108 } }, { "2020-06-03T08:00:00-07:00" => { "Altitude: " => "\x{2212}17.701", "Azimuth: " => "\x{2212}156.084", "Sun degrees above horizon" => "31.0652801390284", "Visible: " => "Set", "azimuth" => "82.1673527295036", "cloud layers" => undef, "date-from-local" => "2020-06-03-08:00:00 PDT", "forecast-string" => "Mostly Sunny", "forecast-temp-F" => 88, "human-readable" => "Wed 8 AM", "julian day" => "2459004.125", "number" => 111 } }, { "2020-06-03T09:00:00-07:00" => { "Altitude: " => "\x{2212}17.701", "Azimuth: " => "\x{2212}156.084", "Sun degrees above horizon" => "43.537502398186", "Visible: " => "Set", "azimuth" => "89.779629384787", "cloud layers" => undef, "date-from-local" => "2020-06-03-09:00:00 PDT", "forecast-string" => "Sunny", "forecast-temp-F" => 92, "human-readable" => "Wed 9 AM", "julian day" => "2459004.16666667", "number" => 112 } }, { "2020-06-03T20:00:00-07:00" => { "Altitude: " => "\x{2212}17.700", "Azimuth: " => "\x{2212}156.080", "Sun degrees above horizon" => "-5.44783053937081", "Visible: " => "Set", "azimuth" => "301.52083115685", "cloud layers" => undef, "date-from-local" => "2020-06-03-20:00:00 PDT", "forecast-string" => "Mostly Clear", "forecast-temp-F" => 96, "human-readable" => "Wed 8 PM", "julian day" => "2459004.625", "number" => 123 } } ]

The thing that is not attaining is that the Altitude and Azimuth values are not changing as $start_time_dateobj does.

Q1) What gives with time values at the end of this script not changing?

[Consider:] my $UTCdateobj = $start_time_dateobj->set_time_zone('UTC');

I did not use this line, and it might be why I don't succeed.

Anyways, thanks for your post, bliako, and your perspective from the world of positive time offsets. We'll be in the high desert this weekend, and you can be sure I'll have a weather report to take some of the guesswork out of it. Occasionally, the "data" can be quite beautiful: pictures of clouds (with data!)


In reply to Re^2: getting Sun info with Astro::Coord::ECI::Sun by Aldebaran
in thread getting Sun info with Astro::Coord::ECI::Sun by Aldebaran

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.