Utilities Module#

The utilities module contains helper functions and utilities.

Data selection utilities for electromagnetic field training.

This module provides functionality to select initial training data from the available dataset. Selected data are output to X_train_new.txt.

class EMFieldML.Utils.DataSelect.DataSelect#

Bases: object

Select and manage initial training data for electromagnetic field models.

static select_init_data(n_total_shapes: int = 372) list[int]#

Select initial training data using a systematic sampling pattern.

static generate_x_train_init(output_path_init: Path = None, output_path: Path = None) None#

Generate initial training data files from selected data indices.

static generate_x_test_init(input_path: Path = None, output_path_init: Path = None, output_path: Path = None) None#

Generate test data files from training data indices.

Float comparison utilities for electromagnetic field validation.

This module provides a class for comparing lists of floats within a specified precision.

class EMFieldML.Utils.FloatAssert.FloatAssert(precision: float = 1e-07)#

Bases: object

Float comparison utility for electromagnetic field validation.

__init__(precision: float = 1e-07)#

Initialize the validator with a specified precision.

Parameters:

precision – The precision threshold for float comparisons.

read_floats_from_file(file_path: Path) numpy.ndarray#

Read a list of floats from a specified file, assuming space-separated values in each line.

Parameters:

file_path – Path to the file to read.

Returns:

A NumPy array of floats read from the file.

compare_files(file1: Path, file2: Path) bool#

Compare two files containing lists of floats.

Parameters:
  • file1 – Path to the first file.

  • file2 – Path to the second file.

Returns:

True if the files are equivalent within the specified precision, False otherwise.

compare_float_arrays(array1: numpy.ndarray, array2: numpy.ndarray) bool#

Compare two arrays of floats within the specified precision.

Parameters:
  • array1 – The first array of floats.

  • array2 – The second array of floats.

Returns:

True if the arrays are equivalent within the precision, False otherwise.

Custom logger class to add line numbers to log messages with a level of WARNING or higher.

class EMFieldML.Utils.logger.Logger(level=20, fmt=None, log_file=None, log_dir='log')#

Bases: object

Custom logger class to add line numbers to log messages with a level of WARNING or higher.

level#

The logging level for the logger.

Type:

str

fmt#

The format for the log messages.

Type:

str

log_file#

The log file to write the log messages to.

Type:

str

log_dir#

The directory to store the log files.

Type:

str

__init__(level=20, fmt=None, log_file=None, log_dir='log')#

Initialize the CustomLogger class.

class LineNumberFilter(name='')#

Bases: Filter

Custom filter class to add line numbers.

filter(record)#

Filter log records to add line number information.

get_logger(name)#

Create and configure a logger with the provided name.

Parameters:

name (str) – The name for the logger, typically use __name__ from the calling module.

Returns:

Configured logger instance.

Return type:

logging.Logger

Ferrite shield modeling and parameter generation.

Create parameters for the ferrite shield. 372 types of ferrite shield shapes are created. By preparing 169 positions for these, a total of 62,868 pieces of data are created.

class EMFieldML.Utils.ShieldModeler.ShieldModeler#

Bases: object

Generate ferrite shield shapes and parameters for electromagnetic field modeling.

static make_shield_coordinate() None#

Create parameters for the ferrite shield.