pinnicle.utils

pinnicle.utils.backends_specified module

pinnicle.utils.backends_specified.jacobian(output_var, input_var, i, j, val=0)

Compute jacobian using deepxde

pinnicle.utils.backends_specified.jacobian_jax(output_var, input_var, i, j, val=0)[source]

Compute jacobian using deepxde This is a hack for now to take the first entry from the tuple returned by jax

pinnicle.utils.backends_specified.jacobian_tf(output_var, input_var, i, j, val=0)[source]

Compute jacobian using deepxde

pinnicle.utils.backends_specified.matmul(A, B)
pinnicle.utils.backends_specified.matmul_jax(A, B)[source]
pinnicle.utils.backends_specified.matmul_tf(A, B)[source]
pinnicle.utils.backends_specified.slice_column(variable, i)

slice the column i:i+1 of variable, tensorflow version

pinnicle.utils.backends_specified.slice_column_jax(variable, i)[source]

slice the column i:i+1 of variable, jax version currently jax output returns tuple (variable, function)

pinnicle.utils.backends_specified.slice_column_tf(variable, i)[source]

slice the column i:i+1 of variable, tensorflow version

pinnicle.utils.backends_specified.slice_function_jax(variable, x, i)[source]

slice the column i:i+1 of function, jax version currently jax output returns tuple (variable, function)

pinnicle.utils.data_misfit module

pinnicle.utils.data_misfit.get(identifier)[source]

Retrieves a loss function.

Parameters:

identifier – A loss identifier. String name of a loss function, or a loss function.

Returns:

A loss function.

pinnicle.utils.data_misfit.loss_dict_jax()[source]
pinnicle.utils.data_misfit.loss_dict_paddle()[source]
pinnicle.utils.data_misfit.loss_dict_pytorch()[source]
pinnicle.utils.data_misfit.loss_dict_tf()[source]
pinnicle.utils.data_misfit.mean_absolute_percentage_error(y_true, y_pred)[source]

Calculates the Mean Absolute Percentage Error (MAPE).

pinnicle.utils.data_misfit.mean_squared_log_error_jax(y_true, y_pred)[source]

use jax/numpy function to compute mean squared log error

pinnicle.utils.data_misfit.mean_squared_log_error_paddle(y_true, y_pred)[source]

use log function to compute mean squared log error

pinnicle.utils.data_misfit.mean_squared_log_error_pytorch(y_true, y_pred)[source]

use log function to compute mean squared log error

pinnicle.utils.data_misfit.mean_squared_log_error_tf(y_true, y_pred)[source]

use tensorflow function to compute mean squared log error

pinnicle.utils.data_misfit.surface_log_vel_misfit_jax(v_true, v_pred)[source]

Compute SurfaceLogVelMisfit: This function is for jax

pinnicle.utils.data_misfit.surface_log_vel_misfit_paddle(v_true, v_pred)[source]

Compute SurfaceLogVelMisfit: This function is for paddle backend

pinnicle.utils.data_misfit.surface_log_vel_misfit_pytorch(v_true, v_pred)[source]

Compute SurfaceLogVelMisfit: This function is for pytorch backend

pinnicle.utils.data_misfit.surface_log_vel_misfit_tf(v_true, v_pred)[source]

Compute SurfaceLogVelMisfit: This function is for tensorflow backend

pinnicle.utils.helper module

pinnicle.utils.helper.coord_window_indices(coord, lo, hi, pad=0)[source]

Return slice indices for coord values between lo and hi. Works for both ascending and descending coordinate arrays.

Parameters:
  • coord (array) – a sorted coordinates, either ascending or descending

  • lo (float) – lowest coordinate

  • hi (float) – highest coordinate

  • pad (int) – number of pad

Returns:

the indices of low and high values of the window

Return type:

i0, i1 (int)

pinnicle.utils.helper.createsubdomain(xmin, ymin, xid, yid, dx=50000, dy=50000, margin=0)[source]

