Skip to content

Commit

Permalink
Removed Numpy-types to silence depreciation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Sindre Nordmark Olufsen committed Apr 15, 2021
1 parent a622aa3 commit e192a71
Show file tree
Hide file tree
Showing 14 changed files with 75 additions and 76 deletions.
4 changes: 2 additions & 2 deletions muDIC/elements/b_splines.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,8 @@ def __partial_outer_product__(n_nodes_y, n_nodes_x, n_pts, span_vs, bases_vs, sp
results = np.zeros(n_pts * n_nodes_x * n_nodes_y, dtype=np.float64)

# Calculate node span in x and y direction
deg_range_u = np.array(range(0, degree_u + 1), dtype=np.int)
deg_range_v = np.array(range(0, degree_v + 1), dtype=np.int)
deg_range_u = np.array(range(0, degree_u + 1), dtype=np.int64)
deg_range_v = np.array(range(0, degree_v + 1), dtype=np.int64)

# Generate index matrix for all points
u_ind = (span_us[:, np.newaxis] - degree_u + deg_range_u[np.newaxis, :])[:, np.newaxis, :]
Expand Down
12 changes: 6 additions & 6 deletions muDIC/elements/q4.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def fx_full(x, y):
[np.ones(np.size(x)), x, y, x * y, x ** 2., y ** 2., x ** 2. * y, x * y ** 2., x ** 3., y ** 3.,
x ** 3. * y,
x ** 2. * y ** 2., x * y ** 3., x ** 3. * y ** 2., x ** 2. * y ** 3., x ** 3. * y ** 3.][:n_terms],
dtype=np.float64).transpose()
dtype=float).transpose()

return fx_full

Expand All @@ -46,7 +46,7 @@ def dxfx_full(x, y):

2. * x * y, y ** 2, 3. * x ** 2, np.zeros(np.size(x)),
3. * x ** 2. * y, 2. * x * y ** 2., y ** 3., 3. * x ** 2. * y ** 2., 2. * x * y ** 3.,
3. * x ** 2. * y ** 3.][:n_terms], dtype=np.float64).transpose()
3. * x ** 2. * y ** 3.][:n_terms], dtype=float).transpose()

return dxfx_full

Expand All @@ -63,14 +63,14 @@ def dyfx_full(x, y):
[np.zeros(np.size(x)), np.zeros(np.size(x)), np.ones(np.size(x)), x, np.zeros(np.size(x)), 2. * y,
x ** 2., 2. * x * y, np.zeros(np.size(x)), 3. * y ** 2.,
x ** 3., 2. * x ** 2. * y, 3. * x * y ** 2., 2. * x ** 3. * y, 3. * x ** 2. * y ** 2.,
3. * x ** 3. * y ** 2.][:n_terms], dtype=np.float64).transpose()
3. * x ** 3. * y ** 2.][:n_terms], dtype=float).transpose()

return dyfx_full

