PlanetaryImage uses three main classes: PlanetaryImage, PDS3Image, and CubeFile. PlanetaryImage is the base class for PDS3Image and CubeFile and can be inherited for other image readers. PDS3Image and CubeFile are used to read images. See Usage to see more in depth examples using PDS3Image and CubeFile.
Contents
PlanetaryImage¶
-
class
planetaryimage.image.
PlanetaryImage
(stream_string_or_array, filename=None, compression=None)[source]¶ A generic image reader. Parent object for PDS3Image and CubeFile
Parameters: stream
file object to read as an image file
filename : string
an optional filename to attach to the object
compression : string
an optional string that indicate the compression type ‘bz2’ or ‘gz’
Examples
>>> from planetaryimage import PDS3Image >>> testfile = 'tests/mission_data/2p129641989eth0361p2600r8m1.img' >>> image = PDS3Image.open(testfile) >>> # Examples of attributes >>> image.bands 1 >>> image.lines 64 >>> image.samples 64 >>> str(image.format) 'BAND_SEQUENTIAL' >>> image.data_filename >>> image.dtype dtype('>i2') >>> image.start_byte 34304 >>> image.shape (1, 64, 64) >>> image.size 4096
See https://planetaryimage.readthedocs.io/en/latest/usage.html to see how to open images to view them and make manipulations.
Attributes
compression (string) Compression type (i.e. ‘gz’, ‘bz2’, or None). data (numpy array) A numpy array representing the image. filename (string) The filename given. label (pvl module) The image’s label in dictionary form. -
bands
¶ Number of image bands.
-
data
= None¶ A numpy array representing the image
-
data_filename
¶ Return detached filename else None.
-
dtype
¶ Pixel data type.
-
filename
= None¶ The filename if given, otherwise none.
-
format
¶ Image format.
-
image
¶ An Image like array of
self.data
convenient for image processing tasks- 2D array for single band, grayscale image data
- 3D array for three band, RGB image data
Enables working with
self.data
as if it were a PIL image.See https://planetaryimage.readthedocs.io/en/latest/usage.html to see how to open images to view them and make manipulations.
-
label
= None¶ The parsed label header in dictionary form.
-
lines
¶ Number of lines per band.
-
classmethod
open
(filename)[source]¶ Read an image file from disk
Parameters: filename : string
Name of file to read as an image file. This file may be gzip (
.gz
) or bzip2 (.bz2
) compressed.
-
samples
¶ Number of samples per line.
-
shape
¶ Tuple of images bands, lines and samples.
-
size
¶ Total number of pixels
-
start_byte
¶ Index of the start of the image data (zero indexed).
-
PDS3Image¶
-
class
planetaryimage.pds3image.
PDS3Image
(stream_string_or_array, filename=None, compression=None)[source]¶ Bases:
planetaryimage.image.PlanetaryImage
A PDS3 image reader.
Examples
>>> from planetaryimage import PDS3Image >>> testfile = 'tests/mission_data/2p129641989eth0361p2600r8m1.img' >>> image = PDS3Image.open(testfile) >>> # Examples of PDS3Image Attributes >>> image.dtype dtype('>i2') >>> image.record_bytes 128 >>> image.data_filename
-
dtype
¶ Pixel data type.
-
record_bytes
¶ Number of bytes for fixed length records.
-
CubeFile¶
-
class
planetaryimage.cubefile.
CubeFile
(stream_string_or_array, filename=None, compression=None)[source]¶ Bases:
planetaryimage.image.PlanetaryImage
A Isis Cube file reader.
Examples
>>> from planetaryimage import CubeFile >>> image = CubeFile.open('tests/data/pattern.cub') >>> # Examples of CubeFile Attributes >>> image.base 0.0 >>> image.multiplier 1.0 >>> image.specials['His'] -3.4028233e+38 >>> image.tile_lines 128 >>> image.tile_samples 128 >>> image.tile_shape (128, 128)
-
apply_numpy_specials
(copy=True)[source]¶ Convert isis special pixel values to numpy special pixel values.
Isis Numpy Null nan Lrs -inf Lis -inf His inf Hrs inf Parameters: copy : bool [True]
Whether to apply the new special values to a copy of the pixel data and leave the original unaffected
Returns: Numpy Array
A numpy array with special values converted to numpy’s nan, inf, and -inf
-
apply_scaling
(copy=True)[source]¶ Scale pixel values to there true DN.
Parameters: copy: bool [True]
Whether to apply the scaling to a copy of the pixel data and leave the original unaffected
Returns: Numpy Array
A scaled version of the pixel data
-
base
¶ An additive factor by which to offset pixel DN.
-
data_filename
¶ Return detached filename else None.
-
get_image_array
()[source]¶ Create an array for use in making an image.
Creates a linear stretch of the image and scales it to between 0 and 255. Null, Lis and Lrs pixels are set to 0. His and Hrs pixels are set to 255.
Usage:
from planetaryimage import CubeFile from PIL import Image # Read in the image and create the image data image = CubeFile.open('test.cub') data = image.get_image_array() # Save the first band to a new file Image.fromarray(data[0]).save('test.png')
Returns: A uint8 array of pixel values.
-
multiplier
¶ A multiplicative factor by which to scale pixel DN.
-
specials
¶ Return the special pixel values
-
specials_mask
()[source]¶ Create a pixel map for special pixels.
Returns: An array where the value is False if the pixel is special
and True otherwise
-
tile_lines
¶ Number of lines per tile.
-
tile_samples
¶ Number of samples per tile.
-
tile_shape
¶ Shape of tiles.
-