-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add separate validation argument for realization_in_ensemble
- Loading branch information
1 parent
c3214c2
commit 683f3ee
Showing
5 changed files
with
94 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
from ert.storage import Ensemble | ||
from ert.validation.range_string_argument import RangeStringArgument | ||
from ert.validation.rangestring import rangestring_to_list | ||
|
||
from .validation_status import ValidationStatus | ||
|
||
|
||
class RealizationsInEnsembleArgument(RangeStringArgument): | ||
UNINITIALIZED_REALIZATIONS_SPECIFIED = ( | ||
"The specified realization(s) %s are not found in selected ensemble." | ||
) | ||
NO_REALIZATIONS_SPECIFIED = "No realizations specified." | ||
|
||
def __init__(self, ensemble: Ensemble, **kwargs: bool) -> None: | ||
super().__init__(**kwargs) | ||
self.__ensemble = ensemble | ||
|
||
def validate(self, token: str) -> ValidationStatus: | ||
if not token: | ||
return ValidationStatus() | ||
|
||
validation_status = super().validate(token) | ||
if not validation_status: | ||
return validation_status | ||
print(f"{validation_status.message()=}") | ||
attempted_realizations = rangestring_to_list(token) # might be duplicate | ||
### NOT NECCESSARY IF WE WANT EMPTY TO BE VALID. IN THIS CONTEXT, 'NO' REALIZATION IS VALID, AS IT WILL BE IN ENSEMBLE | ||
if len(attempted_realizations) < 1: | ||
validation_status.setFailed() | ||
validation_status.addToMessage( | ||
RealizationsInEnsembleArgument.NO_REALIZATIONS_SPECIFIED | ||
) | ||
if self.__ensemble is None: | ||
validation_status.setFailed() | ||
validation_status.addToMessage("NO ENSEMBLE FOUND!") | ||
return validation_status | ||
invalid_realizations = [] | ||
for realization in attempted_realizations: | ||
if not self._validate_selected_realization_exist(realization): | ||
invalid_realizations.append(realization) | ||
|
||
if invalid_realizations: | ||
print(f"{self.__ensemble.get_realization_mask_with_responses()=}") | ||
validation_status.setFailed() | ||
validation_status.addToMessage( | ||
RealizationsInEnsembleArgument.UNINITIALIZED_REALIZATIONS_SPECIFIED | ||
% str(invalid_realizations) | ||
) | ||
|
||
elif not validation_status.failed(): | ||
validation_status.setValue(token) | ||
|
||
return validation_status | ||
|
||
def _validate_selected_realization_exist(self, realization: int): | ||
if self.__ensemble._responses_exist_for_realization(realization): | ||
print(f"VALID REALIZATION {realization=}") | ||
return True | ||
|
||
# print(f"{realization=} does not exist!") | ||
return False |