ms_camera_model package

Submodules

ms_camera_model.data_comparison module

Multispectral Camera Model - Data Comparison

  • Description: Classes and their methods used for comparing real MS data with modeled data

  • Author: Tomas Vacek

class ms_camera_model.data_comparison.DataComparator(ms_img_data, modeled_img_data)[source]

Bases: object

Parameters:
calculate_spectral_angle_mapper(real_ms_ratios, modeled_ms_ratios)[source]

Calculate the spectral angle mapper (shape similarity) between real and modeled data

Parameters:
  • real_ms_ratios (ndarray) – real MS band ratios

  • modeled_ms_ratios (ndarray) – modeled MS band ratios

Returns:

angle in rad describing the similarity independent of brightness

Raises:

ValueError – if the calculation would cause division by 0

Return type:

float

compare_band_ratios(real_ms_area_location, modeled_ms_area_location, set_areas_globally=True)[source]

Compare band ratios of real MS image data with modeled MS image data

Parameters:
  • real_ms_area_location (AreaLocation | list[AreaLocation]) – AreaLocation or list[AreaLocation] objects describing the area that will be compared

  • modeled_ms_square_mean – AreaLocation or list[AreaLocation] object describing the area that will be compared

  • set_areas_globally (bool) – if True, provide only single AreaLocation, else list[AreaLocation] of length nbands

  • modeled_ms_area_location (AreaLocation | list[AreaLocation])

Returns:

tuple(real_ms_ratios, modeled_ms_ratios)

Raises:

ValueError – if sum of means of selected area is less than 1e-10

Return type:

tuple[ndarray, ndarray]

ms_camera_model.errors module

Multispectral Camera Model - Custom Errors

  • Description: Custom error definitions to improve readability and make debugging easier

  • Author: Tomas Vacek

exception ms_camera_model.errors.AreaOutsideOfBounds[source]

Bases: Exception

The provided area is outside of bounds of the image

exception ms_camera_model.errors.ImageDataIncompatible[source]

Bases: Exception

Image Data isn’t incompatible

exception ms_camera_model.errors.ImageImportFailed[source]

Bases: Exception

Image import failed

exception ms_camera_model.errors.IncompatibleBandChoice[source]

Bases: Exception

Chosen bands are not compatible with this method

exception ms_camera_model.errors.InvalidProvidedArea[source]

Bases: Exception

Provided area is invalid

exception ms_camera_model.errors.NoDarkFrame[source]

Bases: Exception

No embedded dark frame found

exception ms_camera_model.errors.NoImageData[source]

Bases: Exception

Provided ImageData instance doesn’t contain img_data

exception ms_camera_model.errors.NoProvidedArea[source]

Bases: Exception

No area was provided

exception ms_camera_model.errors.NoProvidedFilepaths[source]

Bases: Exception

No filepaths were provided

exception ms_camera_model.errors.NoProvidedFilterSensorUnits[source]

Bases: Exception

No provided FilterSensorUnit class instances

exception ms_camera_model.errors.WavelengthMismatch[source]

Bases: Exception

Provided filter wavelengths do not match with available hyperspectral image data

ms_camera_model.filter_sensor module

Multispectral Camera Model - Filters and Sensors

  • Description: Dataclasses and their methods for filters and sensors

  • Author: Tomas Vacek

class ms_camera_model.filter_sensor.FilterSensorUnit(filter_spec, sensor_spec)[source]

Bases: object

Combination of filter and sensor

Parameters:
filter_spec: FilterSpecs
classmethod from_excel(filename_filter, filename_sensor)[source]

Load filter transmission and sensor spectral sensitivity from Excel file

Parameters:
  • filename_filter (str) – Filename or path to the filter xlsx file

  • filename_sensor (str) – Filename or path to the sensor xlsx file

Return type:

FilterSensorUnit

sensor_spec: SensorSpecs
class ms_camera_model.filter_sensor.FilterSpecs(filter_transmittance, name='Generic', supplier='Generic', band_center=0, band_width=0)[source]

Bases: object

Filter specification

Parameters:
  • filter_transmittance (ndarray)

  • name (str)

  • supplier (str)

  • band_center (float)

  • band_width (float)

band_center: float = 0
band_width: float = 0
filter_transmittance: ndarray
name: str = 'Generic'
supplier: str = 'Generic'
class ms_camera_model.filter_sensor.InterpolatedFilterSensorUnit(filter_spec, sensor_spec, combined_response=None)[source]

Bases: FilterSensorUnit

FilterSensorUnit interpolated to hyperspectral data

Parameters:
combined_response: ndarray | None = None
classmethod interpolate_to_hs_data(fs_unit, hs_band_centers)[source]

