def from_file(self, sfile, fformat="guess", engine="segyio"): """Import cube data from file. If fformat is not provided, the file type will be guessed based on file extension (e.g. segy og sgy for SEGY format) Args: sfile (str): Filename (as string or pathlib.Path instance). fformat (str): file format guess/segy/rms_regular/xtgregcube where 'guess' is default. Regard 'xtgrecube' format as experimental. engine (str): For the SEGY reader, 'xtgeo' is builtin while 'segyio' uses the SEGYIO library (default). deadtraces (float): Set 'dead' trace values to this value (SEGY only). Default is UNDEF value (a very large number). Raises: OSError: if the file cannot be read (e.g. not found) ValueError: Input is invalid Example:: >>> zz = Cube() >>> zz.from_file('some.segy') """ fobj = xtgeosys._XTGeoFile(sfile) fobj.check_file(raiseerror=OSError) _, fext = fobj.splitext(lower=True) if fformat == "guess": if not fext: raise ValueError( "File extension for Cube missing while fformat==guess") fformat = fext.lower() if "rms" in fformat: _cube_import.import_rmsregular(self, fobj.name) elif fformat in ("segy", "sgy"): _cube_import.import_segy(self, fobj.name, engine=engine) elif fformat == "storm": _cube_import.import_stormcube(self, fobj.name) elif fformat == "xtgregcube": # experimental format _cube_import.import_xtgregcube(self, fobj) else: raise ValueError(f"File format fformat={fformat} is not supported") self._filesrc = fobj.name self._metadata.required = self
def from_file(self, sfile, fformat="guess", engine="segyio"): """Import cube data from file. If fformat is not provided, the file type will be guessed based on file extension (e.g. segy og sgy for SEGY format) Args: sfile (str): Filename fformat (str): file format guess/segy/rms_regular where 'guess' is default engine (str): For the SEGY reader, 'xtgeo' is builtin while 'segyio' uses the SEGYIO library (default) deadtraces (float): Set 'dead' trace values to this value (SEGY only). Default is UNDEF value (a very large number) Raises: IOError if the file cannot be read (e.g. not found) Example:: >>> zz = Cube() >>> zz.from_file('some.segy') """ if os.path.isfile(sfile): pass else: logger.critical("Not OK file") raise IOError("Input file for Cube cannot be read") # work on file extension _froot, fext = os.path.splitext(sfile) if fformat == "guess": if not fext: logger.critical("File extension missing. STOP") sys.exit(9) else: fformat = fext.lower().replace(".", "") if "rms" in fformat.lower(): _cube_import.import_rmsregular(self, sfile) elif fformat.lower() == "segy" or fformat.lower() == "sgy": _cube_import.import_segy(self, sfile, engine=engine) elif fformat == "storm": _cube_import.import_stormcube(self, sfile) else: logger.error("Invalid or unknown file format") self._filesrc = sfile
def from_file(self, sfile, fformat="guess", engine="segyio"): """Import cube data from file. If fformat is not provided, the file type will be guessed based on file extension (e.g. segy og sgy for SEGY format) Args: sfile (str): Filename (as string or pathlib.Path) fformat (str): file format guess/segy/rms_regular where 'guess' is default engine (str): For the SEGY reader, 'xtgeo' is builtin while 'segyio' uses the SEGYIO library (default) deadtraces (float): Set 'dead' trace values to this value (SEGY only). Default is UNDEF value (a very large number) Raises: OSError if the file cannot be read (e.g. not found) Example:: >>> zz = Cube() >>> zz.from_file('some.segy') """ fobj = xtgeosys._XTGeoFile(sfile) fobj.check_file(raiseerror=OSError) _froot, fext = fobj.splitext(lower=True) if fformat == "guess": if not fext: logger.critical("File extension missing. STOP") sys.exit(9) else: fformat = fext.lower() if "rms" in fformat: _cube_import.import_rmsregular(self, fobj.name) elif fformat in ("segy", "sgy"): _cube_import.import_segy(self, fobj.name, engine=engine) elif fformat == "storm": _cube_import.import_stormcube(self, fobj.name) else: logger.error("Invalid or unknown file format") self._filesrc = fobj.name