Skip to main content

A (lazy) parser and writer for the ecl output format.

Project description

ecl-data-io

Parser for the ecl output format, such as found in files with extensions .UNRST, .EGRID, .INIT, etc. and also the corresponding ascii files with extension .FUNRST, .FEGRID, .FINIT, etc.

The file format comes in two forms: formatted or unformatted, which are ascii and binary respectively (the terminology comes from fortran).

The files consists of named arrays, starting with a 8 character ascii keyword name, followed by a 4 byte signed integer which is the length of the array, then a 4 character keyword describing the data type of elements in the array. Each file consists of a sequence of such arrays.

ecl-data-io does not interpret the output, but simply give you the arrays:

import ecl_data_io as eclio

for kw, arr in eclio.read("my_grid.egrid"):
    print(kw)

>>> "FILEHEAD"
>>> "GRIDHEAD"
>>> "COORD"
>>> "ZCORN"
>>> "ACTNUM"
>>> "MAPAXES"

Similarly, the write function will generate such files:

import ecl_data_io as eclio

eclio.write("my_grid.egrid", {"FILEHEAD": [...], "GRIDHEAD": [10,10,10]})

The default format is is binary (unformatted), but it is possible to read and write ascii aswell:

import ecl_data_io as eclio

eclio.write(
    "my_grid.egrid",
    {"FILEHEAD": [...], "GRIDHEAD": [10,10,10]},
    fileformat=eclio.Format.FORMATTED
)

lazy reading

It is also possible to read through the file without loading all arrays into memory, ie. lazily:

import ecl_data_io as eclio

for item in eclio.lazy_read("my_grid.egrid"):
    print(item.read_keyword())

>>> "FILEHEAD"
>>> "GRIDHEAD"
>>> "COORD"
>>> "ZCORN"
>>> "ACTNUM"
>>> "MAPAXES"

Note that eclio.lazy_read in the above example is a generator of array entries and the file will be closed once the generator is finished. Therefore, care will have to be taken in when arrays/keywords are read from the entries. For better control, one can pass the opened file:

import ecl_data_io as eclio

with open("my_grid.egrid", "rb") as f:
    generator = eclio.lazy_read("my_grid.egrid")
    item = next(generator)
    print(item.read_keyword())

>>> "FILEHEAD"

Duplicate keywords

The simple write function works best for keywords with unique names, however, if the file has multiple arays with the same name, list of tuples can be used:

import ecl_data_io as eclio

contents = [
 ("COORD", [1.0, ...]),
 ("COORD", [2.0, ...]),
]

eclio.write("my/file.grdecl", contents)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ecl-data-io-1.0.0.tar.gz (19.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ecl_data_io-1.0.0-py3-none-any.whl (18.0 kB view details)

Uploaded Python 3

File details

Details for the file ecl-data-io-1.0.0.tar.gz.

File metadata

  • Download URL: ecl-data-io-1.0.0.tar.gz
  • Upload date:
  • Size: 19.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.12

File hashes

Hashes for ecl-data-io-1.0.0.tar.gz
Algorithm Hash digest
SHA256 0a723b5cd8a2a627ea00cf200ecdcdbb1fdc61bef5ea89529d4ff0c003f16254
MD5 dad71bdfce89c7978748f8b60a9719a4
BLAKE2b-256 8a2f31db6b139268b2ca25009e4dab1fb4a1108fb5bfc85a40e891be425df9ab

See more details on using hashes here.

File details

Details for the file ecl_data_io-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: ecl_data_io-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 18.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.12

File hashes

Hashes for ecl_data_io-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e3d1190f3fb8688d86ed8b95b3fd005828627d125a5f4218f9e925edb512505e
MD5 eb2fab02c574846fe9b2f687f8877a72
BLAKE2b-256 b1621fdceed5c14eccb75ce5aecabb40043d3f53f6fdcfc47236fefba9f14940

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page