In [1]:
from pocs.utils.database import PanMongo
from astropy.time import Time
import pandas as pd
from matplotlib import pyplot as plt
%matplotlib inline
There are some convenience scripts that can be used to export the data from the NUC, which can then either be imported into a local mongo instance.
Note: Your output will vary
Export data:
➜ python pocs/utils/database.py --help
usage: database.py [-h] [--yesterday] [--start-date START_DATE]
[--end-date END_DATE] [--collections COLLECTIONS]
[--backup-dir BACKUP_DIR] [--compress]
Exporter for mongo collections
optional arguments:
-h, --help show this help message and exit
--yesterday Export yesterday, defaults to True unless start-date
specified
--start-date START_DATE
Export start date, e.g. 2016-01-01
--end-date END_DATE Export end date, e.g. 2016-01-31
--collections COLLECTIONS
Collections to export
--backup-dir BACKUP_DIR
Directory to store backup files, defaults to
$PANDIR/backups
--compress If exported files should be compressed, defaults to
True
➜ python pocs/utils/database.py --start-date 2017-01-30 --end-date 2017-01-31
Exporting collections: 2017-01-30 to 2017-01-31
config
No records found
current
No records found
drift_align
No records found
environment
No records found
mount
No records found
observations
293 records exported
Compressing...
Writing file: /var/panoptes/backups/20170130_to_20170131_observations.json.gz
state
No records found
weather
2094 records exported
Compressing...
Writing file: /var/panoptes/backups/20170130_to_20170131_weather.json.gz
Output file: [
'/var/panoptes/backups/20170130_to_20170131_observations.json.gz',
'/var/panoptes/backups/20170130_to_20170131_weather.json.gz']
In [2]:
db = PanMongo()
In [3]:
db.collections
Out[3]:
In [4]:
db.get_current('weather')
Out[4]:
In [5]:
db.get_current('environment')
Out[5]:
In [6]:
cursor = db.environment.find({
'date': {
'$gte': Time('2017-04-10').datetime,
'$lte': Time('2017-04-12').datetime
}
}) #.sort([('date', -1)])
In [7]:
print("Num records: {}".format(cursor.count()))
In [8]:
environment = {
'telemetry_board': {
'temp_0': list(),
'temp_1': list(),
'temp_2': list(),
'temp_3': list(),
# 'humidity': list(),
'date': list(),
},
'camera_board': {
'temp_0': list(),
'humidity': list(),
'date': list(),
}
}
In [9]:
for record in cursor:
try:
data = record['data']['telemetry_board']
board = 'telemetry_board'
environment[board]['temp_0'].append(data['temp_00'])
environment[board]['temp_1'].append(data['temperature'][0])
environment[board]['temp_2'].append(data['temperature'][1])
environment[board]['temp_3'].append(data['temperature'][2])
# environment[board]['humidity'].append(data['humidity'])
environment[board]['date'].append(record['date'])
except KeyError:
pass
try:
data = record['data']['camera_board']
board = 'camera_board'
environment[board]['temp_0'].append(data['temp_00'])
environment[board]['humidity'].append(data['humidity'])
environment[board]['date'].append(record['date'])
except KeyError:
pass
In [10]:
# camera = pd.DataFrame(environment['camera_board']).set_index('date')
computer_box = pd.DataFrame(environment['telemetry_board']).set_index('date')
In [11]:
computer_box.plot(figsize=(12,9), title="Computer Box Temperatures")
Out[11]:
In [12]:
cursor = db.environment.find({
'date': {
'$gte': Time('2017-04-10 12:00:00').datetime,
'$lte': Time('2017-04-10 23:59:59').datetime
}
}) #.sort([('date', -1)])
In [13]:
print("Num records: {}".format(cursor.count()))
In [14]:
# Convert to list
records = list(cursor)
In [15]:
# Examine first record
records[0]
Out[15]:
In [16]:
def get_power_reading(records, key):
# Get the timestamps
ts = pd.Series([rec['date'] for rec in records])
power = pd.Series(
[
rec['data']['telemetry_board']['power'][key]
if 'telemetry_board' in rec['data'] else None
for rec in records
],
index=ts
)
if key == 'computer':
key = 'main'
current = pd.Series(
[
rec['data']['telemetry_board']['current'][key]
if 'telemetry_board' in rec['data'] else None
for rec in records
],
index=ts
)
return pd.DataFrame({'current': current, 'power': power}, index=ts).dropna()
In [17]:
df0 = get_power_reading(records, 'computer')
In [18]:
df0.head(15)
Out[18]:
In [19]:
df0.plot(figsize=(12,9))
Out[19]:
In [20]:
# Zoom in a bit
df0[0:1500].plot(figsize=(12,9))
Out[20]: