Skip to content

Commit

Permalink
Merge pull request #421 from sot/vehicle-filter
Browse files Browse the repository at this point in the history
Handle vehicle mode with custom filtered backstop
  • Loading branch information
jeanconn authored Jul 21, 2023
2 parents 2b6a98d + cabe5ec commit 8174834
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
2 changes: 1 addition & 1 deletion starcheck/calc_ccd_temps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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' %
Expand Down
25 changes: 22 additions & 3 deletions starcheck/src/starcheck.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down
18 changes: 18 additions & 0 deletions starcheck/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

0 comments on commit 8174834

Please sign in to comment.