Skip to content

Commit

Permalink
Change to 'pull_isotime' convenience function - now returns UTC datet…
Browse files Browse the repository at this point in the history
…imes.

Also, improvements to docs / tox.
  • Loading branch information
timstaley committed Nov 3, 2015
1 parent 46d50a3 commit 7544a5a
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 174 deletions.
2 changes: 1 addition & 1 deletion documentation/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#

# You can set these variables from the command line.
SPHINXOPTS =
SPHINXOPTS = -W
SPHINXBUILD = $(shell which python) $(shell which sphinx-build)
PAPER =
BUILDDIR = build
Expand Down
2 changes: 1 addition & 1 deletion documentation/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
lxml>=2.3
sphinxcontrib-napoleon
sphinx>=1.3
sphinx_rtd_theme #If building locally.

154 changes: 2 additions & 152 deletions documentation/source/conf.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,17 @@
# -*- coding: utf-8 -*-
#
# VOEvent-parse documentation build configuration file, created by
# sphinx-quickstart on Mon Jan 14 15:58:36 2013.
#
# This file is execfile()d with the current directory set to its containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
#
# All configuration values have a default; values that are commented out
# serve to show the default.

import sys, os
import voeventparse

# 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.
#sys.path.insert(0, os.path.abspath('.'))

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

# If your documentation needs a minimal Sphinx version, state it here.
#needs_sphinx = '1.0'
needs_sphinx = '1.3'

# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.intersphinx', 'sphinx.ext.todo',
'sphinx.ext.coverage', 'sphinx.ext.viewcode',
'sphinxcontrib.napoleon']
'sphinx.ext.napoleon']


# Add any paths that contain templates here, relative to this directory.
Expand All @@ -37,8 +20,6 @@
# The suffix of source filenames.
source_suffix = '.rst'

# The encoding of source files.
#source_encoding = 'utf-8-sig'

# The master toctree document.
master_doc = 'index'
Expand All @@ -47,56 +28,18 @@
project = u'voevent-parse'
copyright = u'2013,2014 Tim Staley'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = voeventparse._nominal_version
# The full version, including alpha/beta/rc tags.
release = version

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#language = None

# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
#today = ''
# Else, today_fmt is used as the format for a strftime call.
#today_fmt = '%B %d, %Y'

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
exclude_patterns = []

# The reST default role (used for this markup: `text`) to use for all documents.
#default_role = None

# If true, '()' will be appended to :func: etc. cross-reference text.
#add_function_parentheses = True

# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
#add_module_names = True

# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
#show_authors = False

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'

# A list of ignored prefixes for module index sorting.
#modindex_common_prefix = []


# -- Options for HTML output ---------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
# html_theme = 'default'
# html_theme = 'nature'

# on_rtd is whether we are on readthedocs.org
import os
Expand All @@ -109,75 +52,11 @@

# otherwise, readthedocs.org uses their theme by default, so no need to specify it

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#html_theme_options = {}

# Add any paths that contain custom themes here, relative to this directory.
#html_theme_path = []

# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
#html_title = None

# A shorter title for the navigation bar. Default is the same as html_title.
#html_short_title = None

# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
#html_logo = None

# The name of an image file (within the static path) to use as favicon of the
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
#html_favicon = None

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']

# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
#html_last_updated_fmt = '%b %d, %Y'

# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
#html_use_smartypants = True

# Custom sidebar templates, maps document names to template names.
#html_sidebars = {}

# Additional templates that should be rendered to pages, maps page names to
# template names.
#html_additional_pages = {}

# If false, no module index is generated.
#html_domain_indices = True

# If false, no index is generated.
#html_use_index = True

# If true, the index is split into individual pages for each letter.
#html_split_index = False

# If true, links to the reST sources are added to the pages.
#html_show_sourcelink = True

# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
#html_show_sphinx = True

# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
#html_show_copyright = True

# If true, an OpenSearch description file will be output, and all pages will
# contain a <link> tag referring to it. The value of this option must be the
# base URL from which the finished HTML is served.
#html_use_opensearch = ''

# This is the file name suffix for HTML files (e.g. ".xhtml").
#html_file_suffix = None

# Output file base name for HTML help builder.
htmlhelp_basename = 'VOEvent-parsedoc'
Expand All @@ -203,26 +82,6 @@
u'Tim Staley', 'manual'),
]

# The name of an image file (relative to this directory) to place at the top of
# the title page.
#latex_logo = None

# For "manual" documents, if this is true, then toplevel headings are parts,
# not chapters.
#latex_use_parts = False

# If true, show page references after internal links.
#latex_show_pagerefs = False

# If true, show URL addresses after external links.
#latex_show_urls = False

# Documents to append as an appendix to all manuals.
#latex_appendices = []

# If false, no module index is generated.
#latex_domain_indices = True


# -- Options for manual page output --------------------------------------------

Expand All @@ -248,15 +107,6 @@
'Miscellaneous'),
]

# Documents to append as an appendix to all manuals.
#texinfo_appendices = []

# If false, no module index is generated.
#texinfo_domain_indices = True

# How to display URL addresses: 'footnote', 'no', or 'inline'.
#texinfo_show_urls = 'footnote'


# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {'http://docs.python.org/': None}
Expand Down
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

setup(
name="voevent-parse",
version="0.8.3",
version="0.9.0",
packages=['voeventparse', 'voeventparse.tests', 'voeventparse.tests.resources'],
package_data={'voeventparse':['tests/resources/*.xml']},
description="Convenience routines for parsing and manipulation of "
Expand All @@ -13,7 +13,8 @@
author_email="timstaley337@gmail.com",
url="https://github.com/timstaley/voevent-parse",
install_requires=["lxml>=2.3, <4.0",
'six'
'six',
'iso8601',
],
test_suite='voeventparse.tests'
)
8 changes: 4 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ deps =
nose

[testenv:docs]
basepython=python
changedir=documentation
deps=-rdocumentation/requirements.txt
deps=
sphinx
commands=
sphinx-build -W -b html -d {envtmpdir}/doctrees source {envtmpdir}/html
pip install -e .
sphinx-build -W -b html -d {envtmpdir}/doctrees documentation/source {envtmpdir}/html
34 changes: 22 additions & 12 deletions voeventparse/convenience.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
"""Convenience routines for common actions on VOEvent objects"""

from __future__ import absolute_import
import datetime
import iso8601
import lxml
from voeventparse.misc import (Param, Group, Reference, Inference, Position2D,
Citation)



def pull_astro_coords(voevent, index=0):
"""Extracts the `AstroCoords` from a given `WhereWhen.ObsDataLocation`.
Expand All @@ -21,8 +22,8 @@ def pull_astro_coords(voevent, index=0):
index (int): Index of the ObsDataLocation to extract AstroCoords from.
Returns:
:py:class:`.Position2D`: The sky position defined in the
ObsDataLocation.
Position (:py:class:`.Position2D`): The sky position defined in the
ObsDataLocation.
"""
od = voevent.WhereWhen.ObsDataLocation[index]
ac = od.ObservationLocation.AstroCoords
Expand All @@ -45,33 +46,41 @@ def pull_isotime(voevent, index=0):
Accesses a `WhereWhere.ObsDataLocation.ObservationLocation`
element and returns the AstroCoords.Time.TimeInstant.ISOTime element,
converted to a datetime.
converted to a (UTC-timezoned) datetime.
Note that a packet may include multiple 'ObsDataLocation' entries
under the 'WhereWhen' section, for example giving locations of an object
moving over time. Most packets will have only one, however, so the
default is to access the first.
.. warning::
This function currently only works with UTC time-system coords.
Future updates may implement conversion from other systems (TT, GPS)
using astropy functionality.
Args:
voevent (:class:`voeventparse.voevent.Voevent`): Root node of the VOevent
etree.
index (int): Index of the ObsDataLocation to extract an ISOtime from.
Returns:
:class:`datetime.datetime`: Specifically, we return a standard library
datetime object, i.e. one that is **timezone-naive** (that is,
agnostic about its timezone, see python docs).
This avoids an added dependency on pytz.
isotime (:class:`datetime.datetime`): Datetime object as parsed by
`iso8601`_ (with UTC timezone).
The details of the reference system for time and space are provided
in the AstroCoords object, but typically time reference is UTC.
.. _iso8601: https://pypi.python.org/pypi/iso8601/
"""
try:
od = voevent.WhereWhen.ObsDataLocation[index]
ol = od.ObservationLocation
coord_sys = ol.AstroCoords.attrib['coord_system_id']
if coord_sys.split('-')[0] != 'UTC':
raise NotImplementedError(
'Loading from time-systems other than UTC not yet implemented'
)
isotime_str = str(ol.AstroCoords.Time.TimeInstant.ISOTime)
return datetime.datetime.strptime(isotime_str, "%Y-%m-%dT%H:%M:%S.%f")
return iso8601.parse_date(isotime_str)
except AttributeError:
return None

Expand All @@ -82,7 +91,8 @@ def pull_params(voevent):
Args:
voevent (:class:`voeventparse.voevent.Voevent`): Root node of the VOevent etree.
Returns:
Nested dict: Mapping of ``Group->Param->Attribs``. Access like so::
Nested dict (dict): Mapping of ``Group->Param->Attribs``.
Access like so::
foo_param_val = what_dict['GroupName']['ParamName']['value']
Expand Down
4 changes: 2 additions & 2 deletions voeventparse/voevent.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def loads(s, check_version=True):
check_version (bool): (Default=True) Checks that the VOEvent is of a
supported schema version - currently only v2.0 is supported.
Returns:
Root-node of the :class:`Voevent` etree.
voevent (:py:class:`Voevent`): Root-node of the etree.
Raises:
exceptions.ValueError
Expand Down Expand Up @@ -112,7 +112,7 @@ def load(file, check_version=True):
check_version (bool): (Default=True) Checks that the VOEvent is of a
supported schema version - currently only v2.0 is supported.
Returns:
Root-node of the :class:`Voevent` etree.
voevent (:py:class:`Voevent`): Root-node of the etree.
"""
s = file.read()
return loads(s, check_version)
Expand Down

0 comments on commit 7544a5a

Please sign in to comment.