diff --git a/DG_Approximation.py b/DG_Approximation.py index e09819fc8c98be94947cd89ef8d5b0c914d3a1e3..ea826715fc6a3210ecefac5f6f73fc360097ec14 100644 --- a/DG_Approximation.py +++ b/DG_Approximation.py @@ -12,6 +12,7 @@ TODO: Force input_size for each ANN model to be stencil length TODO: Combine ANN workflows TODO: Unify use of 'length' and 'len' in naming TODO: Add an environment file for Snakemake +TODO: Make all directories local variable -> Done Critical, but not urgent: TODO: Use cfl_number for updating, not just time @@ -121,8 +122,6 @@ class DGScheme: Right boundary of interval. Default: 1. verbose : bool, optional Flag whether commentary in console is wanted. Default: False. - plot_dir : str, optional - Path to directory in which plots are saved. Default: 'test'. history_threshold : float, optional Threshold when history will be recorded. Default: math.ceil(0.2/cfl_number). @@ -153,7 +152,6 @@ class DGScheme: self._left_bound = kwargs.pop('left_bound', -1) self._right_bound = kwargs.pop('right_bound', 1) self._verbose = kwargs.pop('verbose', False) - self._plot_dir = kwargs.pop('plot_dir', 'testing') self._history_threshold = kwargs.pop('history_threshold', math.ceil(0.2/self._cfl_number)) self._detector = detector @@ -203,7 +201,7 @@ class DGScheme: self._polynomial_degree, self._num_grid_cells, self._detector, self._limiter) - def approximate(self, data_name): + def approximate(self, data_dir, data_name): """Approximates projection. Initializes projection and evolves it in time. Each time step consists @@ -215,6 +213,8 @@ class DGScheme: Attributes ---------- + data_dir: str + Path to directory in which data is saved. data_name : str Name of data. @@ -254,12 +254,12 @@ class DGScheme: for key in approx_stats.keys()} # Save approximation results in JSON format - with open(self._plot_dir+'/' + data_name + '.json', 'w') \ + with open(data_dir + '/' + data_name + '.json', 'w') \ as json_file: json_file.write(json.dumps(approx_stats)) # Read approximation results - with open(self._plot_dir+'/' + data_name + '.json') as json_file: + with open(data_dir + '/' + data_name + '.json') as json_file: approx_stats = json.load(json_file) # Decode all ndarrays by converting lists @@ -270,7 +270,7 @@ class DGScheme: # and any detector-dependant plots self._detector.plot_results(**approx_stats) - def save_plots(self, plot_name): + def save_plots(self, plot_dir, plot_name): """Saves plotted results. Sets plot directory, if not already existing, and saves plots @@ -278,22 +278,24 @@ class DGScheme: Parameters ---------- + plot_dir: str + Path to directory in which plots are saved. plot_name : str Name of plot. """ # Set paths for plot files if not existing already - if not os.path.exists(self._plot_dir): - os.makedirs(self._plot_dir) + if not os.path.exists(plot_dir): + os.makedirs(plot_dir) # Save plots for identifier in plt.get_figlabels(): # Set path for figure directory if not existing already - if not os.path.exists(self._plot_dir + '/' + identifier): - os.makedirs(self._plot_dir + '/' + identifier) + if not os.path.exists(plot_dir + '/' + identifier): + os.makedirs(plot_dir + '/' + identifier) plt.figure(identifier) - plt.savefig(self._plot_dir + '/' + identifier + '/' + + plt.savefig(plot_dir + '/' + identifier + '/' + plot_name + '.pdf') def _reset(self): diff --git a/workflows/approximation.smk b/workflows/approximation.smk index fa509bbc75d103943d41d1a352b88e722af0d2fa..75f7982f33ea9e2ba28d864ac80aed08dce7fa34 100644 --- a/workflows/approximation.smk +++ b/workflows/approximation.smk @@ -46,10 +46,12 @@ rule approximate_solution: params.dg_params['detector_config']['model_state'] = input print(params.dg_params) - dg_scheme = DGScheme(plot_dir=params.plot_dir, **params.dg_params) + dg_scheme = DGScheme(**params.dg_params) - dg_scheme.approximate(wildcards.scheme) - dg_scheme.save_plots(wildcards.scheme) + dg_scheme.approximate(data_dir=params.plot_dir, + data_name=wildcards.scheme) + dg_scheme.save_plots(plot_dir=params.plot_dir, + plot_name=wildcards.scheme) toc = time.perf_counter() print(f'Time: {toc - tic:0.4f}s') \ No newline at end of file