%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
Read in a list of PDS image files.
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
[<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?
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
pancam1 = images[3]
plt.imshow(pancam1.data, cmap='gray')
<matplotlib.image.AxesImage at 0x109fac850>
mcam1 = images[0]
plt.imshow(mcam1.data, cmap='gray')
<matplotlib.image.AxesImage at 0x10a13c250>
Displaying a subframe
plt.imshow(mcam1.data[700:1100, 600:1000])
<matplotlib.image.AxesImage at 0x10fb75090>
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')
<matplotlib.image.AxesImage at 0x10fccd210>
caltarget = mcam1.data[700:1100, 600:1000]
plt.imshow(caltarget)
<matplotlib.image.AxesImage at 0x10fdec410>
imsave('caltarget.png', caltarget)
i = mpimg.imread('caltarget.png')
plt.imshow(i)
<matplotlib.image.AxesImage at 0x1121f6950>
plt.hist(pancam1.data.flatten(), 4096)
(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>)
plt.imshow(pancam1.data, cmap='gray', vmin=1400, vmax=2500)
print pancam1.data.mean(), pancam1.data.min(), pancam1.data.max()
1894.63953018 0 4065
plt.imshow(ndimage.gaussian_filter(pancam1.data, 6), cmap='gray', vmin=1400, vmax=2500)
<matplotlib.image.AxesImage at 0x1138a1d50>
isisimage = CubeFile.open("tests/data/pattern.cub")
isisimage.data.dtype, isisimage.data.shape, isisimage.shape
(dtype('<f4'), (90, 90), (1, 90, 90))
plt.imshow(isisimage.data, cmap='gray')
<matplotlib.image.AxesImage at 0x114010610>