Commit 0d024334 authored by ihuszar's avatar ihuszar
Browse files

Updated env & configs, removed pprint, fixed tests.

parent 0c5e90bf
......@@ -12,13 +12,13 @@
"logfile": null,
"paramlogfile": null,
"verbose": false,
"outputdir": "/home/inhuszar/Desktop/example/stage1",
"outputdir": "/Users/inhuszar/temp/stage1",
"stages": ["rotation", "rigid", "affine", "nonlinear"],
"warnings": false,
"isotropic": true
},
"histology": {
"file": "/home/inhuszar/Desktop/example/1_histology/histology.tif",
"file": "/Users/inhuszar/temp/1_histology/histology.tif",
"storage": "mem",
"dtype": "f4",
"resolution": 0.008,
......@@ -36,7 +36,7 @@
"snapshot": true
},
"block": {
"file": "/home/inhuszar/Desktop/example/2_tissue_block/tissue_block.tif",
"file": "/Users/inhuszar/temp/2_tissue_block/tissue_block.tif",
"storage": "mem",
"dtype": "f4",
"resolution": 0.05,
......@@ -115,7 +115,7 @@
"smoothing": [0, 0, 0],
"sigma": 1,
"truncate": 1.5,
"regweight": 0.3,
"regweight": 0.6,
"maxiter": [20, 20, 20, 20, 5],
"xtol_abs": 0.1,
"xtol_rel": 0.01,
......
......@@ -9,15 +9,15 @@
"direction": "b2s",
"system": "linux",
"loglevel": "debug",
"logfile": "/home/inhuszar/Desktop/example/stage2/logfile.log",
"paramlogfile": "/home/inhuszar/Desktop/example/stage2/paramlog.log",
"logfile": "/Users/inhuszar/temp/stage2/logfile.log",
"paramlogfile": "/Users/inhuszar/temp/stage2/paramlog.log",
"verbose": false,
"outputdir": "/home/inhuszar/Desktop/example/stage2",
"outputdir": "/Users/inhuszar/temp/stage2",
"stages": ["rigid", "affine", "nonlinear"],
"warnings": false
},
"block": {
"file": "/home/inhuszar/Desktop/example/2_tissue_block/tissue_block.tif",
"file": "/Users/inhuszar/temp/2_tissue_block/tissue_block.tif",
"storage": "mem",
"dtype": "f4",
"resolution": 0.05,
......@@ -35,7 +35,7 @@
"snapshot": true
},
"slice": {
"file": "/home/inhuszar/Desktop/example/3_brain_slice/0.tif",
"file": "/Users/inhuszar/temp/3_brain_slice/0.tif",
"storage": "mem",
"dtype": "f4",
"resolution": 0.05,
......@@ -85,7 +85,7 @@
"ub": null
}
},
"sites": "/home/inhuszar/Desktop/example/3_brain_slice/sites/sites.txt",
"sites": "/Users/inhuszar/temp/3_brain_slice/sites/sites.txt",
"jiggle": {
"scale": 0.1,
"xrange": [10.0, 10.0],
......
......@@ -9,16 +9,16 @@
"system": "linux",
"loglevel": "debug",
"logfile": null,
"paramlogfile": "/home/inhuszar/Desktop/example/stage3/paramlogs.log",
"paramlogfile": "/Users/inhuszar/temp/stage3/paramlogs.log",
"verbose": false,
"outputdir": "/home/inhuszar/Desktop/example/stage3",
"outputdir": "/Users/inhuszar/temp/stage3",
"stages": [1, 2, 3, 4, 5, 3, 4, 5],
"isotropic": true,
"cost": "MIND",
"warnings": false
},
"slice": {
"file": "/home/inhuszar/Desktop/example/3_brain_slice/0.tif",
"file": "/Users/inhuszar/temp/3_brain_slice/0.tif",
"storage": "mem",
"dtype": "f4",
"resolution": 0.05,
......@@ -36,7 +36,7 @@
"snapshot": true
},
"volume": {
"file": "/home/inhuszar/Desktop/example/4_mri/mri.nii.gz",
"file": "/Users/inhuszar/temp/4_mri/mri.nii.gz",
"storage": "mem",
"dtype": "f4",
"resolution": null,
......@@ -81,8 +81,8 @@
"offset": 0,
"thickness": 10,
"n_positions": 5,
"range": [0, 0, 0],
"n_orientations": [1, 1, 1]
"range": [0, 10, 10],
"n_orientations": [1, 3, 3]
},
"iterations": 1,
"n_cpu": -1,
......@@ -154,10 +154,10 @@
},
"optsize": 4,
"vectorder": "xy",
"slice_scaling": [2, 1],
"slice_smoothing": [0, 0],
"volume_scaling": [1, 1],
"volume_smoothing": [0, 0],
"slice_scaling": [1],
"slice_smoothing": [0],
"volume_scaling": [1],
"volume_smoothing": [0],
"lower_dxy": 5.0,
"upper_dxy": 5.0,
"regweight": 0,
......@@ -189,17 +189,17 @@
},
"optsize": 4,
"vectorder": "xyz",
"slice_scaling": [2, 1],
"slice_smoothing": [0, 0],
"volume_scaling": [1, 1],
"volume_smoothing": [0, 0],
"lower_dxy": 5.0,
"lower_dz": 5.0,
"upper_dxy": 5.0,
"upper_dz": 5.0,
"slice_scaling": [1],
"slice_smoothing": [0],
"volume_scaling": [1],
"volume_smoothing": [0],
"lower_dxy": 3.0,
"lower_dz": 3.0,
"upper_dxy": 3.0,
"upper_dz": 3.0,
"regweight": 0,
"model": "multiquadric",
"opt_step": 0.3,
"opt_step": 0.1,
"xtol_abs": 0.01
},
"stage_5": {
......
......@@ -30,9 +30,6 @@ User-adjustable constants must not be stored in this file. Please use the
# DEFINITIONS
# Universal data type for floating-point results (and intermediates)
DEFAULT_FLOAT_TYPE = "<f4"
# Storage modes (Domain, TField, TImage)
MEM = "mem"
HDD = "hdd"
......
......@@ -378,9 +378,13 @@ def create(fname, dump, overwrite=False, compressed=False):
try:
js_header = json.dumps(header).encode()
except TypeError:
from pprint import pprint
pprint(header)
raise
from pygments import highlight, lexers, formatters
formatted_json = json.dumps(header, indent=4)
colorful_json = highlight(formatted_json.encode("UTF-8"),
lexers.JsonLexer(),
formatters.TerminalFormatter())
print(colorful_json)
f.write(int2bytes(len(js_header), UINT64)) # main header size
f.write(js_header)
......
......@@ -26,6 +26,7 @@ from numbers import Number, Integral
# TIRL IMPORTS
import tirl.utils as tu
import tirl.settings as ts
from tirl.domain import Domain
from tirl.tfield import TField
from tirl.interpolators.scipyinterpolator import ScipyInterpolator
......@@ -100,7 +101,7 @@ class TxDisplacementField(TxNonLinear):
f = TField.fromarray(
field.data, tensor_axes=field.taxes, copy=False,
domain=domain, order=TENSOR_MAJOR,
dtype=DEFAULT_FLOAT_TYPE, interpolator=interpolator,
dtype=ts.DEFAULT_FLOAT_TYPE, interpolator=interpolator,
name=None, storage=field.storage, **field.kwargs)
# Input is NDArray: displacement dimension must be the first axis
......@@ -108,7 +109,7 @@ class TxDisplacementField(TxNonLinear):
f = TField.fromarray(
np.asanyarray(field), tensor_axes=(0,), copy=False,
domain=domain, order=TENSOR_MAJOR,
dtype=DEFAULT_FLOAT_TYPE, interpolator=interpolator,
dtype=ts.DEFAULT_FLOAT_TYPE, interpolator=interpolator,
name=None, storage=MEM)
else:
......@@ -289,7 +290,7 @@ class TxDisplacementField(TxNonLinear):
# Create output TField with relative vectors on self domain
relative_field = TField(
self.domain, tensor_shape=(self.vectdim,), order=TENSOR_MAJOR,
dtype=DEFAULT_FLOAT_TYPE, buffer=v.T.ravel(), offset=0,
dtype=ts.DEFAULT_FLOAT_TYPE, buffer=v.T.ravel(), offset=0,
interpolator=self.interpolator, name=name, storage=MEM)
return relative_field
......@@ -328,7 +329,7 @@ class TxDisplacementField(TxNonLinear):
# Create output TField with relative vectors on self domain
relative_field = TField(
self.domain, tensor_shape=(self.vectdim,), order=TENSOR_MAJOR,
dtype=DEFAULT_FLOAT_TYPE, buffer=v.T.ravel(), offset=0,
dtype=ts.DEFAULT_FLOAT_TYPE, buffer=v.T.ravel(), offset=0,
interpolator=self.interpolator, name=name, storage=MEM)
return relative_field
......@@ -358,7 +359,7 @@ class TxDisplacementField(TxNonLinear):
name = f"{field.name}_abs"
return TField(
self.domain, tensor_shape=(self.vectdim,),
order=TENSOR_MAJOR, dtype=DEFAULT_FLOAT_TYPE,
order=TENSOR_MAJOR, dtype=ts.DEFAULT_FLOAT_TYPE,
buffer=v.T.ravel(), offset=0,
interpolator=self.interpolator.copy(),
name=name, storage=MEM)
......@@ -372,7 +373,7 @@ class TxDisplacementField(TxNonLinear):
name = f"{field.name}_abs"
absolute_field = TField(
field.domain, tensor_shape=field.tshape,
order=TENSOR_MAJOR, dtype=DEFAULT_FLOAT_TYPE,
order=TENSOR_MAJOR, dtype=ts.DEFAULT_FLOAT_TYPE,
buffer=v.T.ravel(), offset=0,
interpolator=field.interpolator.copy(), name=name,
storage=field.storage, **field.kwargs)
......@@ -498,10 +499,10 @@ class TxDisplacementField(TxNonLinear):
if self.mode == NL_ABS:
parameters = self.abs2abs(field).data.ravel()
return parameters.astype(DEFAULT_FLOAT_TYPE)
return parameters.astype(ts.DEFAULT_FLOAT_TYPE)
else:
parameters = self.abs2rel(field).data.ravel()
return parameters.astype(DEFAULT_FLOAT_TYPE)
return parameters.astype(ts.DEFAULT_FLOAT_TYPE)
def params2field(self, parameters, domain=None, **kwargs):
"""
......@@ -515,7 +516,7 @@ class TxDisplacementField(TxNonLinear):
domain = self.domain
elif not isinstance(domain, Domain):
raise TypeError(f"Invalid domain specification: {domain}")
parameters = np.asanyarray(parameters, dtype=DEFAULT_FLOAT_TYPE)
parameters = np.asanyarray(parameters, dtype=ts.DEFAULT_FLOAT_TYPE)
# # If the mode is relative, the vectors must be converted to absolute
# # displacements first.
......@@ -529,7 +530,7 @@ class TxDisplacementField(TxNonLinear):
# alternative field.
alternative_field = TField(
extent=self.domain, tensor_shape=(self.vectdim,),
order=TENSOR_MAJOR, dtype=DEFAULT_FLOAT_TYPE,
order=TENSOR_MAJOR, dtype=ts.DEFAULT_FLOAT_TYPE,
buffer=parameters.ravel(), offset=0,
interpolator=self.interpolator.copy(), name=None, storage=MEM)
......@@ -640,7 +641,7 @@ class TxDisplacementField(TxNonLinear):
field = TField(
domain, tensor_shape=(len(vectorder),), order=TENSOR_MAJOR,
dtype=DEFAULT_FLOAT_TYPE, buffer=params.parameters, offset=0,
dtype=ts.DEFAULT_FLOAT_TYPE, buffer=params.parameters, offset=0,
interpolator=interpolator, name=None, storage=MEM)
# Create transformation object
......
......@@ -26,6 +26,7 @@ from scipy.interpolate import Rbf
# TIRL IMPORTS
import tirl.utils as tu
import tirl.settings as ts
from tirl.domain import Domain
from tirl.cmodules.finv import local_affine
from tirl.transformations.nonlinear.displacement import TxDisplacementField
......@@ -198,7 +199,7 @@ class TxRbfDisplacementField(TxDisplacementField):
field = TField(
domain, tensor_shape=(len(vectorder),), order=TENSOR_MAJOR,
dtype=DEFAULT_FLOAT_TYPE, buffer=params.parameters, offset=0,
dtype=ts.DEFAULT_FLOAT_TYPE, buffer=params.parameters, offset=0,
interpolator=interpolator, name=None, storage=MEM)
# Create transformation object
......@@ -352,7 +353,6 @@ class TxRbfDisplacementField(TxDisplacementField):
d = self.vectdim
return np.kron(np.eye(d, d), jac[:, np.newaxis, :])
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~ PRIVATE METHODS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
def _dummy_interpolator(self):
......
......@@ -21,6 +21,7 @@ import numpy as np
import scipy.sparse as sp
import tirl
import tirl.settings as ts
from tirl.chain import Chain
from tirl.tfield import TField
from tirl.timage import TImage
......@@ -35,7 +36,7 @@ from tirl.transformations.nonlinear.displacement import TxDisplacementField
# DEFINITIONS
from tirl.constants import *
EPS = np.finfo(DEFAULT_FLOAT_TYPE).eps
EPS = np.finfo(ts.DEFAULT_FLOAT_TYPE).eps
SKIP_INVERSE = False
......@@ -47,7 +48,7 @@ class TestConstruction(unittest.TestCase):
field[...] = 1
tx = TxDisplacementField(field, mode=NL_ABS)
self.assertIsInstance(tx, TxDisplacementField)
self.assertEqual(tx.parameters.dtype, DEFAULT_FLOAT_TYPE) # despite input
self.assertEqual(tx.parameters.dtype, ts.DEFAULT_FLOAT_TYPE) # despite input
self.assertEqual(tx.mode, NL_ABS)
self.assertTrue(np.allclose(tx.parameters, 1, EPS)) # from input
......@@ -65,7 +66,7 @@ class TestConstruction(unittest.TestCase):
field[...] = 1
tx = TxDisplacementField(field, mode=NL_REL)
self.assertIsInstance(tx, TxDisplacementField)
self.assertEqual(tx.parameters.dtype, DEFAULT_FLOAT_TYPE) # despite input
self.assertEqual(tx.parameters.dtype, ts.DEFAULT_FLOAT_TYPE) # despite input
self.assertEqual(tx.mode, NL_REL)
self.assertTrue(np.all(tx.parameters != field.data.ravel()))
self.assertTrue(np.allclose(tx.parameters, 1, EPS)) # from input
......@@ -84,7 +85,7 @@ class TestConstruction(unittest.TestCase):
field[...] = 0.8
tx = TxDisplacementField(field, mode=NL_ABS)
self.assertIsInstance(tx, TxDisplacementField)
self.assertEqual(tx.parameters.dtype, DEFAULT_FLOAT_TYPE) # despite input
self.assertEqual(tx.parameters.dtype, ts.DEFAULT_FLOAT_TYPE) # despite input
self.assertEqual(tx.mode, NL_ABS)
self.assertTrue(np.allclose(tx.parameters, 0.8, EPS)) # from input
......@@ -94,7 +95,7 @@ class TestConstruction(unittest.TestCase):
field[...] = 2
tx = TxDisplacementField(field, mode=NL_REL)
self.assertIsInstance(tx, TxDisplacementField)
self.assertEqual(tx.parameters.dtype, DEFAULT_FLOAT_TYPE) # despite input
self.assertEqual(tx.parameters.dtype, ts.DEFAULT_FLOAT_TYPE) # despite input
self.assertEqual(tx.mode, NL_REL)
self.assertTrue(np.allclose(tx.parameters, 2, EPS)) # from input
......@@ -102,7 +103,7 @@ class TestConstruction(unittest.TestCase):
arr = 2 * np.ones((2, 200, 300), dtype="<f2")
tx = TxDisplacementField(arr)
self.assertIsInstance(tx, TxDisplacementField)
self.assertEqual(tx.parameters.dtype, DEFAULT_FLOAT_TYPE) # despite input
self.assertEqual(tx.parameters.dtype, ts.DEFAULT_FLOAT_TYPE) # despite input
self.assertTrue(np.allclose(tx.parameters, 2, EPS)) # from input
def test_invalid_construction(self):
......
name: tirlenv
channels:
- conda-forge
- bioconda
- defaults
- https://fsl.fmrib.ox.ac.uk/fsldownloads/fslconda/channel
dependencies:
- attrdict
- cython
- coverage
- dask
- dill
- ghalton=0.6.1
- imageio
- joblib
- mayavi
- matplotlib=3.2.1
- nibabel=2.5.1
- nlopt>=2.6.2
- numba>=0.49.1
- numpy=1.16.5
- nlopt=2.6.2
- numba=0.49.1
- numpy=1.18.5
- openblas
- opencv
- openjpeg
- openslide
- pillow
- openslide-python=1.1.1
- pillow=7.0.0
- pip
- psutil
- pygments
......@@ -34,7 +36,4 @@ dependencies:
- threadpoolctl
- tifffile
- pip:
- ghalton
- imagecodecs
- pprint
- openslide-wrapper
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment