Geophysical Inversion and Modelling Library  v1.4.3
GIMLI::DataContainer Class Reference

DataContainer to store, load and save data in the GIMLi unified data format. More...

+ Inheritance diagram for GIMLI::DataContainer:
+ Collaboration diagram for GIMLI::DataContainer:

Public Member Functions

 DataContainer ()
 
 DataContainer (const std::string &fileName, bool sensorIndicesFromOne=true, bool removeInvalid=true)
 
 DataContainer (const std::string &fileName, const std::string &sensorTokens, bool sensorIndicesFromOne=true, bool removeInvalid=true)
 
 DataContainer (const DataContainer &data)
 
virtual ~DataContainer ()
 
DataContaineroperator= (const DataContainer &data)
 
const RVectoroperator() (const std::string &token) const
 
RVectoroperator() (const std::string &token)
 
const RVectoroperator[] (const std::string &token) const
 
RVectoroperator[] (const std::string &token)
 
void initDefaults ()
 
virtual void init ()
 
virtual void initTokenTranslator ()
 
bool haveTranslationForAlias (const std::string &alias) const
 
std::string translateAlias (const std::string &alias) const
 
virtual void clear ()
 
Index size () const
 
const std::map< std::string, RVector > & dataMap () const
 
const std::map< std::string, std::string > & dataDescription () const
 
void add (const DataContainer &data, double snap=1e-3)
 
void setSensorPositions (const RVector &sensors)
 
void setSensorPositions (const PosVector &sensors)
 
const PosVectorsensorPositions () const
 
void setSensorPosition (Index i, const RVector3 &pos)
 
const RVector3sensorPosition (double i) const
 
const R3Vectorsensors () const
 
const RVector3sensor (Index i) const
 
void setSensor (Index i, const RVector3 &pos)
 
SIndex createSensor (const RVector3 &pos, double tolerance=1e-3)
 
Index sensorCount () const
 
void registerSensorIndex (const std::string &token)
 
bool isSensorIndex (const std::string &token) const
 
const std::set< std::string > sensorIdx () const
 
void setSensorIndexOnFileFromOne (bool indexFromOne)
 
bool sensorIndexOnFileFromOne () const
 
IndexArray findSensorIndex (const RVector &d) const
 
void markInvalidSensorIndices ()
 
void removeSensorIdx (Index idx)
 
void removeSensorIdx (const IndexArray &idx)
 
const std::string & formatStringSensors () const
 
void sortSensorsX (bool incX=true, bool incY=true, bool incZ=true)
 
void translate (const RVector3 &trans)
 
void scale (const RVector3 &scale)
 
IndexArray dataIndex ()
 
IndexArray sortSensorsIndex ()
 
void setAdditionalPoints (const PosVector &a)
 
const PosVectoradditionalPoints () const
 
void setAdditionalPoint (Index i, const Pos &p)
 
void addAdditionalPoint (const Pos &p)
 
bool allNonZero (const std::string &token) const
 
bool haveData (const std::string &token) const
 
bool exists (const std::string &token) const
 
const std::map< std::string, std::string > & tokenTranslator () const
 
virtual int load (const std::string &fileName, bool sensorIndicesFromOne=true, bool removeInvalid=true)
 
virtual int save (const std::string &fileName, const std::string &fmtData, const std::string &fmtSensor, bool noFilter=false, bool verbose=false) const
 
int save (const std::string &fileName, const std::string &formatData="all", bool noFilter=false, bool verbose=false) const
 
virtual int write (std::fstream &os, const std::string &fmtData, const std::string &fmtSensor, bool noFilter=false, bool verbose=false) const
 
void showInfos () const
 
void resize (Index size)
 
std::string tokenList (bool withAnnotation=true) const
 
void add (const std::string &token, const RVector &data, const std::string &description="")
 
void add (const std::string &token)
 
void set (const std::string &token, const RVector &data)
 
const RVectorget (const std::string &token) const
 
const IndexArray id (const std::string &token) const
 
RVectorref (const std::string &token)
 
void setDataDescription (const std::string &token, const std::string &description)
 
std::string dataDescription (const std::string &token) const
 
virtual void remove (const IndexArray &idx)
 
void remove (const BVector &bvec)
 
