From 430ed5c8ca8aca01b7e0bf231c54a82a0233761a Mon Sep 17 00:00:00 2001 From: Holger Frey Date: Tue, 19 Oct 2021 10:40:42 +0200 Subject: [PATCH] added --quite flag to cli to bypass sanity checks --- sensospot_data/__init__.py | 11 +++++++++-- sensospot_data/parser.py | 8 ++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/sensospot_data/__init__.py b/sensospot_data/__init__.py index fae0abb..b50d95b 100644 --- a/sensospot_data/__init__.py +++ b/sensospot_data/__init__.py @@ -38,9 +38,16 @@ from .dynamic_range import blend, create_xdr, normalize_values # noqa: F401 default="raw_data.h5", help="Output file name", ) -def run(source, outfile): +@click.option( + "-q", + "--quiet", + is_flag=True, + default=False, + help="Ignore Sanity Check", +) +def run(source, outfile, quiet=False): source_path = Path(source) # read the raw data of a folder - raw_data = parse_folder(source_path) + raw_data = parse_folder(source_path, quiet=quiet) hdf5_path = source_path / outfile raw_data.to_hdf(hdf5_path, key="raw_data", format="table") diff --git a/sensospot_data/parser.py b/sensospot_data/parser.py index d2c4ebf..3581b74 100755 --- a/sensospot_data/parser.py +++ b/sensospot_data/parser.py @@ -124,16 +124,20 @@ def _sanity_check(data_frame): spot_positions = len(data_frame[RAW_DATA_POS_ID].unique()) expected_rows = field_rows * field_cols * exposures * spot_positions if expected_rows != len(data_frame): - raise ValueError("Measurements are missing") + raise ValueError( + f"Measurements are missing: {expected_rows} != {len(data_frame)}" + ) # set the right data type for measurement columns for raw_column in RAW_DATA_NORMALIZATION_MAP: data_frame[raw_column] = pandas.to_numeric(data_frame[raw_column]) return data_frame -def parse_folder(folder): +def parse_folder(folder, quiet=False): """ parses all csv files in a folder to one large dataframe """ file_list = list_csv_files(Path(folder)) data_frame = parse_multiple_files(file_list) data_frame = add_optional_measurement_parameters(data_frame, folder) + if quiet: + return data_frame return _sanity_check(data_frame)