equinor / xtgeo

XTGeo Python class library for subsurface Surfaces, Cubes, Wells, Grids, Points, etc
https://xtgeo.readthedocs.io/en/latest/
GNU Lesser General Public License v3.0
109 stars 56 forks source link

Have `FileWrapper` accept a `format` keyword argument #1135

Open mferrera opened 6 months ago

mferrera commented 6 months ago

The FileWrapper class has had a few methods to detect file formats but this should likely be something that is generalized on initialization.

For the moment (with a pending PR) to get the file format one must manually collect it, but it can also be proposed:

gfile = FileWrapper(egridfile)
fformat = gfile.fileformat("egrid")

An improvement to this pattern would making the file format known at instantiation, either explicitly or inferred.

gfile = FileWrapper(egridfile)  # infers fileformat from suffix and/or contents

# declares the file format -- should it be checked against the suffix and/or contents?
gfile = FileWrapper(egridfile, format="egrid")

This is fairly easy to implement when reading files but some consideration is needed when creating a FileWrapper instance to write a file.

(The keyword might also be fformat)