GONet Parsers and Writers

File-format readers and writers used by GONetFile and related command workflows.

Parsers Package

Unified interface for GONet file parsers.

The gonet.parsers package provides low-level parsing utilities for reading GONet data and metadata from various file formats. It serves as the centralized entry point for extracting raw image arrays and structured metadata from both processed and unprocessed GONet camera files.

Modules

  • tiff_reader — Parser for standard TIFF image files.

  • raw_reader — Parser for uncompressed RAW .jpg files produced by GONet cameras.

  • exif_reader — Parser for extracting and structuring EXIF metadata from JPEG headers.

EXIF Reader

Parser for EXIF metadata embedded in GONet JPEG files.

This module defines parse_exif_metadata(), which extracts, normalizes, and restructures EXIF metadata from the header of a GONet JPEG image into a hierarchical Python dictionary.

The function decodes camera-embedded fields such as analog gain, exposure time, and Bayer dimensions, organizes GPS coordinates into a dedicated sub-dictionary, and groups JPEG-specific information (e.g., color space, white balance, component configuration) under the 'JPEG' key.

Functions

  • parse_exif_metadata()

    Parse and restructure EXIF metadata from a GONet JPEG file into a nested dictionary with standardized field names.

GONet_Wizard.GONet_utils.src.gonet.parsers.exif_reader.parse_exif_metadata(exif)[source]

Extract and restructure EXIF metadata from a JPEG file into a structured dictionary.

Parameters:

exif (dict) – A dictionary containing raw EXIF metadata extracted from the JPEG file.

Return type:

dict

Returns:

dict – A structured metadata dictionary, with JPEG-related keys under 'JPEG'.

RAW Reader

Parser for GONet RAW .jpg image files.

This module defines parse_raw_file(), which reads uncompressed RAW .jpg files produced by GONet cameras and reconstructs the individual color channels from the packed 12-bit Bayer data stored in the file.

The function unpacks the BGGR Bayer pattern into four subframes (blue, green1, green2, red), rescales the data to the 16-bit range, and returns the channel arrays in GONet’s standard (B, G₁, G₂, R) order.

Functions

  • parse_raw_file()

    Parse a RAW .jpg file and extract blue, green1, green2, and red channel arrays as 16-bit scaled NumPy arrays.

Classes

  • RawFileReadError

    Exception raised when a RAW file cannot be read due to format issues.

exception GONet_Wizard.GONet_utils.src.gonet.parsers.raw_reader.RawFileReadError[source]

Bases: ValueError

Raised when a raw GONet file cannot be read due to invalid format/offsets.

GONet_Wizard.GONet_utils.src.gonet.parsers.raw_reader.parse_raw_file(filepath)[source]

Parse a raw GONet file and extract RGB channel data and optional metadata.

This static method reads a GONet raw file—typically with a .jpg extension but not in standard JPEG format—and extracts the blue, green, and red image channels.

Parameters:

filepath (str) – Path to the raw file to be parsed.

Return type:

ndarray

Returns:

:class:numpy.ndarray – A NumPy array of shape (3, H, W) representing the blue, green, and red channels.

Raises:
  • FileNotFoundError – If the file does not exist or is not accessible.

  • ValueError – If the file format is incompatible or corrupted.

TIFF Reader

Parser for TIFF image files used in GONet data processing.

This module defines a function, parse_tiff_file(), which reads TIFF images and extracts the RGB channel data in the expected GONet format. The function automatically reorders the color channels from the TIFF storage order (R, G, B) to the standard GONet convention (B, G, R).

Functions

  • parse_tiff_file()

    Parse a TIFF file and return the blue, green, and red channel arrays as NumPy arrays.

GONet_Wizard.GONet_utils.src.gonet.parsers.tiff_reader.parse_tiff_file(filepath)[source]

Parse a TIFF file and extract RGB channel data and optional metadata.

This static method reads a TIFF file and separates the image into blue, green, and red channels.

Parameters:

filepath (str) – Path to the TIFF file to be parsed.

Return type:

ndarray

Returns:

:class:numpy.ndarray – A NumPy array of shape (3, H, W) representing the blue, green, and red channels.

Raises:

Writers Package

Unified interface for image export utilities in GONet.

