IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 10, 2008, 4:50:01 PM (17 years ago)
Author:
bills
Message:

Handle skycells where the wcs is not in the primary header (compressed
files)

File:
1 edited

Legend:

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

    r20587 r20674  
    5252
    5353pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
    54 pod2usage( -msg => "Required options: --magic_id --warp_id --camera --tess_id --ra --dec --outroot",
     54pod2usage( -msg => "Required options: --magic_id --camera --tess_id --ra --dec --outroot",
    5555           -exitval => 3) unless
    5656    defined $magic_id and
    57     defined $warp_id and
    5857    defined $tess_id and
    5958    defined $ra0 and
     
    7877
    7978### Get a list of warpSkyfiles
     79### This is a workaround to allow processing with older diffSkyfiles that don't have
     80### a wcs. If warp_id is provided, we get the wcs from there
    8081my %warpSkyfiles;                   # hash of warps
    81 {
     82if ($warp_id) {
    8283    my $command = "$warptool -warped -warp_id $warp_id"; # Command to run
    8384    $command .= " -dbname $dbname" if defined $dbname;
     
    121122
    122123    foreach my $input ( @$inputs ) {
    123         push @skycells, $input->{node}; # NB: Storing the skycell_id in magicInputSkyfile.node
     124        push @skycells, $input; # NB: Storing the skycell_id in magicInputSkyfile.node
    124125    }
    125126}
     
    127128### For each skycell, project centre of skycell onto tangent plane of boresight
    128129my @fields;
    129 foreach my $skycell_id ( @skycells ) {
     130foreach my $input ( @skycells ) {
    130131    # the filename method doesn't add the $skycell_id
    131132
     
    137138#    $ipprc->skycell_file($tess_id, $skycell_id, $skyfile, $verbose) or &my_die("Unable to generate skycells $skycell_id", $magic_id, $PS_EXIT_PROG_ERROR);
    138139
    139     my $warp = $warpSkyfiles{$skycell_id};
    140     die "warpSkyfile for $skycell_id not found" if !$warp;
    141     my $skyfileBase = $warp->{path_base};
    142     my $skyfile = $ipprc->filename("SKYCELL.TEMPLATE", $skyfileBase);
     140    my $skyfile;
     141    my $skycell_id = $input->{node};
     142    if ($warp_id) {
     143        # Applying the workaround
     144        my $warp = $warpSkyfiles{$skycell_id};
     145        die "warpSkyfile for $skycell_id not found" if !$warp;
     146        my $skyfileBase = $warp->{path_base};
     147        $skyfile = $ipprc->filename("SKYCELL.TEMPLATE", $skyfileBase);
     148    } else {
     149        # using the diffSkyfile
     150        $skyfile = $input->{uri};
     151    }
    143152    my $skyfileResolved = $ipprc->file_resolve( $skyfile );
    144     my ($header, $status) = Astro::FITS::CFITSIO::fits_read_header( $skyfileResolved );
     153
     154#    my ($header, $status) = Astro::FITS::CFITSIO::fits_read_header( $skyfileResolved );
     155#    &my_die("Unable to read skycell header: $status", $magic_id, $PS_EXIT_SYS_ERROR) if $status;
     156
     157    my ($header, $status) = (undef, 0);
     158    my $fits =  Astro::FITS::CFITSIO::open_file( $skyfileResolved, READONLY, $status );
     159    &my_die("failed to open skycell file: $skyfileResolved: $status", $magic_id, $PS_EXIT_SYS_ERROR) if $status;
     160
     161    ($header, $status) = Astro::FITS::CFITSIO::fits_read_header( $fits );
     162   
    145163    &my_die("Unable to read skycell header: $status", $magic_id, $PS_EXIT_SYS_ERROR) if $status;
    146164
     165
    147166    # Get the useful header keywords
    148     my $naxis1 = $$header{'NAXIS1'} or &my_die("Can't find NAXIS1", $magic_id, $PS_EXIT_SYS_ERROR);
     167#    my $naxis1 = $$header{'NAXIS1'} or &my_die("Can't find NAXIS1", $magic_id, $PS_EXIT_SYS_ERROR);
     168    my $naxis1 = $$header{'NAXIS1'};
     169    if (!$naxis1) {
     170        # XXX: if the skyfile is compressed then the WCS won't be in the primary header
     171        my $hdutype;
     172        $fits->movrel_hdu(1, $hdutype, $status);
     173        &my_die("Unable to movrel_hdu: $status", $magic_id, $PS_EXIT_SYS_ERROR) if $status;
     174
     175        ($header, $status) = Astro::FITS::CFITSIO::fits_read_header( $fits );
     176        &my_die("Unable to read extension header: $status", $magic_id, $PS_EXIT_SYS_ERROR) if $status;
     177        $naxis1 = $$header{'NAXIS1'} or &my_die("Can't find NAXIS1", $magic_id, $PS_EXIT_SYS_ERROR);
     178    }
    149179    my $naxis2 = $$header{'NAXIS2'} or &my_die("Can't find NAXIS2", $magic_id, $PS_EXIT_SYS_ERROR);
    150180    my $ctype1 = $$header{'CTYPE1'} or &my_die("Can't find CTYPE1", $magic_id, $PS_EXIT_SYS_ERROR);
Note: See TracChangeset for help on using the changeset viewer.