# PDS4 -- NASA Planetary Data System (Version 4)

PDS4 is a format used primarily by NASA to store and distribute solar, lunar and planetary imagery data. GDAL provides read-write access to PDS4 formatted imagery data.

PDS4 files are compose of a .xml (label) file which references a raw imagery file. The driver also supports imagery stored in a separate uncompressed GeoTIFF file with a strip organization compatible of a raw imagery file.

The driver also reads and write georeferencing and coordinate system information as well as selected other header metadata.

If several Array objects are present in the label, they will be reported as separate subdatasets (typically the main subdataset is an Array3D, and backplanes are represented as Array2D). Creation of new datasets with subdatasets is not supported: only a single Array3D with possibly multiple bands is supported.

A mask band is attached to each source band. The value of this mask band is 0 when the pixel value is one of the missing constants.

Implementation of this driver was supported by the United States Geological Survey.

PDS4 is part of a family of related formats including PDS and ISIS3.

## Metadata

The PDS4 label can be retrieved as XML-serialized content in the xml:PDS4 metadata domain.

On creation, a source template label can be passed to the SetMetadata() interface in the "xml:PDS4" metadata domain.

## Creation support

The PDS4 driver supports updating imagery of existing datasets, creating new datasets through the CreateCopy() and Create() interfaces.

When using CreateCopy(), gdal_translate or gdalwarp, an effort is made to preserve as much as possible of the original label when doing PDS4 to PDS4 conversions. This can be disabled with the USE_SRC_LABEL=NO creation option.

The available creation options are:

- IMAGE_FILENAME=filename. Override default external image filename.
- IMAGE_EXTENSION=ext. Override default extension of the external image filename. The default is 'img' for IMAGE_FORMAT=RAW or 'tif' for IMAGE_FORMAT=GEOTIFF
- IMAGE_FORMAT=RAW/GEOTIFF. Format of the image file. If using RAW, the imagery is put in a raw file whose filename is the main filename with a .img extension. If using GEOTIFF, the imagery is put in a separate GeoTIFF file, whose filename is the main filename with a .tif extension. Defaults to RAW
- INTERLEAVE=BSQ/BIP/BIL. Pixel organization in the image file. BSQ is Band SeQuential, BIP is Band Interleaved per Pixel and BIL is Band Interleave Per Line. The default is BSQ. BIL is not valid for IMAGE_FORMAT=GEOTIFF
- VAR_*=string. If options like VAR_XXXX=yyyy are specified, any {XXXX} string in the template label will be replaced by the yyyy value.
- TEMPLATE=filename. Template label to use. If not specified and not creating from an existing PDS4 file, the data/pds4_template.xml file will be used. For GDAL utilities to find this default PDS4 template, GDAL's data directory should be defined in your environment (typically on Windows builds). Consult the wiki for more information.
- USE_SRC_LABEL=YES/NO. Whether to use the source label in PDS4 to PDS4 conversions. Defaults to YES.
- LATITUDE_TYPE=planetocentric/planetographic. Value of latitude_type. Defaults to planetocentric.
- LONGITUDE_DIRECTION=Positive East/Positive West. Value of longitude_direction. Defaults to Positive East.
- RADII=semi_major_radius,semi_minor_radius. To override the ones of the SRS. Note that the first value (semi_major_radius) will be used to set the <pds:semi_major_radius> and <pds:semi_minor_radius> XML elements, and that second value (semi_minor_radius) will be used to set the <pds:polar_radius> XML element.
- ARRAY_TYPE=Array/Array_2D/Array_2D_Image/Array_2D_Map/ Array_2D_Spectrum/Array_3D/Array_3D_Image/Array_3D_Movie/Array_3D_Spectrum. To set the XML element that defines the type of array. Defaults to Array_3D_Image. Using a Array_2D* for a multiband image is not supported. When using a Array_2D* value, INTERLEAVE will be ignored.
- BOUNDING_DEGREES=west_lon,south_lat,east_lon,north_lat. Manually set bounding box

