MRP.MRPReading
stores all reading relevant information values, datapoints, meta-data
- class MRPReading.MRPReading(_config: MRPMeasurementConfig | None = None, _magnet_id: int = 0)
Stores the raw sensor data, including metadata and import/export functions
- dump_savemat(_filepath_name: str) str
Dumps the reading class instance into a matlab .mat file Includes datapoints only
- dump_to_dict() dict
Serializes the current object into a dictionary format for data export.
- Returns:
- dict: A dictionary containing the serialized data of the object, including
timestamps, additional data, the measurement configuration, and the main dataset.
This function creates a dictionary containing key pieces of information about the current object: - dump_time: The time when the dump occurs. - time_start and time_end: The start and end times of the measurement, formatted based on the export time format. - additional_data: A dictionary containing any additional metadata associated with the object. - data: The main dataset, with each entry converted to a dictionary. - measurement_config: Serialized measurement configuration.
The function also ensures that any extra user data stored in additional_data is directly added to the final dictionary. A placeholder comment is added for potential serialization of more complex objects.
- dump_to_file(_filepath_name: str) str
Dumps the reading class instance into a binary file. Including datapoints, config, measurement_config and additional_data as metadata
- get_additional_data(_k: str) any
Retrieve additional data associated with the given key from the instance’s additional_data dictionary.
Parameters: - _k (str): The key for which to retrieve the associated data. This should be a non-empty string.
Returns: - any: The value associated with the specified key if it exists; otherwise, returns None.
- get_magnet_type() MagnetType
Retrieves the current magnet type from the measurement_config configuration.
- Returns:
MRPMagnetTypes.MagnetType: The currently set magnet type from the measurement_config.
This function accesses the measurement_config object and returns the current magnet type that is stored in the magnet_type attribute.
- get_name() str
Returns the name of the reading
- Returns:
Returns reading name set using set_name(_name_)
- Return type:
- has_additional_data(_k: str) bool
Checks if the provided key exists and is valid in the additional_data dictionary.
- Args:
_k (str): The key to be checked in the additional_data dictionary.
- Returns:
- bool:
True if the key exists and is non-empty.
False if the key is None, empty, or not found in additional_data.
The function first ensures that the input key _k is not None and has a length greater than zero. If the key passes this condition, it checks if the key exists in the additional_data dictionary.
- has_additional_data_keys(_keys: list[str]) bool
Checks if all the provided keys exist in the additional_data dictionary.
- Args:
_keys (list[str]): A list of keys to be checked in the additional_data dictionary.
- Returns:
- bool:
True if all keys in the list exist in additional_data.
False if any key in the list is missing from additional_data.
This function iterates over a list of keys and checks if each one exists in the additional_data dictionary by calling the has_additional_data method for each key. If any key is missing, the function returns False; otherwise, it returns True when all keys are present.
- insert_reading(_read_value: float, _phi: float, _theta: float, _reading_index_phi: int, _reading_index_theta: int, _is_valid: bool = True, _autoupdate_measurement_config: bool = True)
Inserts a new reading into the dataset. The _phi, _theta values need to be valid polar coordinates
- Parameters:
_read_value (float) – hallsensor reading in [mT]
_phi (float) – polar coordinates of the datapoint: phi
_theta (float) – polar coordinates of the datapoint: theta
_reading_index_phi (int) – index of the phi coordinate count = resolution for phi axis
_reading_index_theta (int) – index of the theta coordinate count = resolution for theta axis
_autoupdate_measurement_config (bool)
- insert_reading_instance(_measurement: MRPReadingEntry, _autoupdate_measurement_config: bool = True)
Inserts a new reading into the dataset using an instance of MRPReadingEntry
- Parameters:
_measurement (MRPReadingEntry.MRPReadingEntry) – reading measurement
_autoupdate_measurement_config (bool)
- load_from_file(_filepath_name: str)
Loads a given .mag.json file from a previous dump_to_file(). It restores all meta-data and datapoints.
- Parameters:
_filepath_name (str) – ABS or REL Filepath-string filepath to .mag.pkl
- set_additional_data(_k: str, _v: any)
Set a custom user meta-data entry. For example if the
apply_calibration_data_inplaceis used on a reading, a custom entry `is_calibrated`=1 is added to the reading using this function.
- set_magnet_type(_type: MagnetType)
Sets the magnet type in the measurement_config configuration.
- Args:
_type (MRPMagnetTypes.MagnetType): The magnet type to be set.
This function updates the magnet_type attribute in the measurement_config object with the provided _type value. The _type should be a valid MagnetType from the MRPMagnetTypes class.
- set_name(_name: str = 'unknown')
Sets the name of the reading
- Parameters:
_name (str) – name of the reading
- set_unit_import_scale_factor(_factor: float = 1.0)
Sets the import scale factor for unit conversions or data imports.
- Args:
- _factor (float, optional): The scale factor to be applied during data import or unit conversion.
Defaults to 1.0.
This function updates the import_scale_factor attribute, which can be used to scale imported data or convert units as needed. By default, the factor is set to 1.0, indicating no scaling.
- to_measurement_entry_array() list[MRPReadingEntry]
Returns all values as 1d array in order of insertion.
- Returns:
Returns [value, value]
- Return type:
- to_numpy_cartesian(_normalize: bool = True, _use_sensor_distance: bool = False) array
Converts spherical coordinate data to Cartesian coordinates and returns them as a NumPy array.
- Args:
_normalize (bool, optional): Whether to normalize the data (currently not used in the function). Defaults to True. _use_sensor_distance (bool, optional): Whether to use the sensor distance radius for the conversion. Defaults to False.
- Returns:
np.array: A NumPy array containing the converted Cartesian coordinates.
This function iterates over the spherical data (phi, theta, and value) in the data list. It converts the spherical coordinates to Cartesian using MRPHelpers.asCartesian(). If _use_sensor_distance is True, it uses the sensor distance radius from the measurement_config for the conversion; otherwise, it uses the value from the data for the conversion.
- to_numpy_matrix() ndarray
Generates a matrix representation of the reading. Here eah datapoint will be Note: only the value entry is included RETURN FORMAT: [[phi, theta, value],…]
- Returns:
Returns the matrix with shape ()
- Return type:
np.ndarray
- to_numpy_polar(_normalize: bool = False) ndarray
Generates a 2D numpy array from the stored datapoints. Note: only the value entry is included RETURN FORMAT: [[phi, theta, value],…]
- to_temperature_value_array() ndarray
Returns all temperature values as 1d array in order of insertion.
- Returns:
Returns [value, value]
- Return type:
np.ndarray
- to_value_array() ndarray
Returns all values as 1d array in order of insertion.
- Returns:
Returns [value, value]
- Return type:
np.ndarray
- update_data_from_numpy_polar(_numpy_array: ndarray)
_numpy_array is a (x, 3) shaped array with [[phi, theta, value],…] structured data each matching phi, theta combination in the reading.data structure will be updated with the corresponding value from the _numpy_array entry
- Parameters:
_numpy_array (np.ndarray) – datapoints to update: [[phi, theta, value],…]
- exception MRPReading.MRPReadingException(message='MRPReadingException thrown')
Custom exception class for handling errors related to MRP (Magnetometer Reading Processing).
- Args:
- message (str, optional): The error message to be displayed when the exception is raised.
Defaults to “MRPReadingException thrown”.
This class extends the built-in Exception class to provide a specific exception type for errors encountered during MRP-related operations. The message can be customized or will default to a standard message.
- with_traceback()
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.