adbo package
Submodules
adbo.ani module
afdorce.ani.py
- adbo.ani.plot_gps(path_in='mult1', gp_file='gp_model_outputs.nc', plot_acq=False, add_name='', verbose=False, save_pdf={}, side_length=3)
Plot GPs. Now supports 1D and 2D plots.
Function currently assumes that the GP file contains the following variables: - ypred: GP prediction - yvar: GP variance - acq: acquisition function
And has the following dimensions: - call: number of calls Either x1 or x1 and x2.
Reads bo-config.json to determine the order of the variables.
- Parameters:
- Return type:
adbo.constants module
This file is used to save all possible project wide constants.
Includes source folder, the project path, etc.
Example
Import statement at top of script:
from tcpips.constants import PROJECT_PATH, FIGURE_PATH
adbo.exp module
Run BayesOpt experiments.
Should contain all tensorflow imports so that other scripts are easier to use/test without waiting for tensorflow to load.
- adbo.exp.gp_model_callback_maker(direc, constraints={'angle': {'max': 80, 'min': -80, 'units': 'degrees'}, 'displacement': {'max': 2, 'min': -2, 'units': 'degrees'}, 'order': ['angle', 'trans_speed', 'displacement'], 'trans_speed': {'max': 15, 'min': 0, 'units': 'm/s'}}, acq_rule=None)
Return a callback function that saves the GP model at each step.
TODO: problem from the animation: the x1 and x2 are not the right way around. Could be a problem in the scaled results.
- Parameters:
- Returns:
Callback function for early_stop_callback.
- Return type:
Callable[[any, any, any], bool]
- adbo.exp.objective_f(cfg)
Return a wrapper function for the ADCIRC model that is compatible with being used as an observer in trieste after processing.
At each objective function call the model is run and the result is returned and saved.
- Returns:
trieste observer function.
- Return type:
Callable[[tf.Tensor], tf.Tensor]
- adbo.exp.run_bayesopt_exp(constraints={'angle': {'max': 80, 'min': -80, 'units': 'degrees'}, 'displacement': {'max': 2, 'min': -2, 'units': 'degrees'}, 'order': ['angle', 'trans_speed', 'displacement'], 'trans_speed': {'max': 15, 'min': 0, 'units': 'm/s'}}, seed=10, profile_name='2025_new_orleans_profile_r4i1p1f1', resolution='mid', exp_name='bo_test', root_exp_direc='/home/docs/checkouts/readthedocs.org/user_builds/worstsurge/checkouts/stable/exp', obs_lon=-90.0715, obs_lat=29.9511, init_steps=10, daf_steps=10, daf='mes', kernel='Matern52', wrap_test=False)
Run a Bayesian Optimisation experiment.
- Parameters:
constraints (dict, optional) – Dictionary with the constraints for the optimization. Defaults to DEFAULT_CONSTRAINTS.
seed (int, optional) – Seed to initialize. Defaults to 10.
profile_name (str, optional) – Name of the profile. Defaults to “2025_new_orleans_profile_r4i1p1f1”.
exp_name (str, optional) – Experiment name. Defaults to “bo_test”.
root_exp_direc (str, optional) – Root directory for the experiments. Defaults to “/work/n01/n01/sithom/adcirc-swan/exp”.
init_steps (int, optional) – How many sobol sambles. Defaults to 10.
daf_steps (int, optional) – How many acquisition points. Defaults to 10.
obs_lon (float, optional) – Longitude of the observation point. Defaults to NEW_ORLEANS.lon.
obs_lat (float, optional) – Latitude of the observation point. Defaults to NEW_ORLEANS.lat.
resolution (str, optional) – Resolution of the model. Defaults to “mid”.
daf (str, optional) – Type of acquisition function. Defaults to “mes”.
kernel (str, optional) – Kernel to use. Defaults to “Matern52”.
wrap_test (bool, optional) – Whether to prevent. Defaults to False.
- Return type:
- adbo.exp.run_exists(exp_name, num_runs)
Check if the experiment has already been run. Check if folder exists. Check if the correct number of subdirectories have been created, and check if the summary results have been stored.
- adbo.exp.setup_tf(seed=1793, log_name='experiment1')
Set up the tensorflow environment by seeding and setting up logging/tensorboard.
adbo.exp_1d module
Conduct a 1D experiment for ease of plotting.
adbo.exp_2d module
adbo.exp_2d.py
adbo.exp_3d module
adbo.exp_3d.py
Run an experiment varying the angle, displacement and speed of the storm for a given tropical cyclone profile.
adbo.gp_exp module
GP experiment module: check the gains from different kernels, andor different prior mean functions.
- adbo.gp_exp.fit_gp(x, y, kernel, mean_function)
Fit a GP model to the data.
- adbo.gp_exp.gather_data(columns=['angle', 'angle', 'displacement', 'trans_speed', 'res'])
Gather data from existing experiments.
Get all the LHS samples from the 3D experiments.
Save it all as a large csv file x(displacement, bearing, angle), z (maximum storm height).
- Return type:
- adbo.gp_exp.load_data(data_path='/home/docs/checkouts/readthedocs.org/user_builds/worstsurge/checkouts/stable/data/adbo/gpr_data.csv')
Load data from a csv file. :type data_path:
str:param data_path: Path to the csv file. :type data_path: str- Returns:
Dataframe containing the data.
- Return type:
pd.DataFrame
- adbo.gp_exp.log_likelihood(model, x_test, y_test, noisy=True)
Return the mean of predictive log-likelihood on a test set.
- adbo.gp_exp.run_exp(kernels=('Matern52', 'Matern12', 'SE', 'RationalQuadratic'), mean_functions=('Constant', 'Linear', 'Polynomial', 'Zero', 'Exponential', 'Periodic'), n_train=25, repeats=100)
Run the experiment.
Scale the data.
Split the data into training and test sets.
Fit the GP model to the training set.
Evaluate the model on the test set (log liklihood, r2, rmse).
Save the results in a csv file and a tex file.
- Parameters:
kernels (tuple, optional) – Kernels to use. Defaults to (“Matern52”, “Matern12”, “SE”, “RationalQuadratic”).
mean_functions (tuple, optional) – Mean functions to use. Defaults to (“Constant”, “Linear”, “Polynomial”, “Zero”, “Exponential”, “Periodic”).
n_train (int, optional) – Number of training samples. Defaults to 25.
repeats (int, optional) – Number of repeats for each experiment. Defaults to 100.
- Return type:
adbo.plot module
Plot results from adcirc Bayesian optimization experiments.
- adbo.plot.custom_parallel_coordinates(df, class_column=None, cols=None, colors=None, constraints=None, balance=False, legend=True, ax=None)
Plots a parallel coordinates chart where each column has its own vertical scale.
- Parameters:
df (pd.DataFrame) – DataFrame with data to plot.
class_column (str, optional) – Column to use for coloring. Defaults to None.
cols (list, optional) – Columns to plot. Defaults to None.
colors (dict, optional) – Colors to use for each class. Defaults to None.
constraints (dict, optional) – Constraints for each column. Defaults to None.
balance (bool, optional) – Balance the data. Defaults to False.
legend (bool, optional) – Show legend. Defaults to True.
ax (Optional[plt.Axes], optional) – Axis to plot on. Defaults to None.
- Returns:
Axis with plot.
- Return type:
plt.Axes
- adbo.plot.find_argdifference(stationid)
Find difference in max value between two years.
- adbo.plot.find_argmax(exp)
Find argmax value in experiment.
- adbo.plot.find_difference(stationid)
Find difference in max value between two years.
- adbo.plot.find_max(exp)
Find max value in experiment.
- adbo.plot.get_max_from_ib_list(iblist)
Get max from ib list.
- adbo.plot.listify(exp, key)
Listify the values of a key in a dictionary.
- adbo.plot.make_argmax_table(daf='mes')
We want to make a table of the argmax values for each experiment.
- Parameters:
daf (str, optional) – DAF name. Defaults to “mes”. Also ran an “ei” experiment.
- Return type:
- Columns:
Name (e.g New Orleans, Galverston, Miami)
Year (e.g 2015, 2100)
Trial (e.g 0, 1, 2)
Argmax index (1 to 50)
Displacement
Angle
Translation Speed
Max SSH
- adbo.plot.plot_diff(exps=('miami-2015', 'miami-2100'), figure_name='2015-vs-2100-miami.pdf')
Plot difference between two years.
- adbo.plot.plot_many(year='2015')
Plot difference between two years.
- adbo.plot.plot_multi_argmax()
- adbo.plot.plot_places(bbox=[('Latitude bounds', [28.0, 31.3], 'degrees_north'), ('Longitude bounds', [-92.5, -86.0], 'degrees_east'), 'New Orleans Area Bounding Box padded by 0.5 degrees'], path_to_maxele='/home/docs/checkouts/readthedocs.org/user_builds/worstsurge/checkouts/stable/exp/8729840-2015/exp_0001/maxele.63.nc')
Plot observation places.
adbo.rescale module
Rescale the parameter inputs to fall in 0.0 to 1.0 range.
This is used to rescale the inputs to the GP, and then rescale the outputs back to the original range.
The parameters are defined in the constraints config file, and the rescaling is done by subtracting the minimum value, and dividing by the range.
Input/output numpy arrays are assumed to be of shape [N, F] where N is the number of points and F is the number of features.
- adbo.rescale.rescale(inputs, constraints, verbose=False)
Rescale the numbers to fall in 0.0 to 1.0 range.
- adbo.rescale.rescale_inverse(inputs, constraints, verbose=False)
Rescale back the numbers to fall in original range.
- Parameters:
- Returns:
rescaled array size [N, F] where N is number of points and F is number of features.
- Return type:
np.ndarray