IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 28, 2008, 2:06:45 PM (18 years ago)
Author:
bills
Message:

remove reference to obsolete program

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/pstamp/scripts/pstamp_finish.pl

    r19221 r19265  
    99use Pod::Usage qw( pod2usage );
    1010
     11use Time::Local;
    1112use Sys::Hostname;
    1213use IPC::Cmd 0.36 qw( can_run run );
     
    8283    }
    8384
    84 
    85                         # this function is PStamp::RequestFile::read_request_file
     85    if (! -e $req_file ) {
     86        print STDERR "request file $req_file is missing\n";
     87        stop_request($req_id, $PS_EXIT_CONFIG_ERROR, $dbname);
     88        exit  $PS_EXIT_CONFIG_ERROR;
     89    }
     90
     91    # this function is PStamp::RequestFile::read_request_file
    8692    my ($header, $rows) = read_request_file($req_file);
    8793
    88     die "failed to read request_file $req_file" if !$header or !$rows;
     94    if (!$header or !$rows) {
     95        # Since a request got queued, the request file must have been readable at some
     96        # point
     97        print STDERR "failed to read request_file $req_file"
     98        stop_request($req_id, $PS_EXIT_CONFIG_ERROR, $dbname);
     99        exit  $PS_EXIT_CONFIG_ERROR;
     100    }
    89101
    90102    # at this point we need to find out what kind of request type it is and
     
    144156        my $rownum = $job->{rownum};
    145157        my $fault = $job->{fault};
    146 
    147         my $row_info = get_request_info($rows, $rownum);
    148         # rownum fault img_name job_id
     158        my $exp_id = $job->{exp_id};
     159
     160        # XXX: get the image_db from a table in the database, or maybe save it in the job
     161        my $image_db = "ps_simtest";     
     162        my $exp_info = get_exposure_info($image_db, $exp_id);
     163
     164        # unless $exp_id is null (e.g. stack images) get the metadata for this exposure
     165        my ($row, $req_info) = get_request_info($rows, $rownum) if $exp_id;
     166
    149167        if (($job_type eq "stamp") || ($job_type eq "get_image")) {
    150168            my $jreglist = "$out_dir/reglist$job_id";
     
    158176                    my ($img_name, undef) = split '\|', $line;
    159177
    160                     # XXX TODO: need to get these from somewhere. Maybe the stamp.
    161                     #
    162                     # ra_deg and dec_deg are the coordinates of center of the stamp
    163                     # the rest of the metadata come from the original FPA.
    164                     # we could get these out of the rawExp table in the database....
    165                     #
    166                     # Much of those data do not apply to stamps from Stack images.
    167                     my ($ra_deg, $dec_deg, $mjd_obs, $ra_obs, $dec_obs, $filter, $exp_time, $fpa_id) =
    168                         (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
    169 
    170178                    # add line to the table definition file
    171179                    print $tdf "$rownum|$fault|$img_name|$job_id|";
    172                     print $tdf "$ra_deg|$dec_deg|$mjd_obs|$ra_obs|$dec_obs|$filter|$exp_time|$fpa_id|";
    173                     print $tdf "$row_info";
     180
     181                    # ra_deg and dec_deg are the coordinates of center of the stamp
     182                    #
     183                    # XXX  we need to get the center coordinate of the stamp.
     184                    # if request used -skycenter then we have it in the request info
     185
     186                    print $tdf "0.0|0.0|";
     187                    print $tdf "$exp_info|";
     188                    print $tdf "$req_info|";
    174189                    print $tdf "\n";
    175190                }
     
    178193                print STDERR "no reglist file for job $job_id\n" if $verbose;
    179194                print $tdf "$rownum|$fault|0|$job_id|";
    180                 print $tdf "0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|\n";
     195                print $tdf "0|0|";       # center of (non-existent) stamp
     196                print $tdf "$exp_info|";
     197                print $tdf "$req_info|";
    181198            }
    182199        } else {
    183200            # XXX do list jobs
     201            # we can probably arange things to use the code as above and skip the fileset registration
    184202            print STDERR "Unknown jobType: $job_type";
    185203            next;
     
    226244    }
    227245}
     246
    228247sub stop_request {
    229248    my $req_id = shift;
     
    252271    $rowinfo   .= "$row->{ID}|$row->{CLASS_ID}|$row->{OPTION_MASK}|$row->{MJD_MIN}|$row->{MJD_MAX}|";
    253272    $rowinfo   .= "$row->{REQFILT}|$row->{COORD_MASK}|$row->{CENTER_X}|$row->{CENTER_Y}|";
    254     $rowinfo   .= "$row->{WIDTH}|$row->{HEIGHT}|";
    255 
    256     return $rowinfo;
    257 }
     273    $rowinfo   .= "$row->{WIDTH}|$row->{HEIGHT}";
     274
     275    return ($row, $rowinfo);
     276}
     277
     278sub get_exposure_info {
     279    my $image_db= shift;
     280    my $exp_id = shift;
     281
     282    if (!$exp_id) {
     283        # no exposure id just return zeros
     284        # XXX: we could put a value in for filter, but we don't have a good place to find it
     285
     286        #"$mjd_obs|$ra_obs|$dec_obs|$filter|$exp_time|$fpa_id";
     287        return "0|0|0|0|0|0";
     288    }
     289
     290    my $regtool = can_run('regtool') or (warn "Can't find regtool" and $missing_tools = 1);
     291    if ($missing_tools) {
     292        warn("Can't find required tools.");
     293        exit ($PS_EXIT_CONFIG_ERROR);
     294    }
     295
     296    my $command = "$regtool -processedexp -dbname $image_db -exp_id $exp_id";
     297
     298    # run the tool and parse the output
     299    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     300                run(command => $command, verbose => $verbose);
     301    unless ($success) {
     302        # not sure if we should die here
     303        die "cannot get exposure information for $exp_id from image database $image_db";
     304    }
     305    my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
     306
     307    my $output = join "", @$stdout_buf;
     308    if (!$output) {
     309        print STDERR "no output returned from $command\n" if $verbose;
     310        return undef;
     311    }
     312    my $metadata = $mdcParser->parse($output) or die("Unable to parse metdata config doc");
     313
     314    my $exposures = parse_md_list($metadata);
     315    my $numExp = @$exposures;
     316
     317    die "unexpected number of exposures $numExp found for exp_id: $exp_id in DB: $image_db" if $numExp != 1;
     318   
     319    my $exp = $exposures->[0];
     320
     321    #my $info = "$mjd_obs|$ra_obs|$dec_obs|$filter|$exp_time|$fpa_id";
     322
     323    use constant RADIANS_TO_DEGREES => 90. / atan2(1, 0);
     324    my $ra_deg   = $exp->{ra} * RADIANS_TO_DEGREES;
     325    my $decl_deg = $exp->{decl} * RADIANS_TO_DEGREES;
     326    my $mjd_obs = dateobs_to_mjd($exp->{dateobs}, $exp->{exp_time});
     327
     328    my $info = "$mjd_obs|$ra_deg|$decl_deg|$exp->{filter}|$exp->{exp_time}|$exp->{exp_name}";
     329           
     330    return $info;
     331}
     332
     333sub dateobs_to_mjd {
     334    my $dateobs = shift;
     335    my $exp_time = shift;
     336
     337    # dateobs is in format: 1970-01-01T00:00:00
     338
     339    my ($date, $time) = split "T", $dateobs;
     340    my ($year, $mon, $day) = split "-", $date;
     341    my ($hr, $min, $sec) = split ":", $time;
     342
     343    my $ticks = timegm($sec, $min, $hr, $day, $mon-1, $year-1900);
     344
     345    $ticks += $exp_time / 2.0;
     346
     347    return 40587.0 + ($ticks/86400.);
     348}
Note: See TracChangeset for help on using the changeset viewer.