Skip to content

Commit

Permalink
Merge pull request #6 from mommermi/bib-registry
Browse files Browse the repository at this point in the history
Bib registry
  • Loading branch information
mkelley committed Jul 5, 2017
2 parents 0716524 + 3507c1c commit 0c105d6
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 5 deletions.
91 changes: 87 additions & 4 deletions sbpy/bib/bib.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,45 @@
from collections import OrderedDict
# Licensed under a 3-clause BSD style license - see LICENSE.rst
"""
================================
SBPy Biliography Tracking Module
================================
`sbpy` classes and functions can automatically report citations to the
user through a biliography registry. Use `track` to enable citation
tracking, and `citations` to report the references used.
Example
-------
>>> from sbpy import bib, data
>>> bib.track()
>>> eph = data.Ephem.from_horizons('encke')
>>> citations = bib.report()
>>> citations.to_text()
JPL Horizons:
implementation: 1996DPS....28.2504G
Classes
-------
Bib : A container for bibilography entries.
Functions
---------
register : Register a citation.
report : Report registered citations.
status : Bibliography tracking status.
stop : Stop bibliography tracking.
track : Start bibliography tracking.
__all__ = ['Bib']
"""

__all__ = ['Bib', 'register', 'report', 'status', 'stop', 'track']

from collections import OrderedDict

class Bib():
"""Bibliography class
"""Bibliography class.
References for specific tasks are provided as bibcode elements that can be queried at `ADS`_
References for specific tasks are provided as bibcode elements that can be queried at `ADS`_.
.. _ADS: http://adsabs.harvard.edu
"""
Expand Down Expand Up @@ -70,4 +104,53 @@ def to_bibtex(self):
output += '% {:s}/{:s}:\n{:s}\n'.format(ref, key, val)
return output

def register(task, citations):
"""Register a citation with the `sbpy` bibliography.
Parameters
----------
task : string
The name of the source module requesting a citation.
citations : dict
A dictionary of NASA Astrophysics Data System (ADS) bibcode(s)
to cite. The keys reference the aspect that requires citation,
e.g., `{'method': '1998Icar..131..291H'}`, or
`{'beaming parameter': '2013Icar..226.1138F'}`.
"""
global _bibliography, _track
if _track:
_bibliography[task] = citations

def report():
"""Report tracked `sbpy` citations."""
return _bibliography

def reset():
"""Reset `sbpy` bibliography tracking."""
global _bibliography
_bibliography = Bib()

def stop():
"""Disable `sbpy` bibliography tracking."""
global _track
_track = False

def status():
"""Report `sbpy` bibliography tracking status.
Returns
-------
status : bool
`True` if bibliography tracking is enabled.
"""
return _track

def track():
"""Enable `sbpy` bibliography tracking."""
global _track
_track = True

_track = False # default is no bibliography tracking
_bibliography = Bib()
5 changes: 4 additions & 1 deletion sbpy/thermal/thermal.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,7 @@ class FRM(ThermalClass):
pass

class NEATM(ThermalClass):
pass
def __init__(self):
from .. import bib
bib.register('sbpy.thermal.NEATM', {'method': '1998Icar..131..291H'})

0 comments on commit 0c105d6

Please sign in to comment.