Interpolate the provided filter and sensor data to hyperspectral data

Parameters:
Return type:

InterpolatedFilterSensorUnit

class ms_camera_model.filter_sensor.SensorSpecs(sensor_qe_curve, name='Generic', supplier='Generic', sensor_type='CMOS')[source]

Bases: object

Sensor specification

Parameters:
  • sensor_qe_curve (ndarray)

  • name (str)

  • supplier (str)

  • sensor_type (str)

name: str = 'Generic'
sensor_qe_curve: ndarray
sensor_type: str = 'CMOS'
supplier: str = 'Generic'

ms_camera_model.image_data module

Multispectral Camera Model - Image Data

Dataclasses and their methods for image data

class ms_camera_model.image_data.AreaLocation(ulx, uly, lrx, lry)[source]

Bases: object

Area location value object with checks

Parameters:
  • ulx (int)

  • uly (int)

  • lrx (int)

  • lry (int)

as_tuple()[source]

Return in openCV compatible format

Return type:

tuple[int, int, int, int]

lrx: int
lry: int
ulx: int
uly: int
class ms_camera_model.image_data.HyperspectralImageData(img_data, band_centers, nbands)[source]

Bases: ImageData

Hyperspectral Image Data - imported from hyperspectral data file

Method import_hs_img:

Import hyperspectral cube into img_data, band_centers and nbands

Parameters:
  • img_data (ndarray)

  • band_centers (list[float])

  • nbands (int)

classmethod import_calibrated_hs_img(img_filepath, panel_data_filepath, panel_location)[source]

Import hyperspectral cube as ImageData class instance

Parameters:
  • img_filepath (str) – path to the hyperspectral image file

  • panel_data_filepath (str) – path to the csv panel albedo file

  • panel_location (AreaLocation) – AreaLocation object

Raises:

NoImageData – when spectral fails to load the image

Return type:

HyperspectralImageData

classmethod import_hs_img(img_filepath)[source]

Import hyperspectral cube as ImageData class instance

Parameters:
  • img_filepath (str) – path to the hyperspectral image file

  • panel_data_filepath – path to the csv panel albedo file

  • panel_location – panel_location information format [ulx, uly, lrx, lry]

Raises:

NoImageData – when spectral fails to load the image

Return type:

HyperspectralImageData

static perform_radiometric_calibration(filepath, metadata, img_data, panel_location, snr_multiplier=5.0)[source]

Perform radiometric calibration based on calibration plate with known albedo

Parameters:
  • filepath (str) – path to the wavelength-albedo csv file

  • metadata (dict[str, str]) – dict with hyperspectral data metadata

  • img_data (ndarray) – np.ndarray of image data with shape (rows, cols, bands)

  • panel_location (AreaLocation) – panel_location information format [ulx, uly, lrx, lry]

  • snr_multiplier (float) – multiplier for snr check

Returns:

calibrated numpy img_data array

Return type:

tuple[ndarray, ndarray]

class ms_camera_model.image_data.ImageData(img_data, band_centers, nbands)[source]

Bases: ABC

Image Data class

Parameters:
  • img_data (ndarray) – np.ndarray of image data with shape (rows, cols, bands)

  • band_centers (list[float]) – list of floats storing the center of each band in the img_data array

  • nbands (int) – number of bands in the img_data array

Method __add__:

add two ImageData classes

Method mean_spectrum_area:

calculate mean spectrum for a select area

band_centers: list[float]
img_data: ndarray
static mean_spectrum_area(img, corner_coords)[source]

Calculate mean over spectral bands for select area

Parameters:
  • img (ndarray) – image data

  • corner_coords (tuple[int, int, int, int]) – coordinates of corners of the area in format [ulx, uly, lrx, lry]

Return type:

ndarray

nbands: int
class ms_camera_model.image_data.ModeledMultispectralImageData(img_data, band_centers, nbands, band_names)[source]

Bases: ImageData

Modeled Multispectral Image Data - modeled from HS data

Method perform_radiometric_calibration:

method for performing radiometric calibration against known panel

Parameters:
  • img_data (ndarray)

  • band_centers (list[float])

  • nbands (int)

  • band_names (list[str])

band_names: list[str]
perform_radiometric_calibration(panel_calibration, panel_locations)[source]

Perform radiometric calibration on the modeled multispectral image data

Parameters:
  • panel_calibration (dict[str, float]) – panel_calibration data of used MicaSense CRP

  • panel_location – list of AreaLocation objects

  • panel_locations (list[AreaLocation])

Return type:

ModeledMultispectralImageData

