Skip to content

Commit 00e0f0e

Browse files
committed
Update create_obs_with_localisation_attributes
update distance_based_on_real_case.py
1 parent 429cf6b commit 00e0f0e

File tree

3 files changed

+2002
-835
lines changed

3 files changed

+2002
-835
lines changed

create_obs_with_localisation_attributes.py

Lines changed: 48 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,21 @@
1010
Output files: A csv file for observations and a csv file with localisation attribute
1111
per well and obs type
1212
13+
Assumptions about input data:
14+
Field parameter names are read from ERT config file (the FIELD keywords)
15+
The zone names per field parameter is defined by using APS naming convention of field parameters where
16+
zone name is part of the field parameter name.
17+
1318
"""
1419

1520
import copy
1621
import math
1722
from pathlib import Path
1823
from typing import Any
1924

25+
import polars as pl
2026
import xtgeo
2127
import yaml
22-
import polars as pl
2328

2429
CONFIG_PATH = "/private/olia/IES_DL/"
2530
FILENAME = "example_config_to_get_pos_and_loc_params_from_rms.yml"
@@ -305,7 +310,7 @@ def get_ranges(input_dict: dict, kw: str, parent_kw: str) -> tuple:
305310
if len(ranges) != 3:
306311
raise ValueError(
307312
"Expect 3 range parameters for influence ellipse: "
308-
"MainRange, PerpendicularRange, RotationAngle."
313+
"MainRange, PerpendicularRange, AnisotropyAngle."
309314
"Range parameters must be postive, but angle can also be 0."
310315
"Angle is expected to be in degrees measured "
311316
"from x-axis in anticlock direction."
@@ -576,7 +581,10 @@ def check_specified_strings(
576581

577582

578583
def write_result_summary_obs(
579-
filename: str, all_obs_dict: dict, allow_overwrite: bool = False, use_polars=True,
584+
filename: str,
585+
all_obs_dict: dict,
586+
allow_overwrite: bool = False,
587+
use_polars=True,
580588
) -> None:
581589
"""
582590
Write csv file with following columns:
@@ -663,8 +671,8 @@ def write_result_summary_obs(
663671
value_list.append(float(obs_dict["value"]))
664672
error = float(obs_dict["error"])
665673
error_list.append(error)
666-
min_error_list.append(error * 0.5) # TODO What should this be?
667-
max_error_list.append(error * 1.5) # TODO What should this be?
674+
min_error_list.append(error * 0.5) # TODO What should this be?
675+
max_error_list.append(error * 1.5) # TODO What should this be?
668676
date_list.append(obs_dict["date"])
669677
zone_list.append(zone_name)
670678
ert_id_list.append(ert_id)
@@ -679,10 +687,14 @@ def write_result_summary_obs(
679687
"zone_name": zone_list,
680688
}
681689
df = pl.DataFrame(data_dict)
682-
df.write_csv(filename,separator=' ')
690+
df.write_csv(filename, separator=" ")
691+
683692

684693
def write_localisation_obs_attributes(
685-
filename: str, all_obs_dict: dict, allow_overwrite: bool = False, use_polars=True,
694+
filename: str,
695+
all_obs_dict: dict,
696+
allow_overwrite: bool = False,
697+
use_polars=True,
686698
) -> None:
687699
"""
688700
Write csv file with following columns:
@@ -709,7 +721,7 @@ def write_localisation_obs_attributes(
709721
ypos_header = "YPOS"
710722
main_range_header = "MAIN_RANGE"
711723
perp_range_header = "PERP_RANGE"
712-
rotation_angle_header = "AZIMUTH"
724+
anisotropy_angle_header = "ANISOTROPY_ANGLE"
713725
if not use_polars:
714726
max_summary_vector_length = 12
715727
max_zone_name_length = 12
@@ -731,7 +743,7 @@ def write_localisation_obs_attributes(
731743
content += f"{ypos_header:>{max_value_length}}"
732744
content += f"{main_range_header:>{max_range_length}}"
733745
content += f"{perp_range_header:>{max_range_length}}"
734-
content += f"{rotation_angle_header:>{max_angle_length}}"
746+
content += f"{anisotropy_angle_header:>{max_angle_length}}"
735747
content += f"{zone_name_header:>{max_zone_name_length}}"
736748
content += "\n"
737749
file.write(content)
@@ -748,14 +760,14 @@ def write_localisation_obs_attributes(
748760
ypos = float(obs_dict["ypos"])
749761
main_range = float(obs_dict["main_range"])
750762
perp_range = float(obs_dict["perp_range"])
751-
rotation_angle = float(obs_dict["anisotropy_angle"])
763+
anisotropy_angle = float(obs_dict["anisotropy_angle"])
752764
content = ""
753765
content += f"{summary_vector:<{max_summary_vector_length}}"
754766
content += f"{xpos:{max_value_length}.1f}"
755767
content += f"{ypos:{max_value_length}.1f}"
756768
content += f"{main_range:{max_range_length}.1f}"
757769
content += f"{perp_range:{max_range_length}.1f}"
758-
content += f"{rotation_angle:{max_angle_length}.1f}"
770+
content += f"{anisotropy_angle:{max_angle_length}.1f}"
759771
content += f"{zone_name:>{max_zone_name_length}}"
760772
content += "\n"
761773
file.write(content)
@@ -767,7 +779,7 @@ def write_localisation_obs_attributes(
767779
ypos_list = []
768780
main_range_list = []
769781
perp_range_list = []
770-
azimuth_list = []
782+
anisotropy_angle_list = []
771783
zone_list = []
772784
ert_id_list = []
773785

@@ -779,7 +791,7 @@ def write_localisation_obs_attributes(
779791
ypos_list.append(float(obs_dict["ypos"]))
780792
main_range_list.append(float(obs_dict["main_range"]))
781793
perp_range_list.append(float(obs_dict["perp_range"]))
782-
azimuth_list.append(float(obs_dict["anisotropy_angle"]))
794+
anisotropy_angle_list.append(float(obs_dict["anisotropy_angle"]))
783795
zone_list.append(zone_name)
784796
ert_id_list.append(ert_id)
785797
data_dict = {
@@ -789,18 +801,21 @@ def write_localisation_obs_attributes(
789801
"ypos": ypos_list,
790802
"main_range": main_range_list,
791803
"perp_range": perp_range_list,
792-
"azimuth": azimuth_list,
804+
"anisotropy_angle": anisotropy_angle_list,
793805
"zone_name": zone_list,
794806
}
795807
df = pl.DataFrame(data_dict)
796-
df.write_csv(filename,separator=' ')
808+
df.write_csv(filename, separator=" ")
809+
797810

798811
def write_obs_with_localization(
799-
filename: str, all_obs_dict: dict, allow_overwrite: bool = False,
812+
filename: str,
813+
all_obs_dict: dict,
814+
allow_overwrite: bool = False,
800815
) -> None:
801816
"""
802817
Write csv file with following columns:
803-
- ert_id
818+
- observation_key
804819
- summary_vector
805820
- date
806821
- obs_value
@@ -833,7 +848,7 @@ def write_obs_with_localization(
833848
ypos_list = []
834849
main_range_list = []
835850
perp_range_list = []
836-
azimuth_list = []
851+
anisotropy_angle_list = []
837852
zone_list = []
838853

839854
for key, obs_dict in all_obs_dict.items():
@@ -844,17 +859,17 @@ def write_obs_with_localization(
844859
value_list.append(float(obs_dict["value"]))
845860
error = float(obs_dict["error"])
846861
error_list.append(error)
847-
min_error_list.append(error * 0.5) # TODO What should this be?
848-
max_error_list.append(error * 1.5) # TODO What should this be?
862+
min_error_list.append(error * 0.5) # TODO What should this be?
863+
max_error_list.append(error * 1.5) # TODO What should this be?
849864
xpos_list.append(float(obs_dict["xpos"]))
850865
ypos_list.append(float(obs_dict["ypos"]))
851866
main_range_list.append(float(obs_dict["main_range"]))
852867
perp_range_list.append(float(obs_dict["perp_range"]))
853-
azimuth_list.append(float(obs_dict["anisotropy_angle"]))
868+
anisotropy_angle_list.append(float(obs_dict["anisotropy_angle"]))
854869
zone_list.append(zone_name)
855870

856871
data_dict = {
857-
"ert_id": ert_id_list,
872+
"observation_key": ert_id_list,
858873
"summary_vector": summary_vector,
859874
"date": date_list,
860875
"value": value_list,
@@ -865,13 +880,12 @@ def write_obs_with_localization(
865880
"ypos": ypos_list,
866881
"main_range": main_range_list,
867882
"perp_range": perp_range_list,
868-
"azimuth": azimuth_list,
883+
"anisotropy_angle": anisotropy_angle_list,
869884
"zone_name": zone_list,
870885
}
871886

872887
df = pl.DataFrame(data_dict)
873-
df.write_csv(filename,separator=' ')
874-
888+
df.write_csv(filename, separator=" ")
875889

876890

877891
def create_obs_local(project, config_file):
@@ -911,6 +925,7 @@ def create_obs_local(project, config_file):
911925
field_settings_spec_list,
912926
expand_specification,
913927
) = get_specification(spec)
928+
914929
print(f"Read file: {obs_summary_file}")
915930
obs_dict_list = read_ert_summary_obs_file(obs_summary_file)
916931

@@ -951,6 +966,8 @@ def create_obs_local(project, config_file):
951966
obs_localisation_dict["summary_vector"] = obs_dict["summary_vector"]
952967
if obs_localisation_dict["hlength"] > min_range_hwell:
953968
well_path_angle = obs_localisation_dict["well_path_angle"]
969+
# Localisation ellipse main axis in same
970+
# direction as horizontal well path
954971
obs_localisation_dict["anisotropy_angle"] = well_path_angle
955972
obs_localisation_dict["main_range"] = max(
956973
obs_localisation_dict["hlength"],
@@ -1042,11 +1059,12 @@ def create_obs_local(project, config_file):
10421059
output_dict[key] = obs_localisation_dict
10431060

10441061
# Write result
1045-
write_result_summary_obs(result_summary_obs_file, output_dict, allow_overwrite=True, use_polars=True)
1046-
# write_localisation_obs_attributes(
1047-
# result_localisation_obs_file, output_dict, allow_overwrite=True, use_polars=True,
1048-
# )
1049-
write_obs_with_localization(result_localisation_obs_file, output_dict, allow_overwrite=True)
1062+
write_result_summary_obs(
1063+
result_summary_obs_file, output_dict, allow_overwrite=True, use_polars=True
1064+
)
1065+
write_obs_with_localization(
1066+
result_localisation_obs_file, output_dict, allow_overwrite=True
1067+
)
10501068

10511069

10521070
if __name__ == "__main__":

0 commit comments

Comments
 (0)