From aade4e58545265f5b9585dc6c83b1a9af9c115ed Mon Sep 17 00:00:00 2001 From: dngoldberg <31406058+dngoldberg@users.noreply.github.com> Date: Fri, 17 May 2024 16:38:22 +0100 Subject: [PATCH 1/6] 1st attempt -- vaf masking --- fenics_ice/config.py | 4 ++++ fenics_ice/inout.py | 2 +- fenics_ice/model.py | 7 +++++-- fenics_ice/solver.py | 10 ++++++++-- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/fenics_ice/config.py b/fenics_ice/config.py index 680049b..8908ccb 100644 --- a/fenics_ice/config.py +++ b/fenics_ice/config.py @@ -265,6 +265,8 @@ class ErrorPropCfg(ConfigPrinter): Configuration related to error propagation """ qoi: str = 'vaf' + qoi_apply_vaf_mask: bool = False + qoi_mask: str = '' phase_name: str = 'error_prop' phase_suffix: str = '' @@ -487,6 +489,7 @@ class IOCfg(ConfigPrinter): alpha_data_file: str = None melt_depth_therm_data_file: str = None melt_max_data_file: str = None + vaf_mask_data_file: str = None thick_field_name: str = "thick" bed_field_name: str = "bed" @@ -498,6 +501,7 @@ class IOCfg(ConfigPrinter): alpha_field_name: str = "alpha" melt_depth_therm_field_name: str = "melt_depth" melt_max_field_name: str = "melt_max" + vaf_mask_field_name: str = "vaf_mask" inversion_file: str = None qoi_file: str = None # "Qval_ts.p" diff --git a/fenics_ice/inout.py b/fenics_ice/inout.py index 03ed8b2..e934522 100644 --- a/fenics_ice/inout.py +++ b/fenics_ice/inout.py @@ -497,7 +497,7 @@ def __init__(self, params): # List of fields to search for field_list = ["thick", "bed", "bmelt", "smb", "Bglen", "Bglenmask", "alpha", \ - "melt_depth_therm", "melt_max"] + "melt_depth_therm", "melt_max", "vaf_mask"] # Dictionary of filenames & field names (i.e. field to get from HDF5 file) # Possibly equal to None for variables which have sensible defaults diff --git a/fenics_ice/model.py b/fenics_ice/model.py index d57e0cb..2900163 100644 --- a/fenics_ice/model.py +++ b/fenics_ice/model.py @@ -162,8 +162,8 @@ def init_fields_from_data(self): if self.params.melt.use_melt_parameterisation: - melt_depth_therm_const: float = -999.0 - melt_max_const: float = -999.0 + #melt_depth_therm_const: float = -999.0 + #melt_max_const: float = -999.0 if (self.params.melt.melt_depth_therm_const == -999.0 or \ self.params.melt.melt_max_const == -999.0): @@ -177,6 +177,9 @@ def init_fields_from_data(self): method='nearest') self.melt_max = self.field_from_data("melt_max", self.M2, default=melt_max, method='nearest') + if self.params.errorprop.qoi_apply_vaf_mask: + self.vaf_mask = self.field_from_data("vaf_mask", self.M2, default=1.0, method='nearest') + self.H = self.H_np.copy(deepcopy=True) self.H.rename("thick_H", "") self.H_DG = Function(self.M2, name="H_DG") diff --git a/fenics_ice/solver.py b/fenics_ice/solver.py index 7c9a6cc..d90481a 100644 --- a/fenics_ice/solver.py +++ b/fenics_ice/solver.py @@ -130,6 +130,8 @@ def __init__(self, model, mixed_space=False, obs_sensitivity=False): if self.params.melt.use_melt_parameterisation: self.melt_depth_therm = model.melt_depth_therm self.melt_max = model.melt_max + if self.params.errorprop.qoi_apply_vaf_mask: + self.vaf_mask = model.vaf_mask self.set_inv_params() @@ -1454,8 +1456,12 @@ def comp_Q_vaf(self, verbose=False): b_ex = conditional(bed < 0.0, 1.0, 0.0) HAF = ufl.Max(b_ex * (H + (rhow/rhoi)*bed) + (1-b_ex)*(H), 0.0) - - Q_vaf = HAF * dx + + if self.params.errorprop.qoi_apply_vaf_mask: + msk_ex = conditional(self.vaf_mask > 0.0, 1.0, 0.0) + Q_vaf = msk_ex * HAF * dx + else: + Q_vaf = HAF * dx if verbose: info(f"Q_vaf: {assemble(Q_vaf)}") From b9a054f29b45c7aa85b868ad8874eaeaa2724c77 Mon Sep 17 00:00:00 2001 From: dngoldberg <31406058+dngoldberg@users.noreply.github.com> Date: Fri, 17 May 2024 17:07:48 +0100 Subject: [PATCH 2/6] fix error in toml header name --- fenics_ice/model.py | 2 +- fenics_ice/solver.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/fenics_ice/model.py b/fenics_ice/model.py index 2900163..7276dc4 100644 --- a/fenics_ice/model.py +++ b/fenics_ice/model.py @@ -177,7 +177,7 @@ def init_fields_from_data(self): method='nearest') self.melt_max = self.field_from_data("melt_max", self.M2, default=melt_max, method='nearest') - if self.params.errorprop.qoi_apply_vaf_mask: + if self.params.error_prop.qoi_apply_vaf_mask: self.vaf_mask = self.field_from_data("vaf_mask", self.M2, default=1.0, method='nearest') self.H = self.H_np.copy(deepcopy=True) diff --git a/fenics_ice/solver.py b/fenics_ice/solver.py index d90481a..50136ce 100644 --- a/fenics_ice/solver.py +++ b/fenics_ice/solver.py @@ -130,7 +130,7 @@ def __init__(self, model, mixed_space=False, obs_sensitivity=False): if self.params.melt.use_melt_parameterisation: self.melt_depth_therm = model.melt_depth_therm self.melt_max = model.melt_max - if self.params.errorprop.qoi_apply_vaf_mask: + if self.params.error_prop.qoi_apply_vaf_mask: self.vaf_mask = model.vaf_mask self.set_inv_params() @@ -1457,7 +1457,7 @@ def comp_Q_vaf(self, verbose=False): b_ex = conditional(bed < 0.0, 1.0, 0.0) HAF = ufl.Max(b_ex * (H + (rhow/rhoi)*bed) + (1-b_ex)*(H), 0.0) - if self.params.errorprop.qoi_apply_vaf_mask: + if self.params.error_prop.qoi_apply_vaf_mask: msk_ex = conditional(self.vaf_mask > 0.0, 1.0, 0.0) Q_vaf = msk_ex * HAF * dx else: From 178c36f406d56aef1ba9ebdd8085e480b68b88f9 Mon Sep 17 00:00:00 2001 From: dngoldberg <31406058+dngoldberg@users.noreply.github.com> Date: Wed, 22 May 2024 09:08:08 +0100 Subject: [PATCH 3/6] do not need qoi_mask param --- fenics_ice/config.py | 1 - 1 file changed, 1 deletion(-) diff --git a/fenics_ice/config.py b/fenics_ice/config.py index 8908ccb..e37ba09 100644 --- a/fenics_ice/config.py +++ b/fenics_ice/config.py @@ -266,7 +266,6 @@ class ErrorPropCfg(ConfigPrinter): """ qoi: str = 'vaf' qoi_apply_vaf_mask: bool = False - qoi_mask: str = '' phase_name: str = 'error_prop' phase_suffix: str = '' From 166726b1a87f0683b6cdab80f57121b881055a0f Mon Sep 17 00:00:00 2001 From: dngoldberg <31406058+dngoldberg@users.noreply.github.com> Date: Wed, 22 May 2024 14:15:05 +0100 Subject: [PATCH 4/6] add param back in --- fenics_ice/config.py | 1 + 1 file changed, 1 insertion(+) diff --git a/fenics_ice/config.py b/fenics_ice/config.py index e37ba09..8908ccb 100644 --- a/fenics_ice/config.py +++ b/fenics_ice/config.py @@ -266,6 +266,7 @@ class ErrorPropCfg(ConfigPrinter): """ qoi: str = 'vaf' qoi_apply_vaf_mask: bool = False + qoi_mask: str = '' phase_name: str = 'error_prop' phase_suffix: str = '' From f8d097a3edf69539be5cdbec58bc6f2ddbf12367 Mon Sep 17 00:00:00 2001 From: dngoldberg <31406058+dngoldberg@users.noreply.github.com> Date: Wed, 22 May 2024 14:29:45 +0100 Subject: [PATCH 5/6] remove param again --- fenics_ice/config.py | 1 - 1 file changed, 1 deletion(-) diff --git a/fenics_ice/config.py b/fenics_ice/config.py index 8908ccb..e37ba09 100644 --- a/fenics_ice/config.py +++ b/fenics_ice/config.py @@ -266,7 +266,6 @@ class ErrorPropCfg(ConfigPrinter): """ qoi: str = 'vaf' qoi_apply_vaf_mask: bool = False - qoi_mask: str = '' phase_name: str = 'error_prop' phase_suffix: str = '' From d4ff40030d0f52099674cd7455526541a1cf6ed2 Mon Sep 17 00:00:00 2001 From: dngoldberg <31406058+dngoldberg@users.noreply.github.com> Date: Thu, 23 May 2024 08:35:48 +0100 Subject: [PATCH 6/6] Update model.py remove commented lines --- fenics_ice/model.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/fenics_ice/model.py b/fenics_ice/model.py index 7276dc4..e2f1653 100644 --- a/fenics_ice/model.py +++ b/fenics_ice/model.py @@ -161,9 +161,6 @@ def init_fields_from_data(self): self.H_np = self.field_from_data("thick", self.M, min_val=min_thick) if self.params.melt.use_melt_parameterisation: - - #melt_depth_therm_const: float = -999.0 - #melt_max_const: float = -999.0 if (self.params.melt.melt_depth_therm_const == -999.0 or \ self.params.melt.melt_max_const == -999.0):