Skip to content

Hook Reference

HookModeDescription
detect_formatfirstresultIdentify a sonar file’s format
extract_navfirstresultExtract lat/lon track from a file
get_format_signatureshistoricContribute magic byte signatures
get_extension_maphistoricContribute extension-to-format mappings
export_datafirstresultExport data to a specific format
get_export_formatshistoricList available export formats
register_web_routeshistoricAdd routes to the Flask web app

Mode: firstresult (first non-None result wins)

Identify the sonar format of a file based on its header bytes and/or extension.

ParameterTypeDescription
file_pathstrAbsolute path to the file
headerbytesFirst 32 bytes of the file
extensionstrFile extension (lowercase, with dot)

str — Format name (e.g., "xtf", "jsf"), or None to pass.

def detect_my_format(file_path=None, header=None, extension=None, **kw):
if header and header[:2] == b"\xAB\xCD":
return "my_format"
return None

Mode: firstresult

Extract navigation (lat/lon) track data from a sonar file.

ParameterTypeDescription
file_pathstrAbsolute path to the file
sonar_formatstrDetected format name
sidecar_configlist[dict]Sidecar file patterns from config

NavResult — with .track (list of [lat, lon] pairs) and .source (string identifier), or None.

from sonar_catalog.extractors.base import NavResult
def extract_my_nav(file_path=None, sonar_format=None, **kw):
if sonar_format != "my_format":
return None
track = parse_my_file(file_path)
return NavResult(track=track, source="my_format_nav")

Mode: historic (all plugins contribute)

Return magic byte signatures and extension mappings for format detection.

None (called with no arguments).

dict with optional keys:

{
"signatures": [
{
"format": "my_format",
"hex_bytes": "abcd",
"byte_length": 2,
"offset": 0,
}
],
"extensions": {
".myf": "my_format",
},
}

Mode: historic

Return a mapping of file extensions to format names.

dict[str, str] — e.g., {".myf": "my_format", ".myformat": "my_format"}


Mode: firstresult

Export catalog data to a specific file format.

ParameterTypeDescription
datalist[dict]Rows from the catalog
format_namestrTarget format (e.g., "csv", "geojson")
output_pathstr or NoneOutput file path (None = return as string)

str — The output (file path or string content), or None to pass.


Mode: historic

List the export formats this plugin provides.

list[dict] — Format descriptors:

[
{
"name": "my_export",
"description": "My custom export format",
"extension": ".myexp",
}
]

Mode: historic

Register additional routes on the Flask web application.

ParameterTypeDescription
appFlaskThe Flask application instance
def register_my_routes(app=None, **kw):
@app.route("/my-plugin/status")
def plugin_status():
return {"status": "ok"}