Skip to content

Commit

Permalink
Add example
Browse files Browse the repository at this point in the history
  • Loading branch information
AlainKadar committed Oct 26, 2023
1 parent 5bdf0d0 commit 2de1dfb
Show file tree
Hide file tree
Showing 24 changed files with 433 additions and 64 deletions.
Binary file added Example/.DS_Store
Binary file not shown.
Binary file added Example/ANF/Binarized/cleaned_merged_skel.gsd
Binary file not shown.
Binary file added Example/ANF/Binarized/merged_skel.gsd
Binary file not shown.
Binary file added Example/ANF/Binarized/skel.gsd
Binary file not shown.
Binary file added Example/ANF/Binarized/slice0000.tiff
Binary file not shown.
Binary file added Example/ANF/slice0000.tiff
Binary file not shown.
37 changes: 37 additions & 0 deletions Example/AgNWN/1_175_6/1_175_6_Results.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
,Theta,O_eff
0,0.0,132.57072688353588
1,10.0,134.9301966929933
2,20.0,125.95388312874962
3,30.0,105.9930473677451
4,40.0,81.87194619754801
5,50.0,60.31469076515667
6,60.0,46.32175945873722
7,70.0,38.9090421640372
8,80.0,34.10182433856702
9,90.0,32.016375613444
10,100.0,32.68944594570813
11,110.0,34.537476926411436
12,120.0,40.500038745055484
13,130.0,53.71422627746765
14,140.0,69.99170431620517
15,150.0,90.89873768877797
16,160.0,108.19992220950888
17,170.0,122.15791623707804
18,180.0,132.67697629043923
19,190.0,133.92895577409672
20,200.0,125.47752302002705
21,210.0,105.90636039743487
22,220.0,81.75009236941338
23,230.0,60.63752207855191
24,240.0,46.205582224026045
25,250.0,38.95952409951256
26,260.0,33.986665846403525
27,270.0,32.00350478163239
28,280.0,32.531519736571695
29,290.0,34.79470123200407
30,300.0,40.35336259431624
31,310.0,53.79040660719977
32,320.0,69.54383946079517
33,330.0,90.47407922315519
34,340.0,108.5561376967024
35,350.0,121.46018755685213
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added Example/AgNWN/1_175_6/Binarized/skel.gsd
Binary file not shown.
Binary file added Example/AgNWN/1_175_6/Binarized/slice000.tiff
Binary file not shown.
Binary file added Example/AgNWN/1_175_6/Binarized/slice0000.tiff
Binary file not shown.
Binary file added Example/AgNWN/1_175_6/Binarized/slice3.tiff
Binary file not shown.
1 change: 1 addition & 0 deletions Example/AgNWN/1_175_6/img_options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"Thresh_method":1, "gamma": 0.8, "md_filter": 1, "g_blur":1, "autolvl": 0,"fg_color":0, "laplacian": 0, "scharr": 0, "sobel":0 , "lowpass": 0, "asize": 23, "bsize":31, "wsize":21, "thresh": 100}
6 changes: 6 additions & 0 deletions Example/AgNWN/1_175_6/params.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"pix_per_m":1.37E8,
"crop":1765,
"O_x": 38,
"O_y": 144
}
Binary file added Example/AgNWN/1_175_6/scalebar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Example/AgNWN/1_175_6/slice0000.tiff
Binary file not shown.
275 changes: 275 additions & 0 deletions Example/Example.ipynb

Large diffs are not rendered by default.

40 changes: 40 additions & 0 deletions Example/config/freud.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

[LAYOUT]
# Width of sidebar that contains server names
server_width = 15
# Height of container that holds headers
header_height = 10
# Height of container that shows server summary
summary_height = 10

[KEYS]
new_server = n
edit_server = e
send_request = r
edit_authentication = a
edit_headers = h
edit_body = b
delete_server = d
open_response_body = o
sort_servers = s
key_quick_ref = c-f

[DB]
filename = requests.db

[JSON]
indentation = 2

[SORT_BY]
# Column options: name, timestamp, url, method, body, authtype, authuser,
# authpass, headers
# Order options: asc, desc
column = timestamp
order = asc

