Skip to content

Low level API

Joe Futrelle edited this page Nov 4, 2016 · 3 revisions

pyifcb provides "low-level" functions for reading IFCB data. These provide minimal capabilities for cases where the higher-level functions do not provide enough flexibility for advanced applications. These are not recommended unless you are writing specialized code and need complete control over when and how IFCB data is read and accessed.

The low-level API is organized into three packages, one for each type of raw data file

ifcb.data.hdr

In the ifcb.data.hdr module, two functions are provided for parsing header files: parse_hdr_file, and parse_hdr.

parse_hdr_file accepts a pathname as an argument and returns a dict of key / value pairs. parse_hdr provides the same output but accepts any iterable over the lines in a header file. Use the latter function if you are reading header data from some location other than a file.

For example, this code reads the 'temperature' field from a header file:

from ifcb.data.hdr import parse_hdr_file

PATHNAME = '/mnt/ifcb_data/D20150101T010101_IFCB100.hdr'

temp = parse_hdr_file(PATHNAME)['temperature']

ifcb.data.adc

A single function, parse_adc_file, can be used to parse ADC data. It can be given any argument that pandas.read_csv will accept (e.g., pathname, buffer) and returns a pandas.DataFrame containing ADC data.

Constants identifying ADC columns are available in the ifcb.data.adc.SCHEMA_VERSION_1 and ifcb.data.adc.SCHEMA_VERSION_2 classes. Unless you are using data from older, pre-commercial instruments, you should use the constants in SCHEMA_VERSION_2.

Column schema constants include names such as ROI_X, TRIGGER, and START_BYTE.

ifcb.data.roi

A single function, read_image, can be used to read an image from a ROI file. It requires four arguments:

  1. An open .roi file or file-like object
  2. The byte offset into that file
  3. The ROI width
  4. The ROI height

It returns a numpy.array with a dtype of np.uint8 containing the image. The parameters are accessible from the ADC data in the START_BYTE, ROI_WIDTH, and ROI_HEIGHT columns from the appropriate schema.

It is not recommended to use this function unless you are familiar with the way that ROI files are formatted. You should use FilesetBin's images property instead.