Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
tomotools
Nabu
Commits
aaa5c367
Commit
aaa5c367
authored
Nov 19, 2019
by
Pierre Paleo
Browse files
Modify configuration file. Start estimate_required_memory
parent
1bb75bdf
Changes
7
Hide whitespace changes
Inline
Side-by-side
nabu/cuda/utils.py
View file @
aaa5c367
...
...
@@ -45,6 +45,15 @@ def count_cuda_devices():
def
get_gpu_memory
(
device_id
):
"""
Return the total memory (in GigaBytes) of a device.
"""
cuda
.
init
()
return
cuda
.
Device
(
device_id
).
total_memory
()
/
1e9
"""
pycuda/driver.py
np.complex64: SIGNED_INT32, num_channels = 2
...
...
nabu/resources/cli/reconstruct.py
View file @
aaa5c367
...
...
@@ -12,13 +12,20 @@ The user needs to provide:
import
os
from
.utils
import
parse_params_values
from
.cli_configs
import
ReconstructConfig
from
.validate
import
validate_conffile_noexcept
def
parse_args
():
def
main
():
args
=
parse_params_values
(
ReconstructConfig
,
parser_description
=
"Perform a tomographic reconstruction."
)
validator
=
validate_conffile_noexcept
(
args
[
"input_file"
],
print_ok
=
False
)
nabu_config
=
validator
.
nabu_config
dataset_structure
=
validator
.
dataset_config
if
__name__
==
"__main__"
:
parse_args
()
main
()
nabu/resources/cli/validate.py
View file @
aaa5c367
...
...
@@ -25,7 +25,7 @@ def get_config(fname):
return
config
def
nabu_
validate
(
fname
):
def
validate
_conffile
(
fname
):
# Read the configuration file and extract the key/values
config
=
get_config
(
fname
)
...
...
@@ -42,6 +42,19 @@ def nabu_validate(fname):
# Remove unused radios (modifies dataset_structure)
validator
.
remove_unused_radios
()
return
validator
def
validate_conffile_noexcept
(
fname
,
print_ok
=
True
):
try
:
validator
=
validate_conffile
(
fname
)
except
Exception
as
exc
:
print
(
"Error while checking %s:"
%
fname
)
print
(
exc
)
exit
(
-
1
)
if
print_ok
:
print
(
"Configuration file %s is valid"
%
fname
)
return
validator
def
main
():
...
...
@@ -50,13 +63,7 @@ def main():
parser_description
=
"Validate a Nabu configuration file."
)
fname
=
args
[
"input_file"
]
try
:
nabu_validate
(
fname
)
except
Exception
as
exc
:
print
(
"Error while checking %s:"
%
fname
)
print
(
exc
)
exit
(
-
1
)
print
(
"Configuration file %s is valid"
%
fname
)
validate_conffile_noexcept
(
fname
)
if
__name__
==
"__main__"
:
main
()
nabu/resources/computations.py
0 → 100644
View file @
aaa5c367
#!/usr/bin/env python
"""
computations.py: determine computational needs, chunking method to be used, etc.
"""
def
get_chunk_size
(
nabu_config
,
dataset
,
available_mem
):
"""
Return the maximum chunk size that can be used with a given amount of memory.
"""
def
estimate_required_memory
(
nabu_config
,
dataset
,
chunk_size
=
None
):
"""
Estimate the memory (RAM) needed for a reconstruction.
Parameters
----------
nabu_config: dict
Dictionary describing the nabu configuration. Usually extracted from
the configuration file.
dataset: nabu.resources.dataset_analyzer.DatasetAnalyzer
Dataset structure.
"""
Ny
,
Nx
=
dataset
.
radio_dims
Na
=
dataset
.
n_angles
if
chunk_size
is
not
None
:
Ny
=
chunk_size
if
nabu_config
[
"dataset"
][
"binning"
]:
Nx
=
Nx
//
nabu_config
[
"dataset"
][
"binning"
]
if
nabu_config
[
"dataset"
][
"binning_z"
]:
Ny
=
Ny
//
nabu_config
[
"dataset"
][
"binning_z"
]
if
nabu_config
[
"dataset"
][
"projections_subsampling"
]:
Na
=
Na
//
nabu_config
[
"dataset"
][
"projections_subsampling"
]
data_volume_size
=
Nx
*
Ny
*
Na
*
2
# assuming uint16
rec_config
=
nabu_config
[
"reconstruction"
]
reconstructed_volume_size
=
0
if
rec_config
[
"method"
]
!=
"none"
:
Nx_rec
=
rec_config
[
"end_x"
]
-
rec_config
[
"start_x"
]
+
1
Ny_rec
=
rec_config
[
"end_y"
]
-
rec_config
[
"start_y"
]
+
1
Nz_rec
=
rec_config
[
"end_z"
]
-
rec_config
[
"start_z"
]
+
1
reconstructed_volume_size
=
Nx_rec
*
Ny_rec
*
Nz_rec
*
4
# float32
nabu/resources/nabu_config.py
View file @
aaa5c367
...
...
@@ -46,6 +46,24 @@ nabu_config = {
"hst_key"
:
"background_file"
,
"validator"
:
optional_file_name_validator
,
},
"binning"
:
{
"default"
:
"1"
,
"help"
:
"Binning factor.
\n
The final slices dimensions will be divided by 'slices_binning'"
,
"hst_key"
:
None
,
"validator"
:
binning_validator
,
},
"binning_z"
:
{
"default"
:
"1"
,
"help"
:
"Whether to also bin in the 'z' direction, resulting in a lesser number of reconstructed slices"
,
"hst_key"
:
None
,
"validator"
:
binning_validator
,
},
"projections_subsampling"
:
{
"default"
:
"1"
,
"help"
:
"Projections subsampling factor: take one projection out of 'projection_subsampling'"
,
"hst_key"
:
"file_interval"
,
"validator"
:
binning_validator
,
},
},
"preproc"
:
{
"flatfield_enabled"
:
{
...
...
@@ -162,7 +180,7 @@ nabu_config = {
},
"method"
:
{
"default"
:
"FBP"
,
"help"
:
"Reconstruction method"
,
"help"
:
"Reconstruction method
. Possible values: FBP, none. If value is 'none', no reconstruction will be done.
"
,
"hst_key"
:
None
,
"validator"
:
reconstruction_method_validator
,
},
...
...
@@ -220,24 +238,6 @@ nabu_config = {
"hst_key"
:
None
,
"validator"
:
integer_validator
,
},
"slices_binning"
:
{
"default"
:
"1"
,
"help"
:
"Binning factor in the case where the reconstructed slices are to be binned.
\n
The slices dimensions will be divided by 'slices_binning'"
,
"hst_key"
:
None
,
"validator"
:
binning_validator
,
},
"slices_binning_z"
:
{
"default"
:
"1"
,
"help"
:
"Whether to also bin in the 'z' direction, resulting in a lesser number of reconstructed slices"
,
"hst_key"
:
None
,
"validator"
:
binning_validator
,
},
"projections_subsampling"
:
{
"default"
:
"1"
,
"help"
:
"Projections subsampling factor: take one projection out of 'projection_subsampling'"
,
"hst_key"
:
"file_interval"
,
"validator"
:
binning_validator
,
},
"iterations"
:
{
"default"
:
"200"
,
"help"
:
"
\n
Parameters for iterative algorithms
\n
------------------------------------
\n
Number of iterations"
,
...
...
nabu/resources/validators.py
View file @
aaa5c367
...
...
@@ -203,7 +203,7 @@ def padding_mode_validator(val):
@
validator
def
reconstruction_method_validator
(
val
):
avail_rec_methods
=
[
"fbp"
,
"
dfi"
]
avail_rec_methods
=
[
"fbp"
,
"
none"
]
# dfi, iterative...
return
name_range_checker
(
val
,
avail_rec_methods
,
"reconstruction method"
)
@
validator
...
...
setup.py
View file @
aaa5c367
...
...
@@ -109,6 +109,7 @@ def setup_package():
"nabu-test=nabu.tests:nabu_test"
,
"nabu-config=nabu.resources.cli.bootstrap:bootstrap"
,
"nabu-validate=nabu.resources.cli.validate:main"
,
"nabu-reconstruct=nabu.resources.cli.reconstruct:main"
,
],
},
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment