Skip to main content

Simple pure-python AVM meta-data handling

Project description

|Build Status| |Coverage Status| |Documentation Status|


PyAVM is a module to represent, read, and write metadata following the
`*Astronomy Visualization
Metadata* <>`__ (AVM)


PyAVM supports Python 2.7 and 3.5+. No other dependencies are needed
simply to read and embed AVM meta-data.

However, the following optional dependencies are needed for more
advanced functionality:

- `Astropy <>`__ to handle WCS objects and FITS
- `py.test <>`__ and
`PIL <>`__ for tests

Installing and Reporting issues

PyAVM can be installed with pip::

pip install pyavm

Please report any issues you encounter via the `issue
tracker <>`__ on GitHub.

Using PyAVM


PyAVM provides the ``AVM`` class to represent AVM meta-data, and is
imported as follows:

.. code:: python

>>> from pyavm import AVM

Parsing files

To parse AVM meta-data from an existing image, simply call the
``from_image`` class method using the filename of the image (or any
file-like object):

.. code:: python

>>> avm = AVM.from_image('myexample.jpg')

Only JPEG and PNG files are properly supported in that the parsing
follows the JPEG and PNG specification. For other file formats, PyAVM
will simply scan the contents of the file, looking for an XMP packet.
This method is less reliable, but should work in most real-life cases.

Accessing and setting the meta-data

You can view the contents of the AVM object by using

.. code:: python

>>> print(avm)

The AVM meta-data can be accessed using the attribute notation:

.. code:: python

>>> avm.Spatial.Equinox
>>> avm.Publisher
'Chandra X-ray Observatory'

Tags can be modified:

.. code:: python

>>> avm.Spatial.Equinox = "B1950"
>>> avm.Spatial.Notes = "The WCS information was updated on 04/02/2010"

Creating an AVM object from scratch

To create an empty AVM meta-data holder, simply call ``AVM()`` without
any arguments:

.. code:: python

>>> avm = AVM()

Note that this will create an AVM object following the 1.2
specification. If necessary, you can specify which version of the
standard to use:

.. code:: python

>>> avm = AVM(version=1.1)

Converting to a WCS object

It is possible to create an Astropy WCS object from the AVM meta-data:

.. code:: python

>>> wcs = avm.to_wcs()

By default, ``Spatial.FITSheader`` will be used if available, but if
not, the WCS information is extracted from the other ``Spatial.*`` tags.
To force PyAVM to not try ``Spatial.FITSheader``, use:

.. code:: python

>>> wcs = avm.to_wcs(use_full_header=False)

Initializing from a FITS header

To create an AVM meta-data object from a FITS header, simply pass the
header (as an Astropy Header instance) to the ``from_header`` class

.. code:: python

>>> from import fits
>>> header = fits.getheader('image.fits')
>>> avm = AVM.from_header(header)

By default, the AVM tag ``Spatial.FITSheader`` will be created,
containing the full header (in addition to the other ``Spatial.*``
tags). This can be disabled with:

.. code:: python

>>> avm = AVM.from_header(header, include_full_header=False)

Initializing from a WCS object

Similarly, it is possible to create an AVM meta-data object from an
Astropy WCS instance:

.. code:: python

>>> from astropy.wcs import WCS
>>> from pyavm import AVM
>>> wcs = WCS('image.fits')
>>> avm = AVM.from_wcs(wcs)

Tagging images with AVM meta-data

It is possible to embed AVM meta-data into an image file:

.. code:: python

>>> avm.embed('original_image.jpg', 'tagged_image.jpg')

At this time, only JPG and PNG files are supported for embedding.

.. |Build Status| image::
.. |Coverage Status| image::

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

PyAVM-0.9.3.tar.gz (220.8 kB view hashes)

Uploaded source

Built Distribution

PyAVM-0.9.3-py2.py3-none-any.whl (377.8 kB view hashes)

Uploaded py2 py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page