From 396e9c8a3e5206fede882d5579294f13faf10af6 Mon Sep 17 00:00:00 2001 From: qitianshi <65122416+qitianshi@users.noreply.github.com> Date: Mon, 10 Jan 2022 20:09:17 +0800 Subject: [PATCH 1/4] Add quantities argument --- analysis/__main__.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/analysis/__main__.py b/analysis/__main__.py index 992e5225..a6a36caa 100644 --- a/analysis/__main__.py +++ b/analysis/__main__.py @@ -182,6 +182,16 @@ def __parse_cli_input() -> tuple: help="magnetization components to plot and analyze, any of: x y z, defaults to all" ) + comm_spatial.add_argument( + "--quantities", + dest="quantities", + type=str, + nargs='+', + required=False, + default=None, + help="magnetization components to plot and analyze, defaults to all" + ) + # spatialline args argobj_spatialline_dates = comm_spatialline.add_argument( @@ -271,7 +281,7 @@ def __parse_cli_input() -> tuple: __validate_date(args.date, argobj_spatial_dates) __validate_arg_list(args.components, argobj_spatial_components, ("x", "y", "z")) - return (Commands.SPATIAL, (args.date, args.components), (args.cli_test,)) + return (Commands.SPATIAL, (args.date, args.components, args.quantities), (args.cli_test,)) if args.command == "spatialline": @@ -574,7 +584,7 @@ def __create_json(): if COMMAND is Commands.RESONANCE: date_arg, MAG_VARS, PLOT_DEPTH = COMM_ARGS #pylint: disable=W0632 elif COMMAND is Commands.SPATIAL: - date_arg, COMPONENTS = COMM_ARGS #pylint: disable=W0632 + date_arg, COMPONENTS, QUANTITIES = COMM_ARGS #pylint: disable=W0632 elif COMMAND is Commands.SPATIALLINE: date_arg, QUANTITY, COMPONENTS, SHOW, SAVE, AXIS, AXIS_VAL = COMM_ARGS #pylint: disable=W0632 elif COMMAND is Commands.PREPARSE: From 0f08bf0ea777f9903c15ccc0947929b3ee819dca Mon Sep 17 00:00:00 2001 From: qitianshi <65122416+qitianshi@users.noreply.github.com> Date: Mon, 10 Jan 2022 20:27:08 +0800 Subject: [PATCH 2/4] Add support for quantities argument --- analysis/__main__.py | 68 +++++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 30 deletions(-) diff --git a/analysis/__main__.py b/analysis/__main__.py index a6a36caa..1b049194 100644 --- a/analysis/__main__.py +++ b/analysis/__main__.py @@ -505,36 +505,44 @@ def __convert_npy(): def __plot_spatial(): print("Plotting all spatial distribution data...") - for filename in os.listdir(anl.paths.spatial.root(DATE)): - if not filename.endswith("json"): - for component in COMPONENTS: - try: - anl.plot.plot_image( - anl.read.read_data( - anl.paths.spatial.spatial_path( - filename, component, None, DATE) - ), - xlabel="x (m)", - ylabel="y (m)", - title=filename + " (T)", - save_to=anl.paths.plots.spatial_dir( - filename, component, DATE - ), - xindexes=[150, 362], - yindexes=[150, 362], - show_plot=False, - date=DATE - ) - except FileNotFoundError as err: - if len( - os.listdir(os.path.join( - anl.paths.spatial.root(DATE), filename)) - ) > 0: - #TODO: Add in condition to look for x, y or z in the name - print( - f"{component} not found for {filename}. Component skipped.") - else: - raise err + plot_files = [] + if QUANTITIES is None: + plot_files = [f for f in os.listdir(anl.paths.spatial.root(DATE)) if f.endswith("json")] + else: + plot_files = [f for f in os.listdir(anl.paths.spatial.root(DATE)) if f in QUANTITIES] + + # Checks if plot_files is empty. + if not plot_files: + print("No data matches the requested patterns.") + + for filename in plot_files: + for component in COMPONENTS: + + try: + + anl.plot.plot_image( + anl.read.read_data( + anl.paths.spatial.spatial_path( + filename, component, None, DATE) + ), + xlabel="x (m)", + ylabel="y (m)", + title=filename + " (T)", + save_to=anl.paths.plots.spatial_dir( + filename, component, DATE + ), + xindexes=[150, 362], + yindexes=[150, 362], + show_plot=False, + date=DATE + ) + + except FileNotFoundError: + + print(f"{component} not found for {filename}. Component skipped.") + + #TODO: Check that it's only the singular component that is not found. + # Otherwise the error should still be raised. #endregion From 9df6ac86a313a2bdb931e0cb1ddb05b54df0e363 Mon Sep 17 00:00:00 2001 From: qitianshi <65122416+qitianshi@users.noreply.github.com> Date: Mon, 10 Jan 2022 20:51:07 +0800 Subject: [PATCH 3/4] Fix help for components and quantities args --- analysis/__main__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/analysis/__main__.py b/analysis/__main__.py index 1b049194..5996ea05 100644 --- a/analysis/__main__.py +++ b/analysis/__main__.py @@ -179,7 +179,7 @@ def __parse_cli_input() -> tuple: nargs='+', required=False, default=["x", "y", "z"], - help="magnetization components to plot and analyze, any of: x y z, defaults to all" + help="components to plot and analyze, any of: x y z, defaults to all" ) comm_spatial.add_argument( @@ -189,7 +189,7 @@ def __parse_cli_input() -> tuple: nargs='+', required=False, default=None, - help="magnetization components to plot and analyze, defaults to all" + help="quantities to plot, defaults to all" ) # spatialline args From 5fa957b89692f96607ff452a9527170377a5754b Mon Sep 17 00:00:00 2001 From: qitianshi <65122416+qitianshi@users.noreply.github.com> Date: Mon, 10 Jan 2022 20:51:23 +0800 Subject: [PATCH 4/4] Fix file parsing in __plot_spatial --- analysis/__main__.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/analysis/__main__.py b/analysis/__main__.py index 5996ea05..c6edbbf1 100644 --- a/analysis/__main__.py +++ b/analysis/__main__.py @@ -507,9 +507,11 @@ def __plot_spatial(): plot_files = [] if QUANTITIES is None: - plot_files = [f for f in os.listdir(anl.paths.spatial.root(DATE)) if f.endswith("json")] + plot_files = [f for f in os.listdir(anl.paths.spatial.root(DATE)) + if not f.endswith("json")] else: - plot_files = [f for f in os.listdir(anl.paths.spatial.root(DATE)) if f in QUANTITIES] + plot_files = [f for f in os.listdir(anl.paths.spatial.root(DATE)) + if not f.endswith("json") and f.strip(".tsv") in QUANTITIES] # Checks if plot_files is empty. if not plot_files: