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:
  • path_in (str, optional) – name of data folder. Defaults to “mult1”.

  • gp_file (str, optional) – name of GP file. Defaults to “gp_model_outputs.nc”.

  • plot_acq (bool, optional) – Plot acquisition function. Defaults to False.

  • add_name (str, optional) – Additional name for the gif. Defaults to “”.

Return type:

None

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:
  • direc (str) – Directory to save the models.

  • constraints (dict, optional) – Dictionary with the constraints for the optimization. Defaults to DEFAULT_CONSTRAINTS.

  • acq_rule (Optional[EfficientGlobalOptimization], optional) – The acquisition rule. Defaults to None.

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:

None

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.

Parameters:

exp_name (str) – Name of the experiment.

Returns:

Whether the experiment has already been run.

Return type:

bool

adbo.exp.setup_tf(seed=1793, log_name='experiment1')

Set up the tensorflow environment by seeding and setting up logging/tensorboard.

Parameters:
  • seed (int, optional) – Random seed for numpy/tensorflow. Defaults to 1793.

  • log_name (str, optional) – Name for the log. Defaults to “experiment1”.

Return type:

None

adbo.exp_1d module

Conduct a 1D experiment for ease of plotting.

adbo.exp_1d.create_1d_run()

Run a 1D experiment to make an animation of the GP model output being refined in BayesOpt.

Return type:

None

adbo.exp_2d module

adbo.exp_2d.py

adbo.exp_2d.create_2d_ani_run()

Run a 2D experiment to make an animation of the GP model output being refined in BayesOpt.

Return type:

None

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.exp_3d.run_3d_exp()

Run an experiment varying the angle, displacement and speed of the storm for a given tropical cyclone profile.

Return type:

None

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.

Parameters:
  • x (np.ndarray) – Input data.

  • y (np.ndarray) – Output data.

  • kernel (str) – Kernel to use.

  • mean_function (str) – Mean function to use.

Returns:

Fitted GP model.

Return type:

gpflow.models.GPR

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:

None

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.

Parameters:
  • model (gpflow.models.GPR) – The GP model.

  • x_test (np.ndarray) – Test input data.

  • y_test (np.ndarray) – Test output data.

  • noisy (bool, optional) – Whether to include noise in the prediction. Defaults to True.

Returns:

The average log-likelihood.

Return type:

float

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:

None

adbo.gp_exp.save_results_tex(n_train=25)

Save the results in a LaTeX table.

Parameters:

n_train (int, optional) – Number of training samples. Defaults to 25.

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.

Parameters:

stationid (int) – Station ID.

Returns:

argmax1, argmax2, take_diff(argmax1, argmax2)

Return type:

Tuple[float, float, float]

adbo.plot.find_argmax(exp)

Find argmax value in experiment.

Parameters:

exp (dict) – Experiment dictionary.

Returns:

Index of maximum value.

Return type:

int

adbo.plot.find_difference(stationid)

Find difference in max value between two years.

Parameters:

stationid (int) – Station ID.

Returns:

Difference in max value.

Return type:

float

adbo.plot.find_differences()

Find differences in max values.

Return type:

None

adbo.plot.find_max(exp)

Find max value in experiment.

Parameters:

exp (dict) – Experiment dictionary.

Returns:

Maximum value.

Return type:

float

adbo.plot.get_max_from_ib_list(iblist)

Get max from ib list.

Parameters:

iblist (List[Tuple[int, int]]) – List of tuples.

Return type:

Tuple[List[float], List[int]]

adbo.plot.listify(exp, key)

Listify the values of a key in a dictionary.

Parameters:
  • exp (dict) – Experiment dictionary.

  • key (str) – Key to listify.

Returns:

List of values.

Return type:

List[float]

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:

None

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_bo_comp()
Return type:

None

adbo.plot.plot_bo_exp()
Return type:

None

adbo.plot.plot_diff(exps=('miami-2015', 'miami-2100'), figure_name='2015-vs-2100-miami.pdf')

Plot difference between two years.

Parameters:
  • exps (Tuple[str, str], optional) – Experiment names. Defaults to (“miami-2015”, “miami-2100”).

  • figure_name (str, optional) – Figure name. Defaults to “2015-vs-2100-miami.pdf”.

Return type:

None

adbo.plot.plot_many(year='2015')

Plot difference between two years.

Parameters:

year (str, optional) – Year to plot. Defaults to “2015”.

Return type:

None

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.

Parameters:
  • bbox (optional, Optional[BoundingBox]) – edge of bounding box.

  • path_to_maxele (str, optional) – path to maxele file. Defaults to os.path.join(EXP_PATH, “8729840-2015”, “exp_0001”, “maxele.63.nc”).

Return type:

None

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.

Parameters:
  • inputs (np.ndarray) – Input array [N, F].

  • constraints (dict) – constraints dictionary. Should have key “order”.

  • verbose (bool) – Print debug information. Default is False.

Returns:

Rescaled array [N, F].

Return type:

np.ndarray

adbo.rescale.rescale_inverse(inputs, constraints, verbose=False)

Rescale back the numbers to fall in original range.

Parameters:
  • inputs (np.ndarray) – Input array [N, F].

  • constraints (dict) – constraints dictionary. Should have key “order”.

  • verbose (bool) – Print debug information. Default is False.

Returns:

rescaled array size [N, F] where N is number of points and F is number of features.

Return type:

np.ndarray

adbo.rescale.test_rescale_test(verbose=True)

Test rescale function can round trip/ is self inverse and accurate.

Parameters:

verbose (bool) – Print debug information. Default is True.

Return type:

None

Examples

>>> test_rescale_test(verbose=False)
Rescaling round trip test passed.

Module contents