IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 24, 2010, 5:17:10 PM (16 years ago)
Author:
Paul Price
Message:

Finished first cut at script to produce chip,cell,x,y for magic clusters.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/microtest.pl

    r27438 r27442  
    1616my ($label);                               # Label of interest
    1717my ($verbose);                             # Verbosity?
     18my ($save_temps);                          # Save temporary outputs?
    1819
    1920GetOptions(
     
    2425           'label=s' => \$label, # Label of interest
    2526           'verbose' => \$verbose, # Verbosity?
     27    'save-temps' => \$save_temps,  # Save temporary outputs?
    2628           ) or die "Unable to parse arguments.\n";
    2729die "Unknown option: @ARGV\n" if @ARGV;
     
    4244# Exposures of interest
    4345my $exps = $db->selectall_arrayref(
    44         "SELECT exp_id, exp_name, magic_id, outroot FROM magicRun JOIN rawExp USING(exp_id) WHERE label = '$label' AND magicRun.state = 'full'",
     46        "SELECT exp_id, exp_name, magic_id, magicRun.outroot AS magic_path, camProcessedExp.path_base AS cam_path FROM magicRun JOIN rawExp USING(exp_id) WHERE label = '$label' AND magicRun.state = 'full'",
    4547        Slice => {}
    4648        ) or die "Unable to execute SQL: $DBI::errstr";
     
    5052    my $name = $exp->{exp_name}; # Exposure name
    5153    my $magic = $exp->{magic_id}; # Magic identifier
    52     my $outroot = $exp->{outroot}; # Output root for magic
     54    my $magic_path = $exp->{magic_path}; # Output root for magic
     55    my $cam_path = $exp->{cam_path}; # Output root for camera
    5356
    54     my $clusters = "$outroot/$id/$id.mgc.$magic.verify/${id}_clusterPos.txt"; # File with cluster RA,Dec
     57    my $clusters = "${magic_path}/$id/$id.mgc.$magic.verify/${id}_clusterPos.txt"; # File with cluster RA,Dec
    5558    die "Cannot find clusters file $clusters" unless -e $clusters;
    5659
    57     my ($tempFile, $tempName) = tempfile( "/tmp/chip.$exp_id.$class_id.deburned.XXXX",
    58                                           UNLINK => !$save_temps, SUFFIX => '.fits' );
     60    my $astrom = "${cam_path}.smf"; # Astrometry file
     61    die "Cannot find astrometry file $astrom" unless -e $astrom;
    5962
    60     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    61         run(command => "$ppCoord  , verbose => $verbose);
     63    # Format the clusters file
     64    open my $clustersFile, "$clusters" or die "Cannot open clusters file $clusters: $!";
     65    my ($radecFile, $radecName) = tempfile( "/tmp/microtest.XXXX",
     66                                          UNLINK => !$save_temps, SUFFIX => '.dat' );
     67    my @contents = <$clustersFile>; # Contents of clusters file
     68    foreach my $line (@contents) {
     69        $line =~ s/^\s*//;
     70        my ($ra, $dec) = split /\s+/, $line;
     71        print $radecFile "$ra $dec\n" if defined $ra and defined $dec and $ra !~ /\w/ and $dec !~ /\w/;
     72    }
     73    close $clustersFile;
     74    close $radecFile;
     75
     76    my $raws = $db->selectcol_arrayref("SELECT uri FROM rawImfile where exp_id = $id") or
     77        die "Unable to execute SQL: $DBI::errstr";
     78
     79    open my $outFile, "${name}_clusters.xy" or die "Cannot open output file: $!";
     80    foreach my $raw (@$raws) {
     81#        my $resolved = `neb-locate --path $raw`; # Resolved filename
     82#        chomp $resolved;
     83        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     84            run(command => "$ppCoord -astrom $astrom -raw $raw -radec $radecName", verbose => $verbose);
     85        die "Unable to run ppCoord" unless $success;
     86
     87        foreach my $line (@$stdout_buf) {
     88            my @line = split /\s+/, $line;
     89
     90            my $ra = $line[0];
     91            my $dec = $line[1];
     92            my $x = $line[3];
     93            my $y = $line[4];
     94            my $chip = $line[5];
     95            my $cell = $line[6];
     96
     97            print $outFile "$chip $cell $x $y $ra $dec\n";
     98        }
     99    }
     100    close $outFile;
     101}
Note: See TracChangeset for help on using the changeset viewer.