## Examples:

- Listing bands and subdatasets:

    $ gdalinfo b0011_p237201_01_01v02.xml

    Driver: PDS4/NASA Planetary Data System 4
    Files: b0011_p237201_01_01v02.xml
           b0011_p237201_01_01v02.qub
    Size is 512, 512
    Coordinate System is `'
    Image Structure Metadata:
      INTERLEAVE=BAND
    Subdatasets:
      SUBDATASET_1_NAME=PDS4:b0011_p237201_01_01v02.xml:1:1
      SUBDATASET_1_DESC=Image file b0011_p237201_01_01v02.qub, array Spectral_Qube_Object
      SUBDATASET_2_NAME=PDS4:b0011_p237201_01_01v02.xml:1:2
      SUBDATASET_2_DESC=Image file b0011_p237201_01_01v02.qub, array iof_r2
      SUBDATASET_3_NAME=PDS4:b0011_p237201_01_01v02.xml:1:3
      SUBDATASET_3_DESC=Image file b0011_p237201_01_01v02.qub, array iof_r7
      SUBDATASET_4_NAME=PDS4:b0011_p237201_01_01v02.xml:1:4
    [...]
      SUBDATASET_16_DESC=Image file b0011_p237201_01_01v02.qub, array emission_angle
      SUBDATASET_17_NAME=PDS4:b0011_p237201_01_01v02.xml:1:17
      SUBDATASET_17_DESC=Image file b0011_p237201_01_01v02.qub, array phase_angle
      SUBDATASET_18_NAME=PDS4:b0011_p237201_01_01v02.xml:1:18
      SUBDATASET_18_DESC=Image file b0011_p237201_01_01v02.qub, array approx_incidence_angle
      SUBDATASET_19_NAME=PDS4:b0011_p237201_01_01v02.xml:1:19
      SUBDATASET_19_DESC=Image file b0011_p237201_01_01v02.qub, array approx_emission_angle
      SUBDATASET_20_NAME=PDS4:b0011_p237201_01_01v02.xml:1:20
      SUBDATASET_20_DESC=Image file b0011_p237201_01_01v02.qub, array approx_phase_angle
    Corner Coordinates:
    Upper Left  (    0.0,    0.0)
    Lower Left  (    0.0,  512.0)
    Upper Right (  512.0,    0.0)
    Lower Right (  512.0,  512.0)
    Center      (  256.0,  256.0)
    Band 1 Block=512x1 Type=Int16, ColorInterp=Undefined
      Offset: 0.146998785514825,   Scale:4.48823844390647e-06
    Band 2 Block=512x1 Type=Int16, ColorInterp=Undefined
      Offset: 0.146998785514825,   Scale:4.48823844390647e-06
    Band 3 Block=512x1 Type=Int16, ColorInterp=Undefined
      Offset: 0.146998785514825,   Scale:4.48823844390647e-06
    Band 4 Block=512x1 Type=Int16, ColorInterp=Undefined
      Offset: 0.146998785514825,   Scale:4.48823844390647e-06
    Band 5 Block=512x1 Type=Int16, ColorInterp=Undefined
      Offset: 0.146998785514825,   Scale:4.48823844390647e-06

The information displayed by default is the one of the first subdataset (SUBDATASET_1_NAME)

- Getting information on a subdataset:

    $ gdalinfo PDS4:b0011_p237201_01_01v02.xml:1:2

    Driver: PDS4/NASA Planetary Data System 4
    Files: b0011_p237201_01_01v02.xml
           b0011_p237201_01_01v02.qub
    Size is 512, 512
    Coordinate System is `'
    Corner Coordinates:
    Upper Left  (    0.0,    0.0)
    Lower Left  (    0.0,  512.0)
    Upper Right (  512.0,    0.0)
    Lower Right (  512.0,  512.0)
    Center      (  256.0,  256.0)
    Band 1 Block=512x1 Type=Int16, ColorInterp=Undefined
      Offset: 0.04984971,   Scale:7.454028e-06

