PTW File Functions¶
Overview¶
This module provides functionality to read the contents of files in the PTW file format and convert the raw data to source radiance or source temperature (provided that the instrument calibration data is available).
Functions are provided to read the binary Agema/Cedip/FLIR Inc PTW format into data structures for further processing.
The following functions are available to read PTW files:
readPTWHeader(ptwfilename)showHeader(header)getPTWFrame(header, frameindex)
- readPTWHeader(ptwfilename):
Returns a PTWFrameInfo object with all header information from the ptw file.
- showHeader(header):
Returns nothing. Prints the PTW header content to the screen.
- getPTWFrame(header, frameindex):
Return the raw DL levels of the frame defined by frameindex.
The authors wish to thank FLIR Advanced Thermal Solutions for the permission to publicly release our Python version of the ptw file reader. Please note that the copyright to the proprietary ptw file format remains the property of FLIR Inc.
This package was partly developed to provide additional material in support of students and readers of the book Electro-Optical System Analysis and Design: A Radiometry Perspective, Cornelius J. Willers, ISBN 9780819495693, SPIE Monograph Volume PM236, SPIE Press, 2013. http://spie.org/x648.html?product_id=2021423&origin_id=x646
Module classes¶
- class PTWFrameInfo[source]¶
Bases:
objectContainer for PTW file header and frame information.
Attributes are populated by
readPTWHeader()(file-level fields) andGetPTWFrameFromFile()(per-frame fields). Attribute names follow the original DL002U-D Altair Reference Guide conventions.
- class JadeCalibrationData(filename, datafileroot)[source]¶
Bases:
objectContainer and loader for Jade camera calibration data.
Reads an XML calibration file and associated spectral data files, then builds a
pyradi.rylookup.RadLookuptable for DL ↔ temperature / radiance conversion.- Parameters:
Module functions¶
- readPTWHeader(ptwfilename)[source]¶
Read the PTW file header and return a populated PTWFrameInfo object.
- Parameters:
ptwfilename (str) – Full path to the ptw file.
- Returns:
Object containing all PTW header information.
- Return type:
- Raises:
No exception is raised. –
- Reference:
Header field names and byte positions are from DL002U-D Altair Reference Guide.
- showHeader(Header)[source]¶
Print all PTW header fields to stdout.
- Parameters:
Header (PTWFrameInfo) – PTW file header object.
- Returns:
None
- getPTWFrame(header, frameindex)[source]¶
Retrieve a single PTW frame given the header and frame index.
The frame data array is also stored inside header as
header.data. The header is returned explicitly to make it clear that its contents have been updated (frame time, detector temperature).- Parameters:
header (PTWFrameInfo) – PTW file header object.
frameindex (int) – 1-based index of the frame to extract.
- Returns:
(data, header)where data isnp.ndarrayof shape(rows, cols)containing raw DL values, and header is the updated PTWFrameInfo object. On error a barenp.ndarray([0])is returned instead of the tuple.- Return type:
- Raises:
No exception is raised. –
- GetPTWFrameFromFile(header)[source]¶
Load the frame specified by header.h_framepointer from the PTW file.
- Parameters:
header (PTWFrameInfo) – Header object with h_framepointer set to the desired 1-based frame index.
- Returns:
- The same header object, updated with:
data(np.ndarray of shape(cols, rows)),h_frameMinute,h_frameHour,h_frameSecond,h_detectorTemp,h_sensorTemp4,h_minval,h_maxval.
- Return type:
- Raises:
No exception is raised. –
- getPTWFrames(header, loadFrames=[])[source]¶
Retrieve multiple PTW frames specified by a list of frame indices.
- Parameters:
header (PTWFrameInfo) – PTW file header object.
- Returns:
(data, fheaders)where data isnp.ndarrayof shape(len(loadFrames), rows, cols)and fheaders is a list of PTWFrameInfo objects (one per frame, carrying frame time and FPA temperature). On error returns(np.asarray([0]), None).- Return type:
- Raises:
No exception is raised. –
- myint(x)[source]¶
Decode a 2-byte little-endian signed integer from a bytes slice.
- Parameters:
x – bytes of length 2.
- Returns:
signed 16-bit integer value.
- Return type:
- mylong(x)[source]¶
Decode a 4-byte little-endian unsigned integer from a bytes slice.
- Parameters:
x – bytes of length 4.
- Returns:
unsigned integer value.
- Return type:
Note
Pre-existing bug: the shift for byte 3 is
x[3] << 32instead of the correctx[3] << 24. When byte 3 is non-zero the result is larger than expected by a factor of 256. In practice all PTW integer fields fit within 24 bits so byte 3 is always 0 and the result is correct.
- myfloat(x)[source]¶
Decode a 4-byte IEEE 754 single-precision float from a bytes slice.
- Parameters:
x – bytes of length 4.
- Returns:
single-precision floating-point value.
- Return type:
- mydouble(x)[source]¶
Decode an 8-byte IEEE 754 double-precision float from a bytes slice.
- Parameters:
x – bytes of length 8.
- Returns:
double-precision floating-point value.
- Return type:
- mybyte(x)[source]¶
Decode a single unsigned byte from a bytes slice of length 1.
- Parameters:
x – bytes of length 1.
- Returns:
unsigned byte value (0–255).
- Return type:
Note
Will raise
TypeErrorif x is longer than one byte.
- mypass(x)[source]¶
Identity function — return x unchanged.
- Parameters:
x – any value.
- Returns:
The input x unchanged.
- myRGB(x)[source]¶
Decode three bytes as an HTML-style hex colour string.
- Parameters:
x – bytes of length 3, ordered R, G, B.
- Returns:
colour string of the form
'#rrggbb'.- Return type:
- terminateStrOnZero(str)[source]¶
Iterate through str and terminate on the first null byte.
- Parameters:
str – bytes object to scan.
- Returns:
prefix of str up to (but not including) the first null byte.
- Return type:
Note
Pre-existing Python-3 bug:
str[idx]on a bytes object returns anint, so the comparisonstr[idx] != '\00'(int vs str) is alwaysTrueand the loop never exits early. The function therefore always returns the full input slice unchanged. Callers inreadPTWHeadercompensate by using.rstrip('\x00')on the decoded string, which achieves the intended trimming for null-padded fields.