-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d52ce87
commit 0b777e2
Showing
13 changed files
with
258 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file added
BIN
+1.06 KB
StructuralGT/pytest/__pycache__/test_AverageNodalConnectivity.cpython-310-pytest-7.4.0.pyc
Binary file not shown.
Binary file added
BIN
+1.06 KB
StructuralGT/pytest/__pycache__/test_AverageNodalConnectivity.cpython-310-pytest-7.4.3.pyc
Binary file not shown.
Binary file added
BIN
+1.21 KB
StructuralGT/pytest/__pycache__/test_Electronic.cpython-310-pytest-7.4.0.pyc
Binary file not shown.
Binary file added
BIN
+1.19 KB
StructuralGT/pytest/__pycache__/test_Electronic.cpython-310-pytest-7.4.3.pyc
Binary file not shown.
Binary file added
BIN
+2.27 KB
StructuralGT/pytest/__pycache__/test_Structural.cpython-310-pytest-7.4.0.pyc
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from StructuralGT import interaction_networks, base | ||
import StructuralGT | ||
import pytest | ||
|
||
_path = StructuralGT.__path__[0] | ||
|
||
def test_find_node(): | ||
pass | ||
""" | ||
N = interaction_networks.InteractionNetwork(_path + '/pytest/data/ANF') | ||
N.binarize() | ||
N.set_graph([0,1000,0,1000,0,4]) | ||
N.to_gsd() | ||
N.node_calc() | ||
N.Node_labelling(N.Degree[0],'Degree','test.gsd') | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from StructuralGT import physical_networks, base | ||
import StructuralGT | ||
import pytest | ||
import os | ||
import shutil | ||
|
||
_path = StructuralGT.__path__[0] | ||
|
||
@pytest.fixture(params=[pytest.param(_path+'/pytest/data/AgNWN'), | ||
pytest.param(_path+'/pytest/data/ANF')]) | ||
def binarize(request): | ||
_dir = request.param | ||
if os.path.isdir(_dir+'/Binarized'): shutil.rmtree(_dir+'/Binarized') | ||
|
||
N = StructuralGT.physical_networks.ResistiveNetwork(_dir) | ||
N.binarize() | ||
|
||
#assert N.img_bin.shape == N.img.shape | ||
|
||
return N | ||
|
||
@pytest.fixture | ||
def gsd(binarize): | ||
N = binarize | ||
if N._2d: | ||
N.stack_to_gsd(crop=[149, 868, 408, 1127], rotate=45) | ||
else: | ||
N.stack_to_gsd(crop=[0,100,0,90,4,9]) | ||
|
||
return N | ||
|
||
@pytest.fixture | ||
def graph(gsd): | ||
N = gsd | ||
N.set_graph(weight_type=['FixedWidthConductance'], sub=True) | ||
|
||
return N | ||
|
||
@pytest.fixture | ||
def potential(graph): | ||
N = graph | ||
if N._2d: | ||
N.potential_distribution(0,[0,20],[180,200],R_j=10) | ||
else: | ||
N.potential_distribution(0,[0,20],[70,90],R_j=10) | ||
|
||
return N | ||
|
||
def test_node_labelling(potential): | ||
N = potential | ||
N.Node_labelling(N.P,'P','test.gsd') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from StructuralGT import physical_networks, base | ||
import StructuralGT | ||
import pytest | ||
|
||
_path = StructuralGT.__path__[0] | ||
|
||
def test_3D(): | ||
N = physical_networks.StructuralNetwork(_path + '/pytest/data/Rectangle1') | ||
N.binarize() | ||
N.stack_to_gsd() | ||
N.set_graph() | ||
N.node_calc() | ||
N.Node_labelling(N.Degree[0],'Degree','test.gsd') | ||
|
||
def test_3D_crop(): | ||
N = physical_networks.StructuralNetwork(_path + '/pytest/data/Rectangle1') | ||
N.binarize() | ||
N.stack_to_gsd(crop=[0,550,0,550,0,2]) | ||
N.set_graph() | ||
N.node_calc() | ||
N.Node_labelling(N.Degree[0],'Degree','test.gsd') | ||
|
||
def test_2D(): | ||
N = physical_networks.StructuralNetwork(_path + '/pytest/data/AgNWN') | ||
N.binarize() | ||
N.stack_to_gsd() | ||
N.set_graph() | ||
N.node_calc() | ||
N.Node_labelling(N.Degree[0],'Degree','test.gsd') | ||
|
||
def test_2D_crop(): | ||
N = physical_networks.StructuralNetwork(_path + '/pytest/data/AgNWN') | ||
N.binarize() | ||
N.stack_to_gsd(crop=[0,550,0,550]) | ||
N.set_graph() | ||
N.node_calc() | ||
N.Node_labelling(N.Degree[0],'Degree','test.gsd') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from StructuralGT import networks | ||
import numpy as np | ||
|
||
import StructuralGT | ||
_path = StructuralGT.__path__[0] | ||
|
||
anf_options = {"Thresh_method":0, "gamma": 3, "md_filter": 0, "g_blur": 1, | ||
"autolvl": 0,"fg_color":0,"laplacian": 0, "scharr": 0, "sobel":0 , | ||
"lowpass": 1, "asize":7, "bsize":3, "wsize":5, "thresh": 103} | ||
|
||
agnwn_options = {"Thresh_method":0, "gamma": 3, "md_filter": 0, "g_blur": 1, | ||
"autolvl": 0,"fg_color":0,"laplacian": 0, "scharr": 0, "sobel":0 , | ||
"lowpass": 1, "asize":7, "bsize":3, "wsize":5, "thresh": 103} | ||
|
||
def fibrous(weight_type=None): | ||
ANF = networks.Network(_path + '/pytest/data/ANF') | ||
ANF.binarize(options_dict=anf_options) | ||
ANF.img_to_skel(crop=[200,300,200,300, 1, 3]) | ||
ANF.set_graph(sub=True, weight_type=weight_type) | ||
|
||
return ANF | ||
|
||
def conductive(): | ||
AgNWN = networks.Network(_path + '/pytest/data/AgNWN') | ||
AgNWN.binarize(options_dict=agnwn_options) | ||
AgNWN.img_to_skel(crop=[149, 868, 408, 1127], rotate=45) | ||
AgNWN.set_graph(weight_type=['FixedWidthConductance'], sub=True, R_j=10, rho_dim=2) | ||
|
||
return AgNWN | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from StructuralGT.average_nodal_connectivity import AverageNodalConnectivity | ||
from network_factory import fibrous | ||
|
||
import igraph as ig | ||
import pytest | ||
from networkx import average_node_connectivity | ||
import numpy.testing as npt | ||
|
||
|
||
class TestAverageNodalConnectivity: | ||
def test(self): | ||
#Obtain a connected graph | ||
testNetwork = fibrous() | ||
testGraph = testNetwork.graph.to_networkx() | ||
|
||
#Instantiate a compute module and run calculation | ||
ComputeModule = AverageNodalConnectivity() | ||
ComputeModule.compute(testNetwork) | ||
|
||
#Check that the StructuralGT and networkx values are equal | ||
npt.assert_allclose(ComputeModule.average_nodal_connectivity, | ||
average_node_connectivity(testGraph), | ||
rtol=1e-2 | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from StructuralGT.electronic import Electronic | ||
from network_factory import conductive | ||
|
||
import igraph as ig | ||
import pytest | ||
import numpy.testing as npt | ||
|
||
import StructuralGT | ||
_path = StructuralGT.__path__[0] | ||
|
||
class TestElectronic: | ||
@pytest.fixture | ||
def test_compute(self): | ||
#Obtain a conductive graph | ||
testNetwork = conductive() | ||
|
||
#Instantiate a compute module and run calculation | ||
ComputeModule = Electronic() | ||
ComputeModule.compute(testNetwork, 10, 0, [[0,50],[testNetwork.shape[0]-50, testNetwork.shape[0]]]) | ||
|
||
return ComputeModule | ||
|
||
def test_Kirchhoff(self, test_compute): | ||
#Ensure Kirchhoff's Law satisfied | ||
ComputeModule = test_compute | ||
|
||
npt.assert_allclose((ComputeModule.P[-2] - ComputeModule.P[-1])/ComputeModule.effective_resistance, | ||
1, | ||
atol=1e-2 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
from StructuralGT.structural import Structural | ||
from network_factory import fibrous | ||
import igraph as ig | ||
import pytest | ||
from networkx import diameter, density, clustering, average_clustering | ||
import numpy.testing as npt | ||
|
||
|
||
class TestUnweightedStructural: | ||
@pytest.fixture | ||
def test_compute(self): | ||
#Obtain an unweighted connected graph | ||
testNetwork = fibrous() | ||
testGraph = testNetwork.graph.to_networkx() | ||
|
||
#Instantiate a compute module and run calculation | ||
ComputeModule = Structural() | ||
ComputeModule.compute(testNetwork) | ||
|
||
return ComputeModule, testGraph | ||
|
||
def test_diameter(self, test_compute): | ||
ComputeModule, testGraph = test_compute | ||
npt.assert_allclose( | ||
ComputeModule.diameter, | ||
diameter(testGraph), | ||
atol=1e-2, | ||
) | ||
|
||
def test_density(self, test_compute): | ||
ComputeModule, testGraph = test_compute | ||
npt.assert_allclose( | ||
ComputeModule.density, | ||
density(testGraph), | ||
atol=1e-2, | ||
) | ||
|
||
def test_average_clustering(self, test_compute): | ||
""" | ||
ComputeModule, testGraph = test_compute | ||
npt.assert_allclose( | ||
ComputeModule.average_clustering, | ||
average_clustering(testGraph), | ||
atol=1e-2, | ||
) | ||
""" | ||
pass | ||
|
||
class TestWeightedStructural: | ||
@pytest.fixture | ||
def test_compute(self): | ||
#Obtain an unweighted connected graph | ||
testNetwork = fibrous(weight_type=['Length']) | ||
testGraph = testNetwork.graph.to_networkx() | ||
|
||
#Instantiate a compute module and run calculation | ||
ComputeModule = Structural(weight_type=['Length']) | ||
ComputeModule.compute(testNetwork) | ||
|
||
return ComputeModule, testGraph | ||
|
||
def test_diameter(self, test_compute): | ||
ComputeModule, testGraph = test_compute | ||
npt.assert_allclose( | ||
ComputeModule.diameter, | ||
diameter(testGraph), | ||
atol=1e-2, | ||
) |