Skip to content

Commit 792802c

Browse files
committed
Updated for scipy sphinx theme
1 parent 01b45d2 commit 792802c

10 files changed

+119
-62
lines changed

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "docs/scipy-sphinx-theme"]
2+
path = docs/scipy-sphinx-theme
3+
url = https://github.com/scipy/scipy-sphinx-theme

README.md

+8-23
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,34 @@
11
# PLSXML
22

3+
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/plsxml.svg)
34
![PyPI](https://img.shields.io/pypi/v/plsxml.svg)
45
[![Build Status](https://travis-ci.com/line-mind/plsxml.svg?branch=master)](https://travis-ci.com/line-mind/plsxml)
56
[![Documentation Status](https://readthedocs.org/projects/plsxml/badge/?version=latest)](https://plsxml.readthedocs.io/en/latest/?badge=latest)
67
[![codecov](https://codecov.io/gh/line-mind/plsxml/branch/master/graph/badge.svg)](https://codecov.io/gh/line-mind/plsxml)
78

89

9-
## Contents
10-
11-
### API Contents
12-
13-
* [About](#about)
14-
* [Installation](#installation)
15-
* [Example Usage](#example-usage)
16-
17-
### Developer Contents
18-
19-
* [Local Testing](#local-testing)
20-
21-
### Module Contents
10+
## Table of Contents
2211

2312
* [PLSXML](plsxml.rst)
24-
* [Data Loader](data.rst)
25-
26-
## API Notes
13+
* [Data](data.rst)
2714

28-
### About
15+
## About
2916

3017
This package provides a class for parsing PLS-CADD XML files to dictionaries and `pandas` data frames. It is also capable of converting elements with 'units' attributes to `astropy` quantities, though currently this package may not be able to handle all units.
3118

32-
### Installation
19+
## Installation
3320

3421
This package may be installed via pip:
3522

3623
```
3724
pip install plsxml
3825
```
3926

40-
### Example Usage
41-
42-
See [example.ipynb](example.ipynb) for example usages of this package.
27+
## Example Usage
4328

44-
## Developer Notes
29+
See [example.ipynb](https://github.com/line-mind/plsxml/blob/master/example.ipynb) for example usages of this package.
4530

46-
### Local Testing
31+
## Local Testing
4732

4833
Testing is performed using `pytest` and `pytest-cov`. To test the package locally,
4934
run the following command from the root directory:

docs/conf.py

+26-6
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ def write_index():
8585
'sphinx.ext.githubpages',
8686
]
8787

88-
numpydoc_show_inherited_class_members = False
89-
9088
# Add any paths that contain templates here, relative to this directory.
9189
templates_path = ['_templates']
9290

@@ -113,7 +111,7 @@ def write_index():
113111
# List of patterns, relative to source directory, that match files and
114112
# directories to ignore when looking for source files.
115113
# This pattern also affects html_static_path and html_extra_path .
116-
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
114+
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', 'scipy-sphinx-theme/*']
117115

118116
# The name of the Pygments (syntax highlighting) style to use.
119117
pygments_style = 'sphinx'
@@ -124,8 +122,30 @@ def write_index():
124122
# The theme to use for HTML and HTML Help pages. See the documentation for
125123
# a list of builtin themes.
126124
#
127-
html_theme = 'sphinx_rtd_theme'
128-
html_theme_path = ['_themes']
125+
themedir = os.path.join(os.path.dirname(__file__), 'scipy-sphinx-theme', '_theme')
126+
if not os.path.isdir(themedir):
127+
raise RuntimeError('Get the scipy-sphinx-theme first, '
128+
'via git submodule init && git submodule update')
129+
130+
131+
html_theme = 'scipy'
132+
html_theme_path = [themedir]
133+
134+
# numpydoc settings
135+
numpydoc_show_class_members = False
136+
numpydoc_show_inherited_class_members = False
137+
class_members_toctree = False
138+
139+
html_theme_options = {
140+
"edit_link": False,
141+
"sidebar": "left",
142+
"scipy_org_logo": False,
143+
"rootlinks": []
144+
}
145+
html_sidebars = {}
146+
147+
html_title = "%s v%s Manual" % (project, version)
148+
html_last_updated_fmt = '%b %d, %Y'
129149

130150
# Theme options are theme-specific and customize the look and feel of a theme
131151
# further. For a list of options available for each theme, see the
@@ -224,6 +244,6 @@ def write_index():
224244
def setup(app):
225245
app.add_config_value('recommonmark_config', {
226246
'url_resolver': lambda url: github_doc_root + url,
227-
'auto_toc_tree_section': 'Module Contents',
247+
'auto_toc_tree_section': 'Table of Contents',
228248
}, True)
229249
app.add_transform(AutoStructify)

docs/scipy-sphinx-theme

Submodule scipy-sphinx-theme added at d990ab9

example.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"source": [
6565
"## Listing Keys\n",
6666
"\n",
67-
"Calling the `PLSXML.keys()` method will provide a list of parsed tables, keys, and example data. This may be useful when determining which tables and data you want to work with. An example output is below:"
67+
"Calling the `table_summary` method will provide a list of parsed tables, keys, and example data. This may be useful when determining which tables and data you want to work with. An example output is below:"
6868
]
6969
},
7070
{

plsxml/data/__init__.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
2-
=================================
3-
Data Loaders (:mod:`plsxml.data`)
4-
=================================
2+
=========================
3+
Data (:mod:`plsxml.data`)
4+
=========================
55
66
.. automodule:: plsxml.data.loader
77
:members:

plsxml/data/loader.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
"""
2-
The PLSXML data module contains sample and test data.
2+
Summary
3+
-------
4+
The PLSXML data module contains methods for accessing sample and test data.
5+
6+
Global Variables
7+
----------------
8+
DATA_FOLDER
9+
The absolute path to the data directory.
10+
11+
Methods
12+
-------
13+
314
"""
415

516
import os

plsxml/plsxml.py

+59-25
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
11
"""
2+
Summary
3+
-------
24
The PLSXML module contains a class for parsing PLS-CADD XML files.
5+
6+
Classes
7+
-------
8+
39
"""
410

511
import ast
612
from collections import OrderedDict
7-
import xml.etree.ElementTree as et
13+
import xml.etree.cElementTree as et
814
import pandas as pd
915
import astropy.units as u
1016
u.imperial.enable()
1117

1218

1319
class PLSXML(OrderedDict):
1420
"""
15-
A class for parsing PLS-CADD XML files. Data can be accessed using
16-
via table name -> row index -> column name. Example:
17-
18-
.. code::
19-
20-
PLSXML['galloping_ellipses_summary'][0]['phase']
21-
21+
A class for parsing PLS-CADD XML files.
2222
2323
Parameters
2424
----------
25-
source : str or list
25+
source : str or list, default is None
2626
A string or list of strings defining the XML file path(s).
2727
If None, then no tables will be parsed.
28-
tables : list
28+
tables : list, default is None
2929
A list of strings defining the table names to be loaded from the
3030
referenced XML files. If None, then all tables in the XML files
3131
will be parsed.
32-
parse_units : bool
32+
parse_units : bool, default is False
3333
If True, elements with the 'units' attribute will attempt to be
3434
converted to Astropy quantities. This operation takes longer so could
3535
be disabled if including units is unimportant to you.
36-
print_statuses : bool
36+
print_statuses : bool, default is False
3737
If True, status messages will be printed during the parsing process.
3838
This can be useful to see the progress of long XML files.
3939
@@ -50,11 +50,45 @@ class PLSXML(OrderedDict):
5050
--------
5151
>>> from plsxml import PLSXML
5252
>>> from plsxml.data import data_path
53+
54+
To load data from the intializer:
55+
5356
>>> path = data_path('galloping')
5457
>>> xml = PLSXML(path, parse_units = True)
58+
59+
You can add files after the initialization via the `append` method:
60+
61+
>>> xml = PLSXML(parse_units = True)
62+
>>> xml.append(path)
63+
64+
The class is a subclass of an OrderedDict. Once loaded, data can be accessed
65+
via table name > row index > column name:
66+
5567
>>> xml['galloping_ellipses_summary'][0]['minimum_clearance_galloping_ellipse_method']
5668
'Single mid span'
5769
70+
A summary of keys can be acquired via the `table_summary` method:
71+
72+
>>> print(xml.table_summary())
73+
galloping_ellipses_summary
74+
rowtext None
75+
structure 'TERM'
76+
set 1
77+
phase 1
78+
ahead_span_length 258.2 ft
79+
minimum_clearance_set 1
80+
minimum_clearance_phase 2
81+
minimum_clearance_galloping_ellipse_method 'Single mid span'
82+
minimum_clearance_distance 1.52 ft
83+
minimum_clearance_overlap 0.0
84+
minimum_clearance_wind_from 'Left'
85+
minimum_clearance_mid_span_sag 12.15 ft
86+
minimum_clearance_insulator_swing_angle 0.0 deg
87+
minimum_clearance_span_swing_angle 63.1 deg
88+
minimum_clearance_major_axis_length 16.2 ft
89+
minimum_clearance_minor_axis_length 6.5 ft
90+
minimum_clearance_b_distance 3.0 ft
91+
5892
"""
5993
def __init__(self, source = None, tables = None, parse_units = False, print_statuses = False):
6094
self.parse_units = parse_units
@@ -66,7 +100,7 @@ def __init__(self, source = None, tables = None, parse_units = False, print_stat
66100
for x in source:
67101
self.append(x, tables)
68102

69-
def drop_duplicates(self, data):
103+
def _drop_duplicates(self, data):
70104
"""Drops duplicates from list of dictionaries in place."""
71105
oset = set()
72106
drop_indices = []
@@ -81,14 +115,14 @@ def drop_duplicates(self, data):
81115
for i in reversed(drop_indices):
82116
del data[i]
83117

84-
def convert_type(self, data):
118+
def _convert_type(self, data):
85119
"""Converts data into appropriate type if it can."""
86120
try:
87121
return ast.literal_eval(data)
88122
except:
89123
return data
90124

91-
def clean_unit(self, unit):
125+
def _clean_unit(self, unit):
92126
"""Attemps to replace characters and units that astrpoy cannot understand."""
93127
repl = {
94128
'-' : ' ',
@@ -113,12 +147,12 @@ def append(self, source, tables = None):
113147
----------
114148
source : str
115149
A string defining the XML file path.
116-
tables: list
150+
tables : list, default is None
117151
A list of strings defining the table names to be loaded from the
118152
referenced XML file. If None, then all tables in the XML file
119153
will be parsed.
120154
"""
121-
self.print('Parsing:', source)
155+
self._print('Parsing:', source)
122156
messages = set()
123157
exist_tables = set(self.keys())
124158
new_tables = set()
@@ -140,15 +174,15 @@ def append(self, source, tables = None):
140174
table = elem.attrib['tagname']
141175
titledetail = elem.attrib['titledetail']
142176
new_tables.add(table)
143-
self.print('Loading:', table)
177+
self._print('Loading:', table)
144178
if table not in self.keys():
145179
self[table] = []
146180

147181
elif table is not None and obj is None and elem.tag != 'source_file':
148182
obj = elem.tag
149183
odict = OrderedDict()
150184
if titledetail not in (None, ''):
151-
odict['titledetail'] = self.convert_type(titledetail)
185+
odict['titledetail'] = self._convert_type(titledetail)
152186

153187
elif event == 'end':
154188
if elem.tag == 'table':
@@ -161,10 +195,10 @@ def append(self, source, tables = None):
161195
obj = None
162196

163197
elif obj != None:
164-
v = self.convert_type(elem.text)
198+
v = self._convert_type(elem.text)
165199
if self.parse_units and type(v) != str and 'units' in elem.attrib:
166200
try:
167-
unit = self.clean_unit(elem.attrib['units'])
201+
unit = self._clean_unit(elem.attrib['units'])
168202
v *= u.Unit(unit)
169203
except:
170204
messages.add('Unit {!r} could not be parsed.'.format(elem.attrib['units']))
@@ -175,13 +209,13 @@ def append(self, source, tables = None):
175209
new_tables &= exist_tables
176210

177211
for key in new_tables:
178-
self.print('Dropping Duplicates:', key)
179-
self.drop_duplicates(self[key])
212+
self._print('Dropping Duplicates:', key)
213+
self._drop_duplicates(self[key])
180214

181215
if messages:
182216
print('\n'.join(messages))
183217

184-
def print(self, *args):
218+
def _print(self, *args):
185219
"""Prints the message if print_statuses is True."""
186220
if self.print_statuses:
187221
print(*args)
@@ -204,7 +238,7 @@ def dataframes(self, tables = None):
204238
205239
Parameters
206240
----------
207-
tables : list
241+
tables : list, default is None
208242
A list of strings defining the table names for which dataframes
209243
will be created. If None, then all tables parsed in the object
210244
will be converted.

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ codecov>=2.0.15
1010
jinja2>=2.10
1111
recommonmark>=0.4.0
1212
docutils==0.14
13+
numpydoc>=0.8.0

setup.cfg

+5-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ version = 0.0.1
88
author = Matt Pewsey
99
author_email = [email protected]
1010
copyright = 2018, Matt Pewsey
11-
description = Parse PLS-CADD XML files.
11+
description = Parse PLS-CADD XML files to dictionaries and data frames.
1212
long_description = file: README.md
1313
long_description_content_type = text/markdown
1414
license = BSD 3-Clause License
@@ -17,11 +17,12 @@ url = https://github.com/line-mind/plsxml
1717
keywords =
1818
pls-cadd
1919
xml-parser
20-
transmission-line
2120
classifiers =
22-
Programming Language :: Python :: 3
21+
Programming Language :: Python :: 3.5
22+
Programming Language :: Python :: 3.6
2323
Operating System :: OS Independent
2424
License :: OSI Approved :: BSD License
25+
Development Status :: 5 - Production/Stable
2526

2627
[options]
2728
packages = find:
@@ -40,3 +41,4 @@ docs =
4041
jinja2>=2.10
4142
recommonmark>=0.4.0
4243
docutils==0.14
44+
numpydoc>=0.8.0

0 commit comments

Comments
 (0)