void markValid (const BVector &bvec, bool valid=true)
 
void markValid (const IndexArray &idx, bool valid=true)
 
void markValid (Index idx, bool valid=true)
 
void markInvalid (const BVector &bvec)
 
void markInvalid (const IndexArray &idx)
 
void markInvalid (Index idx)
 
void checkDataValidity (bool remove=true)
 
virtual void checkDataValidityLocal ()
 
void removeInvalid ()
 
void removeUnusedSensors (bool verbose=false)
 
void setInputFormatString (const std::string &inputFormatString)
 
const std::string & inputFormatString () const
 
Index hash () const
 

Protected Member Functions

virtual void copy_ (const DataContainer &data)
 

Protected Attributes

std::string inputFormatStringSensors_
 
std::string inputFormatString_
 
std::map< std::string, RVectordataMap_
 Data map. More...
 
PosVector sensorPoints_
 Sensor positions. More...
 
std::set< std::string > dataSensorIdx_
 Data field that is sensor index. More...
 
std::map< std::string, std::string > dataDescription_
 Description for the data map entries. More...
 
PosVector topoPoints_
 
std::map< std::string, std::string > tT_
 
bool sensorIndexOnFileFromOne_
 

Detailed Description

DataContainer to store, load and save data in the GIMLi unified data format.

DataContainer to store, load and save data in the GIMLi unified data format. The DataContainer contains a data map that holds the data itself. Each map entry can be identified by tokens. By default there is a data field with the token 'valid' to mark the validity of the data. There is also a vector of unique sensor positions that holds sensor locations and a set of additional points, e.g., topographic positions. A vector of indices to the sensor positions can be defined for each datum. e.g., Store an index-vector 'a' to the first current electrode 'A' of a ERT measurement. If you need a special DataContainer you should derive a child and specify a token translator and sensor index entries. There is also a unit test for the DataContainer that may help to understand what is it good for.

Constructor & Destructor Documentation

◆ DataContainer() [1/4]

GIMLI::DataContainer::DataContainer ( )

Simple Constructor, builds an empty data container.

◆ DataContainer() [2/4]

GIMLI::DataContainer::DataContainer ( const std::string &  fileName,
bool  sensorIndicesFromOne = true,
bool  removeInvalid = true 
)

Constructor, builds a data container and fills the data from a file. See load.

Parameters
fileNameString of the file name

◆ DataContainer() [3/4]

GIMLI::DataContainer::DataContainer ( const std::string &  fileName,
const std::string &  sensorTokens,
bool  sensorIndicesFromOne = true,
bool  removeInvalid = true 
)

Constructor, builds a data container, registers sensor indices and fills the data from a file. See load.

Parameters
fileNameString of the file name

◆ DataContainer() [4/4]

GIMLI::DataContainer::DataContainer ( const DataContainer data)

Copy Constructor

◆ ~DataContainer()

GIMLI::DataContainer::~DataContainer ( )
virtual

Destructor.

Member Function Documentation

◆ add() [1/3]

void GIMLI::DataContainer::add ( const DataContainer data,
double  snap = 1e-3 
)

Add data to this DataContainer and snap new sensor positions by tolerance snap. Data fields from this data are preserved.

References id().

◆ add() [2/3]

void GIMLI::DataContainer::add ( const std::string &  token)
inline

Add new data field

◆ add() [3/3]

void GIMLI::DataContainer::add ( const std::string &  token,
const RVector data,
const std::string &  description = "" 
)

Add new data field with optional description. Throws an exception if the data field size is not the same size of the DataContainer.

Parameters
tokenString to identify the data
dataRVector of the data
descriptionString that describe the data

◆ addAdditionalPoint()

void GIMLI::DataContainer::addAdditionalPoint ( const Pos p)
inline

Push back additional point p.

◆ additionalPoints()

const PosVector& GIMLI::DataContainer::additionalPoints ( ) const
inline

Return the additional points.

Referenced by translateAlias().

◆ allNonZero()

bool GIMLI::DataContainer::allNonZero ( const std::string &  token) const
inline

Return true if token data exist and all elements != 0.0. Return false if the data contains one zero value.

◆ checkDataValidity()

void GIMLI::DataContainer::checkDataValidity ( bool  remove = true)

Mark data as invalid if they contain nan or inf. Call the virtual method checkData. If remove is set, invalid data will be removed.

◆ checkDataValidityLocal()

virtual void GIMLI::DataContainer::checkDataValidityLocal ( )
inlinevirtual
  • Virtual method with some data validity rules. Wrong data should be marked invalid here.

Reimplemented in GIMLI::DataContainerERT.

◆ clear()

void GIMLI::DataContainer::clear ( )
virtual

Clear the container, remove all sensor locations and data.

Referenced by translateAlias().

◆ createSensor()

SIndex GIMLI::DataContainer::createSensor ( const RVector3 pos,
double  tolerance = 1e-3 
)

Create a valid sensor at a given position and returns the id of the sensor. Is there already a sensor at the given position NO new sensor will be created. Atm. brute force search with a snapping distance of tolerance is done.

Parameters
posRVector3 of the sensor position
toleranceDouble of the snapping tolerance

References dataSensorIdx_, exists(), set(), and size().

◆ dataDescription() [1/2]

const std::map< std::string, std::string >& GIMLI::DataContainer::dataDescription ( ) const
inline

Return the complete data descriptions map

◆ dataDescription() [2/2]

std::string GIMLI::DataContainer::dataDescription ( const std::string &  token) const

Returns a copy of the description string for the specified data field. Return empty string if the data doesn't exist.

Parameters
tokenString that identify the data.

◆ dataIndex()

IndexArray GIMLI::DataContainer::dataIndex ( )

Return unique sortable data index, based on sensor index. $$id_i = \sum_j sensorIndex[i](j) * nSensors^j$$

◆ dataMap()

const std::map< std::string, RVector >& GIMLI::DataContainer::dataMap ( ) const
inline

Return the complete data map as read-only map

◆ exists()

bool GIMLI::DataContainer::exists ( const std::string &  token) const
inline

Return true if the data with the token exist.

Referenced by createSensor(), and ref().

◆ findSensorIndex()

IndexArray GIMLI::DataContainer::findSensorIndex ( const RVector d) const

Translate a RVector into a valid IndexArray for the corresponding sensors.

◆ formatStringSensors()

const std::string& GIMLI::DataContainer::formatStringSensors ( ) const
inline

Return the input format string for the sensors.

◆ get()

const RVector & GIMLI::DataContainer::get ( const std::string &  token) const

Read only access to a data field. Throws an exception if token data don't exist.

Parameters
tokenString to identify the data

Referenced by GIMLI::TTModellingWithOffset::createJacobian(), GIMLI::TTModellingWithOffset::response(), and GIMLI::TTModellingWithOffset::TTModellingWithOffset().

◆ hash()

Index GIMLI::DataContainer::hash ( ) const

Return a unique hash value.

◆ haveData()

bool GIMLI::DataContainer::haveData ( const std::string &  token) const
inline

Return true if token data exist and at least one value is != 0.0. Return false if the data contains ONLY zero values.

◆ haveTranslationForAlias()

bool GIMLI::DataContainer::haveTranslationForAlias ( const std::string &  alias) const

Return true if there is a valid translation for the token

◆ id()

const IndexArray GIMLI::DataContainer::id ( const std::string &  token) const

Return a copy of the index data field as IndexArray. Throws an exception if token index don't exist.

Parameters
tokenString to identify the index data field

Referenced by add().

◆ init()

void GIMLI::DataContainer::init ( )
virtual

Specify the datacontainer for your needs. TODO Write example if someone wants to use this.

Reimplemented in GIMLI::DataContainerERT.

◆ initDefaults()

void GIMLI::DataContainer::initDefaults ( )

Init default data fields 'valid' and call virtual init method.

References tT_.

◆ initTokenTranslator()

void GIMLI::DataContainer::initTokenTranslator ( )
virtual

Init a token translator map. store a map ['alias'] = 'token'. Only lowercase starting aliases are handled i.e. alias(power, u) map to token => u On request, the first char of the alias will converted to lowercase. e.g. translateToken('power') -> return 'u' translateToken('Power') -> return 'u' translateToken('u') -> return 'u' translateToken('U') -> return 'u' TODO Write example if someone use this

