From 5d91184ec2cd08661b168077f19c55c66bc46661 Mon Sep 17 00:00:00 2001 From: jeipollack Date: Mon, 13 Nov 2023 18:59:03 +0100 Subject: [PATCH 01/23] Removed unused imports --- src/wf_psf/tests/test_utils/conftest.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/wf_psf/tests/test_utils/conftest.py b/src/wf_psf/tests/test_utils/conftest.py index 279601df..4d2f77b0 100644 --- a/src/wf_psf/tests/test_utils/conftest.py +++ b/src/wf_psf/tests/test_utils/conftest.py @@ -8,9 +8,6 @@ """ import pytest - -from wf_psf.utils.read_config import RecursiveNamespace -from wf_psf.utils.io import FileIOHandler import os cwd = os.getcwd() From 415e0802b188c5dd4770f2224091a461df9c3699 Mon Sep 17 00:00:00 2001 From: jeipollack Date: Mon, 13 Nov 2023 19:00:00 +0100 Subject: [PATCH 02/23] Added unit tests for configs_handler_test config_class methods --- .../tests/test_utils/configs_handler_test.py | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/wf_psf/tests/test_utils/configs_handler_test.py diff --git a/src/wf_psf/tests/test_utils/configs_handler_test.py b/src/wf_psf/tests/test_utils/configs_handler_test.py new file mode 100644 index 00000000..42a9b8ab --- /dev/null +++ b/src/wf_psf/tests/test_utils/configs_handler_test.py @@ -0,0 +1,52 @@ +"""UNIT TESTS FOR PACKAGE MODULE: CONFIGS_HANDLER. + +This module contains unit tests for the wf_psf.utils configs_handler module. + +:Author: Jennifer Pollack + + +""" + +import pytest +from wf_psf.utils import configs_handler +from wf_psf.utils.io import FileIOHandler +import os + + +@configs_handler.register_configclass +class TestClass: + ids = ("test_conf",) + + def __init__(self, config_params, file_handler): + self.config_param = config_params + self.file_handler = file_handler + + +def test_register_configclass(): + assert configs_handler.CONFIG_CLASS["test_conf"] == TestClass + + +def test_set_run_config(): + config_class = configs_handler.set_run_config("test_conf") + assert config_class == TestClass + + config_class = configs_handler.set_run_config("training_conf") + assert config_class == configs_handler.TrainingConfigHandler + + config_class = configs_handler.set_run_config("metrics_conf") + assert config_class == configs_handler.MetricsConfigHandler + + config_class = configs_handler.set_run_config("plotting_conf") + assert config_class == configs_handler.PlottingConfigHandler + + +def test_get_run_config(path_to_repo_dir, path_to_tmp_output_dir, path_to_config_dir): + test_file_handler = FileIOHandler( + path_to_repo_dir, path_to_tmp_output_dir, path_to_config_dir + ) + + config_class = configs_handler.get_run_config( + "test_conf", "fake_config.yaml", test_file_handler + ) + + assert type(config_class) is TestClass From c1b1fcdffda876056b873a294712d905ed0b75f0 Mon Sep 17 00:00:00 2001 From: jeipollack Date: Tue, 14 Nov 2023 17:33:58 +0100 Subject: [PATCH 03/23] Added unit test for MetricsConfigHandler weights_basename attr --- .../tests/test_utils/configs_handler_test.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/wf_psf/tests/test_utils/configs_handler_test.py b/src/wf_psf/tests/test_utils/configs_handler_test.py index 42a9b8ab..3540fb68 100644 --- a/src/wf_psf/tests/test_utils/configs_handler_test.py +++ b/src/wf_psf/tests/test_utils/configs_handler_test.py @@ -50,3 +50,23 @@ def test_get_run_config(path_to_repo_dir, path_to_tmp_output_dir, path_to_config ) assert type(config_class) is TestClass + + +def test_MetricsConfigHandler_weights_basename_filepath( + path_to_repo_dir, path_to_tmp_output_dir, path_to_config_dir +): + test_file_handler = FileIOHandler( + path_to_repo_dir, path_to_tmp_output_dir, path_to_config_dir + ) + + metrics_config_file = "metrics_config.yaml" + + metrics_object = configs_handler.MetricsConfigHandler( + os.path.join(path_to_config_dir, metrics_config_file), test_file_handler + ) + weights_filepath = metrics_object.weights_basename_filepath + + assert ( + weights_filepath + == "src/wf_psf/tests/data/validation/main_random_seed/checkpoint/checkpoint*_poly*_sample_w_bis1_2k_cycle2*" + ) From 72a39893f23a607f76f7a2ba490f899ede70f573 Mon Sep 17 00:00:00 2001 From: jeipollack Date: Tue, 14 Nov 2023 17:53:04 +0100 Subject: [PATCH 04/23] Added new func to get model weights and Custom Exception Handling --- src/wf_psf/psf_models/psf_models.py | 41 +++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/src/wf_psf/psf_models/psf_models.py b/src/wf_psf/psf_models/psf_models.py index d75d3d96..bcfec0b4 100644 --- a/src/wf_psf/psf_models/psf_models.py +++ b/src/wf_psf/psf_models/psf_models.py @@ -12,6 +12,7 @@ from tensorflow.python.keras.engine import data_adapter from wf_psf.utils.utils import PI_zernikes, zernike_generator from wf_psf.sims.SimPSFToolkit import SimPSFToolkit +import glob from sys import exit import logging @@ -21,7 +22,13 @@ class PsfModelError(Exception): - pass + """PSF Model Parameter Error exception class for specific error scenarios.""" + + def __init__( + self, message="An error with your PSF model parameter settings occurred." + ): + self.message = message + super().__init__(self.message) def register_psfclass(psf_class): @@ -67,10 +74,9 @@ def set_psf_model(model_name): try: psf_class = PSF_CLASS[model_name] - except KeyError: - logger.exception("PSF model entered is invalid. Check your config settings.") - exit() - + except KeyError as e: + logger.exception(e) + raise PsfModelError("PSF model entered is invalid. Check your config settings.") return psf_class @@ -102,6 +108,31 @@ def get_psf_model(model_params, training_hparams, *coeff_matrix): return psf_class(model_params, training_hparams, *coeff_matrix) +def get_psf_model_weights_filepath(weights_filepath): + """Get PSF model weights filepath. + + A function to return the basename of the user-specified psf model weights path. + + Parameters + ---------- + weights_filepath: str + Basename of the psf model weights to be loaded. + + Returns + ------- + str + The absolute path concatenated to the basename of the psf model weights to be loaded. + + """ + try: + return glob.glob(weights_filepath)[0].split(".")[0] + except IndexError: + logger.exception( + "PSF weights file not found. Check that you've specified the correct weights file in the metrics config file." + ) + raise PsfModelError("PSF model weights error.") + + def tf_zernike_cube(n_zernikes, pupil_diam): """Tensor Flow Zernike Cube. From 472244297eba6f5ce7aedd75e4f781b4e9e9084f Mon Sep 17 00:00:00 2001 From: jeipollack Date: Tue, 14 Nov 2023 17:53:34 +0100 Subject: [PATCH 05/23] Added unit test for new psf_models get weights method --- src/wf_psf/tests/psf_models_test.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/wf_psf/tests/psf_models_test.py diff --git a/src/wf_psf/tests/psf_models_test.py b/src/wf_psf/tests/psf_models_test.py new file mode 100644 index 00000000..fbbb1191 --- /dev/null +++ b/src/wf_psf/tests/psf_models_test.py @@ -0,0 +1,23 @@ +"""UNIT TESTS FOR PACKAGE MODULE: PSF MODELS. + +This module contains unit tests for the wf_psf.psf_models psf_models module. + +:Author: Jennifer Pollack + + +""" + +import pytest +from wf_psf.psf_models import psf_models +from wf_psf.utils.io import FileIOHandler +import os + + +def test_get_psf_model_weights_filepath(): + weights_filepath = "src/wf_psf/tests/data/validation/main_random_seed/checkpoint/checkpoint*_poly*_sample_w_bis1_2k_cycle2*" + + ans = psf_models.get_psf_model_weights_filepath(weights_filepath) + assert ( + ans + == "src/wf_psf/tests/data/validation/main_random_seed/checkpoint/checkpoint_callback_poly_sample_w_bis1_2k_cycle2" + ) From 35cb887e67e8e20c12f3b347a94d54b2d881c9f7 Mon Sep 17 00:00:00 2001 From: jeipollack Date: Tue, 14 Nov 2023 17:54:49 +0100 Subject: [PATCH 06/23] Reformatted with black --- src/wf_psf/utils/io.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/wf_psf/utils/io.py b/src/wf_psf/utils/io.py index 1bc646ef..bb822448 100644 --- a/src/wf_psf/utils/io.py +++ b/src/wf_psf/utils/io.py @@ -193,7 +193,9 @@ def copy_conffile_to_output_dir(self, source_file): """ source = os.path.join(self.config_path, source_file) - destination = os.path.join(self.get_config_dir(self._run_output_dir), source_file) + destination = os.path.join( + self.get_config_dir(self._run_output_dir), source_file + ) shutil.copy(source, destination) From 3dde2ce82472028fe8dc1b02be34cbd9f40a33c1 Mon Sep 17 00:00:00 2001 From: jeipollack Date: Tue, 14 Nov 2023 18:02:14 +0100 Subject: [PATCH 07/23] Added metrics config yaml file --- .../config/metrics_config.yaml | 123 ++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 src/wf_psf/tests/data/validation/main_random_seed/config/metrics_config.yaml diff --git a/src/wf_psf/tests/data/validation/main_random_seed/config/metrics_config.yaml b/src/wf_psf/tests/data/validation/main_random_seed/config/metrics_config.yaml new file mode 100644 index 00000000..f3fcd12e --- /dev/null +++ b/src/wf_psf/tests/data/validation/main_random_seed/config/metrics_config.yaml @@ -0,0 +1,123 @@ +metrics: + # Specify the type of model weights to load by entering "psf_model" to load weights of final psf model or "checkpoint" to load weights from a checkpoint callback. + model_save_path: checkpoint + # Choose the training cycle for which to evaluate the psf_model. Can be: 1, 2, ... + saved_training_cycle: 2 + # Metrics-only run: Specify model_params for a pre-trained model else leave blank if running training + metrics + # Specify path to Parent Directory of Trained Model + trained_model_path: src/wf_psf/tests/data/validation/main_random_seed + # Name of the Trained Model Config file stored in config sub-directory in the trained_model_path parent directory + trained_model_config: training_config.yaml + #Evaluate the monchromatic RMSE metric. + eval_mono_metric_rmse: True + #Evaluate the OPD RMSE metric. + eval_opd_metric_rmse: True + #Evaluate the super-resolution and the shape RMSE metrics for the train dataset. + eval_train_shape_sr_metric_rmse: True + # Name of Plotting Config file - Enter name of yaml file to run plot metrics else if empty run metrics evaluation only + plotting_config: + ground_truth_model: + model_params: + #Model used as ground truth for the evaluation. Options are: 'poly' for polychromatic and 'physical' [not available]. + model_name: poly + + # Evaluation parameters + #Number of bins used for the ground truth model poly PSF generation + n_bins_lda: 20 + + #Downsampling rate to match the oversampled model to the specified telescope's sampling. + output_Q: 3 + + #Oversampling rate used for the OPD/WFE PSF model. + oversampling_rate: 3 + + #Dimension of the pixel PSF postage stamp + output_dim: 32 + + #Dimension of the OPD/Wavefront space." + pupil_diameter: 256 + + #Boolean to define if we use sample weights based on the noise standard deviation estimation + use_sample_weights: True + + #Interpolation type for the physical poly model. Options are: 'none', 'all', 'top_K', 'independent_Zk'." + interpolation_type: None + + # SED intepolation points per bin + sed_interp_pts_per_bin: 0 + + # SED extrapolate + sed_extrapolate: True + + # SED interpolate kind + sed_interp_kind: linear + + # Standard deviation of the multiplicative SED Gaussian noise. + sed_sigma: 0 + + #Limits of the PSF field coordinates for the x axis. + x_lims: [0.0, 1.0e+3] + + #Limits of the PSF field coordinates for the y axis. + y_lims: [0.0, 1.0e+3] + + # Hyperparameters for Parametric model + param_hparams: + # Random seed for Tensor Flow Initialization + random_seed: 3877572 + + # Parameter for the l2 loss function for the Optical path differences (OPD)/WFE + l2_param: 0. + + #Zernike polynomial modes to use on the parametric part. + n_zernikes: 45 + + #Max polynomial degree of the parametric part. + d_max: 2 + + #Flag to save optimisation history for parametric model + save_optim_history_param: true + + # Hyperparameters for non-parametric model + nonparam_hparams: + #Max polynomial degree of the non-parametric part. + d_max_nonparam: 5 + + # Number of graph features + num_graph_features: 10 + + #L1 regularisation parameter for the non-parametric part." + l1_rate: 1.0e-8 + + #Flag to enable Projected learning for DD_features to be used with `poly` or `semiparametric` model. + project_dd_features: False + + #Flag to reset DD_features to be used with `poly` or `semiparametric` model + reset_dd_features: False + + #Flag to save optimisation history for non-parametric model + save_optim_history_nonparam: True + + metrics_hparams: + # Batch size to use for the evaluation. + batch_size: 16 + + #Save RMS error for each super resolved PSF in the test dataset in addition to the mean across the FOV." + #Flag to get Super-Resolution pixel PSF RMSE for each individual test star. + #If `True`, the relative pixel RMSE of each star is added to ther saving dictionary. + opt_stars_rel_pix_rmse: False + + ## Specific parameters + # Parameter for the l2 loss of the OPD. + l2_param: 0. + + ## Define the resolution at which you'd like to measure the shape of the PSFs + #Downsampling rate from the high-resolution pixel modelling space. + # Recommended value: 1 + output_Q: 1 + + #Dimension of the pixel PSF postage stamp; it should be big enough so that most of the signal is contained inside the postage stamp. + # It also depends on the Q values used. + # Recommended value: 64 or higher + output_dim: 64 + From f4cddb5b445d127ead9312aa2d1220157c2ab048 Mon Sep 17 00:00:00 2001 From: jeipollack Date: Tue, 14 Nov 2023 18:02:54 +0100 Subject: [PATCH 08/23] Changed id name for testing --- .../validation/main_random_seed/config/training_config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wf_psf/tests/data/validation/main_random_seed/config/training_config.yaml b/src/wf_psf/tests/data/validation/main_random_seed/config/training_config.yaml index 5c398cbe..ef1f0635 100644 --- a/src/wf_psf/tests/data/validation/main_random_seed/config/training_config.yaml +++ b/src/wf_psf/tests/data/validation/main_random_seed/config/training_config.yaml @@ -1,6 +1,6 @@ training: # ID name - id_name: _validation + id_name: _sample_w_bis1_2k # Name of Data Config file data_config: data_config.yaml # Metrics Config file - Enter file to run metrics evaluation else if empty run train only From 42cf087a85c53de65c6df0b19c122abf0af7a8fe Mon Sep 17 00:00:00 2001 From: jeipollack Date: Tue, 14 Nov 2023 18:03:32 +0100 Subject: [PATCH 09/23] Changed path to metrics config file --- src/wf_psf/tests/test_utils/configs_handler_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wf_psf/tests/test_utils/configs_handler_test.py b/src/wf_psf/tests/test_utils/configs_handler_test.py index 3540fb68..5e8db118 100644 --- a/src/wf_psf/tests/test_utils/configs_handler_test.py +++ b/src/wf_psf/tests/test_utils/configs_handler_test.py @@ -59,7 +59,7 @@ def test_MetricsConfigHandler_weights_basename_filepath( path_to_repo_dir, path_to_tmp_output_dir, path_to_config_dir ) - metrics_config_file = "metrics_config.yaml" + metrics_config_file = "validation/main_random_seed/config/metrics_config.yaml" metrics_object = configs_handler.MetricsConfigHandler( os.path.join(path_to_config_dir, metrics_config_file), test_file_handler From f7be0be6e5aba04aa0a756000c6baafa5325dab0 Mon Sep 17 00:00:00 2001 From: jeipollack Date: Tue, 14 Nov 2023 18:03:58 +0100 Subject: [PATCH 10/23] Changed path to config fixture --- src/wf_psf/tests/test_utils/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wf_psf/tests/test_utils/conftest.py b/src/wf_psf/tests/test_utils/conftest.py index 4d2f77b0..6df37416 100644 --- a/src/wf_psf/tests/test_utils/conftest.py +++ b/src/wf_psf/tests/test_utils/conftest.py @@ -30,4 +30,4 @@ def path_to_tmp_output_dir(tmp_path): @pytest.fixture def path_to_config_dir(path_to_test_dir): - return os.path.join(path_to_test_dir, "data", "config") + return os.path.join(path_to_test_dir, "data") From b82104de1309bcc727f3e12e7a8b2761038a7f8f Mon Sep 17 00:00:00 2001 From: jeipollack Date: Tue, 14 Nov 2023 18:04:41 +0100 Subject: [PATCH 11/23] Refactored MetricsConfigHandler --- src/wf_psf/utils/configs_handler.py | 158 ++++++++++++++-------------- 1 file changed, 81 insertions(+), 77 deletions(-) diff --git a/src/wf_psf/utils/configs_handler.py b/src/wf_psf/utils/configs_handler.py index c55409c1..bfd573de 100644 --- a/src/wf_psf/utils/configs_handler.py +++ b/src/wf_psf/utils/configs_handler.py @@ -97,9 +97,18 @@ def get_run_config(run_config, config_params, file_handler): """ config_class = set_run_config(run_config) + return config_class(config_params, file_handler) +class ConfigParameterError(Exception): + """Custom Config Parameter Error exception class for specific error scenarios.""" + + def __init__(self, message="An error with your config settings occurred."): + self.message = message + super().__init__(self.message) + + class DataConfigHandler: """DataConfigHandler. @@ -237,95 +246,97 @@ class MetricsConfigHandler: ids = ("metrics_conf",) def __init__(self, metrics_conf, file_handler, training_conf=None): - self.metrics_conf = read_conf(metrics_conf) - self.metrics_dir = file_handler.get_metrics_dir(file_handler._run_output_dir) - self.file_handler = file_handler + self._metrics_conf = read_conf(metrics_conf) + self._file_handler = file_handler + self._training_conf = self._load_training_conf(training_conf) + + @property + def metrics_conf(self): + return self._metrics_conf + + @property + def metrics_dir(self): + return self._file_handler.get_metrics_dir(self._file_handler._run_output_dir) + + @property + def training_conf(self): + return self._training_conf + + @property + def plotting_conf(self): + return self.metrics_conf.metrics.plotting_config + + @property + def data_conf(self): + return self._load_data_conf() + + @property + def psf_model(self): + return psf_models.get_psf_model( + self.training_conf.training.model_params, + self.training_conf.training.training_hparams, + ) + def weights_path(self): + return psf_models.get_psf_model_weights_filepath(self.weights_basename_filepath) + + def _load_training_conf(self, training_conf): if training_conf is None: try: - self.training_conf = read_conf( - os.path.join( - self.file_handler.get_config_dir( - self.metrics_conf.metrics.trained_model_path - ), - self.metrics_conf.metrics.trained_model_config, - ) + model_config_path = os.path.join( + self._file_handler.get_config_dir( + self._metrics_conf.metrics.trained_model_path + ), + self._metrics_conf.metrics.trained_model_config, ) + return read_conf(model_config_path) except TypeError: - logger.info( + logger.error( "Check metrics config file trained model path or config values are empty." ) - exit() - - self.trained_model_workdir = os.path.join( - self.metrics_conf.metrics.trained_model_path - ) - - else: - self.training_conf = training_conf + raise ConfigParameterError("Configuration loading error.") - self.trained_model_workdir = os.path.join( - self.file_handler.output_path, - self.file_handler.parent_output_dir, - self.file_handler.workdir, - ) - - self.plotting_conf = self.metrics_conf.metrics.plotting_config + return training_conf + def _load_data_conf(self): try: - self.data_conf = DataConfigHandler( + return DataConfigHandler( os.path.join( - self.file_handler.config_path, + self._file_handler.config_path, self.training_conf.training.data_config, ), self.training_conf.training.model_params, ) except TypeError as e: logger.exception(e) + raise ConfigParameterError("Data configuration loading error.") - self.psf_model = psf_models.get_psf_model( - self.training_conf.training.model_params, - self.training_conf.training.training_hparams, - ) - self.weights_path = self.get_psf_model_weights_filepath() - - def get_psf_model_weights_filepath(self): + @property + def weights_basename_filepath(self): """Get PSF model weights filepath. A function to return the basename of the user-specified psf model weights path. Returns ------- - weights_filepath: str + weights_basename: str The basename of the psf model weights to be loaded. """ - weights_basename = ( - self.metrics_conf.metrics.model_save_path - + "*_" - + self.training_conf.training.model_params.model_name - + "*" - + self.training_conf.training.id_name - + "_cycle" - + str(self.metrics_conf.metrics.saved_training_cycle) - + "*" + return os.path.join( + self.metrics_conf.metrics.trained_model_path, + self.metrics_conf.metrics.model_save_path, + ( + self.metrics_conf.metrics.model_save_path + + "*_" + + self.training_conf.training.model_params.model_name + + "*" + + self.training_conf.training.id_name + + "_cycle" + + str(self.metrics_conf.metrics.saved_training_cycle) + + "*" + ), ) - try: - weights_filepath = glob.glob( - os.path.join( - self.trained_model_workdir, - self.metrics_conf.metrics.model_save_path, - weights_basename, - ) - )[0].split(".")[0] - - except IndexError: - logger.error( - "PSF weights file not found. Check that you've specified the correct weights file in the metrics config file." - ) - exit() - - return weights_filepath def call_plot_config_handler_run(self, model_metrics): """Make Metrics Plots. @@ -341,23 +352,23 @@ def call_plot_config_handler_run(self, model_metrics): of the trained PSF model. """ - self.plotting_conf = os.path.join( - self.file_handler.config_path, - self.metrics_conf.metrics.plotting_config, + self._plotting_conf = os.path.join( + self._file_handler.config_path, + self.plotting_conf, ) plots_config_handler = PlottingConfigHandler( - self.plotting_conf, - self.file_handler, + self._plotting_conf, + self._file_handler, ) # Update metrics_confs dict with latest result plots_config_handler.metrics_confs[ - self.file_handler.workdir + self._file_handler.workdir ] = self.metrics_conf # Update metric results dict with latest result - plots_config_handler.list_of_metrics_dict[self.file_handler.workdir] = [ + plots_config_handler.list_of_metrics_dict[self._file_handler.workdir] = [ { self.training_conf.training.model_params.model_name + self.training_conf.training.id_name: [model_metrics] @@ -387,7 +398,7 @@ def run(self): ) if self.plotting_conf is not None: - self.file_handler.copy_conffile_to_output_dir( + self._file_handler.copy_conffile_to_output_dir( self.metrics_conf.metrics.plotting_config ) self.call_plot_config_handler_run(model_metrics) @@ -478,7 +489,7 @@ def _metrics_run_id_name(self, wf_outdir, metrics_params): Parameters ---------- wf_outdir: str - Name of the wf-psf run output directory + Name of the wf-psf run output directory metrics_params: RecursiveNamespace Object RecursiveNamespace object containing the metrics parameters used to evaluated the trained model. @@ -507,13 +518,6 @@ def _metrics_run_id_name(self, wf_outdir, metrics_params): ) ) - training_config_files = glob.glob( - os.path.join( - self.plotting_conf.plotting_params.metrics_output_path, - self.file_handler.get_config_dir(wf_outdir), - "training*", - ) - ) training_confs = [ read_conf(training_conf) for training_conf in glob.glob( From b2cfcd45c6854e8a067cd8bbc65c4dadd4a5dd5b Mon Sep 17 00:00:00 2001 From: jeipollack Date: Tue, 14 Nov 2023 18:26:45 +0100 Subject: [PATCH 12/23] Added missing @property to weights_path --- src/wf_psf/utils/configs_handler.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/wf_psf/utils/configs_handler.py b/src/wf_psf/utils/configs_handler.py index bfd573de..a51f511c 100644 --- a/src/wf_psf/utils/configs_handler.py +++ b/src/wf_psf/utils/configs_handler.py @@ -277,6 +277,7 @@ def psf_model(self): self.training_conf.training.training_hparams, ) + @property def weights_path(self): return psf_models.get_psf_model_weights_filepath(self.weights_basename_filepath) @@ -387,6 +388,7 @@ def run(self): logger.info( "Running metrics evaluation on psf model: {}".format(self.weights_path) ) + breakpoint() model_metrics = evaluate_model( self.metrics_conf.metrics, self.training_conf.training, From 6d9094db8dd5d24ca14d2f0c0b2bf428486b9f98 Mon Sep 17 00:00:00 2001 From: jeipollack Date: Tue, 14 Nov 2023 18:39:02 +0100 Subject: [PATCH 13/23] Removed accidental pdb --- src/wf_psf/utils/configs_handler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wf_psf/utils/configs_handler.py b/src/wf_psf/utils/configs_handler.py index a51f511c..0be39d17 100644 --- a/src/wf_psf/utils/configs_handler.py +++ b/src/wf_psf/utils/configs_handler.py @@ -388,7 +388,7 @@ def run(self): logger.info( "Running metrics evaluation on psf model: {}".format(self.weights_path) ) - breakpoint() + model_metrics = evaluate_model( self.metrics_conf.metrics, self.training_conf.training, From 10bc2acec8bbaad298e7655bc586bdb1abc33842 Mon Sep 17 00:00:00 2001 From: jeipollack Date: Tue, 14 Nov 2023 21:22:04 +0100 Subject: [PATCH 14/23] Added missing method to set trained_model_path --- src/wf_psf/utils/configs_handler.py | 77 ++++++++++++++++++++++------- 1 file changed, 58 insertions(+), 19 deletions(-) diff --git a/src/wf_psf/utils/configs_handler.py b/src/wf_psf/utils/configs_handler.py index 0be39d17..ea43d92c 100644 --- a/src/wf_psf/utils/configs_handler.py +++ b/src/wf_psf/utils/configs_handler.py @@ -281,23 +281,68 @@ def psf_model(self): def weights_path(self): return psf_models.get_psf_model_weights_filepath(self.weights_basename_filepath) - def _load_training_conf(self, training_conf): + def _get_trained_model_path(self, training_conf): + """Get Trained Model Path. + + Helper method to get the trained model path. + + Parameters + ---------- + training_conf: None or RecursiveNamespace + None type or RecursiveNamespace + + Returns + ------- + str + A string representing the path to the trained model output run directory. + + """ if training_conf is None: try: - model_config_path = os.path.join( + return os.path.join( self._file_handler.get_config_dir( self._metrics_conf.metrics.trained_model_path ), self._metrics_conf.metrics.trained_model_config, ) - return read_conf(model_config_path) - except TypeError: - logger.error( - "Check metrics config file trained model path or config values are empty." + except TypeError as e: + logger.exception(e) + raise ConfigParameterError( + "Metrics config file trained model path or config values are empty." ) - raise ConfigParameterError("Configuration loading error.") + else: + return os.path.join( + self._file_handler.output_path, + self._file_handler.parent_output_dir, + self._file_handler.workdir, + ) - return training_conf + def _load_training_conf(self, training_conf): + """Load Training Conf. + Load the training configuration if training_conf is not provided. + + Parameters + ---------- + training_conf: None or RecursiveNamespace + None type or a RecursiveNamespace storing the training configuration parameter setttings + None type or a RecursiveNamespace storing the training configuration parameter setttings + + Returns + ------- + RecursiveNamespace storing the training configuration parameter settings + + """ + if training_conf is None: + try: + model_config_path = self._get_trained_model_path(training_conf) + return read_conf(model_config_path) + except TypeError as e: + logger.exception(e) + raise ConfigParameterError( + "Metrics config file trained model path or config values are empty." + ) + else: + return training_conf def _load_data_conf(self): try: @@ -320,22 +365,16 @@ def weights_basename_filepath(self): Returns ------- - weights_basename: str - The basename of the psf model weights to be loaded. + weights_basename: str + The basename of the psf model weights to be loaded. """ return os.path.join( self.metrics_conf.metrics.trained_model_path, self.metrics_conf.metrics.model_save_path, ( - self.metrics_conf.metrics.model_save_path - + "*_" - + self.training_conf.training.model_params.model_name - + "*" - + self.training_conf.training.id_name - + "_cycle" - + str(self.metrics_conf.metrics.saved_training_cycle) - + "*" + f"{self.metrics_conf.metrics.model_save_path}*_{self.training_conf.training.model_params.model_name}" + f"*{self.training_conf.training.id_name}_cycle{self.metrics_conf.metrics.saved_training_cycle}*" ), ) @@ -388,7 +427,7 @@ def run(self): logger.info( "Running metrics evaluation on psf model: {}".format(self.weights_path) ) - + model_metrics = evaluate_model( self.metrics_conf.metrics, self.training_conf.training, From 4c90f876f1c4cdd3ca9fcf2483ccbfbe7b8aec20 Mon Sep 17 00:00:00 2001 From: jeipollack Date: Tue, 14 Nov 2023 23:16:04 +0100 Subject: [PATCH 15/23] Fixed trained_model_path setter bug wrong path --- pytest.xml | 1 + src/pytest.xml | 107 +++++++++++++++ .../main_random_seed/config/configs.yaml | 2 + .../config/training_config_error.yaml | 122 ++++++++++++++++++ src/wf_psf/tests/pytest.xml | 49 +++++++ .../tests/test_utils/configs_handler_test.py | 4 + src/wf_psf/tests/test_utils/pytest.xml | 45 +++++++ src/wf_psf/utils/configs_handler.py | 21 +-- 8 files changed, 341 insertions(+), 10 deletions(-) create mode 100644 pytest.xml create mode 100644 src/pytest.xml create mode 100644 src/wf_psf/tests/data/validation/main_random_seed/config/configs.yaml create mode 100644 src/wf_psf/tests/data/validation/main_random_seed/config/training_config_error.yaml create mode 100644 src/wf_psf/tests/pytest.xml create mode 100644 src/wf_psf/tests/test_utils/pytest.xml diff --git a/pytest.xml b/pytest.xml new file mode 100644 index 00000000..d9f636f7 --- /dev/null +++ b/pytest.xml @@ -0,0 +1 @@ +/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/Projects/wf-psf/src/wf_psf/tests/metrics_test.py:110: Requires gpu/Users/jenniferpollack/Projects/wf-psf/src/wf_psf/tests/metrics_test.py:158: Requires gpu/Users/jenniferpollack/Projects/wf-psf/src/wf_psf/tests/metrics_test.py:208: Requires gpu/Users/jenniferpollack/Projects/wf-psf/src/wf_psf/tests/metrics_test.py:273: Requires gpu/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/Projects/wf-psf/src/wf_psf/tests/train_test.py:69: Requires gpu/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks \ No newline at end of file diff --git a/src/pytest.xml b/src/pytest.xml new file mode 100644 index 00000000..a7584e59 --- /dev/null +++ b/src/pytest.xml @@ -0,0 +1,107 @@ +/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/Projects/wf-psf/src/wf_psf/tests/metrics_test.py:110: Requires gpu/Users/jenniferpollack/Projects/wf-psf/src/wf_psf/tests/metrics_test.py:158: Requires gpu/Users/jenniferpollack/Projects/wf-psf/src/wf_psf/tests/metrics_test.py:208: Requires gpu/Users/jenniferpollack/Projects/wf-psf/src/wf_psf/tests/metrics_test.py:273: Requires gpu/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checksweights_filepath = 'src/wf_psf/tests/data/validation/main_random_seed/checkpoint/checkpoint*_poly*_sample_w_bis1_2k_cycle2*' + + def get_psf_model_weights_filepath(weights_filepath): + """Get PSF model weights filepath. + + A function to return the basename of the user-specified psf model weights path. + + Parameters + ---------- + weights_filepath: str + Basename of the psf model weights to be loaded. + + Returns + ------- + str + The absolute path concatenated to the basename of the psf model weights to be loaded. + + """ + try: +> return glob.glob(weights_filepath)[0].split(".")[0] +E IndexError: list index out of range + +../../../miniconda/envs/wf-psf/lib/python3.10/site-packages/wf_psf/psf_models/psf_models.py:128: IndexError + +During handling of the above exception, another exception occurred: + + def test_get_psf_model_weights_filepath(): + weights_filepath = "src/wf_psf/tests/data/validation/main_random_seed/checkpoint/checkpoint*_poly*_sample_w_bis1_2k_cycle2*" + +> ans = psf_models.get_psf_model_weights_filepath(weights_filepath) + +wf_psf/tests/psf_models_test.py:19: +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + +weights_filepath = 'src/wf_psf/tests/data/validation/main_random_seed/checkpoint/checkpoint*_poly*_sample_w_bis1_2k_cycle2*' + + def get_psf_model_weights_filepath(weights_filepath): + """Get PSF model weights filepath. + + A function to return the basename of the user-specified psf model weights path. + + Parameters + ---------- + weights_filepath: str + Basename of the psf model weights to be loaded. + + Returns + ------- + str + The absolute path concatenated to the basename of the psf model weights to be loaded. + + """ + try: + return glob.glob(weights_filepath)[0].split(".")[0] + except IndexError: + logger.exception( + "PSF weights file not found. Check that you've specified the correct weights file in the metrics config file." + ) +> raise PsfModelError("PSF model weights error.") +E wf_psf.psf_models.psf_models.PsfModelError: PSF model weights error. + +../../../miniconda/envs/wf-psf/lib/python3.10/site-packages/wf_psf/psf_models/psf_models.py:133: PsfModelError/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/Projects/wf-psf/src/wf_psf/tests/train_test.py:69: Requires gpu/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checkspath_to_repo_dir = '/Users/jenniferpollack/Projects/wf-psf/src' +path_to_tmp_output_dir = PosixPath('/private/var/folders/_m/5lz4vq6522q4lhlf3x1pq4_80000gr/T/pytest-of-jenniferpollack/pytest-63/test_MetricsConfigHandler_weig0') +path_to_config_dir = '/Users/jenniferpollack/Projects/wf-psf/src/src/wf_psf/tests/data' + + def test_MetricsConfigHandler_weights_basename_filepath( + path_to_repo_dir, path_to_tmp_output_dir, path_to_config_dir + ): + test_file_handler = FileIOHandler( + path_to_repo_dir, path_to_tmp_output_dir, path_to_config_dir + ) + + metrics_config_file = "metrics_config.yaml" + +> metrics_object = configs_handler.MetricsConfigHandler( + os.path.join(path_to_config_dir, metrics_config_file), test_file_handler + ) + +wf_psf/tests/test_utils/configs_handler_test.py:64: +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ +../../../miniconda/envs/wf-psf/lib/python3.10/site-packages/wf_psf/utils/configs_handler.py:249: in __init__ + self._metrics_conf = read_conf(metrics_conf) +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + +conf_file = '/Users/jenniferpollack/Projects/wf-psf/src/src/wf_psf/tests/data/metrics_config.yaml' + + def read_conf(conf_file): + """Read Conf. + + A function to read a yaml configuration file, recursively. + + Parameters + ---------- + conf_file: str + Name of configuration file + + Returns + ------- + RecursiveNamespace + Recursive Namespace object + + """ + logger.info("Loading...{}".format(conf_file)) +> with open(conf_file, "r") as f: +E FileNotFoundError: [Errno 2] No such file or directory: '/Users/jenniferpollack/Projects/wf-psf/src/src/wf_psf/tests/data/metrics_config.yaml' + +../../../miniconda/envs/wf-psf/lib/python3.10/site-packages/wf_psf/utils/read_config.py:105: FileNotFoundError/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks \ No newline at end of file diff --git a/src/wf_psf/tests/data/validation/main_random_seed/config/configs.yaml b/src/wf_psf/tests/data/validation/main_random_seed/config/configs.yaml new file mode 100644 index 00000000..a958b07e --- /dev/null +++ b/src/wf_psf/tests/data/validation/main_random_seed/config/configs.yaml @@ -0,0 +1,2 @@ +--- +metrics_conf: metrics_config.yaml \ No newline at end of file diff --git a/src/wf_psf/tests/data/validation/main_random_seed/config/training_config_error.yaml b/src/wf_psf/tests/data/validation/main_random_seed/config/training_config_error.yaml new file mode 100644 index 00000000..97bd36a1 --- /dev/null +++ b/src/wf_psf/tests/data/validation/main_random_seed/config/training_config_error.yaml @@ -0,0 +1,122 @@ +training: + # ID name + id_name: _errorsample_w_bis1_2k + # Name of Data Config file + data_config: data_config.yaml + # Metrics Config file - Enter file to run metrics evaluation else if empty run train only + metrics_config: metrics_config.yaml + model_params: + # Model type. Options are: 'mccd', 'graph', 'poly, 'param', 'poly_physical'." + model_name: poly + + #Num of wavelength bins to reconstruct polychromatic objects. + n_bins_lda: 8 + + #Downsampling rate to match the oversampled model to the specified telescope's sampling. + output_Q: 3 + + #Oversampling rate used for the OPD/WFE PSF model. + oversampling_rate: 3 + + #Dimension of the pixel PSF postage stamp + output_dim: 32 + + #Dimension of the OPD/Wavefront space." + pupil_diameter: 256 + + #Boolean to define if we use sample weights based on the noise standard deviation estimation + use_sample_weights: True + + #Interpolation type for the physical poly model. Options are: 'none', 'all', 'top_K', 'independent_Zk'." + interpolation_type: None + + # SED intepolation points per bin + sed_interp_pts_per_bin: 0 + + # SED extrapolate + sed_extrapolate: True + + # SED interpolate kind + sed_interp_kind: linear + + # Standard deviation of the multiplicative SED Gaussian noise. + sed_sigma: 0 + + #Limits of the PSF field coordinates for the x axis. + x_lims: [0.0, 1.0e+3] + + #Limits of the PSF field coordinates for the y axis. + y_lims: [0.0, 1.0e+3] + + # Hyperparameters for Parametric model + param_hparams: + # Random seed for Tensor Flow Initialization + random_seed: 3877572 + + # Parameter for the l2 loss function for the Optical path differences (OPD)/WFE + l2_param: 0. + + #Zernike polynomial modes to use on the parametric part. + n_zernikes: 15 + + #Max polynomial degree of the parametric part. chg to max_deg_param + d_max: 2 + + #Flag to save optimisation history for parametric model + save_optim_history_param: true + + # Hyperparameters for non-parametric model + nonparam_hparams: + + #Max polynomial degree of the non-parametric part. chg to max_deg_nonparam + d_max_nonparam: 5 + + # Number of graph features + num_graph_features: 10 + + #L1 regularisation parameter for the non-parametric part." + l1_rate: 1.0e-8 + + #Flag to enable Projected learning for DD_features to be used with `poly` or `semiparametric` model. + project_dd_features: False + + #Flag to reset DD_features to be used with `poly` or `semiparametric` model + reset_dd_features: False + + #Flag to save optimisation history for non-parametric model + save_optim_history_nonparam: true + + # Training hyperparameters + training_hparams: + n_epochs_params: [2, 2, 2] + + n_epochs_non_params: [2, 2, 2] + + batch_size: 32 + + multi_cycle_params: + + # Total amount of cycles to perform. + total_cycles: 2 + + # Train cycle definition. It can be: 'parametric', 'non-parametric', 'complete', 'only-non-parametric' and 'only-parametric'." + cycle_def: complete + + # Make checkpoint at every cycle or just save the checkpoint at the end of the training." + save_all_cycles: True + + #"Saved cycle to use for the evaluation. Can be 'cycle1', 'cycle2', ..." + saved_cycle: cycle2 + + # Learning rates for the parametric parts. It should be a str where numeric values are separated by spaces. + learning_rate_params: [1.0e-2, 1.0e-2] + + # Learning rates for the non-parametric parts. It should be a str where numeric values are separated by spaces." + learning_rate_non_params: [1.0e-1, 1.0e-1] + + # Number of training epochs of the parametric parts. It should be a strign where numeric values are separated by spaces." + n_epochs_params: [20, 20] + + # Number of training epochs of the non-parametric parts. It should be a str where numeric values are separated by spaces." + n_epochs_non_params: [100, 120] + \ No newline at end of file diff --git a/src/wf_psf/tests/pytest.xml b/src/wf_psf/tests/pytest.xml new file mode 100644 index 00000000..f8b5b462 --- /dev/null +++ b/src/wf_psf/tests/pytest.xml @@ -0,0 +1,49 @@ +--- /Users/jenniferpollack/Projects/wf-psf/src/wf_psf/tests/verify_config_test.py 2023-10-24 14:54:09.858428+00:00 ++++ /Users/jenniferpollack/Projects/wf-psf/src/wf_psf/tests/verify_config_test.py 2023-10-24 14:54:13.972764+00:00 +@@ -10,9 +10,8 @@ + import pytest + import os + + + def test_config(training_params): +- + for k, v in training_params.__dict__.items(): + breakpoint() +- print(k,v) +\ No newline at end of file ++ print(k, v) +training_params = <wf_psf.training.train.TrainingParamsHandler object at 0x1642b10f0> + + def test_config(training_params): + + for k, v in training_params.__dict__.items(): + breakpoint() +> print(k,v) + +verify_config_test.py:18: +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ +../../../../../miniconda/envs/wf-psf/lib/python3.10/codecs.py:327: in reset + def reset(self): +../../../../../miniconda/envs/wf-psf/lib/python3.10/bdb.py:92: in trace_dispatch + return self.dispatch_call(frame, arg) +../../../../../miniconda/envs/wf-psf/lib/python3.10/bdb.py:136: in dispatch_call + self.user_call(frame, arg) +../../../../../miniconda/envs/wf-psf/lib/python3.10/pdb.py:243: in user_call + self.interaction(frame, None) +../../../../../miniconda/envs/wf-psf/lib/python3.10/pdb.py:348: in interaction + self._cmdloop() +../../../../../miniconda/envs/wf-psf/lib/python3.10/pdb.py:313: in _cmdloop + self.cmdloop() +../../../../../miniconda/envs/wf-psf/lib/python3.10/cmd.py:126: in cmdloop + line = input(self.prompt) +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + +self = <_pytest.capture.DontReadFromInput object at 0x104606710>, size = -1 + + def read(self, size: int = -1) -> str: +> raise OSError( + "pytest: reading from stdin while output is captured! Consider using `-s`." + ) +E OSError: pytest: reading from stdin while output is captured! Consider using `-s`. + +../../../../../miniconda/envs/wf-psf/lib/python3.10/site-packages/_pytest/capture.py:202: OSError \ No newline at end of file diff --git a/src/wf_psf/tests/test_utils/configs_handler_test.py b/src/wf_psf/tests/test_utils/configs_handler_test.py index 5e8db118..0ed32781 100644 --- a/src/wf_psf/tests/test_utils/configs_handler_test.py +++ b/src/wf_psf/tests/test_utils/configs_handler_test.py @@ -70,3 +70,7 @@ def test_MetricsConfigHandler_weights_basename_filepath( weights_filepath == "src/wf_psf/tests/data/validation/main_random_seed/checkpoint/checkpoint*_poly*_sample_w_bis1_2k_cycle2*" ) + + +def test_training_and_metrics_config(): + \ No newline at end of file diff --git a/src/wf_psf/tests/test_utils/pytest.xml b/src/wf_psf/tests/test_utils/pytest.xml new file mode 100644 index 00000000..44d846da --- /dev/null +++ b/src/wf_psf/tests/test_utils/pytest.xml @@ -0,0 +1,45 @@ +path_to_repo_dir = '/Users/jenniferpollack/Projects/wf-psf/src/wf_psf/tests/test_utils', path_to_test_dir = '/Users/jenniferpollack/Projects/wf-psf/src/wf_psf/tests/test_utils/src/wf_psf/tests' +path_to_tmp_output_dir = PosixPath('/private/var/folders/_m/5lz4vq6522q4lhlf3x1pq4_80000gr/T/pytest-of-jenniferpollack/pytest-25/test_metrics_config_class0') +path_to_config_dir = '/Users/jenniferpollack/Projects/wf-psf/src/wf_psf/tests/test_utils/src/wf_psf/tests/data/config' + + def test_metrics_config_class( + path_to_repo_dir, path_to_test_dir, path_to_tmp_output_dir, path_to_config_dir + ): + test_file_handler = FileIOHandler( + path_to_repo_dir, path_to_tmp_output_dir, path_to_config_dir + ) + metrics_config_file = "metrics_config.yaml" + +> metrics_object = configs_handler.MetricsConfigHandler( + metrics_config_file, test_file_handler + ) + +configs_handler_test.py:63: +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ +../../../../../../miniconda/envs/wf-psf/lib/python3.10/site-packages/wf_psf/utils/configs_handler.py:249: in __init__ + self._metrics_conf = read_conf(metrics_conf) +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + +conf_file = 'metrics_config.yaml' + + def read_conf(conf_file): + """Read Conf. + + A function to read a yaml configuration file, recursively. + + Parameters + ---------- + conf_file: str + Name of configuration file + + Returns + ------- + RecursiveNamespace + Recursive Namespace object + + """ + logger.info("Loading...{}".format(conf_file)) +> with open(conf_file, "r") as f: +E FileNotFoundError: [Errno 2] No such file or directory: 'metrics_config.yaml' + +../../../../../../miniconda/envs/wf-psf/lib/python3.10/site-packages/wf_psf/utils/read_config.py:105: FileNotFoundError \ No newline at end of file diff --git a/src/wf_psf/utils/configs_handler.py b/src/wf_psf/utils/configs_handler.py index ea43d92c..1ca4a896 100644 --- a/src/wf_psf/utils/configs_handler.py +++ b/src/wf_psf/utils/configs_handler.py @@ -248,6 +248,7 @@ class MetricsConfigHandler: def __init__(self, metrics_conf, file_handler, training_conf=None): self._metrics_conf = read_conf(metrics_conf) self._file_handler = file_handler + self.trained_model_path = self._get_trained_model_path(training_conf) self._training_conf = self._load_training_conf(training_conf) @property @@ -299,12 +300,8 @@ def _get_trained_model_path(self, training_conf): """ if training_conf is None: try: - return os.path.join( - self._file_handler.get_config_dir( - self._metrics_conf.metrics.trained_model_path - ), - self._metrics_conf.metrics.trained_model_config, - ) + return self._metrics_conf.metrics.trained_model_path + except TypeError as e: logger.exception(e) raise ConfigParameterError( @@ -334,8 +331,12 @@ def _load_training_conf(self, training_conf): """ if training_conf is None: try: - model_config_path = self._get_trained_model_path(training_conf) - return read_conf(model_config_path) + return read_conf( + os.path.join( + self._file_handler.get_config_dir(self.trained_model_path), + self._metrics_conf.metrics.trained_model_config, + ) + ) except TypeError as e: logger.exception(e) raise ConfigParameterError( @@ -370,7 +371,7 @@ def weights_basename_filepath(self): """ return os.path.join( - self.metrics_conf.metrics.trained_model_path, + self.trained_model_path, self.metrics_conf.metrics.model_save_path, ( f"{self.metrics_conf.metrics.model_save_path}*_{self.training_conf.training.model_params.model_name}" @@ -427,7 +428,7 @@ def run(self): logger.info( "Running metrics evaluation on psf model: {}".format(self.weights_path) ) - + model_metrics = evaluate_model( self.metrics_conf.metrics, self.training_conf.training, From ae1b0ca2d7b5df75322280bd68406c0f2b9f274f Mon Sep 17 00:00:00 2001 From: jeipollack Date: Tue, 14 Nov 2023 23:27:05 +0100 Subject: [PATCH 16/23] Removed pytest.xml --- pytest.xml | 1 - src/wf_psf/tests/pytest.xml | 49 ------------------------------------- 2 files changed, 50 deletions(-) delete mode 100644 pytest.xml delete mode 100644 src/wf_psf/tests/pytest.xml diff --git a/pytest.xml b/pytest.xml deleted file mode 100644 index d9f636f7..00000000 --- a/pytest.xml +++ /dev/null @@ -1 +0,0 @@ -/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/Projects/wf-psf/src/wf_psf/tests/metrics_test.py:110: Requires gpu/Users/jenniferpollack/Projects/wf-psf/src/wf_psf/tests/metrics_test.py:158: Requires gpu/Users/jenniferpollack/Projects/wf-psf/src/wf_psf/tests/metrics_test.py:208: Requires gpu/Users/jenniferpollack/Projects/wf-psf/src/wf_psf/tests/metrics_test.py:273: Requires gpu/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/Projects/wf-psf/src/wf_psf/tests/train_test.py:69: Requires gpu/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks \ No newline at end of file diff --git a/src/wf_psf/tests/pytest.xml b/src/wf_psf/tests/pytest.xml deleted file mode 100644 index f8b5b462..00000000 --- a/src/wf_psf/tests/pytest.xml +++ /dev/null @@ -1,49 +0,0 @@ ---- /Users/jenniferpollack/Projects/wf-psf/src/wf_psf/tests/verify_config_test.py 2023-10-24 14:54:09.858428+00:00 -+++ /Users/jenniferpollack/Projects/wf-psf/src/wf_psf/tests/verify_config_test.py 2023-10-24 14:54:13.972764+00:00 -@@ -10,9 +10,8 @@ - import pytest - import os - - - def test_config(training_params): -- - for k, v in training_params.__dict__.items(): - breakpoint() -- print(k,v) -\ No newline at end of file -+ print(k, v) -training_params = <wf_psf.training.train.TrainingParamsHandler object at 0x1642b10f0> - - def test_config(training_params): - - for k, v in training_params.__dict__.items(): - breakpoint() -> print(k,v) - -verify_config_test.py:18: -_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ -../../../../../miniconda/envs/wf-psf/lib/python3.10/codecs.py:327: in reset - def reset(self): -../../../../../miniconda/envs/wf-psf/lib/python3.10/bdb.py:92: in trace_dispatch - return self.dispatch_call(frame, arg) -../../../../../miniconda/envs/wf-psf/lib/python3.10/bdb.py:136: in dispatch_call - self.user_call(frame, arg) -../../../../../miniconda/envs/wf-psf/lib/python3.10/pdb.py:243: in user_call - self.interaction(frame, None) -../../../../../miniconda/envs/wf-psf/lib/python3.10/pdb.py:348: in interaction - self._cmdloop() -../../../../../miniconda/envs/wf-psf/lib/python3.10/pdb.py:313: in _cmdloop - self.cmdloop() -../../../../../miniconda/envs/wf-psf/lib/python3.10/cmd.py:126: in cmdloop - line = input(self.prompt) -_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ - -self = <_pytest.capture.DontReadFromInput object at 0x104606710>, size = -1 - - def read(self, size: int = -1) -> str: -> raise OSError( - "pytest: reading from stdin while output is captured! Consider using `-s`." - ) -E OSError: pytest: reading from stdin while output is captured! Consider using `-s`. - -../../../../../miniconda/envs/wf-psf/lib/python3.10/site-packages/_pytest/capture.py:202: OSError \ No newline at end of file From 7857f41a283dc7948096e8616b4d3e0177343a2e Mon Sep 17 00:00:00 2001 From: jeipollack Date: Tue, 14 Nov 2023 23:37:24 +0100 Subject: [PATCH 17/23] Removed incomplete test committed by accident --- src/wf_psf/tests/test_utils/configs_handler_test.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/wf_psf/tests/test_utils/configs_handler_test.py b/src/wf_psf/tests/test_utils/configs_handler_test.py index 0ed32781..b7714a56 100644 --- a/src/wf_psf/tests/test_utils/configs_handler_test.py +++ b/src/wf_psf/tests/test_utils/configs_handler_test.py @@ -72,5 +72,4 @@ def test_MetricsConfigHandler_weights_basename_filepath( ) -def test_training_and_metrics_config(): - \ No newline at end of file + From af5642cdfe795a89d3fcb613f9ae553ad4312ae2 Mon Sep 17 00:00:00 2001 From: jeipollack Date: Tue, 14 Nov 2023 23:42:16 +0100 Subject: [PATCH 18/23] Reformatted configs_handler_test.py with Black --- src/wf_psf/tests/test_utils/configs_handler_test.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/wf_psf/tests/test_utils/configs_handler_test.py b/src/wf_psf/tests/test_utils/configs_handler_test.py index b7714a56..5e8db118 100644 --- a/src/wf_psf/tests/test_utils/configs_handler_test.py +++ b/src/wf_psf/tests/test_utils/configs_handler_test.py @@ -70,6 +70,3 @@ def test_MetricsConfigHandler_weights_basename_filepath( weights_filepath == "src/wf_psf/tests/data/validation/main_random_seed/checkpoint/checkpoint*_poly*_sample_w_bis1_2k_cycle2*" ) - - - From 279e409e072a474d41b471146e89063069e72665 Mon Sep 17 00:00:00 2001 From: jeipollack Date: Tue, 14 Nov 2023 23:56:28 +0100 Subject: [PATCH 19/23] Removed pytest.xml commited by err via VScode feat --- src/pytest.xml | 107 ------------------------------------------------- 1 file changed, 107 deletions(-) delete mode 100644 src/pytest.xml diff --git a/src/pytest.xml b/src/pytest.xml deleted file mode 100644 index a7584e59..00000000 --- a/src/pytest.xml +++ /dev/null @@ -1,107 +0,0 @@ -/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/Projects/wf-psf/src/wf_psf/tests/metrics_test.py:110: Requires gpu/Users/jenniferpollack/Projects/wf-psf/src/wf_psf/tests/metrics_test.py:158: Requires gpu/Users/jenniferpollack/Projects/wf-psf/src/wf_psf/tests/metrics_test.py:208: Requires gpu/Users/jenniferpollack/Projects/wf-psf/src/wf_psf/tests/metrics_test.py:273: Requires gpu/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checksweights_filepath = 'src/wf_psf/tests/data/validation/main_random_seed/checkpoint/checkpoint*_poly*_sample_w_bis1_2k_cycle2*' - - def get_psf_model_weights_filepath(weights_filepath): - """Get PSF model weights filepath. - - A function to return the basename of the user-specified psf model weights path. - - Parameters - ---------- - weights_filepath: str - Basename of the psf model weights to be loaded. - - Returns - ------- - str - The absolute path concatenated to the basename of the psf model weights to be loaded. - - """ - try: -> return glob.glob(weights_filepath)[0].split(".")[0] -E IndexError: list index out of range - -../../../miniconda/envs/wf-psf/lib/python3.10/site-packages/wf_psf/psf_models/psf_models.py:128: IndexError - -During handling of the above exception, another exception occurred: - - def test_get_psf_model_weights_filepath(): - weights_filepath = "src/wf_psf/tests/data/validation/main_random_seed/checkpoint/checkpoint*_poly*_sample_w_bis1_2k_cycle2*" - -> ans = psf_models.get_psf_model_weights_filepath(weights_filepath) - -wf_psf/tests/psf_models_test.py:19: -_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ - -weights_filepath = 'src/wf_psf/tests/data/validation/main_random_seed/checkpoint/checkpoint*_poly*_sample_w_bis1_2k_cycle2*' - - def get_psf_model_weights_filepath(weights_filepath): - """Get PSF model weights filepath. - - A function to return the basename of the user-specified psf model weights path. - - Parameters - ---------- - weights_filepath: str - Basename of the psf model weights to be loaded. - - Returns - ------- - str - The absolute path concatenated to the basename of the psf model weights to be loaded. - - """ - try: - return glob.glob(weights_filepath)[0].split(".")[0] - except IndexError: - logger.exception( - "PSF weights file not found. Check that you've specified the correct weights file in the metrics config file." - ) -> raise PsfModelError("PSF model weights error.") -E wf_psf.psf_models.psf_models.PsfModelError: PSF model weights error. - -../../../miniconda/envs/wf-psf/lib/python3.10/site-packages/wf_psf/psf_models/psf_models.py:133: PsfModelError/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/Projects/wf-psf/src/wf_psf/tests/train_test.py:69: Requires gpu/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checkspath_to_repo_dir = '/Users/jenniferpollack/Projects/wf-psf/src' -path_to_tmp_output_dir = PosixPath('/private/var/folders/_m/5lz4vq6522q4lhlf3x1pq4_80000gr/T/pytest-of-jenniferpollack/pytest-63/test_MetricsConfigHandler_weig0') -path_to_config_dir = '/Users/jenniferpollack/Projects/wf-psf/src/src/wf_psf/tests/data' - - def test_MetricsConfigHandler_weights_basename_filepath( - path_to_repo_dir, path_to_tmp_output_dir, path_to_config_dir - ): - test_file_handler = FileIOHandler( - path_to_repo_dir, path_to_tmp_output_dir, path_to_config_dir - ) - - metrics_config_file = "metrics_config.yaml" - -> metrics_object = configs_handler.MetricsConfigHandler( - os.path.join(path_to_config_dir, metrics_config_file), test_file_handler - ) - -wf_psf/tests/test_utils/configs_handler_test.py:64: -_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ -../../../miniconda/envs/wf-psf/lib/python3.10/site-packages/wf_psf/utils/configs_handler.py:249: in __init__ - self._metrics_conf = read_conf(metrics_conf) -_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ - -conf_file = '/Users/jenniferpollack/Projects/wf-psf/src/src/wf_psf/tests/data/metrics_config.yaml' - - def read_conf(conf_file): - """Read Conf. - - A function to read a yaml configuration file, recursively. - - Parameters - ---------- - conf_file: str - Name of configuration file - - Returns - ------- - RecursiveNamespace - Recursive Namespace object - - """ - logger.info("Loading...{}".format(conf_file)) -> with open(conf_file, "r") as f: -E FileNotFoundError: [Errno 2] No such file or directory: '/Users/jenniferpollack/Projects/wf-psf/src/src/wf_psf/tests/data/metrics_config.yaml' - -../../../miniconda/envs/wf-psf/lib/python3.10/site-packages/wf_psf/utils/read_config.py:105: FileNotFoundError/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks/Users/jenniferpollack/miniconda/envs/wf-psf/lib/python3.10/site-packages/pytest_black.py:67: file(s) previously passed black format checks \ No newline at end of file From 869672a9849b42727f5313101ae21e95e31979f7 Mon Sep 17 00:00:00 2001 From: jeipollack Date: Wed, 15 Nov 2023 00:01:15 +0100 Subject: [PATCH 20/23] Removed docstring duplication --- src/wf_psf/utils/configs_handler.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/wf_psf/utils/configs_handler.py b/src/wf_psf/utils/configs_handler.py index 1ca4a896..1166bd36 100644 --- a/src/wf_psf/utils/configs_handler.py +++ b/src/wf_psf/utils/configs_handler.py @@ -321,12 +321,11 @@ def _load_training_conf(self, training_conf): Parameters ---------- training_conf: None or RecursiveNamespace - None type or a RecursiveNamespace storing the training configuration parameter setttings - None type or a RecursiveNamespace storing the training configuration parameter setttings + None type or a RecursiveNamespace storing the training configuration parameter setttings. Returns ------- - RecursiveNamespace storing the training configuration parameter settings + RecursiveNamespace storing the training configuration parameter settings. """ if training_conf is None: From 514e67243cc97ecec3b9175766e8ea7952f3e33c Mon Sep 17 00:00:00 2001 From: jeipollack Date: Wed, 15 Nov 2023 00:04:53 +0100 Subject: [PATCH 21/23] Added missing docstring --- src/wf_psf/utils/configs_handler.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/wf_psf/utils/configs_handler.py b/src/wf_psf/utils/configs_handler.py index 1166bd36..bb8dc688 100644 --- a/src/wf_psf/utils/configs_handler.py +++ b/src/wf_psf/utils/configs_handler.py @@ -345,6 +345,15 @@ def _load_training_conf(self, training_conf): return training_conf def _load_data_conf(self): + """Load Data Conf. + + A method to load the data configuration file + and return an instance of DataConfigHandler class. + + Returns + ------- + An instance of the DataConfigHandler class. + """ try: return DataConfigHandler( os.path.join( From 1ad6f913c9a62ee9038a6cf8894a26dff7b72160 Mon Sep 17 00:00:00 2001 From: jeipollack Date: Wed, 15 Nov 2023 11:15:35 +0100 Subject: [PATCH 22/23] Added pytest.xml --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 2a578997..9d08f4eb 100644 --- a/.gitignore +++ b/.gitignore @@ -62,6 +62,7 @@ htmlcov/ .coverage.* .cache nosetests.xml +pytest.xml coverage.xml *.cover *.py,cover From 52214a095cc7156d0219946a3b7e7131f600420d Mon Sep 17 00:00:00 2001 From: jeipollack Date: Wed, 15 Nov 2023 11:16:11 +0100 Subject: [PATCH 23/23] Removed pytest.xml from tests.test_utils --- src/wf_psf/tests/test_utils/pytest.xml | 45 -------------------------- 1 file changed, 45 deletions(-) delete mode 100644 src/wf_psf/tests/test_utils/pytest.xml diff --git a/src/wf_psf/tests/test_utils/pytest.xml b/src/wf_psf/tests/test_utils/pytest.xml deleted file mode 100644 index 44d846da..00000000 --- a/src/wf_psf/tests/test_utils/pytest.xml +++ /dev/null @@ -1,45 +0,0 @@ -path_to_repo_dir = '/Users/jenniferpollack/Projects/wf-psf/src/wf_psf/tests/test_utils', path_to_test_dir = '/Users/jenniferpollack/Projects/wf-psf/src/wf_psf/tests/test_utils/src/wf_psf/tests' -path_to_tmp_output_dir = PosixPath('/private/var/folders/_m/5lz4vq6522q4lhlf3x1pq4_80000gr/T/pytest-of-jenniferpollack/pytest-25/test_metrics_config_class0') -path_to_config_dir = '/Users/jenniferpollack/Projects/wf-psf/src/wf_psf/tests/test_utils/src/wf_psf/tests/data/config' - - def test_metrics_config_class( - path_to_repo_dir, path_to_test_dir, path_to_tmp_output_dir, path_to_config_dir - ): - test_file_handler = FileIOHandler( - path_to_repo_dir, path_to_tmp_output_dir, path_to_config_dir - ) - metrics_config_file = "metrics_config.yaml" - -> metrics_object = configs_handler.MetricsConfigHandler( - metrics_config_file, test_file_handler - ) - -configs_handler_test.py:63: -_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ -../../../../../../miniconda/envs/wf-psf/lib/python3.10/site-packages/wf_psf/utils/configs_handler.py:249: in __init__ - self._metrics_conf = read_conf(metrics_conf) -_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ - -conf_file = 'metrics_config.yaml' - - def read_conf(conf_file): - """Read Conf. - - A function to read a yaml configuration file, recursively. - - Parameters - ---------- - conf_file: str - Name of configuration file - - Returns - ------- - RecursiveNamespace - Recursive Namespace object - - """ - logger.info("Loading...{}".format(conf_file)) -> with open(conf_file, "r") as f: -E FileNotFoundError: [Errno 2] No such file or directory: 'metrics_config.yaml' - -../../../../../../miniconda/envs/wf-psf/lib/python3.10/site-packages/wf_psf/utils/read_config.py:105: FileNotFoundError \ No newline at end of file