Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the base folder for Serialization #18

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
918 changes: 918 additions & 0 deletions PythonSerialize/Coffee-Code-Scripts.ipynb

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions PythonSerialize/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Python Serialization (and other script fun)

## Binder

[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/OZAstroComputingResources/MQCoffee-CodeResources/python-serialize?urlpath=lab)
148 changes: 148 additions & 0 deletions PythonSerialize/Use-Planet-Config.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import yaml\n",
"import json\n",
"import numpy as np\n",
"from matplotlib import pyplot as plt\n",
"%matplotlib inline"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"planet_config = 'planet_config.yaml'"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Our convenience function (could be loaded rather than copied):\n",
"def load_config(filename):\n",
" with open(filename, 'r') as f:\n",
" my_config = yaml.safe_load(f.read())\n",
" \n",
" return my_config"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"planets = load_config(planet_config)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"planets"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## What about Bob?"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"name = 'Bob'"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"planets[name]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"for lc_json_file in planets[name]:\n",
" # Load the json data\n",
" with open(lc_json_file, 'r') as f:\n",
" lc0 = json.loads(f.read())\n",
" \n",
" plt.plot(np.array(lc0))\n",
" plt.title(name)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### All planets"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fig, ax = plt.subplots(1)\n",
"fig.set_size_inches(12, 9)\n",
"\n",
"\n",
"for name, files in planets.items():\n",
" for lc_json_file in files:\n",
" # Load the json data\n",
" with open(lc_json_file, 'r') as f:\n",
" lc0 = json.loads(f.read())\n",
"\n",
" ax.plot(np.array(lc0), label=f'{name} - {lc_json_file}')\n",
" ax.set_title(name)\n",
" ax.legend()\n",
" "
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
117 changes: 117 additions & 0 deletions PythonSerialize/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
---
######################### PANOPTES UNIT ########################################
# name: Can be anything you want it to be. This name is displayed in several
# places and should be a "personal" name for the unit.
#
# pan_id: This is an identification number assigned by the PANOPTES team and is
# the official designator for your unit. This id is used to store image
# files and communicate with the Google Cloud network.
#
# Leave the pan_id at `PAN000` for testing until you have been assigned
# an official id. Update pocs_local.yaml with offical name once received.
################################################################################
name: Generic PANOPTES Unit
pan_id: PAN000

location:
name: Mauna Loa Observatory
latitude: 19.54 # Degrees
longitude: -155.58 # Degrees
elevation: 3400.0 # Meters
horizon: 30 # Degrees; targets must be above this to be considered valid.
flat_horizon: -6 # Degrees - Flats when sun between this and focus horizon.
focus_horizon: -12 # Degrees - Dark enough to focus on stars.
observe_horizon: -18 # Degrees - Sun below this limit to observe.
timezone: US/Hawaii
gmt_offset: -600 # Offset in minutes from GMT during.
# standard time (not daylight saving).
directories:
base: /var/panoptes
images: images
data: data
resources: POCS/resources/
targets: POCS/resources/targets
mounts: POCS/resources/mounts
db:
name: panoptes
type: file
scheduler:
type: dispatch
fields_file: simple.yaml
check_file: False
mount:
brand: ioptron
model: 30
driver: ioptron
serial:
port: /dev/ttyUSB0
timeout: 0.
baudrate: 9600
non_sidereal_available: True
pointing:
auto_correct: False
threshold: 500 # arcseconds ~ 50 pixels
exptime: 30 # seconds
max_iterations: 3
cameras:
auto_detect: True
primary: 14d3bd
devices:
-
model: canon_gphoto2
-
model: canon_gphoto2
messaging:
# Must match ports in peas.yaml.
cmd_port: 6500
msg_port: 6510

########################## Observations ########################################
# An observation folder contains a contiguous sequence of images of a target/field
# recorded by a single camera, with no slewing of the mount during the sequence;
# there may be tracking adjustments during the observation.
#
# An example folder structure would be:
#
# $PANDIR/images/fields/Hd189733/14d3bd/20180901T120001/
#
# In this folder will be stored JPG and FITS images. A timelapse of the
# observation can be made (one per camera) and the JPGs optionally removed
# afterward.
#
# TODO: Add options for cleaning up old data (e.g. >30 days)
################################################################################
observations:
make_timelapse: True
keep_jpgs: True

