planetarypy / planetaryimage

Python PDS and Isis Cube file parser.
BSD 3-Clause "New" or "Revised" License
39 stars 20 forks source link

Write sample new file support test #10

Closed godber closed 9 years ago

godber commented 9 years ago

Every file/mission type we claim to support must have a minimal test implemented. Please implement one of these tests for a PDS3 pancam product. It should be roughly

# -*- coding: utf-8 -*-
import pytest
import os
import numpy
from numpy.testing import assert_almost_equal
from planetaryimage.pds3image import PDS3Image

DATA_DIR = os.path.join(os.path.dirname(__file__), 'data/')

def test_pds3_pancam():
    filename = os.path.join(DATA_DIR, '1P....IMG')
    image = PDS3Image.open(filename)

    assert image.format == 'BAND_SEQUENTIAL'
    assert image.pixel_type == numpy.dtype('int16')
    assert image.dtype == numpy.dtype('>i2')

    expected = numpy.loadtxt(
        os.path.join(DATA_DIR, 'pds3_pancam.txt')).reshape(1, 10, 10)
    assert_almost_equal(image.data[20:30,20:30], expected)
godber commented 9 years ago

Lets also write some documentation pointing out the presence of this test and explaining that it is an example for what is needed for claiming support of a particular data product type.

godber commented 9 years ago

Actually, these tests should be data driven. We should have a mission_data.json file that contains URLs to data products and a standard set of test data: label entries and small subarrays that can be validated. Basically these tests should use JSON that looks like this:

{
    "1p432690858esfc847p2111l2m1.img": {
        "url": "http://...",
                "label": {
                        "IMAGE": {
                                "BANDS": 3
                        }
                },
                "data_location": [100, 101, 200, 201],
                "data_value": [
                        [193, 194],
                        [194, 195],
                ]
    },
}

The JSON file and retrieval code should be implemented in the following package: https://github.com/planetarypy/planetary_test_data

I guess the tests themselves should be implemented within this planetaryimage package itself. Though they shouldn't run with the normal unit tests.