diff --git a/starcheck/calc_ccd_temps.py b/starcheck/calc_ccd_temps.py index 4e444245..d3862d29 100755 --- a/starcheck/calc_ccd_temps.py +++ b/starcheck/calc_ccd_temps.py @@ -407,7 +407,7 @@ def mock_telem_predict(states, stat=None): def get_bs_cmds(oflsdir): """Return commands for the backstop file in opt.oflsdir. """ - backstop_file = globfile(os.path.join(oflsdir, 'CR*.backstop')) + backstop_file = globfile(os.path.join(oflsdir, '*.backstop')) logger.info('Using backstop file %s' % backstop_file) bs_cmds = kadi.commands.get_cmds_from_backstop(backstop_file) logger.info('Found %d backstop commands between %s and %s' % diff --git a/starcheck/src/starcheck.pl b/starcheck/src/starcheck.pl index 47599ef6..f8f7adc1 100755 --- a/starcheck/src/starcheck.pl +++ b/starcheck/src/starcheck.pl @@ -142,8 +142,7 @@ my @global_warn; # asterisk only include to make globs work correctly -my $backstop = - get_file("$par{dir}/${sosa_dir_slash}*.backstop", 'backstop', 'required'); + my $guide_summ = get_file("$par{dir}/mps/mg*.sum", 'guide summary'); my $or_file = get_file("$par{dir}/mps/or/*.or", 'OR'); my $mm_file = get_file("$par{dir}/mps/mm*.sum", 'maneuver'); @@ -227,6 +226,26 @@ "copy(${Starcheck_Data}/${data_file}, ${STARCHECK}/${data_file}) failed: $! \n"; } +# If in vehicle mode, make a filtered version of the backstop and write out to the output file. +# Otherwise, use the backstop file found in the directory in $par{dir}. +my $backstop; +if ($par{vehicle}) { + my $backstop_source = + get_file("$par{dir}/*.backstop", 'backstop source file', 'required'); + call_python( + "utils.vehicle_filter_backstop", + [], + { + backstop_file => $backstop_source, + outfile => "$STARCHECK/vehicle_filtered.backstop", + } + ); + $backstop = get_file("$STARCHECK/*.backstop", 'vehicle backstop', 'required'); +} +else { + $backstop = get_file("$par{dir}/*.backstop", 'backstop', 'required'); +} + # First read the Backstop file, and split into components print "Reading backstop file $backstop\n"; my @bs = Ska::Parse_CM_File::backstop($backstop); @@ -577,7 +596,7 @@ sub json_obsids { "utils.ccd_temp_wrapper", [], { - oflsdir => $par{dir}, + oflsdir => $par{vehicle} ? $STARCHECK : $par{dir}, outdir => $STARCHECK, json_obsids => $json_text, orlist => $or_file, diff --git a/starcheck/utils.py b/starcheck/utils.py index 483bfac9..acd797cb 100644 --- a/starcheck/utils.py +++ b/starcheck/utils.py @@ -20,6 +20,7 @@ from chandra_aca.transform import mag_to_count_rate, pixels_to_yagzag, yagzag_to_pixels from kadi.commands import states from mica.archive import aca_dark +from parse_cm import read_backstop_as_list, write_backstop from proseco.catalog import get_aca_catalog, get_effective_t_ccd from proseco.core import ACABox from proseco.guide import get_imposter_mags @@ -543,3 +544,20 @@ def proseco_probs(**kw): ] return p_acqs, float(-np.log10(acq_cat.calc_p_safe())), float(np.sum(p_acqs)) + + +def vehicle_filter_backstop(backstop_file, outfile): + """ + Filter the backstop file to remove SCS 131, 132, 133 except MP_OBSID commands. + This is basically equivalent to the vehicle backstop file, but the MP_OBSID + commands are useful for ACA to associate maneuvers with observations. + """ + # Use parse_cm read_backstop_as_list instead of kadi.commands.read_backstop + # as we want the params to keep the SCS to write back later. + cmds = read_backstop_as_list(backstop_file, inline_params=False) + # Filter the commands to remove SCS 131, 132, 133 except MP_OBSID commands + filtered_cmds = [cmd for cmd in cmds + if cmd["scs"] < 131 + or cmd["type"] == "MP_OBSID"] + # Write the filtered commands to the output file + write_backstop(filtered_cmds, outfile)