sidescanpy.export.ml.tiles#
Swath tiles for annotation and detection, and boxes drawn on them back to targets.
The round trip a detector workflow needs:
write_swath_tiles()cuts a channel into dual-swath tiles (swath_tiles()), writes each as an 8-bit PNG and records where every tile sits in the sonar data in an index file (tiles.json).People annotate the tiles, or a detector predicts boxes on them, in any tool that exports COCO (FiftyOne, CVAT, Label Studio, …).
read_coco_boxes()reads the boxes per image.boxes_to_targets()turns the boxes on one tile intoTargetrecords: file, ping, side, sample and, on a georeferenced channel, latitude and longitude. They can be rendered as chips withbuild_target_dataset()or scored against a catalog withsidescanpy.targets.score.match_targets().
2026 rshomberg@uri.edu
Contents
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str |
|
One box on a tile image, from an annotation or a detector. |
|
Where one tile image sits in the sonar data (an entry of |
|
Write a channel as dual-swath PNG tiles plus an index for mapping boxes back. |
|
Read a |
|
Read the boxes of a COCO file, per image file name. |
|
Turn boxes drawn on one tile into targets in the sonar data. |
- sidescanpy.export.ml.tiles.TILE_INDEX_NAME = 'tiles.json'#
str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.
- class sidescanpy.export.ml.tiles.TileBox(x, y, w, h, category=None, score=None)#
Bases:
objectOne box on a tile image, from an annotation or a detector.
- Attributes:
- x, y, w, hfloat
Box in image pixels: top-left corner and size.
- categorystr, optional
Class name.
- scorefloat, optional
Detector confidence;
Nonefor a human annotation.
- class sidescanpy.export.ml.tiles.TileRecord(file_name, ss_h5, freq_key, window)#
Bases:
objectWhere one tile image sits in the sonar data (an entry of
tiles.json).- Attributes:
- file_namestr
Image file, relative to the index.
- ss_h5str
Stem of the
.ss.h5file the tile was cut from.- freq_keystr
Frequency channel, e.g.
"hz_400000".- windowNativeWindow
- sidescanpy.export.ml.tiles.write_swath_tiles(ds, out_dir, *, ss_h5, freq_key, tile_m, px_m, overlap_m=0.0, value_var='backscatter_intensity', pct_low=1.0, pct_high=99.0, gamma=1.0)#
Write a channel as dual-swath PNG tiles plus an index for mapping boxes back.
- Parameters:
- dsxr.Dataset
One frequency channel, usually corrected (TVG, so the tiles are even across range).
- out_dirpath
Created if needed. Tiles are written as
<ss_h5>_<freq_key>_<n>.png; the indextiles.jsonthere is extended, so several channels and files can share one folder.- ss_h5, freq_keystr
Where
dscame from: the.ss.h5file stem and frequency key. Recorded in the index so boxes can be traced back to the data.- tile_m, px_m, overlap_mfloat
Tile length along track, pixel size and along-track overlap, in metres (see
swath_tiles()).- value_varstr, default “backscatter_intensity”
- pct_low, pct_high, gammafloat
8-bit stretch (see
to_uint8()), applied per tile.
- Returns:
- list of TileRecord
The tiles written by this call.
- sidescanpy.export.ml.tiles.read_tile_index(path)#
Read a
tiles.jsonwritten bywrite_swath_tiles().- Parameters:
- pathpath
The index file, or the folder holding it.
- Returns:
- dict
{file_name: TileRecord}.
- sidescanpy.export.ml.tiles.read_coco_boxes(path)#
Read the boxes of a COCO file, per image file name.
Works for annotation exports (FiftyOne, CVAT, Label Studio) and for detector results written in COCO form: an annotation’s
scoreis kept when present.- Parameters:
- pathpath
COCO JSON with
images,annotationsandcategories.
- Returns:
- dict
{file_name: [TileBox, ...]}keyed by the image’s file name without folders. Images with no boxes map to an empty list.
- sidescanpy.export.ml.tiles.boxes_to_targets(ds, record, boxes, *, source_format='tile_box', catalog_source='')#
Turn boxes drawn on one tile into targets in the sonar data.
Each box becomes a
Targetat the box centre: the side under the centre (a dual-swath box crossing nadir is clipped to that side), the ping and sample there, and, whendsis georeferenced (latitude_per_sample), the position of that sample.- Parameters:
- dsxr.Dataset
The channel the tile was cut from (
record.ss_h5,record.freq_key), with the same pings and samples.- recordTileRecord
The tile (from
write_swath_tiles()orread_tile_index()).- boxesiterable of TileBox
- source_format, catalog_sourcestr
Recorded on each target (e.g.
"detector"and the model path).
- Returns:
- list of Target
pingandsampleare the dataset’spingandsamplecoordinates at the box centre (the axes a catalog’s ping and sample refer to).extra_attributesholdsss_h5andping_index(socorrelate_target()places the target on that exact ping),ping_meters_per_sample,score,tileand the box size in metres (length_malong track,width_macross).position_confidenceis"verified"for a box without a score (a person drew it) and"approximate"for a detection.