The gonet.writers package consolidates output functions that convert GONet image data into standard file formats for external use and analysis. Each writer handles both GONetFile and GONetFileRaw instances, automatically managing color channel handling, scaling, and metadata propagation.

Modules

  • jpeg — Export GONet data to 8-bit JPEG format.

  • tiff — Export GONet data to 16-bit TIFF format.

  • fits — Export GONet data to multi-extension FITS format.

FITS Writer

Utility for exporting GONet image data to FITS format.

This module defines a function, write_to_fits(), for saving the RGB image data and associated metadata from a GONetFile or GONetFileRaw instance into a standard multi-extension FITS file.

Each color channel is written to a separate FITS image extension (HDU), and all relevant metadata from the GONet file is propagated into the FITS headers. Metadata fields are automatically sanitized to comply with FITS format conventions.

Functions

  • write_to_fits()

    Write GONet RGB data and metadata to a multi-extension FITS file with separate HDUs for each color channel.

GONet_Wizard.GONet_utils.src.gonet.writers.fits.write_to_fits(self, output_filename)[source]

Write the image data to a multi-extension FITS file.

This method saves the blue, green, and red channel data into separate HDUs (Header/Data Units) within a single FITS file. The metadata stored in the meta attribute is propagated into the FITS headers, adhering to the standard FITS format.

Parameters:

output_filename (str) – The full path and filename where the FITS file will be written.

Return type:

None

Returns:

None – This method does not return a value.

Notes

  • The FITS file is created using the astropy.io.fits library.

  • Each color channel (blue, green, red) is stored in a separate image extension.

  • Metadata keys longer than 8 characters or containing lowercase letters or symbols

    will be truncated or sanitized to conform to FITS header requirements.

JPEG Writer

Utility for exporting GONet image data to JPEG format.

This module defines a convenience function, write_to_jpeg(), for saving the RGB image data of a GONetFile or GONetFileRaw instance as a standard 8-bit JPEG image.

The function automatically handles both single-green (averaged) and dual-green (BGGR) channel configurations, applies optional white balance corrections from metadata, rescales pixel values from 16-bit to 8-bit, and ensures the output is clipped and properly formatted for JPEG encoding.

Functions

GONet_Wizard.GONet_utils.src.gonet.writers.jpeg.write_to_jpeg(self, output_filename, white_balance=True)[source]

Write the RGB image data to a JPEG file.

This method assumes that the blue, green, and red channels are in the uint16 range [0, 65535], and rescales them to the standard 8-bit range [0, 255] required for JPEG output. Values outside this range are clipped, and the data is converted to 8-bit for JPEG compatibility.

If white_balance is True, the method applies red and blue channel gains from self.meta['JPEG']['WB'] prior to conversion, in order to produce a more natural-looking image. The white balance is expected to be a list or tuple of two floats: [R_gain, B_gain].

Parameters:
  • output_filename (str) – Path where the resulting JPEG file will be saved.

  • white_balance (bool, optional) – Whether to apply white balance using gains from metadata (default is False).

Raises:

ValueError – If white_balance is True but the WB metadata is missing or invalid.

Return type:

None

TIFF Writer

Utility for exporting GONet image data to TIFF format.

This module provides a generic function, write_to_tiff(), which writes the RGB image data of a GONetFile or GONetFileRaw instance to a standard 16-bit TIFF file.

The function automatically handles both averaged-green and dual-green (BGGR) inputs, applies optional white balance corrections from metadata, and ensures values are safely clipped and cast to uint16 for TIFF compatibility.

Functions

GONet_Wizard.GONet_utils.src.gonet.writers.tiff.write_to_tiff(self, output_filename, white_balance=True)[source]

Write the RGB image data to a TIFF file.

This method assumes that the blue, green, and red channels are in the uint16 range [0, 65535]. Values outside this range are clipped, and the data is cast to uint16 for TIFF compatibility.

If white_balance is True, the method applies red and blue channel gains from self.meta['JPEG']['WB'] prior to writing, in order to produce a more natural-looking image. The white balance is expected to be a list or tuple of two floats: [R_gain, B_gain].

Parameters:
  • output_filename (str) – Path where the resulting TIFF file will be saved.

  • white_balance (bool, optional) – Whether to apply white balance using gains from metadata (default is True).

Raises:

ValueError – If white_balance is True but the WB metadata is missing or invalid.

Return type:

None