Skip to content

Commit

Permalink
Merge pull request #75 from abel-research/aopFixes
Browse files Browse the repository at this point in the history
various fixes to aop file read and write
  • Loading branch information
JoshuaSteer committed Nov 1, 2022
2 parents 9ed4277 + e0d36f7 commit 7a3d5f8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
4 changes: 3 additions & 1 deletion ampscan/analyse/analyse.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ def calc_widths(polys):
r"""
Calculate the coronal and sagittal widths of each polygon from the slicing of the AmpObject
Assumes that coronal width corresponds with the x-axis
Parameters
----------
polys: list
Expand All @@ -203,7 +205,7 @@ def calc_widths(polys):
ind.remove(ix)
for i, p in enumerate(polys):
# Get the widths through min - max
sag_width[i], cor_width[i] = p[:, ind].max(axis=0) - p[:, ind].min(axis=0)
cor_width[i], sag_width[i] = p[:, ind].max(axis=0) - p[:, ind].min(axis=0)
return cor_width, sag_width

def calc_csa(polys):
Expand Down
25 changes: 17 additions & 8 deletions ampscan/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,8 @@ def read_aop(self, filename, unify=True, struc=True):
spokes = np.asarray(spokes)
else:
# regular spacing so compute
spokes = np.arange(0, 2*np.pi, spokeDist)
spokes = np.arange(-0.5*np.pi, 1.5*np.pi, spokeDist)
spokes = np.flip(spokes)

# slices
nSlices = int(lines[lID])
Expand All @@ -275,12 +276,19 @@ def read_aop(self, filename, unify=True, struc=True):
nFaces = (nSlices - 1) * (nSpokes * 2);
self.vert = np.zeros([nVerts, 3], dtype=float)
self.faces = np.zeros([nFaces, 3], dtype=int)
self.values = np.zeros([len(self.vert)])
# Read in the radii as verts
for i in range(nSlices):
z = slices[i];
for j in range(nSpokes):
idx = (i * nSpokes) + j;
r = float(lines[lID])
line = lines[lID].split(' ')
r = float(line[0])
if len(line) > 1:
try:
self.values[idx] = float(line[1])
except:
self.values[idx] = 0
theta = spokes[j];
x = r * np.cos(theta)
y = r * np.sin(theta)
Expand All @@ -297,8 +305,8 @@ def read_aop(self, filename, unify=True, struc=True):
v1 = cur_stack_idx + next_spoke;
v2 = next_stack_idx + next_spoke;
v3 = next_stack_idx + sp;
self.faces[fidx, :] = [v0, v1, v3];
self.faces[fidx + 1, :] = v1, v2, v3;
self.faces[fidx, :] = [v0, v3, v1];
self.faces[fidx + 1, :] = v1, v3, v2;
fidx += 2;
# Call function to unify vertices of the array
self.calcStruct()
Expand All @@ -308,7 +316,7 @@ def read_aop(self, filename, unify=True, struc=True):
# self.fixNorm()
if struc is True:
self.calcStruct()
self.values = np.zeros([len(self.vert)])


def calcStruct(self, norm=True, edges=True,
edgeFaces=True, faceEdges=True, vNorm=False):
Expand Down Expand Up @@ -673,7 +681,7 @@ def save_aop(self, filename, slices=100, spokes=72, sliceInterval = None, spokeI
# Write the spokes
if isinstance(spokes, int):
spacing = (360) / spokes
spokes = np.arange(0, 360, spacing)
spokes = np.arange(-90, 270, spacing)
nSpokes = len(spokes)
lines.append("%i\n" % nSpokes)
lines.append("%f\n" % spacing)
Expand Down Expand Up @@ -747,13 +755,14 @@ def save_aop(self, filename, slices=100, spokes=72, sliceInterval = None, spokeI
z = slices[i] - minSl
rPoly = ((x ** 2) + (y ** 2)) ** 0.5
tPoly = np.rad2deg(np.arctan2(y, x))
tPoly[tPoly < 0] += 360
tPoly[tPoly < -90] += 360
idx = np.argsort(tPoly)
rPoly = rPoly[idx]
np.append(rPoly, rPoly[0])
tPoly = tPoly[idx]
np.append(tPoly, 360)
np.append(tPoly, 270)
rs = np.interp(spokes, tPoly, rPoly)
rs = np.flip(rs)
for j, r in enumerate(rs):
lines.append("%f\n" % r)
verts[vId, :] = [r, spokes[j], z]
Expand Down

0 comments on commit 7a3d5f8

Please sign in to comment.