Skip to content

Commit

Permalink
Add nominal overheads
Browse files Browse the repository at this point in the history
  • Loading branch information
albireox committed Nov 11, 2024
1 parent 5babd4d commit c1db46c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/lvmapi/data/night_log_email_template.html
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,9 @@ <h1 class="header-text">
<li>Night length: {{ metrics.night_length }}</li>
<li>Number of object exposures: {{ metrics.n_object_exps }}</li>
<li>Time not observing: {{ metrics.time_lost if metrics.night_started else "N/A" }}</li>
<li>Efficiency (without readout): {{ metrics.efficiency_no_readout|string + "%" if metrics.night_started else "N/A" }}</li>
<li>Efficiency (with nominal overheads): {{ metrics.efficiency_nominal|string + "%" if metrics.night_started else "N/A" }}</li>
<li>Efficiency (with readout): {{ metrics.efficiency_readout|string + "%" if metrics.night_started else "N/A" }}</li>
<li>Efficiency (without readout): {{ metrics.efficiency_no_readout|string + "%" if metrics.night_started else "N/A" }}</li>
</ul>
{% else %}
<div>Metrics not available.</div>
Expand Down
6 changes: 5 additions & 1 deletion src/lvmapi/routers/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,11 @@ class NightMetrics(BaseModel):
]
efficiency_readout: Annotated[
float,
Field(description="Efficiency assuming 60s readout, as percentage"),
Field(description="Efficiency assuming 50s readout, as percentage"),
]
efficiency_nominal: Annotated[
float,
Field(description="Efficiency assuming 90s overhead, as percentage"),
]
night_started: Annotated[
bool,
Expand Down
19 changes: 15 additions & 4 deletions src/lvmapi/tools/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import pathlib
import smtplib
import warnings
from datetime import UTC, datetime
from datetime import UTC, datetime, timedelta
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

Expand Down Expand Up @@ -570,8 +570,9 @@ async def get_plaintext_night_log(sjd: int | None = None):
- Night length: {night_length}.
- Number of object exposures: {n_object_exps}.
- Time not observing: {time_lost}
- Efficiency (without readout): {efficiency_no_readout}%
- Efficiency (with nominal overheads): {efficiency_nominal}%
- Efficiency (with readout): {efficiency_no_readout}%
- Efficiency (without readout): {efficiency_no_readout}%
Exposure data
-------------
Expand Down Expand Up @@ -625,6 +626,9 @@ async def get_plaintext_night_log(sjd: int | None = None):
"time_lost": secs_to_hours(metrics["time_lost"])
if metrics["night_started"]
else "-",
"efficiency_nominal": metrics["efficiency_nominal"]
if metrics["night_started"]
else "-",
"efficiency_no_readout": metrics["efficiency_no_readout"]
if metrics["night_started"]
else "-",
Expand Down Expand Up @@ -710,6 +714,7 @@ async def email_night_log(
"night_length": secs_to_hours(metrics["night_length"]),
"n_object_exps": metrics["n_object_exps"],
"time_lost": secs_to_hours(metrics["time_lost"]),
"efficiency_nominal": metrics["efficiency_nominal"],
"efficiency_no_readout": metrics["efficiency_no_readout"],
"efficiency_readout": metrics["efficiency_readout"],
"night_started": metrics["night_started"],
Expand Down Expand Up @@ -784,14 +789,16 @@ class NightMetricsDict(TypedDict):
time_lost: float
efficiency_no_readout: float
efficiency_readout: float
efficiency_nominal: float
night_started: bool
night_ended: bool


def get_night_metrics(sjd: int | None = None) -> NightMetricsDict:
"""Retrieves automatically calculated metrics for the night."""

READOUT_OVERHEAD: float = 60
READOUT_OVERHEAD: float = 50
NOMINAL_OVERHEAD: float = 90

sjd = sjd or get_sjd("LCO")

Expand All @@ -818,6 +825,7 @@ def get_night_metrics(sjd: int | None = None) -> NightMetricsDict:
"time_lost": 0.0,
"efficiency_no_readout": 0.0,
"efficiency_readout": 0.0,
"efficiency_nominal": 0.0,
"night_started": False,
"night_ended": False,
}
Expand All @@ -840,6 +848,7 @@ def get_night_metrics(sjd: int | None = None) -> NightMetricsDict:
"time_lost": twilight_start.unix - twilight_end.unix,
"efficiency_no_readout": 0.0,
"efficiency_readout": 0.0,
"efficiency_nominal": 0.0,
"night_started": True,
"night_ended": False,
}
Expand All @@ -857,7 +866,7 @@ def get_night_metrics(sjd: int | None = None) -> NightMetricsDict:
exposures = exposures.filter(
polars.col.image_type == "object",
polars.col.obstime > twilight_end.datetime,
polars.col.endtime < twilight_start.datetime,
polars.col.endtime < (twilight_start.datetime + timedelta(seconds=300)),
)

n_exp = exposures.height
Expand All @@ -866,6 +875,7 @@ def get_night_metrics(sjd: int | None = None) -> NightMetricsDict:
# Efficiency with and without taking into account readout.
eff_no_readout = total_exp_time / current_night_length
eff_readout = (total_exp_time + n_exp * READOUT_OVERHEAD) / current_night_length
eff_nominal = (total_exp_time + n_exp * NOMINAL_OVERHEAD) / current_night_length

return {
"sjd": sjd,
Expand All @@ -877,6 +887,7 @@ def get_night_metrics(sjd: int | None = None) -> NightMetricsDict:
"time_lost": round(night_length - total_exp_time, 2),
"efficiency_no_readout": round(eff_no_readout * 100, 2),
"efficiency_readout": round(eff_readout * 100, 2),
"efficiency_nominal": round(eff_nominal * 100, 2),
"night_started": now.unix >= twilight_end.unix,
"night_ended": now.unix >= twilight_start.unix,
}

0 comments on commit c1db46c

Please sign in to comment.