Create a rectangle subdomain within the large domain defined by the bottom-left corner and x, y indices

Parameters:
  • xmin (float) – x coordinate of bottom-left corner of the large domain

  • ymin (float) – y coordinate of bottom-left corner of the large domain

  • xid (int) – x index of the subdomain (starting from 0)

  • yid (int) – y index of the subdomain (starting from 0)

  • dx (float, optional) – width of the subdomain. Defaults to 50000.

  • dy (float, optional) – height of the subdomain. Defaults to 50000.

  • margin (float, optional) – between 0 and 1, percentage of the margin extended beyond the given subdomain size

Returns:

(x0, x1, y0, y1) coordinates of the subdomain, this need to be consistent with domain.shapebox

Return type:

tuple

pinnicle.utils.helper.down_sample(points, data_size)[source]

downsample points to be a size of data_size, the strategy is to call down_sample_core with at least double resolution required, then randomly choose

Parameters:
  • points (np array)

  • data_size (Integer) – number of data points needed

Returns:

indices of the downsample

Return type:

ind

pinnicle.utils.helper.down_sample_core(points, resolution=100)[source]

downsample the given scatter points using KDtree with the nearest neighbors on a Cartisian grid

Parameters:
  • points (np array)

  • resolution (Integer) – resolution of the downsample grid

Returns:

indices of the downsample

Return type:

ind

pinnicle.utils.helper.feathered_rect_weights(x, y, rect, width)[source]

Compute 2D weights for points (x, y) relative to an axis-aligned rectangle. Inside the rectangle: weight = 1 Outside, within width: weight = 1 - d / width (linear falloff) Outside, beyond width: weight = 0

Parameters:
  • x (float or array) – x-coordinates

  • y (float or array) – y-coordinates

  • rect (tuple) – Rectangle bounds (xmin, xmax, ymin, ymax).

  • width (float) – Non-negative feather distance outside the rectangle over which the weight

  • 0 (falls linearly from 1 to 0. If width <=)

  • mask. (this reduces to a hard)

Returns:

Weights in [0, 1] with shape broadcast from x and y.

Return type:

(ndarray)

pinnicle.utils.helper.is_file_ext(path, ext)[source]

check if a given path is ended by ext

pinnicle.utils.helper.load_dict_from_json(path, filename)[source]

Load a dict data from a .json file

Parameters:
  • path (Path, str) – Path to load

  • filename (str) – name to load, attach ‘.json’ if needed

Returns:

Dictionary data to load

Return type:

data (dict)

pinnicle.utils.helper.load_mat(file)[source]

load .mat file, if the file is in MATLAB 7.3 format use mat73.loadmat, otherwise use scipy.io.loadmat()

pinnicle.utils.helper.save_dict_to_json(data, path, filename)[source]

Save the dict to the path as a .json file

Parameters:
  • data (dict) – Dictionary data to save

  • path (Path, str) – Path to save

  • filename (str) – name to save, attach ‘.json’ if needed

pinnicle.utils.history module

class pinnicle.utils.history.History(loss_history, names)[source]

Bases: object

class of the training history, based on deepxde LossHistory only need steps and loss_train

load(path, filename='history.json')[source]

load training history from folder or path

plot(path, figname='history.png', cols=4)[source]

plot the history

save(path, filename='history.json')[source]

save training history

pinnicle.utils.plotting module

pinnicle.utils.plotting.cmap_Rignot()[source]

colormap from ISSM

pinnicle.utils.plotting.diffplot(pinn, feature, feat_title=None, mdata='ISSM', sim='mae', figsize=(15, 4), cmap='jet', scale=1, clim=None, cbar_bins=10, elements=None)[source]
pinnicle.utils.plotting.plot_data(X, Y, im_data, axs=None, vranges={}, **kwargs)[source]

plot all the data in im_data