[STYLE]
# More styles here:
# https://bitbucket.org/birkenfeld/pygments-main/src/stable/pygments/styles
theme = default
separator_line_fg = gray
separator_line_bg = black
64 changes: 32 additions & 32 deletions StructuralGT/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,24 +308,24 @@ def debubble(g, elements):
canvas = skeletonize_3d(canvas)/255
canvas = binary_closing(canvas, footprint=elem)

g.skeleton = skeletonize_3d(canvas)/255
g._skeleton = skeletonize_3d(canvas)/255

if g._2d:
g.skeleton_3d = np.swapaxes(np.array([g.skeleton]), 2, 1)
g.skeleton_3d = np.asarray([g.skeleton])
g._skeleton_3d = np.swapaxes(np.array([g.skeleton]), 2, 1)
g._skeleton_3d = np.asarray([g.skeleton])
else:
g.skeleton_3d = np.asarray(g.skeleton)
g._skeleton_3d = np.asarray(g.skeleton)

positions = np.asarray(np.where(g.skeleton_3d!=0)).T
positions = np.asarray(np.where(g._skeleton_3d!=0)).T
with gsd.hoomd.open(name=g.gsd_name, mode='w') as f:
s = gsd.hoomd.Frame()
s.particles.N = int(sum(g.skeleton_3d.ravel()))
s.particles.N = int(sum(g._skeleton_3d.ravel()))
s.particles.position = positions
s.particles.types = ['A']
s.particles.typeid = ['0']*s.particles.N
f.append(s)
end = time.time()
print('Ran debubble in ', end-start, 'for an image with shape ', g.skeleton_3d.shape)
print('Ran debubble in ', end-start, 'for an image with shape ', g._skeleton_3d.shape)

return g

Expand All @@ -335,25 +335,25 @@ def merge_nodes(g, disk_size):
start = time.time()
g.gsd_name = g.gsd_dir + '/merged_' + os.path.split(g.gsd_name)[1]

canvas = g.skeleton
g.skeleton = skel_ID.merge_nodes(canvas, disk_size)
canvas = g._skeleton
g._skeleton = skel_ID.merge_nodes(canvas, disk_size)

if g._2d:
g.skeleton_3d = np.swapaxes(np.array([g.skeleton]), 2, 1)
g.skeleton_3d = np.asarray([g.skeleton])
g._skeleton_3d = np.swapaxes(np.array([g.skeleton]), 2, 1)
g._skeleton_3d = np.asarray([g.skeleton])
else:
g.skeleton_3d = np.asarray(g.skeleton)
g._skeleton_3d = np.asarray(g.skeleton)

positions = np.asarray(np.where(g.skeleton_3d!=0)).T
positions = np.asarray(np.where(g._skeleton_3d!=0)).T
with gsd.hoomd.open(name=g.gsd_name, mode='w') as f:
s = gsd.hoomd.Frame()
s.particles.N = int(sum(g.skeleton_3d.ravel()))
s.particles.N = int(sum(g._skeleton_3d.ravel()))
s.particles.position = positions
s.particles.types = ['A']
s.particles.typeid = ['0']*s.particles.N
f.append(s)
end = time.time()
print('Ran merge in ', end-start, 'for an image with shape ', g.skeleton_3d.shape)
print('Ran merge in ', end-start, 'for an image with shape ', g._skeleton_3d.shape)

return g

Expand All @@ -362,25 +362,25 @@ def prune(g, size):
start = time.time()
g.gsd_name = g.gsd_dir + '/pruned_' + os.path.split(g.gsd_name)[1]

canvas = g.skeleton
g.skeleton = skel_ID.pruning(canvas, size)
canvas = g._skeleton
g._skeleton = skel_ID.pruning(canvas, size)

if g._2d:
g.skeleton_3d = np.swapaxes(np.array([g.skeleton]), 2, 1)
g.skeleton_3d = np.asarray([g.skeleton])
g._skeleton_3d = np.swapaxes(np.array([g.skeleton]), 2, 1)
g._skeleton_3d = np.asarray([g.skeleton])
else:
g.skeleton_3d = np.asarray(g.skeleton)
g._skeleton_3d = np.asarray(g.skeleton)

