MarsImage subclasses#

Base class for MarsImage data.

class marsimage.imagebase.MarsImageBase(filename)[source]#

Base class for MarsImage data.

property img#

The image array of the image.

PDR loads the image array lazily, so this poperty is used to prevent preemtive loading. The image is loaded and converted to the appropriate dtype on first access.

property mask#

The mask array of the image.

Lazy loading of mask image, if not found, a blank mask is returned.

process(undebayer=False, uncrop=False, crop=False)[source]#

Calibrates the image according to the calibration settings specified in the kwargs.

This modifies the image in place.

Parameters:

undebayer (bool) – If True, and the image is color, it will be undebayered using the CFA pattern specified in the instrument_defs.

Return type:

None

crop(rect)[source]#

Crop the image and mask to the specified rectangle.

This modifies the image and mask in place. TODO update camera model!

Parameters:

rect (list of int) – The rectangle to crop the image to in the format [x1, y1, x2, y2].

crop_active_area()[source]#

Crop the image and mask to the max active area.

TODO update camera model!

uncrop()[source]#

Revert image to the full sensor size.

This modifies the image and mask in place, padding them with zeros to the full sensor size.

TODO update camera model!

to_subframe(subframe)[source]#

Crop/pad the image and mask to the specified subframe.

This modifies the image and mask in place.

Parameters:

subframe (list of int) – The subframe to crop/pad the image to in the format [first_line_sample, first_line, line_samples, lines].

save(save_path, *args, **kwargs)[source]#

Save the image to the specified path, with optional arguments for metadata etc.

The file format is determined by the file extension of the save_path. Currently supported formats are TIFF and DNG.

Parameters:

save_path (str) – The path to save the image to. The file extension determines the file format.

See also

marsimage.save.save_tiff

Save the image as a TIFF file.

marsimage.dng.save_dng

Save the image as a DNG file.

rawtherapee_convert(save_path, apply_mask=True, remove_dng=True)[source]#

Convert the image to a TIFF file using RawTherapee and save it to the specified path.

Parameters:
  • save_path (str) – The path to save the image to. The file extension determines the file format.

  • apply_mask (bool) – Whether to apply mask layer as an alpha channel.

  • remove_dng (bool) – Whether to clean up and delete the dng.

Returns:

The path to the saved image.

Return type:

str

save_mask(save_path, ignore_empty=True)[source]#

Save the mask to the specified path.

Parameters:
  • save_path (str) – The path to save the mask to. The file extension determines the file format.

  • ignore_empty (bool) – If True, do not save the mask if it is empty (all 255).

property xmp#

Generates an XMP object from the image metadata.

Returns:

XMP

Return type:

The XMP object.

See also

XMP

The XMP class.

metafind(keys, fallback=<object object>)[source]#

Find a value from the metadata object using a list of possible keys.

Nested keys can be accessed by passing a tuple of keys. If the key is not found, return a default value, else raise a KeyError.

Parameters:
  • keys (list or tuple) – A list of possible keys to search for in the metadata.

  • fallback (any, optional) – The value to return if the key is not found. A fallback value of None is valid. Default is the sentry value _UNSET.

Raises:

KeyError – If the key is not found in the metadata and no fallback value was provided.

property mission_id#

The mission ID of the image. e.g. ‘MSL’ or ‘M20’.

property mission_name#

The mission name of the image. e.g. ‘MARS SCIENCE LABORATORY’.

property instrument_id#

The instrument ID of the image. e.g. ‘MAHLI’ or ‘MARDI’.

property instrument_name#

The instrument name of the image. e.g. ‘MARS HAND LENS IMAGER CAMERA’.

property rationale#

The rationale for the image acquisition.

property start_time#

The start time of the image acquisition as a time.struct_time object.

property mean_solar_time#

The mean solar time of the image acquisition as a string.

property sol#

The sol of the image acquisition.

property sclk#

The spacecraft clock counter (sclk) of the image acquisition.

property width#

The width of the image array.

property height#

The height of the image array.

property subframe#

The subframe of the image.

Returns:

The subframe in the format [first_line_sample, first_line, line_samples, lines]. Coordinates start at [1,1] of the image.

Return type:

list of int

property subframe_rect#

The subframe of the image as a rectangle.

Returns:

The subframe in the format [x1, y1, x2, y2]. Coordinates start at [0,0] of the image.

Return type:

list of int

property pixel_averaging#

The downsample factor of an image.

Returns:

The pixel averaging width and height of the image.

Return type:

int

Raises:

Exception – If non-square pixel averaging is detected.

property active_area#

Returns the active area of the image.

The active area in the image coordinates [x1, y1, x2, y2] and start at [0,0] of the image.

Returns:

The active area in the format [x1, y1, x2, y2].

Return type:

list of int

property localization#

Get the localization object containing the rover position and orientation.

Returns:

An instance of OrbitalCoordinateFrame representing the rover position and orientation.

Return type:

OrbitalCoordinateFrame

property cahvore#

CAHVORE camera model object for the image.

Returns:

A CAHVORE camera model object created from the image metadata.

Return type:

CAHVORE

property cm#

Generate a CameraModel object for the image in the rover frame.

Returns:

The camera model object for the image.

Return type:

CameraModel

Notes

The CameraModel is created using the CAHVORE model parameters, image width, image height, and pixel size adjusted by pixel averaging.

See also

CameraModel.from_cahvore

Method to create a CameraModel from CAHVORE parameters.

property cm_global#

Camera model object for the image in the global frame.

Returns:

The camera model object for the image in the global frame.

Return type:

CameraModel

property solar_elevation#

The solar elevation angle at image acquisition.

property solar_azimuth#

The solar azimuth angle at image acquisition.

property target#

The specified target from the label.

property zenith_scaling#

The zenith scaling factor for the image.

Note

The zenith scaling factor is currently only calculated based on the solar elevation angle and ignores the atmospheric optical depth.

property baseline_exposure_factor#

Calculate the baseline exposure factor based on solar elevation.

The baseline exposure factor is only calculated if the solar elevation is above 5 degrees. At night, the image would get too dark, so a default value of 1.0 is returned.

Returns:

The calculated baseline exposure factor if solar elevation is above 5 degrees, otherwise 1.0.

Return type:

float

property baseline_exposure_stops#

The baseline exposure factor in EV stops.

See also

baseline_exposure_factor

The baseline exposure factor.

property whitelevel#

The white level of the image.

The white level is initialized with the maximum valid value from the image label. If the value is not found in the label, the maximum value for the image array’s data type is used.

Returns:

The white level value for the image.

Return type:

int

property radiance_scaling_factor#

Retrieve the radiance scaling factor from the metadata.

This method searches for the radiance scaling factor in the metadata using different possible keys. The keys are specific to different missions and instruments.

Returns:

The radiance scaling factor(s) found in the metadata. If multiple factors are found, a list of floats is returned.

Return type:

float or list of float

property radiance_offset#

Float value of the radiance offset of the image.

Returns:

The radiance offset value for the image.

Return type:

float | list of float

property exposure_time#

Get the exposure time of the image.

Returns:

The exposure time in seconds.

Return type:

float

class marsimage.msl.MAHLIZstackImage(filename)[source]#

Mahli image class to handle non standard MAHLI images.

find_source_image_from_zstack_rationale()[source]#

Find a source image of the MAHLI zstack.

MAHLI Z-STACK images labels contain the rover state during stack generation, so we need to find the source images to get valid metadata. Currently this method only tries to load the middle image of the sequence.

zstack_merge_label(source_label)[source]#

Merge the relevant values from the source image into the zstack image label.