-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from jzuhone/cea
- Loading branch information
Showing
20 changed files
with
6,719 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
#!/usr/bin/env python | ||
|
||
""" | ||
======================== | ||
cea_check | ||
======================== | ||
This code generates backstop load review outputs for checking the HRC | ||
CEA temperature 2CEAHVPT. It also generates CEA model validation | ||
plots comparing predicted values to telemetry for the previous three | ||
weeks. | ||
""" | ||
|
||
# Matplotlib setup | ||
# Use Agg backend for command-line (non-interactive) operation | ||
import matplotlib | ||
matplotlib.use('Agg') | ||
|
||
import sys | ||
from acis_thermal_check import \ | ||
ACISThermalCheck, \ | ||
get_options, \ | ||
mylog | ||
from acis_thermal_check.utils import PredictPlot | ||
from Ska.Matplotlib import pointpair | ||
|
||
|
||
class CEACheck(ACISThermalCheck): | ||
def __init__(self): | ||
valid_limits = {'2CEAHVPT': [(1, 2.0), (50, 1.0), (99, 2.0)], | ||
'PITCH': [(1, 3.0), (99, 3.0)], | ||
'TSCPOS': [(1, 2.5), (99, 2.5)] | ||
} | ||
hist_limit = [5.0] | ||
limits_map = {} | ||
other_telem = ["2imonst", "2sponst", "2s2onst"] | ||
super(CEACheck, self).__init__("2ceahvpt", "cea", valid_limits, | ||
hist_limit, limits_map=limits_map, | ||
other_telem=other_telem) | ||
|
||
def make_prediction_viols(self, temps, states, load_start): | ||
""" | ||
Find limit violations where predicted temperature is above the | ||
specified limits. | ||
Parameters | ||
---------- | ||
temps : dict of NumPy arrays | ||
NumPy arrays corresponding to the modeled temperatures | ||
states : NumPy record array | ||
Commanded states | ||
load_start : float | ||
The start time of the load, used so that we only report | ||
violations for times later than this time for the model | ||
run. | ||
""" | ||
mylog.info('Checking for limit violations') | ||
|
||
temp = temps[self.name] | ||
times = self.predict_model.times | ||
|
||
# Only check this violation when HRC is on | ||
mask = self.predict_model.comp['2imonst_on'].dvals | ||
mask |= self.predict_model.comp['2sponst_on'].dvals | ||
hi_viols = self._make_prediction_viols( | ||
times, temp, load_start, self.limits["planning_hi"].value, | ||
"planning", "max", mask=mask) | ||
viols = {"hi": | ||
{"name": f"Hot ({self.limits['planning_hi'].value} C)", | ||
"type": "Max", | ||
"values": hi_viols} | ||
} | ||
return viols | ||
|
||
def _calc_model_supp(self, model, state_times, states, ephem, state0): | ||
""" | ||
Update to initialize the cea0 pseudo-node. If 2ceahvpt | ||
has an initial value (T_cea) - which it does at | ||
prediction time (gets it from state0), then T_cea0 | ||
is set to that. If we are running the validation, | ||
T_cea is set to None so we use the dvals in model.comp | ||
""" | ||
for node in ["cea0", "cea1"]: | ||
if state0 is None: | ||
T_cea = model.comp["2ceahvpt"].dvals | ||
else: | ||
T_cea = state0["2ceahvpt"] | ||
model.comp[node].set_data(T_cea, model.times) | ||
model.comp["2ps5aon_on"].set_data(True) | ||
model.comp["2ps5bon_on"].set_data(False) | ||
model.comp["2imonst_on"].set_data(states["hrc_i"] == "ON", state_times) | ||
model.comp["2sponst_on"].set_data(states["hrc_s"] == "ON", state_times) | ||
model.comp["2s2onst_on"].set_data(states["hrc_15v"] == "ON", state_times) | ||
model.comp["224pcast_off"].set_data(states["hrc_15v"] == "ON", state_times) | ||
model.comp["215pcast_off"].set_data(states["hrc_15v"] == "ON", state_times) | ||
|
||
def _make_state_plots(self, plots, num_figs, w1, plot_start, | ||
states, load_start): | ||
# Make a plot of ACIS HRC states | ||
plots['hrc'] = PredictPlot( | ||
fig_id=num_figs+1, | ||
title='HRC States', | ||
xlabel='Date', | ||
x=pointpair(states['tstart'], states['tstop']), | ||
y=pointpair(states['hrc_i']), | ||
yy=pointpair(states['hrc_s']), | ||
ylabel='HRC-I/S', | ||
x2=pointpair(states['tstart'], states['tstop']), | ||
y2=pointpair(states['hrc_15v']), | ||
ylabel2='HRC 15 V', | ||
linewidth2=4.0, | ||
xmin=plot_start, | ||
width=w1, load_start=load_start) | ||
plots['hrc'].ax.lines[0].set_label('HRC-I') | ||
plots['hrc'].ax.lines[1].set_label('HRC-S') | ||
plots['hrc'].ax.legend(fancybox=True, framealpha=0.5, loc=2) | ||
plots['hrc'].filename = 'hrc.png' | ||
|
||
num_figs += 1 | ||
super()._make_state_plots(plots, num_figs, w1, plot_start, | ||
states, load_start) | ||
|
||
|
||
def main(): | ||
args = get_options(use_acis_opts=False) | ||
cea_check = CEACheck() | ||
try: | ||
cea_check.run(args) | ||
except Exception as msg: | ||
if args.traceback: | ||
raise | ||
else: | ||
print("ERROR:", msg) | ||
sys.exit(1) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Oops, something went wrong.