class ms_camera_model.image_data.MultispectralImageData(img_data, band_centers, nbands)[source]

Bases: ImageData

Multispectral Image Data - loaded from real MS camera

Method import_altum_pt_ms_imgs:

method for import of images from MicaSense Altum-PT camera

Method import_ms_imgs:

method for import of generic multispectral images

Method check_filepaths:

method which checks that filepaths are a non-empty list and are strings

Parameters:
  • img_data (ndarray)

  • band_centers (list[float])

  • nbands (int)

static check_filepaths(filepaths)[source]

Check that provided list of filepaths is usable

Parameters:

filepaths (list[str]) – list of filepaths

Raises:
  • TypeError – when provided paths aren’t in list

  • TypeError – when provided paths aren’t strings

  • NoProvidedFilepaths – when there are no provided filepaths

Return type:

None

classmethod import_altum_pt_ms_imgs(filepaths, panel_calibration, panel_locations)[source]

Import and pre-process Altum PT images

Parameters:
  • filepaths (list[str]) – list of filepaths to the multispectral images, their order determines order in the final array

  • panel_calibration (dict[str, float]) – panel_calibration data of used MicaSense CRP

  • panel_location – list of AreaLocation objects

  • panel_locations (list[AreaLocation])

Raises:
  • NoProvidedArea – when the provided area of the CRP is None or empty

  • Exception – when the length of filepaths and panel_locations doesn’t match

  • TypeError – when provided paths aren’t in list

  • TypeError – when provided paths aren’t strings

  • NoProvidedFilepaths – when there are no provided filepaths

Return type:

MultispectralImageData

classmethod import_ms_imgs(filepaths)[source]

Import multispectral images as a np.ndarray

Parameters:

filepaths (list[str]) – list of filepaths to the multispectral images, their order determines order in the final array

Raises:
  • TypeError – when provided paths aren’t in list

  • TypeError – when provided paths aren’t strings

  • NoProvidedFilepaths – when there are no provided filepaths

Return type:

MultispectralImageData

ms_camera_model.image_visualiser module

Multispectral Camera Model - Image Visualiser

Dataclasses and their methods for visualising image data

class ms_camera_model.image_visualiser.ImageVisualiser[source]

Bases: object

Image Visualiser class

Parameters:

image_data – ImageData class

Method imshow:

view the img_data as an RGB interpretation of selected bands or as a brightness plot

Method plot_area_spectrum:

visualize the mean spectrum of an area

static imshow(image_data, bands=None)[source]

View image as an RGB interpretation of selected bands or as a brightness plot

Parameters:
  • bands (list[int] | None) – list of band numbers, if the list is not provided, brightness plot will be used instead

  • image_data (ImageData)

Raises:

IncompatibleBandChoice – if ‘bands’ is not [], len(bands) != 3 or the number is out-of-bounds

Return type:

None

static plot_area_spectrum(image_data, coordinates)[source]

Plot spectrum of pixels

Parameters:
  • coordinates (AreaLocation) – list[ulx, uly, lrx, lry] - ulx means upper left x, lry means lower right y, etc.

  • image_data (ImageData)

Return type:

None

ms_camera_model.model module

Multispectral Camera Model - Simulation Model

  • Description: Simulated model of a multispectral camera. Takes in hyperspectral data and colour filter specs. Outputs multispectral data

  • Author: Tomas Vacek

class ms_camera_model.model.MultispectralCameraModel(hs_data, filter_sensor_units, band_names)[source]

Bases: object

Multispectral camera model

Parameters:
  • hs_data (HyperspectralImageData) – HyperspectralImageData class instance

  • filter_sensor_units (list[InterpolatedFilterSensorUnit]) – list of InterpolatedFilterSensorUnit class instances

  • band_names (list[str]) – list of names for spectral bands

  • out_data – simulated multispectral image data as ImageData class instance

band_names: list[str]
classmethod create_model(hs_data, fs_units, band_names)[source]

Interpolate FilterSensorUnits to hyperspectral image data and create model with corrected units

Parameters:
  • hs_data (HyperspectralImageData) – HyperspectralImageData class instance

  • fs_units (list[FilterSensorUnit]) – list of FilterSensorUnit class instances

  • band_names (list[str]) – list of names for spectral bands

Return type:

MultispectralCameraModel

filter_sensor_units: list[InterpolatedFilterSensorUnit]
hs_data: HyperspectralImageData
out_data: ModeledMultispectralImageData
run_simulation()[source]

Match filter_sensor_units specs with hs_data band_centers and calculate out_data

Returns:

Returns resulting simulated ImageData

Return type:

ImageData

Module contents

Multispectral Camera Model - Simulation Model

Simulated model of a multispectral camera. Takes in hyperspectral data and colour filter specs. Outputs multispectral data

class ms_camera_model.AreaLocation(ulx, uly, lrx, lry)[source]

Bases: object

Area location value object with checks

Parameters:
  • ulx (int)

  • uly (int)

  • lrx (int)

  • lry (int)

as_tuple()[source]

Return in openCV compatible format

Return type:

tuple[int, int, int, int]

lrx: int
lry: int
ulx: int
uly: int
class ms_camera_model.DataComparator(ms_img_data, modeled_img_data)[source]

Bases: object

Parameters:
calculate_spectral_angle_mapper(real_ms_ratios, modeled_ms_ratios)[source]

Calculate the spectral angle mapper (shape similarity) between real and modeled data

Parameters:
  • real_ms_ratios (ndarray) – real MS band ratios

  • modeled_ms_ratios (ndarray) – modeled MS band ratios

Returns:

angle in rad describing the similarity independent of brightness

Raises:

ValueError – if the calculation would cause division by 0

Return type:

float

compare_band_ratios(real_ms_area_location, modeled_ms_area_location, set_areas_globally=True)[source]

Compare band ratios of real MS image data with modeled MS image data

Parameters:
  • real_ms_area_location (AreaLocation | list[AreaLocation]) – AreaLocation or list[AreaLocation] objects describing the area that will be compared

  • modeled_ms_square_mean – AreaLocation or list[AreaLocation] object describing the area that will be compared

  • set_areas_globally (bool) – if True, provide only single AreaLocation, else list[AreaLocation] of length nbands

  • modeled_ms_area_location (AreaLocation | list[AreaLocation])

Returns:

tuple(real_ms_ratios, modeled_ms_ratios)

Raises:

ValueError – if sum of means of selected area is less than 1e-10

Return type:

tuple[ndarray, ndarray]

class ms_camera_model.FilterSensorUnit(filter_spec, sensor_spec)[source]

Bases: object

Combination of filter and sensor

Parameters:
filter_spec: FilterSpecs
classmethod from_excel(filename_filter, filename_sensor)[source]

Load filter transmission and sensor spectral sensitivity from Excel file

Parameters:
  • filename_filter (str) – Filename or path to the filter xlsx file

  • filename_sensor (str) – Filename or path to the sensor xlsx file

Return type:

FilterSensorUnit

sensor_spec: SensorSpecs
class ms_camera_model.FilterSpecs(filter_transmittance, name='Generic', supplier='Generic', band_center=0, band_width=0)[source]

Bases: object

Filter specification

Parameters:
  • filter_transmittance (ndarray)

  • name (str)

  • supplier (str)

  • band_center (float)

  • band_width (float)

band_center: float = 0
band_width: float = 0
filter_transmittance: ndarray
name: str = 'Generic'
supplier: str = 'Generic'
class ms_camera_model.HyperspectralImageData(img_data, band_centers, nbands)[source]

Bases: ImageData

Hyperspectral Image Data - imported from hyperspectral data file

Method import_hs_img:

Import hyperspectral cube into img_data, band_centers and nbands

Parameters:
  • img_data (ndarray)

  • band_centers (list[float])

  • nbands (int)

classmethod import_calibrated_hs_img(img_filepath, panel_data_filepath, panel_location)[source]

Import hyperspectral cube as ImageData class instance

Parameters:
  • img_filepath (str) – path to the hyperspectral image file

  • panel_data_filepath (str) – path to the csv panel albedo file

  • panel_location (AreaLocation) – AreaLocation object

Raises:

NoImageData – when spectral fails to load the image

Return type:

HyperspectralImageData

classmethod import_hs_img(img_filepath)[source]

Import hyperspectral cube as ImageData class instance

Parameters:
  • img_filepath (str) – path to the hyperspectral image file

  • panel_data_filepath – path to the csv panel albedo file

  • panel_location – panel_location information format [ulx, uly, lrx, lry]

Raises:

NoImageData – when spectral fails to load the image

Return type:

HyperspectralImageData

static perform_radiometric_calibration(filepath, metadata, img_data, panel_location, snr_multiplier=5.0)[source]

Perform radiometric calibration based on calibration plate with known albedo

Parameters:
  • filepath (str) – path to the wavelength-albedo csv file

  • metadata (dict[str, str]) – dict with hyperspectral data metadata

  • img_data (ndarray) – np.ndarray of image data with shape (rows, cols, bands)

  • panel_location (AreaLocation) – panel_location information format [ulx, uly, lrx, lry]

  • snr_multiplier (float) – multiplier for snr check

