From cc4c5cbefd8764f24373ee3662570fbca6e1852d Mon Sep 17 00:00:00 2001 From: JeanBilheux Date: Thu, 10 Mar 2022 11:02:24 -0500 Subject: [PATCH 1/2] Fixed work. this refs #4 --- .gitignore | 3 +++ neutronimaging/detector_correction.py | 13 ++++++++++--- scripts/mcp_detector_correction.py | 10 +++++++++- setup.py | 2 +- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 250f520..58d3567 100644 --- a/.gitignore +++ b/.gitignore @@ -356,3 +356,6 @@ $RECYCLE.BIN/ # End of https://www.toptal.com/developers/gitignore/api/macos,linux,windows,pycharm,vscode,vim,python,jupyternotebooks .vscode/settings.json + +# pycharm +.idea \ No newline at end of file diff --git a/neutronimaging/detector_correction.py b/neutronimaging/detector_correction.py index a295db6..c842818 100644 --- a/neutronimaging/detector_correction.py +++ b/neutronimaging/detector_correction.py @@ -68,8 +68,12 @@ def skipping_meta_data(meta: pd.DataFrame) -> pd.DataFrame: return pd.concat(_with_skips) -def load_images(raw_imamge_dir: str) -> Type[Normalization]: - """Loading all Images into memory""" +def load_images(raw_imamge_dir: str, nbr_of_duplicated_runs: int = 1) -> Type[Normalization]: + """Loading all Images into memory + + if the nbr_of_duplicated_runs is higher than 1 (default value) that means the MCP produced by + mistake other sets of the same data, those must be removed and not used in the reconstruction + """ import glob from neutronimaging.util import in_jupyter @@ -81,6 +85,9 @@ def load_images(raw_imamge_dir: str) -> Type[Normalization]: ] _img_names.sort() + final_index = int(len(_img_names) / nbr_of_duplicated_runs) + _img_names = _img_names[0: final_index] + o_norm.load(file=_img_names, notebook=in_jupyter()) return o_norm @@ -131,7 +138,7 @@ def correct_images( import os _file_root = os.path.dirname(os.path.abspath(__file__)) - test_data_dir = os.path.join(_file_root, "../data") + test_data_dir = os.path.join(_file_root, "../../../../NeutronImagingScripts/data") # shutter_counts_file = os.path.join(test_data_dir, "OB_1_005_ShutterCount.txt") df_shutter_count = read_shutter_count(shutter_counts_file) diff --git a/scripts/mcp_detector_correction.py b/scripts/mcp_detector_correction.py index 64a6419..cf1dcdb 100755 --- a/scripts/mcp_detector_correction.py +++ b/scripts/mcp_detector_correction.py @@ -40,6 +40,14 @@ output_dir = args[""] skip_first_last_img = args["--skipimg"] verbose = args["--verbose"] + + # in some rare instances, the MCP creates a duplicate set of the run in the same folder + # we need to only consider the first set in the autoreduction + shutter_count_files = glob.glob(input_dir + "/*_ShutterCount.txt") + nbr_of_duplicated_runs = len(shutter_count_files) + if nbr_of_duplicated_runs > 1: + print(f"The folder contains {nbr_of_duplicated_runs} sets of the same data!") + shutter_count_file = glob.glob(input_dir + "/*_ShutterCount.txt")[0] shutter_time_file = glob.glob(input_dir + "/*_ShutterTimes.txt")[0] spectra_file = glob.glob(input_dir + "/*_Spectra.txt")[0] @@ -64,7 +72,7 @@ # load images print("Loading images into memory") - o_norm = load_images(input_dir) + o_norm = load_images(input_dir, nbr_of_duplicated_runs) # perform image correction print("Perform correction") diff --git a/setup.py b/setup.py index e201af4..632c221 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ from setuptools import setup, find_packages NAME = "NeutronImaging" -META_PATH = os.path.join("neutronimaging", "__init__.py") +META_PATH = os.path.join("../ToFImaging/jupyter_notebooks/code/neutronimaging", "__init__.py") KEYWORDS = "neutron imaging mcp" CLASSIFIERS = [ "Development Status :: 5 - Production/Stable", From 80456d3314bb3a444e261d8e626657c322e36891 Mon Sep 17 00:00:00 2001 From: JeanBilheux Date: Thu, 10 Mar 2022 11:56:46 -0500 Subject: [PATCH 2/2] reverted setup.py change. this refs #4 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 632c221..e201af4 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ from setuptools import setup, find_packages NAME = "NeutronImaging" -META_PATH = os.path.join("../ToFImaging/jupyter_notebooks/code/neutronimaging", "__init__.py") +META_PATH = os.path.join("neutronimaging", "__init__.py") KEYWORDS = "neutron imaging mcp" CLASSIFIERS = [ "Development Status :: 5 - Production/Stable",