Skip to content

Commit

Permalink
Proper API for readthedocs
Browse files Browse the repository at this point in the history
  • Loading branch information
kboone committed Apr 22, 2019
1 parent 191c8f2 commit 491455e
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 51 deletions.
3 changes: 2 additions & 1 deletion avocado/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from .astronomical_object import AstronomicalObject
from .astronomical_object import *
from .dataset import *
68 changes: 66 additions & 2 deletions avocado/astronomical_object.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pandas as pd

class AstronomicalObject(object):
class AstronomicalObject():
"""Class representing an astronomical object.
An astronomical object has both metadata describing its global properties,
Expand Down Expand Up @@ -33,8 +33,72 @@ class AstronomicalObject(object):
- flux: The measured flux value of the observation.
- flux_err: The flux measurement uncertainty of the observation.
"""

def __init__(self, metadata, observations):
"""Create a new AstronomicalObject"""
self.metadata = metadata
self.observations = observations

def _get_gp_data(self, object_meta, object_data, fix_background=True):
times = []
fluxes = []
bands = []
flux_errs = []
wavelengths = []

# The zeropoints were arbitrarily set from the first image. Pick the
# 20th percentile of all observations in each channel as a new
# zeropoint. This has good performance when there are supernova-like
# bursts in the image, even if they are quite wide.
# UPDATE: when picking the 20th percentile, observations with just
# noise get really messed up. Revert back to the median for now and see
# if that helps. It doesn't really matter if supernovae go slightly
# negative...
# UPDATE 2: most of the objects of interest are short-lived in time.
# The only issue with the background occurs when there was flux from
# the transient in the reference image. To deal with this, look at the
# last observations and see if they are negative (indicating that the
# reference has additional flux in it). If so, then update the
# background level. Otherwise, leave the background at the reference
# level.
for passband in range(num_passbands):
band_data = object_data[object_data['passband'] == passband]
if len(band_data) == 0:
# No observations in this band
continue

# Use a biweight location to estimate the background
ref_flux = biweight_location(band_data['flux'])

for idx, row in band_data.iterrows():
times.append(row['mjd'] - start_mjd)
flux = row['flux']
if fix_background:
flux = flux - ref_flux
bands.append(passband)
wavelengths.append(band_wavelengths[passband])
fluxes.append(flux)
flux_errs.append(row['flux_err'])

times = np.array(times)
bands = np.array(bands)
wavelengths = np.array(wavelengths)
fluxes = np.array(fluxes)
flux_errs = np.array(flux_errs)

# Guess the scale based off of the highest signal-to-noise point.
# Sometimes the edge bands are pure noise and can have large
# insignificant points. Add epsilon to this calculation to avoid divide
# by zero errors for model fluxes that have 0 error.
scale = fluxes[np.argmax(fluxes / (flux_errs + 1e-5))]

gp_data = {
'meta': object_meta,
'times': times,
'bands': bands,
'scale': scale,
'wavelengths': wavelengths,
'fluxes': fluxes,
'flux_errs': flux_errs,
}

return gp_data
3 changes: 3 additions & 0 deletions avocado/dataset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

class Dataset():
"""Class representing a dataset of many astronomical objects."""
7 changes: 0 additions & 7 deletions docs/api/avocado.astronomical_object.rst

This file was deleted.

7 changes: 0 additions & 7 deletions docs/api/avocado.plasticc.rst

This file was deleted.

17 changes: 0 additions & 17 deletions docs/api/avocado.rst

This file was deleted.

7 changes: 0 additions & 7 deletions docs/api/avocado.settings.rst

This file was deleted.

20 changes: 11 additions & 9 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@
# list see the documentation:
# http://www.sphinx-doc.org/en/master/config

# -- Path setup --------------------------------------------------------------
import os
import sys

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))
# -- Path setup --------------------------------------------------------------

# Generate api directory if it doesn't already exist
if not os.path.exists('api'):
os.mkdir('api')

# -- Project information -----------------------------------------------------

Expand All @@ -24,7 +22,6 @@
# The full version, including alpha/beta/rc tags
release = '0.1'


# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
Expand All @@ -37,6 +34,11 @@
'numpydoc',
]

numpydoc_show_class_members = False
autosummary_generate = ["reference.rst"]
autoclass_content = "class"
autodoc_default_flags = ["members", "no-special-members"]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Welcome to avocado's documentation!
:maxdepth: 2
:caption: Contents:


reference

Indices and tables
==================
Expand Down
20 changes: 20 additions & 0 deletions docs/reference.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Reference / API
===============

.. currentmodule:: avocado

Dataset
=======

.. autosummary::
:toctree: api

Dataset

AstronomicalObject
==================

.. autosummary::
:toctree: api

AstronomicalObject

0 comments on commit 491455e

Please sign in to comment.