Add Exposure Count Totals to NightLog
- Dominant language
- Jupyter Notebook
- Stars
- 0
- Forks
- 1
- PR merge metrics
- No merged PRs in 30d
Description
Part of the end of night routine is for the Lead Observer to calculate the exposure totals for the different programs such as DARK, BRIGHT1B etc. This tasks can be automated by adding a simple database query to the report.py script of the desinightlog code.
The results of this function will have to be integrated with Bokeh to be properly displayed and to make it Into the nightly summary table.
Here is a working example of a function that returns the exposure counts:
```
import DOSlib.util
import DOSlib.logger as Log
def get_exp_counts(programs=['DARK','DARK1B','BRIGHT','BRIGHT1B','BACKUP'], db_connection = None, night = None):
""" get exposure counts for the night for select programs
"""
exp_counts={}
try:
if db_connection is None:
conn, cursor = DOSlib.util.connect2DB(writer=False)
else:
cursor = db_connection.cursor()
if night is None:
night = int(DOSlib.util.obs_day())
for prog in programs:
cursor.execute(f"SELECT count(*) from exposure.exposure where program='{prog}' and night
={night} and sequence='DESI'")
f = cursor.fetchall()
exp_counts[prog]=f[0][0]
except Exception as e:
Log.error('get_exp_counts: Exception %r' % str(e))
return exp_counts
```
and here is the function in action
```
msdos@desi-2 ~/python]# python
Python 3.9.6 (default, Apr 21 2023, 09:02:04)
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import exp_counts
>>> exp_counts.get_exp_counts()
{'DARK': 7, 'DARK1B': 18, 'BRIGHT': 1, 'BRIGHT1B': 2, 'BACKUP': 3}
>>> exp_counts.get_exp_counts(night=20241012)
{'DARK': 9, 'DARK1B': 0, 'BRIGHT': 20, 'BRIGHT1B': 0, 'BACKUP': 2}
```
Notes:
in report.py, the observing night is available as **self.night**.
The database connection is already setup and is available as **self.conn**
That means for the report.py implementation you don't need the lines in my example with ops_day and connect2DB
Instead of Log.error use self.logger.error
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.