Skip to content
forked from planetarypy/pvl

Python implementation of PVL (Parameter Value Language)

License

Notifications You must be signed in to change notification settings

percurnicus/pvl

 
 

Repository files navigation

pvl

https://img.shields.io/pypi/v/pvl.svg?style=flat-square https://img.shields.io/travis/planetarypy/pvl.svg?style=flat-square https://img.shields.io/pypi/dm/pvl.svg?style=flat-square

Python implementation of PVL (Parameter Value Language)

PVL is a markup language, similar to xml, commonly employed for entries in the Planetary Database System used by NASA to store mission data, among other uses. This package supports both encoding a decoding a superset of PVL, including the USGS Isis Cube Label and NASA PDS 3 Label dialects.

Installation

Can either install with pip or with conda.

To install with pip, at the command line:

$ pip install pvl

Directions for installing with conda-forge:

Installing pvl from the conda-forge channel can be achieved by adding conda-forge to your channels with:

conda config --add channels conda-forge

Once the conda-forge channel has been enabled, pvl can be installed with:

conda install pvl

It is possible to list all of the versions of pvl available on your platform with:

conda search pvl --channel conda-forge

Basic Usage

pvl exposes an API familiar to users of the standard library json module.

Decoding is primarily done through pvl.load for file like objects and pvl.loads for strings:

>>> import pvl
>>> module = pvl.loads("""
...     foo = bar
...     items = (1, 2, 3)
...     END
... """)
>>> print module
PVLModule([
  (u'foo', u'bar')
  (u'items', [1, 2, 3])
])
>>> print module['foo']
bar

You may also use pvl.load to read a label directly from an image:

>>> import pvl
>>> label = pvl.load('pattern.cub')
>>> print label
PVLModule([
  (u'IsisCube',
   PVLObject([
    (u'Core',
     PVLObject([
      (u'StartByte', 65537)
      (u'Format', u'Tile')
# output truncated...
>>> print label['IsisCube']['Core']['StartByte']
65537

Similarly, encoding pvl modules is done through pvl.dump and pvl.dumps:

>>> import pvl
>>> print pvl.dumps({
...     'foo': 'bar',
...     'items': [1, 2, 3]
... })
items = (1, 2, 3)
foo = bar
END

PVLModule objects may also be pragmatically built up to control the order of parameters as well as duplicate keys:

>>> import pvl
>>> module = pvl.PVLModule({'foo': 'bar'})
>>> module.append('items', [1, 2, 3])
>>> print pvl.dumps(module)
foo = bar
items = (1, 2, 3)
END

A PVLModule is a dict like container that preserves ordering as well as allows multiple values for the same key. It provides a similar similar semantics to a list of key/value tuples but with dict style access:

>>> import pvl
>>> module = pvl.PVLModule([
...     ('foo', 'bar'),
...     ('items', [1, 2, 3]),
...     ('foo', 'remember me?'),
... ])
>>> print module['foo']
bar
>>> print module.getlist('foo')
['bar', 'remember me?']
>>> print module.items()
[('foo', 'bar'), ('items', [1, 2, 3]), ('foo', u'remember me?')]
>>> print pvl.dumps(module)
foo = bar
items = (1, 2, 3)
foo = "remember me?"
END

For more information on custom serilization and deseralization see the full documentation.

Contributing

Feedback, issues, and contributions are always gratefully welcomed. See the contributing guide for details on how to help and setup a development environment.

About

Python implementation of PVL (Parameter Value Language)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 98.8%
  • Makefile 1.2%