OpenZGY/C++ API and Internals (ALPHA)
Access seismic data stored in ZGY format.
Public Member Functions | Static Public Member Functions | List of all members
OpenZGY::IZgyWriter Class Referenceabstract

Main API for creating ZGY files. More...

#include <api.h>

Inheritance diagram for OpenZGY::IZgyWriter:
OpenZGY::IZgyTools OpenZGY::IZgyMeta OpenZGY::Impl::ZgyWriter

Public Member Functions

virtual void write (const size3i_t &start, const size3i_t &size, const float *data) const =0
 Write an arbitrary region. More...
 
virtual void write (const size3i_t &start, const size3i_t &size, const std::int16_t *data) const =0
 Write an arbitrary region with no conversion. More...
 
virtual void write (const size3i_t &start, const size3i_t &size, const std::int8_t *data) const =0
 Write an arbitrary region with no conversion. More...
 
virtual void writeconst (const size3i_t &start, const size3i_t &size, const float *data) const =0
 Write all-constant data. More...
 
virtual void writeconst (const size3i_t &start, const size3i_t &size, const std::int16_t *data) const =0
 Write an arbitrary region with no conversion. More...
 
virtual void writeconst (const size3i_t &start, const size3i_t &size, const std::int8_t *data) const =0
 Write an arbitrary region with no conversion. More...
 
virtual void finalize (const std::vector< DecimationType > &decimation=std::vector< DecimationType >(), const std::function< bool(std::int64_t, std::int64_t)> &progress=nullptr, bool force=false)=0
 Generate low resolution data, statistics, and histogram. More...
 
virtual void close_incomplete ()=0
 Flush the file to disk and close it. More...
 
virtual void close ()=0
 Flush the file to disk and close it. More...
 
virtual bool errorflag () const =0
 
virtual void set_errorflag (bool)=0
 
- Public Member Functions inherited from OpenZGY::IZgyTools
virtual void transform (const corners_t &from, const corners_t &to, std::vector< std::array< float64_t, 2 >> &) const =0
 General coordinate conversion of an array of points. (NOT IMPLEMENTED YET) More...
 
virtual std::array< float64_t, 2 > transform1 (const corners_t &from, const corners_t &to, const std::array< float64_t, 2 > &) const =0
 General coordinate conversion of a single coordinate pair. More...
 
virtual std::array< float64_t, 2 > annotToIndex (const std::array< float64_t, 2 > &) const =0
 Convert a single coordinate pair.
 
virtual std::array< float64_t, 2 > annotToWorld (const std::array< float64_t, 2 > &) const =0
 Convert a single coordinate pair.
 
virtual std::array< float64_t, 2 > indexToAnnot (const std::array< float64_t, 2 > &) const =0
 Convert a single coordinate pair.
 
virtual std::array< float64_t, 2 > indexToWorld (const std::array< float64_t, 2 > &) const =0
 Convert a single coordinate pair.
 
virtual std::array< float64_t, 2 > worldToAnnot (const std::array< float64_t, 2 > &) const =0
 Convert a single coordinate pair.
 
virtual std::array< float64_t, 2 > worldToIndex (const std::array< float64_t, 2 > &) const =0
 Convert a single coordinate pair.
 
- Public Member Functions inherited from OpenZGY::IZgyMeta
virtual size3i_t size () const =0
 Size in inline, crossline, vertical directions.
 
virtual SampleDataType datatype () const =0
 Type of samples in each brick.
 
virtual std::array< float32_t, 2 > datarange () const =0
 Used for float to int scaling.
 
virtual UnitDimension zunitdim () const =0
 Vertical dimension.
 
virtual UnitDimension hunitdim () const =0
 Horizontal dimension.
 
virtual std::string zunitname () const =0
 For annotation only. Use hunitfactor, not the name, to convert to or from SI.
 
virtual std::string hunitname () const =0
 For annotation only. Use hunitfactor, not the name, to convert to or from SI.
 
virtual float64_t zunitfactor () const =0
 Multiply by this factor to convert from storage units to SI units.
 
