API Reference
This section provides detailed documentation for all modules and functions in the pyoxynet package.
Utilities Module
The utilities module contains the core functionality for data processing, model loading, and inference.
- utilities.PrintHello(hello='hello')[source]
This function prints to screen.
- Parameters:
name (str) – The name to use.
- Returns:
none
- utilities.compute_shap(explainer, df, n_inputs=6, past_points=40, shap_stride=20)[source]
Computes SHAP values
- Parameters:
explainer (explainer SHAP) – deep explainer that explains the deep learning model
data (pd df) – data for the local explanation
- Returns:
SHAP values
- Return type:
shap (dict)
- utilities.create_probabilities(duration=600, VT1=320, VT2=460, training=True, normalization=False, resting=True, resting_duration=60, initial_step=False, y_pm0=1, generator=False, sigmoid_steepness=0.05)[source]
Creates piecewise-linear probabilities for moderate/heavy/severe zones with enforced overlaps at VT1 and VT2.
- Behaviour:
- Nodes at t=1, VT1, VT2, duration with values:
t=1 : (y_pm0, 1-y_pm0, 0) VT1 : (0.5, 0.5, 0) VT2 : (0.0, 0.5, 0.5) end : (0.0, 0.0, 1.0)
Linear interpolation between these nodes ensures fully linear transitions, exact overlaps at VT1 and VT2, and sum-to-1 (after numerical normalization).
- utilities.draw_real_test(resting='random')[source]
Draw a single data file from the directory containing all the real files
- Parameters:
none
- Returns:
Real data output
- Return type:
df (pandas df)
- utilities.generate_CPET(generator, plot=False, fitness_group=None, noise_factor=None, resting=False, training=True, normalization=False)[source]
Generate synthetic CPET data using the TensorFlow generator model.
NOTE: This function requires a loaded TensorFlow generator model (not TFLite). Use load_tf_generator() to load the model first. Requires full TensorFlow installation.
- Parameters:
generator – TensorFlow generator model (required). Use load_tf_generator() to load.
plot (bool) – Whether to plot the generated data. Default False.
fitness_group (int) – Fitness level: 0=very low, 1=low, 2=medium, 3=high. None=random.
noise_factor (float) – Noise factor for white noise (1.5-2.5). None=random.
resting (bool) – Whether to include resting phase. Default False.
training (bool) – Training mode flag. Default True.
normalization (bool) – Whether to normalize data. Default False.
- Returns:
Pandas dataframe with generated CPET data data (dict): Metadata about the generated CPET test
- Return type:
df (pd.DataFrame)
- Raises:
ValueError – If generator model is None or invalid
ImportError – If required dependencies are missing
Note
The generator uses a hardcoded input shape of [1, 23] which consists of: - 20 dimensions for data noise - 3 dimensions for domain probabilities (moderate, heavy, severe)
- utilities.get_sec(time_str)[source]
This function converts strings to time.
- Parameters:
time_str (str) – The time str.
- Returns:
total seconds (int)
- utilities.load_csv_data(csv_file='data_test.csv')[source]
Loads data from csv file (returns test data if no arguments)
- Parameters:
n_inputs (int) – Number of input variables.
past_points (int) – Number of past inputs in the time-series.
- Returns:
Model output example
- Return type:
df (pandas df)
- utilities.load_exercise_threshold_app_data(data_dict={}, filter_size=20)[source]
Loads data from data dict with format provided by https://www.exercisethresholds.com/
- Parameters:
data_dict (dict) – Dictionary with format like test/exercise_threshold_app_test.json
- Returns:
Pandas data frame with format that can be used by Pyoxynet for inference (columns needed: ‘VO2_I’, ‘VCO2_I’, ‘VE_I’, ‘PetO2_I’, ‘PetCO2_I’, ‘VEVO2_I’, ‘VEVCO2_I’)
- Return type:
df (pandas df)
- utilities.load_explainer(tf_model)[source]
Loads a deep explainer from the shap library and automatically loads the data to train it
- Parameters:
tf_model (Model class) – deep learning model that deep explainer needs to explain
- Returns:
deep explainer SHAP
- Return type:
explainer (deep)
- utilities.load_tf_generator()[source]
This function loads the saved TensorFlow generator model.
NOTE: This function requires full TensorFlow installation and will NOT work with tflite_runtime only. If you installed the lite version of pyoxynet, this generator functionality is not available.
- Parameters:
None
- Returns:
Handle on the TensorFlow generator model, or None if unavailable
- Return type:
generator (TF model)
- utilities.load_tf_model(n_inputs=5, past_points=40, model='CNN')[source]
This function loads the saved tf models.
- Parameters:
n_inputs (int) – Number of input variables.
past_points (int) – Number of past inputs in the time-series.
- Returns:
handle on the TFLite interpreter
- Return type:
interpreter (tflite interpreter)
- utilities.normalize(df, min_target=-1, max_target=1)[source]
Pandas df normalisation
- Parameters:
df (pd df) – input df
- Returns:
output df
- Return type:
result (pd df)
- utilities.optimal_filter(t, y, my_lambda)[source]
A bad ass optimisation filter
- Parameters:
t – array Independent coord array
y – array Dependent coord array
my_lambda – float Smoothing factor
- Returns:
- array
Filtered variable
- Return type:
x
- utilities.random_walk(length=1, scale_factor=1, variation=1)[source]
Random walk generator
- Parameters:
length (int) – Length of the output list
scale_factor (float) – Scale factor to be applied to the whole output
variation (float) – Local variation of the main signal with the random walk
- Returns:
none
- utilities.test_pyoxynet(tf_model=[], input_df=[], n_inputs=5, past_points=40, model='CNN', plot=False, inference_stride=1)[source]
Runs the pyoxynet inference
- Parameters:
tf_model (TF model) – Model uploaded with load_tf_model
n_inputs (int) – Number of inputs (deafult to Oxynet configuration)
past_points (int) – Number of past points in the time series (deafult to Oxynet configuration)
inference_stride (int) – Stride inference for NN - speed up computation
- Returns:
Model output example
- Return type:
x (array)
Testing Module
The testing module provides functions for testing and validating the package functionality.
Model Module
The model module contains model-related utilities and configurations.