Difference between revisions of "Python PDS4 Tools"

From The SBN Wiki
Jump to navigation Jump to search
(Created page with " == Introduction == This document describes the current status and usage of tools developed at PDS-SBN to read and visualize PDS4 data in Python. Please note that a more fea...")
 
(Added installation instructions)
Line 43: Line 43:
 
=== Intoduction ===  
 
=== Intoduction ===  
  
A Python package that can read and display PDS4 table data is available. Currently only Table_Character and Table_Binary objects are supported. In the future this tool is expected to support all PDS4 objects. The package expects labels that pass PDS4 Schema and Schematron validation, it will perform additional validation for both PDS4 Standards as well as optionally PDS-SBN standards. A PDS4 data viewer is also available for supported objects.  
+
A Python package that can read and display PDS4 table data is available. Currently only Table_Character and Table_Binary objects are supported. In the future this tool is expected to support all PDS4 objects. The package expects labels that pass PDS4 Schema and Schematron validation, it will perform additional validation for both PDS4 Standards as well as optionally some PDS-SBN standards. A PDS4 data viewer is also available for supported objects.  
  
 
Contact [[User:lnagdi1|Lev Nagdimunov]] with questions or comments regarding this code or its description.
 
Contact [[User:lnagdi1|Lev Nagdimunov]] with questions or comments regarding this code or its description.
Line 49: Line 49:
 
=== Requirements ===
 
=== Requirements ===
  
This tool assumes the user is running Python 2.6 or 2.7. There are no additional requirements to read PDS4 table data, although a recent [http://www.numpy.org/ NumPy] package can be used if installed. To visualize data Tkinter is required although it is part of the standard Python distribution for most platforms.
+
This tool assumes the user is running Python 2.6 or 2.7. There are no additional requirements to read PDS4 table data, although a recent [http://www.numpy.org/ NumPy] package can be used if installed. To visualize table data Tkinter is required although it is part of the standard Python distribution for most platforms.
 +
 
 +
=== Installation ===
 +
 
 +
==== Option 1 ====
 +
 
 +
This is the currently recommended option. You should download the ZIP file available here and extract it to a directory Python can find. To use it follow the instructions below except with the following lines first,
 +
 
 +
<pre>
 +
import sys
 +
sys.path.append("/path/to/your/extraction/directory")
 +
 
 +
import pds4_tools
 +
</pre>
 +
 
 +
==== Option 2 ====
 +
 
 +
This is option is  not recommended. You download the ZIP file available here and extract it. Then you can use the usual "python setup.py install", "pip install pds4_tools" or "easy_install pds4_tools". Note that there is no uninstall script provided, and that this code currently has many missing features and will be updated in the future.
 +
 
 +
=== Example Usage ===

Revision as of 17:53, 4 June 2015

Introduction

This document describes the current status and usage of tools developed at PDS-SBN to read and visualize PDS4 data in Python. Please note that a more feature-complete PDS4 reader and visualizer is also available in IDL here.

Reading PDS4 Images

Introduction

An example Python module that can read and display an image from a PDS4 data product is available. The code will read the data based on the label keywords, but does not otherwise validate the label. If the user wants to display the image, the code will consider the label's Display_Settings, and provide a copy of the image in the correct orientation for drawing with the origin in the lower left corner. The code below is designed for reading BOPPS BIRC images, but can be used as an example for other limited problems. A more general solution will likely use a different approach.

Contact Mike Kelley with questions or comments regarding this code or its description.

Requirements

This example assumes the user is running Python 2.7, with a recent NumPy package installed. The visualization example uses matplotlib.

Goal and Method

The goal is to read in an image from a BOPPS BIRC data product into a Numpy array, providing the correct orientation for display. We will provide a function with the name of the label, the function will then

  1. Open the label.
  2. Find the data product file name.
  3. Determine the Array_2D_Image data type and shape.
  4. Read in the data array.
  5. Return the array and meta data in a single object.

The object will have two attributes that allow access to the data

  1. the data with the axis order and orientation as provided in the file, and
  2. the data with the axis order and orientation reconfigured according to the label's Display_Settings class, so that it will have the correct orientation if drawn with the origin in the lower left corner.

Implementation Details

For this basic example, we designed the reader as a function in a module named birc_example_reader. The user calls a single function, birc.read_image(), passing the name of the label as the first argument. The function will load the label using the ElementTree module and find the first Array_2D_Image element to read in. A second function, read_pds4_array(), determines the correct data type and shape, then reads the data from the file. A class specifically designed for PDS4 Array_2D_Image objects, aptly named PDS4_Array_2D_Image, is initialized with the data, the label describing the data, and the local_identifier of the array. The local_identifier is not normally required in PDS4 array objects, but it must be present when the image display orientation is provided via Display_Settings. Since these are present in the BIRC labels, our class assumes local_identifier is included. The class then determines the image orientation. The image is stored as a class attribute data. The class attribute display_data is also provided, which can be used for displaying with the origin in the lower left corner.

Download File:Birc example reader.zip.

Minimal Working Example

Available here.

Reading PDS4 Tables

Intoduction

A Python package that can read and display PDS4 table data is available. Currently only Table_Character and Table_Binary objects are supported. In the future this tool is expected to support all PDS4 objects. The package expects labels that pass PDS4 Schema and Schematron validation, it will perform additional validation for both PDS4 Standards as well as optionally some PDS-SBN standards. A PDS4 data viewer is also available for supported objects.

Contact Lev Nagdimunov with questions or comments regarding this code or its description.

Requirements

This tool assumes the user is running Python 2.6 or 2.7. There are no additional requirements to read PDS4 table data, although a recent NumPy package can be used if installed. To visualize table data Tkinter is required although it is part of the standard Python distribution for most platforms.

Installation

Option 1

This is the currently recommended option. You should download the ZIP file available here and extract it to a directory Python can find. To use it follow the instructions below except with the following lines first,

import sys
sys.path.append("/path/to/your/extraction/directory")

import pds4_tools

Option 2

This is option is not recommended. You download the ZIP file available here and extract it. Then you can use the usual "python setup.py install", "pip install pds4_tools" or "easy_install pds4_tools". Note that there is no uninstall script provided, and that this code currently has many missing features and will be updated in the future.

Example Usage