From 03a9638a970f1caba9fb4e27a0b7eb2fc591d2ea Mon Sep 17 00:00:00 2001 From: jgostick Date: Mon, 20 Nov 2023 16:49:33 +0900 Subject: [PATCH] adding a try/except to getitem in phase for missing settings --- openpnm/phase/_phase.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/openpnm/phase/_phase.py b/openpnm/phase/_phase.py index 653f19c6c0..803ca37274 100644 --- a/openpnm/phase/_phase.py +++ b/openpnm/phase/_phase.py @@ -95,13 +95,16 @@ def __getitem__(self, key): if element + '.' + prop in self.keys(): vals = super().__getitem__(element + '.' + prop) else: # If above are not triggered then try to interpolate - if self.settings['auto_interpolate']: - if (element == 'pore') and ('throat.'+prop not in self.keys()): + try: + if self.settings['auto_interpolate']: + if (element == 'pore') and ('throat.'+prop not in self.keys()): + raise KeyError(key) + elif (element == 'throat') and ('pore.'+prop not in self.keys()): + raise KeyError(key) + vals = self.interpolate_data(element + '.' + prop) + else: raise KeyError(key) - elif (element == 'throat') and ('pore.'+prop not in self.keys()): - raise KeyError(key) - vals = self.interpolate_data(element + '.' + prop) - else: + except AttributeError: raise KeyError(key) # Finally get locs