positions = np.asarray(np.where(g.skeleton_3d!=0)).T
positions = np.asarray(np.where(g._skeleton_3d!=0)).T
with gsd.hoomd.open(name=g.gsd_name, mode='w') as f:
s = gsd.hoomd.Frame()
s.particles.N = int(sum(g.skeleton_3d.ravel()))
s.particles.N = int(sum(g._skeleton_3d.ravel()))
s.particles.position = positions
s.particles.types = ['A']
s.particles.typeid = ['0']*s.particles.N
f.append(s)
end = time.time()
print('Ran prune in ', end-start, 'for an image with shape ', g.skeleton_3d.shape)
print('Ran prune in ', end-start, 'for an image with shape ', g._skeleton_3d.shape)

return g

Expand All @@ -389,27 +389,27 @@ def remove_objects(g, size):
start = time.time()
g.gsd_name = g.gsd_dir + '/cleaned_' + os.path.split(g.gsd_name)[1]

canvas = g.skeleton
g.skeleton = remove_small_objects(canvas, size, connectivity=2)
canvas = g._skeleton
g._skeleton = remove_small_objects(canvas, size, connectivity=2)

if g._2d:
g.skeleton_3d = np.swapaxes(np.array([g.skeleton]), 2, 1)
g.skeleton_3d = np.asarray([g.skeleton])
g._skeleton_3d = np.swapaxes(np.array([g.skeleton]), 2, 1)
g._skeleton_3d = np.asarray([g.skeleton])
else:
g.skeleton_3d = np.asarray(g.skeleton)
g._skeleton_3d = np.asarray(g.skeleton)

positions = np.asarray(np.where(g.skeleton_3d!=0)).T
positions = np.asarray(np.where(g._skeleton_3d!=0)).T
with gsd.hoomd.open(name=g.gsd_name, mode='w') as f:
s = gsd.hoomd.Frame()
s.particles.N = int(sum(g.skeleton_3d.ravel()))
s.particles.N = int(sum(g._skeleton_3d.ravel()))
s.particles.position = positions
s.particles.types = ['A']
s.particles.typeid = ['0']*s.particles.N
f.append(s)
end = time.time()
print('Ran remove objects in ', end-start, 'for an image with shape ', g.skeleton_3d.shape)

print('Ran remove objects in ', end-start, 'for an image with shape ', g._skeleton_3d.shape)

return g

def igraph_ANC(directory, I):
start = time.time()
Expand Down
4 changes: 2 additions & 2 deletions StructuralGT/interaction_networks.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from StructuralGT import util, base
from StructuralGT import util, base, networks
import numpy as np
import freud
import igraph as ig
import os
from skimage.measure import regionprops, label
import gsd.hoomd

class InteractionNetwork(util.Network):
class InteractionNetwork(networks.Network):
"""Class for extracting bond networks from particle images. In this class,
nodes are particles, and edges connect neighbouring particles.
Neighbours are found using freudCITE.
Expand Down
8 changes: 4 additions & 4 deletions StructuralGT/networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
import gsd.hoomd
import warnings

from util import *
from StructuralGT.util import _image_stack, _cropper, _domain, _fname

class Network:
"""Generic class to represent networked image data. Should not be
instantiated by the user.
Children of this class will hold igraph :class:`Graph` attributes and
Subclasses will hold :class:`graph` attributes
holds additional attributes and methods for supporting geometric features
associated images, dimensionality etc.
Args:
directory (str):
The (absolute or relative) pathname for the stack of images to be
The (absolute or relative) pathname for the image(s) to be
analysed. Where 2D analysis is concerned, the directory should
contain a single image.
child_dir (str):
Expand Down Expand Up @@ -94,7 +94,7 @@ def binarize(self, options_dict=None):
def set_img_bin(self, crop):
"""Sets the :attr:`img_bin` and :attr:`img_bin_3d` attributes, which
are numpy arrays of pixels and voxels which represent the binarized
image. Called internally by child classes of :class:`Network`.
image. Called internally by subclasses of :class:`Network`.
Args:
crop (list):
Expand Down
Loading

0 comments on commit 2de1dfb

Please sign in to comment.