Reimplemented in GIMLI::DataContainerERT.

◆ inputFormatString()

const std::string& GIMLI::DataContainer::inputFormatString ( ) const
inline

Return the token list of a previously loaded file.

◆ isSensorIndex()

bool GIMLI::DataContainer::isSensorIndex ( const std::string &  token) const

Return true if the field entry is of type sensor index.

Referenced by set(), setDataDescription(), and sortSensorsIndex().

◆ load()

int GIMLI::DataContainer::load ( const std::string &  fileName,
bool  sensorIndicesFromOne = true,
bool  removeInvalid = true 
)
virtual

Loads the data from a file. See save for details on the fileformat. On default remove all invalid data that have been marked by checkDataValidity and checkDataValidityLocal.

◆ markInvalid() [1/3]

void GIMLI::DataContainer::markInvalid ( const BVector bvec)
inline

Mark data invalid by index vector.

◆ markInvalid() [2/3]

void GIMLI::DataContainer::markInvalid ( const IndexArray idx)
inline

Mark data invalid by index vector.

◆ markInvalid() [3/3]

void GIMLI::DataContainer::markInvalid ( Index  idx)
inline

Mark data invalid by index.

◆ markInvalidSensorIndices()

void GIMLI::DataContainer::markInvalidSensorIndices ( )

Mark all data invalid that use a sensor index greater than sensor count.

◆ markValid() [1/3]

void GIMLI::DataContainer::markValid ( const BVector bvec,
bool  valid = true 
)
inline

Mark data valid by index vector. Shortcut for this->ref("valid")->setVal(bool vector, valid).

Referenced by sortSensorsIndex().

◆ markValid() [2/3]

void GIMLI::DataContainer::markValid ( const IndexArray idx,
bool  valid = true 
)
inline

Mark data valid by index vector. Shortcut for this->ref("valid")->setVal(idx, valid).

◆ markValid() [3/3]

void GIMLI::DataContainer::markValid ( Index  idx,
bool  valid = true 
)
inline

Mark single data valid. this->ref("valid")->setVal(idx, valid).

◆ operator()() [1/2]

RVector& GIMLI::DataContainer::operator() ( const std::string &  token)
inline

Return reference to the RVector at the data map associated to the token.

◆ operator()() [2/2]

const RVector& GIMLI::DataContainer::operator() ( const std::string &  token) const
inline

Return read-only reference to the RVector at the data map associated to the token.

◆ operator=()

DataContainer & GIMLI::DataContainer::operator= ( const DataContainer data)

Copy constructor, assign a copy of data and return a reference to this DataContainer.

◆ operator[]() [1/2]

RVector& GIMLI::DataContainer::operator[] ( const std::string &  token)
inline

Return reference to the RVector at the data map associated to the token.

◆ operator[]() [2/2]

const RVector& GIMLI::DataContainer::operator[] ( const std::string &  token) const
inline

Return read-only reference to the RVector at the data map associated to the token.

◆ ref()

RVector * GIMLI::DataContainer::ref ( const std::string &  token)

Read/Write access via a pointer to the token data field

Parameters
tokenString to identify the data

References dataDescription_, and exists().

◆ registerSensorIndex()

void GIMLI::DataContainer::registerSensorIndex ( const std::string &  token)

Mark the data field entry as sensor index.

◆ remove() [1/2]

void GIMLI::DataContainer::remove ( const BVector bvec)
inline

Inplace remove from Bvector. Sensors are preserved.

◆ remove() [2/2]

void GIMLI::DataContainer::remove ( const IndexArray idx)
virtual

Inplace remove data from index vector. Remove all data that are covered by idx. Sensors are preserved.

◆ removeInvalid()

void GIMLI::DataContainer::removeInvalid ( )

Remove all data[valid] == 0. Sensors are preserved.

◆ removeSensorIdx() [1/2]

void GIMLI::DataContainer::removeSensorIdx ( const IndexArray idx)

Remove all data that contains the sensor and the sensor itself. *

Parameters
idxIndexArray array of indices regarding sensorPoints_

◆ removeSensorIdx() [2/2]

void GIMLI::DataContainer::removeSensorIdx ( Index  idx)

Remove all data that contains the sensor and the sensor itself.