virtual float64_t hunitfactor () const =0
 Multiply by this factor to convert from storage units to SI units.
 
virtual float32_t zstart () const =0
 First time/depth.
 
virtual float32_t zinc () const =0
 Increment in vertical direction.
 
virtual std::array< float32_t, 2 > annotstart () const =0
 First inline, crossline.
 
virtual std::array< float32_t, 2 > annotinc () const =0
 Increment in inline, crossline directions.
 
virtual const corners_t & corners () const =0
 Survey corner points in world coordinates.
 
virtual const corners_t & indexcorners () const =0
 Survey corner points in ordinal (i,j) coordinates.
 
virtual const corners_t & annotcorners () const =0
 Survey corner points in inline, crossline coordinates.
 
virtual size3i_t bricksize () const =0
 Size of one brick. Almost always (64,64,64), change at your own peril.
 
virtual std::vector< size3i_t > brickcount () const =0
 Number of bricks at each resolution (LOD) level.
 
virtual int32_t nlods () const =0
 Number of resolution (LOD) levels.
 
virtual void meta () const =0
 Dictionary of meta data. NOT IMPLEMENTED.
 
virtual int32_t numthreads () const =0
 Number of threads to use. NOT IMPLEMENTED.
 
virtual void set_numthreads (int32_t)=0
 Number of threads to use. NOT IMPLEMENTED.
 
virtual void dump (std::ostream &) const =0
 Output in human readable form for debugging.
 
virtual SampleStatistics statistics () const =0
 Statistics of all sample values on the file.
 
virtual SampleHistogram histogram () const =0
 Histogram of all sample values on the file.
 

Static Public Member Functions

static std::shared_ptr< IZgyWriteropen (const ZgyWriterArgs &args)
 Create a ZGY file and open it for writing.
 

Additional Inherited Members

- Public Types inherited from OpenZGY::IZgyMeta
typedef std::int8_t int8_t
 
typedef std::int16_t int16_t
 
typedef std::int32_t int32_t
 
typedef std::int64_t int64_t
 
typedef float float32_t
 
typedef double float64_t
 
typedef std::array< int64_t, 3 > size3i_t
 
typedef std::array< std::array< float64_t, 2 >, 4 > corners_t
 
typedef std::pair< std::shared_ptr< const void >, std::int64_t > rawdata_t
 
typedef std::function< rawdata_t(const rawdata_t &, const std::array< int64_t, 3 > &)> compressor_t
 

Detailed Description

Main API for creating ZGY files.

Obtain a concrete instance by calling the factory method IZgyWriter::open(). All meta data is specified in the call to open(), so meta data will appear to be read only. You can use the instance to write bulk data. The file becomes read only once the instance is closed.

It is recommended to call finalize() after all bulk has been written. but if you forget this will be called from close() with default arguments. It is required to explicitly close() the file when done with it, Technically the destructor will call close() but being a destructor it needs to swallow any exceptions.

Note: Yes, I understand that the open() factory method should not have been lexically scoped inside the ostensibly pure IZgyWriter interface. But this reduces the number of classes a library user needs to relate to.

Member Function Documentation

◆ close()

virtual void OpenZGY::IZgyWriter::close ( )
pure virtual

Flush the file to disk and close it.

If the file has been written to, the application is encouraged to call finalize() before close(). This gives more control over the process and allows using a progress callback to track generation of low resolution data.

The function won't bother with statistics, histogram, lowres if there has been an unrecoverable error. The headers might still be written out in case somebody wants to try some forensics.

The ZgyWriter destructor will call close() if not done already, but that will catch and swallow any exception. Relying on the destructor to close the file is strongly discouraged.

Implemented in OpenZGY::Impl::ZgyWriter.

◆ close_incomplete()

virtual void OpenZGY::IZgyWriter::close_incomplete ( )
pure virtual

Flush the file to disk and close it.

This version of close() will not calculate statistics and low resolution bricks. Currently this makes the file useless in most cases. The function may be useful for performance measurements.