Returns:

calibrated numpy img_data array

Return type:

tuple[ndarray, ndarray]

class ms_camera_model.ImageData(img_data, band_centers, nbands)[source]

Bases: ABC

Image Data class

Parameters:
  • img_data (ndarray) – np.ndarray of image data with shape (rows, cols, bands)

  • band_centers (list[float]) – list of floats storing the center of each band in the img_data array

  • nbands (int) – number of bands in the img_data array

Method __add__:

add two ImageData classes

Method mean_spectrum_area:

calculate mean spectrum for a select area

band_centers: list[float]
img_data: ndarray
static mean_spectrum_area(img, corner_coords)[source]

Calculate mean over spectral bands for select area

Parameters:
  • img (ndarray) – image data

  • corner_coords (tuple[int, int, int, int]) – coordinates of corners of the area in format [ulx, uly, lrx, lry]

Return type:

ndarray

nbands: int
class ms_camera_model.MultispectralCameraModel(hs_data, filter_sensor_units, band_names)[source]

Bases: object

Multispectral camera model

Parameters:
  • hs_data (HyperspectralImageData) – HyperspectralImageData class instance

  • filter_sensor_units (list[InterpolatedFilterSensorUnit]) – list of InterpolatedFilterSensorUnit class instances

  • band_names (list[str]) – list of names for spectral bands

  • out_data – simulated multispectral image data as ImageData class instance

band_names: list[str]
classmethod create_model(hs_data, fs_units, band_names)[source]

Interpolate FilterSensorUnits to hyperspectral image data and create model with corrected units

Parameters:
  • hs_data (HyperspectralImageData) – HyperspectralImageData class instance

  • fs_units (list[FilterSensorUnit]) – list of FilterSensorUnit class instances

  • band_names (list[str]) – list of names for spectral bands

Return type:

MultispectralCameraModel

filter_sensor_units: list[InterpolatedFilterSensorUnit]
hs_data: HyperspectralImageData
out_data: ModeledMultispectralImageData
run_simulation()[source]

Match filter_sensor_units specs with hs_data band_centers and calculate out_data

Returns:

Returns resulting simulated ImageData

Return type:

ImageData

class ms_camera_model.MultispectralImageData(img_data, band_centers, nbands)[source]

Bases: ImageData

Multispectral Image Data - loaded from real MS camera

Method import_altum_pt_ms_imgs:

method for import of images from MicaSense Altum-PT camera

Method import_ms_imgs:

method for import of generic multispectral images

Method check_filepaths:

method which checks that filepaths are a non-empty list and are strings

Parameters:
  • img_data (ndarray)

  • band_centers (list[float])

  • nbands (int)

static check_filepaths(filepaths)[source]

Check that provided list of filepaths is usable

Parameters:

filepaths (list[str]) – list of filepaths

Raises:
  • TypeError – when provided paths aren’t in list

  • TypeError – when provided paths aren’t strings

  • NoProvidedFilepaths – when there are no provided filepaths

Return type:

None

classmethod import_altum_pt_ms_imgs(filepaths, panel_calibration, panel_locations)[source]

Import and pre-process Altum PT images

Parameters:
  • filepaths (list[str]) – list of filepaths to the multispectral images, their order determines order in the final array

  • panel_calibration (dict[str, float]) – panel_calibration data of used MicaSense CRP

  • panel_location – list of AreaLocation objects

  • panel_locations (list[AreaLocation])

Raises:
  • NoProvidedArea – when the provided area of the CRP is None or empty

  • Exception – when the length of filepaths and panel_locations doesn’t match

  • TypeError – when provided paths aren’t in list

  • TypeError – when provided paths aren’t strings

  • NoProvidedFilepaths – when there are no provided filepaths

Return type:

MultispectralImageData

classmethod import_ms_imgs(filepaths)[source]

Import multispectral images as a np.ndarray

Parameters:

filepaths (list[str]) – list of filepaths to the multispectral images, their order determines order in the final array

Raises:
  • TypeError – when provided paths aren’t in list

  • TypeError – when provided paths aren’t strings

  • NoProvidedFilepaths – when there are no provided filepaths

Return type:

MultispectralImageData

class ms_camera_model.SensorSpecs(sensor_qe_curve, name='Generic', supplier='Generic', sensor_type='CMOS')[source]

Bases: object

Sensor specification

Parameters:
  • sensor_qe_curve (ndarray)

  • name (str)

  • supplier (str)

  • sensor_type (str)

name: str = 'Generic'
sensor_qe_curve: ndarray
sensor_type: str = 'CMOS'
supplier: str = 'Generic'