Commit 8271658b authored by Pierre Paleo's avatar Pierre Paleo
Browse files

Bugfixes in validators

parent 53823c63
......@@ -32,6 +32,7 @@ class NabuConfigParser(object):
self.file_content = file_content.split(linesep)
def get_dict(self):
# Is there an officially supported way to do this ?
self.conf_dict = self.parser._sections
def __str__(self):
......
......@@ -14,15 +14,11 @@ from .utils import parse_params_values
from .cli_configs import ReconstructConfig
def parse_args():
args = parse_params_values(
ReconstructConfig,
parser_description="Perform a tomographic reconstruction."
)
if __name__ == "__main__":
parse_args()
......@@ -8,6 +8,46 @@ This tool will inspect each entry of the configuration file and ensure that
- Each value of the configuration file is correct (eg. invalid values)
"""
import os
from .utils import parse_params_values
from .cli_configs import ValidateConfig
from ...io.config import NabuConfigParser, validate_nabu_config
from ..dataset_analyzer import analyze_dataset
from ..dataset_validator import NabuValidator
def get_config(fname):
if not(os.path.isfile(fname)):
print("Error: file %s not found" % fname)
exit(-1)
parser = NabuConfigParser(fname)
config = parser.conf_dict
return config
def nabu_validate(fname):
# Read the configuration file and extract the key/values
config = get_config(fname)
# Validation step 1: check the config file alone
config = validate_nabu_config(config)
# Browse the dataset
dataset_structure = analyze_dataset(config["dataset"]["location"])
# Validation step 2: check the consistency of dataset and config file
validator = NabuValidator(config, dataset_structure)
validator.perform_all_checks()
# Remove unused radios (modifies dataset_structure)
validator.remove_unused_radios()
if __name__ == "__main__":
args = parse_params_values(
ValidateConfig,
parser_description="Validate a Nabu configuration file."
)
fname = args["input_file"]
nabu_validate(fname)
print("Configuration file %s is valid" % fname)
......@@ -119,3 +119,19 @@ class HDF5DatasetAnalyzer(DatasetAnalyzer):
if not(os.path.isfile(location)):
raise ValueError("%s is not a file" % location)
self._init_dataset_scan("edf")
def analyze_dataset(dataset_path):
if not(os.path.isdir(dataset_path)):
if not(os.path.isfile(dataset_path)):
raise ValueError("Error: %s no such file or directory")
if os.path.splitext(dataset_path)[-1] not in [".hdf5", ".h5"]:
raise ValueError("Error: expected a HDF5 file")
dataset_analyzer_class = HDF5DatasetAnalyzer
else: # directory -> assuming EDF
dataset_analyzer_class = EDFDatasetAnalyzer
dataset_structure = dataset_analyzer_class(dataset_path)
return dataset_structure
......@@ -22,6 +22,7 @@ class NabuValidator(object):
def __init__(self, nabu_config, dataset_config):
self.nabu_config = nabu_config
self.dataset_config = dataset_config
self.check_not_empty() # has to be done first
self.convert_negative_indices()
......@@ -65,6 +66,11 @@ class NabuValidator(object):
self.nabu_config[section][key], upper_bound
)
def check_not_empty(self):
assert len(self.dataset_config.projections) > 0, "Dataset seems to be empty (no projections)"
assert self.dataset_config.n_angles is not None, "Could not determine the number of projections. Please check the .info file"
for dim_name, n in zip(["dim_1", "dim_2"], self.dataset_config.radio_dims):
assert n is not None, "Could not determine %s. Please check the .info file" % dim_name
def check_first_last_radios(self):
first_idx = self.nabu_config["dataset"]["num_first_radio"]
......
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