-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add simple plotting tool * Further updates * Further updates * Put build_ensemble_df_list * Add docstring * Fix lists * Fix no info error * Check None * Update CHANGELOG * Add observations to plotting * Fix observation tests * Add support for multiple lines * People don't like Cows/lightyear, I thought it was funny. * Updated argparse descriptions * Updates after review
- Loading branch information
Showing
5 changed files
with
456 additions
and
55 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import os | ||
import pathlib | ||
from datetime import datetime | ||
import yaml | ||
|
||
|
||
def _read_ert_obs(ert_obs_file_name: pathlib.Path) -> dict: | ||
"""This function reads the content of a ERT observation file and returns the information in a dictionary. | ||
Args: | ||
ert_obs_file_name: path to the ERT observation file | ||
Returns: | ||
ert_obs: dictionary that contains the information in a ERT observation file | ||
""" | ||
assert os.path.exists(ert_obs_file_name) == 1 | ||
ert_obs: dict = {} | ||
text = "" | ||
with open(ert_obs_file_name, "r") as a_ert_file: | ||
for line in a_ert_file: | ||
text = text + line | ||
|
||
for item in text.replace(" ", "").split("};"): | ||
if "SUMMARY_OBSERVATION" in item: | ||
tmp = item.split("{")[1].split(";") | ||
dic = {} | ||
for var in tmp: | ||
tmp2 = var.split("=") | ||
if len(tmp2) > 1: | ||
dic[tmp2[0]] = tmp2[1] | ||
if not dic["KEY"] in ert_obs: | ||
ert_obs[dic["KEY"]] = [[], [], []] | ||
ert_obs[dic["KEY"]][0].append( | ||
datetime.strptime(dic["DATE"], "%d/%m/%Y").date() | ||
) | ||
ert_obs[dic["KEY"]][1].append(float(dic["VALUE"])) | ||
ert_obs[dic["KEY"]][2].append(float(dic["ERROR"])) | ||
|
||
return ert_obs | ||
|
||
|
||
def _read_yaml_obs(yaml_obs_file_name: pathlib.Path) -> dict: | ||
"""This function reads the content of a YAML observation file and returns the information in a dictionary. | ||
Args: | ||
yaml_obs_file_name: path to the YAML observation file | ||
Returns: | ||
dictionary that contains the information in a YAML observation file | ||
""" | ||
assert os.path.exists(yaml_obs_file_name) == 1 | ||
a_yaml_file = open(yaml_obs_file_name, "r") | ||
|
||
return yaml.load(a_yaml_file, Loader=yaml.FullLoader) |
Oops, something went wrong.