From 0add10081d2d3097044d4ab0b5527cf1f7897801 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Therese=20Natter=C3=B8y?= <61694854+tnatt@users.noreply.github.com> Date: Wed, 18 Sep 2024 13:13:41 +0200 Subject: [PATCH] MAINT: Stop using XTGeoDialog for logging (#138) --- src/grid3d_maps/__init__.py | 15 +++++ .../aggregate/grid3d_aggregate_map.py | 10 +-- src/grid3d_maps/avghc/_compute_avg.py | 26 ++++---- src/grid3d_maps/avghc/_compute_hcpfz.py | 11 ++-- src/grid3d_maps/avghc/_configparser.py | 28 ++++---- .../avghc/_export_via_fmudataio.py | 10 ++- src/grid3d_maps/avghc/_get_grid_props.py | 64 +++++++++---------- .../avghc/_get_zonation_filters.py | 21 +++--- src/grid3d_maps/avghc/_hc_plotmap.py | 20 +++--- src/grid3d_maps/avghc/_loader.py | 6 +- src/grid3d_maps/avghc/_mapsettings.py | 6 +- src/grid3d_maps/avghc/grid3d_average_map.py | 39 ++++++----- src/grid3d_maps/avghc/grid3d_hc_thickness.py | 40 ++++++------ src/grid3d_maps/contact/_compute_contact.py | 8 +-- src/grid3d_maps/contact/_get_grid_props.py | 16 ++--- src/grid3d_maps/contact/grid3d_contact_map.py | 29 ++++----- 16 files changed, 169 insertions(+), 180 deletions(-) diff --git a/src/grid3d_maps/__init__.py b/src/grid3d_maps/__init__.py index df533bd..a8a315b 100644 --- a/src/grid3d_maps/__init__.py +++ b/src/grid3d_maps/__init__.py @@ -1,7 +1,22 @@ """Top-level package for grid3d_maps""" +import logging +import sys + try: from .version import __version__ except ImportError: __version__ = "0.0.0" + +logger = logging.getLogger(__name__) +formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s") +std_out_handler = logging.StreamHandler(sys.stdout) +std_out_handler.setFormatter(formatter) +std_out_handler.setLevel(logging.INFO) +logger.addHandler(std_out_handler) + +std_err_handler = logging.StreamHandler(sys.stderr) +std_err_handler.setFormatter(formatter) +std_err_handler.setLevel(logging.WARNING) +logger.addHandler(std_err_handler) diff --git a/src/grid3d_maps/aggregate/grid3d_aggregate_map.py b/src/grid3d_maps/aggregate/grid3d_aggregate_map.py index ce0ca57..5fb4d01 100644 --- a/src/grid3d_maps/aggregate/grid3d_aggregate_map.py +++ b/src/grid3d_maps/aggregate/grid3d_aggregate_map.py @@ -1,10 +1,10 @@ +import logging import pathlib import sys from typing import List import numpy as np import xtgeo -from xtgeo.common import XTGeoDialog from grid3d_maps.aggregate._config import ( AggregationMethod, @@ -23,8 +23,8 @@ from . import _config, _grid_aggregation -_XTG = XTGeoDialog() - +logger = logging.getLogger(__name__) +logger.setLevel(logging.INFO) # Module variables for ERT hook implementation: DESCRIPTION = ( @@ -89,7 +89,7 @@ def generate_maps( """ Calculate and write aggregated property maps to file """ - _XTG.say("Reading grid, properties and zone(s)") + logger.info("Reading grid, properties and zone(s)") grid = xtgeo.grid_from_file(input_.grid) properties = extract_properties(input_.properties, grid, input_.dates) _filters = [] @@ -97,7 +97,7 @@ def generate_maps( _filters.append(("all", None)) if computesettings.zone: _filters += extract_zonations(zonation, grid) - _XTG.say("Generating Property Maps") + logger.info("Generating Property Maps") xn, yn, p_maps = _grid_aggregation.aggregate_maps( create_map_template(map_settings), grid, diff --git a/src/grid3d_maps/avghc/_compute_avg.py b/src/grid3d_maps/avghc/_compute_avg.py index 8c9cf37..cc6bb69 100644 --- a/src/grid3d_maps/avghc/_compute_avg.py +++ b/src/grid3d_maps/avghc/_compute_avg.py @@ -1,17 +1,17 @@ import getpass +import logging from time import localtime, strftime import numpy as np import numpy.ma as ma import xtgeo -from xtgeo.common import XTGeoDialog, null_logger from xtgeo.surface import RegularSurface from xtgeoviz import quickplot from ._export_via_fmudataio import export_avg_map_dataio -xtg = XTGeoDialog() -logger = null_logger(__name__) +logger = logging.getLogger(__name__) +logger.setLevel(logging.INFO) def get_avg(config, specd, propd, dates, zonation, zoned, filterarray): @@ -19,7 +19,7 @@ def get_avg(config, specd, propd, dates, zonation, zoned, filterarray): It will return a dictionary per parameter and eventually dates """ - logger.info("Dates is unused %s", dates) + logger.debug("Dates is unused %s", dates) avgd = {} @@ -43,12 +43,12 @@ def get_avg(config, specd, propd, dates, zonation, zoned, filterarray): values=np.zeros((ncol, nrow)), ) - xtg.say("Mapping ...") + logger.info("Mapping ...") if len(propd) == 0 or len(zoned) == 0: raise RuntimeError("The dictionary or is zero. Stop") for zname, zrange in zoned.items(): - logger.info("ZNAME and ZRANGE are %s: %s", zname, zrange) + logger.debug("ZNAME and ZRANGE are %s: %s", zname, zrange) usezonation = zonation usezrange = zrange @@ -68,7 +68,7 @@ def get_avg(config, specd, propd, dates, zonation, zoned, filterarray): usezrange = 999 if config["computesettings"]["all"] is not True: - logger.info("Skip <%s> (cf. computesettings: all)", zname) + logger.debug("Skip <%s> (cf. computesettings: all)", zname) continue else: if config["computesettings"]["zone"] is not True: @@ -102,7 +102,7 @@ def get_avg(config, specd, propd, dates, zonation, zoned, filterarray): if filename is None: export_avg_map_dataio(avgd[usename], usename, config) else: - xtg.say("Map file to {}".format(filename)) + logger.info("Map file to {}".format(filename)) avgd[usename].to_file(filename) return avgd @@ -111,7 +111,7 @@ def get_avg(config, specd, propd, dates, zonation, zoned, filterarray): def do_avg_plotting(config, avgd): """Do plotting via matplotlib to PNG (etc) (if requested)""" - xtg.say("Plotting ...") + logger.info("Plotting ...") for names, xmap in avgd.items(): # 'names' is a tuple as (zname, pname) @@ -122,7 +122,7 @@ def do_avg_plotting(config, avgd): pcfg = _avg_plotsettings(config, zname, pname) - xtg.say(f"Plot to {plotfile}") + logger.info("Plot to {}".format(plotfile)) usevrange = pcfg["valuerange"] @@ -131,11 +131,11 @@ def do_avg_plotting(config, avgd): try: fau = xtgeo.polygons_from_file(pcfg["faultpolygons"], fformat="guess") faults = {"faults": fau} - xtg.say("Use fault polygons") + logger.info("Use fault polygons") except OSError as err: - xtg.say(err) + logger.info(str(err)) faults = None - xtg.say("No fault polygons") + logger.info("No fault polygons") quickplot( xmap, diff --git a/src/grid3d_maps/avghc/_compute_hcpfz.py b/src/grid3d_maps/avghc/_compute_hcpfz.py index 211ded2..dd31d4d 100644 --- a/src/grid3d_maps/avghc/_compute_hcpfz.py +++ b/src/grid3d_maps/avghc/_compute_hcpfz.py @@ -1,9 +1,8 @@ -import numpy.ma as ma -from xtgeo.common import XTGeoDialog, null_logger +import logging -xtg = XTGeoDialog() +import numpy.ma as ma -logger = null_logger(__name__) +logger = logging.getLogger(__name__) def get_hcpfz(config, initd, restartd, dates, hcmode, filterarray): @@ -49,7 +48,7 @@ def _get_hcpfz_ecl(config, initd, restartd, dates, hcmode, filterarray): hcmethod = config["computesettings"]["method"] if not dates: - xtg.error("Dates are missing. Bug?") + logger.error("Dates are missing. Bug?") raise RuntimeError("Dates er missing. Bug?") for date in dates: @@ -111,7 +110,7 @@ def _get_hcpfz_ecl(config, initd, restartd, dates, hcmode, filterarray): if dt1 in hcpfzd and dt2 in hcpfzd: hcpfzd[cdate] = hcpfzd[dt1] - hcpfzd[dt2] else: - xtg.warn( + logger.warning( f"Cannot retrieve data for date {dt1} and/or {dt2}. " "Some TSTEPs failed?" ) diff --git a/src/grid3d_maps/avghc/_configparser.py b/src/grid3d_maps/avghc/_configparser.py index 960ea9a..28ac012 100644 --- a/src/grid3d_maps/avghc/_configparser.py +++ b/src/grid3d_maps/avghc/_configparser.py @@ -1,17 +1,15 @@ import argparse import copy import datetime +import logging import os.path import sys import yaml -from xtgeo.common import XTGeoDialog, null_logger from grid3d_maps.avghc._loader import ConstructorError, FMUYamlSafeLoader -xtg = XTGeoDialog() - -logger = null_logger(__name__) +logger = logging.getLogger(__name__) def parse_args(args, appname, appdescr): @@ -96,7 +94,7 @@ def parse_args(args, appname, appdescr): if len(args) < 2: parser.print_help() - print("QUIT") + logger.info("QUIT") raise SystemExit return parser.parse_args(args) @@ -121,10 +119,10 @@ def yconfig(inputfile, tmp=False, standard=False): try: config = yaml.load(stream, Loader=FMUYamlSafeLoader) except ConstructorError as errmsg: - xtg.error(errmsg) + logger.error(errmsg) raise SystemExit from errmsg - xtg.say(f"Input config YAML file <{inputfile}> is read...") + logger.info(f"Input config YAML file <{inputfile}> is read...") # if the file is a temporary file, delete: if tmp: @@ -326,7 +324,7 @@ def yconfig_override(config, args, appname): if args.eclroot: newconfig["input"]["eclroot"] = args.eclroot - xtg.say( + logger.info( "YAML config overruled... eclroot is now: <{}>".format( newconfig["input"]["eclroot"] ) @@ -334,7 +332,7 @@ def yconfig_override(config, args, appname): if args.folderroot: newconfig["input"]["folderroot"] = args.folderroot - xtg.say( + logger.info( "YAML config overruled... folderroot is now: <{}>".format( newconfig["input"]["folderroot"] ) @@ -342,7 +340,7 @@ def yconfig_override(config, args, appname): if args.zfile: newconfig["zonation"]["yamlfile"] = args.zfile - xtg.say( + logger.info( "YAML config overruled... zfile (yaml) is now: <{}>".format( newconfig["zonation"]["yamlfile"] ) @@ -350,7 +348,7 @@ def yconfig_override(config, args, appname): if args.mapfolder: newconfig["output"]["mapfolder"] = args.mapfolder - xtg.say( + logger.info( "YAML config overruled... output:mapfolder is now: <{}>".format( newconfig["output"]["mapfolder"] ) @@ -358,7 +356,7 @@ def yconfig_override(config, args, appname): if args.plotfolder: newconfig["output"]["plotfolder"] = args.plotfolder - xtg.say( + logger.info( "YAML config overruled... output:plotfolder is now: <{}>".format( newconfig["output"]["plotfolder"] ) @@ -445,9 +443,9 @@ def yconfig_set_defaults(config, appname): if appname == "grid3d_hc_thickness": if "dates" not in newconfig["input"]: if newconfig["computesettings"]["mode"] in "rock": - xtg.say('No date give, probably OK since "rock" mode)') + logger.info('No date give, probably OK since "rock" mode)') else: - xtg.warn('Warning: No date given, set date to "unknowndate")') + logger.warning('Warning: No date given, set date to "unknowndate")') newconfig["input"]["dates"] = ["unknowndate"] @@ -509,7 +507,7 @@ def yconfig_addons(config, appname): if "superranges" in zconfig: newconfig["zonation"]["superranges"] = zconfig["superranges"] - xtg.say(f"Add configuration to {appname}") + logger.info(f"Add configuration to {appname}") return newconfig diff --git a/src/grid3d_maps/avghc/_export_via_fmudataio.py b/src/grid3d_maps/avghc/_export_via_fmudataio.py index c09887d..03cba3e 100644 --- a/src/grid3d_maps/avghc/_export_via_fmudataio.py +++ b/src/grid3d_maps/avghc/_export_via_fmudataio.py @@ -1,16 +1,14 @@ """General functions that exports maps / plots using fmu-dataio.""" import json +import logging import os from pathlib import Path import fmu.dataio as dataio from fmu.config import utilities as ut -from xtgeo.common import XTGeoDialog, null_logger -xtg = XTGeoDialog() - -logger = null_logger(__name__) +logger = logging.getLogger(__name__) def _get_global_config(thisconfig): @@ -117,7 +115,7 @@ def export_avg_map_dataio(surf, nametuple, config): workflow="grid3d-maps script average maps", ) fname = edata.export(surf) - xtg.say(f"Output as fmu-dataio: {fname}") + logger.info(f"Output as fmu-dataio: {fname}") return fname @@ -171,5 +169,5 @@ def export_hc_map_dataio(surf, zname, date, hcmode, config): workflow="grid3d-maps script hc thickness maps", ) fname = edata.export(surf) - xtg.say(f"Output as fmu-dataio: {fname}") + logger.info(f"Output as fmu-dataio: {fname}") return fname diff --git a/src/grid3d_maps/avghc/_get_grid_props.py b/src/grid3d_maps/avghc/_get_grid_props.py index f845cff..7f4bb72 100644 --- a/src/grid3d_maps/avghc/_get_grid_props.py +++ b/src/grid3d_maps/avghc/_get_grid_props.py @@ -1,16 +1,12 @@ +import logging from collections import defaultdict import numpy as np import numpy.ma as ma import xtgeo - -# from xtgeo.common.exceptions import KeywordNotFoundError -from xtgeo.common import XTGeoDialog, null_logger from xtgeo.common.exceptions import DateNotFoundError, KeywordFoundNoDateError -xtg = XTGeoDialog() - -logger = null_logger(__name__) +logger = logging.getLogger(__name__) # Heavy need for reprogramming...: # pylint: disable=logging-format-interpolation @@ -134,7 +130,7 @@ def import_data(appname, gfile, initlist, restartlist, dates): appname(str): Name of application """ - logger.info("Import data for %s", appname) + logger.debug("Import data for %s", appname) # get the grid data + some geometrics grd = xtgeo.grid_from_file(gfile) @@ -173,7 +169,7 @@ def import_data(appname, gfile, initlist, restartlist, dates): restdict = defaultdict(list) for rpar, rfile in restartlist.items(): - logger.info("Parameter RESTART: %s \t file is %s", rpar, rfile) + logger.debug("Parameter RESTART: %s \t file is %s", rpar, rfile) restdict[rfile].append(rpar) initobjects = [] @@ -186,7 +182,7 @@ def import_data(appname, gfile, initlist, restartlist, dates): lookfornames.append(lookforname) usenames.append(usename) - xtg.say("Import <{}> from <{}> ...".format(lookfornames, inifile)) + logger.info(f"Import <{lookfornames}> from <{inifile}> ...") tmp = xtgeo.gridproperties_from_file( inifile, names=lookfornames, fformat="init", grid=grd ) @@ -203,14 +199,14 @@ def import_data(appname, gfile, initlist, restartlist, dates): if lookforname and lookforname.lower() in {"none", "unknown"}: lookforname = None - xtg.say(f"Import <{lookforname}> from <{inifile}> ...") + logger.info(f"Import <{lookforname}> from <{inifile}> ...") tmp = xtgeo.gridproperty_from_file( inifile, name=lookforname, fformat="guess", grid=grd ) tmp.name = usename initobjects.append(tmp) - logger.info("Init type data is now imported for {}".format(appname)) + logger.debug("Init type data is now imported for {}".format(appname)) # restarts; will issue an warning if one or more dates are not found # assume that this is Eclipse stuff .UNRST @@ -223,29 +219,29 @@ def import_data(appname, gfile, initlist, restartlist, dates): ) except DateNotFoundError as rwarn: - logger.info("Got warning... %s", rwarn) + logger.debug("Got warning... %s", rwarn) for prop in tmp.props: - logger.info("Append prop: {}".format(prop)) + logger.debug("Append prop: {}".format(prop)) restobjects.append(prop) except KeywordFoundNoDateError as rwarn: - logger.info("Keyword found but not for this date %s", rwarn) + logger.debug("Keyword found but not for this date %s", rwarn) raise SystemExit("STOP") from rwarn except Exception as message: raise SystemExit(message) from message else: - logger.info("Works further...") + logger.debug("Works further...") for prop in tmp.props: - logger.info("Append prop: {}".format(prop)) + logger.debug("Append prop: {}".format(prop)) restobjects.append(prop) - logger.info("Restart type data is now imported for {}".format(appname)) + logger.debug("Restart type data is now imported for {}".format(appname)) newdateslist = [] for rest in restobjects: newdateslist.append(str(rest.date)) # assure date datatype is str newdateslist = list(set(newdateslist)) - logger.info("Actual dates to use: {}".format(newdateslist)) + logger.debug("Actual dates to use: {}".format(newdateslist)) return grd, initobjects, restobjects, newdateslist @@ -268,7 +264,7 @@ def import_filters(config, appname, grd): eclroot = config["input"].get("eclroot") - logger.info("Import filter data for %s", appname) + logger.debug("Import filter data for %s", appname) filterarray = np.ones(grd.dimensions, dtype="int") @@ -281,7 +277,7 @@ def import_filters(config, appname, grd): for flist in config["filters"]: if "name" in flist: name = flist["name"] - logger.info("Filter name: %s", name) + logger.debug("Filter name: %s", name) source = flist["source"] drange = flist.get("discrange", None) @@ -300,7 +296,7 @@ def import_filters(config, appname, grd): source = source.replace("$eclroot", eclroot) gprop = xtgeo.gridproperty_from_file(source, grid=grd, name=name) pval = gprop.values - xtg.say("Filter, import <{}> from <{}> ...".format(name, source)) + logger.info("Filter, import <{}> from <{}> ...".format(name, source)) if not discrete: filterarray[(pval < irange[0]) | (pval > irange[1])] = 0 @@ -313,7 +309,7 @@ def import_filters(config, appname, grd): filterinfo = filterinfo + ":" + str(drangetxt) for ival in drange: if ival not in gprop.codes: - xtg.warn( + logger.warning( "Filter codevalue {} is not present in " "discrete property {}".format(ival, gprop.name) ) @@ -337,7 +333,7 @@ def import_filters(config, appname, grd): filterarray[zc.values < tvdrange[0]] = 0 filterarray[zc.values > tvdrange[1]] = 0 - xtg.say( + logger.info( "Filter on tdvrange {} (rough; based on cell center)".format(tvdrange) ) @@ -349,27 +345,27 @@ def import_filters(config, appname, grd): def get_numpies_hc_thickness(config, grd, initobjects, restobjects, dates): """Process for HC thickness map; to get the needed numpies""" - logger.info("Getting numpies...") + logger.debug("Getting numpies...") - logger.info("Getting actnum...") + logger.debug("Getting actnum...") actnum = grd.get_actnum().values actnum = ma.filled(actnum) - logger.info("Getting xc, yc, zc...") + logger.debug("Getting xc, yc, zc...") xc, yc, zc = grd.get_xyz(asmasked=False) xc = ma.filled(xc.values) yc = ma.filled(yc.values) zc = ma.filled(zc.values) - logger.info("Getting dz...") + logger.debug("Getting dz...") dz = ma.filled(grd.get_dz(asmasked=False).values) - logger.info("Getting dz as ma.filled...") + logger.debug("Getting dz as ma.filled...") dz[actnum == 0] = 0.0 - logger.info("Getting dx dy...") + logger.debug("Getting dx dy...") dx = ma.filled(grd.get_dx().values) dy = ma.filled(grd.get_dy().values) - logger.info("ma.filled for dx dy done") + logger.debug("ma.filled for dx dy done") initd = { "iactnum": actnum, @@ -381,7 +377,7 @@ def get_numpies_hc_thickness(config, grd, initobjects, restobjects, dates): "dz": dz, } - logger.info("Got {}".format(initd.keys())) + logger.debug("Got {}".format(initd.keys())) if config["computesettings"]["critmode"]: crname = config["computesettings"]["critmode"].upper() @@ -433,7 +429,7 @@ def get_numpies_hc_thickness(config, grd, initobjects, restobjects, dates): else: initd["soxcr"] = None - xtg.say("Got relevant INIT numpies, OK ...") + logger.debug("Got relevant INIT numpies, OK ...") # restart data, they have alos a date component: @@ -551,6 +547,6 @@ def get_numpies_avgprops(config, grd, initobjects, restobjects): ptmp = prop.get_npvalues3d() propd[pname] = ptmp - logger.info("Return specd from {} is {}".format(__name__, specd.keys())) - logger.info("Return propd from {} is {}".format(__name__, propd.keys())) + logger.debug("Return specd from {} is {}".format(__name__, specd.keys())) + logger.debug("Return propd from {} is {}".format(__name__, propd.keys())) return specd, propd diff --git a/src/grid3d_maps/avghc/_get_zonation_filters.py b/src/grid3d_maps/avghc/_get_zonation_filters.py index 1738741..aa399b9 100644 --- a/src/grid3d_maps/avghc/_get_zonation_filters.py +++ b/src/grid3d_maps/avghc/_get_zonation_filters.py @@ -1,10 +1,9 @@ +import logging + import numpy as np import xtgeo -from xtgeo.common import XTGeoDialog, null_logger - -xtg = XTGeoDialog() -logger = null_logger(__name__) +logger = logging.getLogger(__name__) def zonation(config, grd): @@ -57,20 +56,20 @@ def zonation(config, grd): elif "zranges" in config["zonation"]: zclist = config["zonation"]["zranges"] - logger.info(type(zclist)) + logger.debug(type(zclist)) for i, zz in enumerate(config["zonation"]["zranges"]): zname = list(zz.keys())[0] # zz.keys()[0] intv = list(zz.values())[0] k01 = intv[0] - 1 k02 = intv[1] - logger.info("K01 K02: %s - %s", k01, k02) + logger.debug("K01 K02: %s - %s", k01, k02) usezonation[:, :, k01:k02] = i + 1 zoned[zname] = i + 1 if "superranges" in config["zonation"]: - logger.info("Found superranges keyword...") + logger.debug("Found superranges keyword...") for i, zz in enumerate(config["zonation"]["superranges"]): zname = list(zz.keys())[0] superzoned[zname] = [] @@ -79,16 +78,16 @@ def zonation(config, grd): for zn in intv: superzoned[zname].append(zoned[zn]) else: - logger.info("Did not find any superranges...") + logger.debug("Did not find any superranges...") for myz, val in zoned.items(): - logger.info("Zonation list: %s: %s", myz, val) + logger.debug("Zonation list: %s: %s", myz, val) for key, vals in superzoned.items(): logger.debug("Superzoned %s %s", key, vals) - logger.info("The zoned dict: %s", zoned) - logger.info("The superzoned dict: %s", superzoned) + logger.debug("The zoned dict: %s", zoned) + logger.debug("The superzoned dict: %s", superzoned) zmerged = zoned.copy() zmerged.update(superzoned) diff --git a/src/grid3d_maps/avghc/_hc_plotmap.py b/src/grid3d_maps/avghc/_hc_plotmap.py index 60e48f7..ec7f1d1 100644 --- a/src/grid3d_maps/avghc/_hc_plotmap.py +++ b/src/grid3d_maps/avghc/_hc_plotmap.py @@ -1,19 +1,17 @@ """Private module for HC thickness functions.""" import getpass +import logging from time import localtime, strftime import numpy as np import xtgeo -from xtgeo.common import XTGeoDialog, null_logger from xtgeo.surface import RegularSurface from xtgeoviz import quickplot from ._export_via_fmudataio import export_hc_map_dataio -xtg = XTGeoDialog() - -logger = null_logger(__name__) +logger = logging.getLogger(__name__) def do_hc_mapping(config, initd, hcpfzd, zonation, zoned, hcmode): @@ -62,17 +60,17 @@ def do_hc_mapping(config, initd, hcpfzd, zonation, zoned, hcmode): usezrange = 999 if config["computesettings"]["all"] is not True: - logger.info("Skip <%s> (cf. computesettings: all)", zname) + logger.debug("Skip <%s> (cf. computesettings: all)", zname) continue else: if config["computesettings"]["zone"] is not True: - logger.info("Skip <%s> (cf. computesettings: zone)", zname) + logger.debug("Skip <%s> (cf. computesettings: zone)", zname) continue mapd = {} for date, hcpfz in hcpfzd.items(): - logger.info("Mapping <%s> for date <%s> ...", zname, date) + logger.debug("Mapping <%s> for date <%s> ...", zname, date) xmap = basemap.copy() xmap.hc_thickness_from_3dprops( @@ -89,7 +87,7 @@ def do_hc_mapping(config, initd, hcpfzd, zonation, zoned, hcmode): filename = None if config["output"]["mapfolder"] != "fmu-dataio": filename = _hc_filesettings(config, zname, date, hcmode) - xtg.say(f"Map file to {filename}") + logger.info(f"Map file to {filename}") xmap.to_file(filename) else: export_hc_map_dataio(xmap, zname, date, hcmode, config) @@ -106,7 +104,7 @@ def do_hc_mapping(config, initd, hcpfzd, zonation, zoned, hcmode): def do_hc_plotting(config, mapzd, hcmode, filtermean=None): """Do plotting via matplotlib to PNG (etc) (if requested)""" - xtg.say("Plotting ...") + logger.info("Plotting ...") for zname, mapd in mapzd.items(): for date, xmap in mapd.items(): @@ -114,7 +112,7 @@ def do_hc_plotting(config, mapzd, hcmode, filtermean=None): pcfg = _hc_plotsettings(config, zname, date, filtermean) - xtg.say("Plot to {}".format(plotfile)) + logger.info("Plot to {}".format(plotfile)) usevrange = pcfg["valuerange"] if len(date) > 10: @@ -128,7 +126,7 @@ def do_hc_plotting(config, mapzd, hcmode, filtermean=None): ) faults = {"faults": fau} except OSError as err: - xtg.say(err) + logger.info(err) faults = None quickplot( diff --git a/src/grid3d_maps/avghc/_loader.py b/src/grid3d_maps/avghc/_loader.py index 6b0843a..569e5ba 100644 --- a/src/grid3d_maps/avghc/_loader.py +++ b/src/grid3d_maps/avghc/_loader.py @@ -1,17 +1,17 @@ """Loading nested config files""" import io +import logging import os.path import yaml -from xtgeo.common import XTGeoDialog, null_logger from yaml.constructor import ConstructorError from yaml.nodes import MappingNode file_types = (io.IOBase,) -xtg = XTGeoDialog() -logger = null_logger(__name__) + +logger = logging.getLogger(__name__) class FMUYamlSafeLoader(yaml.SafeLoader): diff --git a/src/grid3d_maps/avghc/_mapsettings.py b/src/grid3d_maps/avghc/_mapsettings.py index f29d343..50db18e 100644 --- a/src/grid3d_maps/avghc/_mapsettings.py +++ b/src/grid3d_maps/avghc/_mapsettings.py @@ -1,11 +1,9 @@ import copy +import logging import xtgeo -from xtgeo.common import null_logger -xtg = xtgeo.common.XTGeoDialog() - -logger = null_logger(__name__) +logger = logging.getLogger(__name__) def check_mapsettings(config, grd): diff --git a/src/grid3d_maps/avghc/grid3d_average_map.py b/src/grid3d_maps/avghc/grid3d_average_map.py index 37b47cb..e83a770 100644 --- a/src/grid3d_maps/avghc/grid3d_average_map.py +++ b/src/grid3d_maps/avghc/grid3d_average_map.py @@ -5,10 +5,9 @@ are equally supported. """ +import logging import sys -from xtgeo.common import XTGeoDialog - from . import ( _compute_avg, _configparser, @@ -30,9 +29,8 @@ + "https://fmu-docs.equinor.com/docs/grid3d-maps/" ) -xtg = XTGeoDialog() - -logger = xtg.basiclogger(__name__) +logger = logging.getLogger(__name__) +logger.setLevel(logging.INFO) def do_parse_args(args): @@ -68,17 +66,17 @@ def get_grid_props_data(config): config, APPNAME ) - xtg.say(f"Grid file is {gfile}") + logger.info("Grid file is {}".format(gfile)) - xtg.say("Getting INIT file data") + logger.info("Getting INIT file data") for initpar, initfile in initlist.items(): logger.info("%s file is %s", initpar, initfile) - xtg.say("Getting RESTART file data") + logger.info("Getting RESTART file data") for restpar, restfile in restartlist.items(): logger.info("%s file is %s", restpar, restfile) - xtg.say("Getting dates") + logger.info("Getting dates") for date in dates: logger.info("Date is %s", date) @@ -134,10 +132,10 @@ def compute_avg_and_plot( if config["mapsettings"] is None: config = _mapsettings.estimate_mapsettings(config, grd) else: - xtg.say("Check map settings vs grid...") + logger.info("Check map settings vs grid...") status = _mapsettings.check_mapsettings(config, grd) if status >= 10: - xtg.critical("STOP! Mapsettings defined is outside the 3D grid!") + logger.critical("STOP! Mapsettings defined is outside the 3D grid!") # This is done a bit different here than in the HC thickness. Here the # mapping and plotting is done within _compute_avg.py @@ -152,28 +150,27 @@ def compute_avg_and_plot( def main(args=None): """Main routine.""" - XTGeoDialog.print_xtgeo_header(APPNAME, __version__) - - xtg.say("Parse command line") + logger.info(f"Starting {APPNAME} (version {__version__})") + logger.info("Parse command line") args = do_parse_args(args) config = None if not args.config: - xtg.error("Config file is missing") + logger.error("Config file is missing") sys.exit(1) logger.debug("--config option is applied, reading YAML ...") # get the configurations - xtg.say("Parse YAML file") + logger.info("Parse YAML file") config = yamlconfig(args.config, args) # get the files - xtg.say("Collect files...") + logger.info("Collect files...") gfile, initlist, restartlist, dates = get_grid_props_data(config) # import data from files and return relevant numpies - xtg.say("Import files...") + logger.info("Import files...") grd, specd, propd, dates = import_pdata(config, gfile, initlist, restartlist, dates) @@ -181,16 +178,16 @@ def main(args=None): filterarray = import_filters(config, grd) logger.info("Filter mean value: %s", filterarray.mean()) if filterarray.mean() < 1.0: - xtg.say("Property filters are active") + logger.info("Property filters are active") for prop, val in propd.items(): logger.info("Key is %s, avg value is %s", prop, val.mean()) # Get the zonations - xtg.say("Get zonation info") + logger.info("Get zonation info") zonation, zoned = get_zranges(config, grd) - xtg.say("Compute average properties") + logger.info("Compute average properties") compute_avg_and_plot(config, grd, specd, propd, dates, zonation, zoned, filterarray) diff --git a/src/grid3d_maps/avghc/grid3d_hc_thickness.py b/src/grid3d_maps/avghc/grid3d_hc_thickness.py index d4677c1..68f8c00 100644 --- a/src/grid3d_maps/avghc/grid3d_hc_thickness.py +++ b/src/grid3d_maps/avghc/grid3d_hc_thickness.py @@ -5,10 +5,9 @@ """ +import logging import sys -from xtgeo.common import XTGeoDialog - from . import ( _compute_hcpfz, _configparser, @@ -31,9 +30,9 @@ + "https://fmu-docs.equinor.com/docs/grid3d-maps/" ) -xtg = XTGeoDialog() -logger = xtg.basiclogger(__name__) +logger = logging.getLogger(__name__) +logger.setLevel(logging.INFO) def do_parse_args(args): @@ -68,20 +67,20 @@ def get_grid_props_data(config): config, APPNAME ) - xtg.say("Grid file is {}".format(gfile)) + logger.info("Grid file is {}".format(gfile)) if initlist: - xtg.say("Getting INITIAL file data (as INIT or ROFF)") + logger.info("Getting INITIAL file data (as INIT or ROFF)") for initpar, initfile in initlist.items(): logger.info("%s file is %s", initpar, initfile) if restartlist: - xtg.say("Getting RESTART file data") + logger.info("Getting RESTART file data") for restpar, restfile in restartlist.items(): logger.info("%s file is %s", restpar, restfile) - xtg.say("Getting dates") + logger.info("Getting dates") for date in dates: logger.info("Date is %s", date) @@ -145,10 +144,10 @@ def plotmap(config, grd, initd, hcpfzd, zonation, zoned, hcmode, filtermean=None if config["mapsettings"] is None: config = _mapsettings.estimate_mapsettings(config, grd) else: - xtg.say("Check map settings vs grid...") + logger.info("Check map settings vs grid...") status = _mapsettings.check_mapsettings(config, grd) if status >= 10: - xtg.critical("STOP! Mapsettings defined is outside the 3D grid!") + logger.critical("STOP! Mapsettings defined is outside the 3D grid!") mapzd = _hc_plotmap.do_hc_mapping(config, initd, hcpfzd, zonation, zoned, hcmode) @@ -157,28 +156,27 @@ def plotmap(config, grd, initd, hcpfzd, zonation, zoned, hcmode, filtermean=None def main(args=None): - XTGeoDialog.print_xtgeo_header(APPNAME, __version__) - - xtg.say("Parse command line") + logger.info(f"Starting {APPNAME} (version {__version__})") + logger.info("Parse command line") args = do_parse_args(args) config = None if not args.config: - xtg.error("Config file is missing") + logger.error("Config file is missing") sys.exit(1) logger.debug("--config option is applied, reading YAML ...") # get the configurations - xtg.say("Parse YAML file") + logger.info("Parse YAML file") config = yamlconfig(args.config, args) # get the files - xtg.say("Collect files...") + logger.info("Collect files...") gfile, initlist, restartlist, dates = get_grid_props_data(config) # import data from files and return relevant numpies - xtg.say("Import files...") + logger.info("Import files...") grd, initd, restartd, dates = import_pdata( config, gfile, initlist, restartlist, dates ) @@ -187,10 +185,10 @@ def main(args=None): filterarray = import_filters(config, grd) logger.info("Filter mean value: %s", filterarray.mean()) if filterarray.mean() < 1.0: - xtg.say("Property filters are active") + logger.info("Property filters are active") # Get the zonations - xtg.say("Get zonation info") + logger.info("Get zonation info") zonation, zoned = get_zranges(config, grd) @@ -200,10 +198,10 @@ def main(args=None): hcmodelist = [config["computesettings"]["mode"]] for hcmode in hcmodelist: - xtg.say("Compute HCPFZ property for {}".format(hcmode)) + logger.info("Compute HCPFZ property for {}".format(hcmode)) hcpfzd = compute_hcpfz(config, initd, restartd, dates, hcmode, filterarray) - xtg.say("Do mapping...") + logger.info("Do mapping...") plotmap( config, grd, diff --git a/src/grid3d_maps/contact/_compute_contact.py b/src/grid3d_maps/contact/_compute_contact.py index 00780b1..b61e97d 100644 --- a/src/grid3d_maps/contact/_compute_contact.py +++ b/src/grid3d_maps/contact/_compute_contact.py @@ -1,10 +1,10 @@ +import logging + import numpy as np import xtgeo -from xtgeo.common import XTGeoDialog, null_logger from xtgeo.surface import RegularSurface -xtg = XTGeoDialog() -logger = null_logger(__name__) +logger = logging.getLogger(__name__) def gridmap_contact(config, specd, propd, dates): @@ -26,4 +26,4 @@ def gridmap_contact(config, specd, propd, dates): yinc=config["mapsettings"].get("yinc"), values=np.zeros((ncol, nrow)), ) - print(propd) + logger.info(propd) diff --git a/src/grid3d_maps/contact/_get_grid_props.py b/src/grid3d_maps/contact/_get_grid_props.py index 6078ba4..65b75c1 100644 --- a/src/grid3d_maps/contact/_get_grid_props.py +++ b/src/grid3d_maps/contact/_get_grid_props.py @@ -1,17 +1,13 @@ +import logging import pprint from collections import defaultdict import numpy as np import numpy.ma as ma import xtgeo - -# from xtgeo.common.exceptions import KeywordNotFoundError -from xtgeo.common import XTGeoDialog, null_logger from xtgeo.common.exceptions import DateNotFoundError, KeywordFoundNoDateError -xtg = XTGeoDialog() - -logger = null_logger(__name__) +logger = logging.getLogger(__name__) def files_to_import(config, appname): @@ -41,7 +37,7 @@ def files_to_import(config, appname): restartlist["SGAS"] = eclroot + ".UNRST" for date in config["input"]["dates"]: - logger.debug("DATE {}".format(date)) + logger.debug(f"DATE {date}") if len(date) == 8: dates.append(date) elif len(date) > 12: @@ -129,7 +125,7 @@ def import_data(appname, gfile, initlist, restartlist, dates): lookfornames.append(lookforname) usenames.append(usename) - xtg.say("Import <{}> from <{}> ...".format(lookfornames, inifile)) + logger.info(f"Import <{lookfornames}> from <{inifile}> ...") tmp = xtgeo.gridproperties_from_file( inifile, names=lookfornames, fformat="init", grid=grd ) @@ -142,7 +138,7 @@ def import_data(appname, gfile, initlist, restartlist, dates): # single properties, typically ROFF stuff usename, lookforname = iniprops[0] - xtg.say("Import <{}> from <{}> ...".format(lookforname, inifile)) + logger.info(f"Import <{lookforname}> from <{inifile}> ...") tmp = xtgeo.gridproperty_from_file( inifile, name=lookforname, fformat="guess", grid=grd ) @@ -260,7 +256,7 @@ def get_numpies_contact(config, grd, initobjects, restobjects, dates): initd.update({"porv": porv, "poro": poro, "ntg": ntg, "dx": dx, "dy": dy, "dz": dz}) - xtg.say("Got relevant INIT numpies, OK ...") + logger.info("Got relevant INIT numpies, OK ...") # restart data, they have alos a date component: diff --git a/src/grid3d_maps/contact/grid3d_contact_map.py b/src/grid3d_maps/contact/grid3d_contact_map.py index 07bb660..13ef5f3 100644 --- a/src/grid3d_maps/contact/grid3d_contact_map.py +++ b/src/grid3d_maps/contact/grid3d_contact_map.py @@ -1,9 +1,8 @@ """Script to estimate contact maps directly from 3D grids.""" +import logging import sys -from xtgeo.common import XTGeoDialog - from grid3d_maps.avghc import _configparser, _get_zonation_filters from grid3d_maps.contact import _compute_contact, _get_grid_props @@ -20,9 +19,8 @@ + "https://fmu-docs.equinor.com/docs/grid3d-maps/" ) -xtg = XTGeoDialog() -logger = xtg.basiclogger(__name__) +logger = logging.getLogger(__name__) def do_parse_args(args): @@ -56,20 +54,20 @@ def get_grid_props_data(config, appname): config, appname ) - xtg.say("Grid file is {}".format(gfile)) + logger.info("Grid file is {}".format(gfile)) if len(initlist) > 0: - xtg.say("Getting INITIAL file data (as INIT or ROFF)") + logger.info("Getting INITIAL file data (as INIT or ROFF)") for initpar, initfile in initlist.items(): logger.info("{} file is {}".format(initpar, initfile)) if len(restartlist) > 0: - xtg.say("Getting RESTART file data") + logger.info("Getting RESTART file data") for restpar, restfile in restartlist.items(): logger.info("{} file is {}".format(restpar, restfile)) - xtg.say("Getting dates") + logger.info("Getting dates") for date in dates: logger.info("Date is {}".format(date)) @@ -119,28 +117,27 @@ def compute_contact(config, initd, restartd, dates): def main(args=None): - XTGeoDialog.print_xtgeo_header(APPNAME, __version__) - - xtg.say("Parse command line") + logger.info(f"Starting {APPNAME} (version {__version__})") + logger.info("Parse command line") args = do_parse_args(args) config = None if not args.config: - xtg.error("Config file is missing") + logger.error("Config file is missing") sys.exit(1) logger.debug("--config option is applied, reading YAML ...") # get the configurations - xtg.say("Parse YAML file") + logger.info("Parse YAML file") config = yamlconfig(args.config, args) # get the files - xtg.say("Collect files...") + logger.info("Collect files...") gfile, initlist, restartlist, dates = get_grid_props_data(config, APPNAME) # import data from files and return releavnt numpies - xtg.say("Import files...") + logger.info("Import files...") grd, initd, restartd, dates = import_pdata( config, APPNAME, gfile, initlist, restartlist, dates ) @@ -148,7 +145,7 @@ def main(args=None): # Get the zonations # zonation, zoned = get_zranges(config, grd) - xtg.say("Grid contact map...") + logger.info("Grid contact map...") compute_contact(config, initd, restartd, dates)