def determineCoefficients(self):
A = self.fx(self.nodal_xpos, self.nodal_ypos)
Ainv = np.linalg.inv(A)
a = np.zeros((self.n_nodes, self.n_nodes), dtype=np.float64)
a = np.zeros((self.n_nodes, self.n_nodes), dtype=float)
for i in range(self.n_nodes):
s = np.zeros(self.n_nodes)
s[i] = 1.
Expand All @@ -93,9 +93,9 @@ def __init__(self):
Quadratic 4-noded Finite Element
Uses bi-linear interpolation polynomials
"""
self.nodal_xpos = np.array([0., 1., 1., 0.], dtype=np.float64)
self.nodal_xpos = np.array([0., 1., 1., 0.], dtype=float)

self.nodal_ypos = np.array([0., 0., 1., 1.], dtype=np.float64)
self.nodal_ypos = np.array([0., 0., 1., 1.], dtype=float)
self.n_nodes = 4
self.corner_nodes = np.array([0, 1, 2, 3])
Finite_Element.__init__(self, 1)
4 changes: 2 additions & 2 deletions muDIC/mesh/meshUtilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ def make_grid(c1x, c1y, c2x, c2y, ny, nx, elm):
node_x = np.array(xnod) + c1x
node_y = np.array(ynod) + c1y

con_matrix = np.zeros((nx * ny,1),dtype=np.int)
con_matrix[:,0] = np.arange(nx*ny,dtype=np.int)
con_matrix = np.zeros((nx * ny,1),dtype=int)
con_matrix[:,0] = np.arange(nx*ny,dtype=int)

return con_matrix, node_x, node_y

Expand Down
12 changes: 6 additions & 6 deletions muDIC/solver/correlate.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,15 +241,15 @@ def correlate_img_to_ref_q4(node_coordss, img, ref, settings):

img = nd.spline_filter(img, order=settings.interpolation_order)

pix_cord_local = [np.zeros((2, ref.Nref_stack[elm_nr].shape[0]), dtype=np.float64) for elm_nr in
pix_cord_local = [np.zeros((2, ref.Nref_stack[elm_nr].shape[0]), dtype=float) for elm_nr in
range(settings.mesh.n_elms)]

n_nodes = settings.mesh.n_nodes
n_nodes_elm = settings.mesh.element_def.n_nodes

di = np.zeros(n_nodes_elm * 2, dtype=np.float64)
dnod = np.zeros(n_nodes * 2, dtype=np.float64)
C = np.zeros(n_nodes * 2, dtype=np.float64)
di = np.zeros(n_nodes_elm * 2, dtype=float)
dnod = np.zeros(n_nodes * 2, dtype=float)
C = np.zeros(n_nodes * 2, dtype=float)

# Find borders of the elements
borders = find_elm_borders_mesh(node_coords, settings.mesh, settings.mesh.n_elms)
Expand All @@ -269,7 +269,7 @@ def correlate_img_to_ref_q4(node_coordss, img, ref, settings):
C[:] = 0.0

for el in range(settings.mesh.n_elms):
Ic = np.zeros_like(ref.I0_stack[el], dtype=np.float64)
Ic = np.zeros_like(ref.I0_stack[el], dtype=float)
# Find current coordinates element within the elm_frame
np.dot(ref.Nref_stack[el], node_coords[0, settings.mesh.ele[:, el]] - borders[0, el] + settings.pad,
out=pix_cord_local[el][1])
Expand Down Expand Up @@ -338,7 +338,7 @@ def __init__(self, inputs):
>>> image_shape = (2000, 2000)
>>> speckle_image = vlab.rosta_speckle(image_shape, dot_size=4, density=0.32, smoothness=2.0, layers=4)
>>> F = np.array([[1.1, .0], [0., 1.0]], dtype=np.float64)
>>> F = np.array([[1.1, .0], [0., 1.0]], dtype=float)
>>> image_deformer = vlab.imageDeformer_from_defGrad(F)
>>> downsampler = vlab.Downsampler(image_shape=image_shape, factor=4, fill=0.8, pixel_offset_stddev=0.1)
>>> noise_injector = vlab.noise_injector("gaussian", sigma=.1)
Expand Down
23 changes: 11 additions & 12 deletions muDIC/solver/reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,12 @@ def identify_pixels_within_frame(xnod, ynod, elm, over_sampling=1.1):
y_min, y_max = find_borders(ynod)

# Calculate coordinates (e,n) covered by the element on a fine grid
n_search_pixels = np.int(over_sampling * max((x_max - x_min), y_max - y_min))
n_search_pixels = int(over_sampling * max((x_max - x_min), y_max - y_min))
es, ns = np.meshgrid(np.linspace(0., 1., n_search_pixels), np.linspace(0., 1., n_search_pixels))
es = es.flatten()
ns = ns.flatten()

num_blocks = np.ceil(len(es) / chunk_size).astype(np.int)
num_blocks = np.ceil(len(es) / chunk_size).astype(int)
logger.info("Splitting in %i block"%num_blocks)


Expand All @@ -205,17 +205,17 @@ def identify_pixels_within_frame(xnod, ynod, elm, over_sampling=1.1):
pixel_ys = np.append(pixel_ys, np.dot(elm.Nn(es_blocks[i], ns_blocks[i]), ynod))


pixel_xs_closest = np.around(pixel_xs).astype(np.int)
pixel_ys_closest = np.around(pixel_ys).astype(np.int)
pixel_xs_closest = np.around(pixel_xs).astype(int)
pixel_ys_closest = np.around(pixel_ys).astype(int)

xs_ys = np.stack([pixel_xs_closest, pixel_ys_closest], axis=0)
xs_ys_unique, unique_inds = np.unique(xs_ys, return_index=True, axis=1)

pixel_x = xs_ys_unique[0, :].astype(np.float64)
pixel_y = xs_ys_unique[1, :].astype(np.float64)
pixel_x = xs_ys_unique[0, :].astype(float)
pixel_y = xs_ys_unique[1, :].astype(float)

pixel_es = es[unique_inds].astype(np.float64)
pixel_ns = ns[unique_inds].astype(np.float64)
pixel_es = es[unique_inds].astype(float)
pixel_ns = ns[unique_inds].astype(float)

return pixel_x, pixel_y, pixel_es, pixel_ns

Expand Down Expand Up @@ -285,8 +285,7 @@ def find_covered_pixel_blocks(node_x, node_y, elm,xs=None,ys=None,keep_all=False

block_size = 1.e5
# Split into blocks
#n_pix_in_block = block_size / np.float(len(node_x))
num_blocks = np.ceil(len(pix_es) / block_size).astype(np.int)
num_blocks = np.ceil(len(pix_es) / block_size).astype(int)
logger.info("Splitting in %s blocks:" % str(num_blocks))

pix_e_blocks = np.array_split(pix_es, num_blocks)
Expand Down Expand Up @@ -339,8 +338,8 @@ def find_covered_pixel_blocks(node_x, node_y, elm,xs=None,ys=None,keep_all=False

found_e.append(epE_block)
founc_n.append(nyE_block)
found_x.append(Xe_block.astype(np.int))
found_y.append(Ye_block.astype(np.int))
found_x.append(Xe_block.astype(int))
found_y.append(Ye_block.astype(int))

break
if (i + 1) == max_iter:
Expand Down
2 changes: 1 addition & 1 deletion muDIC/tests/test_dic/test_DIC_Post.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_green_strain_(self):
# Calculate green deformation as F^T*F
Green_deformation = np.einsum('nij...,noj...->nio...', F, F)

I = np.eye(2, dtype=np.float)
I = np.eye(2, dtype=float)

# Calculate green strain tensor as 0.5(F^T * F - I)
Green_strain = 0.5 * (Green_deformation - I[np.newaxis, :, :, np.newaxis, np.newaxis, np.newaxis])
Expand Down
36 changes: 18 additions & 18 deletions muDIC/tests/test_dic/test_DIC_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ def __calculate_DIC_error__(self, F_correct, F_dic):

# Make empty matrix for storing deformation gradients
F_correct_at_frame = np.zeros((n_frames, 2, 2))
F_correct_at_frame[0, :, :] = np.eye(2, dtype=np.float)
F_correct_at_frame[0, :, :] = np.eye(2, dtype=float)

print("F Correct:", F_correct)

for i in range(n_frames - 1):
F_correct_at_frame[i + 1] = np.dot(F_correct_at_frame[i], F_correct)

F_correct_deviatior = F_correct_at_frame - np.eye(2, dtype=np.float)[np.newaxis, :, :]
F_correct_deviatior = F_correct_at_frame - np.eye(2, dtype=float)[np.newaxis, :, :]

F11_abs_error = np.zeros((F11.shape[1], F11.shape[2], F11.shape[3]))
F12_abs_error = np.zeros_like(F11_abs_error)
Expand Down Expand Up @@ -167,7 +167,7 @@ def __calculate_DIC_error__(self, F_correct, F_dic):
def test_deg1_rotation(self):
element = dic.elements.BSplineSurface(deg_e=1, deg_n=1)
theta = 0.01
F = np.array([[np.cos(theta), -np.sin(theta)], [np.sin(theta), np.cos(theta)]], dtype=np.float64)
F = np.array([[np.cos(theta), -np.sin(theta)], [np.sin(theta), np.cos(theta)]], dtype=float)

passed = self.__run_DIC_defgrad__(F, element, n_elx=4, n_ely=4)
self.assertEqual(passed, True)
Expand All @@ -176,8 +176,8 @@ def test_deg1_rotation_biaxial(self):
element = dic.elements.BSplineSurface(deg_e=1, deg_n=1)

theta = 0.01
F_rot = np.array([[np.cos(theta), -np.sin(theta)], [np.sin(theta), np.cos(theta)]], dtype=np.float64)
F_biax = np.array([[1.001, 0.], [0., 0.999]], dtype=np.float64)
F_rot = np.array([[np.cos(theta), -np.sin(theta)], [np.sin(theta), np.cos(theta)]], dtype=float)
F_biax = np.array([[1.001, 0.], [0., 0.999]], dtype=float)
F = np.dot(F_rot, F_biax)
# print F

Expand All @@ -186,14 +186,14 @@ def test_deg1_rotation_biaxial(self):

def test_deg1_biaxial(self):
element = dic.elements.BSplineSurface(deg_e=1, deg_n=1)
F = np.array([[1.001, 0.], [0., 0.999]], dtype=np.float64)
F = np.array([[1.001, 0.], [0., 0.999]], dtype=float)

passed = self.__run_DIC_defgrad__(F, element, n_elx=4, n_ely=4)
self.assertEqual(passed, True)

def test_deg1_simple_shear(self):
element = dic.elements.BSplineSurface(deg_e=1, deg_n=1)
F = np.array([[1.00, .005], [0., 1.]], dtype=np.float64)
F = np.array([[1.00, .005], [0., 1.]], dtype=float)

passed = self.__run_DIC_defgrad__(F, element, n_elx=4, n_ely=4)
self.assertEqual(passed, True)
Expand All @@ -202,22 +202,22 @@ def test_deg2_rotation(self):
element = dic.elements.BSplineSurface(deg_e=2, deg_n=2)

theta = 0.01
F = np.array([[np.cos(theta), -np.sin(theta)], [np.sin(theta), np.cos(theta)]], dtype=np.float64)
F = np.array([[np.cos(theta), -np.sin(theta)], [np.sin(theta), np.cos(theta)]], dtype=float)
# print F

passed = self.__run_DIC_defgrad__(F, element, n_elx=4, n_ely=4)
self.assertEqual(passed, True)

def test_deg2_biaxial(self):
element = dic.elements.BSplineSurface(deg_e=2, deg_n=2)
F = np.array([[1.001, 0.], [0., .999]], dtype=np.float64)
F = np.array([[1.001, 0.], [0., .999]], dtype=float)

passed = self.__run_DIC_defgrad__(F, element, n_elx=4, n_ely=4)
self.assertEqual(passed, True)

def test_deg2_simple_shear(self):
element = dic.elements.BSplineSurface(deg_e=2, deg_n=2)
F = np.array([[1.00, .005], [0., 1.]], dtype=np.float64)
F = np.array([[1.00, .005], [0., 1.]], dtype=float)

passed = self.__run_DIC_defgrad__(F, element, n_elx=4, n_ely=4)
self.assertEqual(passed, True)
Expand All @@ -226,30 +226,30 @@ def test_deg3_rotation(self):
element = dic.elements.BSplineSurface(deg_e=3, deg_n=3)

theta = 0.01
F = np.array([[np.cos(theta), -np.sin(theta)], [np.sin(theta), np.cos(theta)]], dtype=np.float64)
F = np.array([[np.cos(theta), -np.sin(theta)], [np.sin(theta), np.cos(theta)]], dtype=float)
# print F

passed = self.__run_DIC_defgrad__(F, element, x1=100, x2=300, y1=100, y2=300, n_elx=4, n_ely=4)
self.assertEqual(passed, True)

def test_deg3_biaxial(self):
element = dic.elements.BSplineSurface(deg_e=3, deg_n=3)
F = np.array([[1.001, 0.], [0., .999]], dtype=np.float64)
F = np.array([[1.001, 0.], [0., .999]], dtype=float)

passed = self.__run_DIC_defgrad__(F, element, n_elx=4, n_ely=4)
self.assertEqual(passed, True)

def test_deg3_simple_shear(self):
element = dic.elements.BSplineSurface(deg_e=3, deg_n=3)
F = np.array([[1.00, .005], [0., 1.]], dtype=np.float64)
F = np.array([[1.00, .005], [0., 1.]], dtype=float)

passed = self.__run_DIC_defgrad__(F, element, n_elx=4, n_ely=4)
self.assertEqual(passed, True)

def test_Q4_rotation(self):
element = dic.elements.Q4()
theta = 0.01
F = np.array([[np.cos(theta), -np.sin(theta)], [np.sin(theta), np.cos(theta)]], dtype=np.float64)
F = np.array([[np.cos(theta), -np.sin(theta)], [np.sin(theta), np.cos(theta)]], dtype=float)

passed = self.__run_DIC_defgrad__(F, element, n_elx=4, n_ely=4)
self.assertEqual(passed, True)
Expand All @@ -258,8 +258,8 @@ def test_Q4_rotation_biaxial(self):
element = dic.elements.Q4()

theta = 0.01
F_rot = np.array([[np.cos(theta), -np.sin(theta)], [np.sin(theta), np.cos(theta)]], dtype=np.float64)
F_biax = np.array([[1.001, 0.], [0., 0.999]], dtype=np.float64)
F_rot = np.array([[np.cos(theta), -np.sin(theta)], [np.sin(theta), np.cos(theta)]], dtype=float)
F_biax = np.array([[1.001, 0.], [0., 0.999]], dtype=float)
F = np.dot(F_rot, F_biax)
# print F

Expand All @@ -268,14 +268,14 @@ def test_Q4_rotation_biaxial(self):

def test_Q4_biaxial(self):
element = dic.elements.Q4()
F = np.array([[1.001, 0.], [0., 0.999]], dtype=np.float64)
F = np.array([[1.001, 0.], [0., 0.999]], dtype=float)

passed = self.__run_DIC_defgrad__(F, element, n_elx=4, n_ely=4)
self.assertEqual(passed, True)

def test_Q4_simple_shear(self):
element = dic.elements.Q4()
F = np.array([[1.00, .005], [0., 1.]], dtype=np.float64)
F = np.array([[1.00, .005], [0., 1.]], dtype=float)

passed = self.__run_DIC_defgrad__(F, element, n_elx=4, n_ely=4)
self.assertEqual(passed, True)
10 changes: 5 additions & 5 deletions muDIC/tests/test_vlab/test_imageDeformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ def test_defgrad_dilate_square_by_biaxial_tension(self):
Deforms a image with a square by a given amount and checks the area of the square
"""
tol = 1e-4
square = np.zeros((200, 200), dtype=np.float)
square = np.zeros((200, 200), dtype=float)
square[75:125, 75:125] = 1.

