moordiag

moordiag — generate engineering diagrams for oceanographic moorings from YAML configuration files.

moordiag.readers

Configuration and image loading functions for mooring diagram generator.

moordiag.readers.load_image_metadata()[source]

Load image dimensions from images.yaml.

moordiag.readers.load_mooring_config(config_path)[source]

Load and validate a mooring YAML config. Raises FileNotFoundError or ValueError on bad input.

moordiag.tools

Calculation and data processing tools for mooring diagram generator.

moordiag.tools.calculate_element_spacing(element, prev_element, config)[source]

Calculate spacing between two elements based on depth and repeat groups.

moordiag.tools.calculate_hardware_move_distance(current_element, prev_element, image_metadata, config)[source]

Calculate move distance for hardware elements with fixed rope/chain heights.

moordiag.tools.calculate_hardware_spacing(element, prev_element, config)[source]

Calculate spacing between hardware elements - zero spacing except for glass spheres.

moordiag.tools.calculate_instrument_stack_height(instruments, image_metadata, config)[source]

Calculate total height needed for a stack of instruments using mooring spacing logic.

moordiag.tools.calculate_layout_positions(elements, image_metadata, config, direction='bottom_up')[source]

Calculate exact layout positions for elements using bottom_up logic (like original).

moordiag.tools.calculate_layout_positions_hardware(elements, image_metadata, config)[source]

Calculate layout positions for hardware elements.

moordiag.tools.calculate_missing_depth_or_hab(element, waterdepth)[source]

Calculate missing depth or HAB values based on waterdepth, or recalculate depth from HAB.

moordiag.tools.calculate_move_distance(current_element, prev_element, image_metadata, config)[source]

Calculate exact move distance between two elements using original spacing logic.

moordiag.tools.calculate_plotted_height(elements, image_metadata, config)[source]

Calculate height span from layout positions using bottom_up (standard).

moordiag.tools.calculate_subplot_layout(positioned_elements, image_metadata, direction, center_x, config=None)[source]

Use pre-calculated positions and adjust for left/right column placement.

moordiag.tools.expand_repeats_hardware(elements)[source]

Expand hardware elements that have ‘repeat’ field into multiple elements.

moordiag.tools.find_column_breaks_with_positions(elements, image_metadata, config, column_height_limit)[source]

Find where to break elements into columns and return with calculated positions.

moordiag.tools.get_deploy_status(config)[source]

Return a display string for mooring deployment status.

Uses the ‘status’ field if present (any string is accepted; unknown values trigger a warning at validation time but are still formatted as “as <value>”). Falls back to checking seabed_latitude for backwards compatibility with configs that predate the status field.

moordiag.tools.get_element_position_value(element, use_hab=False)[source]

Get the position value for sorting - either depth or HAB.

moordiag.tools.get_hardware_plot_height(element, image_metadata, config)[source]

Get plotting height for hardware element - use fixed height for ropes + instruments.

moordiag.tools.group_elements_for_splitting(elements)[source]

Group elements by their original element ID to keep repeat groups together.

moordiag.tools.sort_elements_by_depth(elements, use_hab=False)[source]

Sort elements by depth (deep to shallow for top-to-bottom display) - simplified for regular diagrams.

moordiag.tools.sort_elements_by_position(elements)[source]

Sort hardware elements by position number (inline first, then clamp).

moordiag.tools.split_elements_into_pages(layout_elements, image_metadata, config)[source]

Split elements into multiple pages based on actual height calculations.

moordiag.tools.validate_array_config(config)[source]

Validate an array config dict. Logs warnings for missing or malformed entries.

moordiag.tools.validate_mooring_config(config)[source]

Validate a mooring config dict. Raises ValueError for fatal errors, logs warnings for minor ones.

moordiag.coordinates

Coordinate formatting utilities for oceanographic mooring diagrams.

Provides CoordConverter for decimal-degrees → degrees/decimal-minutes formatting. Standalone map-bounds and cruise-track helpers archived in archive/coordinates-old202607.py.

class moordiag.coordinates.CoordConverter[source]

Bases: object

Utility class for coordinate unit conversions.

This class provides static methods for converting between different coordinate representations commonly used in maritime and scientific contexts.

static decimal_degrees_to_ddm(decimal_degrees: float) tuple[float, float][source]

Convert decimal degrees to degrees and decimal minutes.

Parameters:

decimal_degrees (float) – Coordinate in decimal degrees format.

Returns:

Tuple of (degrees, decimal_minutes).

Return type:

tuple of float

Examples

>>> CoordConverter.decimal_degrees_to_ddm(65.7458)
(65.0, 44.75)
static format_latitude_decmin(decimal_degrees: float) str[source]

Convert latitude to decimal minutes format.

Parameters:

decimal_degrees (float) – Latitude in decimal degrees format.

Returns:

Latitude in “DD MM.MMM N/S” format.

Return type:

str

Examples

>>> CoordConverter.format_latitude_decmin(65.244)
"65 14.640 N"
>>> CoordConverter.format_latitude_decmin(-65.244)
"65 14.640 S"
static format_longitude_decmin(decimal_degrees: float) str[source]

Convert longitude to decimal minutes format.

Parameters:

decimal_degrees (float) – Longitude in decimal degrees format.

Returns:

Longitude in “DDD MM.MMM E/W” format.

Return type:

str

Examples

>>> CoordConverter.format_longitude_decmin(-31.3177)
"031 19.062 W"
>>> CoordConverter.format_longitude_decmin(31.3177)
"031 19.062 E"

moordiag.drawing

Drawing and visualization functions for mooring diagram generator.

moordiag.drawing.add_continuation_indicator(ax, layout, subplot_type)[source]

Add dashed line and ‘continued…’ label to indicate mooring continues.

moordiag.drawing.add_depth_labels(ax, layout, use_hab=False, config=None)[source]

Add depth labels to the left of each image or repeat group (shows unique depth/HAB values only).

moordiag.drawing.add_element_labels(ax, layout, show_sample_interval=False)[source]

Add element labels to the right of each image or repeat group.

moordiag.drawing.add_metadata_box(ax, config)[source]

Add metadata box across bottom of page with title section and table.

moordiag.drawing.add_rope_distance_markers(ax, instrument_positions, rope_start_hab, rope_end_hab, rope_center_x)[source]

Add blue distance markers showing distances from rope ends to instruments.

moordiag.drawing.draw_instruments_on_rope(ax, rope_element, rope_item, image_metadata, config=None, current_plot_y=None)[source]

Draw instruments positioned on an extended rope section.

moordiag.drawing.draw_mooring_line(ax, layout, is_anchor_column=False, is_topmost_column=False, config=None)[source]

Draw the continuous mooring line behind all images with appropriate extensions.

moordiag.drawing.get_element_image_path(image_filename)[source]

Get the path to an element image file from the package resources.

moordiag.drawing.place_images(ax, layout, image_metadata, config=None)[source]

Place element images with continuous y-positioning for rope instruments.

moordiag.page_generator

Page generation and layout functions for mooring diagram generator.

moordiag.page_generator.add_mooring_backbone_line(ax, layout)[source]

Add a thin black vertical line representing the mooring backbone from anchor to top.

moordiag.page_generator.add_timestamp(ax)[source]

Add a small timestamp in the lower right corner.

moordiag.page_generator.generate_single_page(page_data, config, image_metadata, page_num, total_pages, output_dir, dpi=300, temp_file=False, skip_metadata=False, debug_mode=False)[source]

Generate a single page of the mooring diagram.