Inverse Distance Weighting [CAD]

Module focused on the Inverse Distance Weighting interpolation technique. The IDW algorithm is an average moving interpolation that is usually applied to highly variable data. The main idea of this interpolation strategy lies in fact that it is not desirable to honour local high/low values but rather to look at a moving average of nearby data points and estimate the local trends. The node value is calculated by averaging the weighted sum of all the points. Data points that lie progressively farther from the node inuence much less the computed value than those lying closer to the node.

Theoretical Insight

This implementation is based on the simplest form of inverse distance weighting interpolation, proposed by D. Shepard, A two-dimensional interpolation function for irregularly-spaced data, Proceedings of the 23 rd ACM National Conference.

The interpolation value u of a given point \mathrm{x} from a set of samples u_k = u(\mathrm{x}_k), with k = 1,2,\dotsc,\mathcal{N}, is given by:

u(\mathrm{x}) = \displaystyle\sum_{k=1}^\mathcal{N} \frac{w(\mathrm{x},\mathrm{x}_k)} {\displaystyle\sum_{j=1}^\mathcal{N} w(\mathrm{x},\mathrm{x}_j)} u_k

where, in general, w(\mathrm{x}, \mathrm{x}_i) represents the weighting function:

w(\mathrm{x}, \mathrm{x}_i) = \| \mathrm{x} - \mathrm{x}_i \|^{-p}

being \| \mathrm{x} - \mathrm{x}_i \|^{-p} \ge 0 is the Euclidean distance between \mathrm{x} and data point \mathrm{x}_i and p is a power parameter, typically equal to 2.

class IDW(original_control_points=None, deformed_control_points=None, power=2, u_knots_to_add=0, v_knots_to_add=0, t_knots_to_add=0, tolerance=0.0001)[source]

Bases: pygem.cad.cad_deformation.CADDeformation, pygem.idw.IDW

Class that perform the Inverse Distance Weighting (IDW) on CAD geometries.

Parameters
  • power (int) – the power parameter. The default value is 2.

  • original_control_points (numpy.ndarray) – it is an (n_control_points, 3) array with the coordinates of the original interpolation control points before the deformation. The default is the vertices of the unit cube.

  • deformed_control_points (numpy.ndarray) – it is an (n_control_points, 3) array with the coordinates of the interpolation control points after the deformation. The default is the vertices of the unit cube.

  • u_knots_to_add (int) – the number of knots to add to the NURBS surfaces along u direction before the deformation. This parameter is useful whenever the gradient of the imposed deformation present spatial scales that are smaller than the local distance among the original poles of the surface/curve. Enriching the poles will allow for a more accurate application of the deformation, and might also reduce possible mismatches between bordering faces. On the orther hand, it might result in higher computational cost and bigger output files. Default is 0.

  • v_knots_to_add (int) – the number of knots to add to the NURBS surfaces along v direction before the deformation. This parameter is useful whenever the gradient of the imposed deformation present spatial scales that are smaller than the local distance among the original poles of the surface/curve. Enriching the poles will allow for a more accurate application of the deformation, and might also reduce possible mismatches between bordering faces. On the orther hand, it might result in higher computational cost and bigger output files. Default is 0.

  • t_knots_to_add (int) – the number of knots to add to the NURBS curves before the deformation. This parameter is useful whenever the gradient of the imposed deformation present spatial scales that are smaller than the local distance among the original poles of the surface/curve. Enriching the poles will allow for a more accurate application of the deformation, and might also reduce possible mismatches between bordering faces. On the orther hand, it might result in higher computational cost and bigger output files. Default is 0.

  • tolerance (float) – the tolerance involved in several internal operations of the procedure (joining wires in a single curve before deformation and placing new poles on curves and surfaces). Change the default value only if the input file scale is significantly different form mm, making some of the aforementioned operations fail. Default is 0.0001.

Variables
  • power (int) – the power parameter. The default value is 2.

  • original_control_points (numpy.ndarray) – it is an (n_control_points, 3) array with the coordinates of the original interpolation control points before the deformation. The default is the vertices of the unit cube.

  • deformed_control_points (numpy.ndarray) – it is an (n_control_points, 3) array with the coordinates of the interpolation control points after the deformation. The default is the vertices of the unit cube.

  • u_knots_to_add (int) – the number of knots to add to the NURBS surfaces along u direction before the deformation. This parameter is useful whenever the gradient of the imposed deformation present spatial scales that are smaller than the local distance among the original poles of the surface/curve. Enriching the poles will allow for a more accurate application of the deformation, and might also reduce possible mismatches between bordering faces. On the orther hand, it might result in higher computational cost and bigger output files. Default is 0.

  • v_knots_to_add (int) – the number of knots to add to the NURBS surfaces along v direction before the deformation. This parameter is useful whenever the gradient of the imposed deformation present spatial scales that are smaller than the local distance among the original poles of the surface/curve. Enriching the poles will allow for a more accurate application of the deformation, and might also reduce possible mismatches between bordering faces. On the orther hand, it might result in higher computational cost and bigger output files. Default is 0.

  • t_knots_to_add (int) – the number of knots to add to the NURBS curves before the deformation. This parameter is useful whenever the gradient of the imposed deformation present spatial scales that are smaller than the local distance among the original poles of the surface/curve. Enriching the poles will allow for a more accurate application of the deformation, and might also reduce possible mismatches between bordering faces. On the orther hand, it might result in higher computational cost and bigger output files. Default is 0.

  • tolerance (float) – the tolerance involved in several internal operations of the procedure (joining wires in a single curve before deformation and placing new poles on curves and surfaces). Change the default value only if the input file scale is significantly different form mm, making some of the aforementioned operations fail. Default is 0.0001.

Example
>>> from pygem.cad import IDW
>>> idw = IDW()
>>> idw.read_parameters(
>>>        'tests/test_datasets/parameters_test_idw_iges.prm')
>>> input_cad_file_name = "input.iges"
>>> modified_cad_file_name = "output.iges"
>>> idw(input_cad_file_name, modified_cad_file_name)