Skip to content

Commit

Permalink
Simplify documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
khaeru committed Apr 24, 2015
1 parent d44d151 commit 643068a
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 271 deletions.
30 changes: 30 additions & 0 deletions doc/api.rst
@@ -0,0 +1,30 @@
Internals
=========

.. automodule:: gdx.api
:members:
:private-members:

Most methods in the GDX API have similar semantics:

- Names are in CamelCase, e.g. gdxMethodName.
- A list is returned; the first element is a return code.

:class:`GDX` hides these details, allowing for simpler code. Methods can be
accessed using :func:`call`. For instance, the following code calls the API
method gdxFileVersion_:

>>> g = GDX()
>>> g.call('FileVersion')

Alternately, methods can be accessed as members of :class:`GDX` objects,
where the CamelCase API names are replaced by lowercase, with underscores
separating words:

>>> g.file_version() # same as above

See :py:attr:`GDX.__valid` for the list of supported methods.

.. _`GDX API`: http://www.gams.com/dd/docs/api/expert-level/gdxqdrep.html
.. _gdxFileVersion:
http://www.gams.com/dd/docs/api/expert-level/gdxqdrep.html#gdxFileVersion
159 changes: 20 additions & 139 deletions doc/conf.py
Expand Up @@ -67,53 +67,29 @@ def __getattr__(cls, name):
# 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'

# General information about the project.
project = u'GDX-Python'
project = u'pyGDX'
copyright = u'2012–2015, Paul Natsuo Kishimoto'

# 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 = '1.0'
# The full version, including alpha/beta/rc tags.
release = '1.0'

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

# 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'
# The short X.Y version.
version = gdx.__version__
# The full version, including alpha/beta/rc tags.
release = gdx.__version__

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

# 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'

Expand All @@ -123,92 +99,28 @@ def __getattr__(cls, name):

# -- 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'

# 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
# on_rtd is whether we are on readthedocs.org, this line of code grabbed from docs.readthedocs.org
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'

# Custom sidebar templates, maps document names to template names.
#html_sidebars = {}
if not on_rtd: # only import and set the theme if we're building docs locally
import sphinx_rtd_theme
html_theme = 'sphinx_rtd_theme'
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]

# 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
# otherwise, readthedocs.org uses their theme by default, so no need to specify it

# Output file base name for HTML help builder.
htmlhelp_basename = 'GDX-Pythondoc'
htmlhelp_basename = 'pygdxdoc'


# -- Options for LaTeX output --------------------------------------------------

latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#'papersize': 'letterpaper',
'papersize': 'a5',

# The font size ('10pt', '11pt' or '12pt').
#'pointsize': '10pt',
'pointsize': '12pt',

# Additional stuff for the LaTeX preamble.
#'preamble': '',
Expand All @@ -217,63 +129,32 @@ def __getattr__(cls, name):
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'GDX-Python.tex', u'GDX-Python Documentation',
('index', 'pygdx.tex', u'pyGDX Documentation',
u'Paul Natsuo Kishimoto', '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 --------------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'gdx-python', u'GDX-Python Documentation',
('index', 'py-gdx', u'pyGDX Documentation',
[u'Paul Natsuo Kishimoto'], 1)
]

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


# -- Options for Texinfo output ------------------------------------------------

# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
('index', 'GDX-Python', u'GDX-Python Documentation',
u'Paul Natsuo Kishimoto', 'GDX-Python', 'One line description of project.',
('index', 'py-gdx', u'pyGDX Documentation',
u'Paul Natsuo Kishimoto', 'pyGDX', 'A Pythonic interface to GAMS GDX files.',
'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'

# -- Options for extensions ----------------------------------------------------
intersphinx_mapping = {
Expand Down
30 changes: 30 additions & 0 deletions doc/file.rst
@@ -0,0 +1,30 @@
gdx.File
========

.. autoclass:: gdx.File
:members:

:class:`File` is a subclass of :class:`xray.Dataset`. The GDX data is
represented as follows:

- One-dimensional GDX Sets are stored as xray *coordinates*.
- GDX Parameters and multi-dimensional GDX Sets are stored as
:class:`xray.DataArray` variables within the :class:`xray.Dataset`.
- Other information and metadata on GDX Symbols is stored as attributes of
the :class:`File`, or attributes of individual data variables or
coordinates.

Individual Symbols are thus available in one of three ways:

1. As dict-like members of the :class:`xray.Dataset`; see
http://xray.readthedocs.org/en/stable/data-structures.html#dataset:

>>> f = File('example.gdx')
>>> f['myparam']

2. As attributes of the :class:`File`:

>>> f.myparam

3. Using :func:`get_symbol_by_index`, using the index of the Symbol within
the GDX file.
85 changes: 85 additions & 0 deletions doc/gdx.rst
@@ -0,0 +1,85 @@
GDX data terminology
====================

Objects in GDX files are termed **Symbols**, and are of several types:

- **Sets** are ordered collections of labels.
- **Parameters** contain numerical data.
- **Variables** are scalar values.
- **Aliases** are alternate names for other Symbols.
- **Equations**, not currently supported by PyGDX.

For clarity (e.g., Python has a built-in class :class:`python.set`), these terms are capitalized throughout this documentation.

Both Sets and Parameters may be declared with one-dimensional Sets for each dimension. An example:

.. code-block:: none
set s 'Animals' /
a Aardvark
b Blue whale
c Chicken
d Dingo
e Elephant
f Frog
g Grasshopper
/;
set t 'Colours' /
r Red
o Orange
y Yellow
g Green
b Blue
i Indigo
v Violet
/;
set u 'Countries' /
CA Canada
US United States
CN China
JP Japan
/;
set v(s,t) 'Valid animal colours'
/ set.s.set.t yes /;
parameter p(s,t,u) 'Counts of nationalistic, colourful animals'
/ set.s.set.t.set.u 5 /;
parameter total(s) 'Total populations of each type of animal';
total(s) = sum((t, u), p(s, t, u));
execute_unload 'example.gdx';
In the resulting file `example.gdx`:

- ``s``, ``t`` and ``u`` are 1-dimensional Sets.
- ``v`` is a 2-dimensional Set, defined over the *parent* Sets ``s`` and ``t``. Any Set defined with reference to others, in this way, may include or exclude each element of the parent set. For instance, the following GAMS code defines a subset of ``u``:

.. code-block:: none
set na(u) 'North American countries' / CA, US /;
- ``p`` and ``total`` are Parameters containing numerical data.

Other concepts
--------------

The **universal Set**, ``*``, contains every element appearing in any Set in the GDX file.

- In the above example, ``*`` would contain: ``a b c d e f g r o y b i v CA US CN JP``.
- GAMS allows defining Sets and Parameters over the universal set:

.. code-block:: none
parameter new(*) 'More data';
new('L') = 3;
This would add ``L`` to the universal set.

The **descriptive text** provided on declaration of Symbols or Set elements is stored in GDX files along with the data contained in those variables.

- For Set ``v``, the string ``"Valid animal colours"``.
- For Set element ``o``, the string ``"Orange"``.

0 comments on commit 643068a

Please sign in to comment.