IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 27619


Ignore:
Timestamp:
Apr 6, 2010, 12:23:59 PM (16 years ago)
Author:
Paul Price
Message:

Rework to allow streak endpoints to be on different chips.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/microtest.pl

    r27612 r27619  
    2020my ($verbose);                             # Verbosity?
    2121my ($save_temps);                          # Save temporary outputs?
    22 my ($clusters_raw, $clusters_ds9, $streaks_ds9);     # Output modes
     22my ($clusters_raw, $clusters_ds9, $streaks_raw, $streaks_ds9);     # Output modes
    2323
    2424GetOptions(
     
    3232    'clusters-raw' => \$clusters_raw,       # Output raw x,y for clusters?
    3333    'clusters-ds9' => \$clusters_ds9, # Output ds9 region files of clusters?
     34    'streaks-raw' => \$streaks_raw,   # Output raw x,y for streaks?
    3435    'streaks-ds9' => \$streaks_ds9,   # Output ds9 region files of streaks?
    3536           'verbose' => \$verbose, # Verbosity?
     
    7980
    8081    # Format the clusters file
    81     open my $clustersFile, "$clusters" or die "Cannot open clusters file $clusters: $!";
     82    open my $clustersInput, "$clusters" or die "Cannot open clusters file $clusters: $!";
    8283    my ($radecFile, $radecName) = tempfile( "/tmp/microtest.XXXX",
    8384                                          UNLINK => !$save_temps, SUFFIX => '.dat' );
    84     my @contents = <$clustersFile>; # Contents of clusters file
     85    my @contents = <$clustersInput>; # Contents of clusters file
    8586    foreach my $line (@contents) {
    8687        $line =~ s/^\s*//;
     
    8990            defined $ra and defined $dec and $ra !~ /[[:alpha:]]/ and $dec !~ /[[:alpha:]]/;
    9091    }
    91     close $clustersFile;
     92    close $clustersInput;
    9293    close $radecFile;
    9394
     
    9697        ) or die "Unable to execute SQL: $DBI::errstr";
    9798
    98     open my $outFile, "> $label.${name}.clusters.xy" or die "Cannot open output file: $!" if defined $clusters_raw;
     99    open my $clustersFile, "> $label.${name}.clusters.xy" or die "Cannot open output file: $!" if defined $clusters_raw;
     100    print $clustersFile "# chip cell x y ra dec\n" if defined $clusters_raw;
     101    my (@streak1, @streak2, $num_streaks);
     102    if (defined $streaks_raw) {
     103        $num_streaks = `head -n 1 $streaks`;
     104        chomp $num_streaks;
     105    }
    99106    foreach my $chip (@$chips) {
    100107        my $class = $chip->{class_id};
     
    117124                my $cellName = $line[6];
    118125
    119                 print $outFile "$chipName $cellName $x $y $ra $dec\n";
     126                print $clustersFile "$chipName $cellName $x $y $ra $dec\n";
    120127            }
    121128        }
     129
     130        if (defined $streaks_raw) {
     131            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     132                run(command => "$ppCoord -astrom $astrom -raw $uri -streaks $streaks -all -radians",
     133                    verbose => $verbose);
     134            die "Unable to run ppCoord" unless $success;
     135
     136            my @lines = split(/\n/, join("", @$stdout_buf));
     137            my $index = 0;
     138            foreach my $line (@lines) {
     139                my @line = split /\s+/, $line;
     140
     141                my $ra1 = $line[0];
     142                my $dec1 = $line[1];
     143                my $ra2 = $line[2];
     144                my $dec2 = $line[3];
     145                my $x1 = $line[5];
     146                my $y1 = $line[6];
     147                my $chipName1 = $line[7];
     148                my $cellName1 = $line[8];
     149                my $x2 = $line[9];
     150                my $y2 = $line[10];
     151                my $chipName2 = $line[11];
     152                my $cellName2 = $line[12];
     153
     154                if ($x1 ne "nan" and $y1 ne "nan") {
     155                    my $streak = $streak1[$index];
     156                    unless (defined $streak) {
     157                        $streak = { 'ra' => $ra1,
     158                                    'dec' => $dec1,
     159                                    'x' => $x1,
     160                                    'y' => $y1,
     161                                    'chip' => $chipName1,
     162                                    'cell' => $cellName1
     163                        };
     164                        $streak1[$index] = $streak;
     165                    }
     166                }
     167                if ($x2 ne "nan" and $y2 ne "nan") {
     168                    my $streak = $streak2[$index];
     169                    unless (defined $streak) {
     170                        $streak = { 'ra' => $ra2,
     171                                    'dec' => $dec2,
     172                                    'x' => $x2,
     173                                    'y' => $y2,
     174                                    'chip' => $chipName2,
     175                                    'cell' => $cellName2
     176                        };
     177                        $streak2[$index] = $streak;
     178                    }
     179                }
     180                $index++;
     181            }
     182        }
     183
    122184
    123185        if (defined $clusters_ds9) {
     
    136198
    137199    }
    138     close $outFile if defined $clusters_raw;
     200    close $clustersFile if defined $clusters_raw;
     201
     202    if (defined $streaks_raw) {
     203        open my $streaksFile, "> $label.${name}.streaks.xy" or die "Cannot open output file: $!";
     204        print $streaksFile "# chip1 cell1 x1 y1 chip2 cell2 x2 y2 ra1 dec1 ra2 dec2\n";
     205        for (my $i = 0; $i < $num_streaks; $i++) {
     206            my $s1 = $streak1[$i];
     207            my $s2 = $streak2[$i];
     208
     209            my $ra1 = $s1->{ra};
     210            my $dec1 = $s1->{dec};
     211            my $ra2 = $s2->{ra};
     212            my $dec2 = $s2->{dec};
     213            my $x1 = $s1->{x};
     214            my $y1 = $s1->{y};
     215            my $chipName1 = $s1->{chip};
     216            my $cellName1 = $s1->{cell};
     217            my $x2 = $s2->{x};
     218            my $y2 = $s2->{y};
     219            my $chipName2 = $s2->{chip};
     220            my $cellName2 = $s2->{cell};
     221
     222            if (defined $ra1 and defined $dec1 and defined $ra2 and defined $dec2 and
     223                defined $x1 and defined $y1 and defined $chipName1 and defined $cellName1 and
     224                defined $x2 and defined $y2 and defined $chipName2 and defined $cellName2) {
     225                print $streaksFile "$chipName1 $cellName1 $x1 $y1 $chipName2 $cellName2 $x2 $y2 $ra1 $dec1 $ra2 $dec2\n";
     226            } else {
     227                print $streaksFile "UNKNOWN UNKNOWN nan nan UNKNOWN UNKNOWN nan nan nan nan nan nan\n";
     228            }
     229        }
     230        close $streaksFile;
     231
     232    }
     233
    139234}
Note: See TracChangeset for help on using the changeset viewer.