- Conversion to GeoTIFF of a given subdatasets:

    $ gdal_translate PDS4:b0011_p237201_01_01v02.xml:1:2 iof_r2.tif

- Conversion to GeoTIFF of a all subdatasets:

    $ gdal_translate -sds b0011_p237201_01_01v02.xml b0011_p237201_01_01v02.tif

This will create b0011_p237201_01_01v02_X.tif files where X=1,....,N

- Creation of a new PDS4 dataset, using the default template and setting its parameterized variables:

    $ gdal_translate input.tif output.xml -of PDS4 \
                -co VAR_TARGET_TYPE=Satellite \
                -co VAR_Target=Moon \
                -co VAR_OBSERVING_SYSTEM_NAME=LOLA \
                -co VAR_LOGICAL_IDENTIFIER=Lunar_LRO_LOLA_DEM_Global_64ppd.tif \
                -co VAR_TITLE="LRO LOLA Digital Elevation Model (DEM) 64ppd" \
                -co VAR_INVESTIGATION_AREA_NAME="Lunar Reconnaissance Orbiter" \
                -co VAR_INVESTIGATION_AREA_LID_REFERENCE="urn:nasa:pds:context:instrument_host:spacecraft.lro"

- Creation of the same PDS4 dataset as above, using the default template but setting its parameterized variables from a text file. Helps with long command lines:

Create a text file "myOptions.txt" with the below content

    #This is a comment
    #Conversion parameters for the LRO LOLA dataset
    -co VAR_TARGET_TYPE=Satellite
    -co VAR_Target=Moon
    -co VAR_OBSERVING_SYSTEM_NAME=LOLA
    -co VAR_LOGICAL_IDENTIFIER=Lunar_LRO_LOLA_DEM_Global_64ppd.tif
    -co VAR_TITLE="LRO LOLA Digital Elevation Model (DEM) 64ppd"
    -co VAR_INVESTIGATION_AREA_NAME="Lunar Reconnaissance Orbiter"
    -co VAR_INVESTIGATION_AREA_LID_REFERENCE="urn:nasa:pds:context:instrument_host:spacecraft.lro"
    #end of file

    gdal_translate input.tif output.xml -of PDS4 --optfile myOptions.txt

For more on --optfile, consult the general documentation on GDAL utilities.

- Creation of a PDS4 dataset, using a non default template (here on a HTTP server, but local filename also possible):

    $ gdal_translate input.tif output.xml -of PDS4 \
                -co TEMPLATE=http://example.com/mytemplate.xml

- Creation of a PDS4 dataset from a source PDS4 dataset (using the XML file of this source PDS4 dataset as an implicit template), with subsetting:

    $ gdal_translate input.xml output.xml -of PDS4 -projwin ullx ully lrx lry

- In Python, creation of a PDS4 dataset from a GeoTIFF, using a base template into which one substitute one element with a new value:

    from osgeo import gdal
    from lxml import etree

    # Customization of template
    template = open('template.xml','rb').read()
    root = etree.XML(template)
    ns = '{http://pds.nasa.gov/pds4/pds/v1}'
    identifier = root.find(".//{ns}Identification_Area/{ns}logical_identifier".format(ns = ns))
    identifier.text = 'new_identifier'

    # Serialize the modified template in a in-memory file
    in_memory_template = '/vsimem/template.xml'
    gdal.FileFromMemBuffer(in_memory_template, etree.tostring(root))

    # Create the output dataset
    gdal.Translate('out.xml', 'in.tif', format = 'PDS4',
                   creationOptions = ['TEMPLATE='+in_memory_template])

    # Cleanup
    gdal.Unlink(in_memory_template)

## Limitations

- No support for the creation of subdatasets
- No PDS4 table support

As a new driver and new format, please report any issues to the bug tracker, as explained on the wiki

## See Also:

- Implemented as `gdal/frmts/pds/pds4dataset.cpp`.
- Official documentation
- Schemas, including the cartography extension
- GDAL PDS Driver
- GDAL ISIS3 Driver