Skip to content

Commit

Permalink
Print out a table of all of the obsids and store it in a separate HTM…
Browse files Browse the repository at this point in the history
…L file. Also print the limit that is violated in the table
  • Loading branch information
jzuhone committed Aug 10, 2023
1 parent f354243 commit a4a6427
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 56 deletions.
19 changes: 2 additions & 17 deletions acis_thermal_check/apps/acisfp_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ def __init__(self):
# Create an empty observation list which will hold the results. This
# list contains all ACIS and all ECS observations.
self.acis_and_ecs_obs = []
self.acis_hot_obs = []

def _calc_model_supp(self, model, state_times, states, ephem, state0):
"""
Expand Down Expand Up @@ -221,17 +220,6 @@ def make_prediction_plots(self, outdir, states, temps, load_start):
capthick=2,
label="ACIS-S",
)
plots[name].ax.errorbar(
[0.0, 0.0],
[1.0, 1.0],
xerr=1.0,
lw=2,
xlolims=True,
color="saddlebrown",
capsize=4,
capthick=2,
label="Hot ACIS-S",
)

# Make the legend on the temperature plot
plots[name].ax.legend(
Expand Down Expand Up @@ -289,10 +277,8 @@ def make_prediction_viols(self, temps, states, load_start):
"""
viols = super().make_prediction_viols(temps, states, load_start)

# Store all obsids which can go to -109 C
# Store the obsid table
self.acis_and_ecs_obs = self.limit_object.acis_obs_info.as_table()
hot_acis = self.acis_and_ecs_obs["hot_acis"].data
self.acis_hot_obs = self.acis_and_ecs_obs[hot_acis]

return viols

Expand Down Expand Up @@ -360,7 +346,6 @@ def draw_obsids(

obsid = eachobservation["obsid"]
in_fp = eachobservation["instrument"]
hot_acis = eachobservation["hot_acis"]

if obsid > 60000:
# ECS observations during the science orbit are colored blue
Expand All @@ -371,7 +356,7 @@ def draw_obsids(
if in_fp == "ACIS-I":

Check failure on line 356 in acis_thermal_check/apps/acisfp_check.py

View workflow job for this annotation

GitHub Actions / build

Ruff (PLR5501)

acis_thermal_check/apps/acisfp_check.py:353:9: PLR5501 Use `elif` instead of `else` then `if`, to reduce indentation
color = "red"
else:
color = "saddlebrown" if hot_acis else "green"
color = "green"

obsid_txt = str(obsid)
# If this is an ECS measurement in the science orbit mark
Expand Down
52 changes: 35 additions & 17 deletions acis_thermal_check/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,6 @@ def run(self, args, override_limits=None):
"pred_only": args.pred_only,
"plots_validation": plots_validation,
}
if self.msid == "fptemp":
context["acis_hot_obs"] = self.acis_hot_obs

self.write_index_rst(args.outdir, context)

Expand Down Expand Up @@ -1216,22 +1214,26 @@ def rst_to_html(self, outdir):
)

stylesheet_path = str(outdir / "acis_thermal_check.css")
infile = str(outdir / "index.rst")
outfile = str(outdir / "index.html")
publish_file(
source_path=infile,
destination_path=outfile,
writer_name="html",
settings_overrides={"stylesheet_path": stylesheet_path},
)
prefixes = ["index"]
if self.msid == "fptemp":
prefixes.append("obsid_table")
for prefix in prefixes:
infile = str(outdir / f"{prefix}.rst")
outfile = str(outdir / f"{prefix}.html")
publish_file(
source_path=infile,
destination_path=outfile,
writer_name="html",
settings_overrides={"stylesheet_path": stylesheet_path},
)

# Remove the stupid <colgroup> field that docbook inserts. This
# <colgroup> prevents HTML table auto-sizing.
del_colgroup = re.compile(r"<colgroup>.*?</colgroup>", re.DOTALL)
with open(outfile) as f:
outtext = del_colgroup.sub("", f.read())
with open(outfile, "w") as f:
f.write(outtext)
# Remove the stupid <colgroup> field that docbook inserts. This
# <colgroup> prevents HTML table auto-sizing.
del_colgroup = re.compile(r"<colgroup>.*?</colgroup>", re.DOTALL)
with open(outfile) as f:
outtext = del_colgroup.sub("", f.read())
with open(outfile, "w") as f:
f.write(outtext)

