Skip to content

Latest commit

 

History

History
420 lines (352 loc) · 12.9 KB

API_REFERENCE.md

File metadata and controls

420 lines (352 loc) · 12.9 KB

kleinPy Public API Reference

This document lists the public API surface intended for SDK users.

  • Source of truth for exported names: klein_colorimeter/__init__.py.
  • Public API in this document means names exported from klein_colorimeter plus non-underscore methods on those exported classes.
  • Internal helpers (names starting with _) are intentionally omitted.

Quick Start

Use this sequence for the most common workflow (connect, measure, optional continuous mode, cleanup):

  1. KClmtr()
  2. connect(port)
  3. setMeasureSpeedMode(SpeedMode.SPEEDMODE_NORMAL | SpeedMode.SPEEDMODE_FAST) (optional)
  4. setRange(-1) (auto range; optional)
  5. getNextMeasurement()
  6. measurement.getBigY() and measurement.getCIE1931_x()/getCIE1931_y()
  7. measurement.getRGB_Red()/getRGB_Green()/getRGB_Blue()
  8. measurement.getWavelength_nm()/getWavelength_duv()
  9. startMeasuring() + getMeasurement() for streaming (optional)
  10. stopMeasuring() (if streaming)
  11. closePort()

Minimal one-shot example:

from klein_colorimeter import KClmtr

meter = KClmtr()
if meter.connect("COM3"):
    try:
        m = meter.getNextMeasurement()
        print(f"Y: {m.getBigY():.4f} nits")
        print(f"xy: ({m.getCIE1931_x():.6f}, {m.getCIE1931_y():.6f})")
        print(f"RGB: ({m.getRGB_Red():.6f}, {m.getRGB_Green():.6f}, {m.getRGB_Blue():.6f})")
        print(f"Wavelength: {m.getWavelength_nm():.3f} nm, duv: {m.getWavelength_duv():.6f}")
    finally:
        meter.closePort()
else:
    print("Unable to connect")

Tip: RGB getters return normalized values (typically 0.0-1.0 in-gamut). For percent display, multiply by 100.

Import Surface

from klein_colorimeter import (
    KClmtr,
    Matrix,
    GamutSpec,
    Measurement,
    Counts,
    Flicker,
    FlickerSetting,
    FlickerSettingRange,
    WRGB,
    CorrectedCoefficient,
    BlackMatrix,
    PercentMode,
    DecibelMode,
    CorrectionMode,
    MeasurementRange,
    GamutCode,
    SpeedMode,
    KleinsErrorCodes,
)

Enums

PercentMode

  • ContrastMethod = 0
  • Normaized = 1

DecibelMode

  • VESA = 0
  • JEITA = 1

CorrectionMode

  • ArrayFit = 0
  • PolyFit = 1

MeasurementRange

  • range1 = 1
  • range2 = 2
  • range3 = 3
  • range4 = 4
  • range5 = 5
  • range6 = 6
  • range1B = 1
  • range1T = 2
  • range2B = 3
  • range2T = 4
  • range3B = 5
  • range3T = 6

GamutCode

  • NTSC = 0
  • EBU = 1
  • REC709 = 2
  • REC2020 = 3
  • SMPTE = 4
  • DCIP3 = 5
  • USER_DEFINE = 6
  • defaultGamut = REC709

SpeedMode

  • SPEEDMODE_NORMAL = 0
  • SPEEDMODE_FAST = 1

KleinsErrorCodes (IntFlag)

  • NONE
  • NOT_OPEN
  • TIMED_OUT
  • LOST_CONNECTION
  • BAD_VALUES
  • CONVERTED_NM
  • KELVINS
  • AIMING_LIGHTS
  • AVERAGING_LOW_LIGHT
  • BOTTOM_UNDER_RANGE
  • TOP_OVER_RANGE
  • OVER_HIGH_RANGE
  • BLACK_ZERO
  • BLACK_OVERDRIVE
  • BLACK_EXCESSIVE
  • BLACK_PARSING_ROM
  • BLACK_STORING_ROM
  • CAL_WHITE_RGB
  • CAL_STORING
  • CAL_CONVERT_BINARY
  • FFT_BAD_STRING
  • FFT_RANGE_CAL
  • FFT_NO_XYZ
  • FFT_NO_RANGE
  • FFT_INSUFFICIENT_DATA
  • FFT_PREVIOUS_RANGE
  • FFT_NOT_SUPPORTED
  • FFT_BAD_SAMPLES
  • FFT_OVER_SATURATED
  • FIRMWARE

