From c3c3eb32d031cfa48768844e53ac0539eebf49ec Mon Sep 17 00:00:00 2001 From: Cleveland Date: Tue, 7 Jan 2025 15:22:05 -0700 Subject: [PATCH 01/14] add an optional pre and post parser hook and and add_parser_arg hook --- opppy/interactive_utils.py | 84 +++++++++++++++++++++++++++++++++----- 1 file changed, 74 insertions(+), 10 deletions(-) diff --git a/opppy/interactive_utils.py b/opppy/interactive_utils.py index 005faba..b7d5447 100644 --- a/opppy/interactive_utils.py +++ b/opppy/interactive_utils.py @@ -156,10 +156,17 @@ def append_pickle(self, args): print("This version of OPPPY is ", __version__) print("Delete the old ", args.pickle_name, "file and rebuild it") sys.exit(0) - + + if hasattr(self.opppy_parser, "pre_parse"): + self.opppy_parser.pre_parse(args) + # append new dictionary data to the pickle file append_output_dictionary(data, args.output_files, self.opppy_parser, args.append_date, args.nthreads) - + + if hasattr(self.opppy_parser, "post_parse"): + self.opppy_parser.post_parse(args, data) + + pickle.dump(data,open(args.pickle_name,"wb")) print("Output Data Saved To: ", args.pickle_name) @@ -170,6 +177,8 @@ def pickle_output_parser(self, subparser): pickle_parser.add_argument('-pf','--pickle_file', dest='pickle_name', help='Pickle file name to be created or appended to', required=True ) pickle_parser.add_argument('-ad','--append_date', dest='append_date', help='Append the date and time to the output file name', nargs='?', type=bool, const=True, default=False) pickle_parser.add_argument('-nt','--nthreads', dest='nthreads', help='Number of threads to use during parsing', nargs='?', type=int, default=0) + if hasattr(self.opppy_parser, "add_parser_args"): + self.opppy_parser.add_parser_args(pickle_parser) pickle_parser.set_defaults(func=self.append_pickle) @@ -184,6 +193,8 @@ def plot_dictionary_parser(self, subparser): plot_parser.add_argument('-nt','--nthreads', dest='nthreads', help='Number of threads to use during parsing', nargs='?', type=int, default=0) self.dict_ploter = plot_dictionary() self.dict_ploter.setup_parser(plot_parser) + if hasattr(self.opppy_parser, "add_parser_args"): + self.opppy_parser.add_parser_args(plot_parser) plot_parser.set_defaults(func=self.plot_dictionary) def plot_dictionary(self, args): @@ -196,8 +207,14 @@ def plot_dictionary(self, args): dictionaries = [] file_names = [] if args.output_files is not None: + if hasattr(self.opppy_parser, "pre_parse"): + self.opppy_parser.pre_parse(args) dictionaries, file_names = build_output_dictionary_list(args.output_files, - self.opppy_parser, nthreads=args.nthreads) + self.opppy_parser, + nthreads=args.nthreads) + if hasattr(self.opppy_parser, "post_parse"): + for data in dictionaries: + self.opppy_parser.post_parse(args, data) else: # get the dictionaries from the pickle files file_names = args.pickle_files @@ -214,6 +231,8 @@ def plot_output_parser(self, subparser): input_type_parser.add_argument('-pf','--pickle_files', dest='pickle_files', help='pickle files to be plotted (run1.p run2.p etc...)', nargs='+' ) input_type_parser.add_argument('-of','--output_files', dest='output_files', help='output files to be parsed and plotted (output_file1.txt output_file2.txt etc...)', nargs='+', action='append') plot_output_parser.add_argument('-nt','--nthreads', dest='nthreads', help='Number of threads to use during parsing', nargs='?', type=int, default=0) + if hasattr(self.opppy_parser, "add_parser_args"): + self.opppy_parser.add_parser_args(plot_output_parser) plot_output_parser.set_defaults(func=self.plot_output) def get_plot_option(self): @@ -268,9 +287,14 @@ def plot_output(self, args): dictionary_data=[] dictionary_names=[] if args.output_files is not None: + if hasattr(self.opppy_parser, "pre_parse"): + self.opppy_parser.pre_parse(args) dictionary_data, dictionary_names = build_output_dictionary_list(args.output_files, self.opppy_parser, nthreads=args.nthreads) + if hasattr(self.opppy_parser, "post_parse"): + for data in dictionary_data: + self.opppy_parser.post_parse(args, data) else: # We no longer flatten this data #file_list = [] @@ -502,6 +526,8 @@ def parse_output_plot_args(self, input_string): parser.add_argument('-dn','--dictionary_name', dest='dictionary_name', help='dictionary that the plotting data is contained in', required=True, type=str) parser.add_argument('-x','--x_data', dest='x_value_name', help='dictionary data to be plotted on the x axis.', required=True) parser.add_argument('-y','--y_data', dest='y_value_names', help='dictionary data to be plotted on the y axis.', required=True, action='append') + if hasattr(self.opppy_parser, "add_parser_args"): + self.opppy_parser.add_parser_args(parser) add_plot_options(parser); return parser.parse_args(shlex.split(input_string)) @@ -534,7 +560,6 @@ def __init__(self, opppy_dump_parser, argument_parser): ''' self.dump_parser = opppy_dump_parser self.parser = argument_parser - self.subparser = self.parser.add_subparsers(help="Dump options", dest='command') self.pickle_dumps_parser(self.subparser) self.plot_1d_parser(self.subparser) @@ -558,6 +583,8 @@ def plot_1d_parser(self, subparser): plot_parser.add_argument('-kw','--key_words', dest='key_words', help='Only extract the specified key_words', nargs='+', default=None ) self.ploter_1d = plot_1d_dump_dictionary() self.ploter_1d.setup_parser(plot_parser) + if hasattr(self.dump_parser, "add_parser_args"): + self.dump_parser.add_parser_args(plot_parser) plot_parser.set_defaults(func=self.plot_1d) def plot_2d_parser(self, subparser): @@ -574,6 +601,8 @@ def plot_2d_parser(self, subparser): plot_parser.add_argument('-kw','--key_words', dest='key_words', help='Only extract the specified key_words', nargs='+', default=None ) self.ploter_2d = plot_2d_dump_dictionary() self.ploter_2d.setup_parser(plot_parser) + if hasattr(self.dump_parser, "add_parser_args"): + self.dump_parser.add_parser_args(plot_parser) plot_parser.set_defaults(func=self.plot_2d) def plot_3d_parser(self, subparser): @@ -590,6 +619,8 @@ def plot_3d_parser(self, subparser): plot_parser.add_argument('-kw','--key_words', dest='key_words', help='Only extract the specified key_words', nargs='+', default=None ) self.ploter_3d = plot_3d_dump_dictionary() self.ploter_3d.setup_parser(plot_parser) + if hasattr(self.dump_parser, "add_parser_args"): + self.dump_parser.add_parser_args(plot_parser) plot_parser.set_defaults(func=self.plot_3d) def plot_3d(self, args): @@ -616,6 +647,8 @@ def pickle_dumps_parser(self, subparser): pickle_parser.add_argument('-pf','--pickle_file', dest='pickle_name', help='Pickle file name to be created or appended to', required=True ) pickle_parser.add_argument('-kw','--key_words', dest='key_words', help='Only extract the specified key_words', nargs='+', default=None ) pickle_parser.add_argument('-nt','--nthreads', dest='nthreads', help='Specify number of threads for dump parsing', nargs='?', type=int, default=0 ) + if hasattr(self.dump_parser, "add_parser_args"): + self.dump_parser.add_parser_args(pickle_parser) pickle_parser.set_defaults(func=self.pickle_dumps) def pickle_dumps(self, args): @@ -682,6 +715,8 @@ def plot_series_point_parser(self, subparser): # suppress the x and y variable request plot_parser.add_argument('-x','--x_data',dest='x_value_name', help=argparse.SUPPRESS) plot_parser.add_argument('-y','--y_data',dest='y_value_name', help=argparse.SUPPRESS) + if hasattr(self.dump_parser, "add_parser_args"): + self.dump_parser.add_parser_args(plot_parser) plot_parser.set_defaults(func=self.plot_series_point) def plot_series_point(self, args): @@ -749,6 +784,8 @@ def plot_series_line_parser(self, subparser): # suppress the x and y variable request plot_parser.add_argument('-x','--x_data',dest='x_value_name', help=argparse.SUPPRESS) plot_parser.add_argument('-y','--y_data',dest='y_value_name', help=argparse.SUPPRESS) + if hasattr(self.dump_parser, "add_parser_args"): + self.dump_parser.add_parser_args(plot_parser) plot_parser.set_defaults(func=self.plot_series_line) def plot_series_line(self, args): @@ -806,6 +843,8 @@ def plot_series_contour_parser(self, subparser): # suppress the x and y variable request plot_parser.add_argument('-x','--x_data',dest='x_value_name', help=argparse.SUPPRESS) plot_parser.add_argument('-y','--y_data',dest='y_value_name', help=argparse.SUPPRESS) + if hasattr(self.dump_parser, "add_parser_args"): + self.dump_parser.add_parser_args(plot_parser) plot_parser.set_defaults(func=self.plot_series_contour) def plot_series_contour(self, args): @@ -937,8 +976,14 @@ def append_pickle(self, args): print("Delete the old ", args.pickle_name, "file and rebuild it") sys.exit(0) + if hasattr(self.opppy_parser, "pre_parse"): + self.opppy_parser.pre_parse(args) + # append new dictionary data to the pickle file append_tally_dictionary(data, args.tally_files, self.opppy_parser, args.append_date, args.nthreads) + + if hasattr(self.opppy_parser, "post_parse"): + self.opppy_parser.post_parse(args, data) pickle.dump(data,open(args.pickle_name,"wb")) print("Output Data Saved To: ", args.pickle_name) @@ -950,6 +995,8 @@ def pickle_tally_parser(self, subparser): pickle_parser.add_argument('-pf','--pickle_file', dest='pickle_name', help='Pickle file name to be created or appended to', required=True ) pickle_parser.add_argument('-ad','--append_date', dest='append_date', help='Append the date and time to the output file name', nargs='?', type=bool, const=True, default=False) pickle_parser.add_argument('-nt','--nthreads', dest='nthreads', help='Number of threads to use during parsing', nargs='?', type=int, default=0) + if hasattr(self.opppy_parser, "add_parser_args"): + self.opppy_parser.add_parser_args(pickle_parser) pickle_parser.set_defaults(func=self.append_pickle) @@ -966,6 +1013,8 @@ def plot_tally_parser(self, subparser): plot_parser.add_argument('-nt','--nthreads', dest='nthreads', help='Number of threads to use during parsing', nargs='?', type=int, default=0) self.dict_ploter = plot_dictionary() self.dict_ploter.setup_parser(plot_parser) + if hasattr(self.opppy_parser, "add_parser_args"): + self.opppy_parser.add_parser_args(plot_parser) plot_parser.set_defaults(func=self.plot_tally) def plot_tally(self, args): @@ -978,8 +1027,14 @@ def plot_tally(self, args): raw_dictionary_data=[] raw_dictionary_names=[] if args.tally_files is not None: + if hasattr(self.opppy_parser, "pre_parse"): + self.opppy_parser.pre_parse(args) raw_dictionary_data, raw_dictionary_names = build_tally_dictionary_list(args.tally_files, - self.opppy_parser, nthreads=args.nthreads) + self.opppy_parser, + nthreads=args.nthreads) + if hasattr(self.opppy_parser, "post_parse"): + for data in raw_dictionary_data: + self.opppy_parser.post_parse(args, data) else: for pickle_file_name in args.pickle_files: raw_dictionary_names.append(pickle_file_name.split('/')[-1].split('.p')[0]) @@ -1016,7 +1071,8 @@ def plot_interactive_tally_parser(self, subparser): input_type_parser.add_argument('-pf','--pickle_files', dest='pickle_files', help='pickle files to be plotted (run1.p run2.p etc...)', nargs='+' ) input_type_parser.add_argument('-tf','--tally_files', dest='tally_files', help='tally files to be parsed and plotted (tally_file1.txt tally_file2.txt etc...)', nargs='+', action='append') plot_parser.add_argument('-nt','--nthreads', dest='nthreads', help='Number of threads to use during parsing', nargs='?', type=int, default=0) - + if hasattr(self.opppy_parser, "add_parser_args"): + self.opppy_parser.add_parser_args(plot_parser) plot_parser.set_defaults(func=self.plot_interactive_tally) def get_plot_option(self): @@ -1053,9 +1109,9 @@ def get_interactive_plot_parser(self): parser.add_argument('-p','--plot', dest='plot', help='re-open plot', nargs='?', type=bool, const=True, default=False) parser.add_argument('-l','--labels', dest='legend_labels', help='specify the legend labels [line1_label, line2_label,...]', type=str, nargs='+') parser.add_argument('-rs','--resize', dest='plot_size', help='specify the plot size [x_size, y_size]', type=float, nargs=2) - - add_plot_options(parser) + if hasattr(self.opppy_parser, "add_parser_args"): + self.opppy_parser.add_parser_args(parser) return parser def plot_interactive_tally(self, args): @@ -1071,8 +1127,14 @@ def plot_interactive_tally(self, args): raw_dictionary_data=[] raw_dictionary_names=[] if args.tally_files is not None: - raw_dictionary_data, raw_dictionary_names = build_tally_dictionary_list(args.tally_files, - self.opppy_parser, nthreads=args.nthreads) + if hasattr(self.opppy_parser, "pre_parse"): + self.opppy_parser.pre_parse(args) + raw_dictionary_data, raw_dictionary_names = build_tally_dictionary_list(args.tally_files, + self.opppy_parser, + nthreads=args.nthreads) + if hasattr(self.opppy_parser, "post_parse"): + for data in raw_dictionary_data: + self.opppy_parser.post_parse(args, data) else: for pickle_file_name in args.pickle_files: raw_dictionary_names.append(pickle_file_name.split('/')[-1].split('.p')[0]) @@ -1321,6 +1383,8 @@ def parse_tally_plot_args(self, input_string): parser.add_argument('-y','--y_data', dest='y_value_names', help='dictionary data to be plotted on the y axis.', required=True, action='append') parser.add_argument('-sk','--series_key', dest='series_key', help='Series key string to access the data (i.e time or cycle)', nargs='?', required=True) parser.add_argument('-sv','--series_value', dest='series_value', help='Series value to plot the data at (default is the last value of the series_key data)', nargs='?', action='append', type=float, default=None) + if hasattr(self.opppy_parser, "add_parser_args"): + self.opppy_parser.add_parser_args(parser) add_plot_options(parser); return parser.parse_args(shlex.split(input_string)) From 58e2e9076a6a685d09d0742d11ec237e1af1f307 Mon Sep 17 00:00:00 2001 From: Cleveland Date: Thu, 23 Jan 2025 09:47:32 -0700 Subject: [PATCH 02/14] update arrivial plotting --- opppy/plot_dictionary.py | 24 +++++++++++++++++------- opppy/plotting_help.py | 2 ++ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/opppy/plot_dictionary.py b/opppy/plot_dictionary.py index e06760c..977d635 100644 --- a/opppy/plot_dictionary.py +++ b/opppy/plot_dictionary.py @@ -146,7 +146,7 @@ def plot_dict(self, args, dictionaries, data_names): print('# ', header_xlabel, header_ylabel, file=outputfile) for x_value, y_value in zip(x, y): - outstring = "%.9e"%(x_value*scale_x)+" %.9e"%(y_value*scale_y)+"\n" + outstring = "%.9e"%(x_value)+" %.9e"%(y_value)+"\n" outputfile.write(outstring) data_name = '' if(args.data_file_name is not None): @@ -199,12 +199,13 @@ def plot_dict(self, args, dictionaries, data_names): if(len(x)>0): last_x.append(x[-1]) last_y.append(y[-1]) + + if(args.font_size is not None): + PyPloter.rcParams.update({'font_size':args.font_size}) if(args.plot_max): last_y.append(sum(sorted(y,reverse=True)[0:2])/3.0) last_x.append(x[-1]) - elif(args.plot_arrival): - continue elif(data_line_color != '' and data_line_type != ''): PyPloter.plot(x,y,label = data_name, linestyle = data_line_type, color = data_line_color) elif(data_line_color != '' ): @@ -214,17 +215,22 @@ def plot_dict(self, args, dictionaries, data_names): else: PyPloter.plot(x,y,label = data_name) + interp_x = x[0] if(args.plot_arrival): + args.plot_arrival = False last_x = x[0] last_y = y[0] for x_value, y_value in zip(x,y): if(y_value>args.y_exceeds_value): + args.plot_arrival = True dy = (args.y_exceeds_value - last_y)/(y_value - last_y) interp_x = last_x + dy*(x_value-last_x) - print(data_name, "first exceeds ", y_exceeds_value, " at ", interp_x) + print(data_name, "first exceeds ", args.y_exceeds_value, " at ", interp_x) break last_x = x_value last_y = y_value + if(not args.plot_arrival): + print("WARNING: y never exceeds y_exceeds_value="+str(args.y_exceeds_value)); if(args.find_max_y): print(data_name, "max y value ", x[y.index(max(y))], max(y)) @@ -233,9 +239,13 @@ def plot_dict(self, args, dictionaries, data_names): if(args.last_point_only): PyPloter.plot(last_x, last_y, label = data_name) - elif(args.plot_arrival or args.plot_max): - print(last_x, last_y) - PyPloter.plot(last_x, last_y, label = data_name) + elif(args.plot_arrival): + color=PyPloter.gca().lines[-1].get_color() + PyPloter.plot(interp_x, args.y_exceeds_value, linestyle=None, color=color, marker='o', label = data_name + " exceeds y="+str(args.y_exceeds_value)+" @ x="+str(interp_x)) + elif(args.plot_max): + print("max y= "+str(last_y)+" @ x="+str(last_x)) + color=PyPloter.gca().lines[-1].get_color() + PyPloter.plot(last_x, last_y, linestyle=None, color=color, marker='x', label = data_name + " max y="+str(last_y)+" @ x="+str(last_x)) if(args.x_label is not None): PyPloter.xlabel(args.x_label) diff --git a/opppy/plotting_help.py b/opppy/plotting_help.py index eae315b..a65cd4c 100644 --- a/opppy/plotting_help.py +++ b/opppy/plotting_help.py @@ -276,6 +276,7 @@ def add_plot_options(parser): parser.add_argument('-lpo','--last_point_only', dest='last_point_only', help='only plot the last data point', nargs='?', type=bool, default=False, const=True ) parser.add_argument('-ltv','--last_time_value', dest='last_time_value', help='only plot the last time value', nargs=1, type=float) parser.add_argument('-fr','--figure_resolution', dest='figure_resolution', help='figure resolution in dpi', nargs='?', type=float, default=300.0) + parser.add_argument('-fs','--font_size', dest='font size', help='set the plot font size', type=float, default=None, nargs="?") parser.add_argument('-yev','--y_exceeds_value', dest='y_exceeds_value', help='y arrival value', nargs=1, type=float, default=0.0) parser.add_argument('-sy','--scale_y', dest='scale_y', help='scale y values', type=float, default=[], action="append") parser.add_argument('-sx','--scale_x', dest='scale_x', help='scale x values', type=float, default=[], action="append") @@ -301,6 +302,7 @@ def add_2d_plot_options(parser): parser.add_argument('-xlab','--xlab', dest='x_label', help='x axis label') parser.add_argument('-ylab','--ylabl', dest='y_label', help='y axis label') parser.add_argument('-fr','--figure_resolution', dest='figure_resolution', help='figure resolution in dpi', nargs='?', type=float, default=300.0) + parser.add_argument('-fs','--font_size', dest='font size', help='set the plot font size', type=float, default=None, nargs="?") parser.add_argument('-sv','--scale_value', dest='scale_value', help='scale values', type=float, default=1.0) parser.add_argument('-sx','--scale_x', dest='scale_x', help='scale x values', type=float, default=1.0) parser.add_argument('-sy','--scale_y', dest='scale_y', help='scale y values', type=float, default=1.0) From e935bfd3cb476388fe8f87ea6c3dc1a43d06f52f Mon Sep 17 00:00:00 2001 From: Cleveland Date: Thu, 30 Jan 2025 16:53:28 -0700 Subject: [PATCH 03/14] fix font size and add pre/post/add_parser_args tests --- opppy/plotting_help.py | 4 ++-- tests/my_test_opppy_dump_parser.py | 1 + tests/my_test_opppy_parser.py | 18 ++++++++++++++++-- tests/my_test_opppy_tally_parser.py | 16 +++++++++++++++- 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/opppy/plotting_help.py b/opppy/plotting_help.py index a65cd4c..4eff7c5 100644 --- a/opppy/plotting_help.py +++ b/opppy/plotting_help.py @@ -276,7 +276,7 @@ def add_plot_options(parser): parser.add_argument('-lpo','--last_point_only', dest='last_point_only', help='only plot the last data point', nargs='?', type=bool, default=False, const=True ) parser.add_argument('-ltv','--last_time_value', dest='last_time_value', help='only plot the last time value', nargs=1, type=float) parser.add_argument('-fr','--figure_resolution', dest='figure_resolution', help='figure resolution in dpi', nargs='?', type=float, default=300.0) - parser.add_argument('-fs','--font_size', dest='font size', help='set the plot font size', type=float, default=None, nargs="?") + parser.add_argument('-fs','--font_size', dest='font_size', help='set the plot font size', type=float, default=None, nargs="?") parser.add_argument('-yev','--y_exceeds_value', dest='y_exceeds_value', help='y arrival value', nargs=1, type=float, default=0.0) parser.add_argument('-sy','--scale_y', dest='scale_y', help='scale y values', type=float, default=[], action="append") parser.add_argument('-sx','--scale_x', dest='scale_x', help='scale x values', type=float, default=[], action="append") @@ -302,7 +302,7 @@ def add_2d_plot_options(parser): parser.add_argument('-xlab','--xlab', dest='x_label', help='x axis label') parser.add_argument('-ylab','--ylabl', dest='y_label', help='y axis label') parser.add_argument('-fr','--figure_resolution', dest='figure_resolution', help='figure resolution in dpi', nargs='?', type=float, default=300.0) - parser.add_argument('-fs','--font_size', dest='font size', help='set the plot font size', type=float, default=None, nargs="?") + parser.add_argument('-fs','--font_size', dest='font_size', help='set the plot font size', type=float, default=None, nargs="?") parser.add_argument('-sv','--scale_value', dest='scale_value', help='scale values', type=float, default=1.0) parser.add_argument('-sx','--scale_x', dest='scale_x', help='scale x values', type=float, default=1.0) parser.add_argument('-sy','--scale_y', dest='scale_y', help='scale y values', type=float, default=1.0) diff --git a/tests/my_test_opppy_dump_parser.py b/tests/my_test_opppy_dump_parser.py index 50b3dbb..730fd6f 100644 --- a/tests/my_test_opppy_dump_parser.py +++ b/tests/my_test_opppy_dump_parser.py @@ -45,3 +45,4 @@ def build_data_dictionary(self, filename, dump_keys=None): return data + diff --git a/tests/my_test_opppy_parser.py b/tests/my_test_opppy_parser.py index 00f8d26..410738a 100644 --- a/tests/my_test_opppy_parser.py +++ b/tests/my_test_opppy_parser.py @@ -14,6 +14,15 @@ def __init__(self): self.file_end_string = None print("Initializing my_test_opppy_parser") + def add_parser_args(self, parser): + parser.add_argument('-ppt', '--pre_parser_test', dest="pre_parser_test", nargs="?", default=None) + + def pre_parse(self, args): + if(args.pre_parser_test is not None): + print("pre_parse hook works: args.pre_parser_test") + else: + print("pre_parse hook works: None") + def parse_cycle_string(self,cycle_string): # return dictionary of dictionaries data_dict = {} @@ -53,8 +62,13 @@ def parse_cycle_string(self,cycle_string): # append dictionary with multiple entries data_dict['density'] = density_data + return data_dict + def post_parse(self, args, data): + if(args.pre_parser_test is not None): + data["post_parse_test_"+args.pre_parser_test]=data['test_data1'] + else: + data['post_parser_test']=data['test_data1'] - return data_dict - + diff --git a/tests/my_test_opppy_tally_parser.py b/tests/my_test_opppy_tally_parser.py index 678b233..56ec98a 100644 --- a/tests/my_test_opppy_tally_parser.py +++ b/tests/my_test_opppy_tally_parser.py @@ -20,6 +20,16 @@ def __init__(self): self.file_end_string = None print("Initializing my_test_opppy_tally_parser") + def add_parser_args(self, parser): + parser.add_argument('-ppt', '--pre_parser_test', dest="pre_parser_test", nargs="?", default=None) + + def pre_parse(self, args): + if(args.pre_parser_test is not None): + print("pre_parse hook works: args.pre_parser_test") + else: + print("pre_parse hook works: None") + + def parse_cycle_string(self,cycle_string): cycle_data_keys = ['bins','odd_counts','even_counts'] cycle_info_keys = ['time', 'cycle'] @@ -58,4 +68,8 @@ def parse_cycle_string(self,cycle_string): data_dict['cool_counts'] = counts return data_dict - + + def post_parse(self, args, data): + print("Post Parse Test Data keys: ",data.keys()) + + From 7cb94af92d219957e5d11ca5c73e58fa985c9034 Mon Sep 17 00:00:00 2001 From: Cleveland Date: Thu, 30 Jan 2025 17:06:17 -0700 Subject: [PATCH 04/14] fix type conversion error --- opppy/interactive_utils.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/opppy/interactive_utils.py b/opppy/interactive_utils.py index b7d5447..d80943b 100644 --- a/opppy/interactive_utils.py +++ b/opppy/interactive_utils.py @@ -1237,24 +1237,24 @@ def plot_interactive_tally(self, args): plabels = [] x = [] y = [] - xmin.append(min(data[plot_args.x_value_name])*scale_x) - xmax.append(max(data[plot_args.x_value_name])*scale_x) - ymin.append(min(data[plot_args.y_value_names[0]])*scale_y) - ymax.append(max(data[plot_args.y_value_names[0]])*scale_y) + xmin.append(min(data[plot_args.x_value_name])) + xmax.append(max(data[plot_args.x_value_name])) + ymin.append(min(data[plot_args.y_value_names[0]])) + ymax.append(max(data[plot_args.y_value_names[0]])) # material specific plot for yname in plot_args.y_value_names: x.append(array(data[plot_args.x_value_name])*scale_x) - ymin[-1] = min(ymin[-1],min(data[yname])*scale_y) - ymax[-1] = max(ymin[-1],max(data[yname])*scale_y) + ymin[-1] = min(ymin[-1],min(data[yname])) + ymax[-1] = max(ymin[-1],max(data[yname])) plabels.append(label+" "+yname) if (option.no_y_names): plabels[-1] = '' y.append(array(data[yname])*scale_y) - xmin = array(xmin) - xmax = array(xmax) - ymin = array(ymin) - ymax = array(ymax) + xmin = array(xmin*scale_x) + xmax = array(xmax*scale_x) + ymin = array(ymin*scale_y) + ymax = array(ymax*scale_y) if last_xmin is not None: xmin = min(last_xmin,xmin.min()) xmax = max(last_xmax,xmax.max()) From aba75c49ca1aff75acc1993b606a23dd95fa5830 Mon Sep 17 00:00:00 2001 From: Cleveland Date: Fri, 31 Jan 2025 07:37:23 -0700 Subject: [PATCH 05/14] cleanup testing error --- opppy/interactive_utils.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/opppy/interactive_utils.py b/opppy/interactive_utils.py index d80943b..fd1e6dd 100644 --- a/opppy/interactive_utils.py +++ b/opppy/interactive_utils.py @@ -1243,18 +1243,18 @@ def plot_interactive_tally(self, args): ymax.append(max(data[plot_args.y_value_names[0]])) # material specific plot for yname in plot_args.y_value_names: - x.append(array(data[plot_args.x_value_name])*scale_x) + x.append(array(data[plot_args.x_value_name])) ymin[-1] = min(ymin[-1],min(data[yname])) ymax[-1] = max(ymin[-1],max(data[yname])) plabels.append(label+" "+yname) if (option.no_y_names): plabels[-1] = '' - y.append(array(data[yname])*scale_y) + y.append(array(data[yname])) - xmin = array(xmin*scale_x) - xmax = array(xmax*scale_x) - ymin = array(ymin*scale_y) - ymax = array(ymax*scale_y) + xmin = array(xmin) + xmax = array(xmax) + ymin = array(ymin) + ymax = array(ymax) if last_xmin is not None: xmin = min(last_xmin,xmin.min()) xmax = max(last_xmax,xmax.max()) @@ -1269,6 +1269,10 @@ def plot_interactive_tally(self, args): last_xmax = xmax last_ymin = ymin last_ymax = ymax + xmin = xmin*scale_x + xmax = xmax*scale_x + ymin = ymin*scale_y + ymax = ymax*scale_y xlab = plot_args.x_label ylab = plot_args.y_label @@ -1294,7 +1298,7 @@ def plot_interactive_tally(self, args): show(block=False) for i in range(len(x)): - logplot(option.log_x,option.log_y,x[i],y[i],label=name+" "+plabels[i]) + logplot(option.log_x,option.log_y,(x[i]*scale_x),(y[i]*scale_y),label=name+" "+plabels[i]) if option.data_file_name is not None: output_file_temp = option.data_file_name @@ -1303,7 +1307,7 @@ def plot_interactive_tally(self, args): outfile = open(outfile_name,'w') print("# ", xlab, ylab, file=outfile) for j in range(len(x[i])): - print('%15e %15e' %(x[i][j], y[i][j]), file=outfile) + print('%15e %15e' %(x[i][j]*scale_x, y[i][j]*scale_y), file=outfile) print("Data written to - ", outfile_name) outfile.close() From e40fd97101945a99111a7df5eb45d41a11f6fbaf Mon Sep 17 00:00:00 2001 From: Cleveland Date: Fri, 31 Jan 2025 07:51:03 -0700 Subject: [PATCH 06/14] more scale factor cleanup --- opppy/interactive_utils.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/opppy/interactive_utils.py b/opppy/interactive_utils.py index fd1e6dd..5be2d97 100644 --- a/opppy/interactive_utils.py +++ b/opppy/interactive_utils.py @@ -382,19 +382,19 @@ def plot_output(self, args): plabels = [] x = [] y = [] - xmin.append(min(data[plot_args.x_value_name])*scale_x) - xmax.append(max(data[plot_args.x_value_name])*scale_x) - ymin.append(min(data[plot_args.y_value_names[0]])*scale_y) - ymax.append(max(data[plot_args.y_value_names[0]])*scale_y) + xmin.append(min(data[plot_args.x_value_name])) + xmax.append(max(data[plot_args.x_value_name])) + ymin.append(min(data[plot_args.y_value_names[0]])) + ymax.append(max(data[plot_args.y_value_names[0]])) # material specific plot for yname in plot_args.y_value_names: - x.append(array(data[plot_args.x_value_name])*scale_x) - ymin[-1] = min(ymin[-1],min(data[yname])*scale_y) - ymax[-1] = max(ymin[-1],max(data[yname])*scale_y) + x.append(array(data[plot_args.x_value_name])) + ymin[-1] = min(ymin[-1],min(data[yname])) + ymax[-1] = max(ymin[-1],max(data[yname])) plabels.append(label+" "+yname) if (option.no_y_names): plabels[-1] = '' - y.append(array(data[yname])*scale_y) + y.append(array(data[yname])) xmin = array(xmin) xmax = array(xmax) @@ -414,6 +414,10 @@ def plot_output(self, args): last_xmax = xmax last_ymin = ymin last_ymax = ymax + xmin = xmin*scale_x + xmax = xmax*scale_x + ymin = ymin*scale_y + ymax = ymax*scale_y xlab = plot_args.x_label ylab = plot_args.y_label @@ -439,7 +443,7 @@ def plot_output(self, args): show(block=False) for i in range(len(x)): - logplot(option.log_x,option.log_y,x[i],y[i],label=name+" "+plabels[i]) + logplot(option.log_x,option.log_y,x[i]*scale_x,y[i]*scale_y,label=name+" "+plabels[i]) if option.data_file_name is not None: output_file_temp = option.data_file_name @@ -448,7 +452,7 @@ def plot_output(self, args): outfile = open(outfile_name,'w') print("# ", xlab, ylab, file=outfile) for j in range(len(x[i])): - print('%15e %15e' %(x[i][j], y[i][j]), file=outfile) + print('%15e %15e' %(x[i][j]*scale_x, y[i][j]*scale_y), file=outfile) print("Data written to - ", outfile_name) outfile.close() From 254afffa06b17480aabf81d773a784ec134a7bc8 Mon Sep 17 00:00:00 2001 From: Cleveland Date: Fri, 31 Jan 2025 08:18:25 -0700 Subject: [PATCH 07/14] fix more numpy min max type errors --- opppy/dump_utils.py | 2 +- opppy/plot_dump_dictionary.py | 52 +++++++++++++++++++++++------------ 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/opppy/dump_utils.py b/opppy/dump_utils.py index 97931d6..1d67294 100644 --- a/opppy/dump_utils.py +++ b/opppy/dump_utils.py @@ -515,7 +515,7 @@ def thread_all(file_name, key_words, result_d): result_d[file_name.split('/')[-1]] = opppy_parser.build_data_dictionary(file_name,key_words) print("Number of threads used for processing: ",nthreads) for stride in range(math.ceil(float(total)/float(nthreads))): - files = dump_files[nthreads*stride:min(nthreads*(stride+1),len(dump_files))] + files = dump_files[nthreads*stride:min(int(nthreads*(stride+1)),len(dump_files))] with Manager() as manager: result_d = manager.dict() threads = [] diff --git a/opppy/plot_dump_dictionary.py b/opppy/plot_dump_dictionary.py index 2ef30eb..377ccb1 100644 --- a/opppy/plot_dump_dictionary.py +++ b/opppy/plot_dump_dictionary.py @@ -773,17 +773,23 @@ def init_lines(): if(args.data_file_name is not None): outputfile = open(args.data_file_name+'_'+filename.split('/')[-1]+'.'+re.sub(r'[^\w]','',yname)+'.dat', 'w') - xmin=(np.array(series_data[0][xname])*scale_x).min() - xmax=(np.array(series_data[0][xname])*scale_x).max() - ymin=(np.array(series_data[0][yname])*scale_y).min() - ymax=(np.array(series_data[0][yname])*scale_y).max() + xmin=(np.array(series_data[0][xname])).min() + xmax=(np.array(series_data[0][xname])).max() + ymin=(np.array(series_data[0][yname])).min() + ymax=(np.array(series_data[0][yname])).max() for data, index_value in zip(series_data, series_pair.index[index_key]): - x = np.array(data[xname])*scale_x - y = np.array(data[yname])*scale_y + x = np.array(data[xname]) + y = np.array(data[yname]) xmin = min(x.min(),xmin) xmax = max(x.max(),xmax) ymin = min(y.min(),ymin) ymax = max(y.max(),ymax) + x = x*scale_x + y = y*scale_y + xmin = xmin*scale_x + xmax = xmax*scale_x + ymin = ymin*scale_y + ymax = ymax*scale_y if(args.data_file_name is not None): if(args.x_label is not None): header_xlabel = args.x_label @@ -797,7 +803,7 @@ def init_lines(): print('# ', index_key, header_xlabel, header_ylabel, file=outputfile) for x_value, y_value in zip(x, y): - outstring = "%.9e"%(index_value)+" %.9e"%(x_value*scale_x)+" %.9e"%(y_value*scale_y)+"\n" + outstring = "%.9e"%(index_value)+" %.9e"%(x_value)+" %.9e"%(y_value)+"\n" outputfile.write(outstring) if(args.data_file_name is not None): print("data saved as -- "+args.data_file_name+'_'+filename.split('/')[-1]+'.'+re.sub(r'[^\w]','',yname)+'.dat') @@ -1003,28 +1009,40 @@ def init_contour(): if(args.data_file_name is not None): outputfile = open(args.data_file_name+'_'+filename.split('/')[-1]+'.'+re.sub(r'[^\w]','',yname)+'.dat', 'w') - vmin=(np.array(series_data[0][dname])*args.scale_value).min() - vmax=(np.array(series_data[0][dname])*args.scale_value).max() - xmin=(np.array(series_data[0][xname])*args.scale_x).min() - xmax=(np.array(series_data[0][xname])*args.scale_x).max() - ymin=(np.array(series_data[0][yname])*args.scale_y).min() - ymax=(np.array(series_data[0][yname])*args.scale_y).max() + vmin=(np.array(series_data[0][dname])).min() + vmax=(np.array(series_data[0][dname])).max() + xmin=(np.array(series_data[0][xname])).min() + xmax=(np.array(series_data[0][xname])).max() + ymin=(np.array(series_data[0][yname])).min() + ymax=(np.array(series_data[0][yname])).max() bias = 0.0 for data, index_value in zip(series_data, series_pair.index[index_key]): - v = np.array(data[dname])*args.scale_value + v = np.array(data[dname]) if(args.log_scale): bias = v.min() bias = 0.0 if bias>0.0 else abs(bias) v = np.array([ [log10(val+bias) if (val+bias)>0.0 else 0.0 for val in vals] for vals in v]) - x = np.array(data[xname])*args.scale_x - y = np.array(data[yname])*args.scale_y + vmin = v.min() + vmax = v.max() + x = np.array(data[xname]) + y = np.array(data[yname]) vmin = min(v.min(),vmin) vmax = max(v.max(),vmax) xmin = min(x.min(),xmin) xmax = max(x.max(),xmax) ymin = min(y.min(),ymin) ymax = max(y.max(),ymax) + # apply scaling + v = v*args.scale_value + x = x*args.scale_x + y = y*args.scale_y + vmin = vmin*args.scale_value + vmax = vmax*args.scale_value + xmin = xmin*args.scale_x + xmax = xmax*args.scale_x + ymin = ymin*args.scale_y + ymax = ymax*args.scale_y if(args.data_file_name is not None): if(args.x_label is not None): header_xlabel = args.x_label @@ -1038,7 +1056,7 @@ def init_contour(): print('# ', index_key, header_xlabel, header_ylabel, dname, file=outputfile) for x_value, y_value, v_value in zip(x, y, v): - outstring = "%.9e"%(index_value)+" %.9e"%(x_value*args.scale_x)+" %.9e"%(y_value*args.scale_y)+" %.9e"%(v_value*args.scale_value)+"\n" + outstring = "%.9e"%(index_value)+" %.9e"%(x_value)+" %.9e"%(y_value)+" %.9e"%(v_value)+"\n" outputfile.write(outstring) if(args.data_file_name is not None): print("data saved as -- "+args.data_file_name+'_'+filename.split('/')[-1]+'.'+re.sub(r'[^\w]','',dname)+'.dat') From b9bc29a9207120408037964575ef6bdc64680161 Mon Sep 17 00:00:00 2001 From: Cleveland Date: Fri, 31 Jan 2025 08:35:11 -0700 Subject: [PATCH 08/14] fix min max type casting --- opppy/plot_dump_dictionary.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/opppy/plot_dump_dictionary.py b/opppy/plot_dump_dictionary.py index 377ccb1..a7532e9 100644 --- a/opppy/plot_dump_dictionary.py +++ b/opppy/plot_dump_dictionary.py @@ -773,10 +773,10 @@ def init_lines(): if(args.data_file_name is not None): outputfile = open(args.data_file_name+'_'+filename.split('/')[-1]+'.'+re.sub(r'[^\w]','',yname)+'.dat', 'w') - xmin=(np.array(series_data[0][xname])).min() - xmax=(np.array(series_data[0][xname])).max() - ymin=(np.array(series_data[0][yname])).min() - ymax=(np.array(series_data[0][yname])).max() + xmin=np.array(series_data[0][xname]).min() + xmax=np.array(series_data[0][xname]).max() + ymin=np.array(series_data[0][yname]).min() + ymax=np.array(series_data[0][yname]).max() for data, index_value in zip(series_data, series_pair.index[index_key]): x = np.array(data[xname]) y = np.array(data[yname]) @@ -1009,13 +1009,12 @@ def init_contour(): if(args.data_file_name is not None): outputfile = open(args.data_file_name+'_'+filename.split('/')[-1]+'.'+re.sub(r'[^\w]','',yname)+'.dat', 'w') - vmin=(np.array(series_data[0][dname])).min() - vmax=(np.array(series_data[0][dname])).max() - xmin=(np.array(series_data[0][xname])).min() - xmax=(np.array(series_data[0][xname])).max() - ymin=(np.array(series_data[0][yname])).min() - ymax=(np.array(series_data[0][yname])).max() - bias = 0.0 + vmin=np.array(series_data[0][dname]).min() + vmax=np.array(series_data[0][dname]).max() + xmin=np.array(series_data[0][xname]).min() + xmax=np.array(series_data[0][xname]).max() + ymin=np.array(series_data[0][yname]).min() + ymax=np.array(series_data[0][yname]).max() for data, index_value in zip(series_data, series_pair.index[index_key]): v = np.array(data[dname]) if(args.log_scale): From 73ff697d6164649819e7048678939df54e54ae79 Mon Sep 17 00:00:00 2001 From: Cleveland Date: Fri, 31 Jan 2025 10:00:02 -0700 Subject: [PATCH 09/14] revert changes --- opppy/plot_dump_dictionary.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/opppy/plot_dump_dictionary.py b/opppy/plot_dump_dictionary.py index a7532e9..b3b5500 100644 --- a/opppy/plot_dump_dictionary.py +++ b/opppy/plot_dump_dictionary.py @@ -773,10 +773,10 @@ def init_lines(): if(args.data_file_name is not None): outputfile = open(args.data_file_name+'_'+filename.split('/')[-1]+'.'+re.sub(r'[^\w]','',yname)+'.dat', 'w') - xmin=np.array(series_data[0][xname]).min() - xmax=np.array(series_data[0][xname]).max() - ymin=np.array(series_data[0][yname]).min() - ymax=np.array(series_data[0][yname]).max() + xmin=(np.array(series_data[0][xname])).min() + xmax=(np.array(series_data[0][xname])).max() + ymin=(np.array(series_data[0][yname])).min() + ymax=(np.array(series_data[0][yname])).max() for data, index_value in zip(series_data, series_pair.index[index_key]): x = np.array(data[xname]) y = np.array(data[yname]) @@ -1009,12 +1009,13 @@ def init_contour(): if(args.data_file_name is not None): outputfile = open(args.data_file_name+'_'+filename.split('/')[-1]+'.'+re.sub(r'[^\w]','',yname)+'.dat', 'w') - vmin=np.array(series_data[0][dname]).min() - vmax=np.array(series_data[0][dname]).max() - xmin=np.array(series_data[0][xname]).min() - xmax=np.array(series_data[0][xname]).max() - ymin=np.array(series_data[0][yname]).min() - ymax=np.array(series_data[0][yname]).max() + vmin=(np.array(series_data[0][dname])).min() + vmax=(np.array(series_data[0][dname])).max() + xmin=(np.array(series_data[0][xname])).min() + xmax=(np.array(series_data[0][xname])).max() + ymin=(np.array(series_data[0][yname])).min() + ymax=(np.array(series_data[0][yname])).max() + bias = 0.0 for data, index_value in zip(series_data, series_pair.index[index_key]): v = np.array(data[dname]) if(args.log_scale): @@ -1022,8 +1023,6 @@ def init_contour(): bias = 0.0 if bias>0.0 else abs(bias) v = np.array([ [log10(val+bias) if (val+bias)>0.0 else 0.0 for val in vals] for vals in v]) - vmin = v.min() - vmax = v.max() x = np.array(data[xname]) y = np.array(data[yname]) vmin = min(v.min(),vmin) From dcc15b1f7dcd68f387843dd4047d65afc6425d8f Mon Sep 17 00:00:00 2001 From: Cleveland Date: Fri, 31 Jan 2025 10:06:47 -0700 Subject: [PATCH 10/14] alternative min max calls for dumps --- opppy/plot_dump_dictionary.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/opppy/plot_dump_dictionary.py b/opppy/plot_dump_dictionary.py index b3b5500..9bbdaa5 100644 --- a/opppy/plot_dump_dictionary.py +++ b/opppy/plot_dump_dictionary.py @@ -780,10 +780,10 @@ def init_lines(): for data, index_value in zip(series_data, series_pair.index[index_key]): x = np.array(data[xname]) y = np.array(data[yname]) - xmin = min(x.min(),xmin) - xmax = max(x.max(),xmax) - ymin = min(y.min(),ymin) - ymax = max(y.max(),ymax) + xmin = np.array([x.min(),xmin]).min() + xmax = np.array([x.max(),xmax]).max() + ymin = np.array([y.min(),ymin]).min() + ymax = np.array([y.max(),ymax]).max() x = x*scale_x y = y*scale_y xmin = xmin*scale_x @@ -1025,12 +1025,12 @@ def init_contour(): for val in vals] for vals in v]) x = np.array(data[xname]) y = np.array(data[yname]) - vmin = min(v.min(),vmin) - vmax = max(v.max(),vmax) - xmin = min(x.min(),xmin) - xmax = max(x.max(),xmax) - ymin = min(y.min(),ymin) - ymax = max(y.max(),ymax) + vmin = np.array([v.min(),vmin]).min() + vmax = np.array([v.max(),vmax]).max() + xmin = np.array([x.min(),xmin]).min() + xmax = np.array([x.max(),xmax]).max() + ymin = np.array([y.min(),ymin]).min() + ymax = np.array([y.max(),ymax]).max() # apply scaling v = v*args.scale_value x = x*args.scale_x From 759d3e9f33038f74ddfb133306c3f90d479f3cc0 Mon Sep 17 00:00:00 2001 From: Cleveland Date: Fri, 31 Jan 2025 10:27:14 -0700 Subject: [PATCH 11/14] prevent agressive numpy data type casting --- opppy/dump_utils.py | 2 +- tests/my_test_opppy_dump_parser.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/opppy/dump_utils.py b/opppy/dump_utils.py index 1d67294..131e3e5 100644 --- a/opppy/dump_utils.py +++ b/opppy/dump_utils.py @@ -515,7 +515,7 @@ def thread_all(file_name, key_words, result_d): result_d[file_name.split('/')[-1]] = opppy_parser.build_data_dictionary(file_name,key_words) print("Number of threads used for processing: ",nthreads) for stride in range(math.ceil(float(total)/float(nthreads))): - files = dump_files[nthreads*stride:min(int(nthreads*(stride+1)),len(dump_files))] + files = dump_files[nthreads*stride:array([nthreads*(stride+1),len(dump_files)]).min()] with Manager() as manager: result_d = manager.dict() threads = [] diff --git a/tests/my_test_opppy_dump_parser.py b/tests/my_test_opppy_dump_parser.py index 730fd6f..505c335 100644 --- a/tests/my_test_opppy_dump_parser.py +++ b/tests/my_test_opppy_dump_parser.py @@ -32,7 +32,7 @@ def build_data_dictionary(self, filename, dump_keys=None): for line in lines: for key in keys: if key in line and len(key) is len(line.split(':')[0]): - data[key] = array(str_vector_to_float_vector(line.strip('\n').split(' ')[1:])) + data[key] = array(str_vector_to_float_vector(line.strip('\n').split(' ')[1:])).astype(float) # build xy_verts for 2d mesh plotting example From 806f10038d6877185a1f305c1452d65b5deebdf6 Mon Sep 17 00:00:00 2001 From: Cleveland Date: Fri, 31 Jan 2025 10:37:26 -0700 Subject: [PATCH 12/14] more numpy1-numpy2 min/max fixes --- opppy/interactive_utils.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/opppy/interactive_utils.py b/opppy/interactive_utils.py index 5be2d97..5c4fd6c 100644 --- a/opppy/interactive_utils.py +++ b/opppy/interactive_utils.py @@ -389,8 +389,8 @@ def plot_output(self, args): # material specific plot for yname in plot_args.y_value_names: x.append(array(data[plot_args.x_value_name])) - ymin[-1] = min(ymin[-1],min(data[yname])) - ymax[-1] = max(ymin[-1],max(data[yname])) + ymin[-1] = array([ymin[-1],min(data[yname])]).min() + ymax[-1] = array([ymin[-1],max(data[yname])]).max() plabels.append(label+" "+yname) if (option.no_y_names): plabels[-1] = '' @@ -1248,8 +1248,8 @@ def plot_interactive_tally(self, args): # material specific plot for yname in plot_args.y_value_names: x.append(array(data[plot_args.x_value_name])) - ymin[-1] = min(ymin[-1],min(data[yname])) - ymax[-1] = max(ymin[-1],max(data[yname])) + ymin[-1] = array([ymin[-1],min(data[yname])]).min() + ymax[-1] = array([ymin[-1],max(data[yname])]).max() plabels.append(label+" "+yname) if (option.no_y_names): plabels[-1] = '' From 637b718a0a5ea5a952f1c3f7a3ba9f87e8242a3a Mon Sep 17 00:00:00 2001 From: Cleveland Date: Fri, 31 Jan 2025 10:51:58 -0700 Subject: [PATCH 13/14] add a diagnostic print --- tests/test_dump_utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_dump_utils.py b/tests/test_dump_utils.py index f22bd7f..443b92e 100644 --- a/tests/test_dump_utils.py +++ b/tests/test_dump_utils.py @@ -495,7 +495,7 @@ def test_data_2_line(self): def test_line_series(self): ''' - Thest the three different point value extraction functions + Test the three different point value extraction functions ''' from my_test_opppy_dump_parser import my_test_opppy_dump_parser @@ -543,6 +543,7 @@ def test_line_series(self): gold_data = pickle.load(goldfile) goldfile.close() for k, v in gold_data.items(): + print(k,v,check_data[k]) np.testing.assert_allclose(check_data[k],v) From 36b22f3eed3f20ff395c6f9ed283d896476a6ad0 Mon Sep 17 00:00:00 2001 From: Cleveland Date: Fri, 31 Jan 2025 11:21:53 -0700 Subject: [PATCH 14/14] fix ambiguous 1d/2d/3d dump parsing --- tests/example_1d_dump.txt | 12 ++++++++++++ tests/example_1d_dump_2.txt | 10 ++++++++++ tests/example_1d_dump_3.txt | 10 ++++++++++ tests/example_2d_dump.txt | 12 ++++++++++++ tests/example_2d_dump_2.txt | 11 +++++++++++ tests/example_2d_dump_3.txt | 12 ++++++++++++ tests/gold_dumps.p | Bin 15014 -> 14853 bytes tests/gold_line_data.p | Bin 1765 -> 1765 bytes tests/gold_sub_dumps.p | Bin 1013 -> 920 bytes tests/test_dump_utils.py | 31 ++++++++++++++++++++++++------- 10 files changed, 91 insertions(+), 7 deletions(-) create mode 100644 tests/example_1d_dump.txt create mode 100644 tests/example_1d_dump_2.txt create mode 100644 tests/example_1d_dump_3.txt create mode 100644 tests/example_2d_dump.txt create mode 100644 tests/example_2d_dump_2.txt create mode 100644 tests/example_2d_dump_3.txt diff --git a/tests/example_1d_dump.txt b/tests/example_1d_dump.txt new file mode 100644 index 0000000..24579e1 --- /dev/null +++ b/tests/example_1d_dump.txt @@ -0,0 +1,12 @@ +keys: time cell_id x y z density temperature pressure + +time: 1.0 + +cell_id: 1 2 3 4 +x: 1 2 3 4 5 +y: 1 1 1 1 1 +z: 1 1 1 1 1 +density: 1.1 1.1 1.1 1.1 1.1 +temperature: 3.1 3.1 3.1 3.1 3.1 +pressure: 5.1 5.1 5.1 5.1 5.1 + diff --git a/tests/example_1d_dump_2.txt b/tests/example_1d_dump_2.txt new file mode 100644 index 0000000..585d453 --- /dev/null +++ b/tests/example_1d_dump_2.txt @@ -0,0 +1,10 @@ +keys: time cell_id x y z density temperature pressure + +time: 2.0 + +cell_id: 1 2 3 4 5 +x: 1 2 3 4 5 +density: 1.2 1.2 1.2 1.2 1.2 +temperature: 3.2 3.2 3.2 3.2 3.2 +pressure: 5.2 5.2 5.2 5.2 5.2 + diff --git a/tests/example_1d_dump_3.txt b/tests/example_1d_dump_3.txt new file mode 100644 index 0000000..15a0cb9 --- /dev/null +++ b/tests/example_1d_dump_3.txt @@ -0,0 +1,10 @@ +keys: time cell_id x y z density temperature pressure + +time: 3.0 + +cell_id: 1 2 3 4 5 +x: 1 2 3 4 5 +density: 1.3 1.3 1.3 1.3 1.3 +temperature: 3.3 3.3 3.3 3.3 3.3 +pressure: 5.3 5.3 5.3 5.3 5.3 + diff --git a/tests/example_2d_dump.txt b/tests/example_2d_dump.txt new file mode 100644 index 0000000..bd49321 --- /dev/null +++ b/tests/example_2d_dump.txt @@ -0,0 +1,12 @@ +keys: time cell_id x y z density temperature pressure + +time: 1.0 + +cell_id: 1 2 3 4 5 6 7 8 9 10 +x: 1 2 3 4 5 1 2 3 4 5 +y: 1 1 1 1 1 2 2 2 2 2 +z: 1 1 1 1 1 1 1 1 1 1 +density: 1.1 1.1 1.1 1.1 1.1 2.1 2.1 2.1 2.1 2.1 +temperature: 3.1 3.1 3.1 3.1 3.1 4.1 4.1 4.1 4.1 4.1 +pressure: 5.1 5.1 5.1 5.1 5.1 6.1 6.1 6.1 6.1 6.1 + diff --git a/tests/example_2d_dump_2.txt b/tests/example_2d_dump_2.txt new file mode 100644 index 0000000..4ce907f --- /dev/null +++ b/tests/example_2d_dump_2.txt @@ -0,0 +1,11 @@ +keys: time cell_id x y z density temperature pressure + +time: 2.0 + +cell_id: 1 2 3 4 5 6 7 8 9 10 +x: 1 2 3 4 5 1 2 3 4 5 +y: 1 1 1 1 1 2 2 2 2 2 +density: 1.2 1.2 1.2 1.2 1.2 2.2 2.2 2.2 2.2 2.2 +temperature: 3.2 3.2 3.2 3.2 3.2 4.2 4.2 4.2 4.2 4.2 +pressure: 5.2 5.2 5.2 5.2 5.2 6.2 6.2 6.2 6.2 6.2 + diff --git a/tests/example_2d_dump_3.txt b/tests/example_2d_dump_3.txt new file mode 100644 index 0000000..12e43f5 --- /dev/null +++ b/tests/example_2d_dump_3.txt @@ -0,0 +1,12 @@ +keys: time cell_id x y z density temperature pressure + +time: 3.0 + +cell_id: 1 2 3 4 5 6 7 8 9 10 +x: 1 2 3 4 5 1 2 3 4 5 +y: 1 1 1 1 1 2 2 2 2 2 +z: 1 1 1 1 1 1 1 1 1 1 +density: 1.3 1.3 1.3 1.3 1.3 2.3 2.3 2.3 2.3 2.3 +temperature: 3.3 3.3 3.3 3.3 3.3 4.3 4.3 4.3 4.3 4.3 +pressure: 5.3 5.3 5.3 5.3 5.3 6.3 6.3 6.3 6.3 6.3 + diff --git a/tests/gold_dumps.p b/tests/gold_dumps.p index b55e85826c54debe554e2b84fac3d882f6402a12..8ae08da6cfc673d947901f3461f30914fd683c3e 100644 GIT binary patch literal 14853 zcmeI2&1+m`6o-@AkJMI3C6N?ds1ykyq+c!+#0+$2q=!X1k~GXrBoPERRSUE0 zb)hT&ApIZw6Dqn8H##%#`N8$%Irn`#1{d0)^pJa>Ip=xrJ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T6UZ{?H0s-U_^aLqTc1=p|cz!gXtxZ?`dMS?5j4Gf^S z@<|yuSEw!$T=NZ}w*prnW#C+)x=3(^ynz8+Tlu66oGVlp39eSI-i4xFUfVn!X(xLm zP)`8WMS^R-K|^mj10ZGKNT@CnTp@38TpN1J82~8*M?!Ux;0k#I*M{D520+Tdkx*SE YxI*5*6|Sv(QU=Zys*4=X*A7RW_lfU0fM_y1RW_sQn0e2iL?*%&ADr-6Z%1C*Y;0w^|XCJ1ObKd&dkr7(!*w;XQ*druu;C3(J_NHgCm36o1t|| y25O?^5Cd)AGC&CmC0;YH~uL1xyPBYQ~ delta 130 zcmbQi{*_(6fo19|W(F{*oubjhUY1%^oSC0DrH9o(&rr{Nqe3qudk;%VW^U?~$?F-# x1ciE-(k!NQcC=3knxf&&oFO)GjWiR3!^D#+j9Qc5G43a(RRFK2D^maf diff --git a/tests/test_dump_utils.py b/tests/test_dump_utils.py index 443b92e..b688a54 100644 --- a/tests/test_dump_utils.py +++ b/tests/test_dump_utils.py @@ -502,32 +502,49 @@ def test_line_series(self): # initialize my test dump parser dump_parser = my_test_opppy_dump_parser() - data = [] + data3d = [] filename = dir_path + "example_dump.txt" # extract all data from the example dump file - data.append(dump_parser.build_data_dictionary(filename)) + data3d.append(dump_parser.build_data_dictionary(filename)) filename = dir_path + "example_dump2.txt" - data.append(dump_parser.build_data_dictionary(filename)) + data3d.append(dump_parser.build_data_dictionary(filename)) filename = dir_path + "example_dump3.txt" - data.append(dump_parser.build_data_dictionary(filename)) + data3d.append(dump_parser.build_data_dictionary(filename)) + data2d = [] + filename = dir_path + "example_2d_dump.txt" + # extract all data from the example dump file + data2d.append(dump_parser.build_data_dictionary(filename)) + filename = dir_path + "example_2d_dump_2.txt" + data2d.append(dump_parser.build_data_dictionary(filename)) + filename = dir_path + "example_2d_dump_3.txt" + data2d.append(dump_parser.build_data_dictionary(filename)) + data1d = [] + filename = dir_path + "example_1d_dump.txt" + # extract all data from the example dump file + data1d.append(dump_parser.build_data_dictionary(filename)) + filename = dir_path + "example_1d_dump_2.txt" + data1d.append(dump_parser.build_data_dictionary(filename)) + filename = dir_path + "example_1d_dump_3.txt" + data1d.append(dump_parser.build_data_dictionary(filename)) + check_data = {} # extract a 1D data value - tracer_t, tracer_grid = extract_series_line(data,'time',"temperature",['x'], [1.0], [5.0], npts=5 ) + tracer_t, tracer_grid = extract_series_line(data1d,'time',"temperature",['x'], [1.0], [5.0], npts=5 ) check_data['time1'] = np.array([t[0] for t in tracer_t['time']]) for i in range(len(check_data['time1'])): check_data['temperature1'+str(i)] = tracer_grid[i]['temperature'] check_data['x1'+str(i)] = tracer_grid[i]['distance'] print(tracer_t, tracer_grid) - tracer_t, tracer_grid = extract_series_line(data,'time',"temperature",['x','y'], [5.0, 1.0], [5.0, 2.0], npts=5 ) + tracer_t, tracer_grid = extract_series_line(data2d,'time',"temperature",['x','y'], [5.0, 1.0], [5.0, 2.0], npts=5 ) check_data['time2'] = np.array([t[0] for t in tracer_t['time']]) for i in range(len(check_data['time2'])): check_data['temperature2'+str(i)] = tracer_grid[i]['temperature'] check_data['x2'+str(i)] = tracer_grid[i]['distance'] print(tracer_t, tracer_grid) - tracer_t, tracer_grid = extract_series_line(data,'time',"temperature",['x','y','z'], [5.0, 1.0, 1.2], [5.0, 2.0, 1.75], npts=5 ) + tracer_t, tracer_grid = extract_series_line(data3d,'time',"temperature",['x','y','z'], [5.0, 1.0, 1.2], [5.0, 2.0, 1.75], npts=5 ) check_data['time3'] = np.array([t[0] for t in tracer_t['time']]) for i in range(len(check_data['time3'])): check_data['temperature3'+str(i)] = tracer_grid[i]['temperature']