fpipy.raw

Functions for manipulating raw CFA data.

Example

Calculating radiances from raw data and plotting them can be done as follows:

import xarray as xr
import fpipy as fpi
import matplotlib
import os.path as osp
from fpipy.data import house_raw

data = house_raw() # Example raw data (including dark current)
rad = fpi.raw_to_radiance(data)
rad.swap_dims({'band': 'wavelength'}).radiance.sel(wavelength=600,
                                                  method='nearest').plot()

Functions

demosaic(cfa, pattern, dm_method)

Perform demosaicing on a DataArray.

radiance_to_reflectance(radiance, white[, …])

Computes reflectance from radiance and a white reference cube.

raw_to_radiance(raw, **kwargs)

Performs demosaicing and computes radiance from RGB values.

raw_to_reflectance(raw, whiteraw[, …])

Performs demosaicing and computes radiance from RGB values.

subtract_dark(ds[, keep_variables])

Subtracts dark current reference from image data.

Classes

BayerPattern

Enumeration of the Bayer Patterns as used by FPI headers.

class fpipy.raw.BayerPattern[source]

Enumeration of the Bayer Patterns as used by FPI headers.

BGGR = 2
BayerBG = 2
BayerGB = 0
BayerGR = 1
BayerRG = 3
GBRG = 0
GRBG = 1
RGGB = 3
bggr = 2
gbrg = 0
get = <bound method BayerPattern.get of <enum 'BayerPattern'>>[source]
grbg = 1
rggb = 3
fpipy.raw.demosaic(cfa, pattern, dm_method)[source]

Perform demosaicing on a DataArray.

Parameters
Returns

Return type

xarray.DataArray

fpipy.raw.radiance_to_reflectance(radiance, white, keep_variables=None)[source]

Computes reflectance from radiance and a white reference cube.

Parameters
  • radiance (xarray.Dataset) – Dataset containing the image(s) to divide by the references.

  • white (xarray.Dataset) – White reference image(s).

  • keep_variables (list-like, optional) – List of variables to keep in the result, default None. If you wish to keep the intermediate data, pass the relevant names from fpipy.conventions.

Returns

reflectance – Dataset containing the reflectance and the original metadata for both datasets indexed by measurement type.

Return type

xarray.Dataset

fpipy.raw.raw_to_radiance(raw, **kwargs)[source]

Performs demosaicing and computes radiance from RGB values.

Parameters
  • raw (xarray.Dataset) – A dataset containing the following variables: c.sinv_data, c.wavelength_data´, `c.fwhm_data c.camera_exposure c.cfa_data, c.dark_reference_data,

  • dm_method (str, optional) – {‘bilinear’, ‘DDFAPD’, ‘Malvar2004’, ‘Menon2007’} Demosaicing method. Default is ‘bilinear’. See the colour_demosaicing package for more info on the different methods.

  • keep_variables (list-like, optional) – List of variables to keep in the result, default None. If you wish to keep the intermediate data, pass the relevant names from fpipy.conventions.

Returns

radiances – Includes computed radiance sorted by wavelength along with original metadata.

Return type

xarray.Dataset

fpipy.raw.raw_to_reflectance(raw, whiteraw, keep_variables=None)[source]

Performs demosaicing and computes radiance from RGB values.

Parameters
  • raw (xarray.Dataset) – A dataset containing the following variables: c.cfa_data, c.dark_reference_data, c.sinv_data, c.wavelength_data´, `c.fwhm_data c.camera_exposure

  • white (xarray.Dataset) – Same as raw but for a cube that describes a white reference target.

  • keep_variables (list-like, optional) – List of variables to keep in the result, default None. If you wish to keep the intermediate data, pass the relevant names from fpipy.conventions.

Returns

reflectance – Includes computed radiance and reflectance as data variables sorted by wavelength or just the reflectance DataArray.

Return type

xarray.Dataset or xarray.DataArray

fpipy.raw.subtract_dark(ds, keep_variables=None)[source]

Subtracts dark current reference from image data.

Subtracts a dark reference frame from all the layers in the given raw data and clamps any negative values in the result to zero. The result is stored in the dataset as the variable c.dark_corrected_cfa_data which is overwritten if it exists.

Parameters
  • ds (xarray.DataSet) – Dataset containing the raw images in fpipy.conventions.cfa_data and the dark current reference measurement as fpipy.conventions.dark_reference_data.

  • keep_variables (list-like, optional) – List of variables to keep in the result, default None. If you wish to keep the dark reference data and/or the original raw images, pass a list including the variable names.

Returns

Dataset with the dark corrected data as fpipy.conventions.dark_corrected_cfa_data

Return type

xarray.Dataset