MarsImage Introduction#

from marsimage import MarsImage
from marsimage.download import download_pds3

Download an example image from the PDS#

pds_img = 'https://planetarydata.jpl.nasa.gov/img/data/msl/MSLMHL_0029/DATA/RDR/SURFACE/3215/3215MH0008300011103206C00_DRXX.IMG'

image = download_pds3(pds_img, 'temp/')

Load the image#

This will load the PDS image file and display a short metadata summary and preview.

We can also automatically crop away the black border on the left:

img = MarsImage(image)

# original MAHLI image
display(img)

# cropped MAHLI image
img.process(crop=True)
display(img)
Filename3215MH0008300011103206C00_DRXX.IMG
MissionMARS SCIENCE LABORATORY
InstrumentMARS HAND LENS IMAGER CAMERA
FilterN/A
Image Size1632 x 1200
Image Subframe[1, 1, 1632, 1200]
TargetMARS
Date UTC2021-08-22 10:26:52
Mission DateSol-03215M11:05:09.188
Solar Elevation58.6°
Solar Azimuth17.7°
Exposure Time0.0063s
Site, Drive90, 2630
Camera Position137.398°E, -4.7442°N
Yaw, Pitch, Roll-110.3°, -78.8°, 10.0°
RationalePhobos shine experiment - roverremote sensing mast (RSM) - daylight context image - manual focus assumes ~3 meter standoff
Filename3215MH0008300011103206C00_DRXX.IMG
MissionMARS SCIENCE LABORATORY
InstrumentMARS HAND LENS IMAGER CAMERA
FilterN/A
Image Size1606 x 1198
Image Subframe[np.uint16(25), np.uint16(3), 1606, 1198]
TargetMARS
Date UTC2021-08-22 10:26:52
Mission DateSol-03215M11:05:09.188
Solar Elevation58.6°
Solar Azimuth17.7°
Exposure Time0.0063s
Site, Drive90, 2630
Camera Position137.398°E, -4.7442°N
Yaw, Pitch, Roll-110.3°, -78.8°, 10.0°
RationalePhobos shine experiment - roverremote sensing mast (RSM) - daylight context image - manual focus assumes ~3 meter standoff

Now let’s save the image in different output formats:

# this will save the image as a tiff file with sRGB gamma correction and zenith scaling
img.save('temp/mahli_gamma.tiff', gamma='sRGB')

# this will save the image as a dng file with included metadata and color correction and zenith scaling
# setting `rawtherapee_convert` to `True` could also automatically convert the dng image to a tiff file.
img.save('temp/mahli.dng', rawtherapee_convert=False)

If you only want the converted Tiff file from RawTherapee and don’t care about the DNG, you can also convert the tiff directly with this command (The DNG will still be created, but deleted automatically):

# this will save the image as a TIFF file with included metadata and color correction and zenith scaling
img.rawtherapee_convert('temp/mahli_rawtherapee.tif')
PosixPath('/tmp/tmpo89g1dgi/temp/mahli_rawtherapee.tif')

Image masking#

Marsimage will automatically load Navcam MXY mask files if they are present in the image directory.

First we need to download the necessary files:

pds_img = 'https://planetarydata.jpl.nasa.gov/img/data/msl/MSLNAV_1XXX/DATA/SOL03708/NLB_726680597RAD_F0991450NCAM00250M1.IMG'
mask_img = 'https://planetarydata.jpl.nasa.gov/img/data/msl/MSLNAV_1XXX/DATA/SOL03708/NLB_726680597MXY_F0991450NCAM00250M1.IMG'

image = download_pds3(pds_img, 'temp/')
mask = download_pds3(mask_img, 'temp/')

Now we’ll load the image and display a preview.

If you click the preview, you can show the mask of the rover.

img = MarsImage(image)

# display the image preview
display(img)
FilenameNLB_726680597RAD_F0991450NCAM00250M1.IMG
MissionMARS SCIENCE LABORATORY
InstrumentNAVIGATION CAMERA LEFT STRING B
FilterN/A
Image Size1024 x 1024
Image Subframe[1, 1, 1024, 1024]
TargetMARS
Date UTC2023-01-11 04:37:01
Mission DateSol-03708M15:50:51.818
Solar Elevation40.8°
Solar Azimuth278.4°
Exposure Time0.2304s
Site, Drive99, 1450
Camera Position137.3977°E, -4.7633°N
Yaw, Pitch, Roll170.6°, -76.1°, 20.2°
Rationale

Converting the image with a Mask applied#

This command will convert the image to tiff via RawTherapee and apply the mask to the alpha channel.

img.rawtherapee_convert('temp/navcam_rawtherapee_masked.tif', apply_mask=True)
PosixPath('/tmp/tmpo89g1dgi/temp/navcam_rawtherapee_masked.tif')

Saving the image and mask separately#

Since the DNG format does not support alpha channels for all images, it may be necessary to save the mask to a different file.

img.save_mask('temp/navcam_mask.tif')

Subframed images#

Many rover images are subframed before they are sent down to Earth to conserve data volume. This creates many different crops for the same camera system which is suboptimal for photogrammtry purposes because different camera models need to be created.

MarsImage allows to revert the image to the native sensor geometry and will automatically create masks for the missing data areas.

pds_img = download_pds3('https://planetarydata.jpl.nasa.gov/img/data/msl/MSLNAV_1XXX/DATA/SOL03076/NLB_670577263RAD_S0871444NCAM00266M1.IMG', 'temp/')
subframe_img = MarsImage(pds_img)

# native image geometry
display(subframe_img)

# uncropped image with mask
subframe_img.process(uncrop=True)
display(subframe_img)
FilenameNLB_670577263RAD_S0871444NCAM00266M1.IMG
MissionMARS SCIENCE LABORATORY
InstrumentNAVIGATION CAMERA LEFT STRING B
FilterN/A
Image Size1024 x 512
Image Subframe[1, 1, 1024, 512]
TargetMARS
Date UTC2021-04-01 20:12:49
Mission DateSol-03076M16:24:57.678
Solar Elevation28.0°
Solar Azimuth284.6°
Exposure Time0.58368s
Site, Drive87, 1444
Camera Position137.4123°E, -4.7354°N
Yaw, Pitch, Roll167.8°, -82.0°, 16.1°
Rationale
FilenameNLB_670577263RAD_S0871444NCAM00266M1.IMG
MissionMARS SCIENCE LABORATORY
InstrumentNAVIGATION CAMERA LEFT STRING B
FilterN/A
Image Size1024 x 1024
Image Subframe[1, 1, 1024, 1024]
TargetMARS
Date UTC2021-04-01 20:12:49
Mission DateSol-03076M16:24:57.678
Solar Elevation28.0°
Solar Azimuth284.6°
Exposure Time0.58368s
Site, Drive87, 1444
Camera Position137.4123°E, -4.7354°N
Yaw, Pitch, Roll167.8°, -82.0°, 16.1°
Rationale