In the future it might be possible to re-open the file at some later date and continue writing data to it. Calling the regular close() only when all data has been output.

Implemented in OpenZGY::Impl::ZgyWriter.

◆ finalize()

virtual void OpenZGY::IZgyWriter::finalize ( const std::vector< DecimationType > &  decimation = std::vector< DecimationType >(),
const std::function< bool(std::int64_t, std::int64_t)> &  progress = nullptr,
bool  force = false 
)
pure virtual

Generate low resolution data, statistics, and histogram.

This method will be called automatically from close(), but in that case it is not possible to request a progress callback.

If the processing raises an exception the data is still marked as clean. Called can force a retry by passing force=True.

The C++ code is very different from Python because it needs an entirely different approach to be performant.

Parameters
decimationOptionally override the decimation algorithms by passing an array of DecimationType with one entry for each level of detail. If the array is too short then the last entry is used for subsequent levels.
progressFunction(done, total) called to report progress. If it returns False the computation is aborted. Will be called at least one, even if there is no work.
forceIf true, generate the low resolution data even if it appears to not be needed. Use with caution. Especially if writing to the cloud, where data should only be written once.

Implemented in OpenZGY::Impl::ZgyWriter.

◆ write() [1/3]

virtual void OpenZGY::IZgyWriter::write ( const size3i_t &  start,
const size3i_t &  size,
const float *  data 
) const
pure virtual

Write an arbitrary region.

This will apply conversion float -> storage if needed.

A read/modify/write will be done if the region's start and size doesn't align with bricksize. When writing to the cloud this read/modify/write may incur performance and size penalties. So do write brick aligned data if possible. The same applies to writing compressed data where r/m/w can cause a severe loss of quality.

The start position refers to the specified lod level. At lod 0 start + data.size can be up to the survey size. At lod 1 the maximum is just half that, rounded up.

Implemented in OpenZGY::Impl::ZgyWriter.

◆ write() [2/3]

virtual void OpenZGY::IZgyWriter::write ( const size3i_t &  start,
const size3i_t &  size,
const std::int16_t *  data 
) const
pure virtual

Write an arbitrary region with no conversion.

As the write overload with a float buffer but only works for files with SampleDataType::int16 and does not scale the samples.

Implemented in OpenZGY::Impl::ZgyWriter.

◆ write() [3/3]

virtual void OpenZGY::IZgyWriter::write ( const size3i_t &  start,
const size3i_t &  size,
const std::int8_t *  data 
) const
pure virtual

Write an arbitrary region with no conversion.

As the write overload with a float buffer but only works for files with SampleDataType::int8 and does not scale the samples.

Implemented in OpenZGY::Impl::ZgyWriter.

◆ writeconst() [1/3]

virtual void OpenZGY::IZgyWriter::writeconst ( const size3i_t &  start,
const size3i_t &  size,
const float *  data 
) const
pure virtual

Write all-constant data.

Works as the corresponding write but the entire region is set to the same value. So the provided data buffer needs just one value, or alternatively can be passed as &scalar_value.

Calling this method is faster than filling a buffer with constant values and calling write. But it produces the exact same result. This is because write will automatically detect whether the input buffer is all constant.

Implemented in OpenZGY::Impl::ZgyWriter.

◆ writeconst() [2/3]

virtual void OpenZGY::IZgyWriter::writeconst ( const size3i_t &  start,
const size3i_t &  size,
const std::int16_t *  data 
) const
pure virtual

Write an arbitrary region with no conversion.

As the writeconst overload with a float buffer but only works for files with SampleDataType::int16 and does not scale the samples.

Implemented in OpenZGY::Impl::ZgyWriter.

◆ writeconst() [3/3]

virtual void OpenZGY::IZgyWriter::writeconst ( const size3i_t &  start,
const size3i_t &  size,
const std::int8_t *  data 
) const
pure virtual

Write an arbitrary region with no conversion.

As the write overload with a float buffer but only works for files with SampleDataType::int8 and does not scale the samples.

Implemented in OpenZGY::Impl::ZgyWriter.


The documentation for this class was generated from the following files: