diff --git a/Makefile b/Makefile
index c09f9b2d..477a1161 100644
--- a/Makefile
+++ b/Makefile
@@ -7,9 +7,9 @@ SRC = starcheck/src
RELATED_LIB = $(SRC)/StarcheckParser.pm
BIN = $(SRC)/starcheck.pl $(SRC)/starcheck
LIB = $(SRC)/lib/Ska/Starcheck/Obsid.pm \
- $(SRC)/lib/Ska/Starcheck/Dark_Cal_Checker.pm $(SRC)/lib/Ska/Parse_CM_File.pm
+ $(SRC)/lib/Ska/Parse_CM_File.pm
PYTHON_LIB = starcheck/calc_ccd_temps.py starcheck/pcad_att_check.py starcheck/plot.py \
- starcheck/version.py starcheck/__init__.py
+ starcheck/utils.py starcheck/__init__.py
DOC_RST = $(SRC)/aca_load_review_cl.rst
DOC_HTML = aca_load_review_cl.html
@@ -23,7 +23,6 @@ TEST_BACKSTOP = JUL0918A/CR190_0603.backstop
DATA_FILES = starcheck/data/aca_spec.json starcheck/data/ACABadPixels starcheck/data/agasc.bad \
starcheck/data/fid_CHARACTERIS_JUL01 starcheck/data/fid_CHARACTERIS_FEB07 \
starcheck/data/fid_CHARACTERISTICS starcheck/data/characteristics.yaml \
- starcheck/data/A.tlr starcheck/data/B.tlr starcheck/data/tlr.cfg \
starcheck/data/overlib.js starcheck/data/up.gif starcheck/data/down.gif \
SHA_FILES = ${SKA_ARCH_OS}/bin/ska_version $(BIN) $(LIB) \
diff --git a/sandbox_starcheck b/sandbox_starcheck
index 03114591..89b9c04b 100755
--- a/sandbox_starcheck
+++ b/sandbox_starcheck
@@ -14,7 +14,7 @@ then
exit 1
fi
# Check for perl deps
-perl -e "use IO::All; use Time::DayOfYear;"
+perl -e "use IO::All;"
if [[ $? -ne 0 ]];
then
echo "****"
diff --git a/starcheck/data/A.tlr b/starcheck/data/A.tlr
deleted file mode 100644
index 8f7dddef..00000000
--- a/starcheck/data/A.tlr
+++ /dev/null
@@ -1,222 +0,0 @@
- 2000:001:00:00:00.000 AAC1CCSC 34B 60C0
- 350 A000
- 358 0080
- 343 59E0
- 35F 83A0
- 348 3260
- 350 0000
- 2000:001:00:11:30.000 AOFUNCDS 0 803 0203
- 2000:001:00:12:00.000 CIMODESL 0 7C0 6BA0
- 2000:001:00:12:20.000 AAC1CCSC 0 35B 8060
- 34C C000
- 35C 4000
- 354 2700
- 2000:001:00:13:05.000 AAC1CCSC 0 35A 8060
- 34D C000
- 35C 4000
- 354 2700
- 2000:001:00:13:50.000 AAC1CCSC 0 35C 4060
- 34C 3FE0
- 35C 4000
- 354 2700
- 2000:001:00:14:35.000 AAC1CCSC 0 35B 4060
- 34D 3FE0
- 35C 4000
- 354 2700
- 2000:001:00:15:20.000 AAC1CCSC 0 354 6060
- 34C C000
- 35C 4000
- 354 4E00
- 2000:001:00:16:50.000 AAC1CCSC 0 353 6060
- 34D C000
- 35C 4000
- 354 4E00
- 2000:001:00:18:20.000 AAC1CCSC 0 355 2060
- 34C 3FE0
- 35C 4000
- 354 4E00
- 2000:001:00:19:50.000 AAC1CCSC 0 354 2060
- 34D 3FE0
- 35C 4000
- 354 4E00
- 2000:001:00:21:20.000 AAC1CCSC 0 35D 2060
- 34D 3FE0
- 35C 0000
- 354 0580
- 2000:001:00:21:50.000 CIMODESL 0 7C0 63A0
- 2000:001:00:22:20.000 AOFUNCEN 0 803 0303
- 2000:001:00:22:30.000 AOSETINT 0 813 2B01
- 8A3 0001
- A06 A000
- 2000:001:00:54:30.000 AOFUNCDS 1 803 0203
- 2000:001:00:55:00.000 CIMODESL 1 7C0 6BA0
- 2000:001:00:55:20.000 AAC1CCSC 1 35B 0060
- 34C C000
- 35C C000
- 354 2700
- 2000:001:00:56:05.000 AAC1CCSC 1 35A 0060
- 34D C000
- 35C C000
- 354 2700
- 2000:001:00:56:50.000 AAC1CCSC 1 35B C060
- 34C 3FE0
- 35C C000
- 354 2700
- 2000:001:00:57:35.000 AAC1CCSC 1 35A C060
- 34D 3FE0
- 35C C000
- 354 2700
- 2000:001:00:58:20.000 AAC1CCSC 1 353 E060
- 34C C000
- 35C C000
- 354 4E00
- 2000:001:00:59:50.000 AAC1CCSC 1 352 E060
- 34D C000
- 35C C000
- 354 4E00
- 2000:001:01:01:20.000 AAC1CCSC 1 354 A060
- 34C 3FE0
- 35C C000
- 354 4E00
- 2000:001:01:02:50.000 AAC1CCSC 1 353 A060
- 34D 3FE0
- 35C C000
- 354 4E00
- 2000:001:01:04:20.000 AAC1CCSC 1 35C A060
- 34D 3FE0
- 35C 8000
- 354 0580
- 2000:001:01:04:50.000 CIMODESL 1 7C0 63A0
- 2000:001:01:05:20.000 AOFUNCEN 1 803 0303
- 2000:001:01:05:30.000 AOSETINT 1 813 2B01
- 8A3 0001
- A06 A000
- 2000:001:01:37:30.000 AOFUNCDS 2 803 0203
- 2000:001:01:38:00.000 CIMODESL 2 7C0 6BA0
- 2000:001:01:38:20.000 AAC1CCSC 2 35A 8060
- 34C C000
- 35D 4000
- 354 2700
- 2000:001:01:39:05.000 AAC1CCSC 2 359 8060
- 34D C000
- 35D 4000
- 354 2700
- 2000:001:01:39:50.000 AAC1CCSC 2 35B 4060
- 34C 3FE0
- 35D 4000
- 354 2700
- 2000:001:01:40:35.000 AAC1CCSC 2 35A 4060
- 34D 3FE0
- 35D 4000
- 354 2700
- 2000:001:01:41:20.000 AAC1CCSC 2 353 6060
- 34C C000
- 35D 4000
- 354 4E00
- 2000:001:01:42:50.000 AAC1CCSC 2 352 6060
- 34D C000
- 35D 4000
- 354 4E00
- 2000:001:01:44:20.000 AAC1CCSC 2 354 2060
- 34C 3FE0
- 35D 4000
- 354 4E00
- 2000:001:01:45:50.000 AAC1CCSC 2 353 2060
- 34D 3FE0
- 35D 4000
- 354 4E00
- 2000:001:01:47:20.000 AAC1CCSC 2 35C 2060
- 34D 3FE0
- 35D 0000
- 354 0580
- 2000:001:01:47:50.000 CIMODESL 2 7C0 63A0
- 2000:001:01:48:20.000 AOFUNCEN 2 803 0303
- 2000:001:01:48:30.000 AOSETINT 2 813 2B01
- 8A3 0001
- A06 A000
- 2000:001:02:20:30.000 AOFUNCDS 3 803 0203
- 2000:001:02:21:00.000 CIMODESL 3 7C0 6BA0
- 2000:001:02:21:20.000 AAC1CCSC 3 35A 0060
- 34C C000
- 35D C000
- 354 2700
- 2000:001:02:22:05.000 AAC1CCSC 3 359 0060
- 34D C000
- 35D C000
- 354 2700
- 2000:001:02:22:50.000 AAC1CCSC 3 35A C060
- 34C 3FE0
- 35D C000
- 354 2700
- 2000:001:02:23:35.000 AAC1CCSC 3 359 C060
- 34D 3FE0
- 35D C000
- 354 2700
- 2000:001:02:24:20.000 AAC1CCSC 3 352 E060
- 34C C000
- 35D C000
- 354 4E00
- 2000:001:02:25:50.000 AAC1CCSC 3 351 E060
- 34D C000
- 35D C000
- 354 4E00
- 2000:001:02:27:20.000 AAC1CCSC 3 353 A060
- 34C 3FE0
- 35D C000
- 354 4E00
- 2000:001:02:28:50.000 AAC1CCSC 3 352 A060
- 34D 3FE0
- 35D C000
- 354 4E00
- 2000:001:02:30:20.000 AAC1CCSC 3 35B A060
- 34D 3FE0
- 35D 8000
- 354 0580
- 2000:001:02:30:50.000 CIMODESL 3 7C0 63A0
- 2000:001:02:31:20.000 AOFUNCEN 3 803 0303
- 2000:001:02:31:30.000 AOSETINT 3 813 2B01
- 8A3 0001
- A06 A000
- 2000:001:03:03:30.000 AOFUNCDS 4 803 0203
- 2000:001:03:04:00.000 CIMODESL 4 7C0 6BA0
- 2000:001:03:04:20.000 AAC1CCSC 4 359 8060
- 34C C000
- 35E 4000
- 354 2700
- 2000:001:03:05:05.000 AAC1CCSC 4 358 8060
- 34D C000
- 35E 4000
- 354 2700
- 2000:001:03:05:50.000 AAC1CCSC 4 35A 4060
- 34C 3FE0
- 35E 4000
- 354 2700
- 2000:001:03:06:35.000 AAC1CCSC 4 359 4060
- 34D 3FE0
- 35E 4000
- 354 2700
- 2000:001:03:07:20.000 AAC1CCSC 4 352 6060
- 34C C000
- 35E 4000
- 354 4E00
- 2000:001:03:08:50.000 AAC1CCSC 4 351 6060
- 34D C000
- 35E 4000
- 354 4E00
- 2000:001:03:10:20.000 AAC1CCSC 4 353 2060
- 34C 3FE0
- 35E 4000
- 354 4E00
- 2000:001:03:11:50.000 AAC1CCSC 4 352 2060
- 34D 3FE0
- 35E 4000
- 354 4E00
- 2000:001:03:13:20.000 AAC1CCSC 4 35B 2060
- 34D 3FE0
- 35E 0000
- 354 0580
- 2000:001:03:13:50.000 CIMODESL 4 7C0 63A0
- 2000:001:03:14:20.000 AOFUNCEN 4 803 0303
- 2000:001:03:14:30.000 AOSETINT 4 813 2B01
- 8A3 0001
- A06 A000
diff --git a/starcheck/data/B.tlr b/starcheck/data/B.tlr
deleted file mode 100644
index 11d6d3ff..00000000
--- a/starcheck/data/B.tlr
+++ /dev/null
@@ -1,222 +0,0 @@
- 2000:001:00:00:00.000 AAC1CCSC 34B 60C0
- 350 A000
- 358 0080
- 343 59E0
- 35F 83A0
- 348 3260
- 350 0000
- 2000:001:00:11:30.000 AOFUNCDS 0 803 0203
- 2000:001:00:12:00.000 CIMODESL 0 7C0 6FA0
- 2000:001:00:12:20.000 AAC1CCSC 0 35B 8060
- 34C C000
- 35C 4000
- 354 2700
- 2000:001:00:13:05.000 AAC1CCSC 0 35A 8060
- 34D C000
- 35C 4000
- 354 2700
- 2000:001:00:13:50.000 AAC1CCSC 0 35C 4060
- 34C 3FE0
- 35C 4000
- 354 2700
- 2000:001:00:14:35.000 AAC1CCSC 0 35B 4060
- 34D 3FE0
- 35C 4000
- 354 2700
- 2000:001:00:15:20.000 AAC1CCSC 0 354 6060
- 34C C000
- 35C 4000
- 354 4E00
- 2000:001:00:16:50.000 AAC1CCSC 0 353 6060
- 34D C000
- 35C 4000
- 354 4E00
- 2000:001:00:18:20.000 AAC1CCSC 0 355 2060
- 34C 3FE0
- 35C 4000
- 354 4E00
- 2000:001:00:19:50.000 AAC1CCSC 0 354 2060
- 34D 3FE0
- 35C 4000
- 354 4E00
- 2000:001:00:21:20.000 AAC1CCSC 0 35D 2060
- 34D 3FE0
- 35C 0000
- 354 0580
- 2000:001:00:21:50.000 CIMODESL 0 7C0 67A0
- 2000:001:00:22:20.000 AOFUNCEN 0 803 0303
- 2000:001:00:22:30.000 AOSETINT 0 813 2B01
- 8A3 0001
- A06 A000
- 2000:001:00:54:30.000 AOFUNCDS 1 803 0203
- 2000:001:00:55:00.000 CIMODESL 1 7C0 6FA0
- 2000:001:00:55:20.000 AAC1CCSC 1 35B 0060
- 34C C000
- 35C C000
- 354 2700
- 2000:001:00:56:05.000 AAC1CCSC 1 35A 0060
- 34D C000
- 35C C000
- 354 2700
- 2000:001:00:56:50.000 AAC1CCSC 1 35B C060
- 34C 3FE0
- 35C C000
- 354 2700
- 2000:001:00:57:35.000 AAC1CCSC 1 35A C060
- 34D 3FE0
- 35C C000
- 354 2700
- 2000:001:00:58:20.000 AAC1CCSC 1 353 E060
- 34C C000
- 35C C000
- 354 4E00
- 2000:001:00:59:50.000 AAC1CCSC 1 352 E060
- 34D C000
- 35C C000
- 354 4E00
- 2000:001:01:01:20.000 AAC1CCSC 1 354 A060
- 34C 3FE0
- 35C C000
- 354 4E00
- 2000:001:01:02:50.000 AAC1CCSC 1 353 A060
- 34D 3FE0
- 35C C000
- 354 4E00
- 2000:001:01:04:20.000 AAC1CCSC 1 35C A060
- 34D 3FE0
- 35C 8000
- 354 0580
- 2000:001:01:04:50.000 CIMODESL 1 7C0 67A0
- 2000:001:01:05:20.000 AOFUNCEN 1 803 0303
- 2000:001:01:05:30.000 AOSETINT 1 813 2B01
- 8A3 0001
- A06 A000
- 2000:001:01:37:30.000 AOFUNCDS 2 803 0203
- 2000:001:01:38:00.000 CIMODESL 2 7C0 6FA0
- 2000:001:01:38:20.000 AAC1CCSC 2 35A 8060
- 34C C000
- 35D 4000
- 354 2700
- 2000:001:01:39:05.000 AAC1CCSC 2 359 8060
- 34D C000
- 35D 4000
- 354 2700
- 2000:001:01:39:50.000 AAC1CCSC 2 35B 4060
- 34C 3FE0
- 35D 4000
- 354 2700
- 2000:001:01:40:35.000 AAC1CCSC 2 35A 4060
- 34D 3FE0
- 35D 4000
- 354 2700
- 2000:001:01:41:20.000 AAC1CCSC 2 353 6060
- 34C C000
- 35D 4000
- 354 4E00
- 2000:001:01:42:50.000 AAC1CCSC 2 352 6060
- 34D C000
- 35D 4000
- 354 4E00
- 2000:001:01:44:20.000 AAC1CCSC 2 354 2060
- 34C 3FE0
- 35D 4000
- 354 4E00
- 2000:001:01:45:50.000 AAC1CCSC 2 353 2060
- 34D 3FE0
- 35D 4000
- 354 4E00
- 2000:001:01:47:20.000 AAC1CCSC 2 35C 2060
- 34D 3FE0
- 35D 0000
- 354 0580
- 2000:001:01:47:50.000 CIMODESL 2 7C0 67A0
- 2000:001:01:48:20.000 AOFUNCEN 2 803 0303
- 2000:001:01:48:30.000 AOSETINT 2 813 2B01
- 8A3 0001
- A06 A000
- 2000:001:02:20:30.000 AOFUNCDS 3 803 0203
- 2000:001:02:21:00.000 CIMODESL 3 7C0 6FA0
- 2000:001:02:21:20.000 AAC1CCSC 3 35A 0060
- 34C C000
- 35D C000
- 354 2700
- 2000:001:02:22:05.000 AAC1CCSC 3 359 0060
- 34D C000
- 35D C000
- 354 2700
- 2000:001:02:22:50.000 AAC1CCSC 3 35A C060
- 34C 3FE0
- 35D C000
- 354 2700
- 2000:001:02:23:35.000 AAC1CCSC 3 359 C060
- 34D 3FE0
- 35D C000
- 354 2700
- 2000:001:02:24:20.000 AAC1CCSC 3 352 E060
- 34C C000
- 35D C000
- 354 4E00
- 2000:001:02:25:50.000 AAC1CCSC 3 351 E060
- 34D C000
- 35D C000
- 354 4E00
- 2000:001:02:27:20.000 AAC1CCSC 3 353 A060
- 34C 3FE0
- 35D C000
- 354 4E00
- 2000:001:02:28:50.000 AAC1CCSC 3 352 A060
- 34D 3FE0
- 35D C000
- 354 4E00
- 2000:001:02:30:20.000 AAC1CCSC 3 35B A060
- 34D 3FE0
- 35D 8000
- 354 0580
- 2000:001:02:30:50.000 CIMODESL 3 7C0 67A0
- 2000:001:02:31:20.000 AOFUNCEN 3 803 0303
- 2000:001:02:31:30.000 AOSETINT 3 813 2B01
- 8A3 0001
- A06 A000
- 2000:001:03:03:30.000 AOFUNCDS 4 803 0203
- 2000:001:03:04:00.000 CIMODESL 4 7C0 6FA0
- 2000:001:03:04:20.000 AAC1CCSC 4 359 8060
- 34C C000
- 35E 4000
- 354 2700
- 2000:001:03:05:05.000 AAC1CCSC 4 358 8060
- 34D C000
- 35E 4000
- 354 2700
- 2000:001:03:05:50.000 AAC1CCSC 4 35A 4060
- 34C 3FE0
- 35E 4000
- 354 2700
- 2000:001:03:06:35.000 AAC1CCSC 4 359 4060
- 34D 3FE0
- 35E 4000
- 354 2700
- 2000:001:03:07:20.000 AAC1CCSC 4 352 6060
- 34C C000
- 35E 4000
- 354 4E00
- 2000:001:03:08:50.000 AAC1CCSC 4 351 6060
- 34D C000
- 35E 4000
- 354 4E00
- 2000:001:03:10:20.000 AAC1CCSC 4 353 2060
- 34C 3FE0
- 35E 4000
- 354 4E00
- 2000:001:03:11:50.000 AAC1CCSC 4 352 2060
- 34D 3FE0
- 35E 4000
- 354 4E00
- 2000:001:03:13:20.000 AAC1CCSC 4 35B 2060
- 34D 3FE0
- 35E 0000
- 354 0580
- 2000:001:03:13:50.000 CIMODESL 4 7C0 67A0
- 2000:001:03:14:20.000 AOFUNCEN 4 803 0303
- 2000:001:03:14:30.000 AOSETINT 4 813 2B01
- 8A3 0001
- A06 A000
diff --git a/starcheck/data/tlr.cfg b/starcheck/data/tlr.cfg
deleted file mode 100644
index 0bb1da81..00000000
--- a/starcheck/data/tlr.cfg
+++ /dev/null
@@ -1,231 +0,0 @@
-# Config file for ACA Dark Cal Checker
-# Presently used by DarkCalChecker.pm
-
-# Designed for use for Config::General.pm
-
-# First section specifies the format of the TLR file
-# Here's the "header" from within the file
-
-
-# _____________________ ________ ______________ _ ____________________________________ ________ ______________ ________ ___ ________
-#| GMT | Orbit | Command |C| Command | Command| Trace | OBC |OBC|SCS|Step|
-#| (extended) | /DSN | Mnemonic |r| Description | Data | ID | Clock |ID | |
-#| | Event | |t| | (Hex) | | | | |
-#|_____________________|________|______________|_|____________________________________|________|______________|________|___|________|
-# 2005:311:06:14:17.003 COSATDLY NA//NA//-2//0 97C 80AF 16548015 A 130| 1
-
-# Format of the TLR where start and stop specify the range of text
-# columns of the field
-
-
" . $out . "" ; - return $html; - } - - return $out; -} - -##*************************************************************************** -sub transponder_timing{ -##*************************************************************************** - my $self = shift; - my $trans = ''; - my $text = "For dark current operations, transponder should be set to:\n"; - for my $t (0 .. 4){ - if ($trans ne $self->{"tnc_replica_$t"}->{'transponder'}){ - $trans = $self->{"tnc_replica_$t"}->{'transponder'}; - $text .= "Transponder " . $trans; - if ($t > 0){ - $text .= "\tafter " . $self->{'tlr'}->end_replica($t-1)->datestamp() . "\n\t"; - } - $text .= "\tbefore " . $self->{'tlr'}->begin_replica($t)->datestamp() . "\n"; - if ($self->{"trans_replica_$t"}->{status} == 1){ - $text .= "\t\t(Commanding already included in Loads)\n"; - } - else{ - $text .= "\t\tRequires real time commanding\n"; - } - } - } - - return $text; -} - -##*************************************************************************** -sub is_ok{ -##*************************************************************************** - my $check = shift; - my $red_font_start = qq{}; - my $font_stop = qq{}; - if ($check){ - return "ok"; - } - else{ - return "${red_font_start}NO${font_stop}"; - } -} - - - -##*************************************************************************** -sub format_dark_cal_check{ -# Run check controls the printing of all information passed back from the -# checking subroutines -##*************************************************************************** - - my $self = shift; - my $check_name = shift; - # if anything left, use the options, else set defaults - my $opt = 1 == @_ ? pop @_ : { 'criteria' => 0, 'verbose' => 0, 'html_standalone' => 0 }; - - my $feedback = $self->{$check_name}; - - my $red_font_start = qq{}; - my $yellow_font_start = qq{}; - my $blue_font_start = qq{}; - my $font_stop = qq{}; - - my $return_string; - - if ($opt->{criteria}){ - # add a ref to get here from the starcheck page - $return_string .= "\n"; - } - - $return_string .= "[" . is_ok($feedback->{status}). "]\t"; - - if (!$opt->{criteria} & !$opt->{verbose} & !$opt->{html_standalone} & defined $opt->{link_to}){ - $return_string .= "{link_to}#$check_name\">"; - } - - $return_string .= $feedback->{comment}[0] . "\n"; - - if (!$opt->{criteria} & !$opt->{verbose} & !$opt->{html_standalone} & defined $opt->{link_to}){ - $return_string .= ""; - } - - # if verbose or there's an error - if ($opt->{criteria}){ - for my $line (@{$feedback->{criteria}}){ - $return_string .= "$blue_font_start $line${font_stop}\n"; - } - } - if ($opt->{verbose}){ - for my $entry (@{$feedback->{info}}){ - my $line = $entry->{text}; - my $type = $entry->{type}; - if ($type eq 'info'){ - $return_string .= " \t$line \n"; - } - if ($type eq 'error'){ - $return_string .= "${red_font_start} --->>> $line${font_stop}\n"; - } - if ($type eq 'warn'){ - $return_string .= "${yellow_font_start} --->>> $line${font_stop}\n"; - } - } - - } - - return $return_string; - -} - - - - - -package TLR; - -use strict; -use warnings; -use IO::All; -use Data::Dumper; -use Carp; - - -##*************************************************************************** -sub new { -##*************************************************************************** - my ($class, $file, $type, $config) = @_; - my @tlr_lines = io($file)->slurp; - my @tlr_entries; - my $self; - $self->{n_entries} = 0; - $self->{entries} = []; - - bless $self, $class; - - if ($type eq 'tlr'){ - @tlr_entries = get_tlr_array(\@tlr_lines, $config, $self); - } - if ($type eq 'template'){ - @tlr_entries = get_templ_array(\@tlr_lines, $config, $self); - } - - for my $entry (@tlr_entries){ - $self->add_entry($entry); - } - - - return $self; - -} - -##*************************************************************************** -sub add_entry{ -##*************************************************************************** - my $self = shift; - my $entry = shift; - $entry->set_index($self->{n_entries}); - $self->{n_entries}++; - push @{$self->{entries}}, $entry; - return 1; -} - - -##*************************************************************************** -sub first_aca_hw_cmd{ -##*************************************************************************** - my $self = shift; - return $self->{first_aca_hw_cmd} if (defined $self->{first_aca_hw_cmd}); - - for my $entry (@{$self->{entries}}){ - if (defined $entry->{comm_mnem}){ - if ($entry->{comm_mnem} eq 'AAC1CCSC'){ - $self->{first_aca_hw_cmd} = $entry; - last; - } - } - } - - croak("No ACA commanding found.") unless defined $self->{first_aca_hw_cmd}; - - - return $self->{first_aca_hw_cmd}; - -} - -##*************************************************************************** -sub begin_replica{ -##*************************************************************************** - my $self = shift; - my $replica = shift; - return $self->{begin_replica}->{$replica} if (defined $self->{begin_replica}->{$replica}); - - my @aca_hw_cmds; - - for my $entry (@{$self->{entries}}){ - if (defined $entry->trace_id()){ - #print $entry->trace_id(), "\n"; - } - if ((defined $entry->trace_id()) and ($entry->trace_id() =~ /ADC_R$replica/)){ - $self->{begin_replica}->{$replica} = $entry; - last; - } - - } - - croak( "Could not find replica $replica beginning") - unless defined $self->{begin_replica}->{$replica}; - return $self->{begin_replica}->{$replica}; - -} - -##*************************************************************************** -sub end_replica{ -##*************************************************************************** - my $self = shift; - my $replica = shift; - return $self->{end_replica}->{$replica} if (defined $self->{end_replica}->{$replica}); - - for my $entry (reverse @{$self->{entries}}){ - if ((defined $entry->trace_id()) and ( $entry->trace_id() =~ /ADC_R$replica/)) { - $self->{end_replica}->{$replica} = $entry; - last; - } - } - - - croak("Could not find replica $replica end") - unless defined $self->{end_replica}->{$replica}; - - return $self->{end_replica}->{$replica}; - -} - -##*************************************************************************** -sub last_aca_hw_cmd{ -##*************************************************************************** - my $self = shift; - return $self->{last_aca_hw_cmd} if (defined $self->{last_aca_hw_cmd}); - - $self->{last_aca_hw_cmd} = $self->end_replica(4); - - - croak("No ACA commanding found. Could not define reference entry") - unless defined $self->{last_aca_hw_cmd}; - - - return $self->{last_aca_hw_cmd}; - -} - -##*************************************************************************** -sub manvr_away_from_dfc{ -##*************************************************************************** - my $self = shift; - return $self->{manvr_away_from_dfc} if (defined $self->{manvr_away_from_dfc}); - - # I want the maneuver away from dfc, which should be the 2nd maneuver - # after the last aca hw cmd - my $manvr_cnt = 0; - my @manvr_list; - - - for my $entry (@{$self->{entries}}){ - next unless (defined $entry->{comm_mnem}); - next unless ($entry->time() > $self->last_aca_hw_cmd()->time()); -# print $entry->datestamp, "\t", $entry->time(), "\t", ref($entry), "\n"; - next unless ($entry->comm_mnem() eq 'AOMANUVR'); - last if $manvr_cnt == 2; - push @manvr_list, $entry; - $manvr_cnt++; - } - - croak("Error finding maneuver away from DFC. ") - unless scalar(@manvr_list) == 2; - - $self->{manvr_away_from_dfc} = $manvr_list[1]; - - return $self->{manvr_away_from_dfc}; - -} - - -##*************************************************************************** -sub get_tlr_array { -##*************************************************************************** - - my $raw_tlr = shift; - my $config = shift; - my $parent = shift; - my $arr_field = $config->{format}{TLR}{arr_field}; - my $field = $config->{format}{TLR}{field}; - my @tlr; - my @raw_tlr_array = @{$raw_tlr}; - - for my $line_index (0 .. $#raw_tlr_array){ - - my $timestamp = tlr_substr($raw_tlr_array[$line_index], $field->{datestamp}); - - if (has_timestamp($timestamp)){ - - my $hex = tlr_substr($raw_tlr_array[$line_index], $arr_field->{hex}); - - if (has_hex($hex)){ - - my %linehash = ( - type => 'command', - parent => $parent, - ); - - for my $key (keys %{$field}){ - $linehash{$key} = tlr_substr($raw_tlr_array[$line_index], $field->{$key}); - } - - # clean up the hash - %linehash = remove_nullsnspaces(\%linehash); - - # print Dumper %linehash; - my $entry = CandidateTLREntry->new(%linehash); - $entry->add_hex($hex); - - push @tlr, $entry; - - } - # if there is no hex, store the line as info - else{ - my %linehash = ( - type => 'entry', - parent => $parent, - datestamp => $timestamp, - string => $raw_tlr_array[$line_index] =~ s/\s$timestamp//, - ); - my $entry = CandidateTLREntry->new(%linehash); - push @tlr, $entry; - } - } - # if no timestamp but there is hex - else{ - my $hex = tlr_substr($raw_tlr_array[$line_index], $arr_field->{hex}); - if (defined $hex && $hex =~ /\S\S\S\s\S\S\S\S/){ - my $last_entry = $tlr[-1]; -# print Dumper $last_entry; - $last_entry->add_hex($hex); - } - } - - } - - return @tlr; - -} - -##*************************************************************************** -sub remove_nullsnspaces{ -##*************************************************************************** - my $hashref = shift; - my %newhash = %{$hashref}; - - #don't bother with nulls and strip off spaces - while (my ($key, $value) = each(%newhash)){ - if ($value =~ /^\s+$/){ - delete($newhash{$key}); - } - else{ - $newhash{$key} =~ s/^\s+//; - $newhash{$key} =~ s/\s+$//; - } - } - - return %newhash; -} - -##*************************************************************************** -sub has_hex{ -##*************************************************************************** - my $field = shift; - if (not defined $field){ - return 0; - } - if ($field =~ /\S\S\S\s\S\S\S\S/){ - return 1; - } - else{ - return 0; - } - -} - - -##*************************************************************************** -sub has_timestamp{ -##*************************************************************************** - my $field = shift; - if ( not defined $field){ - return 0; - } - if ( $field =~ /\d\d\d\d:\d\d\d:\d\d:\d\d:\d\d\.\d\d\d/ ){ - return 1; - } - else{ - return 0; - } - -} - -##*************************************************************************** -sub get_templ_array { -##*************************************************************************** - - my $raw_tlr = shift; - my $config = shift; - my $parent = shift; - my $field = $config->{format}{Template}{field}; - - my $arr_field = $config->{format}{Template}{arr_field}; - - my @template; - my @raw_tlr_array = @{$raw_tlr}; - - for my $line_index (0 .. $#raw_tlr_array ){ - - my $timestamp_area = tlr_substr($raw_tlr_array[$line_index], $field->{datestamp}); - - if (has_timestamp($timestamp_area)){ - my $hex_area = tlr_substr($raw_tlr_array[$line_index], $arr_field->{hex}); - - if (has_hex($hex_area)){ - my %linehash = ( - type => 'command', - parent => $parent, - ); - - for my $key (keys %{$field}){ - $linehash{$key} = tlr_substr($raw_tlr_array[$line_index], $field->{$key}); - } - - #don't bother with nulls and strip off spaces - %linehash = remove_nullsnspaces(\%linehash); - - my $entry = TemplateTLREntry->new(%linehash); - - $entry->add_hex($hex_area); - - if (scalar(@template)){ - $entry->previous_entry($template[-1]); - } - - push @template, $entry; - } - } - # if no timestamp but there is hex - else{ - my $hex_area = tlr_substr($raw_tlr_array[$line_index], $arr_field->{hex}); - if (has_hex($hex_area)){ - my $last_entry = $template[-1]; - $last_entry->add_hex($hex_area); - } - } - - } - - - return @template; - -} - - -##*************************************************************************** -sub tlr_substr{ -##*************************************************************************** - my $line = shift; - my $loc_ref = shift; - my $string; - - if (length($line) >= $loc_ref->{stop}){ - $string = substr($line, ($loc_ref->{start}-1), ($loc_ref->{stop}-($loc_ref->{start}-1))); - } - - return $string; -} - - - -package TLREntry; - -use strict; -use Carp; -use Ska::Convert qw(date2time); - - -use Class::MakeMethods::Standard::Hash ( - scalar => [ (qw( - comm_desc - datestamp - replica - hex - index - trace_id - previous_entry - )) - ], - ); - - -##*************************************************************************** -sub new{ -##*************************************************************************** - my ($class, %data) = @_; - my $clean_hash = strip_whitespace(\%data); - bless $clean_hash, $class; - -} - -##*************************************************************************** -sub set_index{ -##*************************************************************************** - my $self = shift; - $self->{index} = shift; -} - -##*************************************************************************** -sub matches_entry{ -##*************************************************************************** - my $entry1 = shift; - my $entry2 = shift; - - my %output = ( - status => 0, - ); - - $output{info} = [{ text => sprintf($entry1->datestamp() . "\t" . $entry1->comm_mnem() . "\t" . $entry1->comm_desc()), - type => 'info'}]; - - my $comm_mnem_match = ($entry1->comm_mnem() eq $entry2->comm_mnem()); - - if ( !$comm_mnem_match ){ -# push @{$output{error}} ,sprintf($entry1->datestamp() . "\t" . $entry1->comm_mnem() . "\t" . $entry1->comm_desc()); - push @{$output{info}}, { text => sprintf($entry1->datestamp() . "\t" . $entry1->comm_mnem() . "\t" . $entry1->comm_desc()), - type => 'error'}; - - push @{$output{info}}, { text => sprintf( "\tBad comm_mnem: " . $entry1->comm_mnem() . " does not match expected " . $entry2->comm_mnem()), - type => 'error' }; - } - - my $REL_TIME_TOL = 1e-6; # seconds - my $step_rel_time_match = (abs($entry1->step_rel_time_replica() - $entry2->step_rel_time_replica()) < $REL_TIME_TOL); - if ( !$step_rel_time_match ){ -# push @{$output{error}} ,sprintf($entry1->datestamp() . "\t" . $entry1->comm_mnem() . "\t" . $entry1->comm_desc()); -# push @{$output{error}}, sprintf("step relative time mismatch: " . $entry1->step_rel_time_replica() . " secs tlr, " . $entry2->step_rel_time_replica() . " secs template "); - push @{$output{info}}, { text => sprintf($entry1->datestamp() . "\t" . $entry1->comm_mnem() . "\t" . $entry1->comm_desc()), - type => 'error'}; - - push @{$output{info}}, { text => sprintf("step relative time mismatch: " - . $entry1->step_rel_time_replica() . " secs tlr, " - . $entry2->step_rel_time_replica() . " secs template "), - type => 'error'}; - } - else{ - push @{$output{info}}, { text => sprintf("step relative time match : " . $entry1->step_rel_time_replica() . " secs "), - type => 'info' }; - } - -# my $rel_time_match = ($entry1->rel_time() == $entry2->rel_time()); -# -# if ( !$rel_time_match ){ -## push @{$output{info}} ,sprintf($entry1->datestamp() . "\t" . $entry1->comm_mnem() . "\t" . $entry1->comm_desc()); -## push @{$output{info}}, { text => sprintf($entry1->datestamp() . "\t" . $entry1->comm_mnem() . "\t" . $entry1->comm_desc()), -## type => 'error'}; -# -# push @{$output{info}}, { text => sprintf( "Bad rel time from start: " . $entry1->rel_time() . " does not match expected " . $entry2->rel_time()), -# type => 'info'}; -#} -# else{ -# push @{$output{info}}, { text => sprintf("Good rel time from start: " . $entry1->rel_time() . " secs "), -# type => 'info'}; -# } - - my $hex_equal = check_hex_equal($entry1->hex(), $entry2->hex()); - if (defined $hex_equal->{info}){ - push @{$output{info}}, @{$hex_equal->{info}}; - } - if (($entry1->comm_mnem() eq $entry2->comm_mnem()) and - ($step_rel_time_match) and - ($hex_equal->{status})){ - $output{status} = 1; - } - - return \%output; - -} - -##*************************************************************************** -sub loose_match{ - - my $entry1 = shift; - my $entry2 = shift; - - my %output; - - $output{status} = 0; - - $output{info} = [{ text => sprintf($entry1->datestamp() . "\t" . $entry1->comm_mnem() . "\t" . $entry1->comm_desc()), - type => 'info', - }]; - - my $comm_mnem_match = ($entry1->comm_mnem() eq $entry2->comm_mnem()); - - if ( !$comm_mnem_match ){ - - push @{$output{info}}, { text => sprintf($entry1->datestamp() . "\t" . $entry1->comm_mnem() . "\t" . $entry1->comm_desc()), - type => 'error', - }; - - push @{$output{info}}, { text => sprintf( "\tBad comm_mnem: " . $entry1->comm_mnem() . " does not match expected " . $entry2->comm_mnem()), - type => 'error', - }; - } - - my $hex_equal = check_hex_equal($entry1->hex(), $entry2->hex()); - - if (defined $hex_equal->{info}){ - push @{$output{info}}, @{$hex_equal->{info}}; - } -# if (defined $hex_equal->{error}){ -# push @{$output{error}}, sprintf($entry1->datestamp() . "\t" . $entry1->comm_mnem() . "\t" . $entry1->comm_desc()); -# push @{$output{error}}, @{$hex_equal->{error}}; -# } - - - if (($comm_mnem_match) and - ($hex_equal->{status})){ - $output{status} = 1; - } - - return \%output; - -} - - - - -##*************************************************************************** -sub check_hex_equal { -##*************************************************************************** - - my %output; - $output{status} = 1; - - my ($hex_a, $hex_b) = @_; - - if ( scalar(@{$hex_a}) != scalar(@{$hex_b}) ){ - $output{info} = [{ text => "hex commands have different number of entries", - type => 'error'}]; - $output{status} = 0; - return \%output; - } - - for my $i (0 .. scalar(@{$hex_a})-1){ - if ($hex_a->[$i] ne $hex_b->[$i]){ - $output{info} = [{ text => "\tBad hex: $hex_a->[$i] does not match expected $hex_b->[$i]", - type => 'error'}]; - $output{status} = 0; - return \%output; - } - push @{$output{info}}, { text => "\thex ok: $hex_a->[$i] matches expected $hex_b->[$i]", - type => 'info'}; - } - - return \%output; - - -} - - - -##*************************************************************************** -sub strip_whitespace{ -##*************************************************************************** - my $hash = shift; - my %clean_hash; - - while ( my ($key, $value) = each (%{$hash})){ - $value =~ s/\s+$//; - $value =~ s/^\s+//; - $clean_hash{$key} = $value; - } - return \%clean_hash; -} - -##*************************************************************************** -sub time{ -##*************************************************************************** - my $entry = shift; - - if (@_){ - $entry->{time} = $_[0]; - } elsif (not defined $entry->{time}){ - $entry->{time} = date2time($entry->datestamp); - } - return $entry->{time}; -} - -##*************************************************************************** -sub comm_mnem{ -# return empty string instead of undef if undefined! -##*************************************************************************** - my $entry = shift; - if (defined $entry->{comm_mnem}){ - return $entry->{comm_mnem}; - } - return qq(); -} - -sub step_rel_time_replica{ - # reset to give replica relative times... - my $entry = shift; - if ((defined $entry->previous_entry()) - and (defined $entry->replica()) - and (defined $entry->previous_entry()->replica()) - and ($entry->previous_entry()->replica() == $entry->replica())){ - return ( $entry->time() - $entry->previous_entry()->time()); - } - return 0; -} - - -##*************************************************************************** -sub rel_time{ -##*************************************************************************** - my $entry = shift; - return ($entry->time() - $entry->{parent}->first_aca_hw_cmd->time()); - -} - - -##*************************************************************************** -sub add_hex{ -##*************************************************************************** - my ($entry, $hex) = @_; - push @{$entry->{hex}}, $hex; -} -1; - - -package TemplateTLREntry; - -use strict; -use warnings; -use Carp; - -use base 'TLREntry'; - -our @ISA = qw( TLREntry ); -1; - - -package CandidateTLREntry; -use strict; -use warnings; -use Carp; - -use base 'TLREntry'; - -our @ISA = qw( TLREntry ); - -sub replica{ - my $self = shift; - return $self->{replica} if (defined $self->{replica}); - for my $r_idx (0 .. 4){ - # find the indexes in the real tlr and trim to a reduced set of commands to check - my $r_start = $self->{parent}->begin_replica($r_idx)->index(); - my $r_end = $self->{parent}->end_replica($r_idx)->index(); - if (($self->index() >= $r_start) and ($self->index() <= $r_end)){ - $self->{replica} = $r_idx; - return $self->{replica}; - } - } - return undef; -} - -1; - - diff --git a/starcheck/src/lib/Ska/Starcheck/Obsid.pm b/starcheck/src/lib/Ska/Starcheck/Obsid.pm index 8cea3ea1..deb2c815 100644 --- a/starcheck/src/lib/Ska/Starcheck/Obsid.pm +++ b/starcheck/src/lib/Ska/Starcheck/Obsid.pm @@ -25,9 +25,11 @@ use Inline Python => q{ import numpy as np from astropy.table import Table +from starcheck.utils import time2date, date2time, de_bytestr from mica.archive import aca_dark from chandra_aca.star_probs import guide_count -from chandra_aca.transform import yagzag_to_pixels, count_rate_to_mag, mag_to_count_rate +from chandra_aca.transform import (yagzag_to_pixels, pixels_to_yagzag, + count_rate_to_mag, mag_to_count_rate) import Quaternion from Ska.quatutil import radec2yagzag import agasc @@ -43,6 +45,20 @@ ACQS = mica.stats.acq_stats.get_stats() GUIDES = mica.stats.guide_stats.get_stats() +def _pixels_to_yagzag(i, j): + """ + Call chandra_aca.transform.pixels_to_yagzag. + This wrapper is set to pass allow_bad=True, as exceptions from the Python side + in this case would not be helpful, and the very small bad pixel list should be + on the CCD. + :params i: pixel row + :params j: pixel col + :returns tuple: yag, zag as floats + """ + yag, zag = pixels_to_yagzag(i, j, allow_bad=True) + return float(yag), float(zag) + + def _yagzag_to_pixels(yag, zag): """ Call chandra_aca.transform.yagzag_to_pixels. @@ -212,12 +228,10 @@ def get_mica_star_stats(agasc_id, time): use List::Util qw(min max); use Quat; -use Ska::ACACoordConvert; use File::Basename; use POSIX qw(floor); use English; use IO::All; -use Ska::Convert qw(date2time time2date); use RDB; @@ -334,7 +348,7 @@ sub set_ACA_bad_pixels { foreach my $j ($line[2]..$line[3]) { my $pixel = {'row' => $i, 'col' => $j}; - my ($yag,$zag) = Ska::ACACoordConvert::toAngle($i,$j); + my ($yag,$zag) = _pixels_to_yagzag($i, $j); $pixel->{yag} = $yag; $pixel->{zag} = $zag; push @bad_pixels, $pixel; diff --git a/starcheck/src/starcheck b/starcheck/src/starcheck index 1d48e9a6..a2a8f70b 100755 --- a/starcheck/src/starcheck +++ b/starcheck/src/starcheck @@ -20,7 +20,7 @@ then exit 1 fi # Check for perl deps -perl -e "use IO::All; use Time::DayOfYear;" +perl -e "use IO::All;" if [[ $? -ne 0 ]]; then echo "****" diff --git a/starcheck/src/starcheck.pl b/starcheck/src/starcheck.pl index 010b09eb..4af6740c 100755 --- a/starcheck/src/starcheck.pl +++ b/starcheck/src/starcheck.pl @@ -21,22 +21,14 @@ use File::Copy; use Scalar::Util qw(looks_like_number); -use Time::JulianDay; -use Time::DayOfYear; -use Time::Local; use PoorTextFormat; -#use lib '/proj/axaf/simul/lib/perl'; -#use GrabEnv qw( grabenv ); -#use Shell::GetEnv; - use Ska::Starcheck::Obsid; use Ska::Parse_CM_File; use Carp; use YAML; use JSON (); -use Ska::Convert qw( date2time ); use Cwd qw( abs_path ); use HTML::TableExtract; @@ -50,107 +42,15 @@ import os import traceback -from Chandra.Time import DateTime from chandra_aca.star_probs import set_acq_model_ms_filter -import starcheck -from starcheck.pcad_att_check import make_pcad_attitude_check_report, check_characteristics_date -from starcheck.calc_ccd_temps import get_ccd_temps -from starcheck import __version__ as version -from kadi.commands import states - -# Borrowed from https://stackoverflow.com/a/33160507 -def de_bytestr(data): - if isinstance(data, bytes): - return data.decode() - if isinstance(data, dict): - return dict(map(de_bytestr, data.items())) - if isinstance(data, tuple): - return tuple(map(de_bytestr, data)) - if isinstance(data, list): - return list(map(de_bytestr, data)) - if isinstance(data, set): - return set(map(de_bytestr, data)) - return data - -def ccd_temp_wrapper(kwargs): - try: - return get_ccd_temps(**de_bytestr(kwargs)) - except Exception: - import traceback - traceback.print_exc() - raise - -def plot_cat_wrapper(kwargs): - try: - from starcheck.plot import make_plots_for_obsid - except ImportError as err: - # write errors to starcheck's global warnings and STDERR - perl.warning("Error with Inline::Python imports {}\n".format(err)) - return make_plots_for_obsid(**de_bytestr(kwargs)) - -def starcheck_version(): - return version - -def get_data_dir(): - sc_data = os.path.join(os.path.dirname(starcheck.__file__), 'data') - return sc_data if os.path.exists(sc_data) else "" - -def _make_pcad_attitude_check_report(kwargs): - try: - return make_pcad_attitude_check_report(**de_bytestr(kwargs)) - except Exception as err: - perl.warning("Error running dynamic attitude checks {}\n".format(err)) - - -def get_dither_kadi_state(date): - date = date.decode('ascii') - cols = ['dither', 'dither_ampl_pitch', 'dither_ampl_yaw', 'dither_period_pitch', 'dither_period_yaw'] - state = states.get_continuity(date, cols) - # Cast the numpy floats as plain floats - for key in ['dither_ampl_pitch', 'dither_ampl_yaw', 'dither_period_pitch', 'dither_period_yaw']: - state[key] = float(state[key]) - # get most recent change time - state['time'] = float(np.max([DateTime(state['__dates__'][key]).secs for key in cols])) - return state - - -def get_run_start_time(run_start_time, backstop_start): - """ - Determine a reasonable reference run start time based on the supplied - run start time and the time of the first backstop command. This - code uses a small hack so that a negative number is interpreted - as the desired "days back" from the backstop start time. All other - Chandra.Time compatible formats for run start are used as absolute - times (which will then be passed to the thermal model code as the - time before which telemetry should be found for an initial state). - Note that the logic to determine the initial state will not allow - that state to be after backstop start time. - - :param run_start_time: supplied run start time in a Chandra.Time format, - empty string interpreted as "now" as expected, - negative numbers special cased to be interpreted as - "days back" relative to first backstop command. - :param backstop_start: time of first backstop command - :returns: YYYY:DOY string of reference run start time - """ - - run_start_time = de_bytestr(run_start_time) - backstop_start = de_bytestr(backstop_start) - - # For the special case where run_start_time casts as a float - # check to see if it is negative and if so, set the reference - # time to be a time run_start_time days back from backstop start - try: - run_start_time = float(run_start_time) - # Handle nominal errors if run_start_time None or non-float Chandra.Time OK string. - except (TypeError, ValueError): - ref_time = DateTime(run_start_time) - else: - if run_start_time < 0: - ref_time = DateTime(backstop_start) + run_start_time - else: - raise ValueError("Float run_start_time should be negative") - return ref_time.date +from starcheck.pcad_att_check import check_characteristics_date +from starcheck.utils import (_make_pcad_attitude_check_report, + plot_cat_wrapper, + date2time, time2date, + ccd_temp_wrapper, + starcheck_version, get_data_dir, + get_dither_kadi_state, + get_run_start_time) }; @@ -158,10 +58,6 @@ my $version = starcheck_version(); -# cheat to get the OS (major) -my $OS = `uname`; -chomp($OS); - # Set some global vars with directory locations my $SKA = $ENV{SKA} || '/proj/sot/ska'; @@ -341,26 +237,6 @@ my ($fid_time_violation, $error, $fidsel) = Ska::Parse_CM_File::fidsel($fidsel_file, \@bs) ; map { warning("$_\n") } @{$error}; -## Warn if we are on Solaris -if ($OS eq 'SunOS'){ - warning("uname == SunOS; starcheck is only approved on Linux \n"); -} - - -# Dark Cal Checker Section -use Ska::Starcheck::Dark_Cal_Checker; -my $dark_cal_checker; -eval{ - $dark_cal_checker = Ska::Starcheck::Dark_Cal_Checker->new({ dir => $par{dir}, - app_data => $Starcheck_Data}); -}; -if ($@){ - unless ($@ =~ /No ACA commanding found/){ - warning("Dark Cal Checker Failed $@ \n"); - } -} - - # Now that global_warn exists, if the DOT wasn't made/modified by SAUSAGE # throw an error @@ -381,16 +257,6 @@ Ska::Starcheck::Obsid::set_config($config_ref); -# If there is a dark current, add the obsids of the dark cal replicas -# (which have keys beginning with "DC_T") to the set of obsids/oflsids -# that are "ok" to not have star catalogs -if ($dark_cal_checker->{dark_cal_present}){ - foreach my $key (keys %{$dark_cal_checker->{dc_oflsid}}){ - if ($key =~ /DC_T/){ - push @{$config_ref->{no_starcat_oflsid}}, $dark_cal_checker->{dc_oflsid}->{$key}; - } - } -} # Set the multple star filter disabled in the model if after this date my $MSF_ENABLED = $bs[0]->{date} lt '2016:102:00:00:00.000'; @@ -803,18 +669,6 @@ sub json_obsids{ } } -# Dark Cal Checker -if ($dark_cal_checker->{dark_cal_present}){ - $out .= "------------ DARK CURRENT CALIBRATION CHECKS -----------------\n\n"; - # Add a link to the comm summary if we've figured out a mission planning week name for these products - if ($mp_top_link){ - my $url = sprintf("https://occweb.cfa.harvard.edu/occweb/FOT/mission_planning/Backstop/%s/output/%s_CommSum.html", $mp_top_link->{week}, $mp_top_link->{week}); - $out .= sprintf("Comm Summary: %s\n\n", $url, $mp_top_link->{week}); - } - $out .= dark_cal_print($dark_cal_checker, $STARCHECK); - $out .= "\n"; -} - # CCD temperature plot if ($obsid_temps){ $out .= "------------ CCD TEMPERATURE PREDICTION -----------------\n\n"; @@ -1025,35 +879,7 @@ sub json_obsids{ print STDERR "Wrote text report to $STARCHECK.txt\n"; } - -##*************************************************************************** -sub dark_cal_print{ -##*************************************************************************** - - my $dark_cal_checker = shift; - my $out_dir = shift; - - io("${out_dir}/dark_cal_verbose.html")->print($dark_cal_checker->print({ verbose => 1, - criteria => 0, - html_standalone => 1})); - - - io("${out_dir}/dark_cal_super_verbose.html")->print($dark_cal_checker->print({verbose => 1, - criteria => 1, - html_standalone => 1})); - - my $out; - $out .= "VERBOSE "; - $out .= "SUPERVERBOSE\n"; - $out .= $dark_cal_checker->print({verbose => 0, - criteria => 0, - html => 0, - link_to => "${out_dir}/dark_cal_super_verbose.html", - }); - - return $out; -} ##*************************************************************************** sub guess_mp_toplevel{ diff --git a/starcheck/utils.py b/starcheck/utils.py new file mode 100644 index 00000000..04d0b520 --- /dev/null +++ b/starcheck/utils.py @@ -0,0 +1,117 @@ +import os +import numpy as np + +from Chandra.Time import DateTime +from Chandra.Time import secs2date as time2date, date2secs as pydate2secs +from chandra_aca.star_probs import set_acq_model_ms_filter +import starcheck +from starcheck.pcad_att_check import make_pcad_attitude_check_report, check_characteristics_date +from starcheck.calc_ccd_temps import get_ccd_temps +from starcheck import __version__ as version +from kadi.commands import states + + +# Borrowed from https://stackoverflow.com/a/33160507 +def de_bytestr(data): + if isinstance(data, bytes): + return data.decode() + if isinstance(data, dict): + return dict(map(de_bytestr, data.items())) + if isinstance(data, tuple): + return tuple(map(de_bytestr, data)) + if isinstance(data, list): + return list(map(de_bytestr, data)) + if isinstance(data, set): + return set(map(de_bytestr, data)) + return data + + +def date2time(date): + return pydate2secs(de_bytestr(date)) + + +def ccd_temp_wrapper(kwargs): + try: + return get_ccd_temps(**de_bytestr(kwargs)) + except Exception: + import traceback + traceback.print_exc() + raise + + +def plot_cat_wrapper(kwargs): + try: + from starcheck.plot import make_plots_for_obsid + except ImportError as err: + # write errors to starcheck's global warnings and STDERR + perl.warning("Error with Inline::Python imports {}\n".format(err)) + return make_plots_for_obsid(**de_bytestr(kwargs)) + + +def starcheck_version(): + return version + + +def get_data_dir(): + sc_data = os.path.join(os.path.dirname(starcheck.__file__), 'data') + return sc_data if os.path.exists(sc_data) else "" + + +def _make_pcad_attitude_check_report(kwargs): + try: + return make_pcad_attitude_check_report(**de_bytestr(kwargs)) + except Exception as err: + perl.warning("Error running dynamic attitude checks {}\n".format(err)) + + +def get_dither_kadi_state(date): + date = date.decode('ascii') + cols = ['dither', 'dither_ampl_pitch', 'dither_ampl_yaw', + 'dither_period_pitch', 'dither_period_yaw'] + state = states.get_continuity(date, cols) + # Cast the numpy floats as plain floats + for key in ['dither_ampl_pitch', 'dither_ampl_yaw', + 'dither_period_pitch', 'dither_period_yaw']: + state[key] = float(state[key]) + # get most recent change time + state['time'] = float(np.max([DateTime(state['__dates__'][key]).secs for key in cols])) + return state + + +def get_run_start_time(run_start_time, backstop_start): + """ + Determine a reasonable reference run start time based on the supplied + run start time and the time of the first backstop command. This + code uses a small hack so that a negative number is interpreted + as the desired "days back" from the backstop start time. All other + Chandra.Time compatible formats for run start are used as absolute + times (which will then be passed to the thermal model code as the + time before which telemetry should be found for an initial state). + Note that the logic to determine the initial state will not allow + that state to be after backstop start time. + + :param run_start_time: supplied run start time in a Chandra.Time format, + empty string interpreted as "now" as expected, + negative numbers special cased to be interpreted as + "days back" relative to first backstop command. + :param backstop_start: time of first backstop command + :returns: YYYY:DOY string of reference run start time + """ + + run_start_time = de_bytestr(run_start_time) + backstop_start = de_bytestr(backstop_start) + + # For the special case where run_start_time casts as a float + # check to see if it is negative and if so, set the reference + # time to be a time run_start_time days back from backstop start + try: + run_start_time = float(run_start_time) + # Handle nominal errors if run_start_time None or non-float Chandra.Time OK string. + except (TypeError, ValueError): + ref_time = DateTime(run_start_time) + else: + if run_start_time < 0: + ref_time = DateTime(backstop_start) + run_start_time + else: + raise ValueError("Float run_start_time should be negative") + return ref_time.date