Parameters:
  • X (np.array) – x-coordinates of the 2D plot

  • Y (np.array) – y-coordinates of the 2D plot

  • im_data (dict) – Dict of data for the 2D plot, each element has the same size as X and Y

  • axs (array of AxesSubplot) – axes to plot each data, if not given, then generate a subplot according to the size of data_names

  • vranges (dict) – range of the data

Returns:

axes of the subplots

Return type:

axs (array of AxesSubplot)

pinnicle.utils.plotting.plot_dict_data(X_dict, data_dict, axs=None, vranges={}, resolution=200, **kwargs)[source]

plot the data in data_dict, with coordinates in X_dict

Parameters:
  • X_dict (dict) – Dict of the coordinates, with keys ‘x’, ‘y’

  • data_dict (dict) – Dict of data

  • axs (array of AxesSubplot) – axes to plot each data, if not given, then generate a subplot according to the size of data_names

  • vranges (dict) – range of the data

  • resolution (int) – number of pixels in horizontal and vertical direction

Returns:

x-coordinates of the 2D plot Y (np.array): y-coordinates of the 2D plot im_data (dict): Dict of data for the 2D plot, each element has the same size as X and Y axs (array of AxesSubplot): axes of the subplots

Return type:

X (np.array)

pinnicle.utils.plotting.plot_nn(pinn, data_names=None, X_mask=None, axs=None, vranges={}, resolution=200, **kwargs)[source]

plot the prediction of the nerual network in pinn, according to the data_names

Parameters:
  • pinn (class PINN) – The PINN model

  • data_names (list) – List of data names

  • X_mask (np.array) – xy-coordinates of the ice mask

  • axs (array of AxesSubplot) – axes to plot each data, if not given, then generate a subplot according to the size of data_names

  • vranges (dict) – range of the data

  • resolution (int) – number of pixels in horizontal and vertical direction

Returns:

x-coordinates of the 2D plot Y (np.array): y-coordinates of the 2D plot im_data (dict): Dict of data for the 2D plot, each element has the same size as X and Y axs (array of AxesSubplot): axes of the subplots

Return type:

X (np.array)

pinnicle.utils.plotting.plot_solutions(pinn, path='', filename='2Dsolution.png', X_ref=None, sol_ref=None, cols=None, resolution=200, absvariable=[], default_time=None, **kwargs)[source]

plot model predictions

Parameters:
  • path (Path, str) – Path to save the figures

  • filename (str) – name to save the figures, if set to None, then the figure will not be saved

  • X_ref (dict) – Coordinates of the reference solutions, if None, then just plot the predicted solutions

  • u_ref (dict) – Reference solutions, if None, then just plot the predicted solutions

  • cols (int) – Number of columns of subplot

  • resolution (int) – Number of grid points per row/column for plotting

  • absvariable (list) – Names of variables in the predictions that will need to take abs() before comparison

pinnicle.utils.plotting.plot_tracks(pinn, feature, filepath=None, x_name_map='x', y_name_map='y', feat_name_map=None, gdata=None, mdata='ISSM', elements=None, scale=1, cmap='jet', figsize=(10, 8), clim=None, cbar_bins=10)[source]

plotting (sparse) ground truth data on top of prediction

pinnicle.utils.plotting.resplot(pinn, mdata='ISSM', figsize=None, cmap='RdBu', cbar_bins=10, cbar_limits=[-5000.0, 5000.0], elements=None)[source]

plotting the pde residuals

pinnicle.utils.plotting.tripcolor_residuals(pinn, cmap='RdBu', colorbar_bins=10, cbar_limits=[-5000.0, 5000.0])[source]

plot pde residuals with ISSM triangulation

pinnicle.utils.plotting.tripcolor_similarity(pinn, feature_name, feat_title=None, mdata='ISSM', sim='MAE', cmap='jet', scale=1, colorbar_bins=10, elements=None)[source]

tripcolor similarity, plot with ISSM triangulation