sgtlib 3.3.9__cp313-cp313-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- StructuralGT/__init__.py +31 -0
- StructuralGT/apps/__init__.py +0 -0
- StructuralGT/apps/cli_main.py +258 -0
- StructuralGT/apps/gui_main.py +69 -0
- StructuralGT/apps/gui_mcw/__init__.py +0 -0
- StructuralGT/apps/gui_mcw/checkbox_model.py +91 -0
- StructuralGT/apps/gui_mcw/controller.py +1073 -0
- StructuralGT/apps/gui_mcw/image_provider.py +74 -0
- StructuralGT/apps/gui_mcw/imagegrid_model.py +75 -0
- StructuralGT/apps/gui_mcw/qthread_worker.py +102 -0
- StructuralGT/apps/gui_mcw/table_model.py +79 -0
- StructuralGT/apps/gui_mcw/tree_model.py +154 -0
- StructuralGT/apps/sgt_qml/CenterMainContent.qml +19 -0
- StructuralGT/apps/sgt_qml/LeftContent.qml +48 -0
- StructuralGT/apps/sgt_qml/MainWindow.qml +762 -0
- StructuralGT/apps/sgt_qml/RightLoggingPanel.qml +125 -0
- StructuralGT/apps/sgt_qml/assets/icons/back_icon.png +0 -0
- StructuralGT/apps/sgt_qml/assets/icons/brightness_icon.png +0 -0
- StructuralGT/apps/sgt_qml/assets/icons/cancel_icon.png +0 -0
- StructuralGT/apps/sgt_qml/assets/icons/crop_icon.png +0 -0
- StructuralGT/apps/sgt_qml/assets/icons/edit_icon.png +0 -0
- StructuralGT/apps/sgt_qml/assets/icons/graph_icon.png +0 -0
- StructuralGT/apps/sgt_qml/assets/icons/hide_panel.png +0 -0
- StructuralGT/apps/sgt_qml/assets/icons/next_icon.png +0 -0
- StructuralGT/apps/sgt_qml/assets/icons/notify_icon.png +0 -0
- StructuralGT/apps/sgt_qml/assets/icons/rescale_icon.png +0 -0
- StructuralGT/apps/sgt_qml/assets/icons/show_panel.png +0 -0
- StructuralGT/apps/sgt_qml/assets/icons/square_icon.png +0 -0
- StructuralGT/apps/sgt_qml/assets/icons/undo_icon.png +0 -0
- StructuralGT/apps/sgt_qml/components/ImageFilters.qml +82 -0
- StructuralGT/apps/sgt_qml/components/ImageProperties.qml +112 -0
- StructuralGT/apps/sgt_qml/components/ProjectNav.qml +127 -0
- StructuralGT/apps/sgt_qml/widgets/BinaryFilterWidget.qml +151 -0
- StructuralGT/apps/sgt_qml/widgets/BrightnessControlWidget.qml +103 -0
- StructuralGT/apps/sgt_qml/widgets/CreateProjectWidget.qml +112 -0
- StructuralGT/apps/sgt_qml/widgets/GTWidget.qml +94 -0
- StructuralGT/apps/sgt_qml/widgets/GraphComputeWidget.qml +77 -0
- StructuralGT/apps/sgt_qml/widgets/GraphExtractWidget.qml +175 -0
- StructuralGT/apps/sgt_qml/widgets/GraphPropertyWidget.qml +77 -0
- StructuralGT/apps/sgt_qml/widgets/ImageFilterWidget.qml +137 -0
- StructuralGT/apps/sgt_qml/widgets/ImagePropertyWidget.qml +78 -0
- StructuralGT/apps/sgt_qml/widgets/ImageViewWidget.qml +585 -0
- StructuralGT/apps/sgt_qml/widgets/MenuBarWidget.qml +137 -0
- StructuralGT/apps/sgt_qml/widgets/MicroscopyPropertyWidget.qml +80 -0
- StructuralGT/apps/sgt_qml/widgets/ProjectWidget.qml +141 -0
- StructuralGT/apps/sgt_qml/widgets/RescaleControlWidget.qml +83 -0
- StructuralGT/apps/sgt_qml/widgets/RibbonWidget.qml +406 -0
- StructuralGT/apps/sgt_qml/widgets/StatusBarWidget.qml +173 -0
- StructuralGT/compute/__init__.py +0 -0
- StructuralGT/compute/c_lang/include/sgt_base.h +21 -0
- StructuralGT/compute/c_lang/sgt_base.c +61 -0
- StructuralGT/compute/c_lang/sgt_c_module.cp313-win_amd64.pyd +0 -0
- StructuralGT/compute/c_lang/sgtmodule.c +183 -0
- StructuralGT/compute/graph_analyzer.py +1499 -0
- StructuralGT/entrypoints.py +49 -0
- StructuralGT/imaging/__init__.py +0 -0
- StructuralGT/imaging/base_image.py +403 -0
- StructuralGT/imaging/image_processor.py +780 -0
- StructuralGT/modules.py +29 -0
- StructuralGT/networks/__init__.py +0 -0
- StructuralGT/networks/fiber_network.py +490 -0
- StructuralGT/networks/graph_skeleton.py +425 -0
- StructuralGT/networks/sknw_mod.py +199 -0
- StructuralGT/utils/__init__.py +0 -0
- StructuralGT/utils/config_loader.py +244 -0
- StructuralGT/utils/configs.ini +97 -0
- StructuralGT/utils/progress_update.py +67 -0
- StructuralGT/utils/sgt_utils.py +291 -0
- sgtlib-3.3.9.dist-info/METADATA +790 -0
- sgtlib-3.3.9.dist-info/RECORD +75 -0
- sgtlib-3.3.9.dist-info/WHEEL +5 -0
- sgtlib-3.3.9.dist-info/entry_points.txt +3 -0
- sgtlib-3.3.9.dist-info/licenses/LICENSE +674 -0
- sgtlib-3.3.9.dist-info/licenses/license.txt +658 -0
- sgtlib-3.3.9.dist-info/top_level.txt +1 -0
@@ -0,0 +1,183 @@
|
|
1
|
+
#include <stdlib.h>
|
2
|
+
#include <stdio.h>
|
3
|
+
#include <stdarg.h>
|
4
|
+
|
5
|
+
#define PY_SSIZE_T_CLEAN
|
6
|
+
#include <Python.h>
|
7
|
+
//#include "sgt_base.h"
|
8
|
+
#include "include/sgt_base.h"
|
9
|
+
|
10
|
+
|
11
|
+
static PyObject *ErrorObject;
|
12
|
+
static PyObject *
|
13
|
+
compute_anc(PyObject *self, PyObject *args)
|
14
|
+
{
|
15
|
+
int num_cpus;
|
16
|
+
int allow_mp;
|
17
|
+
char *f_name;
|
18
|
+
|
19
|
+
// Consider passing graph as String
|
20
|
+
if (!PyArg_ParseTuple(args, "sii:compute_anc", &f_name, &num_cpus, &allow_mp)){
|
21
|
+
return NULL;
|
22
|
+
}
|
23
|
+
|
24
|
+
/*if ( f_name == ''){
|
25
|
+
PyErr_SetString(ErrorObject, "Unable to retrieve graph.");
|
26
|
+
return NULL;
|
27
|
+
}*/
|
28
|
+
|
29
|
+
if ( num_cpus <= 0 || allow_mp < 0){
|
30
|
+
PyErr_SetString(ErrorObject, "Invalid CPU parameters.");
|
31
|
+
return NULL;
|
32
|
+
}
|
33
|
+
|
34
|
+
// Declare required variables
|
35
|
+
FILE *file;
|
36
|
+
|
37
|
+
igraph_t graph;
|
38
|
+
igraph_integer_t num_nodes;
|
39
|
+
igraph_integer_t count_nc = 0;
|
40
|
+
igraph_integer_t sum_nc = 0;
|
41
|
+
igraph_real_t anc = 0;
|
42
|
+
|
43
|
+
// Open the file containing the serialized graph
|
44
|
+
file = fopen(f_name, "r");
|
45
|
+
// Read the graph from the file
|
46
|
+
igraph_read_graph_edgelist(&graph, file, 0, IGRAPH_UNDIRECTED);
|
47
|
+
fclose(file);
|
48
|
+
// printf("Nodes: %d\nEdges: %d\n", (int)igraph_vcount(&graph), (int)igraph_ecount(&graph));
|
49
|
+
|
50
|
+
num_nodes = igraph_vcount(&graph);
|
51
|
+
if (allow_mp == 0){
|
52
|
+
printf("Using single processing\n");
|
53
|
+
igraph_integer_t lnc;
|
54
|
+
for (igraph_integer_t i=0; i<num_nodes; i++) {
|
55
|
+
for (igraph_integer_t j=i+1; j<num_nodes; j++){
|
56
|
+
igraph_st_vertex_connectivity(&graph, &lnc, i, j, IGRAPH_VCONN_NEI_NEGATIVE);
|
57
|
+
if (lnc == -1) { continue; }
|
58
|
+
sum_nc += lnc;
|
59
|
+
count_nc += 1;
|
60
|
+
}
|
61
|
+
}
|
62
|
+
|
63
|
+
}
|
64
|
+
else {
|
65
|
+
printf("Using multiprocessing\n");
|
66
|
+
// Initialize mutex
|
67
|
+
pthread_mutex_t mutex;
|
68
|
+
pthread_mutex_init(&mutex, NULL);
|
69
|
+
|
70
|
+
// Create thread pool
|
71
|
+
const int MAX_THREAD_COUNT = num_cpus;
|
72
|
+
|
73
|
+
// Allocate memory for threads and args arrays
|
74
|
+
pthread_t *threads = (pthread_t *)malloc(MAX_THREAD_COUNT * sizeof(pthread_t));
|
75
|
+
ThreadArgsLNC *args = (ThreadArgsLNC *)malloc(MAX_THREAD_COUNT * sizeof(ThreadArgsLNC));
|
76
|
+
|
77
|
+
if (threads == NULL || args == NULL) {
|
78
|
+
PyErr_SetString(ErrorObject, "Memory allocation failed\n");
|
79
|
+
return NULL;
|
80
|
+
}
|
81
|
+
|
82
|
+
// Initialize thread pool
|
83
|
+
for (int i = 0; i < MAX_THREAD_COUNT; i++) {
|
84
|
+
args[i].graph = &graph;
|
85
|
+
args[i].mutex = &mutex;
|
86
|
+
args[i].total_nc = &sum_nc;
|
87
|
+
args[i].total_count = &count_nc;
|
88
|
+
}
|
89
|
+
|
90
|
+
// Create threads for computing LNC
|
91
|
+
int idx = 0;
|
92
|
+
int thread_count = 0;
|
93
|
+
for (igraph_integer_t i = 0; i < num_nodes; i++) {
|
94
|
+
for (igraph_integer_t j = i + 1; j < num_nodes; j++) {
|
95
|
+
idx = (int)(thread_count % MAX_THREAD_COUNT);
|
96
|
+
if (thread_count >= MAX_THREAD_COUNT) {
|
97
|
+
// Wait for a thread to finish before starting a new one
|
98
|
+
pthread_join(threads[idx], NULL);
|
99
|
+
thread_count++;
|
100
|
+
}
|
101
|
+
args[idx].i = (int)i;
|
102
|
+
args[idx].j = (int)j;
|
103
|
+
pthread_create(&threads[idx], NULL, compute_lnc, &args[idx]);
|
104
|
+
thread_count++;
|
105
|
+
// printf("thread %d running...\n", (idx));
|
106
|
+
}
|
107
|
+
}
|
108
|
+
|
109
|
+
// Join threads
|
110
|
+
for (int i = 0; i < MAX_THREAD_COUNT && i < thread_count; i++) {
|
111
|
+
pthread_join(threads[i], NULL);
|
112
|
+
}
|
113
|
+
|
114
|
+
// Destroy mutex
|
115
|
+
pthread_mutex_destroy(&mutex);
|
116
|
+
// Free dynamically allocated memory
|
117
|
+
free(threads);
|
118
|
+
free(args);
|
119
|
+
}
|
120
|
+
|
121
|
+
// Compute ANC
|
122
|
+
anc = (float) sum_nc / count_nc;
|
123
|
+
|
124
|
+
// Destroy graph
|
125
|
+
igraph_destroy(&graph);
|
126
|
+
|
127
|
+
return PyFloat_FromDouble((double) anc);
|
128
|
+
|
129
|
+
}
|
130
|
+
static char compute_anc_doc[] =
|
131
|
+
"A C method that uses iGraph library to compute average node connectivity of a graph.\n"
|
132
|
+
"\n"
|
133
|
+
"Args:\n"
|
134
|
+
" file (string): CSV file with edge list of graph A.\n"
|
135
|
+
" cpus (int): number of available CPUs.\n"
|
136
|
+
" mp (int): allow multi-processing (0: No, 1: Yes).\n"
|
137
|
+
"\n"
|
138
|
+
"Returns:\n"
|
139
|
+
" ANC (float): Average Node Connectivity as a float value.\n";
|
140
|
+
|
141
|
+
|
142
|
+
static char sgt_doc[] =
|
143
|
+
"A C language module leveraging the iGraph library to compute Graph Theory (GT) metrics,"
|
144
|
+
"enhanced with multi-threading capabilities for accelerated computation.\n";
|
145
|
+
|
146
|
+
/* Method Table: ist of functions defined in the module */
|
147
|
+
static PyMethodDef sgt_methods[] = {
|
148
|
+
{"compute_anc", compute_anc, METH_VARARGS, compute_anc_doc },
|
149
|
+
//{"compute_lnc", compute_lnc, METH_VARARGS, "Compute local node connectivity." },
|
150
|
+
{NULL, NULL, 0, NULL} /* Sentinel */
|
151
|
+
};
|
152
|
+
|
153
|
+
/* Create module */
|
154
|
+
static struct PyModuleDef sgt_c_module = {
|
155
|
+
PyModuleDef_HEAD_INIT,
|
156
|
+
"sgt_c_module", /* name of module */
|
157
|
+
sgt_doc, /* module documentation, may be NULL */
|
158
|
+
-1, /* size of per-interpreter state of the module, or -1 if the module keeps state in global variables. */
|
159
|
+
sgt_methods
|
160
|
+
};
|
161
|
+
|
162
|
+
/* Initialization function for the module */
|
163
|
+
PyMODINIT_FUNC
|
164
|
+
PyInit_sgt_c_module(void)
|
165
|
+
{
|
166
|
+
PyObject *m;
|
167
|
+
|
168
|
+
m = PyModule_Create(&sgt_c_module);
|
169
|
+
if (m == NULL)
|
170
|
+
return NULL;
|
171
|
+
|
172
|
+
ErrorObject = PyErr_NewException("sgt_c_module.error", NULL, NULL);
|
173
|
+
Py_XINCREF(ErrorObject);
|
174
|
+
if (PyModule_AddObject(m, "error", ErrorObject) < 0) {
|
175
|
+
Py_XDECREF(ErrorObject);
|
176
|
+
Py_CLEAR(ErrorObject);
|
177
|
+
Py_DECREF(m);
|
178
|
+
return NULL;
|
179
|
+
}
|
180
|
+
|
181
|
+
return m;
|
182
|
+
}
|
183
|
+
|