<& /htmlheader, title => ($fpa_id || "$dbname Decider") &>
<& modelheader &>
<% $field_info %>

Histograms

<% $checkboxes %>

Scatter Plots

<% $scatter1 %>
<% $scatter2 %>
<% $scatter3 %>
<% $scatter4 %>

Exposure Name:

SELECT

AS pseudo1,
AS pseudo2,
AS pseudo3
FROM det_rawattr_v2 dr JOIN detections d USING(det_id)
LEFT JOIN tracklet_attrib ta USING(det_id)
LEFT JOIN tracklets t USING(tracklet_id)
LEFT JOIN known k USING(known_id)
WHERE <% $where %>

Stamp limit:

% if (defined($all_aref)) {

Selected | Plots | The Rest
--- | --- | ---
<& stamp_decider, dets => \@sel_stamps, ktbl => \%ktbl, limit => $limit &> | % foreach my $stub (@plot_stubs) { <% $stub %> % } | <& stamp_decider, dets => \@unsel_stamps, ktbl => \%ktbl, limit => $limit &>

% } <& /htmlfooter &> <%args> $fpa_id => undef $det_id => undef $where => '' $limit => 500 $bins => 25 $pseudo1 => undef $pseudo2 => undef $pseudo3 => undef $pseudo1_sql => '' $pseudo2_sql => '' $pseudo3_sql => '' $scatter1_x => '' $scatter1_y => '' $scatter2_x => '' $scatter2_y => '' $scatter3_x => '' $scatter3_y => '' $scatter4_x => '' $scatter4_y => '' <%init> use URI::Escape; use Data::Dumper; use Astro::Time; use PS::MOPS::Lib qw(:all); use PS::MOPS::Constants qw(:all); use PS::MOPS::DC::Field; use PS::MOPS::DC::Detection; my $SQL_STUB = <<"SQL"; SELECT d.det_id det_id FROM det_rawattr_v2 dr JOIN detections d USING(det_id) LEFT JOIN tracklet_attrib ta USING(det_id) LEFT JOIN tracklets t USING(tracklet_id) LEFT JOIN known k USING(known_id) SQL my %cols = ( ); my @extcolnames = qw( mag s2n psf_chi2 psf_dof cr_sig ext_sig psf_major psf_minor psf_theta psf_quality psf_npix moments_xx moments_xy moments_yy n_pos f_pos ratio_bad ratio_mask ratio_all flags ipp_idet psf_inst_flux psf_inst_flux_sig ap_mag ap_mag_raw ap_mag_radius ap_flux ap_flux_sig peak_flux_as_mag cal_psf_mag cal_psf_mag_sig sky sky_sigma psf_qf_perfect moments_r1 moments_rh kron_flux kron_flux_err kron_flux_inner kron_flux_outer diff_r_p diff_sn_p diff_r_m diff_sn_m flags2 n_frames ); my %extcols = ( psf_chi2 => 'float', psf_dof => 'int', cr_sig => 'float', ext_sig => 'float', psf_major => 'float', psf_minor => 'float', psf_theta => 'float', psf_quality => 'float', psf_npix => 'int', moments_xx => 'float', moments_xy => 'float', moments_yy => 'float', n_pos => 'int', f_pos => 'float', ratio_bad => 'float', ratio_mask => 'float', ratio_all => 'float', flags => 'int', ipp_idet => 'int', psf_inst_flux => 'float', psf_inst_flux_sig => 'float', ap_mag => 'float', ap_mag_raw => 'float', ap_mag_radius => 'float', ap_flux => 'float', ap_flux_sig => 'float', peak_flux_as_mag => 'float', cal_psf_mag => 'float', cal_psf_mag_sig => 'float', sky => 'float', sky_sigma => 'float', psf_qf_perfect => 'float', moments_r1 => 'float', moments_rh => 'float', kron_flux => 'float', kron_flux_err => 'float', kron_flux_inner => 'float', kron_flux_outer => 'float', diff_r_p => 'float', diff_sn_p => 'float', diff_r_m => 'float', diff_sn_m => 'float', flags2 => 'int', n_frames => 'int', ); my $inst = $m->notes('INST'); my $dbname = $inst->dbname; my $model = $m->notes('MODEL'); my $dbh = $inst->dbh(); my $sth; my $field; my $field_id; my $field_info = ''; my $all_href; my $all_aref; my $sel_aref; my %sel_tbl; my $sql; my %ktbl; # known table det_id => known_name if ($fpa_id) { $field = modcf_retrieve($inst, fpaId => $fpa_id); $field_info = '' . join("
\n", $field->fpaId, 'Field ID ' . $field->fieldId, sprintf("%.6f", $field->epoch), mopslib_mjd2utctimestr($field->epoch), $field->surveyMode) . "\n"; $field_id = $field->fieldId; } # We will do two queries: one to get all detections from the field, and another # specified by the user to discriminate. We will display two columns of stamps, # one selected for, and all others. if ($field) { my @p; if ($pseudo1_sql) { push @p, "$pseudo1_sql as pseudo1"; } if ($pseudo2_sql) { push @p, "$pseudo2_sql as pseudo2"; } if ($pseudo3_sql) { push @p, "$pseudo3_sql as pseudo3"; } my $pseudo_str = ''; if (@p) { $pseudo_str = ', ' . join(', ', @p); } $sql = <<"SQL"; select d.det_id det_id, d.mag as mag, d.s2n as s2n, k.known_name as known_name, dr.* $pseudo_str from det_rawattr_v2 dr join detections d using(det_id) left join tracklet_attrib ta using(det_id) left join tracklets t using(tracklet_id) left join known k using(known_id) where d.field_id=? SQL $sth = $dbh->prepare($sql) or die $dbh->errstr; $sth->execute($field_id) or die $sql; while (my $href = $sth->fetchrow_hashref) { $all_href->{$href->{det_id}} = $href; # save entire row push @{$all_aref}, $href->{det_id}; $ktbl{$href->{det_id}} = $href->{known_name} if $href->{known_name}; } $sth->finish; } # Beware: we are passing a query directly from a form field. $sql = ''; if ($det_id) { $where = "det_id=$det_id"; } if (defined($all_aref) && $where) { $sql = "$SQL_STUB WHERE d.field_id=$field_id and ($where)"; $sel_aref = $dbh->selectcol_arrayref($sql); # $sel_aref = []; foreach my $sel_id (@{$sel_aref}) { $sel_tbl{$sel_id} = 1; # mark as in selected column } } # Now create Detection lists. my @sel_dets = map { modcd_retrieve($inst, detId => $_) } @{$sel_aref}; my @unsel_dets = map { modcd_retrieve($inst, detId => $_) } grep { !$sel_tbl{$_} } @{$all_aref}; # Truncated lists for stamps only. my @sel_stamps = @sel_dets; #@sel_stamps = @sel_stamps[0..$limit-1]; # if ($limit and scalar @sel_stamps > $limit); my @unsel_stamps = @unsel_dets; #@unsel_stamps = @unsel_stamps[0..$limit-1]; # if ($limit and scalar @unsel_stamps > $limit); # Raw attribute lists. my @sel_raw = map { $all_href->{$_->detId} } @sel_dets; my @unsel_raw = map { $all_href->{$_->detId} } @unsel_dets; sub make_jquery_pairhist_stub { # Create a Javascript JQuery stub for Flot. my ($num, $col, $bins, $det1, $det2) = @_; my $h; my $x0; my $x; my $bw; my $n; my @d; # list of single det column values my @dd; # x,y pairs for Flot my $nd; @d = map { $_->{$col} } @{$det1}; $h = mopslib_histogram(data => \@d, bins => $bins); $bw = $h->{binsize}; $x0 = $h->{min}; $n = 0; @dd = (); $nd = scalar @{$det1} || 1; foreach $x (@{$h->{hist}}) { push @dd, [ $x0 + $n * $bw, $x / $nd]; $n++; } my $d1str = "var d${num}1 = [" . join(',', map {'[' . $_->[0] . ', ' . $_->[1] . ']'} @dd) . '];'; my $bw1 = $bw; my $sel1 = sprintf 'Sel (%d)', scalar @{$det1}; @d = map { $_->{$col} } @{$det2}; $h = mopslib_histogram(data => \@d, bins => $bins); $bw = $h->{binsize}; $x0 = $h->{min}; $n = 0; @dd = (); $nd = scalar @{$det2} || 1; foreach $x (@{$h->{hist}}) { push @dd, [ $x0 + $n * $bw, $x / $nd]; $n++; } my $d2str = "var d${num}2 = [" . join(',', map {'[' . $_->[0] . ', ' . $_->[1] . ']'} @dd) . ']'; my $bw2 = $bw; my $sel2 = sprintf 'Unsel (%d)', scalar @{$det2}; my $stub = <<"STUB";
STUB return $stub; } sub make_jquery_scatter_stub { # Create a Javascript JQuery stub for Flot. my ($num, $xcol, $ycol, $det1, $det2) = @_; my @d; @d = map { [$_->{$xcol}, $_->{$ycol}] } @{$det2}; # list of 2-el arrayrefs my $d2str = "var d${num}2 = [" . join(',', map {'[' . $_->[0] . ', ' . $_->[1] . ']'} @d) . ']'; my $sel2 = sprintf 'Unsel (%d)', scalar @{$det2}; @d = map { [$_->{$xcol}, $_->{$ycol}] } @{$det1}; # list of 2-el arrayrefs my $d1str = "var d${num}1 = [" . join(',', map {'[' . $_->[0] . ', ' . $_->[1] . ']'} @d) . '];'; my $sel1 = sprintf 'Sel (%d)', scalar @{$det1}; my $stub = <<"STUB";
STUB return $stub; } sub make_cb { # mag my ($args, $param) = @_; return sprintf qq{$param}, ($args->{$param} ? ' checked' : ''); } sub make_scatter { # mag my ($cols, $idx, $x, $y) = @_; $x ||= ''; $y ||= ''; my $str1; my $str2; $str1 = qq{Scatter plot ${idx}:
\n}; $str2 = qq{
\n}; return "$str1\n$str2\n"; } my @allcols = (@extcolnames, 'pseudo1', 'pseudo2', 'pseudo3'); my $checkboxes = join("\n", map { make_cb(\%ARGS, $_) } @allcols). "\n"; my $scatter1 = make_scatter(\@allcols, 1, $scatter1_x, $scatter1_y); my $scatter2 = make_scatter(\@allcols, 2, $scatter2_x, $scatter2_y); my $scatter3 = make_scatter(\@allcols, 3, $scatter3_x, $scatter3_y); my $scatter4 = make_scatter(\@allcols, 4, $scatter4_x, $scatter4_y); # Create histogram JQuery stubs. my @plot_stubs; my $istub = 1; #foreach my $v (qw(mag s2n)) { # push @plot_stubs, make_jquery_pairhist_stub($istub++, $v, $bins, \@sel_dets, \@unsel_dets); #} foreach my $v (@extcolnames, qw(pseudo1 pseudo2 pseudo3)) { if ($ARGS{$v}) { push @plot_stubs, make_jquery_pairhist_stub($istub++, $v, $bins, \@sel_raw, \@unsel_raw); } } # Create scatterplot stubs. if ($scatter1_x ne 'N/A' and $scatter1_y ne 'N/A' ) { push @plot_stubs, make_jquery_scatter_stub($istub++, $scatter1_x, $scatter1_y, \@sel_raw, \@unsel_raw); } if ($scatter2_x ne 'N/A' and $scatter2_y ne 'N/A' ) { push @plot_stubs, make_jquery_scatter_stub($istub++, $scatter2_x, $scatter2_y, \@sel_raw, \@unsel_raw); } if ($scatter3_x ne 'N/A' and $scatter3_y ne 'N/A' ) { push @plot_stubs, make_jquery_scatter_stub($istub++, $scatter3_x, $scatter3_y, \@sel_raw, \@unsel_raw); } if ($scatter4_x ne 'N/A' and $scatter4_y ne 'N/A' ) { push @plot_stubs, make_jquery_scatter_stub($istub++, $scatter4_x, $scatter4_y, \@sel_raw, \@unsel_raw); }