Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Re-prototype use of mica stats instead of sybase #257

Closed
wants to merge 14 commits into from
Closed
2 changes: 1 addition & 1 deletion starcheck/calc_ccd_temps.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ def globfile(pathglob):
try:
json_obstemps = get_ccd_temps(**vars(opt))
write_obstemps(opt.output_temps, json_obstemps)
except Exception, msg:
except Exception as msg:
if opt.traceback:
raise
else:
Expand Down
38 changes: 20 additions & 18 deletions starcheck/pcad_att_check.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
import re
import hopper
from astropy.table import Table
import Quaternion

from parse_cm import read_backstop, read_maneuver_summary, read_or_list
from Chandra.Time import DateTime
from astropy.table import Table
import hopper


def check_characteristics_date(ofls_characteristics_file, ref_date=None):
Expand Down Expand Up @@ -67,13 +69,17 @@ def make_pcad_attitude_check_report(backstop_file, or_list_file=None, mm_file=No
lines = [] # output report lines

mm = read_maneuver_summary(mm_file)
q = [mm[0][key] for key in ['q1_0', 'q2_0', 'q3_0', 'q4_0']]
q = Quaternion.normalize([mm[0][key] for key in ['q1_0', 'q2_0', 'q3_0', 'q4_0']])
bs = read_backstop(backstop_file)
simfa_time, simfa = recent_sim_history(DateTime(bs[0]['date']).secs,
simfocus_file)
simpos_time, simpos = recent_sim_history(DateTime(bs[0]['date']).secs,
simtrans_file)
initial_state = {'q_att': q,

initial_state = {'q1': q[0],
'q2': q[1],
'q3': q[2],
'q4': q[3],
'simpos': simpos,
'simfa_pos': simfa}

Expand Down Expand Up @@ -115,22 +121,18 @@ def make_pcad_attitude_check_report(backstop_file, or_list_file=None, mm_file=No
# gives the history of updates as a dict with a `value` and `date` key.
sc = hopper.run_cmds(backstop_file, or_list, ofls_characteristics_file,
initial_state=initial_state)
# Iterate through obsids in order
obsids = [obj['value'] for obj in sc.obsids]
for obsid in obsids:
if obsid not in sc.checks:
continue

checks = sc.checks[obsid]
for check in checks:
if check['name'] == 'CheckObsreqTargetFromPcad':
ok = check['ok']
# Iterate through checks by obsid to print status
checks = sc.get_checks_by_obsid()
for obsid in sc.obsids:
for check in checks[obsid]:
if check.name == 'attitude_consistent_with_obsreq':
ok = check.success
all_ok &= ok
if check.get('skip'):
message = 'SKIPPED: {}'.format(check['message'])
if check.not_applicable:
message = 'SKIPPED: {}'.format(":".join(check.infos))
else:
message = 'OK' if ok else check['message']
line = '{:5d}: {}'.format(obsid, message)
message = 'OK' if ok else "ERROR: {}".format(":".join(check.errors))
line = '{:5d}: {}'.format(obsid, message)
lines.append(line)

if out is not None:
Expand Down
178 changes: 178 additions & 0 deletions starcheck/src/lib/PoorTextFormat.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
package PoorTextFormat;

##***************************************************************************
#
# History:
# 9-May-00 Fixed bug with linked target in 'text'
# Apr-00 Created (TLA)
#
##***************************************************************************

#

use English;

$cmd{latex} = {
list_preamble => '\begin{itemize}',
list_start => '\item',
list_end => '',
list_postamble=> '\end{itemize}',
};

$cmd{text} = {
line_start => '',
line_end => '',
list_start => '',
list_end => '',
item_start => ' * ',
item_end => '',
fixed_start => '',
fixed_end => '',
red_start => '',
red_end => '',
green_start => '',
green_end => '',
yellow_start => '',
yellow_end => '',
link_target_middle => '',
link_target_end => '',
page_break => "====================================================================================\n",
};

$preamble{text} = '';
$postamble{text} = '';

$cmd{html} = {
line_start => '',
line_end => '',
list_start => '<ul>',
list_end => '</ul>',
item_start => '<li>',
item_end => '</li>',
fixed_start => '<pre>',
fixed_end => '</pre>',
red_start => '<font color="#FF0000">',
red_end => '</font>',
blue_start => '<font color="#0000FF">',
blue_end => '</font>',
green_start => '<font color="#00FF00">',
green_end => '</font>',
yellow_start => '<font color="#009900">',
yellow_end => '</font>',
image_start => '<img SRC="',
image_end => '"><br>',
page_break => '<br><hr WIDTH="100%">',
target_start => '<a NAME="',
target_end => '"></a>',
link_target_start => '<a href="',
link_target_middle => '">',
link_target_end => '</a>',
html_start => qq{ },
html_end => qq{ },
};

$preamble{html} = <<'END_HTML_PREAMBLE'
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="Mozilla/4.51 [en] (X11; U; SunOS 5.6 sun4u) [Netscape]">
</head>
<body bgcolor="#FFFFFF">
END_HTML_PREAMBLE
;

$postamble{html} = <<'END_HTML_POSTAMBLE'
</body>
</html>
END_HTML_POSTAMBLE
;

1;

##************************************************************************
sub new {
##************************************************************************
my $classname = shift;
my $self = {};
bless ($self);

return $self;
}

##************************************************************************
sub ptf2any {
##************************************************************************
$self = shift;
$fmt = shift; # Output format
@ptf = split "\n", shift; # Input ptf text to translate

return unless (exists $cmd{$fmt});

$line_start = $cmd{$fmt}->{line_start};
$line_end = $cmd{$fmt}->{line_end};

my $out = $preamble{$fmt};

foreach (@ptf) {
chomp;
if (/\\(\S+{[^}]*})/ || /\\(\S+) ?/) { # There is a PTF command
$ptf_cmd = $1;
my $postmatch = $POSTMATCH;
# print STDERR "PTF_CMD = $ptf_cmd\n";
# print STDERR "postmatch0 = :$POSTMATCH:\n";
$out .= $PREMATCH;
$out .= $cmd{$fmt}->{$ptf_cmd} if (exists $cmd{$fmt}->{$ptf_cmd});

# Command specific special processing
if ($ptf_cmd eq 'list_start') {
$line_start = $cmd{$fmt}->{item_start};
}
if ($ptf_cmd eq 'list_start') {
$line_end = $cmd{$fmt}->{item_end};
}
if ($ptf_cmd eq 'list_end') {
$line_start = $cmd{$fmt}->{line_start};
}
if ($ptf_cmd eq 'list_end') {
$line_end = $cmd{$fmt}->{line_end};
}
if ($ptf_cmd eq 'image') {
if ($cmd{$fmt}->{image_start}) {
$out .= $cmd{$fmt}->{image_start} . $POSTMATCH . $cmd{$fmt}->{image_end} . "\n";
}
next; # Rest of line is ignored
}
if ($ptf_cmd eq 'html') {
if ($cmd{$fmt}->{html_start}) {
$out .= $cmd{$fmt}->{html_start} . $POSTMATCH . $cmd{$fmt}->{html_end} . "\n";
}
next;
}

if ($ptf_cmd =~ /^target\{([^}]*)\}/) {
if ($cmd{$fmt}->{target_start}) {
$out .= $cmd{$fmt}->{target_start} . $1 . $cmd{$fmt}->{target_end};
}
}

if ($ptf_cmd =~ /^link_target\{[^}]*\}/) {
if (exists $cmd{$fmt}->{link_target_end}) {
my ($target, $text) = ($ptf_cmd =~ /\{([^,]+),([^,]+)\}/);
$out .= $cmd{$fmt}->{link_target_start} . $target
if ($cmd{$fmt}->{link_target_start});
$out .= $cmd{$fmt}->{link_target_middle}
. $text
. $cmd{$fmt}->{link_target_end};
}
}

$_ = $postmatch;
redo; # if (/\S/ || $PREMATCH); # Redo only if there is non-trivial stuff left over
} else {
$out .= "$line_start$_$line_end\n";
}
}

$out .= $postamble{$fmt};
}
2 changes: 1 addition & 1 deletion starcheck/src/lib/Ska/Starcheck/Dark_Cal_Checker.pm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use Carp;
use IO::All;
use Ska::Convert qw(date2time time2date);
use Quat;
use Config::General;
use Config::General qw( ParseConfig );
use Math::Trig;
use Data::Dumper;

