Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: &Astro::MoonPhase::phasehunt argument - number of second since 19700101

by parv (Vicar)
on Oct 13, 2021 at 08:20 UTC ( #11137470=note: print w/replies, xml ) Need Help??


in reply to iterating over time with DateTime to obtain values with Astro::Coords

You should have mentioned "phasehunt" function is from "Astro::MoonPhase" module explicitly for anyone casually following the questions. I found it on a first guess.

phasehunt() is documented to accept ...

... the time, expressed as a time returned by the time function. If $seconds_since_1970 is omitted, it does phasehunt(time).

... does not list argument of DateTime object. So get the epoch from it to pass to &phasehunt. Can't say if that would actually solve any of your issues.

Updated much later. Adjusted code in case anybody else care to run the original logic|algorithm without Log::Log4perl or its configuration not supplied in OP ...

use v5.26; use strict; use feature qw[ signatures ]; no warnings qw[ experimental::signatures + ]; # From https://perlmonks.org/index.pl?node_id=11137457 use Astro::Coords; use Astro::MoonPhase qw[ phasehunt ]; use DateTime; use DateTime::Format::ISO8601; # Not want to divine the configuration file for Log::Log4perl, module +used in # the query. { package Log::Log4perl; sub get_logger( $pkg ) { return bless [], $pkg; } sub show( @arg ) { warn @arg, "\n"; } sub debug( $ignore, @rest ) { show( 'DEBUG: ', @rest ); } sub info( $ignore, @rest ) { show( 'INFO: ', @rest ); } sub warn( $ignore, @rest ) { show( 'WARNING: ', @rest ); } sub error( $ignore, @rest ) { die 'ERROR: ', @rest, "\n"; } } my $logger = Log::Log4perl->get_logger(); my $now = DateTime->now( time_zone => 'UTC' ); $logger->info( "$0 start time: $now" ); # Juilan date: 2459496.96802. my $isostr = '2021-10-09T11:13:57'; my $dt = DateTime::Format::ISO8601->parse_datetime($isostr); show_moon_phases( $dt ); show_moon_venus_travel( $dt, my $show_march = 0 ); my $later = DateTime->now( time_zone => 'UTC' ); my $seconds_dur = $later->subtract_datetime_absolute($now )->in_units( + q[seconds] ); my $mess = sprintf q[program run time: %d s], $seconds_dur; $logger->info( $mess ); exit; sub show_moon_venus_travel( $dt, $show_travel = undef ) { my $moon_coord = Astro::Coords->new( planet => 'Moon' ); my $venus_coord = Astro::Coords->new( planet => 'Venus' ); my $jup_coord = Astro::Coords->new( planet => 'Jupiter' ); # NOTE: Need to get the RA based on time, so $coord->datetime_is_un +safe() is # not called. for ( $moon_coord, $venus_coord, $jup_coord ) { # Observation is location dependent. $_->telescope( 'JCMT' ); } # values make initial while condition true my $moon_ra = 4.15; my $venus_ra = 4.2; my $jup_ra = 7; my $adjust_ra = sub { my ( $dt, $coord ) = @_; $coord->datetime( $dt ); return $coord->ra( 'format' => q[deg] ); }; my @march; while ( $moon_ra < $venus_ra ) { ( $moon_ra, $venus_ra ) = map $adjust_ra->( $dt, $_ ), $moon_coord, $venus_coord; if ( $show_travel ) { my $random = rand(); if ( $random > .99 ) { push @march, sprintf qq[- dt: %s Moon RA: %f Venus RA: % +f], $dt, $moon_ra, $venus_ra ; } } $dt->add( seconds => 1 ); } my $et = $dt->clone->subtract( seconds => 1 ); my @mess = ( q[March of Moon & Venus ...], @march, sprintf( qq[final dt: $dt et: $et Julian equality: % +f], $et->jd() ), sprintf( q[final Moon RA: %f Venus RA: %f], $moon_ra, + $venus_ra ) ); $logger->info( join qq[\n ], @mess ); return; } sub show_moon_phases( $dt ) { my @phases = phasehunt( $dt->epoch() ); my ( $start_epoch, $end_epoch ) = @phases[0,4]; my $diff = $end_epoch - $start_epoch; my $lunation = $diff / ( 24 * 60 * 60 ); my $deg_covered_per_day = 360 / ( $diff / ( 24 * 60 * 60 ) ); my @mess = ( qq[Phasing of the Moon ...], sprintf( "phase epoch: %s", join q[, ], @phases ), sprintf( "integer bottom of first phase: %d", int( $st +art_epoch ) ), sprintf( "lunation: %f days", $lunation ), sprintf( "degrees covered per day: %f", $deg_covered_p +er_day ) ); $logger->info( join qq[\n ], @mess ); return; } __END__ INFO: 11137457-program.pl start time: 2021-10-14T05:55:20 INFO: Phasing of the Moon ... phase epoch: 1633518344.15928, 1634095655.87543, 1634741861.07993, 1 +635451604.37235, 1636060526.50686 integer bottom of first phase: 1633518344 lunation: 29.423407 days degrees covered per day: 12.235157 INFO: March of Moon & Venus ... final dt: 2021-10-09T20:25:47 et: 2021-10-09T20:25:46 Julian equal +ity: 2459497.351227 final Moon RA: 239.630096 Venus RA: 239.630026 INFO: program run time: 59 s

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2022-12-05 12:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?