| 1 | package Astro::SolarParallax::Observer; | ||
| 2 | |||
| 3 | #use 5.008003; | ||
| 4 | use strict; | ||
| 5 | use warnings; | ||
| 6 | use Math::Trig; | ||
| 7 | use Time::Piece; | ||
| 8 | use Time::Seconds; | ||
| 9 | |||
| 10 | use Carp; | ||
| 11 | |||
| 12 | our $VERSION = '0.01'; | ||
| 13 | |||
| 14 | |||
| 15 | =head1 NAME | ||
| 16 | |||
| 17 | Astro::SolarParallax::Observer - Class for observer data for Solar Parallax measurements | ||
| 18 | |||
| 19 | =head1 SYNOPSIS | ||
| 20 | |||
| 21 | use Astro::SolarParallax::Observer; | ||
| 22 | use Geo::Coordinates; | ||
| 23 | my $obs1 = new Geo::Coordinates; | ||
| 24 | $obs1->latitude(78.20); # Longyearbyen | ||
| 25 | $obs1->longitude(15.82); | ||
| 26 | my $observer1 = Astro::SolarParallax::Observer->new($obs1); | ||
| 27 | # Longyearbyen | ||
| 28 | $observer1->contacttime(1, "07:17:47"); | ||
| 29 | $observer1->contacttime(4, "13:21:00"); | ||
| 30 | |||
| 31 | =head1 DESCRIPTION | ||
| 32 | |||
| 33 | This class is used to set and retrieve data about a single observer of a Transit of Venus. You may use it to set things like the observer's position on Earth and the observed contact times. | ||
| 34 | |||
| 35 | |||
| 36 | =head1 METHODS | ||
| 37 | |||
| 38 | =over | ||
| 39 | |||
| 40 | =item C<new($coords)> | ||
| 41 | |||
| 42 | This is the constructor of this class. | ||
| 43 | |||
| 44 | As you use it to create a new observer, you should set the coordinates of observers, by giving it a L<Geo::Coordinates> object. | ||
| 45 | |||
| 46 | |||
| 47 | =cut | ||
| 48 | |||
| 49 | sub new { | ||
| 50 | my ($that, $coords) = @_; | ||
| 51 | my $class = ref($that) || $that; | ||
| 52 | my $self = { | ||
| 53 | COORDS => $coords, | ||
| 54 | CONTACTS => [] | ||
| 55 | }; | ||
| 56 | bless($self, $class); | ||
| 57 | return $self; | ||
| 58 | } | ||
| 59 | |||
| 60 | |||
| 61 | =item C<contacttime($number, [$time, [$format]])> | ||
| 62 | |||
| 63 | This method is used to set or retrieve the time of a contact. | ||
| 64 | |||
| 65 | The first parameter C<$number> is an integer representing the number of the contact point (first contact, second contact, etc). If only C<$number> is given, the method will return a L<Time::Piece> object with the contact time for this contact. | ||
| 66 | |||
| 67 | To set the time of a contact, supply a second parameter C<$time>. It may be a L<Time::Piece> object (preferred), or just a string. If it is a string, you may supply a third C<$format> parameter, which gives the time format of the string. The time format follows the C<strptime> of your Operating System. It defaults to C<%T>, for example "15:09:23". Internally, the time is represented by a L<Time::Piece> object. | ||
| 68 | |||
| 69 | If you do not supply a full date and timezone, just make sure you're using the same date and timezone. But then, you might want to supply it all, just to be sure... | ||
| 70 | |||
| 71 | =cut | ||
| 72 | |||
| 73 | |||
| 74 | sub contacttime { | ||
| 75 | my ($self, $number, $time, $format) = @_; | ||
| 76 | return ${$self}{'CONTACTS'}[$number] unless defined($time); | ||
| 77 | if (ref($time) eq 'Time::Piece') { | ||
| 78 | ${$self}{'CONTACTS'}[$number] = $time; | ||
| 79 | } else { | ||
| 80 | unless ($format) { | ||
| 81 | $format = '%T'; | ||
| 82 | } | ||
| 83 | ${$self}{'CONTACTS'}[$number] = Time::Piece->strptime($time, $format); | ||
| 84 | } | ||
| 85 | return $self; | ||
| 86 | } | ||
| 87 | |||
| 88 | =item C<deltatobs(@contacts)> | ||
| 89 | |||
| 90 | This computes the observed duration from a contact to the other for this observer, given the number of the contact in the array C<@contacts> as the parameter. In Mignard's paper, Eqs. (79) and (80) are examples of this. | ||
| 91 | |||
| 92 | In the present implementation, only two contacts can be used, and the array should be in ascending order. | ||
| 93 | |||
| 94 | It will return a L<Time::Seconds> object. | ||
| 95 | |||
| 96 | =cut | ||
| 97 | |||
| 98 | sub deltatobs { | ||
| 99 | my $self = shift; | ||
| 100 | my @contacts = @_; | ||
| 101 | unless ($#contacts == 1) | ||
| 102 | { | ||
| 103 | croak "Only exactly two contact points can be used now."; | ||
| 104 | } | ||
| 105 | return ${$self}{'CONTACTS'}[$contacts[1]] - ${$self}{'CONTACTS'}[$contacts[0]]; | ||
| 106 | } | ||
| 107 | |||
| 108 | =item C<deltatref(@contacts)> | ||
| 109 | |||
| 110 | Identical to the C<deltatobs>, except it computes the reference duration. In Mignard's paper, Eqs. (76) and (77) are examples of this. | ||
| 111 | |||
| 112 | At present, only the combination of contacts 1 and 4, and 2 and 3 are supported. | ||
| 113 | |||
| 114 | The following note is of little interest to a user, but a programmer interested in the details of the implementation may note that the constants of Mignard's Table 10 are hardcoded in this method. This is slightly inelegant, and may change if the class is expanded to support more contacts. | ||
| 115 | |||
| 116 | =cut | ||
| 117 | |||
| 118 | |||
| 119 | |||
| 120 | sub deltatref { | ||
| 121 | my $self = shift; | ||
| 122 | my @contacts = @_; | ||
| 123 | unless ($#contacts == 1) | ||
| 124 | { | ||
| 125 | croak "Only exactly two contact points can be used now."; | ||
| 126 | } | ||
| 127 | my ($deltatgeo, $A, $B, $C, $out); | ||
| 128 | if (($contacts[0] == 1) && ($contacts[1] == 4)) { | ||
| 129 | $deltatgeo = Time::Seconds->new(372.4 * 60); | ||
| 130 | $A = Time::Seconds->new(-221.6); | ||
| 131 | $B = Time::Seconds->new(-235.7); | ||
| 132 | $C = Time::Seconds->new(-491.2); | ||
| 133 | } elsif (($contacts[0] == 2) && ($contacts[1] == 3)) { | ||
| 134 | $deltatgeo = Time::Seconds->new(333.85 * 60); | ||
| 135 | $A = Time::Seconds->new(-200.9); | ||
| 136 | $B = Time::Seconds->new(-167.4); | ||
| 137 | $C = Time::Seconds->new(-548.2); | ||
| 138 | } else { | ||
| 139 | croak "Not implemented for the combination of contacts $contacts[0] and ($contacts[1] (in that order)."; | ||
| 140 | } | ||
| 141 | return $deltatgeo + Time::Seconds->new($self->_deltat($A, $B, $C)); | ||
| 142 | } | ||
| 143 | |||
| 144 | # Internal use only, Mignard's Eq. (74): | ||
| 145 | |||
| 146 | sub _deltat | ||
| 147 | { | ||
| 148 | my ($self, $A, $B, $C) = @_; | ||
| 149 | return ($A * cos(deg2rad(${$self}{'COORDS'}->latitude)) | ||
| 150 | * cos(deg2rad(${$self}{'COORDS'}->longitude)) | ||
| 151 | + $B * cos(deg2rad(${$self}{'COORDS'}->latitude)) | ||
| 152 | * sin(deg2rad(${$self}{'COORDS'}->longitude)) | ||
| 153 | + $C * sin(deg2rad(${$self}{'COORDS'}->latitude))) | ||
| 154 | } | ||
| 155 | |||
| 156 | |||
| 157 | 1; | ||
| 158 | __END__ |