Geophysical Inversion and Modelling Library
v1.5.2-5-g042d7f36
|
DataContainer to store, load and save data in the GIMLi unified data format. More...
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 () |
DataContainer & | operator= (const DataContainer &data) |
const RVector & | operator() (const std::string &token) const |
RVector & | operator() (const std::string &token) |
const RVector & | operator[] (const std::string &token) const |
RVector & | operator[] (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 PosVector & | sensorPositions () const |
void | setSensorPosition (Index i, const RVector3 &pos) |
const RVector3 & | sensorPosition (double i) const |
const R3Vector & | sensors () const |
const RVector3 & | sensor (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 PosVector & | additionalPoints () 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 RVector & | get (const std::string &token) const |
const IndexArray | id (const std::string &token) const |
RVector * | ref (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, RVector > | dataMap_ |
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_ |
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.
GIMLI::DataContainer::DataContainer | ( | ) |
Simple Constructor, builds an empty data container.
References initDefaults().
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.
fileName | String of the file name |
References initDefaults(), load(), and removeInvalid().
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.
References initDefaults(), load(), registerSensorIndex(), removeInvalid(), and tokenList().
GIMLI::DataContainer::DataContainer | ( | const DataContainer & | data | ) |
Copy Constructor
References initDefaults().
|
virtual |
Destructor.
References clear(), and initDefaults().
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 createSensor(), dataMap_, get(), id(), isSensorIndex(), resize(), sensorCount(), sensorPositions(), GIMLI::Vector< ValueType >::setVal(), and size().
|
inline |
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.
token | String to identify the data |
data | RVector of the data |
description | String that describe the data |
References set(), and setDataDescription().
|
inline |
Push back additional point p.
|
inline |
Return the additional points.
|
inline |
Return true if token data exist and all elements != 0.0. Return false if the data contains one zero value.
Referenced by GIMLI::DataContainerERT::checkDataValidityLocal(), GIMLI::DC1dModelling::DC1dModelling(), and GIMLI::getComplexData().
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.
References checkDataValidityLocal(), dataMap_, GIMLI::find(), get(), isSensorIndex(), markInvalid(), remove(), removeInvalid(), GIMLI::saveVec(), sensorCount(), and size().
Referenced by load().
|
inlinevirtual |
Reimplemented in GIMLI::DataContainerERT.
Referenced by checkDataValidity().
|
virtual |
Clear the container, remove all sensor locations and data.
References GIMLI::Vector< ValueType >::clear(), dataMap_, initDefaults(), sensorPoints_, and topoPoints_.
Referenced by load(), and ~DataContainer().
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.
pos | RVector3 of the sensor position |
tolerance | Double of the snapping tolerance |
References GIMLI::Pos::distance(), and sensorPoints_.
|
inline |
Return the complete data descriptions map
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.
token | String that identify the data. |
References dataDescription_, and exists().
IndexArray GIMLI::DataContainer::dataIndex | ( | ) |
Return unique sortable data index, based on sensor index. $$id_i = \sum_j sensorIndex[i](j) * nSensors^j$$
References dataMap_, dataSensorIdx_, sensorCount(), and size().
Referenced by sortSensorsIndex().
|
inline |
Return the complete data map as read-only map
|
inline |
Return true if the data with the token exist.
Referenced by dataDescription(), GIMLI::getComplexData(), registerSensorIndex(), and setDataDescription().
IndexArray GIMLI::DataContainer::findSensorIndex | ( | const RVector & | d | ) | const |
Translate a RVector into a valid IndexArray for the corresponding sensors.
References sensorCount().
|
inline |
Return the input format string for the sensors.
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.
token | String to identify the data |
References dataMap_, and tokenList().
Referenced by add(), GIMLI::DataContainerERT::averageDuplicateData(), checkDataValidity(), GIMLI::DataContainerERT::checkDataValidityLocal(), GIMLI::TTModellingWithOffset::createJacobian(), removeInvalid(), GIMLI::TTModellingWithOffset::response(), and GIMLI::TTModellingWithOffset::TTModellingWithOffset().
Index GIMLI::DataContainer::hash | ( | ) | const |
Return a unique hash value.
References dataMap_, sensorPoints_, and topoPoints_.
|
inline |
Return true if token data exist and at least one value is != 0.0. Return false if the data contains ONLY zero values.
References GIMLI::zero().
Referenced by GIMLI::DataContainerERT::checkDataValidityLocal().
bool GIMLI::DataContainer::haveTranslationForAlias | ( | const std::string & | alias | ) | const |
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.
token | String to identify the index data field |
References dataMap_, isSensorIndex(), and tokenList().
Referenced by add().
|
virtual |
Specify the datacontainer for your needs. TODO Write example if someone wants to use this.
Reimplemented in GIMLI::DataContainerERT.
Referenced by initDefaults().
void GIMLI::DataContainer::initDefaults | ( | ) |
Init default data fields 'valid' and call virtual init method.
References dataMap_, init(), initTokenTranslator(), and sensorIndexOnFileFromOne_.
Referenced by clear(), DataContainer(), and ~DataContainer().
|
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.
References tT_.
Referenced by initDefaults(), and GIMLI::DataContainerERT::initTokenTranslator().
|
inline |
Return the token list of a previously loaded file.
bool GIMLI::DataContainer::isSensorIndex | ( | const std::string & | token | ) | const |
Return true if the field entry is of type sensor index.
References dataSensorIdx_.
Referenced by add(), GIMLI::DataContainerERT::averageDuplicateData(), checkDataValidity(), id(), load(), markInvalidSensorIndices(), removeSensorIdx(), removeUnusedSensors(), resize(), sortSensorsX(), and tokenList().
|
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.
References checkDataValidity(), clear(), createSensor(), dataMap_, haveTranslationForAlias(), isSensorIndex(), removeUnusedSensors(), resize(), scale(), sensorCount(), sensorIndexOnFileFromOne_, sensorPoints_, setSensorIndexOnFileFromOne(), size(), topoPoints_, translateAlias(), GIMLI::x(), GIMLI::y(), and GIMLI::z().
Referenced by DataContainer(), and GIMLI::DataContainerERT::DataContainerERT().
|
inline |
Mark data invalid by index vector.
References GIMLI::find().
Referenced by checkDataValidity(), and GIMLI::DataContainerERT::checkDataValidityLocal().
|
inline |
Mark data invalid by index vector.
|
inline |
Mark data invalid by index.
void GIMLI::DataContainer::markInvalidSensorIndices | ( | ) |
Mark all data invalid that use a sensor index greater than sensor count.
References dataMap_, GIMLI::find(), isSensorIndex(), and markValid().
|
inline |
Mark data valid by index vector. Shortcut for this->ref("valid")->setVal(bool vector, valid).
References GIMLI::find().
Referenced by markInvalidSensorIndices(), remove(), and removeSensorIdx().
|
inline |
Mark data valid by index vector. Shortcut for this->ref("valid")->setVal(idx, valid).
|
inline |
Mark single data valid. this->ref("valid")->setVal(idx, valid).
|
inline |
Return reference to the RVector at the data map associated to the token.
|
inline |
Return read-only reference to the RVector at the data map associated to the token.
DataContainer & GIMLI::DataContainer::operator= | ( | const DataContainer & | data | ) |
Copy constructor, assign a copy of data and return a reference to this DataContainer.
|
inline |
Return reference to the RVector at the data map associated to the token.
|
inline |
Return read-only reference to the RVector at the data map associated to the token.
RVector * GIMLI::DataContainer::ref | ( | const std::string & | token | ) |
Read/Write access via a pointer to the token data field
token | String to identify the data |
References dataMap_, and tokenList().
void GIMLI::DataContainer::registerSensorIndex | ( | const std::string & | token | ) |
Mark the data field entry as sensor index.
References dataSensorIdx_, exists(), set(), and size().
Referenced by DataContainer(), and GIMLI::DataContainerERT::init().
|
inline |
Inplace remove from Bvector. Sensors are preserved.
References GIMLI::find(), and remove().
Referenced by remove().
|
virtual |
Inplace remove data from index vector. Remove all data that are covered by idx. Sensors are preserved.
References markValid(), and removeInvalid().
Referenced by checkDataValidity().
void GIMLI::DataContainer::removeInvalid | ( | ) |
Remove all data[valid] == 0. Sensors are preserved.
References dataMap_, GIMLI::find(), and get().
Referenced by checkDataValidity(), DataContainer(), GIMLI::DataContainerERT::DataContainerERT(), remove(), and removeSensorIdx().
void GIMLI::DataContainer::removeSensorIdx | ( | const IndexArray & | idx | ) |
Remove all data that contains the sensor and the sensor itself. *
idx | IndexArray array of indices regarding sensorPoints_ |
References dataMap_, GIMLI::find(), isSensorIndex(), markValid(), removeInvalid(), and removeUnusedSensors().
void GIMLI::DataContainer::removeSensorIdx | ( | Index | idx | ) |
Remove all data that contains the sensor and the sensor itself.
idx | uint idx single index for a sensor regarding sensorPoints_ |
void GIMLI::DataContainer::removeUnusedSensors | ( | bool | verbose = false | ) |
Remove all unused sensors from this DataContainer and recount data sensor index entries.
References GIMLI::Vector< ValueType >::clear(), dataMap_, isSensorIndex(), sensorCount(), and sensorPoints_.
Referenced by load(), and removeSensorIdx().
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_, isSensorIndex(), and size().
Referenced by add(), GIMLI::DataContainerERT::averageDuplicateData(), GIMLI::DataContainerERT::createFourPointData(), and load().
|
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
fileName | String of the file name |
formatData | String to specify the tokens of the data map to be save. If formatData == "all", all datafields will be saved inclusive invalid data. |
formatSensor | String to specify the tokens of the sensor format to be save |
noFilter | ignore invalid and save all |
|
inline |
Shortcut for save(fileName, formatData, "x y z", verbose);
void GIMLI::DataContainer::scale | ( | const RVector3 & | scale | ) |
|
inline |
Return a single sensor position. Syntactic sugar.
|
inline |
Return the number of sensors.
Referenced by add(), GIMLI::DataContainerERT::averageDuplicateData(), checkDataValidity(), GIMLI::DataContainerERT::currentPatternToElectrode(), dataIndex(), GIMLI::DataContainerERT::electrodeToCurrentPattern(), findSensorIndex(), GIMLI::geometricFactors(), load(), removeUnusedSensors(), showInfos(), and sortSensorsX().
|
inline |
Return the names of all sensor index data fields.
|
inline |
Return true if the sensor indices on a loaded/saved file start with 1. Internally the indices are stored from 0.
|
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_().
|
inline |
Return the complete sensor positions as read-only.
Referenced by add(), and GIMLI::DC1dModelling::DC1dModelling().
|
inline |
Return the complete sensor positions as read-only.
Referenced by setSensorPositions().
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.
token | String to identify the data |
data | RVector of the data |
References dataMap_, and size().
Referenced by add(), GIMLI::DataContainerERT::checkDataValidityLocal(), registerSensorIndex(), and GIMLI::setComplexData().
|
inline |
Set additional point i.
|
inline |
set additional points.
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.
token | String that identify the data to be described |
description | String that describe the data |
References dataDescription_, and exists().
Referenced by add().
|
inline |
Set input format string (e.g. for import routines)
|
inline |
Set sensor positions. Syntactic sugar.
|
inline |
Define whether the sensor indices on a loaded/saved file start with 1. Internally the indices are stored from 0.
Referenced by load().
void GIMLI::DataContainer::setSensorPosition | ( | Index | i, |
const RVector3 & | pos | ||
) |
Set the position for the i-th sensor. Resize sensors if necessary.
References GIMLI::Vector< ValueType >::resize(), and sensorPoints_.
Referenced by GIMLI::geometricFactors().
void GIMLI::DataContainer::setSensorPositions | ( | const PosVector & | sensors | ) |
Set the positions for all sensors.
References sensorPoints_, and sensors().
void GIMLI::DataContainer::setSensorPositions | ( | const RVector & | sensors | ) |
Set the positions for 1D sensors distribution.
References sensors().
void GIMLI::DataContainer::showInfos | ( | ) | const |
Show some information that belongs to the DataContainer.
References sensorCount(), size(), tokenList(), and topoPoints_.
|
inline |
Return the size of the data map.
Referenced by add(), GIMLI::DataContainerERT::addFourPointData(), GIMLI::DataContainerERT::averageDuplicateData(), checkDataValidity(), GIMLI::DataContainerERT::checkDataValidityLocal(), GIMLI::DataContainerERT::createFourPointData(), GIMLI::TTModellingWithOffset::createJacobian(), dataIndex(), GIMLI::DC1dModelling::DC1dModelling(), GIMLI::geometricFactors(), load(), registerSensorIndex(), resize(), GIMLI::TravelTimeDijkstraModelling::response(), set(), showInfos(), and sortSensorsIndex().
IndexArray GIMLI::DataContainer::sortSensorsIndex | ( | ) |
Sort all data regarding there sensor indices and sensorIdxNames. Return the resulting permuation index array.
References dataIndex(), dataMap_, and size().
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.
References dataMap_, isSensorIndex(), sensorCount(), and sensorPoints_.
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:"
References dataMap_, and isSensorIndex().
Referenced by DataContainer(), get(), id(), ref(), and showInfos().
|
inline |
Return reference to the token translator map.
void GIMLI::DataContainer::translate | ( | const RVector3 & | trans | ) |
Translate all sensor positions by trans.
References sensorPoints_.
std::string GIMLI::DataContainer::translateAlias | ( | const std::string & | alias | ) | const |
|
protected |
Description for the data map entries.
Stores an optional description for the associated data field < token, description >.
Referenced by dataDescription(), and setDataDescription().
|
protected |
Data map.
Stores the data map < token, data >. All data map entries have the same size.
Referenced by add(), GIMLI::DataContainerERT::averageDuplicateData(), checkDataValidity(), clear(), GIMLI::DataContainerERT::createFourPointData(), dataIndex(), get(), hash(), id(), GIMLI::DataContainerERT::init(), initDefaults(), load(), markInvalidSensorIndices(), ref(), removeInvalid(), removeSensorIdx(), removeUnusedSensors(), resize(), set(), sortSensorsIndex(), sortSensorsX(), and tokenList().
|
protected |
Data field that is sensor index.
Stores the field token that represent sensor indices
Referenced by dataIndex(), isSensorIndex(), and registerSensorIndex().
|
protected |
Determine if the sensor indices should start from 0 or 1
Referenced by GIMLI::DataContainerERT::init(), initDefaults(), and load().
|
protected |
Sensor positions.
Stores the sensor positions.
Referenced by clear(), createSensor(), hash(), load(), removeUnusedSensors(), scale(), setSensorPosition(), setSensorPositions(), sortSensorsX(), and translate().
|
protected |
Store additionally points
Referenced by clear(), hash(), load(), and showInfos().
|
protected |
tokenTranslator for renaming formats to known cases
Referenced by haveTranslationForAlias(), GIMLI::DataContainerERT::initTokenTranslator(), initTokenTranslator(), and translateAlias().