def write_index_rst(self, outdir, context):
"""
Expand All @@ -1258,6 +1260,22 @@ def write_index_rst(self, outdir, context):
# Render the template and write it to a file
with open(outfile, "w") as fout:
fout.write(template.render(**context))
if self.msid == "fptemp":
context["acis_obs"] = self.acis_and_ecs_obs
template_path = (
TASK_DATA / "acis_thermal_check/templates/obsid_template.rst"
)
outfile = outdir / "obsid_table.rst"
# Open up the reST template and send the context to it using jinja2
with open(template_path) as fin:
index_template = fin.read()
index_template = re.sub(r" %}\n", " %}", index_template)
template = jinja2.Template(index_template)
# Render the template and write it to a file
with open(outfile, "w") as fout:
fout.write(
template.render(acis_obs=self.acis_and_ecs_obs, bsdir=self.bsdir)

Check failure on line 1277 in acis_thermal_check/main.py

View workflow job for this annotation

GitHub Actions / build

Ruff (COM812)

acis_thermal_check/main.py:1277:86: COM812 Trailing comma missing
)

def _setup_proc_and_logger(self, args):
"""
Expand Down
34 changes: 12 additions & 22 deletions acis_thermal_check/templates/index_template.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
================================
{{proc.name}} temperatures check
{{proc.name}} Temperatures Check
================================
.. role:: red

Expand Down Expand Up @@ -32,17 +32,7 @@ States `<states.dat>`_
===================== =============================================

{% if proc.msid == "FPTEMP" %}
"Hot" ACIS Observations (-109 C limit)
--------------------------------------
{% if acis_hot_obs|length > 0 %}
===== ================== ======= =================
Obsid # of counts in seq Grating Spectra Max Count
===== ================== ======= =================
{% for eachobs in acis_hot_obs %}
{{ eachobs.obsid }} {{"{0: <18}".format(eachobs.num_counts)}} {{eachobs.grating}} {{"{0: <10}".format(eachobs.spectra_max_count)}}
{% endfor %}
===== ================== ======= =================
{% endif %}
`ACIS Observations Table <obsid_table.html>`_
{% endif %}

{% for key in viols.keys() %}
Expand All @@ -59,21 +49,21 @@ Obsid # of counts in seq Grating Spectra Max Count
{{proc.msid}} {{viol_type}} Violations
---------------------------------------------------
{% if proc.msid == "FPTEMP" %}
===================== ===================== ================= ================== ==================
Date start Date stop Duration (ks) Max temperature Obsids
===================== ===================== ================= ================== ==================
===================== ===================== ================= ======================= ==================
Date start Date stop Duration (ks) Max Temperature / Limit Obsid
===================== ===================== ================= ======================= ==================
{% for viol in viols[key] %}
{{viol.datestart}} {{viol.datestop}} {{"{:3.2f}".format(viol.duration).rjust(8)}} {{"%.2f"|format(viol.extemp)}} {{viol.obsid}}
{{viol.datestart}} {{viol.datestop}} {{"{:3.2f}".format(viol.duration).rjust(8)}} {{"%.2f"|format(viol.extemp)}} / {{"%.2f"|format(viol.limit[0])}} {{viol.obsid}}
{% endfor %}
===================== ===================== ================= ================== ==================
===================== ===================== ================= ======================= ==================
{% else %}
===================== ===================== ================= ===================
Date start Date stop Duration (ks) {{extreme}} Temperature
===================== ===================== ================= ===================
===================== ===================== ================= ===============================
Date start Date stop Duration (ks) {{extreme}} Temperature / Limit
===================== ===================== ================= ===============================
{% for viol in viols[key] %}
{{viol.datestart}} {{viol.datestop}} {{"{:3.2f}".format(viol.duration).rjust(8)}} {{"{:.2f}".format(viol.extemp)}}
{{viol.datestart}} {{viol.datestop}} {{"{:3.2f}".format(viol.duration).rjust(8)}} {{"{:.2f}".format(viol.extemp)}} / {{"{:.2f}".format(viol.limit[0])}}
{% endfor %}
===================== ===================== ================= ===================
===================== ===================== ================= ===============================
{% endif %}
{% else %}
No {{proc.msid}} {{viol_type}} Violations
Expand Down
12 changes: 12 additions & 0 deletions acis_thermal_check/templates/obsid_template.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
ACIS Observations Table
-----------------------

Observations in {{bsdir}}

===== ================== ======= ================= =====
Obsid # of counts in seq Grating Spectra Max Count Limit
===== ================== ======= ================= =====
{% for eachobs in acis_obs %}
{{ eachobs.obsid }} {{"{0: <18}".format(eachobs.num_counts)}} {{eachobs.grating}} {{"{0: <10}".format(eachobs.spectra_max_count)}} {{eachobs.fp_limit}}
{% endfor %}
===== ================== ======= ================= =====

0 comments on commit a4a6427

Please sign in to comment.