IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 17945


Ignore:
Timestamp:
Jun 5, 2008, 12:25:32 PM (18 years ago)
Author:
Paul Price
Message:

Write the header keywords in the header of the table, not the PHU.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippScripts/scripts/ipp_mops_translate.pl

    r17549 r17945  
    1313use constant EXTNAME => 'MOPS_TRANSIENT_DETECTIONS'; # Extension name for output table
    1414use constant POSITION_ERROR => 0.2 / 3600; # Error in positions, degrees
    15 use constant ZERO_POINT => 25;  # Magnitude zero point
    16 use constant MAG_ERROR => 0.1;  # Error in magnitudes
     15use constant ZERO_POINT => 25;  # Magnitude zero point
     16use constant MAG_ERROR => 0.1;  # Error in magnitudes
    1717use constant OBSERVATORY_CODE => 566; # IAU Observatory Code
    18 use constant FAKE_LIMITING_MAG => 23.0; # Fake limiting magnitude to report
     18use constant FAKE_LIMITING_MAG => 23.0; # Fake limiting magnitude to report
    1919use constant FAKE_DETECTION_EFFICIENCY => 0.0; # Fake detection efficiency to report
    2020
    21 my ( $input,                    # Name of input file with IPP photometry
    22      $extname,                  # Name of extension containing photometry
    23      $skycell,                  # Skycell file with WCS
    24      $output,                   # Name of output file
    25      $save_temps,               # Save temporary files?
     21my ( $input,                    # Name of input file with IPP photometry
     22     $extname,                  # Name of extension containing photometry
     23     $skycell,                  # Skycell file with WCS
     24     $output,                   # Name of output file
     25     $save_temps,               # Save temporary files?
    2626     );
    2727
    2828GetOptions(
    29            'input=s'    => \$input,
    30            'extname=s'  => \$extname,
    31            'skycell=s'  => \$skycell,
    32            'output=s'   => \$output,
    33            'save-temps' => \$save_temps,
     29           'input=s'    => \$input,
     30           'extname=s'  => \$extname,
     31           'skycell=s'  => \$skycell,
     32           'output=s'   => \$output,
     33           'save-temps' => \$save_temps,
    3434) or pod2usage( 2 );
    3535
     
    3737pod2usage( -msg => "Required options: --input --extname --skycell --output",
    3838           -exitval => 3)
    39     unless defined $input 
     39    unless defined $input
    4040    and defined $extname
    4141    and defined $skycell
     
    4444# Specification of columns to write
    4545my $columns = [ { name => 'RA_DEG',   type => 'D' }, # Right ascension
    46                 { name => 'DEC_DEG',  type => 'D' }, # Declination
    47                 { name => 'RA_SIG',   type => 'D' }, # Error in right ascension
    48                 { name => 'DEC_SIG',  type => 'D' }, # Error in declination
    49                 { name => 'FLUX',     type => 'D' }, # Flux
    50                 { name => 'FLUX_SIG', type => 'D' }, # Error in flux
    51                 { name => 'ANG',      type => 'D' }, # Angle
    52                 { name => 'ANG_SIG',  type => 'D' }, # Error in angle
    53                 { name => 'LEN',      type => 'D' }, # Length
    54                 { name => 'LEN_SIG',  type => 'D' }, # Error in length
    55                 ];
     46                { name => 'DEC_DEG',  type => 'D' }, # Declination
     47                { name => 'RA_SIG',   type => 'D' }, # Error in right ascension
     48                { name => 'DEC_SIG',  type => 'D' }, # Error in declination
     49                { name => 'FLUX',     type => 'D' }, # Flux
     50                { name => 'FLUX_SIG', type => 'D' }, # Error in flux
     51                { name => 'ANG',      type => 'D' }, # Angle
     52                { name => 'ANG_SIG',  type => 'D' }, # Error in angle
     53                { name => 'LEN',      type => 'D' }, # Length
     54                { name => 'LEN_SIG',  type => 'D' }, # Error in length
     55                ];
    5656
    5757# Header translation table
     
    6666    'FPA.AZ'       => { name => 'TEL_AZ',   type => TDOUBLE, comment => 'Telescope azimuth' },
    6767    'MJD-OBS'      => { name => 'MJD-OBS',  type => TDOUBLE, comment => 'Time of exposure' },
    68             };
     68            };
    6969
    7070
     
    103103check_fitsio($status);
    104104$inFits->movnam_hdu(BINARY_TBL, $extname, 0, $status) and check_fitsio($status);
    105 my $numRows;                    # Number of rows in table
     105my $numRows;                    # Number of rows in table
    106106$inFits->get_num_rows($numRows, $status) and check_fitsio($status);
    107107
    108 my ($xCol, $yCol, $magCol);             # Column numbers for x and y
     108my ($xCol, $yCol, $magCol);             # Column numbers for x and y
    109109$inFits->get_colnum(0, 'X_PSF', $xCol, $status) and check_fitsio($status);
    110110$inFits->get_colnum(0, 'Y_PSF', $yCol, $status) and check_fitsio($status);
    111111$inFits->get_colnum(0, 'PSF_INST_MAG', $magCol, $status) and check_fitsio($status);
    112112
    113 my ($xType, $yType, $magType);  # Column types
     113my ($xType, $yType, $magType);  # Column types
    114114$inFits->get_coltype($xCol, $xType, undef, undef, $status) and check_fitsio($status);
    115115$inFits->get_coltype($yCol, $yType, undef, undef, $status) and check_fitsio($status);
    116116$inFits->get_coltype($magCol, $magType, undef, undef, $status) and check_fitsio($status);
    117117
    118 my ($x, $y, $mag);              # Sources arrays
     118my ($x, $y, $mag);              # Sources arrays
    119119$inFits->read_col($xType, $xCol, 1, 1, $numRows, 0, $x, undef, $status) and check_fitsio($status);
    120120$inFits->read_col($yType, $yCol, 1, 1, $numRows, 0, $y, undef, $status) and check_fitsio($status);
     
    124124
    125125# Parse the list of columns
    126 my @colNames;                   # Names of columns
    127 my @colTypes;                   # Types of columns
    128 my %colData;                    # Data for each column
     126my @colNames;                   # Names of columns
     127my @colTypes;                   # Types of columns
     128my %colData;                    # Data for each column
    129129foreach my $colSpec ( @$columns) {
    130130    push @colNames, $colSpec->{name};
     
    156156check_fitsio( $status );
    157157
    158 # Write the PHU keywords
     158# Write the table
     159$outFits->create_tbl( BINARY_TBL(), $numRows, scalar @colNames, \@colNames, \@colTypes, undef, EXTNAME,
     160                      $status );
     161check_fitsio( $status );
     162
     163# Write the header keywords
    159164$outFits->create_img( 16, 0, undef, $status );
    160165check_fitsio( $status );
     
    162167    my $value = $inHeader->{$keyword}; # Header keyword value
    163168    unless (defined $value) {
    164         print "Can't find header keyword $keyword\n";
    165         next;
     169        print "Can't find header keyword $keyword\n";
     170        next;
    166171    }
    167172    $value =~ s/\'//g;
     
    196201$outFits->write_key( TINT, 'DE10', FAKE_DETECTION_EFFICIENCY, 'Detection efficiency (FAKE)', $status );
    197202
    198 # Write the table
    199 $outFits->create_tbl( BINARY_TBL(), $numRows, scalar @colNames, \@colNames, \@colTypes, undef, EXTNAME,
    200                       $status );
    201 check_fitsio( $status );
     203# Write the data
    202204for (my $i = 0; $i < scalar @colNames; $i++) {
    203205    my $colName = $colNames[$i];# Column name
     
    215217sub check_fitsio
    216218{
    217     my $status = shift;         # Status of FITSIO calls
     219    my $status = shift;         # Status of FITSIO calls
    218220
    219221    if ($status != 0) {
    220         my $msg;                # Message to output
    221         Astro::FITS::CFITSIO::fits_get_errstatus( $status , $msg );
    222         die "CFITSIO error: $msg\n";
     222        my $msg;                # Message to output
     223        Astro::FITS::CFITSIO::fits_get_errstatus( $status , $msg );
     224        die "CFITSIO error: $msg\n";
    223225    }
    224226}
     
    227229sub pixels_to_sky
    228230{
    229     my ($x, $y) = @_;           # Coordinates
     231    my ($x, $y) = @_;           # Coordinates
    230232
    231233    # Pixel coordinate relative to reference
     
    242244    my $phi = atan2($eta,$xi) + pi/2;
    243245    my $theta = atan(180 / pi / sqrt($xi**2 + $eta**2));
    244    
     246
    245247    # Coordinates on celestial sphere
    246248    my $ra = $crval1 + atan2(cos($theta) * sin($phi),
    247                              sin($theta) * cos($crval2) + cos($theta) * sin($crval2) * cos($phi));
     249                             sin($theta) * cos($crval2) + cos($theta) * sin($crval2) * cos($phi));
    248250    my $dec = asin(sin($theta) * sin($crval2) - cos($theta) * cos($crval2) * cos($phi));
    249    
     251
    250252    return (rad2deg($ra), rad2deg($dec));
    251253}
Note: See TracChangeset for help on using the changeset viewer.