undeformed_hole_area = np.sum(square)

F = np.array([[2., .0], [0., 2.0]], dtype=np.float64)
F = np.array([[2., .0], [0., 2.0]], dtype=float)

image_deformer = vlab.imageDeformer_from_defGrad(F)

Expand All @@ -36,19 +36,19 @@ def test_defgrad_rotate_square(self):
* Rotate 90 deg and subtract, should give a zero difference
"""
tol = 1e-4
square = np.zeros((200, 200), dtype=np.float)
square = np.zeros((200, 200), dtype=float)
square[75:125, 75:125] = 1.

theta = np.pi / 4.
F_rot_45 = np.array([[np.cos(theta), -np.sin(theta)], [np.sin(theta), np.cos(theta)]], dtype=np.float64)
F_rot_45 = np.array([[np.cos(theta), -np.sin(theta)], [np.sin(theta), np.cos(theta)]], dtype=float)
image_deformer_45 = vlab.imageDeformer_from_defGrad(F_rot_45)
image_rotated_45 = image_deformer_45(square, steps=2)[1]

if np.abs(np.sum(np.abs(square - image_rotated_45))) < 1.:
self.fail("The rotated image is the same as the un-rotated one")

theta = np.pi / 2.
F_rot_90 = np.array([[np.cos(theta), -np.sin(theta)], [np.sin(theta), np.cos(theta)]], dtype=np.float64)
F_rot_90 = np.array([[np.cos(theta), -np.sin(theta)], [np.sin(theta), np.cos(theta)]], dtype=float)
image_deformer_90 = vlab.imageDeformer_from_defGrad(F_rot_90)
image_rotated_90 = image_deformer_90(square, steps=2)[1]

Expand Down
2 changes: 1 addition & 1 deletion muDIC/tests/test_vlab/test_virtualTensileTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def setUpClass(cls):
cls.image = vlab.speckle.dots_speckle(cls.img_shape, n_dots=10000, dot_radius_max=10)

def test__pass_through_user_img(self):
F = np.eye(2, dtype=np.float)
F = np.eye(2, dtype=float)
image_deformer = vlab.imageDeformer_from_defGrad(F)

downsampler = vlab.Downsampler(image_shape=self.img_shape, factor=1, fill=1., pixel_offset_stddev=0.0)
Expand Down
4 changes: 2 additions & 2 deletions muDIC/utils/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def convert_to_img_frame(img, node_position, mesh, borders, settings):
def generate_edge_coordinates(seed):
seeding = np.linspace(0., 1., seed)
es, ns = np.meshgrid(seeding, seeding)
mask = np.ones_like(es, dtype=np.bool)
mask = np.ones_like(es, dtype=bool)
mask[1:-1, 1:-1] = 0
return es[mask], ns[mask]

Expand All @@ -34,7 +34,7 @@ def find_element_borders(node_position, mesh, seed=20):

axis = None
# [Xmin_Xmax,Ymin,Ymax,elm_nr]
borders = np.zeros((4, mesh.n_elms), dtype=np.int)
borders = np.zeros((4, mesh.n_elms), dtype=int)
borders[0, :] = np.min(pixel_x, axis=axis)
borders[1, :] = np.max(pixel_x, axis=axis)
borders[2, :] = np.min(pixel_y, axis=axis)
Expand Down
Loading

0 comments on commit e192a71

Please sign in to comment.