Parameters
idxuint idx single index for a sensor regarding sensorPoints_

References sensorCount().

◆ removeUnusedSensors()

void GIMLI::DataContainer::removeUnusedSensors ( bool  verbose = false)

Remove all unused sensors from this DataContainer and recount data sensor index entries.

◆ resize()

void GIMLI::DataContainer::resize ( Index  size)

Resize the data map and all data fields to size. Note, new data from resizeing will be set to invalid.

References dataMap_.

Referenced by translateAlias().

◆ save() [1/2]

int GIMLI::DataContainer::save ( const std::string &  fileName,
const std::string &  fmtData,
const std::string &  fmtSensor,
bool  noFilter = false,
bool  verbose = false 
) const
virtual

Save the data to a file. Saves only valid data(except formatData == "all"). File format is

Number of Sensors
#Sensor tokens
Sensor[token 1] Sensor[token n]
Number of Data
#Data tokens
Data[token 1] Data [token n]
Number of additional points
Additional points
http://www.resistivity.net/?unidata

Parameters
fileNameString of the file name
formatDataString to specify the tokens of the data map to be save. If formatData == "all", all datafields will be saved inclusive invalid data.
formatSensorString to specify the tokens of the sensor format to be save
noFilterignore invalid and save all

◆ save() [2/2]

int GIMLI::DataContainer::save ( const std::string &  fileName,
const std::string &  formatData = "all",
bool  noFilter = false,
bool  verbose = false 
) const
inline

Shortcut for save(fileName, formatData, "x y z", verbose);

◆ scale()

void GIMLI::DataContainer::scale ( const RVector3 scale)

Scale all sensor positions by scale.

◆ sensor()

const RVector3& GIMLI::DataContainer::sensor ( Index  i) const
inline

Return a single sensor position. Syntactic sugar.

◆ sensorCount()

Index GIMLI::DataContainer::sensorCount ( ) const
inline

Return the number of sensors.

Referenced by removeSensorIdx().

◆ sensorIdx()

const std::set< std::string > GIMLI::DataContainer::sensorIdx ( ) const
inline

Return the names of all sensor index data fields.

◆ sensorIndexOnFileFromOne()

bool GIMLI::DataContainer::sensorIndexOnFileFromOne ( ) const
inline

Return true if the sensor indices on a loaded/saved file start with 1. Internally the indices are stored from 0.

◆ sensorPosition()

const RVector3& GIMLI::DataContainer::sensorPosition ( double  i) const
inline

Return a single sensor position. *‍/ inline const RVector3 & sensorPosition(Index i) const { return sensorPoints_[i]; }

