forked from equinor/ert
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add validation for uninitialized ensembles in manual update and evaluate
experiment This commit adds validation for the realizations specified by the user when trying to run `manual_update` or `evaluate_experiment`. The validator checks the selected ensemble if the specified realization(s) exists. If not, the field becomes red and a warning is displayed. The commit also disables the realization field until an ensemble is selected.
- Loading branch information
1 parent
74e401e
commit 79e6917
Showing
4 changed files
with
66 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from typing import TYPE_CHECKING, Optional | ||
|
||
from .range_string_argument import RangeStringArgument | ||
from .rangestring import rangestring_to_list | ||
from .validation_status import ValidationStatus | ||
|
||
if TYPE_CHECKING: | ||
from ert.storage import Ensemble | ||
|
||
|
||
class EnsembleRealizationsArgument(RangeStringArgument): | ||
UNINITIALIZED_REALIZATIONS_SPECIFIED = ( | ||
"The specified realization(s) %s are not found in selected ensemble." | ||
) | ||
|
||
def __init__( | ||
self, ensemble: "Ensemble", max_value: Optional[int], **kwargs: bool | ||
) -> None: | ||
super().__init__(max_value, **kwargs) | ||
self.__ensemble = ensemble | ||
|
||
def set_ensemble(self, ensemble: "Ensemble") -> None: | ||
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 | ||
attempted_realizations = rangestring_to_list(token) | ||
|
||
invalid_realizations = [] | ||
initialized_realization_ids = self.__ensemble.is_initalized() | ||
for realization in attempted_realizations: | ||
if not realization in initialized_realization_ids: | ||
invalid_realizations.append(realization) | ||
|
||
if invalid_realizations: | ||
validation_status.setFailed() | ||
validation_status.addToMessage( | ||
EnsembleRealizationsArgument.UNINITIALIZED_REALIZATIONS_SPECIFIED | ||
% str(invalid_realizations) | ||
) | ||
return validation_status | ||
|
||
validation_status.setValue(token) | ||
return validation_status |