Skip to content

Commit

Permalink
removed global numpy import - tested against custom script, works.
Browse files Browse the repository at this point in the history
  • Loading branch information
demisjohn committed Mar 4, 2018
1 parent 01f7ef0 commit 3041533
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions camfr/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
#
############################################################################

from math import *
from math import * # pretty sure this isn't used in this module
from camfr import *
from numpy import *
#from numpy import *
import numpy as np

import PIL.Image as Image
import PIL.ImageFile as ImageFile
Expand Down Expand Up @@ -109,7 +110,7 @@ def __init__(self, c, r, mat):
def intersection_at_x(self, x):
D = self.r**2 - (x - self.c.x)**2
if D > 0:
return [ self.c.y - sqrt(D), self.c.y + sqrt(D) ]
return [ self.c.y - np.sqrt(D), self.c.y + np.sqrt(D) ]
else:
return []

Expand Down Expand Up @@ -272,13 +273,13 @@ def similar(slab1, slab2, dy):

# Same interface positions?

if abs(dy) < 1e-12:
if np.abs(dy) < 1e-12:
dy = 1e-12

for i in range(len(slab1)):
if abs(slab1[i][0] - slab2[i][0]) >= dy:
if np.abs(slab1[i][0] - slab2[i][0]) >= dy:
return 0
if abs(slab1[i][1] - slab2[i][1]) >= dy:
if np.abs(slab1[i][1] - slab2[i][1]) >= dy:
return 0

return 1
Expand Down Expand Up @@ -541,7 +542,7 @@ def rescale_nearest(self, image, Xsteps, Zsteps):
def rescale_antialias(image, Xsteps, Zsteps):
return image.resize((Xsteps,Zsteps),Image.ANTIALIAS )

def rescale_custom(image, x, z, Xsteps, Zsteps, method='AVARAGE'):
def rescale_custom(image, x, z, Xsteps, Zsteps, method='AVERAGE'):

# Algorithm =
# resize from fine grid x-z to X-Z
Expand All @@ -562,10 +563,10 @@ def rescale_custom(image, x, z, Xsteps, Zsteps, method='AVARAGE'):
for Z in range (Zsteps):
for X in range (Xsteps):

x1 = int(floor(X*dX/dx)) # First x-matching value.
j = int(floor(dX/dx)) # Number of pixels in x direction.
z1 = int(floor(Z*dZ/dz)) # First z-matching value
k = int(floor(dZ/dz)) # Number of pixels in z direction.
x1 = int(np.floor(X*dX/dx)) # First x-matching value.
j = int(np.floor(dX/dx)) # Number of pixels in x direction.
z1 = int(np.floor(Z*dZ/dz)) # First z-matching value
k = int(np.floor(dZ/dz)) # Number of pixels in z direction.

#list with x-lenghts
LX = [(x1+1)*dx - X*dX]
Expand All @@ -591,9 +592,9 @@ def rescale_custom(image, x, z, Xsteps, Zsteps, method='AVARAGE'):
average += opp / (1+pix[x1+_x,z1+_z])

if (method=='AVERAGE'):
newcolor = floor(average/(dX*dZ))
newcolor = np.floor(average/(dX*dZ))
else: # Inverse average.
newcolor = floor((dX*dZ)/average)-1
newcolor = np.floor((dX*dZ)/average)-1
L[Ln] =(newcolor)
Ln += 1

Expand Down Expand Up @@ -703,15 +704,15 @@ def to_expression(self, x0, x1, dx=0, y0=0, y1=0, dy=0, add_flipped=0,
if ys1 > y1:
ys1 = y1

def same(y0,y1): return abs(y0-y1) < 1e-6
def same(y0,y1): return np.abs(y0-y1) < 1e-6

new_slab = []
j = 0
while j < len(slab):

if (slab[j][1] < ys0) or same(slab[j][1], ys0) or \
(slab[j][0] > ys1) or same(slab[j][0], ys1) or \
(abs(ys0-ys1) < .001*dy):
(np.abs(ys0-ys1) < .001*dy):
new_slab.append(slab[j]) # No intersection.
else:
if not same(slab[j][0], ys0): # Old material pre.
Expand Down Expand Up @@ -771,7 +772,7 @@ def same(y0,y1): return abs(y0-y1) < 1e-6

i = i_end

d[-1] += (x1-x0) - sum(d)
d[-1] += (x1-x0) - np.sum(d)
slabs = new_slabs

# Create expression.
Expand Down Expand Up @@ -825,10 +826,10 @@ def pretty_print(s):
nr = s.mode(i).n_eff().real
ni = s.mode(i).n_eff().imag

if abs(nr) < 1e-6:
if np.abs(nr) < 1e-6:
nr = 0

if abs(ni) < 1e-6:
if np.abs(ni) < 1e-6:
ni = 0

print i, nr, ni
Expand Down

0 comments on commit 3041533

Please sign in to comment.