From b945750f46d13561b2ba8888fade1c090cd4c40a Mon Sep 17 00:00:00 2001 From: Patrick Date: Fri, 21 Jul 2023 09:07:37 +0200 Subject: [PATCH] included max thickness due to min w0 in bed_h boundaries --- agile1d/core/inversion.py | 34 ++++++++++++++++++++++----------- agile1d/tests/conftest.py | 2 +- agile1d/tests/test_inversion.py | 16 ++++++++-------- 3 files changed, 32 insertions(+), 20 deletions(-) diff --git a/agile1d/core/inversion.py b/agile1d/core/inversion.py index 8d606db..8a15dea 100644 --- a/agile1d/core/inversion.py +++ b/agile1d/core/inversion.py @@ -302,7 +302,7 @@ def add_setting(): @entity_task(log, writes=['inversion_input']) def prepare_for_agile_inversion(gdir, inversion_settings=None, - filesuffix='_agile'): + filesuffix='_agile'): """TODO """ if inversion_settings is None: @@ -322,11 +322,18 @@ def get_control_var_bounds(data_logger): fl = data_logger.flowline_init ice_mask = data_logger.ice_mask bed_h_bounds = data_logger.bed_h_bounds - bounds[var_indices] = [(sfc_h - thick * bed_h_bounds[1], - sfc_h - thick * bed_h_bounds[0]) - for sfc_h, thick in + + h_max_w0 = (fl.widths_m[fl.thick > 0] - data_logger.min_w0_m) / \ + fl._lambdas[fl.thick > 0] + + bounds[var_indices] = [(sfc_h - min(thick * bed_h_bounds[1], + thick_max), + sfc_h - thick * bed_h_bounds[0] + ) + for sfc_h, thick, thick_max in zip(fl.surface_h[ice_mask], - fl.thick[ice_mask])] + fl.thick[ice_mask], + h_max_w0)] # Outdated calculation using GlabTop # upper_limits = get_adaptive_upper_ice_thickness_limit( @@ -344,14 +351,19 @@ def get_control_var_bounds(data_logger): fl = data_logger.flowline_init ice_mask = data_logger.ice_mask bed_h_bounds = data_logger.bed_h_bounds - bounds[var_indices] = [((sfc_h - thick * bed_h_bounds[1]) * - width_m, - (sfc_h - thick * bed_h_bounds[0]) * - width_m) - for sfc_h, thick, width_m in + + h_max_w0 = (fl.widths_m[fl.thick > 0] - data_logger.min_w0_m) / \ + fl._lambdas[fl.thick > 0] + + bounds[var_indices] = [((sfc_h - min(thick * bed_h_bounds[1], + thick_max)) * width_m, + (sfc_h - thick * bed_h_bounds[0]) * width_m + ) + for sfc_h, thick, width_m, thick_max in zip(fl.surface_h[ice_mask], fl.thick[ice_mask], - fl.widths_m[ice_mask])] + fl.widths_m[ice_mask], + h_max_w0)] # Outdated calculation using GlabTop # upper_limits = get_adaptive_upper_ice_thickness_limit( diff --git a/agile1d/tests/conftest.py b/agile1d/tests/conftest.py index 5d7ddef..db2e2cc 100644 --- a/agile1d/tests/conftest.py +++ b/agile1d/tests/conftest.py @@ -150,7 +150,7 @@ def data_logger_init(hef_gdir, control_vars, spinup_option, dynamic_models, inversion_settings['regularisation_terms'] = {'smoothed_bed': 1., 'smoothed_flux': 10.} prepare_for_agile_inversion(hef_gdir, inversion_settings=inversion_settings, - filesuffix='_agile') + filesuffix='_agile') data_logger = initialise_DataLogger(hef_gdir, inversion_input_filesuffix='_agile') return data_logger diff --git a/agile1d/tests/test_inversion.py b/agile1d/tests/test_inversion.py index 249989a..2fa5abb 100644 --- a/agile1d/tests/test_inversion.py +++ b/agile1d/tests/test_inversion.py @@ -6,9 +6,9 @@ from agile1d.core.first_guess import get_first_guess from agile1d.core.inversion import (prepare_for_agile_inversion, - get_control_var_bounds, - get_default_inversion_settings, - agile_inversion) + get_control_var_bounds, + get_default_inversion_settings, + agile_inversion) from agile1d.core.data_logging import initialise_DataLogger from agile1d.core.cost_function import create_cost_fct, descale_unknown_parameters @@ -27,7 +27,7 @@ def test_default_initialisation(self, hef_gdir): # add default inversion_input_agile and try again prepare_for_agile_inversion(hef_gdir, inversion_settings=None, - filesuffix='_agile') + filesuffix='_agile') data_logger = initialise_DataLogger( hef_gdir, inversion_input_filesuffix='_agile') @@ -103,7 +103,7 @@ def test_get_control_var_bounds(self, data_logger): ids=[#'flux_based', 'implicit']) def test_agile_inversion(self, hef_gdir, control_vars, spinup_options, - dynamic_model, all_supported_control_vars): + dynamic_model, all_supported_control_vars): # Final integration test that the inversion runs with no errors, also # test the saving of the final past evolution inversion_settings = get_default_inversion_settings(get_doc=False) @@ -131,11 +131,11 @@ def test_agile_inversion(self, hef_gdir, control_vars, spinup_options, inversion_settings['observations'][measure_key]['2000-2019'] = -1. prepare_for_agile_inversion(hef_gdir, - inversion_settings=inversion_settings, - filesuffix='_agile') + inversion_settings=inversion_settings, + filesuffix='_agile') data_logger = agile_inversion(hef_gdir, give_data_logger_back=True, - save_past_evolution=True) + save_past_evolution=True) # test if data_logger contains data assert data_logger.minimize_message is not None