Exemplo n.º 1
0
    def to_file(self, sfile, fformat="segy", pristine=False, engine="xtgeo"):
        """Export cube data to file.

        Args:
            sfile (str): Filename
            fformat (str, optional): file format 'segy' (default) or
                'rms_regular'
            pristine (bool): If True, make SEGY from scratch.
            engine (str): Which "engine" to use.

        Example::
            >>> zz = Cube('some.segy')
            >>> zz.to_file('some.rmsreg')
        """
        fobj = xtgeosys._XTGeoFile(sfile, mode="wb")

        fobj.check_folder(raiseerror=OSError)

        if fformat == "segy":
            _cube_export.export_segy(self, fobj.name, pristine=pristine, engine=engine)
        elif fformat == "rms_regular":
            _cube_export.export_rmsreg(self, fobj.name)
        elif fformat == "xtgregcube":
            _cube_export.export_xtgregcube(self, fobj.name)
        else:
            raise ValueError(f"File format fformat={fformat} is not supported")
Exemplo n.º 2
0
    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
Exemplo n.º 3
0
    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