Skip to content

Commit 371110d

Browse files
committed
[tag] v0.5.0, update jdata to 0.8, use 1-time init in test
- use defaultdict in brain2mesh - add pylintrc - some code clean up based on pylint - fix mergemesh shallow copy
1 parent cc7727f commit 371110d

File tree

13 files changed

+720
-117
lines changed

13 files changed

+720
-117
lines changed

.pylintrc

Lines changed: 569 additions & 0 deletions
Large diffs are not rendered by default.

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@ test:
1111
build:
1212
$(PY) -m build
1313

14+
lint:
15+
pylint iso2mesh
16+
1417
report:
1518
@echo '====== all imported functions ======'
1619
@grep '^\s*[a-z]*,' iso2mesh/__init__.py | sed -e 's/^\s*//g' -e 's/,//g' | sort | uniq -c
1720
@echo '====== all tested functions ======'
1821
@grep 'def\s*test' test/run_test.py | sed -e 's/\s*def test_//g' -e 's/(self)://g' -e 's/_.*//g' | sort | uniq -c
1922

2023
.DEFAULT_GOAL=all
21-
.PHONY: all pretty test report
24+
.PHONY: all pretty test report lint

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
* **Copyright**: (C) Qianqian Fang (2024-2025) <q.fang at neu.edu>
66
* **License**: GNU Public License V3 or later
7-
* **Version**: 0.4.2
7+
* **Version**: 0.5.0
88
* **URL**: [https://pypi.org/project/iso2mesh/](https://pypi.org/project/iso2mesh/)
99
* **Homepage**: [https://iso2mesh.sf.net](https://iso2mesh.sf.net)
1010
* **Github**: [https://github.com/NeuroJSON/pyiso2mesh](https://github.com/NeuroJSON/pyiso2mesh)
@@ -225,25 +225,25 @@ tracked in https://github.com/NeuroJSON/pyiso2mesh/issues/1
225225
|`meshunitsphere.m` | ✅ tested | |`loadjson.m` | ⭕️ tested |
226226
|`meshacylinder.m` | ✅ tested | |`savejd.m` | ⭕️ tested |
227227
|`meshgrid5.m` | ✅ tested | |`loadjd.m` | ⭕️ tested |
228-
|`meshgrid6.m` | ✅ tested | | ⭕️ `loadmsgpack.m` | ⭕️ tested |
229-
|`latticegrid.m` | ✅ tested | | ⭕️ `savemsgpack.m` | ⭕️ tested |
228+
|`meshgrid6.m` | ✅ tested | | `loadmsgpack.m` | ⭕️ tested |
229+
|`latticegrid.m` | ✅ tested | | `savemsgpack.m` | ⭕️ tested |
230230
|`extrudecurve.m` | ⭕️ tested | |`savebj.m` | ⭕️ tested |
231231
|`meshcylinders.m` | ✅ tested | |`loadbj.m` | ⭕️ tested |
232232
| > Mesh decomposition and query| | | ⭕️ `savemphtxt.m` | ⭕️ tested |
233-
|`finddisconnsurf.m` | ✅ tested | | ⭕️ `savetetgenele.m` | ⭕️ tested |
234-
|`surfedge.m` | ✅ tested | | ⭕️ `savetetgennode.m` | ⭕️ tested |
233+
|`finddisconnsurf.m` | ✅ tested | | `savetetgenele.m` | ⭕️ tested |
234+
|`surfedge.m` | ✅ tested | | `savetetgennode.m` | ⭕️ tested |
235235
|`volface.m` | ✅ tested | | ⭕️ `saveabaqus.m` | ⭕️ tested |
236236
|`extractloops.m` | ✅ tested | | ⭕️ `savenirfast.m` | ⭕️ tested |
237237
|`meshconn.m` | ✅ tested | | ⭕️ `readnirfast.m` | ⭕️ tested |
238238
|`meshcentroid.m` | ✅ tested | |`loadnifti.m` | ⭕️ tested |
239239
|`nodevolume.m` | ✅ tested | | ⭕️ `readmptiff.m` | ⭕️ tested |
240-
|`elemvolume.m` | ✅ tested | | ⭕️ `loadjsnirf.m` | ⭕️ tested |
241-
|`neighborelem.m` | ✅ tested | | ⭕️ `savejsnirf.m` | ⭕️ tested |
242-
|`layersurf.m` | ⭕️ tested | | ⭕️ `loadsnirf.m` | ⭕️ tested |
243-
|`faceneighbors.m` | ✅ tested | | ⭕️ `savesnirf.m` | ⭕️ tested |
240+
|`elemvolume.m` | ✅ tested | | `loadjsnirf.m` | ⭕️ tested |
241+
|`neighborelem.m` | ✅ tested | | `savejsnirf.m` | ⭕️ tested |
242+
|`layersurf.m` | ⭕️ tested | | `loadsnirf.m` | ⭕️ tested |
243+
|`faceneighbors.m` | ✅ tested | | `savesnirf.m` | ⭕️ tested |
244244
|`edgeneighbors.m` | ✅ tested | | ⭕️ `readobjmesh.m` | ⭕️ tested |
245245
|`maxsurf.m` | ⭕️ tested | | ⭕️ `loadjmesh.m` | ⭕️ tested |
246-
|`flatsegment.m` | ⭕️ tested | | ⭕️ `readobjmesh.m` | ⭕️ tested |
246+
|`flatsegment.m` | ⭕️ tested | | ⭕️ `savejmesh.m` | ⭕️ tested |
247247
|`orderloopedge.m` | ⭕️ tested | | > Volumetric image pre-processing | |
248248
|`mesheuler.m` | ✅ tested | |`volgrow.m` | ✅ tested |
249249
|`bbxflatsegment.m` | ⭕️ tested | |`volshrink.m` | ✅ tested |
@@ -274,8 +274,8 @@ tracked in https://github.com/NeuroJSON/pyiso2mesh/issues/1
274274
|`getintersecttri.m` | ⭕️ tested | | ⭕️ `isoctavemesh.m` | ⭕️ tested |
275275
|`delendelem.m` | ⭕️ tested | | ⭕️ `getvarfrom.m` | ⭕️ tested |
276276
|`surfreorient.m` | ✅ tested | |`raytrace.m` | ✅ tested |
277-
| > Mesh registration | | | ⭕️ `linextriangle.m` | ⭕️ tested |
278-
|`proj2mesh.m` | ⭕️ tested | | ⭕️ `getplanefrom3pt.m` | ⭕️ tested |
277+
| > Mesh registration | | | `linextriangle.m` | ⭕️ tested |
278+
|`proj2mesh.m` | ⭕️ tested | | `getplanefrom3pt.m` | ⭕️ tested |
279279
|`dist2surf.m` | ⭕️ tested | |`getexeext.m` | ✅ tested |
280280
|`regpt2surf.m` | ⭕️ tested | |`fallbackexeext.m` | ✅ tested |
281281
|`affinemap.m` | ⭕️ tested | | ⭕️ `iso2meshver.m` | ⭕️ tested |
@@ -289,8 +289,8 @@ tracked in https://github.com/NeuroJSON/pyiso2mesh/issues/1
289289
| > Mesh resampling and optimization| | | ⭕️ `orthdisk.m` | ⭕️ tested |
290290
|`meshresample.m` | ✅ tested | | ⭕️ `nestbracket2dim.m` | ⭕️ tested |
291291
|`remeshsurf.m` | ✅ tested | |`memmapstream.m` | ⭕️ tested |
292-
|`smoothsurf.m` | ✅ tested | | ⭕️ `aos2soa.m` | ⭕️ tested |
293-
|`sortmesh.m` | ⭕️ tested | | ⭕️ `soa2aos.m` | ⭕️ tested |
292+
|`smoothsurf.m` | ✅ tested | | `aos2soa.m` | ⭕️ tested |
293+
|`sortmesh.m` | ⭕️ tested | | `soa2aos.m` | ⭕️ tested |
294294
|`mergemesh.m` | ✅ tested | | > Brain2mesh toolbox | |
295295
|`meshrefine.m` | ✅ tested | |`brain2mesh.m` | ⭕️ tested |
296296
|`mergesurf.m` | ⭕️ tested | |`brain1020.m` | ⭕️ tested |

iso2mesh/__init__.py

Lines changed: 86 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,74 @@
11
"""pyiso2mesh - Iso2Mesh for Python
22
"""
33

4+
from jdata import (
5+
loadjson,
6+
savejson,
7+
loadbj,
8+
savebj,
9+
loadjd,
10+
savejd,
11+
jdataencode,
12+
jdatadecode,
13+
loadurl,
14+
jsoncache,
15+
jdlink,
16+
jsonpath,
17+
nii2jnii,
18+
jnii2nii,
19+
loadnifti,
20+
loadjnifti,
21+
savenifti,
22+
savejnifti,
23+
nifticreate,
24+
jnifticreate,
25+
memmapstream,
26+
niiheader2jnii,
27+
niicodemap,
28+
niiformat,
29+
savebnii,
30+
savejnii,
31+
loadh5,
32+
saveh5,
33+
regrouph5,
34+
aos2soa,
35+
soa2aos,
36+
jsnirfcreate,
37+
snirfcreate,
38+
loadjsnirf,
39+
loadsnirf,
40+
savejsnirf,
41+
savesnirf,
42+
snirfdecode,
43+
zlibencode,
44+
zlibdecode,
45+
gzipencode,
46+
gzipdecode,
47+
lzmaencode,
48+
lzmadecode,
49+
lz4encode,
50+
lz4decode,
51+
base64encode,
52+
base64decode,
53+
neuroj,
54+
neurojgui,
55+
load_csv_tsv,
56+
loadcsv,
57+
loadtsv,
58+
save_csv_tsv,
59+
loadmsgpack,
60+
savemsgpack,
61+
loadubjson,
62+
saveubjson,
63+
)
64+
465
from .geometry import (
566
meshgrid5,
667
meshgrid6,
768
latticegrid,
869
meshabox,
970
meshacylinder,
1071
meshcylinders,
11-
meshcylinders,
1272
meshanellip,
1373
meshunitsphere,
1474
meshasphere,
@@ -122,7 +182,6 @@
122182
removeisolatedsurf,
123183
surfaceclean,
124184
removeedgefaces,
125-
getintersecttri,
126185
delendelem,
127186
surfreorient,
128187
sortmesh,
@@ -178,9 +237,7 @@
178237
thinbinvol,
179238
)
180239

181-
from jdata import *
182-
183-
__version__ = "0.4.2"
240+
__version__ = "0.5.0"
184241
__all__ = [
185242
"advancefront",
186243
"barycentricgrid",
@@ -205,7 +262,6 @@
205262
"flatsegment",
206263
"getexeext",
207264
"getintersecttri",
208-
"getintersecttri",
209265
"highordertet",
210266
"innersurf",
211267
"insurface",
@@ -357,5 +413,29 @@
357413
"jdlink",
358414
"jsoncache",
359415
"loadurl",
416+
"regrouph5",
417+
"aos2soa",
418+
"soa2aos",
419+
"jsnirfcreate",
420+
"snirfcreate",
421+
"loadjsnirf",
422+
"loadsnirf",
423+
"savejsnirf",
424+
"savesnirf",
425+
"snirfdecode",
426+
"neuroj",
427+
"neurojgui",
428+
"load_csv_tsv",
429+
"loadcsv",
430+
"loadtsv",
431+
"save_csv_tsv",
432+
"loadmsgpack",
433+
"savemsgpack",
434+
"loadubjson",
435+
"saveubjson",
436+
"savebnii",
437+
"savejnii",
438+
"loadh5",
439+
"saveh5",
360440
]
361441
__license__ = """GNU General Public License v3 and later"""

iso2mesh/brain2mesh.py

Lines changed: 9 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
##====================================================================================
1717

1818
import numpy as np
19-
import sys
2019
from iso2mesh.core import v2s, s2m
2120
from iso2mesh.modify import (
2221
removeisolatednode,
@@ -42,9 +41,8 @@
4241
from iso2mesh.plot import plotmesh
4342

4443
from typing import Tuple, Dict, Union, Optional, List
45-
import matplotlib.pyplot as plt
4644
import warnings
47-
from collections import OrderedDict
45+
from collections import defaultdict
4846

4947
##====================================================================================
5048
## implementations
@@ -130,8 +128,10 @@ def brain2mesh(seg, **cfg):
130128
return
131129

132130
# Default density and adaptiveness parameters
133-
density = {"wm": 2, "gm": 2, "csf": 5, "skull": 4, "scalp": 8}
134-
adaptiveness = {"wm": 1, "gm": 1, "csf": 1, "skull": 1, "scalp": 1}
131+
density = defaultdict(
132+
lambda: 20, {"wm": 2, "gm": 2, "csf": 5, "skull": 4, "scalp": 8}
133+
)
134+
adaptiveness = defaultdict(lambda: 1)
135135

136136
# Parse configuration
137137
radbound = cfg.get("radbound", density)
@@ -147,7 +147,7 @@ def brain2mesh(seg, **cfg):
147147
surfonly = cfg.get("surfonly", 0)
148148
marginsize = cfg.get("marginsize", 4)
149149

150-
segname = list(density.keys())
150+
segname = list(radbound.keys())
151151

152152
# Convert seg to dict format if needed
153153
if isinstance(seg, dict):
@@ -1387,7 +1387,9 @@ def brain1020(
13871387
# At this point, initpoints contains {nz, iz, lpa, rpa, cz0}
13881388
# Plot the head mesh
13891389
if showplot:
1390-
hh = plotmesh(node, face, alpha=0, color="wheat", linewidth=0.1)
1390+
hh = plotmesh(
1391+
node, face, alpha=0.5, color="wheat", edgecolor="k", linewidth=0.1
1392+
)
13911393
ax = hh["ax"][0]
13921394
ax.set_xlabel("X")
13931395
ax.set_ylabel("Y")
@@ -1915,37 +1917,3 @@ def tpm2label(
19151917
return vol, names
19161918
else:
19171919
return vol
1918-
1919-
1920-
def orderfields_python(struct_dict, order: List[str]):
1921-
"""
1922-
Python equivalent of MATLAB's orderfields function
1923-
1924-
Reorders dictionary fields according to specified order.
1925-
1926-
Parameters:
1927-
-----------
1928-
struct_dict : dict
1929-
Dictionary to reorder
1930-
order : list
1931-
List specifying the desired field order
1932-
1933-
Returns:
1934-
--------
1935-
ordered_dict : dict
1936-
Dictionary with fields reordered according to order
1937-
"""
1938-
1939-
ordered_dict = OrderedDict()
1940-
1941-
# First add fields in the specified order
1942-
for field_name in order:
1943-
if field_name in struct_dict:
1944-
ordered_dict[field_name] = struct_dict[field_name]
1945-
1946-
# Then add any remaining fields that weren't in the order list
1947-
for field_name, field_value in struct_dict.items():
1948-
if field_name not in ordered_dict:
1949-
ordered_dict[field_name] = field_value
1950-
1951-
return ordered_dict

iso2mesh/core.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@
3030
## dependent libraries
3131
##====================================================================================
3232

33-
import numpy as np
3433
import os
3534
import re
3635
import sys
3736
import subprocess
37+
import numpy as np
3838
from iso2mesh.trait import (
3939
surfinterior,
4040
surfseeds,
@@ -48,7 +48,14 @@
4848
maxsurf,
4949
ismember_rows,
5050
)
51-
from iso2mesh.utils import *
51+
from iso2mesh.utils import (
52+
getexeext,
53+
deletemeshfile,
54+
mwpath,
55+
mcpath,
56+
fallbackexeext,
57+
jsonopt,
58+
)
5259
from iso2mesh.io import (
5360
saveoff,
5461
readoff,

iso2mesh/geometry.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,10 @@
2525
##====================================================================================
2626

2727
import numpy as np
28-
import sys
2928
from itertools import permutations, combinations
3029
from iso2mesh.core import surf2mesh, vol2restrictedtri
3130
from iso2mesh.trait import meshreorient, volface, surfedge, nodesurfnorm
32-
from iso2mesh.utils import *
31+
from iso2mesh.utils import rotatevec3d
3332
from iso2mesh.modify import removeisolatednode, meshcheckrepair
3433

3534
# _________________________________________________________________________________________________________

iso2mesh/line.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def polylinelen(node, p0=None, p1=None, pmid=None):
195195
p1 -= 1
196196
pmid -= 1
197197

198-
if p0 < pmid and pmid < p1:
198+
if p0 < pmid < p1:
199199
inputreversed = 0
200200
node = node[range(p0, p1 + 1), :]
201201
elif p0 < pmid and p1 < pmid:
@@ -206,7 +206,7 @@ def polylinelen(node, p0=None, p1=None, pmid=None):
206206
node = node[idx_range, :]
207207
if not inputreversed:
208208
node = np.flipud(node)
209-
elif p0 > pmid and pmid > p1:
209+
elif p0 > pmid > p1:
210210
inputreversed = 1
211211
node = node[range(p0, p1 - 1, -1), :]
212212
elif p0 > pmid and p1 > pmid:

0 commit comments

Comments
 (0)