Classes

KClmtr

Primary meter/session object for serial connection, measurement, counts, and flicker operations.

Connection and device

  • setPort(portName: str) -> None
  • getPort() -> str
  • isPortOpen() -> bool
  • connect(portName: str | None = None) -> bool
  • closePort() -> None
  • testConnection(portName: str) -> tuple[bool, str, str] (static)
  • getSerialNumber() -> str
  • getModel() -> str
  • sendMessageToKColorimeter(message: _Command | str, expected: int | None = None, timeout: int | None = None) -> tuple[int, str]
  • readFromKColorimeter(expected: int, timeout_seconds: int) -> tuple[int, str]

Range, cal file, matrices

  • setAimingLights(onOff: bool) -> None
  • setRange(range_value: int) -> None
  • getRange() -> int
  • getCalFileName() -> str
  • setCalFileID(calFileID: int) -> None
  • getCalFileID() -> int
  • getCalFileList() -> list[str]
  • deleteCalFile(calFileID: int) -> int
  • setTempCalFile(coeff: CorrectedCoefficient) -> None
  • getCalMatrix() -> Matrix[float]
  • getRGBMatrix() -> Matrix[float]
  • getGamutSpec() -> GamutSpec
  • setGamutSpec(gs: GamutSpec) -> None
  • getCoefficientTestMatrix(reference: WRGB, kclmtr: WRGB) -> CorrectedCoefficient
  • storeMatrices(id: int, name: str, reference: WRGB | Matrix[float] | CorrectedCoefficient, kclmtr: WRGB | None = None) -> int
  • captureBlackLevel() -> BlackMatrix
  • getFlashMatrix() -> BlackMatrix
  • getRAMMatrix() -> BlackMatrix
  • getCoefficientMatrix() -> BlackMatrix

Measurement settings

  • setMaxAverageCount(maxAvg: int) -> bool
  • getMaxAverageCount() -> int
  • getMeasureSpeedMode() -> SpeedMode
  • setMeasureSpeedMode(value: SpeedMode) -> None

Continuous measurements

  • startMeasuring() -> None
  • stopMeasuring() -> None
  • isMeasuring() -> bool
  • getMeasurement() -> tuple[bool, Measurement]
  • getNextMeasurement(n: int = -1) -> Measurement

Raw counts

  • startMeasureCounts() -> None
  • stopMeasureCounts() -> None
  • isMeasureCounts() -> bool
  • getMeasureCounts() -> tuple[bool, Counts]
  • getNextMeasureCount() -> Counts

Flicker configuration and acquisition

  • setFFT_Cosine(use: bool) -> None
  • getFFT_Cosine() -> bool
  • setFFT_Smoothing(use: bool) -> None
  • getFFT_Smoothing() -> bool
  • setFFT_Samples(samples: int) -> int
  • getFFT_Samples() -> int
  • setFFT_PercentJEITA_Discount(onOff: bool) -> None
  • getFFT_PercentJEITA_Discount() -> bool
  • setFFT_DBJEITA_Discount(onOff: bool) -> None
  • getFFT_DBJEITA_Discount() -> bool
  • setFFT_PercentMode(mode: PercentMode) -> None
  • getFFT_PercentMode() -> PercentMode
  • setFFT_DBMode(mode: DecibelMode) -> None
  • getFFT_DBMode() -> DecibelMode
  • setFFT_numberOfPeaks(numberOfPeaks: int) -> None
  • getFFT_numberOfPeaks() -> int
  • startFlicker() -> int
  • stopFlicker() -> None
  • isFlickering() -> bool
  • getFlicker() -> tuple[bool, Flicker]
  • getNextFlicker() -> Flicker