/*! Return a single sensor position. Syntactic sugar.

Referenced by GIMLI::geometricFactors(), and GIMLI::TravelTimeDijkstraModelling::updateMeshDependency_().

◆ sensorPositions()

const PosVector& GIMLI::DataContainer::sensorPositions ( ) const
inline

Return the complete sensor positions as read-only.

Referenced by GIMLI::DC1dModelling::DC1dModelling(), and translateAlias().

◆ sensors()

const R3Vector& GIMLI::DataContainer::sensors ( ) const
inline

Return the complete sensor positions as read-only.

◆ set()

void GIMLI::DataContainer::set ( const std::string &  token,
const RVector data 
)

Set the data for a given token. If there is no such data, new data will be added. Throws an exception if the data field size is not the same size of the DataContainer.

Parameters
tokenString to identify the data
dataRVector of the data

References dataMap_, isSensorIndex(), and tokenList().

Referenced by createSensor(), GIMLI::getComplexResistivities(), and showInfos().

◆ setAdditionalPoint()

void GIMLI::DataContainer::setAdditionalPoint ( Index  i,
const Pos p 
)
inline

Set additional point i.

◆ setAdditionalPoints()

void GIMLI::DataContainer::setAdditionalPoints ( const PosVector a)
inline

set additional points.

◆ setDataDescription()

void GIMLI::DataContainer::setDataDescription ( const std::string &  token,
const std::string &  description 
)

Set description string for a specific data field. If the data do not exist nothing is done.

Parameters
tokenString that identify the data to be described
descriptionString that describe the data

References isSensorIndex(), and size().

Referenced by showInfos().

◆ setInputFormatString()

void GIMLI::DataContainer::setInputFormatString ( const std::string &  inputFormatString)
inline

Set input format string (e.g. for import routines)

◆ setSensor()

void GIMLI::DataContainer::setSensor ( Index  i,
const RVector3 pos 
)
inline

Set sensor positions. Syntactic sugar.

◆ setSensorIndexOnFileFromOne()

void GIMLI::DataContainer::setSensorIndexOnFileFromOne ( bool  indexFromOne)
inline

Define whether the sensor indices on a loaded/saved file start with 1. Internally the indices are stored from 0.

◆ setSensorPosition()

void GIMLI::DataContainer::setSensorPosition ( Index  i,
const RVector3 pos 
)

Set the position for the i-th sensor. Resize sensors if necessary.

Referenced by GIMLI::geometricFactors().

◆ setSensorPositions() [1/2]

void GIMLI::DataContainer::setSensorPositions ( const PosVector sensors)

Set the positions for all sensors.

◆ setSensorPositions() [2/2]

void GIMLI::DataContainer::setSensorPositions ( const RVector sensors)

Set the positions for 1D sensors distribution.

◆ showInfos()

void GIMLI::DataContainer::showInfos ( ) const

Show some information that belongs to the DataContainer.

References set(), and setDataDescription().

◆ size()

◆ sortSensorsIndex()

IndexArray GIMLI::DataContainer::sortSensorsIndex ( )

Sort all data regarding there sensor indices and sensorIdxNames. Return the resulting permuation index array.

References dataMap_, GIMLI::find(), isSensorIndex(), and markValid().

◆ sortSensorsX()

void GIMLI::DataContainer::sortSensorsX ( bool  incX = true,
bool  incY = true,
bool  incZ = true 
)

Sort all sensors regarding their increasing coordinates. Set inc flag to false to sort respective coordinate in decreasing direction.

◆ tokenList()

std::string GIMLI::DataContainer::tokenList ( bool  withAnnotation = true) const

Return string with space-separated list of all available data tokens. If withAnnotation sets the List separated by the Words "SensorIndex:" and "Data:"

Referenced by set().

◆ tokenTranslator()

const std::map< std::string, std::string >& GIMLI::DataContainer::tokenTranslator ( ) const
inline

Return reference to the token translator map.

◆ translate()

void GIMLI::DataContainer::translate ( const RVector3 trans)

Translate all sensor positions by trans.

◆ translateAlias()

std::string GIMLI::DataContainer::translateAlias ( const std::string &  alias) const

Return the token translation

References additionalPoints(), clear(), resize(), sensorPoints_, sensorPositions(), size(), and topoPoints_.

Member Data Documentation

◆ dataDescription_

std::map< std::string, std::string > GIMLI::DataContainer::dataDescription_
protected

Description for the data map entries.

Stores an optional description for the associated data field < token, description >.

Warning
Description will not yet be saved.

Referenced by ref().

◆ dataMap_

std::map< std::string, RVector > GIMLI::DataContainer::dataMap_
protected

Data map.

Stores the data map < token, data >. All data map entries have the same size.

Referenced by GIMLI::DataContainerERT::electrodeToCurrentPattern(), resize(), set(), and sortSensorsIndex().

◆ dataSensorIdx_

std::set< std::string > GIMLI::DataContainer::dataSensorIdx_
protected

Data field that is sensor index.

Stores the field token that represent sensor indices

Referenced by createSensor().

◆ sensorIndexOnFileFromOne_

bool GIMLI::DataContainer::sensorIndexOnFileFromOne_
protected

Determine if the sensor indices should start from 0 or 1

◆ sensorPoints_

PosVector GIMLI::DataContainer::sensorPoints_
protected

Sensor positions.

Stores the sensor positions.

Referenced by translateAlias().

◆ topoPoints_

PosVector GIMLI::DataContainer::topoPoints_
protected

Store additionally points

Referenced by translateAlias().

◆ tT_

std::map< std::string, std::string > GIMLI::DataContainer::tT_
protected

tokenTranslator for renaming formats to known cases

Referenced by initDefaults(), and GIMLI::DataContainerERT::initTokenTranslator().