| 1 | package Astro::FITS::HdrTrans; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | Astro::FITS::HdrTrans - Translate FITS headers to standardised form | ||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | use Astro::FITS::HdrTrans qw/ translate_from_FITS | ||||||||||||||||||||||||||||||||||||||||||
| 10 | translate_to_FITS /; | ||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | %generic_headers = translate_from_FITS(\%FITS_headers, | ||||||||||||||||||||||||||||||||||||||||||
| 13 | frameset => $frameset); | ||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | %FITS_headers = translate_to_FITS(\%generic_headers); | ||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | @headers = Astro::FITS::HdrTrans->generic_headers(); | ||||||||||||||||||||||||||||||||||||||||||
| 18 | @classes = Astro::FITS::HdrTrans->translation_classes(); | ||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | Converts information contained in instrument-specific FITS headers to | ||||||||||||||||||||||||||||||||||||||||||
| 23 | and from generic headers. A list of generic headers are given at the end | ||||||||||||||||||||||||||||||||||||||||||
| 24 | of the module documentation. | ||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 53 | ▶ | use 5.006; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 53 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 53 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 53 | ▶ | use warnings::register; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 53 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 53 | ▶ | use vars qw/ $VERSION $DEBUG @ISA /; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 53 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 53 | our @EXPORT_OK = qw( translate_from_FITS translate_to_FITS ); | |||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 53 | $VERSION = '1.65'; | |||||||||||||||||||||||||||||||||||||||||
| 40 | 53 | $DEBUG = 0; | |||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | # The reference list of classes we can try This list should be | ||||||||||||||||||||||||||||||||||||||||||
| 43 | # extended whenever new translation tables are added. They should | ||||||||||||||||||||||||||||||||||||||||||
| 44 | # have a corresponding Astro::FITS::HdrTrans:: module available Note | ||||||||||||||||||||||||||||||||||||||||||
| 45 | # that there are more perl modules in the distribution than are listed | ||||||||||||||||||||||||||||||||||||||||||
| 46 | # here. This is because some perl modules provide a base set of | ||||||||||||||||||||||||||||||||||||||||||
| 47 | # translations shared by multiple instruments. | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 53 | my @REF_CLASS_LIST = qw/ ACSIS IRCAM CGS4New CGS4Old UIST UFTI RxH3 | |||||||||||||||||||||||||||||||||||||||||
| 50 | JCMT_GSD JCMT_GSD_DB MICHELLE SCUBA SCUBA2 UKIRTDB WFCAM IRIS2 SOFI | ||||||||||||||||||||||||||||||||||||||||||
| 51 | ISAAC NACO INGRID GMOS SPEX NIRI ClassicCam CURVE LCOSBIG_CC | ||||||||||||||||||||||||||||||||||||||||||
| 52 | LCOSBIG_1m0 LCOSBIG_0m4 LCOSBIG_0m8 LCOSINISTRO_1m0 | ||||||||||||||||||||||||||||||||||||||||||
| 53 | LCOFLOYDS LCOMEROPE LCOSPECTRAL LCOFLI_1m0/; | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | # This is the actual list that is currently supported. It should always | ||||||||||||||||||||||||||||||||||||||||||
| 56 | # default to the reference list | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 53 | my @local_class_list = @REF_CLASS_LIST; | |||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | =head1 CLASS METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | Some class methods are available | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | =item B<generic_headers> | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | Returns a list of all the generic headers that can in principal be | ||||||||||||||||||||||||||||||||||||||||||
| 68 | used for header translation. Note that not all the instruments support | ||||||||||||||||||||||||||||||||||||||||||
| 69 | all the headers. | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | @hdrs = Astro::FITS::HdrTrans->generic_headers(); | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 53 | my @generic_headers = qw( | |||||||||||||||||||||||||||||||||||||||||
| 76 | AIRMASS_START | ||||||||||||||||||||||||||||||||||||||||||
| 77 | AIRMASS_END | ||||||||||||||||||||||||||||||||||||||||||
| 78 | ALTITUDE | ||||||||||||||||||||||||||||||||||||||||||
| 79 | AMBIENT_TEMPERATURE | ||||||||||||||||||||||||||||||||||||||||||
| 80 | AZIMUTH_START | ||||||||||||||||||||||||||||||||||||||||||
| 81 | AZIMUTH_END | ||||||||||||||||||||||||||||||||||||||||||
| 82 | BACKEND | ||||||||||||||||||||||||||||||||||||||||||
| 83 | BACKEND_SECTIONS | ||||||||||||||||||||||||||||||||||||||||||
| 84 | BANDWIDTH_MODE | ||||||||||||||||||||||||||||||||||||||||||
| 85 | BOLOMETERS | ||||||||||||||||||||||||||||||||||||||||||
| 86 | CAMERA | ||||||||||||||||||||||||||||||||||||||||||
| 87 | CAMERA_NUMBER | ||||||||||||||||||||||||||||||||||||||||||
| 88 | CHOP_ANGLE | ||||||||||||||||||||||||||||||||||||||||||
| 89 | CHOP_COORDINATE_SYSTEM | ||||||||||||||||||||||||||||||||||||||||||
| 90 | CHOP_FREQUENCY | ||||||||||||||||||||||||||||||||||||||||||
| 91 | CHOP_THROW | ||||||||||||||||||||||||||||||||||||||||||
| 92 | CONFIGURATION_INDEX | ||||||||||||||||||||||||||||||||||||||||||
| 93 | COORDINATE_SYSTEM | ||||||||||||||||||||||||||||||||||||||||||
| 94 | COORDINATE_UNITS | ||||||||||||||||||||||||||||||||||||||||||
| 95 | COORDINATE_TYPE | ||||||||||||||||||||||||||||||||||||||||||
| 96 | CYCLE_LENGTH | ||||||||||||||||||||||||||||||||||||||||||
| 97 | DATA_UNITS | ||||||||||||||||||||||||||||||||||||||||||
| 98 | DEC_BASE | ||||||||||||||||||||||||||||||||||||||||||
| 99 | DEC_SCALE | ||||||||||||||||||||||||||||||||||||||||||
| 100 | DEC_SCALE_UNITS | ||||||||||||||||||||||||||||||||||||||||||
| 101 | DEC_TELESCOPE_OFFSET | ||||||||||||||||||||||||||||||||||||||||||
| 102 | DETECTOR_BIAS | ||||||||||||||||||||||||||||||||||||||||||
| 103 | DETECTOR_INDEX | ||||||||||||||||||||||||||||||||||||||||||
| 104 | DETECTOR_READ_TYPE | ||||||||||||||||||||||||||||||||||||||||||
| 105 | DOME_OPEN | ||||||||||||||||||||||||||||||||||||||||||
| 106 | DR_GROUP | ||||||||||||||||||||||||||||||||||||||||||
| 107 | DR_RECIPE | ||||||||||||||||||||||||||||||||||||||||||
| 108 | ELEVATION_START | ||||||||||||||||||||||||||||||||||||||||||
| 109 | ELEVATION_END | ||||||||||||||||||||||||||||||||||||||||||
| 110 | EPOCH | ||||||||||||||||||||||||||||||||||||||||||
| 111 | EQUINOX | ||||||||||||||||||||||||||||||||||||||||||
| 112 | EXPOSURE_TIME | ||||||||||||||||||||||||||||||||||||||||||
| 113 | FILE_FORMAT | ||||||||||||||||||||||||||||||||||||||||||
| 114 | FILENAME | ||||||||||||||||||||||||||||||||||||||||||
| 115 | FILTER | ||||||||||||||||||||||||||||||||||||||||||
| 116 | FRONTEND | ||||||||||||||||||||||||||||||||||||||||||
| 117 | FOURIER_TRANSFORM_SPECTROMETER | ||||||||||||||||||||||||||||||||||||||||||
| 118 | GAIN | ||||||||||||||||||||||||||||||||||||||||||
| 119 | GALACTIC_LATITUDE | ||||||||||||||||||||||||||||||||||||||||||
| 120 | GALACTIC_LONGITUDE | ||||||||||||||||||||||||||||||||||||||||||
| 121 | GRATING_DISPERSION | ||||||||||||||||||||||||||||||||||||||||||
| 122 | GRATING_NAME | ||||||||||||||||||||||||||||||||||||||||||
| 123 | GRATING_ORDER | ||||||||||||||||||||||||||||||||||||||||||
| 124 | GRATING_WAVELENGTH | ||||||||||||||||||||||||||||||||||||||||||
| 125 | HUMIDITY | ||||||||||||||||||||||||||||||||||||||||||
| 126 | INSTRUMENT | ||||||||||||||||||||||||||||||||||||||||||
| 127 | INST_DHS | ||||||||||||||||||||||||||||||||||||||||||
| 128 | LATITUDE | ||||||||||||||||||||||||||||||||||||||||||
| 129 | LONGITUDE | ||||||||||||||||||||||||||||||||||||||||||
| 130 | MSBID | ||||||||||||||||||||||||||||||||||||||||||
| 131 | MSB_TRANSACTION_ID | ||||||||||||||||||||||||||||||||||||||||||
| 132 | NSCAN_POSITIONS | ||||||||||||||||||||||||||||||||||||||||||
| 133 | NUMBER_OF_COADDS | ||||||||||||||||||||||||||||||||||||||||||
| 134 | NUMBER_OF_CYCLES | ||||||||||||||||||||||||||||||||||||||||||
| 135 | NUMBER_OF_DETECTORS | ||||||||||||||||||||||||||||||||||||||||||
| 136 | NUMBER_OF_EXPOSURES | ||||||||||||||||||||||||||||||||||||||||||
| 137 | NUMBER_OF_FREQUENCIES | ||||||||||||||||||||||||||||||||||||||||||
| 138 | NUMBER_OF_JITTER_POSITIONS | ||||||||||||||||||||||||||||||||||||||||||
| 139 | NUMBER_OF_MICROSTEP_POSITIONS | ||||||||||||||||||||||||||||||||||||||||||
| 140 | NUMBER_OF_OFFSETS | ||||||||||||||||||||||||||||||||||||||||||
| 141 | NUMBER_OF_READS | ||||||||||||||||||||||||||||||||||||||||||
| 142 | NUMBER_OF_SUBFRAMES | ||||||||||||||||||||||||||||||||||||||||||
| 143 | NUMBER_OF_SUBSCANS | ||||||||||||||||||||||||||||||||||||||||||
| 144 | OBJECT | ||||||||||||||||||||||||||||||||||||||||||
| 145 | OBSERVATION_ID | ||||||||||||||||||||||||||||||||||||||||||
| 146 | OBSERVATION_ID_SUBSYSTEM | ||||||||||||||||||||||||||||||||||||||||||
| 147 | OBSERVATION_MODE | ||||||||||||||||||||||||||||||||||||||||||
| 148 | OBSERVATION_NUMBER | ||||||||||||||||||||||||||||||||||||||||||
| 149 | OBSERVATION_TYPE | ||||||||||||||||||||||||||||||||||||||||||
| 150 | OBSERVED_SIDEBAND | ||||||||||||||||||||||||||||||||||||||||||
| 151 | POLARIMETER | ||||||||||||||||||||||||||||||||||||||||||
| 152 | POLARIMETRY | ||||||||||||||||||||||||||||||||||||||||||
| 153 | PROJECT | ||||||||||||||||||||||||||||||||||||||||||
| 154 | RA_BASE | ||||||||||||||||||||||||||||||||||||||||||
| 155 | RA_SCALE | ||||||||||||||||||||||||||||||||||||||||||
| 156 | RA_SCALE_UNITS | ||||||||||||||||||||||||||||||||||||||||||
| 157 | RA_TELESCOPE_OFFSET | ||||||||||||||||||||||||||||||||||||||||||
| 158 | RECEIVER_TEMPERATURE | ||||||||||||||||||||||||||||||||||||||||||
| 159 | REFERENCE_LOCATION | ||||||||||||||||||||||||||||||||||||||||||
| 160 | REMOTE | ||||||||||||||||||||||||||||||||||||||||||
| 161 | REST_FREQUENCY | ||||||||||||||||||||||||||||||||||||||||||
| 162 | ROTATION | ||||||||||||||||||||||||||||||||||||||||||
| 163 | SAMPLE_MODE | ||||||||||||||||||||||||||||||||||||||||||
| 164 | SAMPLING | ||||||||||||||||||||||||||||||||||||||||||
| 165 | SCAN_INCREMENT | ||||||||||||||||||||||||||||||||||||||||||
| 166 | SCAN_PATTERN | ||||||||||||||||||||||||||||||||||||||||||
| 167 | SEEING | ||||||||||||||||||||||||||||||||||||||||||
| 168 | SHIFT_TYPE | ||||||||||||||||||||||||||||||||||||||||||
| 169 | SIDEBAND_MODE | ||||||||||||||||||||||||||||||||||||||||||
| 170 | SLIT_ANGLE | ||||||||||||||||||||||||||||||||||||||||||
| 171 | SLIT_NAME | ||||||||||||||||||||||||||||||||||||||||||
| 172 | SLIT_WIDTH | ||||||||||||||||||||||||||||||||||||||||||
| 173 | SPECIES | ||||||||||||||||||||||||||||||||||||||||||
| 174 | SPEED_GAIN | ||||||||||||||||||||||||||||||||||||||||||
| 175 | STANDARD | ||||||||||||||||||||||||||||||||||||||||||
| 176 | SUBSYSTEM_IDKEY | ||||||||||||||||||||||||||||||||||||||||||
| 177 | SURVEY | ||||||||||||||||||||||||||||||||||||||||||
| 178 | SWITCH_MODE | ||||||||||||||||||||||||||||||||||||||||||
| 179 | SYSTEM_TEMPERATURE | ||||||||||||||||||||||||||||||||||||||||||
| 180 | SYSTEM_VELOCITY | ||||||||||||||||||||||||||||||||||||||||||
| 181 | TAI_UTC_CORRECTION | ||||||||||||||||||||||||||||||||||||||||||
| 182 | TAU | ||||||||||||||||||||||||||||||||||||||||||
| 183 | TELESCOPE | ||||||||||||||||||||||||||||||||||||||||||
| 184 | TILE_NUMBER | ||||||||||||||||||||||||||||||||||||||||||
| 185 | TRACKING_SIDEBAND | ||||||||||||||||||||||||||||||||||||||||||
| 186 | TRANSITION | ||||||||||||||||||||||||||||||||||||||||||
| 187 | USER_AZIMUTH_CORRECTION | ||||||||||||||||||||||||||||||||||||||||||
| 188 | USER_ELEVATION_CORRECTION | ||||||||||||||||||||||||||||||||||||||||||
| 189 | UTDATE | ||||||||||||||||||||||||||||||||||||||||||
| 190 | UTEND | ||||||||||||||||||||||||||||||||||||||||||
| 191 | UTSTART | ||||||||||||||||||||||||||||||||||||||||||
| 192 | UT1_UTC_CORRECTION | ||||||||||||||||||||||||||||||||||||||||||
| 193 | VELOCITY | ||||||||||||||||||||||||||||||||||||||||||
| 194 | VELOCITY_REFERENCE_FRAME | ||||||||||||||||||||||||||||||||||||||||||
| 195 | VELOCITY_TYPE | ||||||||||||||||||||||||||||||||||||||||||
| 196 | WAVEPLATE_ANGLE | ||||||||||||||||||||||||||||||||||||||||||
| 197 | WIND_BLIND | ||||||||||||||||||||||||||||||||||||||||||
| 198 | XBINNING | ||||||||||||||||||||||||||||||||||||||||||
| 199 | YBINNING | ||||||||||||||||||||||||||||||||||||||||||
| 200 | X_APERTURE | ||||||||||||||||||||||||||||||||||||||||||
| 201 | Y_APERTURE | ||||||||||||||||||||||||||||||||||||||||||
| 202 | X_BASE | ||||||||||||||||||||||||||||||||||||||||||
| 203 | Y_BASE | ||||||||||||||||||||||||||||||||||||||||||
| 204 | X_OFFSET | ||||||||||||||||||||||||||||||||||||||||||
| 205 | Y_OFFSET | ||||||||||||||||||||||||||||||||||||||||||
| 206 | X_REFERENCE_PIXEL | ||||||||||||||||||||||||||||||||||||||||||
| 207 | Y_REFERENCE_PIXEL | ||||||||||||||||||||||||||||||||||||||||||
| 208 | X_REQUESTED | ||||||||||||||||||||||||||||||||||||||||||
| 209 | Y_REQUESTED | ||||||||||||||||||||||||||||||||||||||||||
| 210 | X_SCALE | ||||||||||||||||||||||||||||||||||||||||||
| 211 | Y_SCALE | ||||||||||||||||||||||||||||||||||||||||||
| 212 | X_DIM | ||||||||||||||||||||||||||||||||||||||||||
| 213 | Y_DIM | ||||||||||||||||||||||||||||||||||||||||||
| 214 | X_LOWER_BOUND | ||||||||||||||||||||||||||||||||||||||||||
| 215 | X_UPPER_BOUND | ||||||||||||||||||||||||||||||||||||||||||
| 216 | Y_LOWER_BOUND | ||||||||||||||||||||||||||||||||||||||||||
| 217 | Y_UPPER_BOUND | ||||||||||||||||||||||||||||||||||||||||||
| 218 | ZENITH_DISTANCE_START | ||||||||||||||||||||||||||||||||||||||||||
| 219 | ZENITH_DISTANCE_END | ||||||||||||||||||||||||||||||||||||||||||
| 220 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||
| 222 | sub generic_headers { | ||||||||||||||||||||||||||||||||||||||||||
| 223 | 35 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
generic_headers: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 224 | 35 | return @generic_headers; | |||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||
| 227 | =item B<translation_classes> | ||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | Return the names of all the translation classes that will be | ||||||||||||||||||||||||||||||||||||||||||
| 230 | tried when translating a FITS header. | ||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||
| 232 | @classes = Astro::FITS::HdrTrans->translation_classes(); | ||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||
| 234 | If arguments are supplied, the list of translation classes is | ||||||||||||||||||||||||||||||||||||||||||
| 235 | set to the supplied values. | ||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | Astro::FITS::HdrTrans->translation_classes( @new ); | ||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||
| 239 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||
| 241 | sub translation_classes { | ||||||||||||||||||||||||||||||||||||||||||
| 242 | 36 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
translation_classes: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 243 | 36 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | @local_class_list = @_; | |||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||
| 246 | 36 | return @local_class_list; | |||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||
| 249 | =item B<reset_translation_classes> | ||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||
| 251 | Revert back to the reference list of translation classes. | ||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||
| 253 | Astro::FITS::HdrTrans->reset_translation_classes; | ||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||
| 255 | Useful if the list has been modified for a specific translation. | ||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||
| 257 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||
| 259 | sub reset_classes { | ||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reset_classes: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | @local_class_list = @REF_CLASS_LIST; | |||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||
| 264 | =item B<push_class> | ||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||
| 266 | Allows additional classes to be pushed on the list of valid | ||||||||||||||||||||||||||||||||||||||||||
| 267 | translation classes. | ||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||
| 269 | Astro::FITS::HdrTrans->push_class( $class ); | ||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | The class[es] can be specified either as a list or a reference to | ||||||||||||||||||||||||||||||||||||||||||
| 272 | an array. | ||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||
| 274 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||
| 276 | sub push_class { | ||||||||||||||||||||||||||||||||||||||||||
| 277 | 2 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
push_class: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 278 | 2 | my @new = @_; | |||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||
| 280 | # check for array ref | ||||||||||||||||||||||||||||||||||||||||||
| 281 | 2 | ▶ | @new = ( ref($new[0]) ? @{ $new[0] } : @new ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 282 | 2 | push(@local_class_list, @new); | |||||||||||||||||||||||||||||||||||||||||
| 283 | 2 | return @local_class_list; | |||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||
| 286 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||
| 288 | =head1 FUNCTIONS | ||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||
| 290 | The following functions are available. They can be exported but are | ||||||||||||||||||||||||||||||||||||||||||
| 291 | not exported by default. | ||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||
| 293 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||
| 295 | =item B<translate_from_FITS> | ||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||
| 297 | Converts a hash containing instrument-specific FITS headers into a hash | ||||||||||||||||||||||||||||||||||||||||||
| 298 | containing generic headers. | ||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | %generic_headers = translate_from_FITS(\%FITS_headers, | ||||||||||||||||||||||||||||||||||||||||||
| 301 | class => \@classes, | ||||||||||||||||||||||||||||||||||||||||||
| 302 | prefix => 'ORAC_', | ||||||||||||||||||||||||||||||||||||||||||
| 303 | frameset => $frameset, | ||||||||||||||||||||||||||||||||||||||||||
| 304 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||
| 306 | This method takes a reference to a hash containing untranslated headers, | ||||||||||||||||||||||||||||||||||||||||||
| 307 | and a hash reference containing the following optional keys: | ||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||
| 309 | =over 8 | ||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||
| 311 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||
| 313 | class - A reference to a list of subclasses to try to use for header | ||||||||||||||||||||||||||||||||||||||||||
| 314 | translations. This list overrides the default list. If left blank, the | ||||||||||||||||||||||||||||||||||||||||||
| 315 | default list will be used, as returned by the C<translation_classes> | ||||||||||||||||||||||||||||||||||||||||||
| 316 | method. This is sometimes required to break degeneracy when you know | ||||||||||||||||||||||||||||||||||||||||||
| 317 | you have a limited set of valid instruments. | ||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||
| 319 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||
| 321 | frameset - An AST FrameSet describing the WCS. The WCS in this | ||||||||||||||||||||||||||||||||||||||||||
| 322 | FrameSet will override any WCS information contained in the FITS | ||||||||||||||||||||||||||||||||||||||||||
| 323 | headers. | ||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||
| 325 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||
| 327 | prefix - A string prefix to add to the front of every translated header name. | ||||||||||||||||||||||||||||||||||||||||||
| 328 | For example, if this prefix is set to 'ORAC_', then the translated header | ||||||||||||||||||||||||||||||||||||||||||
| 329 | for the instrument value, whose key is normally 'INSTRUMENT', will have a | ||||||||||||||||||||||||||||||||||||||||||
| 330 | key named 'ORAC_INSTRUMENT'. The original keys will not be in the | ||||||||||||||||||||||||||||||||||||||||||
| 331 | returned hash. If left blank, no prefix will be added. | ||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||
| 333 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||
| 335 | This method returns a hash of generic headers. This function dies if | ||||||||||||||||||||||||||||||||||||||||||
| 336 | the header translation fails in any way. | ||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||
| 338 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||
| 340 | sub translate_from_FITS { | ||||||||||||||||||||||||||||||||||||||||||
| 341 | 20 | ▶ | my $FITS_header = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
translate_from_FITS: called CC=8 SCAR=24.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 342 | 20 | my %options = @_; | |||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||
| 344 | # translation classes | ||||||||||||||||||||||||||||||||||||||||||
| 345 | 20 | my @classes; | |||||||||||||||||||||||||||||||||||||||||
| 346 | 20 | ▶ | if ( exists( $options{class} ) && | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
exists $options{"class"} and defined $options{"class"} and ref $options{"class"} eq "ARRAY"
exists $options{"class"} and defined $options{"class"}
MC/DC0%0/3
exists $options{"class"} and defined $options{"class"} and ref $options{"class"} eq "ARRAY"
exists $options{"class"}
defined $options{"class"}
ref $options{"class"} eq "ARRAY"
Truth table25%1/4
A and B and C
A= exists $options{"class"}B= defined $options{"class"}C= ref $options{"class"} eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||
| 347 | defined( $options{class} ) && | ||||||||||||||||||||||||||||||||||||||||||
| 348 | ref( $options{class} ) eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | @classes = @{$options{class}}; | |||||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||
| 352 | 20 | my $prefix; | |||||||||||||||||||||||||||||||||||||||||
| 353 | 20 | ▶ | if ( exists( $options{prefix} ) && | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $options{"prefix"} and defined $options{"prefix"}
MC/DC50%1/2
exists $options{"prefix"} and defined $options{"prefix"}
exists $options{"prefix"}
defined $options{"prefix"}
Truth table66%2/3
A and B
A= exists $options{"prefix"}B= defined $options{"prefix"}
| |||||||||||||||||||||||||||||||||||||||||||
| 354 | defined( $options{prefix} ) ) { | ||||||||||||||||||||||||||||||||||||||||||
| 355 | 1 | $prefix = $options{prefix}; | |||||||||||||||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||
| 358 | 20 | my $frameset; | |||||||||||||||||||||||||||||||||||||||||
| 359 | 20 | ▶ | if ( exists( $options{frameset} ) && | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $options{"frameset"} and defined $options{"frameset"}
MC/DC0%0/2
exists $options{"frameset"} and defined $options{"frameset"}
exists $options{"frameset"}
defined $options{"frameset"}
Truth table33%1/3
A and B
A= exists $options{"frameset"}B= defined $options{"frameset"}
| |||||||||||||||||||||||||||||||||||||||||||
| 360 | defined( $options{frameset} ) ) { | ||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | $frameset = $options{frameset}; | |||||||||||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||
| 364 | # determine which class can be used for the translation | ||||||||||||||||||||||||||||||||||||||||||
| 365 | 20 | my $class = determine_class( $FITS_header, \@classes, 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||
| 367 | # we know this class is already loaded so do the translation | ||||||||||||||||||||||||||||||||||||||||||
| 368 | 20 | return $class->translate_from_FITS( $FITS_header, | |||||||||||||||||||||||||||||||||||||||||
| 369 | prefix => $prefix, | ||||||||||||||||||||||||||||||||||||||||||
| 370 | frameset => $frameset ); | ||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||
| 374 | =item B<translate_to_FITS> | ||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||
| 376 | Converts a hash containing generic headers into one containing | ||||||||||||||||||||||||||||||||||||||||||
| 377 | instrument-specific FITS headers. | ||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||
| 379 | %FITS_headers = translate_to_FITS(\%generic_headers, | ||||||||||||||||||||||||||||||||||||||||||
| 380 | class => \@classes, | ||||||||||||||||||||||||||||||||||||||||||
| 381 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||
| 383 | This method takes a reference to a hash containing untranslated | ||||||||||||||||||||||||||||||||||||||||||
| 384 | headers, and a hash reference containing the following optional | ||||||||||||||||||||||||||||||||||||||||||
| 385 | keys: | ||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||
| 387 | =over 8 | ||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||
| 389 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||
| 391 | class - A reference to a list of subclasses to try to use for header | ||||||||||||||||||||||||||||||||||||||||||
| 392 | translations. This list overrides the default list. If left blank, the | ||||||||||||||||||||||||||||||||||||||||||
| 393 | default list will be used. | ||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||
| 395 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||
| 397 | prefix - A string prefix to remove from the generic header key | ||||||||||||||||||||||||||||||||||||||||||
| 398 | before doing header translation. Why you would want to do this | ||||||||||||||||||||||||||||||||||||||||||
| 399 | is if you've used a prefix in the C<translate_from_FITS> call, and | ||||||||||||||||||||||||||||||||||||||||||
| 400 | want to translate back from the generic headers returned from | ||||||||||||||||||||||||||||||||||||||||||
| 401 | that method. If left blank, no prefix will be removed. | ||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||
| 403 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||
| 405 | This method returns a hash of instrument-specific headers. This | ||||||||||||||||||||||||||||||||||||||||||
| 406 | function dies if the header translation fails in any way. | ||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||
| 408 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||
| 410 | sub translate_to_FITS { | ||||||||||||||||||||||||||||||||||||||||||
| 411 | 15 | ▶ | my $generic_header = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
translate_to_FITS: called CC=10 SCAR=27.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 412 | 15 | my %options = @_; | |||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||
| 414 | 15 | my @classes; | |||||||||||||||||||||||||||||||||||||||||
| 415 | 15 | ▶ | if ( exists( $options{class} ) && | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
exists $options{"class"} and defined $options{"class"} and ref $options{"class"} eq "ARRAY"
exists $options{"class"} and defined $options{"class"}
MC/DC0%0/3
exists $options{"class"} and defined $options{"class"} and ref $options{"class"} eq "ARRAY"
exists $options{"class"}
defined $options{"class"}
ref $options{"class"} eq "ARRAY"
Truth table25%1/4
A and B and C
A= exists $options{"class"}B= defined $options{"class"}C= ref $options{"class"} eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||
| 416 | defined( $options{class} ) && | ||||||||||||||||||||||||||||||||||||||||||
| 417 | ref( $options{class} ) eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 418 | 0 | @classes = @{$options{class}}; | |||||||||||||||||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||
| 422 | 15 | my $prefix; | |||||||||||||||||||||||||||||||||||||||||
| 423 | 15 | ▶ | if ( exists( $options{prefix} ) && | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $options{"prefix"} and defined $options{"prefix"}
MC/DC50%1/2
exists $options{"prefix"} and defined $options{"prefix"}
exists $options{"prefix"}
defined $options{"prefix"}
Truth table66%2/3
A and B
A= exists $options{"prefix"}B= defined $options{"prefix"}
| |||||||||||||||||||||||||||||||||||||||||||
| 424 | defined( $options{prefix} ) ) { | ||||||||||||||||||||||||||||||||||||||||||
| 425 | 1 | $prefix = $options{prefix}; | |||||||||||||||||||||||||||||||||||||||||
| 426 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 427 | 14 | $prefix = ''; | |||||||||||||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||
| 430 | # We need to strip off any prefix before figuring out what | ||||||||||||||||||||||||||||||||||||||||||
| 431 | # class we need to use. | ||||||||||||||||||||||||||||||||||||||||||
| 432 | 15 | my %stripped_header = clean_prefix( $generic_header, $prefix ); | |||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||
| 434 | # Check the UTSTART and UTEND headers to make sure they're | ||||||||||||||||||||||||||||||||||||||||||
| 435 | # Time::Piece objects. | ||||||||||||||||||||||||||||||||||||||||||
| 436 | 15 | for my $h (qw/ UTSTART UTEND / ) { | |||||||||||||||||||||||||||||||||||||||||
| 437 | 30 | ▶ | if ( exists( $stripped_header{$h} ) && | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
exists $stripped_header{$h} and defined $stripped_header{$h} and not UNIVERSAL::isa($stripped_header{$h}, "Time::Piece")
exists $stripped_header{$h} and defined $stripped_header{$h}
MC/DC0%0/3
exists $stripped_header{$h} and defined $stripped_header{$h} and not UNIVERSAL::isa($stripped_header{$h}, "Time::Piece")
exists $stripped_header{$h}
defined $stripped_header{$h}
not UNIVERSAL::isa($stripped_header{$h}, "Time::Piece")
Truth table25%1/4
A and B and not(C)
A= exists $stripped_header{$h}B= defined $stripped_header{$h}C= not UNIVERSAL::isa($stripped_header{$h}, "Time::Piece")
| |||||||||||||||||||||||||||||||||||||||||||
| 438 | defined( $stripped_header{$h} ) && | ||||||||||||||||||||||||||||||||||||||||||
| 439 | ! UNIVERSAL::isa( $stripped_header{$h}, "Time::Piece" ) ) { | ||||||||||||||||||||||||||||||||||||||||||
| 440 | 0 | warnings::warnif( "Warning: $h generic header is not a Time::Piece object" ); | |||||||||||||||||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||
| 444 | # determine which class can be used for the translation | ||||||||||||||||||||||||||||||||||||||||||
| 445 | 15 | my $class = determine_class( \%stripped_header, \@classes, 0 ); | |||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||
| 447 | 15 | return $class->translate_to_FITS( \%stripped_header ); | |||||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||||||
| 449 | } | ||||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||
| 451 | =item B<determine_class> | ||||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||
| 453 | Determine which class should be used for the translation (either way). | ||||||||||||||||||||||||||||||||||||||||||
| 454 | It is given a reference to the header hash and a reference to an array | ||||||||||||||||||||||||||||||||||||||||||
| 455 | of classes which can be queried. | ||||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||
| 457 | $class = determine_class( \%hdr, \@classes, $fromfits ); | ||||||||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||||||||
| 459 | The classes are loaded for each test. Failure to load indicates failure | ||||||||||||||||||||||||||||||||||||||||||
| 460 | to translate. If the classes are undefined, the default internal list | ||||||||||||||||||||||||||||||||||||||||||
| 461 | will be used. | ||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||
| 463 | The third argument is a boolean indicating whether the class is being | ||||||||||||||||||||||||||||||||||||||||||
| 464 | used to translate from FITS (true) or to FITS (false). This is used | ||||||||||||||||||||||||||||||||||||||||||
| 465 | for error message clarity. | ||||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||
| 467 | This function can be useful to allow a single header translation to be | ||||||||||||||||||||||||||||||||||||||||||
| 468 | calculated without requiring that all translation are performed. For example, | ||||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||
| 470 | $class = Astro::FITS::HdrTrans::determine_class( \%hdr, undef, 1 ); | ||||||||||||||||||||||||||||||||||||||||||
| 471 | $value = $class->to_OBSERVATION_ID( \%hdr, $frameset ); | ||||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||
| 473 | If the key _TRANSLATION_CLASS exists and this class allows translation | ||||||||||||||||||||||||||||||||||||||||||
| 474 | and no override classes have been specified, that class is returned | ||||||||||||||||||||||||||||||||||||||||||
| 475 | without checking all classes. This key is automatically filled in when | ||||||||||||||||||||||||||||||||||||||||||
| 476 | a translation from fits is executed. | ||||||||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||||||
| 478 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||
| 480 | sub determine_class { | ||||||||||||||||||||||||||||||||||||||||||
| 481 | 36 | ▶ | my $hdr = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
determine_class: called CC=19 SCAR=33.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 482 | 36 | my $classes = shift; | |||||||||||||||||||||||||||||||||||||||||
| 483 | 36 | my $fromfits = shift; | |||||||||||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||||||||||||
| 485 | # Default classes if empty or undef | ||||||||||||||||||||||||||||||||||||||||||
| 486 | 36 | my @defclasses = __PACKAGE__->translation_classes; | |||||||||||||||||||||||||||||||||||||||||
| 487 | 36 | ▶ | if (!defined $classes || !@$classes) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $classes and @$classes
MC/DC0%0/2
defined $classes and @$classes
defined $classes
@$classes
Truth table66%2/3
A and B
A= defined $classesB= @$classes
| |||||||||||||||||||||||||||||||||||||||||||
| 488 | # see if we have an override | ||||||||||||||||||||||||||||||||||||||||||
| 489 | 36 | ▶ | if (exists $hdr->{_TRANSLATION_CLASS} && defined $hdr->{_TRANSLATION_CLASS}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $hdr->{"_TRANSLATION_CLASS"} and defined $hdr->{"_TRANSLATION_CLASS"}
MC/DC50%1/2
exists $hdr->{"_TRANSLATION_CLASS"} and defined $hdr->{"_TRANSLATION_CLASS"}
exists $hdr->{"_TRANSLATION_CLASS"}
defined $hdr->{"_TRANSLATION_CLASS"}
Truth table66%2/3
A and B
A= exists $hdr->{"_TRANSLATION_CLASS"}B= defined $hdr->{"_TRANSLATION_CLASS"}
| |||||||||||||||||||||||||||||||||||||||||||
| 490 | 16 | my $class = $hdr->{_TRANSLATION_CLASS}; | |||||||||||||||||||||||||||||||||||||||||
| 491 | 16 | my $loaded = eval "require $class"; | |||||||||||||||||||||||||||||||||||||||||
| 492 | 16 | ▶ | if ($loaded) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 493 | 16 | ▶ | if ($class->can("can_translate") && $class->can_translate($hdr) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$class->can("can_translate") and $class->can_translate($hdr)
MC/DC0%0/2
$class->can("can_translate") and $class->can_translate($hdr)
$class->can("can_translate")
$class->can_translate($hdr)
Truth table33%1/3
A and B
A= $class->can("can_translate")B= $class->can_translate($hdr)
| |||||||||||||||||||||||||||||||||||||||||||
| 494 | 16 | return $class; | |||||||||||||||||||||||||||||||||||||||||
| 495 | } | ||||||||||||||||||||||||||||||||||||||||||
| 496 | } | ||||||||||||||||||||||||||||||||||||||||||
| 497 | } | ||||||||||||||||||||||||||||||||||||||||||
| 498 | # did not have an override so use defaults | ||||||||||||||||||||||||||||||||||||||||||
| 499 | 20 | $classes = \@defclasses; | |||||||||||||||||||||||||||||||||||||||||
| 500 | } | ||||||||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||||||
| 502 | # Determine the class name so we can use the appropriate subclass | ||||||||||||||||||||||||||||||||||||||||||
| 503 | # for header translations. We're going to use the "can_translate" method | ||||||||||||||||||||||||||||||||||||||||||
| 504 | # in each subclass listed in @$classes. | ||||||||||||||||||||||||||||||||||||||||||
| 505 | 20 | my %result = (); | |||||||||||||||||||||||||||||||||||||||||
| 506 | 20 | my $base = "Astro::FITS::HdrTrans::"; | |||||||||||||||||||||||||||||||||||||||||
| 507 | 20 | foreach my $subclass ( @$classes ) { | |||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||
| 509 | 660 | my $class = $base.$subclass; | |||||||||||||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||||||||||||
| 511 | 660 | ▶ | print "Trying class $class\n" if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||||||||||||
| 513 | # Try a class and if it fails to load, skip | ||||||||||||||||||||||||||||||||||||||||||
| 514 | 660 | eval "require $class"; | |||||||||||||||||||||||||||||||||||||||||
| 515 | 660 | ▶ | if ( $@ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 516 | 0 | ▶ | print "Error loading class $class: $@\n" if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 517 | } | ||||||||||||||||||||||||||||||||||||||||||
| 518 | 660 | ▶ | next if ( $@ ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 519 | 660 | ▶ | if ( $class->can("can_translate") ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 520 | 660 | ▶ | if ( $class->can_translate( $hdr ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 521 | 20 | ▶ | print "Class $class matches\n" if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 522 | 20 | $result{$subclass}++; | |||||||||||||||||||||||||||||||||||||||||
| 523 | } | ||||||||||||||||||||||||||||||||||||||||||
| 524 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 525 | # What to do, what to do? | ||||||||||||||||||||||||||||||||||||||||||
| 526 | } | ||||||||||||||||||||||||||||||||||||||||||
| 527 | } | ||||||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||||||
| 529 | 20 | ▶ | if ( ( scalar keys %result ) > 1 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 530 | 0 | croak "Ambiguities in determining which header translations to use (". | |||||||||||||||||||||||||||||||||||||||||
| 531 | join(",",keys %result).")"; | ||||||||||||||||||||||||||||||||||||||||||
| 532 | } | ||||||||||||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||||||||||||
| 534 | 20 | ▶ | if ( ( scalar keys %result ) == 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 535 | # We couldn't figure out which one to use. | ||||||||||||||||||||||||||||||||||||||||||
| 536 | 0 | ▶ | croak "Unable to determine header translation subclass. No matches for these headers when trying to convert " | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 537 | . ($fromfits ? 'from' : 'to' ) | ||||||||||||||||||||||||||||||||||||||||||
| 538 | . " FITS using the following classes: ".join(", ",@$classes); | ||||||||||||||||||||||||||||||||||||||||||
| 539 | } | ||||||||||||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||||||||||||
| 541 | # The class we wanted is the only key in the hash | ||||||||||||||||||||||||||||||||||||||||||
| 542 | 20 | my @matched = keys %result; | |||||||||||||||||||||||||||||||||||||||||
| 543 | 20 | my $class = $base . $matched[0]; | |||||||||||||||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||||||||||||||||
| 545 | 20 | return $class; | |||||||||||||||||||||||||||||||||||||||||
| 546 | } | ||||||||||||||||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||||||||||||||||
| 548 | =item B<clean_prefix> | ||||||||||||||||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||||||||||||||||
| 550 | If a prefix has been used and a targetted conversion is required (which will not understand | ||||||||||||||||||||||||||||||||||||||||||
| 551 | the prefix) the prefix must first be removed. This function will remove the preifx, only | ||||||||||||||||||||||||||||||||||||||||||
| 552 | returning headers that contained the prefix. | ||||||||||||||||||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||||||||||||||||
| 554 | %cleaned = clean_prefix( \%header, $prefix ); | ||||||||||||||||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||||||||||||||||
| 556 | If prefix is an empty string or undefined, returns all headers. | ||||||||||||||||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||||||||||||||||
| 558 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||||||||||||||||
| 560 | sub clean_prefix { | ||||||||||||||||||||||||||||||||||||||||||
| 561 | 16 | ▶ | my $href = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clean_prefix: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 562 | 16 | my $prefix = shift; | |||||||||||||||||||||||||||||||||||||||||
| 563 | 16 | ▶ | return %$href unless $prefix; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||||||||||||||||
| 565 | 2 | my %stripped_header; | |||||||||||||||||||||||||||||||||||||||||
| 566 | 2 | ▶ | while ( my ( $key, $value ) = each( %{$href} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 567 | 40 | ▶ | if ($key eq '_TRANSLATION_CLASS') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 568 | # this should be retained | ||||||||||||||||||||||||||||||||||||||||||
| 569 | 2 | $stripped_header{$key} = $value; | |||||||||||||||||||||||||||||||||||||||||
| 570 | } elsif ($key =~ /^$prefix/) { | ||||||||||||||||||||||||||||||||||||||||||
| 571 | # only propagate keys that contain the prefix | ||||||||||||||||||||||||||||||||||||||||||
| 572 | 36 | $key =~ s/^$prefix//; | |||||||||||||||||||||||||||||||||||||||||
| 573 | 36 | $stripped_header{$key} = $value; | |||||||||||||||||||||||||||||||||||||||||
| 574 | } | ||||||||||||||||||||||||||||||||||||||||||
| 575 | } | ||||||||||||||||||||||||||||||||||||||||||
| 576 | 2 | return %stripped_header; | |||||||||||||||||||||||||||||||||||||||||
| 577 | } | ||||||||||||||||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||||||||||||||||
| 579 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||||||||||||||||
| 581 | =head1 NOTES | ||||||||||||||||||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||||||||||||||||
| 583 | Individual translations can be invoked explicitly if a class name is known. | ||||||||||||||||||||||||||||||||||||||||||
| 584 | The syntax for conversion from a FITS header to generic value is | ||||||||||||||||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||||||||||||||||
| 586 | $result = $class->to_GENERIC_KEYWORD( \%header, $frameset ); | ||||||||||||||||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||||||||||||||||
| 588 | Frameset information (Starlink::AST object) is optional. | ||||||||||||||||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||||||||||||||||
| 590 | The syntax for conversion from generic to FITS headers is: | ||||||||||||||||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||||||||||||||||
| 592 | %fits = $class->from_GENERIC_KEYWORD( \%translated_hdr ); | ||||||||||||||||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||||||||||||||||
| 594 | Note that the conversion to FITS can result in multiple header items | ||||||||||||||||||||||||||||||||||||||||||
| 595 | and can require more than a single generic translated header item. | ||||||||||||||||||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||||||||||||||||
| 597 | If you are using a prefix, the general paradigm for converting a | ||||||||||||||||||||||||||||||||||||||||||
| 598 | translated header back to FITS is: | ||||||||||||||||||||||||||||||||||||||||||
| 599 | |||||||||||||||||||||||||||||||||||||||||||
| 600 | my %cleaned = Astro::FITS::HdrTrans::clean_prefix( \%translated_hdr, $prefix ); | ||||||||||||||||||||||||||||||||||||||||||
| 601 | my $class = Astro::FITS::HdrTrans::determine_class( \%cleaned, undef, 0 ); | ||||||||||||||||||||||||||||||||||||||||||
| 602 | my %fits = $class->from_DR_RECIPE( \%cleaned ); | ||||||||||||||||||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||||||||||||||||
| 605 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||||||||||||||||
| 607 | Brad Cavanagh E<lt>b.cavanagh@jach.hawaii.eduE<gt>, | ||||||||||||||||||||||||||||||||||||||||||
| 608 | Tim Jenness E<lt>t.jenness@jach.hawaii.eduE<gt>, | ||||||||||||||||||||||||||||||||||||||||||
| 609 | Malcolm J. Currie E<lt>mjc@jach.hawaii.eduE<gt> | ||||||||||||||||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||||||||||||||||
| 611 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||||||||||||||||
| 613 | Copyright (C) 2007-2009, 2013 Science and Technology Facilities Council. | ||||||||||||||||||||||||||||||||||||||||||
| 614 | Copyright (C) 2003-2007 Particle Physics and Astronomy Research Council. | ||||||||||||||||||||||||||||||||||||||||||
| 615 | All Rights Reserved. | ||||||||||||||||||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||||||||||||||||
| 617 | This program is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||||||||||||
| 618 | the terms of the GNU General Public License as published by the Free Software | ||||||||||||||||||||||||||||||||||||||||||
| 619 | Foundation; either Version 2 of the License, or (at your option) any later | ||||||||||||||||||||||||||||||||||||||||||
| 620 | version. | ||||||||||||||||||||||||||||||||||||||||||
| 621 | |||||||||||||||||||||||||||||||||||||||||||
| 622 | This program is distributed in the hope that it will be useful, but WITHOUT ANY | ||||||||||||||||||||||||||||||||||||||||||
| 623 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A | ||||||||||||||||||||||||||||||||||||||||||
| 624 | PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||||||||||||||||||||||||||||||||||||||||||
| 625 | |||||||||||||||||||||||||||||||||||||||||||
| 626 | You should have received a copy of the GNU General Public License along with | ||||||||||||||||||||||||||||||||||||||||||
| 627 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple | ||||||||||||||||||||||||||||||||||||||||||
| 628 | Place, Suite 330, Boston, MA 02111-1307, USA. | ||||||||||||||||||||||||||||||||||||||||||
| 629 | |||||||||||||||||||||||||||||||||||||||||||
| 630 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 631 | |||||||||||||||||||||||||||||||||||||||||||
| 632 | 53 | 1; | |||||||||||||||||||||||||||||||||||||||||