Utils

seawrd.utils.create_validation_split(input_features: ndarray | DataFrame, input_labels: ndarray | Series, validation_split: float) tuple[ndarray | DataFrame, ndarray | Series, ndarray | DataFrame, ndarray | Series]

Create a validation split from the input features and labels based on the given validation split ratio.

Parameters:
  • input_features (np.ndarray | pd.DataFrame) – The features of the input dataset, which will be split into training and validation sets.

  • input_labels (np.ndarray | pd.Series) – The labels of the input dataset, which will be split into training and validation sets.

  • validation_split (float) – The fraction of the dataset to be used for validation. Must be between 0 and 1.

Returns:

  • x_train (np.ndarray | pd.DataFrame) – The features of the training dataset.

  • y_train (np.ndarray | pd.Series) – The labels of the training dataset.

  • x_val (np.ndarray | pd.DataFrame) – The features of the validation dataset.

  • y_val (np.ndarray | pd.Series) – The labels of the validation dataset.

seawrd.utils.fit_normaliser(train_features: pd.DataFrame | np.ndarray) keras.layers.Normalization

Fit a Keras Normalization layer to the training features.

Parameters:

train_features (pd.DataFrame | np.ndarray) – Training feature pandas DataFrame or numpy array to fit the normalizer.

Returns:

Fitted Keras Normalization layer.

Return type:

keras.layers.Normalization

seawrd.utils.get_logger(name: str, level: int = 20) Logger

Set up a logger with the given name and level. If the logger already has handlers, clear and reset them.

Parameters:
  • name (str) – The name of the logger.

  • level (int, optional) – The logging level, by default logging.INFO

Returns:

The logger with the given name and level.

Return type:

logging.Logger

seawrd.utils.load_npz_bundle(bundle_path: Path) dict[str, ndarray]

Load a NumPy .npz bundle containing training and testing features and labels.

Parameters:

bundle_path (Path) – Path to the .npz bundle file.

Returns:

A dictionary containing the loaded arrays.

Return type:

dict[str, np.ndarray]

Raises:

ValueError – If the bundle is missing any of the required keys: ‘input_features’, ‘input_labels’, ‘test_features’, ‘test_labels’.

seawrd.utils.validate_keras_field(field_name: str, field_type: str)

Validate that Keras can resolve a given field identifier.

Keras provides a mechanism to retrieve various components (like losses, metrics, and activations) using string identifiers. This function checks if the provided field identifier can be resolved by Keras for the specified field type.

Parameters:
  • field_name (str) – The name of the field to validate (e.g., ‘loss’, ‘metric’, ‘activation’).

  • field_type (str) – The name of the Keras module to use for validation (e.g., losses, metrics, activations).

Raises:

ValueError – If the field identifier or type is unknown or unsupported.