######################## Google Network ########################################
# By default all images are stored on googlecloud servers and we also
# use a few google services to store metadata, communicate with servers, etc.
#
# See $POCS/pocs/utils/google/README.md for details about authentication.
#
# Options to change:
# image_storage: If images should be uploaded to Google Cloud Storage.
# service_account_key: Location of the JSON service account key.
################################################################################
panoptes_network:
image_storage: True
service_account_key: # Location of JSON account key
project_id: panoptes-survey
buckets:
images: panoptes-survey

#Enable to output POCS messages to social accounts
# social_accounts:
# twitter:
# consumer_key: [your_consumer_key]
# consumer_secret: [your_consumer_secret]
# access_token: [your_access_token]
# access_token_secret: [your_access_token_secret]
# slack:
# webhook_url: [your_webhook_url]
# output_timestamp: False

state_machine: simple_state_table

74 changes: 74 additions & 0 deletions PythonSerialize/scripts/argparse-lc-plotter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/usr/bin/env python

import os
import yaml
import json
import numpy as np
from matplotlib import pyplot as plt

def main(filename, planet_name, overwrite=False, verbose=False):
if verbose:
print(f'Making plot for {planet_name}')

# Our convenience function (could be loaded rather than copied):
def load_config(filename):
if verbose:
print(f'Loading {filename}')

with open(filename, 'r') as f:
my_config = yaml.safe_load(f.read())

return my_config

# Load our planet info
planets = load_config(filename)

fig, ax = plt.subplots(1)
fig.set_size_inches(12, 9)

for lc_json_file in planets[planet_name]:
# Load the json data
with open(lc_json_file, 'r') as f:
lc0 = json.loads(f.read())

ax.plot(np.array(lc0))
ax.set_title(planet_name)

plot_filename = f'plots/{planet_name.lower()}-light-curve.png'

if os.path.exists(plot_filename) is False or overwrite is True:
fig.savefig(plot_filename)
if verbose:
print(f'Plot created for {planet_name} at {plot_filename}')
else:
print(f'Plot already exists for {planet_name}, use --overwrite')

plt.close(fig)

if __name__ == '__main__':

import argparse

parser = argparse.ArgumentParser(description="Make a plot for a planet")
parser.add_argument('--config', default='planet_config.yaml',
help='Config file to use')
parser.add_argument('--planet-name', required=True,
help='Planet to plot')
parser.add_argument('--overwrite', action='store_true', default=False,
help='Overwrite any existing files, default False.')
parser.add_argument('--verbose', action='store_true', default=False, help='Verbose.')

# Load the arguments
args = parser.parse_args()

if not os.path.exists(args.config):
print("Config file does not exist:", args.config)

clean_dir = main(
filename=args.config,
planet_name=args.planet_name,
overwrite=args.overwrite,
verbose=args.verbose
)
if args.verbose:
print("Done making plot for", args.planet_name)
33 changes: 33 additions & 0 deletions PythonSerialize/scripts/lc-plotter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env python

import yaml
import json
import numpy as np
from matplotlib import pyplot as plt

planet_config = 'planet_config.yaml'
planet_name = 'Bob'

# Our convenience function (could be loaded rather than copied):
def load_config(filename):
with open(filename, 'r') as f:
my_config = yaml.safe_load(f.read())

return my_config

# Load our planet info
planets = load_config(planet_config)

fig, ax = plt.subplots(1)
fig.set_size_inches(12, 9)

for lc_json_file in planets[planet_name]:
# Load the json data
with open(lc_json_file, 'r') as f:
lc0 = json.loads(f.read())

ax.plot(np.array(lc0))
ax.set_title(planet_name)

fig.savefig(f'plots/{planet_name.lower()}-light-curve.png')
plt.close(fig)
Loading