Skip to content

Commit

Permalink
problem_runs.py, to find problematic runs
Browse files Browse the repository at this point in the history
  • Loading branch information
trmrsh committed Mar 29, 2022
1 parent 126041a commit edb84f5
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions useful/problem-runs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env python

"""
Tries to identify problematic runs in the log database files.
"""

import sys
import re
import sqlite3
import os
import pandas as pd

import hipercam as hcam

if __name__ == '__main__':

# Get database files.

# Search in standard directory
dbases_dir = os.path.join(
os.environ.get(
'HIPERCAM_ENV',
os.path.join(os.environ["HOME"],'.hipercam')
),
'dbases'
)

instruments = ('ultracam','ultraspec','hipercam')

results = []
for instrument in instruments:

# connect to database
dbase = os.path.join(dbases_dir, instrument + '.db')
if not os.path.exists(dbase):
print(f'Database = {dbase} does not exist')
continue

conn = sqlite3.connect(f"file:{dbase}?mode=ro",uri=True)

# build query string
query = f'SELECT * FROM {instrument}\n'
query += """WHERE mjd_start IS NULL"""

print(f'\nQuerying database {dbase} with SQL string:\n\n{query}')
res = pd.read_sql_query(query, conn)
if len(res):
print(res)
results.append(res)
else:
print(' no runs found')

# close connection
conn.close()

if False:
total = pd.concat(results,sort=False)
total.to_csv(output)

0 comments on commit edb84f5

Please sign in to comment.