Expand Down
9 changes: 6 additions & 3 deletions starcheck/src/lib/Ska/Starcheck/FigureOfMerit.pm
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ use Inline Python => q{

from chandra_aca.star_probs import acq_success_prob, prob_n_acq, mag_for_p_acq

def _mag_for_p_acq(p_acq, date, t_ccd):
return mag_for_p_acq(p_acq, date.decode(), t_ccd)

def _acq_success_prob(date, t_ccd, mag, color, spoiler, halfwidth):
out = acq_success_prob(date, float(t_ccd), float(mag), float(color), spoiler, int(halfwidth))
out = acq_success_prob(date.decode(), float(t_ccd), float(mag), float(color), spoiler, int(halfwidth))
return out.tolist()

def _prob_n_acq(acq_probs):
Expand Down Expand Up @@ -89,7 +92,7 @@ sub set_dynamic_mag_limits{
my $t_ccd = $self->{ccd_temp};
# Dynamic mag limits based on 75% and 50% chance of successful star acq
# Maximum limits of 10.3 and 10.6
$self->{mag_faint_yellow} = min(10.3, mag_for_p_acq(0.75, $date, $t_ccd));
$self->{mag_faint_red} = min(10.6, mag_for_p_acq(0.5, $date, $t_ccd));
$self->{mag_faint_yellow} = min(10.3, _mag_for_p_acq(0.75, $date, $t_ccd));
$self->{mag_faint_red} = min(10.6, _mag_for_p_acq(0.5, $date, $t_ccd));
}

Loading