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

Handle vehicle mode with custom filtered backstop #421

Merged
merged 1 commit into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, we'd add a unit test for this function, but given the impact I think it can probably go with functional testing.

"""
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.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@taldcroft as I was in a bit of a hurry I didn't dig much into this, but to me it made more sense to use the validated and tagged read-in backstop instead of a grep of some kind in the file. But then if writing out a backstop, it seemed to make sense to use write_backstop... which seemed to have the params it wanted if I used parse_cm's own methods for reading backstop instead of the kadi versions.

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)