Callback dispatch helpers

  • printMeasure(measurement: Measurement) -> None
  • printFlicker(flicker: Flicker) -> None
  • printCounts(counts: Counts) -> None

Matrix[T]

Simple 2D matrix container used by the SDK types.

  • initializeV(rows: int, columns: int, fill: T | float | int = 0) -> None
  • clear(fill: T | float | int = 0) -> None
  • getRow() -> int
  • getColumn() -> int
  • copy() -> Matrix[T]
  • to_numpy(dtype=float)
  • from_rows(rows: Iterable[Iterable[T | float | int]]) -> Matrix[T] (class method)

Public attribute:

  • v: list[list[T | float | int]]

GamutSpec

Chromaticity and white-point model plus matrix conversion helpers.

  • fromCode(code: GamutCode, whiteBigY: float = 100.0) -> GamutSpec (static)
  • getCodeSpec() -> GamutCode
  • setRed(x: float, y: float) -> None
  • setGreen(x: float, y: float) -> None
  • setBlue(x: float, y: float) -> None
  • setWhite(x: float, y: float, bigY: float) -> None
  • getWhite() -> tuple[float, float, float]
  • getRed() -> tuple[float, float, float]
  • getGreen() -> tuple[float, float, float]
  • getBlue() -> tuple[float, float, float]
  • getRGBtoXYZ() -> Matrix[float]
  • getXYZtoRGB() -> Matrix[float]

Public attributes:

  • redX, redY, greenX, greenY, blueX, blueY, whiteX, whiteY, whiteBigY, code

Measurement

Computed color measurement object (XYZ, xy, RGB, Lab/LCh, HSV, CCT/Duv, ranges, and errors).

Getters and mutators

  • getCIE1931_x() -> float
  • getCIE1931_y() -> float
  • getBigX() -> float
  • getBigY() -> float
  • getBigZ() -> float
  • getBigXRaw() -> float
  • getBigYRaw() -> float
  • getBigZRaw() -> float
  • getRGB_Red() -> float
  • getRGB_Green() -> float
  • getRGB_Blue() -> float
  • getCIE1974_u() -> float
  • getCIE1974_v() -> float
  • getWavelength_nm() -> float
  • getWavelength_duv() -> float
  • getLab_L() -> float
  • getLab_a() -> float
  • getLab_b() -> float
  • getLCh_L() -> float
  • getLCh_C() -> float
  • getLCh_h() -> float
  • getHSV_hue() -> float
  • getHSV_saturation() -> float
  • getHSV_value() -> float
  • getRedRange() -> MeasurementRange
  • getGreenRange() -> MeasurementRange
  • getBlueRange() -> MeasurementRange
  • getColorTemperature_K() -> float
  • getColorTemperature_duv() -> float
  • getErrorCode() -> int
  • getAveragingby() -> int
  • getMinX() -> float
  • getMaxX() -> float
  • getMinY() -> float
  • getMaxY() -> float
  • getMinZ() -> float
  • getMaxZ() -> float
  • getGamutSpec() -> GamutSpec
  • setGamutSpec(gs: GamutSpec) -> None

Color-difference and constructors

  • deltaE1976(spec: Measurement) -> float
  • deltaE1994(spec: Measurement) -> float
  • deltaE2000(spec: Measurement) -> float
  • fromBadMeasurement() -> Measurement (static)
  • fromXYZ(X: float, Y: float, Z: float, gs: GamutSpec | None = None) -> Measurement (static)
  • fromxyY(x: float, y: float, Y: float, gs: GamutSpec | None = None) -> Measurement (static)
  • fromuvprimeY(u: float, v: float, Y: float, gs: GamutSpec | None = None) -> Measurement (static)
  • fromTempduvY(_temp: float, _tempduv: float, Y: float, gs: GamutSpec | None = None) -> Measurement (static)
  • fromnmduvY(_nm: float, _nmduv: float, Y: float, gs: GamutSpec | None = None) -> Measurement (static)
  • fromRGB(red: float, green: float, blue: float, gs: GamutSpec | None = None) -> Measurement (static)
  • fromHSV(hue: float, saturation: float, value: float, gs: GamutSpec | None = None) -> Measurement (static; saturation is 0 to 100, value is normalized 0.0 to 1.0)
  • fromLab(L: float, a: float, b: float, gs: GamutSpec | None = None) -> Measurement (static)
  • toNits(FootLamberts: float) -> float (static)
  • toFootLamberts(nits: float) -> float (static)

