Skip to content

Commit

Permalink
better handling of load cache vs. dont load cache
Browse files Browse the repository at this point in the history
grantbuster committed Nov 27, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 357440f commit b32d7d6
Showing 3 changed files with 13 additions and 10 deletions.
15 changes: 9 additions & 6 deletions sup3r/preprocessing/data_handling/dual_data_handling.py
Original file line number Diff line number Diff line change
@@ -185,7 +185,8 @@ def means(self):

if self.hr_dh.data is None:
msg = ('High-res DataHandler object has DataHandler.data=None! '
'Try initializing DualDataHandler with load_cached=True')
'Try initializing the high-res handler with '
'load_cached=True')
logger.error(msg)
raise RuntimeError(msg)

@@ -206,7 +207,8 @@ def stds(self):

if self.hr_dh.data is None:
msg = ('High-res DataHandler object has DataHandler.data=None! '
'Try initializing DualDataHandler with load_cached=True')
'Try initializing the high-res handler with '
'load_cached=True')
logger.error(msg)
raise RuntimeError(msg)

@@ -234,10 +236,10 @@ def normalize(self, means=None, stds=None, max_workers=None):
Has no effect. Used to match MixIn class signature.
"""

if self.lr_dh.data is None or self.hr_dh.data is None:
msg = ('Low-res or High-res DataHandler object has '
'DataHandler.data=None! Try initializing DualDataHandler '
'with load_cached=True')
if self.hr_dh.data is None:
msg = ('High-res DataHandler object has DataHandler.data=None! '
'Try initializing the high-res handler with '
'load_cached=True')
logger.error(msg)
raise RuntimeError(msg)

@@ -254,6 +256,7 @@ def normalize(self, means=None, stds=None, max_workers=None):
self.lr_dh.normalize(means=means, stds=stds,
features=self.lr_dh.features,
max_workers=self.lr_dh.norm_workers)

logger.info('Normalizing high resolution data features='
f'{self.hr_dh.features}')
self.hr_dh.normalize(means=means, stds=stds,
2 changes: 1 addition & 1 deletion sup3r/preprocessing/data_handling/mixin.py
Original file line number Diff line number Diff line change
@@ -1156,7 +1156,7 @@ def normalize(self, means=None, stds=None, features=None,

if self._is_normalized:
logger.info('Skipping DataHandler, already normalized')
else:
elif self.data is not None:
self._normalize(self.data,
self.val_data,
features=features,
6 changes: 3 additions & 3 deletions tests/data_handling/test_dual_data_handling.py
Original file line number Diff line number Diff line change
@@ -615,13 +615,13 @@ def test_bad_cache_load():
t_enhance=t_enhance,
cache_pattern=dual_cache,
load_cached=False,
val_split=0.1)
val_split=0.0)

# because load_cached is False
assert hr_handler.data is None
assert lr_handler.data is not None

good_err = "Try initializing DualDataHandler with load_cached=True"
good_err = "DataHandler.data=None!"
with pytest.raises(RuntimeError) as ex:
_ = copy.deepcopy(dual_handler.means)
assert good_err in str(ex.value)
@@ -640,7 +640,7 @@ def test_bad_cache_load():
t_enhance=t_enhance,
cache_pattern=dual_cache,
load_cached=True,
val_split=0.1)
val_split=0.0)

# because load_cached is True
assert hr_handler.data is not None

0 comments on commit b32d7d6

Please sign in to comment.