Astro-FITS-HdrTrans
view release on metacpan or search on metacpan
lib/Astro/FITS/HdrTrans/JAC.pm view on Meta::CPAN
use Carp;
use DateTime;
use DateTime::TimeZone;
# Cache UTC definition
our $UTC = DateTime::TimeZone->new( name => 'UTC' );
# Inherit from the Base translation class and not HdrTrans itself
# (which is just a class-less wrapper).
use base qw/ Astro::FITS::HdrTrans::FITS /;
our $VERSION = "1.66";
# in each class we have three sets of data.
# - constant mappings
# - unit mappings
# - complex mappings
# For a constant mapping, there is no FITS header, just a generic
# header that is constant.
my %CONST_MAP = (
);
# Unit mapping implies that the value propagates directly
# to the output with only a keyword name change.
my %UNIT_MAP = (
MSBID => 'MSBID',
MSB_TRANSACTION_ID => 'MSBTID',
SHIFT_TYPE => "OPER_SFT",
);
# Create the translation methods.
__PACKAGE__->_generate_lookup_methods( \%CONST_MAP, \%UNIT_MAP );
=head1 METHODS
=over 4
=item B<translate_from_FITS>
This routine overrides the base class implementation to enable the
caches to be cleared and for the location of the DATE-OBS/DATE-END field to
be found so that base class implementations will work correctly.
This means that some conversion methods (in particular those using time in
a base class) may not work properly outside the context of a full translation
unless they have been subclassed locally.
=cut
sub translate_from_FITS {
my $class = shift;
my $headers = shift;
# sort out DATE-OBS and DATE-END
$class->_fix_dates( $headers );
# Go to the base class
return $class->SUPER::translate_from_FITS( $headers, @_ );
}
=back
=head1 COMPLEX CONVERSIONS
These methods are more complicated than a simple mapping. We have to
provide both from- and to-FITS conversions All these routines are
methods and the to_ routines all take a reference to a hash and return
the translated value (a many-to-one mapping). The from_ methods take
a reference to a generic hash and return a translated hash (sometimes
these are many-to-many).
=over 4
=item B<to_OBSERVATION_ID>
Converts the C<OBSID> header directly into the C<OBSERVATION_ID>
generic header, or if that header does not exist, converts the
C<INSTRUME>, C<RUNNR>, and C<DATE-OBS> headers into C<OBSERVATION_ID>.
The form of the observation ID string is documented in
JSA/ANA/001 (http://docs.jach.hawaii.edu/JCMT/JSA/ANA/001/jsa_ana_001.pdf).
=cut
sub to_OBSERVATION_ID {
my $self = shift;
my $FITS_headers = shift;
my $return;
if ( exists( $FITS_headers->{'OBSID'} ) &&
defined( $FITS_headers->{'OBSID'} ) ) {
$return = $FITS_headers->{'OBSID'};
} else {
my $instrume = $self->to_INSTRUMENT( $FITS_headers );
my $obsnum = $self->to_OBSERVATION_NUMBER( $FITS_headers );
my $dateobs = $self->to_UTSTART( $FITS_headers );
if ( defined $dateobs && defined $obsnum && defined $instrume ) {
my $datetime = $dateobs->datetime;
$datetime =~ s/-//g;
$datetime =~ s/://g;
$return = join '_', (lc $instrume), $obsnum, $datetime;
}
}
return $return;
}
=item B<_fix_dates>
Sort out DATE-OBS and DATE-END in cases where they are not available directly.
This is mainly an issue with database retrievals where the date format is not
FITS compliant.
Astro::FITS::HdrTrans::JAC->_fix_dates( \%headers );
( run in 2.110 seconds using v1.01-cache-2.11-cpan-97f6503c9c8 )