Counts

Raw count packet object.

  • getTh1() -> int
  • getTh2() -> int
  • getTherm() -> int
  • getRedRange() -> MeasurementRange
  • getGreenRange() -> MeasurementRange
  • getBlueRange() -> MeasurementRange
  • getTheCounts() -> Matrix[int]
  • getErrorCode() -> int

Public attributes:

  • th1, th2, therm, redrange, greenrange, bluerange, theCounts, errorcode

FlickerSettingRange

  • numbers() -> int

Public attributes:

  • start, end

FlickerSetting

  • getResolution() -> float
  • getCorrection(hz: float) -> float
  • appendCorrection(rangeOfHz: FlickerSettingRange, mode: CorrectionMode, array: Iterable[float]) -> bool
  • deleteCorrection() -> None

Public attributes:

  • samples, speed, numberOfPeaks, cosine, smoothing, JETIADiscount_DB, JEITADiscount_Percent, decibel, percent, corrections

Flicker

Flicker-analysis result object.

  • from_samples(settings: FlickerSetting, data, sectionOfFFT: int = 0, nitsLast32Samples: float | None = None) -> Flicker (class method)
  • getBigY() -> float
  • getRange() -> MeasurementRange
  • getPeakFrequencyPercent() -> Matrix[float]
  • getPeakFrequencyDB() -> Matrix[float]
  • getFlickerPercent() -> Matrix[float]
  • getFlickerDB() -> Matrix[float]
  • getCounts() -> Matrix[float]
  • getNits() -> Matrix[float]
  • getAmplitude() -> Matrix[float]
  • getErrorCode() -> int
  • getSettings() -> FlickerSetting

Public attributes:

  • bigY, range, peakfrequencyPercent, peakfrequencyDB, flickerPercent, flickerDB, counts, nits, amplitude, errorcode, settings

WRGB

Container for white + RGB reference triplets used in calibration matrix fitting.

  • from_measurements(measurements: list[Measurement]) -> WRGB (class method)

Public attribute:

  • v: list[list[float]]

CorrectedCoefficient

Calibration payload container.

Public attributes:

  • colorMatrix: Matrix[float]
  • rgbMatrix: Matrix[float]

BlackMatrix

Black compensation matrix container.

  • from_vector(vector: list[float], errorcode: int) -> BlackMatrix (class method)

Public attributes:

  • range: list[list[float]]
  • therm: float
  • errorcode: int

Notes

  • The package intentionally mirrors original SDK naming, including camelCase method names.
  • Measurement.getRGB_Red(), getRGB_Green(), getRGB_Blue() return normalized RGB values (typically 0.0 to 1.0 in-gamut), not 0 to 100.
  • HSV semantics match the app scale.
  • Measurement.getHSV_value() returns max(R,G,B)/(R+G+B) in 0.0 to 1.0.
  • Measurement.getHSV_saturation() returns (delta/max(R,G,B))*100 in 0.0 to 100.0 (or -1 for achromatic).
  • Measurement.getHSV_hue() and getHSV_saturation() return -1 for achromatic colors.
  • Measurement.getWavelength_nm() and getWavelength_duv() are computed from the measured chromaticity (u,v) by projection onto the SDK wavelength locus spline.
  • Measurement.getColorTemperature_K() and getColorTemperature_duv() are computed using the SDK blackbody spline table (same table-driven nearest-curve approach used by the original C++ SDK).
  • Wavelength outputs can still be NaN for degenerate or invalid measurements (for example zero/invalid XYZ where chromaticity cannot be projected).
  • PercentMode and related FFT percent settings apply to flicker analysis, not to Measurement RGB getters.