Geophysical Inversion and Modelling Library v1.5.4
Loading...
Searching...
No Matches
datacontainer.h
1/******************************************************************************
2 * Copyright (C) 2006-2024 by the GIMLi development team *
3 * Carsten Rücker carsten@resistivity.net *
4 * *
5 * Licensed under the Apache License, Version 2.0 (the "License"); *
6 * you may not use this file except in compliance with the License. *
7 * You may obtain a copy of the License at *
8 * *
9 * http://www.apache.org/licenses/LICENSE-2.0 *
10 * *
11 * Unless required by applicable law or agreed to in writing, software *
12 * distributed under the License is distributed on an "AS IS" BASIS, *
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
14 * See the License for the specific language governing permissions and *
15 * limitations under the License. *
16 * *
17 ******************************************************************************/
18
19#ifndef _GIMLI_DATACONTAINER__H
20#define _GIMLI_DATACONTAINER__H
21
22#include "gimli.h"
23#include "baseentity.h"
24#include "pos.h"
25#include "vector.h"
26
27#include <vector>
28#include <set>
29#include <map>
30#include <iostream>
31#include <fstream>
32
33namespace GIMLI{
34
36
47
48class DLLEXPORT DataContainer{
49public:
52
57 DataContainer(const std::string & fileName,
58 bool sensorIndicesFromOne=true,
59 bool removeInvalid=true);
60
64 DataContainer(const std::string & fileName,
65 const std::string & sensorTokens,
66 bool sensorIndicesFromOne=true,
67 bool removeInvalid=true);
68
70 DataContainer(const DataContainer & data);
71
73 virtual ~DataContainer();
74
77
79 inline const RVector & operator() (const std::string & token) const { return get(token); }
80
82 inline RVector & operator() (const std::string & token) { return *ref(token); }
83
85 inline const RVector & operator[] (const std::string & token) const { return get(token); }
86
88 inline RVector & operator[] (const std::string & token) { return *ref(token); }
89
90
92 void initDefaults();
93
95 virtual void init();
96
106 virtual void initTokenTranslator();
107
109 bool haveTranslationForAlias(const std::string & alias) const;
110
112 std::string translateAlias(const std::string & alias) const;
113
115 virtual void clear();
116
118 inline Index size() const { return dataMap_.find("valid")->second.size(); }
119
121 inline const std::map< std::string, RVector > & dataMap() const { return dataMap_; }
122
124 inline const std::map< std::string, std::string > & dataDescription() const { return dataDescription_; }
125
129 void add(const DataContainer & data, double snap=1e-3);
130
131 // START Sensor related section
133 void setSensorPositions(const RVector & sensors);
134
136 void setSensorPositions(const PosVector & sensors);
137
138 // will be remove on 1.1
139#define GIMLI_USE_POSVECTOR
141 inline const PosVector & sensorPositions() const { return sensorPoints_; }
142
144 void setSensorPosition(Index i, const RVector3 & pos);
145
146// /*! Return a single sensor position. */
147// inline const RVector3 & sensorPosition(Index i) const {
148// return sensorPoints_[i]; }
149
151 inline const RVector3 & sensorPosition(double i) const {
152 return sensorPoints_[(Index)i]; }
153
155 inline const R3Vector & sensors() const { return sensorPositions(); }
156
158 inline const RVector3 & sensor(Index i) const {
159 ASSERT_RANGE(i, 0, this->sensorCount())
160 return sensorPoints_[i];
161 }
162
163 inline void setSensor(Index i, const RVector3 & pos) {
164 this->setSensorPosition(i, pos);
165 }
166
172 SIndex createSensor(const RVector3 & pos, double tolerance=1e-3);
173
175 Index sensorCount() const { return sensorPoints_.size(); }
176
178 void registerSensorIndex(const std::string & token);
179
181 bool isSensorIndex(const std::string & token) const ;
182
184 const std::set< std::string > sensorIdx() const { return dataSensorIdx_; }
185
187 void setSensorIndexOnFileFromOne(bool indexFromOne) { sensorIndexOnFileFromOne_ = indexFromOne; }
188
191
193 IndexArray findSensorIndex(const RVector & d) const;
194
195
197 void markInvalidSensorIndices();
198
202 void removeSensorIdx(Index idx);
203
207 void removeSensorIdx(const IndexArray & idx);
208
210 inline const std::string & formatStringSensors() const { return inputFormatStringSensors_; }
211
215 void sortSensorsX(bool incX=true, bool incY=true, bool incZ=true);
216
218 void translate(const RVector3 & trans);
219
221 void scale(const RVector3 & scale);
222
226 IndexArray dataIndex();
227
231 IndexArray sortSensorsIndex();
232
233 // END Sensor related section
234
236 inline void setAdditionalPoints(const PosVector & a ){ topoPoints_ = a; }
237
239 inline const PosVector & additionalPoints() const { return topoPoints_; }
240
242 inline void setAdditionalPoint(Index i, const Pos & p) {
243 ASSERT_SIZE(topoPoints_, i)
244 topoPoints_[i] = p;
245 }
246
247 inline void addAdditionalPoint(const Pos & p) {
248 topoPoints_.push_back(p);
249 }
250
253 inline bool allNonZero(const std::string & token) const {
254 if (exists(token)) return (min(abs(dataMap_.find(token)->second)) > TOLERANCE);
255 return false;
256 }
257
260 inline bool haveData(const std::string & token) const {
261 if (exists(token) && dataMap_.find(token)->second.size() > 0)
262 return !zero(dataMap_.find(token)->second);
263 return false;
264 }
265
267 inline bool exists(const std::string & token) const {
268 return dataMap_.count(token) != 0; }
269
271 inline const std::map< std::string, std::string > & tokenTranslator() const { return tT_; }
272
276 virtual int load(const std::string & fileName,
277 bool sensorIndicesFromOne=true,
278 bool removeInvalid=true);
279
295 virtual int save(const std::string & fileName,
296 const std::string & fmtData,
297 const std::string & fmtSensor,
298 bool noFilter=false,
299 bool verbose=false) const;
300
302 inline int save(const std::string & fileName,
303 const std::string & formatData="all",
304 bool noFilter=false,
305 bool verbose=false) const {
306 return save(fileName, formatData, "x y z", noFilter, verbose); }
307
308 virtual int write(std::fstream & os,
309 const std::string & fmtData,
310 const std::string & fmtSensor,
311 bool noFilter=false,
312 bool verbose=false) const;
314 void showInfos() const ;
315
318 void resize(Index size);
319
322 std::string tokenList(bool withAnnotation=true) const;
323
329 void add(const std::string & token, const RVector & data, const std::string & description = "");
330
332 void add(const std::string & token){ add(token, RVector(this->size(), 0.0)); }
333
338 void set(const std::string & token, const RVector & data);
339
342 const RVector & get(const std::string & token) const ;
343
346 const IndexArray id(const std::string & token) const ;
347
350 RVector * ref(const std::string & token);
351
355 void setDataDescription(const std::string & token, const std::string & description);
356
359 std::string dataDescription(const std::string & token) const;
360
362 virtual void remove(const IndexArray & idx);
363
365 inline void remove(const BVector & bvec){ remove(find(bvec)); }
366
368 inline void markValid(const BVector & bvec, bool valid=true){
369 dataMap_["valid"].setVal(valid, find(bvec));
370 }
371
372 inline void markValid(const IndexArray & idx, bool valid=true){
373 dataMap_["valid"].setVal(valid, idx);
374 }
375
376 inline void markValid(Index idx, bool valid=true){
377 dataMap_["valid" ].setVal(valid, idx);
378 }
379
381 inline void markInvalid(const BVector & bvec){ markValid(find(bvec), false); }
382
384 inline void markInvalid(const IndexArray & idx){ markValid(idx, false); }
385
387 inline void markInvalid(Index idx){ markValid(idx, false); }
388
394 void checkDataValidity(bool remove=true);
395
397 virtual void checkDataValidityLocal(){}
398
400 void removeInvalid();
401
403 void removeUnusedSensors(bool verbose=false);
404
406 inline void setInputFormatString(const std::string & inputFormatString){
407 inputFormatString_=inputFormatString; }
408
410 inline const std::string & inputFormatString() const {
411 return inputFormatString_; }
412
414 Index hash() const;
415
416protected:
417 virtual void copy_(const DataContainer & data);
418
419 std::string inputFormatStringSensors_;
420
421 std::string inputFormatString_;
422
424
425 std::map< std::string, RVector > dataMap_;
426
428
429 PosVector sensorPoints_;
430
432
433 std::set< std::string > dataSensorIdx_;
434
436
437 std::map< std::string, std::string > dataDescription_;
438
440 PosVector topoPoints_;
441
443 std::map< std::string, std::string > tT_;
444
447
448
449}; // class DataContainer
450
451} // namespace GIMLI
452
453#endif // DATACONTAINER__H
DataContainer to store, load and save data in the GIMLi unified data format.
Definition datacontainer.h:48
DataContainer()
Definition datacontainer.cpp:29
std::map< std::string, std::string > dataDescription_
Description for the data map entries.
Definition datacontainer.h:437
const RVector3 & sensorPosition(double i) const
Definition datacontainer.h:151
virtual void checkDataValidityLocal()
Definition datacontainer.h:397
const std::string & formatStringSensors() const
Definition datacontainer.h:210
std::map< std::string, std::string > tT_
Definition datacontainer.h:443
const std::string & inputFormatString() const
Definition datacontainer.h:410
void setSensorIndexOnFileFromOne(bool indexFromOne)
Definition datacontainer.h:187
void addAdditionalPoint(const Pos &p)
Definition datacontainer.h:247
void markValid(const BVector &bvec, bool valid=true)
Definition datacontainer.h:368
void add(const std::string &token)
Definition datacontainer.h:332
const PosVector & sensorPositions() const
Definition datacontainer.h:141
RVector * ref(const std::string &token)
Definition datacontainer.cpp:719
void markInvalid(const IndexArray &idx)
Definition datacontainer.h:384
PosVector topoPoints_
Definition datacontainer.h:440
bool sensorIndexOnFileFromOne() const
Definition datacontainer.h:190
virtual int save(const std::string &fileName, const std::string &fmtData, const std::string &fmtSensor, bool noFilter=false, bool verbose=false) const
Definition datacontainer.cpp:518
void markValid(const IndexArray &idx, bool valid=true)
Definition datacontainer.h:372
std::set< std::string > dataSensorIdx_
Data field that is sensor index.
Definition datacontainer.h:433
void setAdditionalPoint(Index i, const Pos &p)
Definition datacontainer.h:242
const PosVector & additionalPoints() const
Definition datacontainer.h:239
bool haveData(const std::string &token) const
Definition datacontainer.h:260
bool allNonZero(const std::string &token) const
Definition datacontainer.h:253
void setSensor(Index i, const RVector3 &pos)
Definition datacontainer.h:163
void setAdditionalPoints(const PosVector &a)
Definition datacontainer.h:236
const R3Vector & sensors() const
Definition datacontainer.h:155
const std::map< std::string, std::string > & dataDescription() const
Definition datacontainer.h:124
const std::map< std::string, RVector > & dataMap() const
Definition datacontainer.h:121
void markInvalid(const BVector &bvec)
Definition datacontainer.h:381
std::map< std::string, RVector > dataMap_
Data map.
Definition datacontainer.h:425
const RVector & get(const std::string &token) const
Definition datacontainer.cpp:691
int save(const std::string &fileName, const std::string &formatData="all", bool noFilter=false, bool verbose=false) const
Definition datacontainer.h:302
bool exists(const std::string &token) const
Definition datacontainer.h:267
Index sensorCount() const
Definition datacontainer.h:175
void setSensorPosition(Index i, const RVector3 &pos)
Definition datacontainer.cpp:842
PosVector sensorPoints_
Sensor positions.
Definition datacontainer.h:429
void markInvalid(Index idx)
Definition datacontainer.h:387
void remove(const BVector &bvec)
Definition datacontainer.h:365
DataContainer & operator=(const DataContainer &data)
Definition datacontainer.cpp:64
Index size() const
Definition datacontainer.h:118
const RVector3 & sensor(Index i) const
Definition datacontainer.h:158
void markValid(Index idx, bool valid=true)
Definition datacontainer.h:376
void setInputFormatString(const std::string &inputFormatString)
Definition datacontainer.h:406
bool sensorIndexOnFileFromOne_
Definition datacontainer.h:446
const std::map< std::string, std::string > & tokenTranslator() const
Definition datacontainer.h:271
void removeInvalid()
Definition datacontainer.cpp:756
const std::set< std::string > sensorIdx() const
Definition datacontainer.h:184
3 dimensional vector
Definition pos.h:73
GIMLi main namespace for the Geophyiscal Inversion and Modelling Library.
Definition baseentity.h:24
bool zero(const Vector< ValueType > &v)
Definition vector.h:1315
IndexArray find(const BVector &v)
Definition vector.h:1346
bool load(Matrix< ValueType > &A, const std::string &filename)
Definition matrix.h:828