Testing out PlanetaryImage

In [1]:
%matplotlib inline
from glob import glob
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
from planetaryimage import PDS3Image, CubeFile
from scipy.misc import imsave    # requires pillow as well
from scipy import ndimage

Working with PDS Images

Read in a list of PDS image files.

In [2]:
pdsfiles = glob("tests/data/*.img")
images = []
for pdsfile in pdsfiles:
    images.append(PDS3Image.open(pdsfile))
    print pdsfile

images
tests/data/0044ML0205000000E1_DXXX.img
tests/data/1F345867992EFFB0J3P1212L0M1.img
tests/data/1N345854840EFFB0IEP1994L0M1.img
tests/data/1P345688456EFFB0EJP2363L2C1.img
tests/data/1p432690858esfc847p2111l2m1.img
tests/data/1p432691248esfc847p2563l2m1.img
Out[2]:
[<planetaryimage.pds3image.PDS3Image at 0x108cedd10>,
 <planetaryimage.pds3image.PDS3Image at 0x108cedd90>,
 <planetaryimage.pds3image.PDS3Image at 0x10698b590>,
 <planetaryimage.pds3image.PDS3Image at 0x108ceddd0>,
 <planetaryimage.pds3image.PDS3Image at 0x108d0a950>,
 <planetaryimage.pds3image.PDS3Image at 0x1098b30d0>]

What are the types and shapes?

In [3]:
for i in images:
    print i.data.dtype, i.data.shape, i.shape
uint8 (1200, 1648, 3) (3, 1200, 1648)
>i2 (1024, 1024) (1, 1024, 1024)
>i2 (1024, 1024) (1, 1024, 1024)
>i2 (1024, 1024) (1, 1024, 1024)
>i2 (272, 320) (1, 272, 320)
>i2 (512, 512) (1, 512, 512)

Displaying a sample Pancam and Mastcam Image

In [4]:
pancam1 = images[3]
plt.imshow(pancam1.data, cmap='gray')
Out[4]:
<matplotlib.image.AxesImage at 0x109fac850>
In [5]:
mcam1 = images[0]
plt.imshow(mcam1.data, cmap='gray')
Out[5]:
<matplotlib.image.AxesImage at 0x10a13c250>

Displaying a subframe

In [6]:
plt.imshow(mcam1.data[700:1100, 600:1000])
Out[6]:
<matplotlib.image.AxesImage at 0x10fb75090>
In [7]:
plt.imshow(np.hstack([
    mcam1.data[700:1100, 600:1000, 0],
    mcam1.data[700:1100, 600:1000, 1],
    mcam1.data[700:1100, 600:1000, 2],            
]), cmap='gray')
Out[7]:
<matplotlib.image.AxesImage at 0x10fccd210>
In [8]:
caltarget = mcam1.data[700:1100, 600:1000]
plt.imshow(caltarget)
Out[8]:
<matplotlib.image.AxesImage at 0x10fdec410>
In [9]:
imsave('caltarget.png', caltarget)
i = mpimg.imread('caltarget.png')
plt.imshow(i)
Out[9]:
<matplotlib.image.AxesImage at 0x1121f6950>

Doing some Image Processing

In [10]:
plt.hist(pancam1.data.flatten(), 4096)
Out[10]:
(array([ 56.,   2.,   5., ...,   0.,   0.,   1.]),
 array([  0.00000000e+00,   9.92431641e-01,   1.98486328e+00, ...,
          4.06301514e+03,   4.06400757e+03,   4.06500000e+03]),
 <a list of 4096 Patch objects>)
In [11]:
plt.imshow(pancam1.data, cmap='gray', vmin=1400, vmax=2500)
print pancam1.data.mean(), pancam1.data.min(), pancam1.data.max()
1894.63953018 0 4065
In [12]:
plt.imshow(ndimage.gaussian_filter(pancam1.data, 6), cmap='gray', vmin=1400, vmax=2500)
Out[12]:
<matplotlib.image.AxesImage at 0x1138a1d50>

Working with a Tiled Isis CubeFile

In [13]:
isisimage = CubeFile.open("tests/data/pattern.cub")
In [14]:
isisimage.data.dtype, isisimage.data.shape, isisimage.shape
Out[14]:
(dtype('<f4'), (90, 90), (1, 90, 90))
In [15]:
plt.imshow(isisimage.data, cmap='gray')
Out[15]:
<matplotlib.image.AxesImage at 0x114010610>
In [ ]: