def from_file(self, pfile, fformat="guess"): """Import Points or Polygons from a file. Supported import formats (fformat): * 'xyz' or 'poi' or 'pol': Simple XYZ format * 'zmap': ZMAP line format as exported from RMS (e.g. fault lines) * 'rms_attr': RMS points formats with attributes (extra columns) * 'guess': Try to choose file format based on extension Args: pfile (str): Name of file fformat (str): File format, see list above Returns: Object instance (needed optionally) Raises: OSError: if file is not present or wrong permissions. """ logger.info("Reading from file %s...", pfile) if os.path.isfile(pfile): pass else: logger.critical("Not OK file") raise os.error froot, fext = os.path.splitext(pfile) if fformat == "guess": if not fext: logger.critical("File extension missing. STOP") raise SystemExit fformat = fext.lower().replace(".", "") if fformat in ["xyz", "poi", "pol"]: _xyz_io.import_xyz(self, pfile) elif fformat == "zmap": _xyz_io.import_zmap(self, pfile) elif fformat in ("rms_attr", "rmsattr"): _xyz_io.import_rms_attr(self, pfile) else: logger.error("Invalid file format (not supported): %s", fformat) raise SystemExit logger.info("Reading from file %s... done", pfile) logger.debug("Dataframe head:\n%s", self._df.head()) self._filesrc = pfile return self
def from_file(self, pfile, fformat="xyz"): """Import Points or Polygons from a file. Supported import formats (fformat): * 'xyz' or 'poi' or 'pol': Simple XYZ format * 'zmap': ZMAP line format as exported from RMS (e.g. fault lines) * 'rms_attr': RMS points formats with attributes (extra columns) * 'guess': Try to choose file format based on extension Args: pfile (str): Name of file or pathlib.Path instance fformat (str): File format, see list above Returns: Object instance (needed optionally) Raises: OSError: if file is not present or wrong permissions. """ pfile = xtgeo._XTGeoFile(pfile) logger.info("Reading from file %s...", pfile.name) pfile.check_file(raiseerror=OSError) froot, fext = pfile.splitext(lower=True) if fformat == "guess": if not fext: raise ValueError(f"File extension missing for file: {pfile}") fformat = fext if fformat in ["xyz", "poi", "pol"]: _xyz_io.import_xyz(self, pfile.name) elif fformat == "zmap": _xyz_io.import_zmap(self, pfile.name) elif fformat in ("rms_attr", "rmsattr"): _xyz_io.import_rms_attr(self, pfile.name) else: logger.error("Invalid file format (not supported): %s", fformat) raise ValueError("Invalid file format (not supported): %s", fformat) logger.info("Reading from file %s... done", pfile.name) logger.debug("Dataframe head:\n%s", self._df.head()) self._filesrc = pfile.name return self