def main(): """ Compile metadata for all timelapse maps """ parser = argparse.ArgumentParser(description="Compile metadata for all maps") parser.add_argument( "config_file", help="Enter path to the WebViz-4D configuration file" ) args = parser.parse_args() config_file = args.config_file config = common.read_config(config_file) shared_settings = config["shared_settings"] fmu_directory = shared_settings["fmu_directory"] surface_metadata = common.get_config_item(config, "surface_metadata") metadata_file = os.path.join(fmu_directory, surface_metadata) print("Maps metadata file: ", metadata_file) if os.path.isfile(metadata_file): os.remove(metadata_file) print(" - file removed") map_suffix = common.get_config_item(config, "map_suffix") delimiter = common.get_config_item(config, "delimiter") metadata_file = common.get_config_item(config, "surface_metadata") metadata = get_metadata(shared_settings, map_suffix, delimiter, metadata_file) print(metadata)
def main(): """ Import and convert DSG colormaps """ parser = argparse.ArgumentParser( description="Import and convert DSG colormaps") parser.add_argument("config_file", help="Enter path to the WebViz-4D configuration file") args = parser.parse_args() config_file = args.config_file config = common.read_config(config_file) settings_file = common.get_config_item(config, "settings") settings_file = common.get_full_path(settings_file) settings = common.read_config(settings_file) folder = settings["map_settings"]["colormaps_folder"] SUFFIX = ".clx" import_colormaps(folder, SUFFIX)
def main(): """ Display the tooltip info found in all well list (pickle) files found in a folder Parameters ---------- configuration_file : str The name of WebViz-4D configuration file Returns ------- """ description = "Check well list files" parser = argparse.ArgumentParser(description=description) parser.add_argument("config_file", help="Enter path to the WebViz-4D configuration file") args = parser.parse_args() print(description) print(args) config_file = args.config_file config = common.read_config(config_file) wellfolder = common.get_config_item(config, "wellfolder") wellfolder = common.get_full_path(wellfolder) print("Reading well lists in", wellfolder) pickle_files = glob.glob(wellfolder + "/*.pkl") for pickle_file in pickle_files: file_object = open(pickle_file, "rb") info = pickle.load(file_object) print(pickle_file) data = info["data"] if len(data) > 0: for item in data: print(item["tooltip"]) print("")
def main(): """ Create production data tables """ description = "Create production data tables" parser = argparse.ArgumentParser(description=description) parser.add_argument("config_file", help="Enter path to the WebViz-4D configuration file") args = parser.parse_args() print(description) print(args) config_file = args.config_file config_file = common.read_config(config_file) production_directory = common.get_config_item(config_file, "production_data") production_directory = common.get_full_path(production_directory) production_table_file = os.path.join(production_directory, "production_fluid_table.csv") injection_table_file = os.path.join(production_directory, "injection_fluid_table.csv") bore_oil_file = os.path.join(production_directory, "BORE_OIL_VOL.csv") bore_gas_file = os.path.join(production_directory, "BORE_GAS_VOL.csv") bore_water_file = os.path.join(production_directory, "BORE_WAT_VOL.csv") print("Loading oil volumes from file", bore_oil_file) bore_oil = pd.read_csv(bore_oil_file) print("Loading gas volumes from file", bore_gas_file) bore_gas = pd.read_csv(bore_gas_file) print("Loading water volumes from file", bore_water_file) bore_water = pd.read_csv(bore_water_file) with open(production_table_file, "w") as file_object: file_object.write("Well_name,4D_interval,Volumes,Fluid\n") fluid = "Oil_[Sm3]" write_data(bore_oil, fluid, 1, file_object) fluid = "Gas_[kSm3]" write_data(bore_gas, fluid, 1000, file_object) fluid = "Water_[Sm3]" write_data(bore_water, fluid, 1, file_object) print("Production volumes table stored to file", production_table_file) inject_gas_file = os.path.join(production_directory, "BORE_GI_VOL.csv") inject_water_file = os.path.join(production_directory, "BORE_WI_VOL.csv") print("Loading injected gas volumes from file", inject_gas_file) inject_gas = pd.read_csv(inject_gas_file) print("Loading injected water volumes from file", inject_water_file) inject_water = pd.read_csv(inject_water_file) with open(injection_table_file, "w") as file_object: file_object.write("Well_name,4D_interval,Volumes,Fluid\n") fluid = "Injected_Gas_[kSm3]" write_data(inject_gas, fluid, 1000, file_object) fluid = "Injected_Water_[Sm3]" write_data(inject_water, fluid, 1, file_object) print("Injection volumes table stored to file", injection_table_file)
def main(): # Main description = "Create well lists based on production data" parser = argparse.ArgumentParser(description=description) parser.add_argument("config_file", help="Enter path to the WebViz-4D configuration file") args = parser.parse_args() print(description) print(args) config_file = args.config_file config = common.read_config(config_file) # Well and production data well_suffix = common.get_config_item(config, "well_suffix") map_suffix = common.get_config_item(config, "map_suffix") delimiter = common.get_config_item(config, "delimiter") metadata_file = common.get_config_item(config, "surface_metadata") well_directory = common.get_config_item(config, "wellfolder") well_directory = common.get_full_path(well_directory) prod_info_dir = common.get_config_item(config, "production_data") prod_info_dir = common.get_full_path(prod_info_dir) update_metadata_file = os.path.join(prod_info_dir, ".production_update.yaml") update_dates = common.get_update_dates(well_directory) production_update = update_dates["production_last_date"] print("Production data update", production_update) try: settings_file = common.get_config_item(config, "settings") settings_file = common.get_full_path(settings_file) settings = common.read_config(settings_file) interval = common.get_config_item(config, "default_interval") except: settings_file = None settings = None interval = None shared_settings = config["shared_settings"] print("Extracting 4D intervals ...") metadata_file = common.get_config_item(config, "surface_metadata") metadata = get_metadata(shared_settings, delimiter, map_suffix, metadata_file) intervals_4d, incremental = get_all_intervals(metadata, "reverse") colors = common.get_well_colors(settings) prod_info_files = [os.path.join(prod_info_dir, OIL_PRODUCTION_FILE)] prod_info_files.append(os.path.join(prod_info_dir, GAS_INJECTION_FILE)) prod_info_files.append(os.path.join(prod_info_dir, WATER_INJECTION_FILE)) prod_info_list = [] for prod_info_file in prod_info_files: print("Reading production info from file " + str(prod_info_file)) prod_info = pd.read_csv(prod_info_file) prod_info.name = os.path.basename(str(prod_info_file)) prod_info_list.append(prod_info) drilled_well_df, drilled_well_info, interval_df = well.load_all_wells( well_directory, well_suffix) drilled_well_info = add_production_volumes(drilled_well_info, prod_info_list) #well_info = WellDataFrame(drilled_well_info) wellbores = drilled_well_info["wellbore.name"].unique() # print("well_info.data_frame") print("Last production update", production_update) print("Looping through all 4D intervals ...") for interval_4d in intervals_4d: print("4D interval:", interval_4d) if interval_4d[0:10] <= production_update: well_layer = make_new_well_layer( interval_4d, drilled_well_df, drilled_well_info, interval_df, prod_info_list, colors, selection="production", label="Producers", ) label = "production_well_layer_" store_well_layer(well_layer, well_directory, label, interval_4d) well_layer = make_new_well_layer( interval_4d, drilled_well_df, drilled_well_info, interval_df, prod_info_list, colors, selection="production_start", label="Producers - started", ) label = "production_start_well_layer_" store_well_layer(well_layer, well_directory, label, interval_4d) well_layer = make_new_well_layer( interval_4d, drilled_well_df, drilled_well_info, interval_df, prod_info_list, colors, selection="production_completed", label="Producers - completed", ) label = "production_completed_well_layer_" store_well_layer(well_layer, well_directory, label, interval_4d) well_layer = make_new_well_layer( interval_4d, drilled_well_df, drilled_well_info, interval_df, prod_info_list, colors, selection="injection", label="Injectors", ) label = "injection_well_layer_" store_well_layer(well_layer, well_directory, label, interval_4d) well_layer = make_new_well_layer( interval_4d, drilled_well_df, drilled_well_info, interval_df, prod_info_list, colors, selection="injection_start", label="Injectors - started", ) label = "injection_start_well_layer_" store_well_layer(well_layer, well_directory, label, interval_4d) well_layer = make_new_well_layer( interval_4d, drilled_well_df, drilled_well_info, interval_df, prod_info_list, colors, selection="injection_completed", label="Injectors - completed", ) label = "injection_completed_well_layer_" store_well_layer(well_layer, well_directory, label, interval_4d) else: print(" - no production data for this time interval") prod_headers = prod_info.columns last_header = prod_headers[-1] interval_4d = last_header well_layer = make_new_well_layer( interval_4d, drilled_well_df, drilled_well_info, interval_df, prod_info_list, colors, selection="active", label="Active wells", ) if well_layer: label = "active_well_layer_" store_well_layer(well_layer, well_directory, label, interval_4d)
def main(): """ Compile metadata from all wells and extract top reservoir depths """ description = "Compile metadata from all wells and extract top reservoir depths" parser = argparse.ArgumentParser(description=description) parser.add_argument("config_file", help="Enter path to the WebViz-4D configuration file") args = parser.parse_args() print(description) print(args) config_file = args.config_file config = common.read_config(config_file) try: well_directory = common.get_config_item(config, "wellfolder") well_directory = common.get_full_path(well_directory) except: well_directory = None print("ERROR: Well directory", well_directory, "not found") print("Execution stopped") print("Well directory", well_directory) if well_directory: try: settings_file = common.get_config_item(config, "settings") settings_file = common.get_full_path(settings_file) settings = common.read_config(settings_file) surface_file = settings["depth_maps"]["top_reservoir"] surface = load_surface(surface_file) except: surface_file = None surface = None else: print("ERROR: Well data not found in", well_directory) exit() print("Surface file", surface_file) WELLBORE_INFO_FILE = "wellbore_info.csv" INTERVALS_FILE = "intervals.csv" WELL_SUFFIX = ".w" wellbore_info, intervals = extract_metadata(well_directory) pd.set_option("display.max_rows", None) print(wellbore_info) wellbore_info = compile_data(surface, well_directory, wellbore_info, WELL_SUFFIX) wellbore_info.to_csv(os.path.join(well_directory, WELLBORE_INFO_FILE)) intervals.to_csv(os.path.join(well_directory, INTERVALS_FILE)) # print(intervals) print("Metadata stored to " + os.path.join(well_directory, WELLBORE_INFO_FILE)) print("Completion intervals stored to " + os.path.join(well_directory, INTERVALS_FILE)) planned_wells_dir = [ f.path for f in os.scandir(well_directory) if f.is_dir() ] for folder in planned_wells_dir: wellbore_info = pd.DataFrame() wellbore_info = compile_data(surface, folder, wellbore_info, WELL_SUFFIX) wellbore_info.to_csv(os.path.join(folder, WELLBORE_INFO_FILE)) print(wellbore_info) print("Metadata stored to " + os.path.join(folder, WELLBORE_INFO_FILE))
import os import pytest import webviz_4d._datainput.common as common config_file = "./tests/data/example_config.yaml" config = common.read_config(config_file) config_folder = os.path.dirname(config_file) settings_file = common.get_config_item(config, "settings") settings_file = os.path.join(config_folder, settings_file) settings = common.read_config(settings_file) def test_read_config(): well_folder = common.get_config_item(config, "wellfolder") assert well_folder == "./well_data" def test_get_well_colors(): colors = common.get_well_colors(settings) default = colors["default"] oil = colors["oil_production"] assert default == "black" assert oil == "green"
def main(): # Reek data print("Reek") config_file = "./examples/reek_4d.yaml" config = common.read_config(config_file) print(config_file) print(config) wellfolder = common.get_config_item(config, "wellfolder") print("wellfolder", wellfolder) settings_file = common.get_config_item(config, "settings_file") print("settings_file", settings_file) settings_file = common.get_full_path(settings_file) print("settings_file", settings_file) print("") # Johan Sverdrup (Eli/Tonje) print("Johan Sverdrup - synthetic 4D maps") config_file = "configurations/js_test_eli_v2.yaml" config = common.read_config(config_file) shared_settings = config["shared_settings"] print(config_file) print(config) map_suffix = common.get_config_item(config, "map_suffix") delimiter = common.get_config_item(config, "delimiter") metadata_file = common.get_config_item(config, "surface_metadata") metadata = get_metadata(shared_settings, map_suffix, delimiter, metadata_file) print(metadata) all_intervals, incremental_intervals = get_all_intervals(metadata, "reverse") print("incremental_intervals") print(incremental_intervals) print("all_intervals") print(all_intervals) print("") # Johan Sverdrup (Simulation model) print("Johan Sverdrup - simulation model") config_file = "configurations/js_test.yaml" config = common.read_config(config_file) shared_settings = config["shared_settings"] print(config_file) print(config) map_suffix = common.get_config_item(config, "map_suffix") delimiter = common.get_config_item(config, "delimiter") metadata_file = common.get_config_item(config, "surface_metadata") metadata = get_metadata(shared_settings, map_suffix, delimiter, metadata_file) print(metadata) all_intervals, incremental_intervals = get_all_intervals(metadata, "reverse") print("incremental_intervals") print(incremental_intervals) print("all_intervals") print(all_intervals) print("") # Grane print("Grane") config_file = "configurations/config_template.yaml" print(config_file) config = common.read_config(config_file) shared_settings = config["shared_settings"] map_suffix = common.get_config_item(config, "map_suffix") print("map_suffix", map_suffix) delimiter = common.get_config_item(config, "delimiter") print("delimiter", delimiter) metadata_file = common.get_config_item(config, "surface_metadata") print("metadata_file", metadata_file) metadata = get_metadata(shared_settings, map_suffix, delimiter, metadata_file) print(metadata) all_intervals, incremental_intervals = get_all_intervals(metadata, "normal") print("incremental_intervals") print(incremental_intervals) print("all_intervals") print(all_intervals)
def main(): """Create information about the well layers in WebViz-4D""" description = "Create information about the well layers in WebViz-4D" parser = argparse.ArgumentParser(description=description) parser.add_argument("settings_file", help="Enter name of settings file") parser.add_argument("interval", help="Enter wanted 4D interval") args = parser.parse_args() settings_file = args.settings_file settings_file = os.path.abspath(settings_file) settings_folder = os.path.dirname(settings_file) settings = read_config(settings_file) selected_interval = args.interval well_folder = settings["well_data"] well_folder = os.path.join(settings_folder, well_folder) # Read production data prod_folder = settings["production_data"] prod_folder = os.path.join(settings_folder, prod_folder) prod_names = [ "BORE_OIL_VOL.csv", "BORE_GAS_VOL.csv", "BORE_WAT_VOL.csv", "BORE_GI_VOL.csv", "BORE_WI_VOL.csv", ] prod_data = read_csvs(folder=prod_folder, csv_files=prod_names) print("Reading production data from", prod_folder) print(prod_data) incremental_intervals_df = get_incremental_intervals(prod_data) columns = incremental_intervals_df.columns intervals = [] for i in range(5, len(columns)): interval = columns[i] intervals.append(interval) print("Reading well data from", well_folder) if well_folder: all_wells_info = read_csv(csv_file=Path(well_folder) / "wellbore_info.csv") all_wells_info["file_name"] = all_wells_info["file_name"].apply( lambda x: get_path(Path(x)) ) all_wells_df = load_all_wells(all_wells_info) drilled_wells_df = all_wells_df.loc[ all_wells_df["layer_name"] == "Drilled wells" ] drilled_wells_info = all_wells_info.loc[ all_wells_info["layer_name"] == "Drilled wells" ] drilled_wells_df.sort_values(by=["WELLBORE_NAME"], inplace=True) planned_wells_info = all_wells_info.loc[ all_wells_info["wellbore.type"] == "planned" ] if planned_wells_info is not None: planned_well_layers = planned_wells_info["layer_name"].unique() else: planned_well_layers = [] well_colors = { "default": "black", "oil_open": "lime", "oil_production": "green", "gas_open": "salmon", "gas_production": "magenta", "gas_injection": "red", "water_injection": "blue", "wag_injection": "blueviolet", "planned": "purple", } drilled_well_layers = { "drilled_wells": "Drilled wells", "reservoir_section": "Reservoir sections", "active_production": "Active producers", "active_injection": "Active injectors", "production": "Producers", "production_start": "Producers - started", "production_completed": "Producers - completed", "injection": "Injectors", "injection_start": "Injectors -started", "injection_completed": "Injectors - completed", } fluids_dict = { "production": ["oil"], "active_production": ["oil"], "production_start": ["oil"], "production_completed": ["oil"], "injection": ["gas", "water"], "active_injection": ["gas", "water"], "injection_start": ["gas", "water"], "injection_completed": ["gas", "water"], "planned": [], } headers = [ "Short name", "Well type", "Fluid(s)", "Volume", "Unit", "Start year", "Last year", "Color", ] for key in drilled_well_layers: selection = key value = drilled_well_layers[key] if "active" in selection: fluids = fluids_dict[selection] interval_label = "" elif "production" in selection or "injection" in selection: fluids = fluids_dict[selection] interval_label = "_" + selected_interval else: fluids = None interval_label = "" outfile = os.path.join(well_folder, selection + ".csv") print("\n" + selection, interval, fluids) well_layer = make_new_well_layer( selected_interval, all_wells_df, drilled_wells_info, prod_data, well_colors, selection=selection, fluids=fluids, label=value, ) data = well_layer["data"] short_names = [] well_types = [] fluids = [] volumes = [] units = [] start_years = [] last_years = [] colors = [] index = 1 for item in data: tooltip = item["tooltip"] info = tooltip.split(" ") short_name = info[0].replace(":", "") well_type = info[1] if len(info) >= 3: fluid = info[2] if "Start:" in info: ind = info.index("Start:") - 2 volume = info[ind] unit = info[ind + 1] start_year = info[ind + 3] last_year = info[ind + 5].replace(")", "") else: ind = len(info) start_year = None last_year = None volume = None unit = None for i in range(3, ind): fluid = fluid + " " + info[i] if "WAG" in fluid: volume = None unit = None fluid = fluid.replace("(", "").replace(")", "") color = item["color"] index = index + 1 short_names.append(short_name) well_types.append(well_type) fluids.append(fluid) volumes.append(volume) units.append(unit) start_years.append(start_year) last_years.append(last_year) colors.append(color) zipped_list = list( zip( short_names, well_types, fluids, volumes, units, start_years, last_years, colors, ) ) layer_df = pd.DataFrame(zipped_list, columns=headers) outfile = os.path.join( well_folder, "well_layer_" + selection + interval_label + ".csv" ) layer_df.to_csv(outfile, index=False) print("List of wells in layer", selection, "stored in:", outfile) selection = "planned" fluids = [] for key in planned_well_layers: value = key print("\n" + selection, value) well_layer = make_new_well_layer( interval, all_wells_df, planned_wells_info, prod_data, well_colors, selection=selection, fluids=fluids, label=value, ) data = well_layer["data"] index = 1 for item in data: print(index, item["tooltip"], item["color"]) index = index + 1
except: path = "" return path DESCRIPTION = "Check surface metadata" parser = argparse.ArgumentParser(description=DESCRIPTION) parser.add_argument("settings_file", help="Enter name of settings file") args = parser.parse_args() settings_file = args.settings_file settings_file = os.path.abspath(settings_file) settings_folder = os.path.dirname(settings_file) settings = read_config(settings_file) settings_folder = os.path.dirname(settings_file) map_settings = settings.get("map_settings") surface_metadata_file = map_settings.get("surface_metadata_file") surface_metadata_file = os.path.join(settings_folder, surface_metadata_file) surface_metadata = pd.read_csv(surface_metadata_file) data = { "name": "draupne_fm_1", "attr": "4d_depth_max", "date": "2020-10-01-2019-10-01", } ensemble = "" real = "p10" map_type = "simulated"
get_path, ) from webviz_4d._datainput.common import ( read_config, get_config_item, ) from webviz_4d._datainput._polygons import ( load_polygons, load_zone_polygons, make_new_polyline_layer, get_zone_layer, ) config_file = "./tests/data/example_config.yaml" config = read_config(config_file) config_folder = os.path.dirname(config_file) settings_file = get_config_item(config, "settings") settings_file = os.path.join(config_folder, settings_file) settings_folder = os.path.dirname(settings_file) settings = read_config(settings_file) polygon_folder = settings["polygon_data"] polygon_folder = Path(os.path.join(settings_folder, polygon_folder)) polygon_colors = settings.get("polygon_colors") fault_layer = { "name": "Faults", "checked": True, "base_layer": False,
def __init__( self, app, wellfolder: Path = None, production_data: Path = None, polygons_folder: Path = None, colormaps_folder: Path = None, map1_defaults: dict = None, map2_defaults: dict = None, map3_defaults: dict = None, map_suffix: str = ".gri", default_interval: str = None, settings: Path = None, delimiter: str = "--", surface_metadata_file: Path = None, attribute_maps_file: Path = None, interval_mode: str = "reverse", selector_file: Path = None, ): super().__init__() self.shared_settings = app.webviz_settings["shared_settings"] self.fmu_directory = self.shared_settings["fmu_directory"] self.label = self.shared_settings.get("label", self.fmu_directory) self.basic_well_layers = self.shared_settings.get( "basic_well_layers", None) self.additional_well_layers = self.shared_settings.get( "additional_well_layers") self.map_suffix = map_suffix self.delimiter = delimiter self.interval_mode = interval_mode self.number_of_maps = 3 self.observations = "observed" self.simulations = "simulated" self.wellsuffix = ".w" self.surface_layer = None self.attribute_settings = {} self.well_update = "" self.production_update = "" self.selected_names = [None, None, None] self.selected_attributes = [None, None, None] self.selected_ensembles = [None, None, None] self.selected_realizations = [None, None, None] self.well_base_layers = [] self.interval_well_layers = {} # Define well layers default_basic_well_layers = { "drilled_wells": "Drilled wells", "reservoir_section": "Reservoir sections", "active_production": "Current producers", "active_injection": "Current injectors", } if self.basic_well_layers is None: self.basic_well_layers = default_basic_well_layers default_additional_well_layers = { "production": "Producers", "production_start": "Producers - started", "production_completed": "Producers - completed", "injection": "Injectors", "injection_start": "Injectors - started", "injection_completed": "Injectors - completed", } if self.additional_well_layers is None: self.additional_well_layers = default_additional_well_layers # Read production data self.prod_names = [ "BORE_OIL_VOL.csv", "BORE_GI_VOL.csv", "BORE_WI_VOL.csv" ] self.prod_folder = production_data self.prod_data = read_csvs(folder=self.prod_folder, csv_files=self.prod_names) print("Reading production data from", self.prod_folder) # Read maps metadata self.surface_metadata_file = surface_metadata_file print("Reading maps metadata from", self.surface_metadata_file) self.surface_metadata = (read_csv( csv_file=self.surface_metadata_file) if self.surface_metadata_file is not None else None) self.selector_file = selector_file self.selection_list = read_config(get_path(path=self.selector_file)) # Read custom colormaps self.colormaps_folder = colormaps_folder if self.colormaps_folder is not None: self.colormap_files = [ get_path(Path(fn)) for fn in json.load(find_files(self.colormaps_folder, ".csv")) ] print("Reading custom colormaps from:", self.colormaps_folder) load_custom_colormaps(self.colormap_files) # Read attribute maps settings (min-/max-values) self.colormap_settings = None self.attribute_maps_file = attribute_maps_file if self.attribute_maps_file is not None: self.colormap_settings = read_csv( csv_file=self.attribute_maps_file) print("Colormaps settings loaded from file", self.attribute_maps_file) # Read settings self.settings_path = settings if self.settings_path: self.config = read_config(get_path(path=self.settings_path)) self.attribute_settings = None self.delimiter = None map_settings = self.config.get("map_settings") self.attribute_settings = map_settings.get("attribute_settings") self.default_colormap = map_settings.get("default_colormap", "seismic") # Read settings (defaults) if default_interval is None: try: default_interval = self.selection_list[ self.observations]["interval"][0] except: try: default_interval = self.selection_list[ self.simulations]["interval"][0] except: default_interval = None self.map_defaults = [] self.maps_metadata_list = [] if map1_defaults is not None: map1_defaults["interval"] = default_interval self.map_defaults.append(map1_defaults) self.map1_options = self.selection_list[map1_defaults["map_type"]] if map2_defaults is not None: map2_defaults["interval"] = default_interval self.map_defaults.append(map2_defaults) self.map2_options = self.selection_list[map2_defaults["map_type"]] if map3_defaults is not None: map3_defaults["interval"] = default_interval self.map_defaults.append(map3_defaults) self.map2_options = self.selection_list[map2_defaults["map_type"]] print("Default interval", default_interval) if map1_defaults is None or map2_defaults is None or map3_defaults is None: self.map_defaults = get_map_defaults( self.selection_list, default_interval, self.observations, self.simulations, ) else: self.map_defaults = [] self.map_defaults.append(map1_defaults) self.map_defaults.append(map2_defaults) self.map_defaults.append(map3_defaults) self.selected_intervals = [ default_interval, default_interval, default_interval ] self.colors = get_well_colors(self.config) # Load polygons self.polygons_folder = polygons_folder self.polygon_layers = None self.zone_polygon_layers = None if self.polygons_folder is not None: self.polygon_files = [ get_path(Path(fn)) for fn in json.load(find_files(self.polygons_folder, ".csv")) ] print("Reading polygons from:", self.polygons_folder) polygon_colors = self.config.get("polygon_colors") self.polygon_layers = load_polygons(self.polygon_files, polygon_colors) # Load zone fault if existing self.zone_faults_folder = Path( os.path.join(self.polygons_folder, "rms")) self.zone_faults_files = [ get_path(Path(fn)) for fn in json.load( find_files(self.zone_faults_folder, ".csv")) ] print("Reading zone polygons from:", self.zone_faults_folder) self.zone_polygon_layers = load_zone_polygons( self.zone_faults_files, polygon_colors) # Read update dates and well data # self.drilled_wells_df: dataframe with wellpaths (x- and y positions) for all drilled wells # self.drilled_wells_info: dataframe with metadata for all drilled wells self.wellfolder = wellfolder print("Reading well data from", self.wellfolder) if self.wellfolder: self.wellbore_info = read_csv(csv_file=Path(self.wellfolder) / "wellbore_info.csv") update_dates = get_update_dates( welldata=get_path( Path(self.wellfolder) / ".welldata_update.yaml"), productiondata=get_path( Path(self.wellfolder) / ".production_update.yaml"), ) self.well_update = update_dates["well_update_date"] self.production_update = update_dates["production_last_date"] self.all_wells_info = read_csv(csv_file=Path(self.wellfolder) / "wellbore_info.csv") self.all_wells_info["file_name"] = self.all_wells_info[ "file_name"].apply(lambda x: get_path(Path(x))) self.all_wells_df = load_all_wells(self.all_wells_info) self.drilled_wells_files = list( self.wellbore_info[self.wellbore_info["layer_name"] == "Drilled wells"]["file_name"]) self.drilled_wells_df = self.all_wells_df.loc[ self.all_wells_df["layer_name"] == "Drilled wells"] self.drilled_wells_info = self.all_wells_info.loc[ self.all_wells_info["layer_name"] == "Drilled wells"] interval = self.selected_intervals[0] # Create well layers for the layers that are independent of the selected 4D interval if self.drilled_wells_df is not None: for key, value in self.basic_well_layers.items(): if value is not None: if "production" in key: fluids = ["oil"] elif "injection" in key: fluids = ["gas", "water"] else: fluids = [] print("Creating well layer for", value) well_layer = make_new_well_layer( interval, self.drilled_wells_df, self.drilled_wells_info, self.prod_data, self.colors, selection=key, fluids=fluids, label=value, ) if well_layer is not None: self.well_base_layers.append(well_layer) # Load wellpaths for planned wells and create planned well layers try: planned_well_df = self.all_wells_df.loc[ self.all_wells_df["layer_name"] != "Drilled wells"] planned_well_info = self.all_wells_info.loc[ self.all_wells_info["layer_name"] != "Drilled wells"] except: planned_well_df = None planned_well_info = None if planned_well_df is not None: planned_layers_df = planned_well_info["layer_name"].dropna() planned_layers = planned_layers_df.unique() for planned_layer in planned_layers: self.well_base_layers.append( make_new_well_layer( self.selected_intervals[0], planned_well_df, planned_well_info, prod_data=None, colors=self.colors, selection="planned", fluids=[], label=planned_layer, )) # Create production and injection layers for the default interval self.interval_well_layers = self.create_additional_well_layers( interval) # Create selectors (attributes, names and dates) for all 3 maps self.selector = SurfaceSelector(app, self.selection_list, self.map_defaults[0]) self.selector2 = SurfaceSelector(app, self.selection_list, self.map_defaults[1]) self.selector3 = SurfaceSelector(app, self.selection_list, self.map_defaults[2]) self.set_callbacks(app)
def main(): # Main description = "Create a well overview file (.csv) with relevant metadata" parser = argparse.ArgumentParser(description=description) parser.add_argument("config_file", help="Enter path to the WebViz-4D configuration file") args = parser.parse_args() print(description) print(args) config_file = args.config_file config = common.read_config(config_file) # Well and production data well_suffix = common.get_config_item(config, "well_suffix") map_suffix = common.get_config_item(config, "map_suffix") delimiter = common.get_config_item(config, "delimiter") metadata_file = common.get_config_item(config, "surface_metadata") well_directory = common.get_config_item(config, "wellfolder") well_directory = common.get_full_path(well_directory) prod_info_dir = common.get_config_item(config, "production_data") prod_info_dir = common.get_full_path(prod_info_dir) update_metadata_file = os.path.join(prod_info_dir, ".production_update.yaml") prod_info_files = [os.path.join(prod_info_dir, OIL_PRODUCTION_FILE)] prod_info_files.append(os.path.join(prod_info_dir, GAS_INJECTION_FILE)) prod_info_files.append(os.path.join(prod_info_dir, WATER_INJECTION_FILE)) prod_info_list = [] for prod_info_file in prod_info_files: print("Reading production info from file " + str(prod_info_file)) prod_info = pd.read_csv(prod_info_file) prod_info.name = os.path.basename(str(prod_info_file)) prod_info_list.append(prod_info) _drilled_well_df, drilled_well_info, interval_df = well.load_all_wells( well_directory, well_suffix) print(interval_df) drilled_well_info = add_production_volumes(drilled_well_info, prod_info_list) wellbore_overview = drilled_well_info[[ "wellbore.name", "wellbore.well_name", "BORE_OIL_VOL.csv_PDM well name", "wellbore.drilling_end_date", "wellbore.type", "wellbore.fluids", "BORE_OIL_VOL.csv_Start date", "BORE_OIL_VOL.csv_Stop date", "BORE_GI_VOL.csv_Start date", "BORE_GI_VOL.csv_Stop date", "BORE_WI_VOL.csv_Start date", "BORE_WI_VOL.csv_Stop date", ]] print(wellbore_overview) wellbores = wellbore_overview["wellbore.name"].unique() top_completion = [] end_completion = [] for wellbore in wellbores: try: top_md = interval_df[interval_df["interval.wellbore"] == wellbore]["interval.mdTop"].values[0] except: top_md = None top_completion.append(top_md) try: base_md = interval_df[interval_df["interval.wellbore"] == wellbore]["interval.mdBottom"].values[-1] except: base_md = None print(wellbore, top_md, base_md) end_completion.append(base_md) wellbore_overview.insert(6, "Top Screen", top_completion) wellbore_overview.insert(7, "Base Screen", end_completion) wellbore_overview.rename(columns={ "wellbore.name": "Wellbore", "wellbore.well_name": "Well", "wellbore.drilling_end_date": "Drilling ended", "wellbore.type": "Type", "wellbore.fluids": "Fluid(s)", "BORE_OIL_VOL.csv_PDM well name": "PDM Well", "BORE_OIL_VOL.csv_Start date": "Start oil prod.", "BORE_OIL_VOL.csv_Stop date": "End oil prod.", "BORE_GI_VOL.csv_Start date": "Start gas inj.", "BORE_GI_VOL.csv_Stop date": "End gas inj.", "BORE_WI_VOL.csv_Start date": "Start water inj.", "BORE_WI_VOL.csv_Stop date": "End water inj.", }, inplace=True) wellbore_overview.sort_values("Wellbore", inplace=True) print(wellbore_overview) csv_file = os.path.join(well_directory, "wellbore_overview.csv") wellbore_overview.to_csv(csv_file, index=False, float_format='%.1f') print("Wellbore overview saved to:", csv_file)
def main(): """ Extract min-/max-values for all maps """ parser = argparse.ArgumentParser( description="Extract min-/max-values for all maps") parser.add_argument("config_file", help="Enter path to the WebViz-4D configuration file") parser.add_argument( "--mode", help= "Full=> all maps, Standard (default)=> only one realization and iteration", default="Standard", ) args = parser.parse_args() config_file = args.config_file mode = args.mode config = common.read_config(config_file) shared_settings = config["shared_settings"] map_suffix = common.get_config_item(config, "map_suffix") delimiter = common.get_config_item(config, "delimiter") metadata_file = common.get_config_item(config, "surface_metadata") settings_file = common.get_config_item(config, "settings") settings_file = common.get_full_path(settings_file) settings = common.read_config(settings_file) csv_file = settings["map_settings"]["colormaps_settings"] csv_file = common.get_full_path(csv_file) print(csv_file) if csv_file is not None and os.path.isfile(csv_file): old_map_df = pd.read_csv(csv_file) print(" - file loaded") print(old_map_df) else: old_map_df = None csv_file = settings["map_settings"]["colormaps_settings"] surface_metadata = _metadata.get_metadata(shared_settings, map_suffix, delimiter, metadata_file) print("surface_metadata") print(surface_metadata) surface_types = ["observations", "results"] mapping_dict = {"observations": "observed", "results": "simulated"} results_map_dir = mapping_dict["results"] + "_maps" if results_map_dir is not None: map_settings = shared_settings[results_map_dir] realization_names = map_settings["realization_names"] iteration_names = map_settings["ensemble_names"] selected_realization = realization_names[0].replace("*", "0") selected_iteration = iteration_names[0].replace("*", "0") map_types = [] surface_names = [] attributes = [] intervals = [] map_files = [] min_values = [] max_values = [] lower_limits = [] upper_limits = [] headers = [ "map type", "name", "attribute", "interval", "minimum value", "maximum value", "lower_limit", "upper_limit", "file_path", ] map_df = pd.DataFrame() surface_files = surface_metadata["filename"] surface_files = surface_files.replace("/.", "/").replace(".yaml", "") for _index, row in surface_metadata.iterrows(): #print(row) map_type = row["map_type"] surface_name = row["data.name"] attribute = row["data.content"] interval = (row["data.time.t2"].replace("-", "") + "_" + row["data.time.t1"].replace("-", "")) surface_file = row["filename"] surface_file = surface_file.replace("/.", "/").replace(".yaml", "") # print(surface_file) print(map_type, surface_name, attribute, interval) if not mode == "Full": realization = row["fmu_id.realization"] iteration = row["fmu_id.ensemble"] # print(realization, iteration) if map_type == "results": if (realization == selected_realization and iteration == selected_iteration): surface = load_surface(surface_file) map_types.append(map_type) surface_names.append(surface_name) attributes.append(attribute) intervals.append(interval) zvalues = get_surface_arr(surface)[2] min_val = np.nanmin(zvalues) max_val = np.nanmax(zvalues) min_values.append(min_val) max_values.append(max_val) map_files.append(surface_file) lower_limit, upper_limit = get_plot_limits( old_map_df, map_type, surface_name, attribute, interval) lower_limits.append(lower_limit) upper_limits.append(upper_limit) else: surface = load_surface(surface_file) map_types.append(map_type) surface_names.append(surface_name) attributes.append(attribute) intervals.append(interval) zvalues = get_surface_arr(surface)[2] min_val = np.nanmin(zvalues) max_val = np.nanmax(zvalues) min_values.append(min_val) max_values.append(max_val) map_files.append(surface_file) lower_limit, upper_limit = get_plot_limits( old_map_df, map_type, surface_name, attribute, interval) lower_limits.append(lower_limit) upper_limits.append(upper_limit) else: surface = load_surface(surface_file) map_types.append(map_type) surface_names.append(surface_name) attributes.append(attribute) intervals.append(interval) zvalues = get_surface_arr(surface)[2] min_val = np.nanmin(zvalues) max_val = np.nanmax(zvalues) min_values.append(min_val) max_values.append(max_val) map_files.append(surface_file) lower_limit, upper_limit = get_plot_limits(old_map_df, map_type, surface_name, attribute, interval) lower_limits.append(lower_limit) upper_limits.append(upper_limit) map_df[headers[0]] = map_types map_df[headers[1]] = surface_names map_df[headers[2]] = attributes map_df[headers[3]] = intervals map_df[headers[4]] = min_values map_df[headers[5]] = max_values map_df[headers[6]] = lower_limits map_df[headers[7]] = upper_limits map_df[headers[8]] = map_files print(map_df) map_df.to_csv(csv_file, index=False) print("Data saved to ", csv_file)
def test_get_config_item(): config_file = "../../reek_4d.yaml" config = read_config(config_file) print(get_config_item(config, "fmu_directory")) assert get_config_item(config, "fmu_directory") == FMU_DIRECTORY
def __init__( self, app, wellfolder: Path = None, production_data: Path = None, map1_defaults: dict = None, well_suffix: str = ".w", map_suffix: str = ".gri", default_interval: str = None, settings: Path = None, delimiter: str = "--", surface_metadata: str = "surface_metadata.csv", ): super().__init__() self.shared_settings = app.webviz_settings["shared_settings"] self.fmu_directory = self.shared_settings["fmu_directory"] self.map_suffix = map_suffix self.delimiter = delimiter self.wellfolder = wellfolder self.observations = "observations" self.simulations = "results" self.config = None self.attribute_settings = {} self.surface_metadata = None self.well_base_layers = None #print("default_interval", default_interval) self.fmu_info = self.fmu_directory self.well_update = "" self.production_update = "" self.number_of_maps = 1 self.metadata = get_metadata( self.shared_settings, map_suffix, delimiter, surface_metadata ) #print("Maps metadata") #print(self.metadata) self.intervals, incremental = get_all_intervals(self.metadata, "reverse") #print(self.intervals) if default_interval is None: default_interval = self.intervals[-1] self.surface_layer = None if settings: self.configuration = settings self.config = read_config(self.configuration) # print(self.config) try: self.attribute_settings = self.config["map_settings"][ "attribute_settings" ] except: pass try: colormaps_folder = self.config["map_settings"]["colormaps_folder"] if colormaps_folder: colormaps_folder = get_full_path(colormaps_folder) print("Reading custom colormaps from:", colormaps_folder) load_custom_colormaps(colormaps_folder) except: pass try: attribute_maps_file = self.config["map_settings"]["colormaps_settings"] attribute_maps_file = get_full_path(attribute_maps_file) self.surface_metadata = pd.read_csv(attribute_maps_file) print("Colormaps settings loaded from file", attribute_maps_file) #print(self.surface_metadata) except: pass self.map_defaults = [] if map1_defaults is not None: map1_defaults["interval"] = default_interval self.map_defaults.append(map1_defaults) print("Default interval", default_interval) #print("Map 1 defaults:") #print(map1_defaults) if map1_defaults is None: self.map_defaults = create_map_defaults( self.metadata, default_interval, self.observations, self.simulations ) else: self.map_defaults = [] self.map_defaults.append(map1_defaults) #print("map_defaults", self.map_defaults) self.selected_interval = default_interval self.selected_name = None self.selected_attribute = None self.selected_ensemble = None self.selected_realization = None self.wellsuffix = ".w" self.well_base_layers = [] self.colors = get_well_colors(self.config) if wellfolder and os.path.isdir(wellfolder): self.wellfolder = wellfolder update_dates = get_update_dates(wellfolder) self.well_update = update_dates["well_update_date"] self.production_update = update_dates["production_last_date"] ( self.drilled_well_df, self.drilled_well_info, self.interval_df, ) = load_all_wells(wellfolder, self.wellsuffix) if self.drilled_well_df is not None: self.well_base_layers.append( make_new_well_layer( self.selected_interval, self.drilled_well_df, self.drilled_well_info, ) ) self.well_base_layers.append( make_new_well_layer( self.selected_interval, self.drilled_well_df, self.drilled_well_info, colors=self.colors, selection="reservoir_section", label="Reservoir sections", ) ) planned_wells_dir = [f.path for f in os.scandir(wellfolder) if f.is_dir()] for folder in planned_wells_dir: planned_well_df, planned_well_info, dummy_df = load_all_wells( folder, self.wellsuffix ) if planned_well_df is not None: self.well_base_layers.append( make_new_well_layer( self.selected_interval, planned_well_df, planned_well_info, self.colors, selection="planned", label=os.path.basename(folder), ) ) elif wellfolder and not os.path.isdir(wellfolder): print("ERROR: Folder", wellfolder, "doesn't exist. No wells loaded") self.selector = SurfaceSelector( app, self.metadata, self.intervals, self.map_defaults[0] ) self.set_callbacks(app)